From bd461995c78ad106159178e1e22d960bfaf7b752 Mon Sep 17 00:00:00 2001 From: Md Asif Date: Tue, 24 Dec 2024 00:15:51 +0530 Subject: [PATCH] refactor: improve ChargeEdit component structure --- src/main.jsx | 9 +++++-- src/pages/ChargeEdit.jsx | 57 ++++++++++++++++++---------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/main.jsx b/src/main.jsx index cab5c4e..6a8cc5c 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -14,7 +14,8 @@ import LockerStatus from "./pages/LockerStatus.jsx"; import KeySwap from "./pages/KeySwap.jsx"; import ChargeManagement from "./pages/ChargeManagement.jsx"; import ChargeEdit from "./pages/ChargeEdit.jsx"; -import CheckInOut from "./pages/CheckInOut.jsx"; +import CheckInOutManagement from "./pages/CheckInOutManagement.jsx"; +import Placeholder from "./pages/Placeholder.jsx"; const router = createBrowserRouter([ { @@ -63,7 +64,11 @@ const router = createBrowserRouter([ }, { path: "operation/check-in-out", - element: + element: + }, + { + path: "operation/check-in-out/log", + element: } ], }, diff --git a/src/pages/ChargeEdit.jsx b/src/pages/ChargeEdit.jsx index 9c49fe0..bc65275 100644 --- a/src/pages/ChargeEdit.jsx +++ b/src/pages/ChargeEdit.jsx @@ -6,12 +6,11 @@ import FormSelect from "../components/FormSelect"; import Button from "../components/Button"; import FormBox from "../components/FormBox"; import { useTranslation } from "react-i18next"; -import { useToast } from "../hooks/useToast"; import { useLocation } from "react-router-dom"; import { lockerService } from "../services/locker.service"; -import clsx from "clsx"; -import { AnimatePresence, motion } from "motion/react"; +import { AnimatePresence } from "motion/react"; import { Pencil } from "lucide-react"; +import Notification from "../components/Notification"; function ChargeEdit() { const [chargeDetails, setChargeDetails] = useState({ @@ -29,9 +28,9 @@ function ChargeEdit() { const { setIsLoading } = useLoading(); const { t } = useTranslation(); - const showToast = useToast(); const location = useLocation(); - const { productCode, interestCategory } = location.state; + const productCode = location.state?.productCode; + const interestCategory = location.state?.interestCategory; useEffect(() => { const fetchCharges = async () => { @@ -67,6 +66,10 @@ function ChargeEdit() { fetchCharges(); }, [productCode, interestCategory, setIsLoading]); + if (!location.state) { + return <>; + } + const formFields = [ { name: "rentAmount", @@ -75,10 +78,12 @@ function ChargeEdit() { subType: "number", readOnly: !chargeDetails.rentAmountEdit, icon: { - icon: , + icon: , mode: "plain", - onClick: () => {setChargeDetails({...chargeDetails, rentAmountEdit: true})}, - } + onClick: () => { + setChargeDetails({ ...chargeDetails, rentAmountEdit: true }); + }, + }, }, { name: "penaltyAmount", @@ -87,20 +92,18 @@ function ChargeEdit() { subType: "number", readOnly: !chargeDetails.penaltyAmountEdit, icon: { - icon: , + icon: , mode: "plain", - onClick: () => {setChargeDetails({...chargeDetails, penaltyAmountEdit: true})}, - } + onClick: () => { + setChargeDetails({ ...chargeDetails, penaltyAmountEdit: true }); + }, + }, }, ]; const handleSubmit = async (e) => { e.preventDefault(); - if(!chargeDetails.rentAmountEdit && !chargeDetails.penaltyAmountEdit) { - showToast("No changes made", "warning"); - return; - } try { setIsLoading(true); const response = await lockerService.updateCharges( @@ -164,21 +167,7 @@ function ChargeEdit() { return (
- {notification.visible && ( - - {notification.message} - - )} + {notification.visible && }
{notification.type === "success" && ( @@ -188,7 +177,13 @@ function ChargeEdit() {
{formFields.map(renderField)}
-