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 }) => {
-