import { Modal, ModalOverlay, ModalContent, ModalFooter, ModalHeader, ModalBody, Box, Input, Text, Button, Checkbox, } from "@chakra-ui/react"; import React from "react"; import { useNuiEvent } from "../../hooks/useNuiEvent"; import { useLocales } from "../../providers/LocaleProvider"; import { debugData } from "../../utils/debugData"; import { fetchNui } from "../../utils/fetchNui"; interface Props { heading: string; rows: { type: "input" | "checkbox"; label: string; }[]; } debugData([ { action: "openDialog", data: { heading: "Police locker", rows: [ { type: "input", label: "Locker number" }, { type: "checkbox", label: "Some checkbox" }, { type: "input", label: "Locker PIN" }, { type: "checkbox", label: "Some other checkbox" }, ], }, }, ]); const InputDialog: React.FC = () => { const [fields, setFields] = React.useState({ heading: "", rows: [{ type: "input", label: "" }], }); const [inputData, setInputData] = React.useState>([]); const [visible, setVisible] = React.useState(false); const { locale } = useLocales(); useNuiEvent("openDialog", (data) => { setFields(data); setInputData([]); setVisible(true); }); const handleClose = () => { setVisible(false); fetchNui("inputData"); }; const handleChange = ( e: React.ChangeEvent, index: number, type: "input" | "checkbox" ) => { setInputData((previousData) => { previousData[index] = type === "input" ? e.target.value : e.target.checked; return previousData; }); }; const handleConfirm = () => { setVisible(false); fetchNui("inputData", inputData); }; return ( <> {fields.heading} {fields.rows.map((row, index) => ( {row.type === "input" && ( {row.label} handleChange(e, index, "input")} /> )} {row.type === "checkbox" && ( handleChange(e, index, "checkbox")} > {row.label} )} ))} ); }; export default InputDialog;