import { Modal, ModalOverlay, ModalContent, ModalFooter, ModalHeader, ModalBody, Box, Input, InputGroup, InputRightElement, Text, Button, Checkbox, Select, } from "@chakra-ui/react"; import React from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { useNuiEvent } from "../../hooks/useNuiEvent"; import { useLocales } from "../../providers/LocaleProvider"; import { debugData } from "../../utils/debugData"; import { fetchNui } from "../../utils/fetchNui"; type RowType = "input" | "checkbox" | "select"; interface Props { heading: string; rows: { type: RowType; label: string; options?: { value: string; label: string }[]; password?: boolean; }[]; } debugData([ { action: "openDialog", data: { heading: "Police locker", rows: [ { type: "input", label: "Locker number" }, { type: "checkbox", label: "Some checkbox" }, { type: "input", label: "Locker PIN", password: true }, { type: "checkbox", label: "Some other checkbox" }, { type: "select", label: "Locker type", options: [ { value: "option1", label: "Option 1" }, { value: "option2", label: "Option 2" }, { value: "option3", label: "Option 3" }, ], }, ], }, }, ]); 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(); const [passwordStates, setShowPassword] = React.useState>([]); const handleShowPassword = (index: number) => { setShowPassword({ ...passwordStates, [index]: !passwordStates[index] }) } useNuiEvent("openDialog", (data) => { setShowPassword([]); setFields(data); setInputData([]); setVisible(true); }); const handleClose = () => { setVisible(false); fetchNui("inputData"); }; const handleChange = (value: string | boolean, index: number) => { setInputData((previousData) => { previousData[index] = value; return previousData; }); }; const handleConfirm = () => { setVisible(false); fetchNui("inputData", inputData); }; return ( <> {fields.heading} {fields.rows.map((row, index) => ( {row.type === "input" && ( {row.label} handleChange(e.target.value, index)} type={!row.password || passwordStates[index] ? 'text' : 'password'} /> {row.password && ( handleShowPassword(index)} children={ } /> )} )} {row.type === "checkbox" && ( handleChange(e.target.checked, index)} > {row.label} )} {row.type === "select" && ( )} ))} ); }; export default InputDialog;