From f80f48ec6c66e40bea79c3b34b72c929176b7cb5 Mon Sep 17 00:00:00 2001 From: YasinShaikh123 <123150391+YasinShaikh123@users.noreply.github.com> Date: Tue, 9 Jul 2024 18:56:11 +0530 Subject: [PATCH] investment edit --- src/Contexts/GlobalStateProvider.jsx | 24 +++- .../CreateIO/InvestmentDocument.jsx | 71 ++++++---- .../IO_Management/EditIO/InvestmentEdit.jsx | 121 ++++++++++++++++++ .../IO_Management/InvestmentDocuments.jsx | 2 +- .../IO_Management/ViewIO/InvestmentView.jsx | 78 +++++++++++ src/Pages/Master/Sponser/EditSponser.jsx | 53 ++++---- src/Pages/Master/Sponser/Sponsers.jsx | 2 +- src/Pages/Master/Sponser/ViewSponser.jsx | 2 +- 8 files changed, 289 insertions(+), 64 deletions(-) create mode 100644 src/Pages/IO_Management/EditIO/InvestmentEdit.jsx create mode 100644 src/Pages/IO_Management/ViewIO/InvestmentView.jsx diff --git a/src/Contexts/GlobalStateProvider.jsx b/src/Contexts/GlobalStateProvider.jsx index 79090a1..b58c32b 100644 --- a/src/Contexts/GlobalStateProvider.jsx +++ b/src/Contexts/GlobalStateProvider.jsx @@ -7,6 +7,8 @@ import { TbClock2 } from "react-icons/tb"; import { CiWallet } from "react-icons/ci"; import { HiOutlineReceiptPercent } from "react-icons/hi2"; import { IoMdQrScanner } from "react-icons/io"; +import { GrDocumentPdf } from "react-icons/gr"; +import { AiOutlineFileGif } from "react-icons/ai"; const getRandomDate = (start, end) => { const date = new Date( @@ -468,8 +470,22 @@ const GlobalStateProvider = ({ children }) => { updateOn: "28-Jun-24", }, ]); - - + const [create, setCreate] = useState([ + { + id: 1, + Type: , + fileName: "Investment Private Company", + document: "Investment.pdf", + status: true, + }, + { + id: 2, + Type: , + fileName: "Investment Private", + document: "Investment.pdf", + status: true, + }, + ]); const [keyMerits, setKeyMerits] = useState([ { id: 1, @@ -1507,8 +1523,8 @@ const GlobalStateProvider = ({ children }) => { setDeleteRequest, viewIO, setViewIO, - // create, - // setCreate, + create, + setCreate, keyMerits, setKeyMerits, iOArtifacts, diff --git a/src/Pages/IO_Management/CreateIO/InvestmentDocument.jsx b/src/Pages/IO_Management/CreateIO/InvestmentDocument.jsx index 8b9f946..047a85d 100644 --- a/src/Pages/IO_Management/CreateIO/InvestmentDocument.jsx +++ b/src/Pages/IO_Management/CreateIO/InvestmentDocument.jsx @@ -6,7 +6,6 @@ import { Text, Tooltip, useDisclosure, - VStack, useToast, } from "@chakra-ui/react"; import React, { useContext, useEffect, useRef, useState } from "react"; @@ -25,37 +24,35 @@ import { } from "@chakra-ui/icons"; import { GrDocumentPdf } from "react-icons/gr"; import { AiOutlineFileGif } from "react-icons/ai"; +import InvestmentView from "../ViewIO/InvestmentView"; +import InvestmentEdit from "../EditIO/InvestmentEdit"; const InvestmentDocument = ({ control, errors, enableNextTab, index }) => { - const { slideFromRight } = - useContext(GlobalStateContext); + const { slideFromRight, create, setCreate } = useContext(GlobalStateContext); const firstField = useRef(); + const secondField = useRef(); + const thirdField = useRef(); const [searchTerm, setSearchTerm] = useState(""); const [isLoading, setIsLoading] = useState(true); const [deleteAlert, setDeleteAlert] = useState(false); - const [actionId, setActionId] = useState(null); const [mouseEntered, setMouseEntered] = useState(false); const [mouseEnteredId, setMouseEnteredId] = useState(""); const { isOpen, onOpen, onClose } = useDisclosure(); + const { + isOpen: isViewOpen, + onOpen: onViewOpen, + onClose: onViewClose, + } = useDisclosure(); + const { + isOpen: isEditOpen, + onOpen: onEditOpen, + onClose: onEditClose, + } = useDisclosure(); + const [actionId, setActionId] = useState(null); const navigate = useNavigate(); const toast = useToast(); - const [create, setCreate] = useState([ - { - id: 1, - Type: , - fileName: "Investment Private Company", - document: "Investment.pdf", - status: true, - }, - { - id: 2, - Type: , - fileName: "Investment Private", - document: "Investment.pdf", - status: true, - }, - ]); + useEffect(() => { const timer = setTimeout(() => { @@ -96,6 +93,16 @@ const InvestmentDocument = ({ control, errors, enableNextTab, index }) => { setIsLoading(true); }; + const handleView = (id) => { + setActionId(id) + onViewOpen(); + }; + + const handleEdit = (id) => { + setActionId(id) + onEditOpen(); + }; + const extractedArray = filteredData.map((item, index) => ({ "Sr.no": ( { color="teal.900" fontWeight="500" className="d-flex align-items-center" - fontSize={'xl'} + fontSize={"xl"} > {item.Type} @@ -150,7 +157,7 @@ const InvestmentDocument = ({ control, errors, enableNextTab, index }) => { > + + { + const { create, setCreate } = useContext(GlobalStateContext); + const filteredObject = create?.find((item) => item?.id === id); + + const { + control, + handleSubmit, + reset, + register, + formState: { errors }, + } = useForm({ + resolver: yupResolver(investmentDocSchema), + }); + + useEffect(() => { + if (filteredObject) { + reset(filteredObject); + } + }, [id, create, reset]); + + const onSubmit = (data) => { + const updatedCreate = create.map((item) => + item.id === id ? { ...item, ...data } : item + ); + setCreate(updatedCreate); + onClose(); + }; + + return ( + + + + Edit Document + + + + File Name + + {errors.fileName && ( + + {errors.fileName.message} + + )} + + + Document + + {errors.document && ( + + {errors.document.message} + + )} + + + Type + + {errors.Type && ( + + {errors.Type.message} + + )} + + + + + + + + + + ); + }; + + export default InvestmentEdit; + \ No newline at end of file diff --git a/src/Pages/IO_Management/InvestmentDocuments.jsx b/src/Pages/IO_Management/InvestmentDocuments.jsx index a2a5d6f..0b18295 100644 --- a/src/Pages/IO_Management/InvestmentDocuments.jsx +++ b/src/Pages/IO_Management/InvestmentDocuments.jsx @@ -86,7 +86,7 @@ const InvestmentDocuments = ({ id, isOpen, onClose, firstField, create, setCreat return ; case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': case 'application/msword': - return ; + return ; case 'image/jpeg': case 'image/png': case 'image/gif': diff --git a/src/Pages/IO_Management/ViewIO/InvestmentView.jsx b/src/Pages/IO_Management/ViewIO/InvestmentView.jsx new file mode 100644 index 0000000..4adfb43 --- /dev/null +++ b/src/Pages/IO_Management/ViewIO/InvestmentView.jsx @@ -0,0 +1,78 @@ +import { + Button, + Drawer, + DrawerBody, + DrawerCloseButton, + DrawerContent, + DrawerFooter, + DrawerHeader, + FormControl, + FormLabel, + Input, + Text, + Box, +} from "@chakra-ui/react"; +import React, { useContext } from "react"; +import GlobalStateContext from "../../../Contexts/GlobalStateContext"; + +const InvestmentView = ({ isOpen, onClose, secondField, id }) => { + console.log(id); + const { create, setCreate } = useContext(GlobalStateContext); + const filteredObject = create?.find((item) => item?.id === id) + console.log(filteredObject); + return ( + + + + View Document + + <> + + File Name + {filteredObject?.fileName} + + + Document + {filteredObject?.document} + + + Type + {filteredObject?.Type} + + + + + + + + + ); +}; + +export default InvestmentView; diff --git a/src/Pages/Master/Sponser/EditSponser.jsx b/src/Pages/Master/Sponser/EditSponser.jsx index 71287d5..e1de7c5 100644 --- a/src/Pages/Master/Sponser/EditSponser.jsx +++ b/src/Pages/Master/Sponser/EditSponser.jsx @@ -46,19 +46,14 @@ const EditSponser = () => { } }, [params, sponser, reset]); - - - - if (!foundObject) { return Loading...; // or any loading indicator } - const formFields = [ { label: "Sponser name (English)", - placeHolder:" ", + placeHolder: " ", name: "sponserName", type: "text", isRequired: true, @@ -67,7 +62,7 @@ const EditSponser = () => { { label: "Sponser Name (Arabic)", name: "sponserNameArabic", - placeHolder:" ", + placeHolder: " ", type: "text", isRequired: true, arabic: true, @@ -76,7 +71,7 @@ const EditSponser = () => { { label: "Description (English)", name: "description", - placeHolder:" ", + placeHolder: " ", type: "textarea", isRequired: true, section: "Add Details", @@ -84,7 +79,7 @@ const EditSponser = () => { { label: "Description (Arabic)", name: "descriptionArabic", - placeHolder:" ", + placeHolder: " ", type: "textarea", isRequired: true, arabic: true, @@ -92,8 +87,8 @@ const EditSponser = () => { }, { label: "Address (English)", - name: "sponserAddress", - placeHolder:" ", + name: "sponserAddress", + placeHolder: " ", type: "text", isRequired: true, section: "Add Details", @@ -101,7 +96,7 @@ const EditSponser = () => { { label: "Address (Arabic)", name: "sponserAddressArabic", - placeHolder:" ", + placeHolder: " ", type: "text", isRequired: true, arabic: true, @@ -110,7 +105,7 @@ const EditSponser = () => { { label: "Bank Name (English)", name: "bankName", - placeHolder:" ", + placeHolder: " ", type: "text", isRequired: true, section: "Add Details", @@ -118,7 +113,7 @@ const EditSponser = () => { { label: "Bank Name (Arabic)", name: "bankNameArabic", - placeHolder:" ", + placeHolder: " ", type: "text", isRequired: true, arabic: true, @@ -127,7 +122,7 @@ const EditSponser = () => { { label: "Account Name (English)", name: "accountHolderName", - placeHolder:" ", + placeHolder: " ", type: "text", isRequired: true, section: "Add Details", @@ -135,7 +130,7 @@ const EditSponser = () => { { label: "Account Name (Arabic)", name: "accountHolderNameArabic", - placeHolder:" ", + placeHolder: " ", type: "text", isRequired: true, arabic: true, @@ -144,7 +139,7 @@ const EditSponser = () => { { label: "Mobile Number (English)", name: "mobileNo", - placeHolder:" ", + placeHolder: " ", type: "number", isRequired: true, section: "Add Details", @@ -152,14 +147,14 @@ const EditSponser = () => { { label: "Account Number (English)", name: "accountNumber", - placeHolder:" ", + placeHolder: " ", type: "text", isRequired: true, section: "Add Details", }, { label: "IFSC Code (English)", - placeHolder:" ", + placeHolder: " ", name: "swiftCode", type: "text", isRequired: true, @@ -167,9 +162,6 @@ const EditSponser = () => { }, ]; - - - const groupedFields = formFields.reduce((groups, field) => { const { section } = field; if (!groups[section]) { @@ -180,18 +172,17 @@ const EditSponser = () => { }, {}); const onSubmit = (data) => { -console.log(data); - } + console.log(data); + }; return ( - + ); }; diff --git a/src/Pages/Master/Sponser/Sponsers.jsx b/src/Pages/Master/Sponser/Sponsers.jsx index ba5dea9..4f2a18c 100644 --- a/src/Pages/Master/Sponser/Sponsers.jsx +++ b/src/Pages/Master/Sponser/Sponsers.jsx @@ -149,7 +149,7 @@ const Sponser = () => { { }, { label: "Sponser Name (Arabic)", - value: foundObject.sponserName, + value: foundObject.sponserName, type: "text", isRequired: true, arabic: true,