mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 15:06:02 +01:00
refactor(web): prettier format for input dialog
This commit is contained in:
@@ -1,24 +1,16 @@
|
||||
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";
|
||||
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;
|
||||
@@ -53,12 +45,10 @@ interface Props {
|
||||
|
||||
const InputDialog: React.FC = () => {
|
||||
const [fields, setFields] = React.useState<Props>({
|
||||
heading: "",
|
||||
rows: [{ type: "input", label: "" }],
|
||||
heading: '',
|
||||
rows: [{ type: 'input', label: '' }],
|
||||
});
|
||||
const [inputData, setInputData] = React.useState<
|
||||
Array<string | number | boolean>
|
||||
>([]);
|
||||
const [inputData, setInputData] = React.useState<Array<string | number | boolean>>([]);
|
||||
const [passwordStates, setPasswordStates] = React.useState<boolean[]>([]);
|
||||
const [visible, setVisible] = React.useState(false);
|
||||
const { locale } = useLocales();
|
||||
@@ -70,7 +60,7 @@ const InputDialog: React.FC = () => {
|
||||
});
|
||||
};
|
||||
|
||||
useNuiEvent<Props>("openDialog", (data) => {
|
||||
useNuiEvent<Props>('openDialog', (data) => {
|
||||
setPasswordStates([]);
|
||||
setFields(data);
|
||||
setInputData([]);
|
||||
@@ -79,7 +69,7 @@ const InputDialog: React.FC = () => {
|
||||
|
||||
const handleClose = () => {
|
||||
setVisible(false);
|
||||
fetchNui("inputData");
|
||||
fetchNui('inputData');
|
||||
};
|
||||
|
||||
const handleChange = (value: string | number | boolean, index: number) => {
|
||||
@@ -91,19 +81,12 @@ const InputDialog: React.FC = () => {
|
||||
|
||||
const handleConfirm = () => {
|
||||
setVisible(false);
|
||||
fetchNui("inputData", inputData);
|
||||
fetchNui('inputData', inputData);
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<Modal
|
||||
isOpen={visible}
|
||||
onClose={handleClose}
|
||||
isCentered
|
||||
closeOnEsc
|
||||
closeOnOverlayClick={false}
|
||||
size="xs"
|
||||
>
|
||||
<Modal isOpen={visible} onClose={handleClose} isCentered closeOnEsc closeOnOverlayClick={false} size="xs">
|
||||
<ModalOverlay />
|
||||
<ModalContent
|
||||
onKeyDown={(e) => {
|
||||
@@ -114,7 +97,7 @@ const InputDialog: React.FC = () => {
|
||||
<ModalBody fontFamily="Poppins" textAlign="left">
|
||||
{fields.rows.map((row: IInput | ICheckbox | ISelect | INumber | ISlider, index) => (
|
||||
<React.Fragment key={`row-${index}`}>
|
||||
{row.type === "input" && (
|
||||
{row.type === 'input' && (
|
||||
<InputField
|
||||
key={`input-${index}`}
|
||||
row={row}
|
||||
@@ -124,34 +107,10 @@ const InputDialog: React.FC = () => {
|
||||
handlePasswordStates={handlePasswordStates}
|
||||
/>
|
||||
)}
|
||||
{row.type === "checkbox" && (
|
||||
<CheckboxField
|
||||
row={row}
|
||||
index={index}
|
||||
handleChange={handleChange}
|
||||
/>
|
||||
)}
|
||||
{row.type === "select" && (
|
||||
<SelectField
|
||||
row={row}
|
||||
index={index}
|
||||
handleChange={handleChange}
|
||||
/>
|
||||
)}
|
||||
{row.type === "number" && (
|
||||
<NumberField
|
||||
row={row}
|
||||
index={index}
|
||||
handleChange={handleChange}
|
||||
/>
|
||||
)}
|
||||
{row.type === "slider" && (
|
||||
<SliderField
|
||||
row={row}
|
||||
index={index}
|
||||
handleChange={handleChange}
|
||||
/>
|
||||
)}
|
||||
{row.type === 'checkbox' && <CheckboxField row={row} index={index} handleChange={handleChange} />}
|
||||
{row.type === 'select' && <SelectField row={row} index={index} handleChange={handleChange} />}
|
||||
{row.type === 'number' && <NumberField row={row} index={index} handleChange={handleChange} />}
|
||||
{row.type === 'slider' && <SliderField row={row} index={index} handleChange={handleChange} />}
|
||||
</React.Fragment>
|
||||
))}
|
||||
</ModalBody>
|
||||
|
||||
Reference in New Issue
Block a user