import { Modal, ModalOverlay, ModalContent, ModalFooter, ModalHeader, ModalBody, Button } from '@chakra-ui/react'; import React from 'react'; import { useNuiEvent } from '../../hooks/useNuiEvent'; import { useKeyPress } from '../../hooks/useKeyPress'; import { useLocales } from '../../providers/LocaleProvider'; import { debugData } from '../../utils/debugData'; import { fetchNui } from '../../utils/fetchNui'; import { IInput, ICheckbox, ISelect, INumber, ISlider } from '../../interfaces/dialog'; import InputField from './components/input'; import CheckboxField from './components/checkbox'; import SelectField from './components/select'; import NumberField from './components/number'; import SliderField from './components/slider'; interface Props { heading: string; rows: Array; } // debugData([ // { // action: "openDialog", // data: { // heading: "Police locker", // rows: [ // { type: "input", label: "Locker number", placeholder: "420" }, // { type: "checkbox", label: "Some checkbox" }, // { type: "input", label: "Locker PIN", password: true, icon: "lock" }, // { type: "checkbox", label: "Some other checkbox", checked: true }, // { // type: "select", // label: "Locker type", // options: [ // { value: "option1" }, // { value: "option2", label: "Option 2" }, // { value: "option3", label: "Option 3" }, // ], // }, // { type: "number", label: "Number counter", default: 12 }, // { type: "slider", label: "Slide bar", min: 10, max: 50, step: 2 }, // ], // }, // }, // ]); const InputDialog: React.FC = () => { const [fields, setFields] = React.useState({ heading: '', rows: [{ type: 'input', label: '' }], }); const [inputData, setInputData] = React.useState>([]); const [passwordStates, setPasswordStates] = React.useState([]); const [visible, setVisible] = React.useState(false); const { locale } = useLocales(); const handlePasswordStates = (index: number) => { setPasswordStates({ ...passwordStates, [index]: !passwordStates[index], }); }; useNuiEvent('openDialog', (data) => { setPasswordStates([]); setFields(data); setInputData([]); setVisible(true); }); const handleClose = () => { setVisible(false); fetchNui('inputData'); }; const handleChange = (value: string | number | boolean, index: number) => { setInputData((previousData) => { previousData[index] = value; return previousData; }); }; const handleConfirm = () => { setVisible(false); fetchNui('inputData', inputData); }; return ( <> { if (e.key === 'Enter' && visible) return handleConfirm(); }} > {fields.heading} {fields.rows.map((row: IInput | ICheckbox | ISelect | INumber | ISlider, index) => ( {row.type === 'input' && ( )} {row.type === 'checkbox' && } {row.type === 'select' && } {row.type === 'number' && } {row.type === 'slider' && } ))} ); }; export default InputDialog;