From d3133b0181f27855df42d8dc39a0187fd2693787 Mon Sep 17 00:00:00 2001 From: siddheshmorewdi Date: Wed, 26 Jun 2024 15:03:31 +0530 Subject: [PATCH] Exchange updated --- src/Components/CustomAlertDialog.jsx | 2 + src/Components/EmptySearchList.jsx | 4 +- src/Components/HeaderMain.jsx | 2 +- .../Master/ExchangeRate/EditExchangeRate.jsx | 186 ++++++++++++++++++ .../Master/ExchangeRate/ExchangeRate.jsx | 51 +++-- src/Pages/Master/Sponser/Sponsers.jsx | 13 +- 6 files changed, 228 insertions(+), 30 deletions(-) create mode 100644 src/Pages/Master/ExchangeRate/EditExchangeRate.jsx diff --git a/src/Components/CustomAlertDialog.jsx b/src/Components/CustomAlertDialog.jsx index af5a6a1..f2ff84b 100644 --- a/src/Components/CustomAlertDialog.jsx +++ b/src/Components/CustomAlertDialog.jsx @@ -24,6 +24,7 @@ const CustomAlertDialog = ({ isOpen, onOpen, onClose, alertHandler, isLoading, m size={"sm"} // ref={cancelRef} onClick={onClose} + rounded={'sm'} > No @@ -32,6 +33,7 @@ const CustomAlertDialog = ({ isOpen, onOpen, onClose, alertHandler, isLoading, m isLoading={isLoading} onClick={alertHandler} size={"sm"} + rounded={'sm'} colorScheme="red" ml={3} > diff --git a/src/Components/EmptySearchList.jsx b/src/Components/EmptySearchList.jsx index 9ba4cbd..dc37c9e 100644 --- a/src/Components/EmptySearchList.jsx +++ b/src/Components/EmptySearchList.jsx @@ -1,6 +1,6 @@ import { Box, Image, Text } from "@chakra-ui/react" -import EmptySearchListImage from "../assets/empty_state_empty_folder.svg" -// import EmptySearchListImage from "../assets/EmptySearchList.svg" +// import EmptySearchListImage from "../assets/empty_state_empty_folder.svg" +import EmptySearchListImage from "../assets/EmptySearchList.svg" const EmptySearchList = ({message}) => { return ( diff --git a/src/Components/HeaderMain.jsx b/src/Components/HeaderMain.jsx index 74764f2..e8664ef 100644 --- a/src/Components/HeaderMain.jsx +++ b/src/Components/HeaderMain.jsx @@ -92,7 +92,7 @@ const HeaderMain = ({ Hello, developer admin - siddhesh@rubix.com + siddhesh@tanami.com diff --git a/src/Pages/Master/ExchangeRate/EditExchangeRate.jsx b/src/Pages/Master/ExchangeRate/EditExchangeRate.jsx new file mode 100644 index 0000000..e165e52 --- /dev/null +++ b/src/Pages/Master/ExchangeRate/EditExchangeRate.jsx @@ -0,0 +1,186 @@ +import { + Box, + Button, + Drawer, + DrawerBody, + DrawerCloseButton, + DrawerContent, + DrawerFooter, + DrawerHeader, + DrawerOverlay, + FormControl, + FormLabel, + Input, + Text, + useDisclosure, +} from "@chakra-ui/react"; +import React, { useContext, useRef, useState, useEffect } from "react"; +import GlobalStateContext from "../../../Contexts/GlobalStateContext"; +import CustomAlertDialog from "../../../Components/CustomAlertDialog"; +import { FiEdit3 } from "react-icons/fi"; +import { BiMessageSquareEdit } from "react-icons/bi"; +import { TbEdit } from "react-icons/tb"; + +// Convert date to YYYY-MM-DD format +const formatDateValue = (date) => { + if (!date) return ""; + const d = new Date(date); + let month = "" + (d.getMonth() + 1); + let day = "" + d.getDate(); + const year = d.getFullYear(); + + if (month.length < 2) month = "0" + month; + if (day.length < 2) day = "0" + day; + + return [year, month, day].join("-"); +}; + +const EditExchangeRate = ({ id, setIsLoading }) => { + const btnRef = useRef(); + const { isOpen, onOpen, onClose } = useDisclosure(); + const { rateExchange, setRateExchange } = useContext(GlobalStateContext); + + const foundObject = rateExchange.find((item) => item.id === id); + + const [effectFrom, setEffectFrom] = useState(""); + const [effectTill, setEffectTill] = useState(""); + const [rate, setRate] = useState(""); + const [alert, setAlert] = useState(false); + + useEffect(() => { + if (foundObject) { + setEffectFrom(formatDateValue(foundObject.effectFrom)); + setEffectTill(formatDateValue(foundObject.effectTill)); + setRate(foundObject.rate); + } + }, [foundObject]); + + const handleSave = () => { + setIsLoading(true); + const updatedExchange = rateExchange.map((item) => + item.id === id + ? { + ...item, + effectFrom: new Date(effectFrom), + effectTill: new Date(effectTill), + rate: parseFloat(rate), + } + : item + ); + setTimeout(() => { + setRateExchange(updatedExchange); + setIsLoading(false); + setAlert(false); + onClose(); + }, 100); + setIsLoading(true); + }; + + return ( + <> + + + + + + Edit rate + + + + + From + + {foundObject?.fromCurr} + + + + To + + {foundObject?.toCurr} + + + + + + Effective from + setEffectFrom(e.target.value)} + fontSize={"sm"} + type="date" + size={"sm"} + /> + + + + Effective to + setEffectTill(e.target.value)} + type="date" + size={"sm"} + /> + + + + Rate + setRate(e.target.value)} + /> + + + + + + + + + + + + setAlert(false)} + alertHandler={handleSave} + message={"Are you sure you want to update rates?"} + /> + + ); +}; + +export default EditExchangeRate; diff --git a/src/Pages/Master/ExchangeRate/ExchangeRate.jsx b/src/Pages/Master/ExchangeRate/ExchangeRate.jsx index 40ed679..0b39321 100644 --- a/src/Pages/Master/ExchangeRate/ExchangeRate.jsx +++ b/src/Pages/Master/ExchangeRate/ExchangeRate.jsx @@ -27,6 +27,7 @@ import GlobalStateContext from "../../../Contexts/GlobalStateContext"; import CustomAlertDialog from "../../../Components/CustomAlertDialog"; import ToastBox from "../../../Components/ToastBox"; import { formatDate } from "../../../Components/Functions/UTCConvertor"; +import EditExchangeRate from "./EditExchangeRate"; const ExchangeRate = () => { const toast = useToast(); @@ -70,7 +71,7 @@ const ExchangeRate = () => { // ====================================================[Table Setup]================================================================ const tableHeadRow = [ - "Sr No.", + // "Sr No.", "From currency", "To currency", "Effective from", @@ -81,22 +82,24 @@ const ExchangeRate = () => { const extractedArray = filteredData?.map((item, index) => ({ id: item?.id, - "Sr No.": ( - - {index + 1}. - - ), + // "Sr No.": ( + // + // {index + 1}. + // + // ), "From currency": ( {item.fromCurr} @@ -106,7 +109,8 @@ const ExchangeRate = () => { justifyContent={slideFromRight ? "right" : "left"} as={"span"} color={"gray.600"} - className="d-flex align-items-center fw-bold web-text-small" + fontWeight={'600'} + className="d-flex align-items-center fw- web-text-small" > {item.toCurr} @@ -115,8 +119,9 @@ const ExchangeRate = () => { {formatDate(item.effectFrom)} @@ -125,8 +130,9 @@ const ExchangeRate = () => { {formatDate(item.effectTill)} @@ -136,16 +142,19 @@ const ExchangeRate = () => { justifyContent={slideFromRight ? "right" : "left"} as={"span"} color={"gray.600"} - className="d-flex align-items-center fw-bold web-text-small" + fontWeight={'600'} + className="d-flex align-items-center web-text-small" > {item.rate} ), Action: ( - + // + + ), })); diff --git a/src/Pages/Master/Sponser/Sponsers.jsx b/src/Pages/Master/Sponser/Sponsers.jsx index caf83f7..e5798f5 100644 --- a/src/Pages/Master/Sponser/Sponsers.jsx +++ b/src/Pages/Master/Sponser/Sponsers.jsx @@ -101,22 +101,23 @@ const Sponser = () => { "Sponser name": ( {item.sponserName} ), Address: ( - + {item.sponserAddress} ), "Mobile no": ( - + {item.mobileNo} @@ -124,7 +125,7 @@ const Sponser = () => { Status: handleUpdateStatus(item.id)} isChecked={item.status} /> @@ -142,7 +143,7 @@ const Sponser = () => { , "Created At": ( - + {formatDate(item.createdAt)}