From 35f221038dfd4100a27a343f4e4b635d6107daca Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Fri, 1 Aug 2025 00:42:51 +0530 Subject: [PATCH] added expenses Reimburse --- .../Expenses/ExpenseFilterPanel.jsx | 31 +- src/components/Expenses/ExpenseSchema.js | 56 ++- src/components/Expenses/ManageExpense.jsx | 24 +- src/components/Expenses/ViewExpense.jsx | 420 ++++++++++++------ src/components/common/EmployeeSearchInput.jsx | 85 ++++ src/components/common/Error.jsx | 20 + src/hooks/useEmployees.js | 146 +++--- src/hooks/useExpense.js | 68 +-- src/pages/Expense/ExpensePage.jsx | 169 +++---- src/repositories/EmployeeRepository.jsx | 19 +- src/utils/axiosClient.jsx | 2 +- 11 files changed, 657 insertions(+), 383 deletions(-) create mode 100644 src/components/common/EmployeeSearchInput.jsx create mode 100644 src/components/common/Error.jsx diff --git a/src/components/Expenses/ExpenseFilterPanel.jsx b/src/components/Expenses/ExpenseFilterPanel.jsx index bfe67a95..db5d5c0a 100644 --- a/src/components/Expenses/ExpenseFilterPanel.jsx +++ b/src/components/Expenses/ExpenseFilterPanel.jsx @@ -73,21 +73,6 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => { return ( <> -
- - -
@@ -174,6 +159,21 @@ const ExpenseFilterPanel = ({ onApply, handleGroupBy }) => { +
+ + +
+ ); }; diff --git a/src/components/Expenses/ExpenseSchema.js b/src/components/Expenses/ExpenseSchema.js index c74bcd38..c3b84148 100644 --- a/src/components/Expenses/ExpenseSchema.js +++ b/src/components/Expenses/ExpenseSchema.js @@ -25,7 +25,6 @@ export const ExpenseSchema = (expenseTypes) => { const selected = new Date(val); const today = new Date(); - // Set both to midnight to avoid time-related issues selected.setHours(0, 0, 0, 0); today.setHours(0, 0, 0, 0); @@ -65,9 +64,7 @@ export const ExpenseSchema = (expenseTypes) => { }) ) .nonempty({ message: "At least one file attachment is required" }), - reimburseTransactionId: z.string().optional(), - reimburseDate: z.string().optional(), - reimburseById: z.string().optional(), + }) .refine( @@ -132,10 +129,53 @@ export const defaultExpense = { billAttachments: [], }; -export const ActionSchema = z.object({ - comment: z.string().min(1, { message: "Please leave comment" }), - selectedStatus: z.string().min(1, { message: "Please select a status" }), -}); + +export const ExpenseActionScheam = (isReimbursement = false) => { + return z + .object({ + comment: z.string().min(1, { message: "Please leave comment" }), + statusId: z.string().min(1, { message: "Please select a status" }), + reimburseTransactionId: z.string().nullable().optional(), + reimburseDate: z.string().nullable().optional(), + reimburseById: z.string().nullable().optional(), + }) + .superRefine((data, ctx) => { + if (isReimbursement) { + if (!data.reimburseTransactionId?.trim()) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: ["reimburseTransactionId"], + message: "Reimburse Transaction ID is required", + }); + } + if (!data.reimburseDate) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: ["reimburseDate"], + message: "Reimburse Date is required", + }); + } + if (!data.reimburseById) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + path: ["reimburseById"], + message: "Reimburse By is required", + }); + } + } + }); +}; + + export const defaultActionValues = { + comment: "", + statusId: "", + + reimburseTransactionId: null, + reimburseDate: null, + reimburseById: null, +}; + + export const SearchSchema = z.object({ projectIds: z.array(z.string()).optional(), diff --git a/src/components/Expenses/ManageExpense.jsx b/src/components/Expenses/ManageExpense.jsx index 4a95e114..bda9dd8b 100644 --- a/src/components/Expenses/ManageExpense.jsx +++ b/src/components/Expenses/ManageExpense.jsx @@ -206,7 +206,7 @@ const ManageExpense = ({ closeModal, expenseToEdit = null }) => {
-