diff --git a/web/src/features/dialog/InputDialog.tsx b/web/src/features/dialog/InputDialog.tsx index 8e2b3e2..1bc9148 100644 --- a/web/src/features/dialog/InputDialog.tsx +++ b/web/src/features/dialog/InputDialog.tsx @@ -5,35 +5,22 @@ import { ModalFooter, ModalHeader, ModalBody, - Box, - Input, - InputGroup, - InputRightElement, - Text, Button, - Checkbox, - Select, - InputLeftElement, } from "@chakra-ui/react"; import React from "react"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { IconProp } from "@fortawesome/fontawesome-svg-core"; import { useNuiEvent } from "../../hooks/useNuiEvent"; import { useLocales } from "../../providers/LocaleProvider"; import { debugData } from "../../utils/debugData"; import { fetchNui } from "../../utils/fetchNui"; +import { Row } from "../../interfaces/dialog"; -type RowType = "input" | "checkbox" | "select"; +import Input from "./components/input"; +import CheckboxField from "./components/checkbox"; +import SelectField from "./components/select"; interface Props { heading: string; - rows: { - type: RowType; - label: string; - options?: { value: string; label: string }[]; - password?: boolean; - icon?: IconProp; - }[]; + rows: Row[]; } debugData([ @@ -99,6 +86,7 @@ const InputDialog: React.FC = () => { const handleConfirm = () => { setVisible(false); + console.log(inputData); fetchNui("inputData", inputData); }; @@ -119,65 +107,28 @@ const InputDialog: React.FC = () => { {fields.rows.map((row, index) => ( {row.type === "input" && ( - - {row.label} - - {row.icon && ( - } - /> - )} - handleChange(e.target.value, index)} - type={ - !row.password || passwordStates[index] - ? "text" - : "password" - } - /> - {row.password && ( - handlePasswordStates(index)} - children={ - - } - /> - )} - - + )} {row.type === "checkbox" && ( - - handleChange(e.target.checked, index)} - > - {row.label} - - + )} {row.type === "select" && ( - - - + )} ))} diff --git a/web/src/features/dialog/components/checkbox.tsx b/web/src/features/dialog/components/checkbox.tsx new file mode 100644 index 0000000..7f87ae2 --- /dev/null +++ b/web/src/features/dialog/components/checkbox.tsx @@ -0,0 +1,24 @@ +import { Box, Checkbox } from "@chakra-ui/react"; +import { Row } from "../../../interfaces/dialog"; + +interface Props { + row: Row; + index: number; + handleChange: (value: string | boolean, index: number) => void; +} + +const CheckboxField: React.FC = (props) => { + return ( + <> + + props.handleChange(e.target.checked, props.index)} + > + {props.row.label} + + + + ); +}; + +export default CheckboxField; diff --git a/web/src/features/dialog/components/input.tsx b/web/src/features/dialog/components/input.tsx new file mode 100644 index 0000000..270f254 --- /dev/null +++ b/web/src/features/dialog/components/input.tsx @@ -0,0 +1,60 @@ +import { + Box, + InputGroup, + InputLeftElement, + InputRightElement, + Text, + Input, +} from "@chakra-ui/react"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { Row } from "../../../interfaces/dialog"; + +interface Props { + row: Row; + index: number; + handleChange: (value: string | boolean, index: number) => void; + passwordStates: boolean[]; + handlePasswordStates: (index: number) => void; +} + +const InputField: React.FC = (props) => { + return ( + <> + + {props.row.label} + + {props.row.icon && ( + } + /> + )} + props.handleChange(e.target.value, props.index)} + type={ + !props.row.password || props.passwordStates[props.index] + ? "text" + : "password" + } + /> + {props.row.password && ( + props.handlePasswordStates(props.index)} + children={ + + } + /> + )} + + + + ); +}; + +export default InputField; diff --git a/web/src/features/dialog/components/select.tsx b/web/src/features/dialog/components/select.tsx new file mode 100644 index 0000000..e3be2f1 --- /dev/null +++ b/web/src/features/dialog/components/select.tsx @@ -0,0 +1,32 @@ +import { Box, Select } from "@chakra-ui/react"; +import { Row } from "../../../interfaces/dialog"; + +interface Props { + row: Row; + index: number; + handleChange: (value: string | boolean, index: number) => void; +} + +const SelectField: React.FC = (props) => { + return ( + <> + + + + + ); +}; + +export default SelectField; diff --git a/web/src/features/menu/ContextMenu.tsx b/web/src/features/menu/ContextMenu.tsx index 2bd53af..00664b0 100644 --- a/web/src/features/menu/ContextMenu.tsx +++ b/web/src/features/menu/ContextMenu.tsx @@ -2,7 +2,7 @@ import { useNuiEvent } from "../../hooks/useNuiEvent"; import { Box, Text, Flex, ScaleFade } from "@chakra-ui/react"; import { debugData } from "../../utils/debugData"; import { useEffect, useState } from "react"; -import { ContextMenuProps } from "../../interfaces"; +import { ContextMenuProps } from "../../interfaces/context"; import Item from "./Item"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { fetchNui } from "../../utils/fetchNui"; diff --git a/web/src/features/menu/Item.tsx b/web/src/features/menu/Item.tsx index 625ffe6..dca8d4a 100644 --- a/web/src/features/menu/Item.tsx +++ b/web/src/features/menu/Item.tsx @@ -10,7 +10,7 @@ import { Spacer, } from "@chakra-ui/react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import { Option, ContextMenuProps } from "../../interfaces"; +import { Option, ContextMenuProps } from "../../interfaces/context"; import { fetchNui } from "../../utils/fetchNui"; interface DataProps { diff --git a/web/src/interfaces/index.tsx b/web/src/interfaces/context.ts similarity index 100% rename from web/src/interfaces/index.tsx rename to web/src/interfaces/context.ts diff --git a/web/src/interfaces/dialog.ts b/web/src/interfaces/dialog.ts new file mode 100644 index 0000000..8fc809f --- /dev/null +++ b/web/src/interfaces/dialog.ts @@ -0,0 +1,11 @@ +import { IconProp } from "@fortawesome/fontawesome-svg-core"; + +type RowType = "input" | "checkbox" | "select"; + +export interface Row { + type: RowType; + label: string; + options?: { value: string; label: string }[]; + password?: boolean; + icon?: IconProp; +}