From 2afefc74425b36bc4d2a396a112cab4b51d25c24 Mon Sep 17 00:00:00 2001 From: asif Date: Thu, 26 Dec 2024 20:34:53 +0530 Subject: [PATCH] Refactored CabinetMaintenance.jsx to use FormField and FormInput --- src/pages/CabinetMaintenance.jsx | 77 +++++++++++++++----------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/src/pages/CabinetMaintenance.jsx b/src/pages/CabinetMaintenance.jsx index d5bb967..f832ce2 100644 --- a/src/pages/CabinetMaintenance.jsx +++ b/src/pages/CabinetMaintenance.jsx @@ -3,9 +3,10 @@ import { useNavigate } from "react-router-dom"; import { useTranslation } from "react-i18next"; import FormBox from "../components/FormBox"; import Button from "../components/Button"; -import { motion } from "motion/react"; -import clsx from "clsx"; -import { AnimatePresence } from "motion/react"; +import FormInput from "../components/FormInput"; +import FormSelect from "../components/FormSelect"; +import FieldsWrapper from "../components/FieldsWrapper"; +import FormField from "../components/FormField"; function CabinetMaintenace() { const navigate = useNavigate(); @@ -20,47 +21,41 @@ function CabinetMaintenace() { navigate(operation.value); }; + const formFields = [ + { + name: "value", + label: t("operation"), + options: [{ label: t("create"), value: "create" }], + type: "select", + }, + ]; + + const renderField = (field) => { + const commonProps = { + value: operation[field.name], + onChange: (e) => { + const newValues = { ...operation }; + newValues[field.name] = e.target.value; + newValues[`${field.name}Valid`] = true; + setOperation(newValues); + }, + }; + const options = field.options; + return ( + + {field.type === "input" ? ( + + ) : ( + + )} + + ); + }; + return (
-
-
- -
- - - {!operation.valid && ( - - Invalid Operation - - )} - -
-
-
+ {formFields.map(renderField)}