From bb108f809f20773d519c96c0792dde3183a41ca3 Mon Sep 17 00:00:00 2001 From: Md Asif Date: Wed, 25 Dec 2024 21:13:00 +0530 Subject: [PATCH] refactor: update FormInput and FormSelect components to accept props directly; add FieldsWrapper for improved layout --- src/components/FieldsWrapper.jsx | 12 ++++ src/components/FormHeader.jsx | 2 +- src/components/FormInput.jsx | 27 ++----- src/components/FormSelect.jsx | 10 ++- src/pages/AccountCreation.jsx | 36 +++++----- src/pages/ChargeEdit.jsx | 21 +++--- src/pages/ChargeManagement.jsx | 18 ++--- src/pages/CheckInOutManagement.jsx | 13 ++-- src/pages/KeySwap.jsx | 23 +++--- src/pages/LockerStatus.jsx | 20 +++--- src/pages/LockersRegistration.jsx | 111 ++++++++++++++++------------- 11 files changed, 147 insertions(+), 146 deletions(-) create mode 100644 src/components/FieldsWrapper.jsx diff --git a/src/components/FieldsWrapper.jsx b/src/components/FieldsWrapper.jsx new file mode 100644 index 0000000..25b94a4 --- /dev/null +++ b/src/components/FieldsWrapper.jsx @@ -0,0 +1,12 @@ +import PropTypes from "prop-types"; + +function FieldsWrapper({ children, className = "" }) { + return
{children}
; +} + +FieldsWrapper.propTypes = { + children: PropTypes.node, + className: PropTypes.string, +}; + +export default FieldsWrapper; diff --git a/src/components/FormHeader.jsx b/src/components/FormHeader.jsx index 6ad3d50..b3b5028 100644 --- a/src/components/FormHeader.jsx +++ b/src/components/FormHeader.jsx @@ -1,7 +1,7 @@ import PropTypes from "prop-types"; function FormHeader({ text }) { - return

{text}

; + return

{text}

; } FormHeader.propTypes = { diff --git a/src/components/FormInput.jsx b/src/components/FormInput.jsx index cc550ea..b028796 100644 --- a/src/components/FormInput.jsx +++ b/src/components/FormInput.jsx @@ -2,29 +2,15 @@ import PropTypes from "prop-types"; import { motion, AnimatePresence } from "motion/react"; import clsx from "clsx"; -function FormInput({ - value, - onChange, - placeholder, - valid = true, - maxLength = 17, - readOnly = false, - className = "", - type = "text", -}) { +function FormInput({ props, valid = true, className = "" }) { return (
{!valid && ( @@ -44,14 +30,9 @@ function FormInput({ } FormInput.propTypes = { - value: PropTypes.string.isRequired, - onChange: PropTypes.func.isRequired, - readOnly: PropTypes.bool, - className: PropTypes.string, - type: PropTypes.string, - maxLength: PropTypes.number, + props: PropTypes.object, valid: PropTypes.bool, - placeholder: PropTypes.string, + className: PropTypes.string, }; export default FormInput; diff --git a/src/components/FormSelect.jsx b/src/components/FormSelect.jsx index f779b68..ce876f8 100644 --- a/src/components/FormSelect.jsx +++ b/src/components/FormSelect.jsx @@ -3,21 +3,20 @@ import { AnimatePresence } from "motion/react"; import clsx from "clsx"; import FieldError from "./FieldError"; -function FormSelect({ value, onChange, options, className, valid = true }) { +function FormSelect({ props, valid = true, className = "", options }) { return (