From 17a9f4a9b139b05e0d0616a00b3845d2b9c6b004 Mon Sep 17 00:00:00 2001 From: Kartik Sharma Date: Fri, 21 Nov 2025 11:10:55 +0530 Subject: [PATCH] Implementing Project change --- src/components/Expenses/ManageExpense.jsx | 118 +++++++++++------- src/components/common/EmployeeSearchInput.jsx | 3 +- 2 files changed, 76 insertions(+), 45 deletions(-) diff --git a/src/components/Expenses/ManageExpense.jsx b/src/components/Expenses/ManageExpense.jsx index d595421d..724899c7 100644 --- a/src/components/Expenses/ManageExpense.jsx +++ b/src/components/Expenses/ManageExpense.jsx @@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { defaultExpense, ExpenseSchema } from "./ExpenseSchema"; import { formatFileSize, localToUtc } from "../../utils/appUtils"; -import { useProjectName } from "../../hooks/useProjects"; +import { useProjectName } from "../../hooks/useProjects"; import { useDispatch, useSelector } from "react-redux"; import { changeMaster } from "../../slices/localVariablesSlice"; import useMaster, { @@ -32,6 +32,8 @@ import Label from "../common/Label"; import EmployeeSearchInput from "../common/EmployeeSearchInput"; import Filelist from "./Filelist"; import { DEFAULT_CURRENCY } from "../../utils/constants"; +import SelectEmployeeServerSide, { SelectProjectField } from "../common/Forms/SelectFieldServerSide"; +import { useAllocationServiceProjectTeam } from "../../hooks/useServiceProject"; const ManageExpense = ({ closeModal, expenseToEdit = null }) => { const { @@ -40,6 +42,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { error: ExpenseErrorLoad, } = useExpense(expenseToEdit); const [expenseCategory, setExpenseCategory] = useState(); + const [selectedEmployees, setSelectedEmployees] = useState([]); const dispatch = useDispatch(); const { expenseCategories, @@ -83,11 +86,11 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { loading: StatusLoadding, error: stausError, } = useExpenseStatus(); - const { - data: employees, - isLoading: EmpLoading, - isError: isEmployeeError, - } = useEmployeesNameByProject(selectedproject); + // const { + // data: employees, + // isLoading: EmpLoading, + // isError: isEmployeeError, + // } = useEmployeesNameByProject(selectedproject); const files = watch("billAttachments"); const onFileChange = async (e) => { @@ -150,6 +153,15 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { } }; + const { mutate: AllocationTeam, isPending1 } = useAllocationServiceProjectTeam( + () => { + setSelectedEmployees([]); + setSeletingEmp({ + employee: null, + isOpen: false, + }); + } + ); useEffect(() => { if (expenseToEdit && data) { reset({ @@ -168,19 +180,19 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { currencyId: data.currency.id || DEFAULT_CURRENCY, billAttachments: data.documents ? data.documents.map((doc) => ({ - fileName: doc.fileName, - base64Data: null, - contentType: doc.contentType, - documentId: doc.documentId, - fileSize: 0, - description: "", - preSignedUrl: doc.preSignedUrl, - isActive: doc.isActive ?? true, - })) + fileName: doc.fileName, + base64Data: null, + contentType: doc.contentType, + documentId: doc.documentId, + fileSize: 0, + description: "", + preSignedUrl: doc.preSignedUrl, + isActive: doc.isActive ?? true, + })) : [], - }); + }); } - }, [data, reset, employees]); + }, [data, reset]); const { mutate: ExpenseUpdate, isPending } = useUpdateExpense(() => handleClose() ); @@ -223,7 +235,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
-
+ {/*
@@ -245,6 +257,24 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { {errors.projectId && ( {errors.projectId.message} )} +
*/} +
+ + setValue("projectId", val, { + shouldDirty: true, + shouldValidate: true, + }) + } + /> + {errors.projectId && ( + {errors.projectId.message} + )}
@@ -314,9 +344,9 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { control={control} name="paidById" projectId={null} - forAll={expenseToEdit ? true : false} + forAll={true} /> -
+
@@ -423,10 +453,10 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { {errors.gstNumber.message} )}
- + -
-
+
+
@@ -452,24 +482,24 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { {errors.currencyId.message} )}
- {expenseCategory?.noOfPersonsRequired && ( -
- - - {errors.noOfPersons && ( - - {errors.noOfPersons.message} - - )} -
- )} -
+ {expenseCategory?.noOfPersonsRequired && ( +
+ + + {errors.noOfPersons && ( + + {errors.noOfPersons.message} + + )} +
+ )} +
@@ -540,7 +570,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { (fileError?.fileSize?.message || fileError?.contentType?.message || fileError?.base64Data?.message, - fileError?.documentId?.message) + fileError?.documentId?.message) }
))} @@ -565,8 +595,8 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => { {isPending || createPending ? "Please Wait..." : expenseToEdit - ? "Update" - : "Save as Draft"} + ? "Update" + : "Save as Draft"}
diff --git a/src/components/common/EmployeeSearchInput.jsx b/src/components/common/EmployeeSearchInput.jsx index 34fdecaa..32e78bec 100644 --- a/src/components/common/EmployeeSearchInput.jsx +++ b/src/components/common/EmployeeSearchInput.jsx @@ -7,6 +7,7 @@ import Avatar from "./Avatar"; const EmployeeSearchInput = ({ control, name, + size = "sm", projectId, placeholder, forAll, @@ -46,7 +47,7 @@ const EmployeeSearchInput = ({ {