@appcorp/fusion-storybook 0.5.15 → 0.5.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base-modules/enrollment/context.d.ts +6 -0
- package/base-modules/enrollment/context.js +69 -25
- package/base-modules/enrollment/date.d.ts +8 -0
- package/base-modules/enrollment/date.js +21 -0
- package/base-modules/enrollment/filter.js +1 -1
- package/base-modules/enrollment/form.js +55 -24
- package/base-modules/enrollment/more-actions.js +47 -10
- package/base-modules/enrollment/page.js +11 -14
- package/base-modules/enrollment/validate.d.ts +1 -0
- package/base-modules/enrollment/validate.js +3 -1
- package/base-modules/enrollment/view.js +11 -19
- package/base-modules/expense/context/expense-api-provider.js +22 -9
- package/base-modules/expense/context/shared.d.ts +35 -0
- package/base-modules/expense/context/shared.js +11 -3
- package/base-modules/expense/context/use-expense-module.d.ts +7 -1
- package/base-modules/expense/context/use-expense-module.js +58 -55
- package/base-modules/expense/filter.js +25 -57
- package/base-modules/expense/form.js +17 -74
- package/base-modules/expense/page.js +60 -29
- package/base-modules/expense/validate.d.ts +17 -11
- package/base-modules/expense/validate.js +35 -14
- package/base-modules/family/context.d.ts +13 -9
- package/base-modules/family/context.js +69 -75
- package/base-modules/family/page.js +11 -4
- package/base-modules/family/view.js +3 -2
- package/base-modules/family-member/constants.d.ts +8 -0
- package/base-modules/family-member/constants.js +12 -0
- package/base-modules/family-member/context.d.ts +12 -2
- package/base-modules/family-member/context.js +78 -81
- package/base-modules/family-member/date.d.ts +6 -0
- package/base-modules/family-member/date.js +13 -0
- package/base-modules/family-member/filter.js +1 -1
- package/base-modules/family-member/form.js +25 -2
- package/base-modules/family-member/page.js +12 -4
- package/constants.d.ts +0 -6
- package/constants.js +0 -6
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/resolve-rbac-permissions.js +5 -3
- package/base-modules/expense/more-actions.d.ts +0 -1
- package/base-modules/expense/more-actions.js +0 -265
- package/base-modules/family/more-actions.d.ts +0 -1
- package/base-modules/family/more-actions.js +0 -255
- package/base-modules/family-member/more-actions.d.ts +0 -1
- package/base-modules/family-member/more-actions.js +0 -261
|
@@ -12,6 +12,7 @@ export const VALIDATION_KEYS = {
|
|
|
12
12
|
studentProfileIdRequired: "validationEnrollmentStudentProfileIdRequired",
|
|
13
13
|
sectionIdRequired: "validationEnrollmentSectionIdRequired",
|
|
14
14
|
enrollmentDateRequired: "validationEnrollmentEnrollmentDateRequired",
|
|
15
|
+
invalidDate: "validationEnrollmentInvalidDate",
|
|
15
16
|
};
|
|
16
17
|
// ============================================================================
|
|
17
18
|
// VALIDATION SCHEMA
|
|
@@ -22,6 +23,7 @@ export const enrollmentFormValidation = z.object({
|
|
|
22
23
|
sectionId: z.string().min(1, VALIDATION_KEYS.sectionIdRequired),
|
|
23
24
|
enrollmentDate: z
|
|
24
25
|
.string()
|
|
25
|
-
.min(1, VALIDATION_KEYS.enrollmentDateRequired)
|
|
26
|
+
.min(1, VALIDATION_KEYS.enrollmentDateRequired)
|
|
27
|
+
.refine((value) => !Number.isNaN(new Date(value).getTime()), VALIDATION_KEYS.invalidDate),
|
|
26
28
|
enabled: z.boolean().optional(),
|
|
27
29
|
});
|
|
@@ -14,31 +14,23 @@ import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@app
|
|
|
14
14
|
import { Badge } from "@appcorp/shadcn/components/ui/badge";
|
|
15
15
|
import { Separator } from "@appcorp/shadcn/components/ui/separator";
|
|
16
16
|
import { BookOpen, CheckCircle2, XCircle } from "lucide-react";
|
|
17
|
-
import { DATE_FORMATS, formatDate, } from "@react-pakistan/util-functions/general/format-date";
|
|
18
17
|
import { useEnrollmentModule } from "./context";
|
|
19
|
-
import { getCachedClassesSync } from "../class/cache";
|
|
20
|
-
import { getCachedStudentProfilesSync } from "../student-profile/cache";
|
|
21
|
-
import { getCachedSectionsSync } from "../section/cache";
|
|
22
18
|
import { useTranslations } from "next-intl";
|
|
19
|
+
import { formatEnrollmentDate } from "./date";
|
|
23
20
|
// ============================================================================
|
|
24
21
|
// COMPONENT
|
|
25
22
|
// ============================================================================
|
|
26
23
|
export const EnrollmentView = memo(() => {
|
|
27
|
-
var _a, _b, _c;
|
|
28
|
-
const { state
|
|
24
|
+
var _a, _b, _c, _d;
|
|
25
|
+
const { state } = useEnrollmentModule();
|
|
26
|
+
const { class: cls, classId, enrollmentDate, enabled, section, sectionId, studentProfile, studentProfileId, } = state;
|
|
29
27
|
const t = useTranslations("enrollment");
|
|
30
|
-
|
|
31
|
-
const studentName =
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const sectionName = section
|
|
36
|
-
|
|
37
|
-
? `${section.class.code}-${section.name}`
|
|
38
|
-
: section.name
|
|
39
|
-
: (sectionId !== null && sectionId !== void 0 ? sectionId : "—");
|
|
40
|
-
return (_jsxs("div", { className: "space-y-4", children: [_jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(BookOpen, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionEnrollmentDetails") })] }), _jsx(CardDescription, { children: t("viewSectionCompleteEnrollmentInformation") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6", children: [_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStudent") }), _jsx("p", { className: "text-base", children: studentName })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formClassLabel") }), _jsx("p", { className: "text-base", children: className })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formSectionLabel") }), _jsx("p", { className: "text-base", children: sectionName })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldEnrollmentDate") }), _jsx("p", { className: "text-base", children: enrollmentDate
|
|
41
|
-
? formatDate(enrollmentDate, DATE_FORMATS.LOCALE_DATE)
|
|
42
|
-
: "—" })] })] }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(BookOpen, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewFieldStatus") })] }), _jsx(CardDescription, { children: t("viewFieldEnrollmentAvailability") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsx("div", { className: "grid grid-cols-1 gap-6", children: _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStatus") }), _jsx(Badge, { variant: enabled ? "default" : "destructive", className: "gap-1", children: enabled ? (_jsxs(_Fragment, { children: [_jsx(CheckCircle2, { className: "h-3 w-3" }), " ", t("badgeActive")] })) : (_jsxs(_Fragment, { children: [_jsx(XCircle, { className: "h-3 w-3" }), " ", t("badgeInactive")] })) })] }) }) })] })] }));
|
|
28
|
+
// The single GET includes the relations; fall back to the id.
|
|
29
|
+
const studentName = studentProfile
|
|
30
|
+
? `${(_b = (_a = studentProfile.familyMember) === null || _a === void 0 ? void 0 : _a.firstName) !== null && _b !== void 0 ? _b : ""} ${(_d = (_c = studentProfile.familyMember) === null || _c === void 0 ? void 0 : _c.lastName) !== null && _d !== void 0 ? _d : ""}`.trim() || studentProfile.studentCode
|
|
31
|
+
: studentProfileId || "—";
|
|
32
|
+
const className = cls ? `${cls.name} (${cls.code})` : classId || "—";
|
|
33
|
+
const sectionName = section ? section.name : sectionId || "—";
|
|
34
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(BookOpen, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewSectionEnrollmentDetails") })] }), _jsx(CardDescription, { children: t("viewSectionCompleteEnrollmentInformation") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-6", children: [_jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStudent") }), _jsx("p", { className: "text-base", children: studentName })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formClassLabel") }), _jsx("p", { className: "text-base", children: className })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("formSectionLabel") }), _jsx("p", { className: "text-base", children: sectionName })] }), _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldEnrollmentDate") }), _jsx("p", { className: "text-base", children: formatEnrollmentDate(enrollmentDate) })] })] }) })] }), _jsxs(Card, { children: [_jsxs(CardHeader, { className: "pb-3", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(BookOpen, { className: "text-primary h-5 w-5" }), _jsx(CardTitle, { className: "text-lg", children: t("viewFieldStatus") })] }), _jsx(CardDescription, { children: t("viewFieldEnrollmentAvailability") })] }), _jsx(Separator, {}), _jsx(CardContent, { className: "pt-6", children: _jsx("div", { className: "grid grid-cols-1 gap-6", children: _jsxs("div", { className: "space-y-1", children: [_jsx("p", { className: "text-muted-foreground text-sm font-medium", children: t("viewFieldStatus") }), _jsx(Badge, { variant: enabled ? "default" : "destructive", className: "gap-1", children: enabled ? (_jsxs(_Fragment, { children: [_jsx(CheckCircle2, { className: "h-3 w-3" }), " ", t("badgeActive")] })) : (_jsxs(_Fragment, { children: [_jsx(XCircle, { className: "h-3 w-3" }), " ", t("badgeInactive")] })) })] }) }) })] })] }));
|
|
43
35
|
});
|
|
44
36
|
EnrollmentView.displayName = "EnrollmentView";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, } from "react";
|
|
4
4
|
import { useTheme } from "next-themes";
|
|
5
5
|
import { useTranslations } from "next-intl";
|
|
6
6
|
import { isCreatedOrUpdated } from "@react-pakistan/util-functions/general/is-created-or-updated";
|
|
@@ -72,7 +72,22 @@ export const ExpenseApiProvider = ({ children, }) => {
|
|
|
72
72
|
// ==========================================================================
|
|
73
73
|
// API PARAMETERS
|
|
74
74
|
// ==========================================================================
|
|
75
|
-
const listParams = useMemo(() => (Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {}))
|
|
75
|
+
const listParams = useMemo(() => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.appliedFilterEnabled !== undefined
|
|
76
|
+
? { filterEnabled: String(state.appliedFilterEnabled) }
|
|
77
|
+
: {})), (state.appliedFilterCategory
|
|
78
|
+
? { category: state.appliedFilterCategory }
|
|
79
|
+
: {})), (state.appliedFilterStatus
|
|
80
|
+
? { status: state.appliedFilterStatus }
|
|
81
|
+
: {})), (state.appliedFilterFromDate
|
|
82
|
+
? { fromDate: state.appliedFilterFromDate }
|
|
83
|
+
: {})), (state.appliedFilterToDate
|
|
84
|
+
? { toDate: state.appliedFilterToDate }
|
|
85
|
+
: {}))), [
|
|
86
|
+
state.appliedFilterCategory,
|
|
87
|
+
state.appliedFilterEnabled,
|
|
88
|
+
state.appliedFilterFromDate,
|
|
89
|
+
state.appliedFilterStatus,
|
|
90
|
+
state.appliedFilterToDate,
|
|
76
91
|
state.currentPage,
|
|
77
92
|
state.pageLimit,
|
|
78
93
|
debouncedQuery,
|
|
@@ -100,8 +115,8 @@ export const ExpenseApiProvider = ({ children, }) => {
|
|
|
100
115
|
vendorContact: state.vendorContact || null,
|
|
101
116
|
vendorName: state.vendorName || null,
|
|
102
117
|
}), [state, schoolId]);
|
|
103
|
-
const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
104
|
-
const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
|
|
118
|
+
const byIdParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
|
|
119
|
+
const deleteParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
|
|
105
120
|
// ==========================================================================
|
|
106
121
|
// API CALLBACKS
|
|
107
122
|
// ==========================================================================
|
|
@@ -123,7 +138,6 @@ export const ExpenseApiProvider = ({ children, }) => {
|
|
|
123
138
|
}, [dispatch, showToast, t]);
|
|
124
139
|
const listFetchNowRef = useRef(null);
|
|
125
140
|
const updateCallback = useCallback(({ data, error }) => {
|
|
126
|
-
var _a;
|
|
127
141
|
if (error) {
|
|
128
142
|
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
129
143
|
return;
|
|
@@ -131,11 +145,12 @@ export const ExpenseApiProvider = ({ children, }) => {
|
|
|
131
145
|
if (data) {
|
|
132
146
|
const isCreated = isCreatedOrUpdated(data);
|
|
133
147
|
showToast(isCreated ? t("messagesExpenseCreated") : t("messagesExpenseUpdated"), TOAST_VARIANT.SUCCESS);
|
|
148
|
+
// `useModuleEntityV2` schedules the list refresh.
|
|
134
149
|
resetFormAndCloseDrawer();
|
|
135
|
-
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
136
150
|
}
|
|
137
151
|
}, [showToast, t, resetFormAndCloseDrawer]);
|
|
138
152
|
const byIdCallback = useCallback(({ data, error }) => {
|
|
153
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
139
154
|
if (error) {
|
|
140
155
|
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
141
156
|
return;
|
|
@@ -145,20 +160,18 @@ export const ExpenseApiProvider = ({ children, }) => {
|
|
|
145
160
|
dispatch({
|
|
146
161
|
type: EXPENSE_ACTION_TYPES.SET_FORM_DATA,
|
|
147
162
|
payload: {
|
|
148
|
-
form: Object.assign(Object.assign({}, expense), { expenseDate: normalizeDate(expense.expenseDate), paymentDate: normalizeDate(expense.paymentDate), paymentMethod: expense.paymentMethod || "",
|
|
163
|
+
form: Object.assign(Object.assign({}, expense), { approvedBy: (_a = expense.approvedBy) !== null && _a !== void 0 ? _a : "", description: (_b = expense.description) !== null && _b !== void 0 ? _b : "", expenseDate: normalizeDate(expense.expenseDate), invoiceNumber: (_c = expense.invoiceNumber) !== null && _c !== void 0 ? _c : "", paidBy: (_d = expense.paidBy) !== null && _d !== void 0 ? _d : "", paymentDate: normalizeDate(expense.paymentDate), paymentMethod: expense.paymentMethod || "", receiptNumber: (_e = expense.receiptNumber) !== null && _e !== void 0 ? _e : "", remarks: (_f = expense.remarks) !== null && _f !== void 0 ? _f : "", transactionId: (_g = expense.transactionId) !== null && _g !== void 0 ? _g : "", vendorContact: (_h = expense.vendorContact) !== null && _h !== void 0 ? _h : "", vendorName: (_j = expense.vendorName) !== null && _j !== void 0 ? _j : "" }),
|
|
149
164
|
},
|
|
150
165
|
});
|
|
151
166
|
}
|
|
152
167
|
}, [dispatch, showToast, t]);
|
|
153
168
|
const deleteCallback = useCallback(({ data, error }) => {
|
|
154
|
-
var _a;
|
|
155
169
|
if (error) {
|
|
156
170
|
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
157
171
|
return;
|
|
158
172
|
}
|
|
159
173
|
if (data) {
|
|
160
174
|
showToast(t("messagesExpenseDeleted"), TOAST_VARIANT.SUCCESS);
|
|
161
|
-
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
162
175
|
}
|
|
163
176
|
}, [showToast, t]);
|
|
164
177
|
// ==========================================================================
|
|
@@ -55,6 +55,13 @@ export declare const EXPENSE_ACTION_TYPES: {
|
|
|
55
55
|
filterCategory: EXPENSE_CATEGORY | "";
|
|
56
56
|
filterEnabled: boolean | undefined;
|
|
57
57
|
filterStatus: EXPENSE_STATUS | "";
|
|
58
|
+
filterFromDate: string;
|
|
59
|
+
filterToDate: string;
|
|
60
|
+
appliedFilterCategory: EXPENSE_CATEGORY | "";
|
|
61
|
+
appliedFilterEnabled: boolean | undefined;
|
|
62
|
+
appliedFilterStatus: EXPENSE_STATUS | "";
|
|
63
|
+
appliedFilterFromDate: string;
|
|
64
|
+
appliedFilterToDate: string;
|
|
58
65
|
school: SchoolBE | undefined;
|
|
59
66
|
}>, initialExpenseState: {
|
|
60
67
|
items: ExpenseBE[];
|
|
@@ -88,6 +95,13 @@ export declare const EXPENSE_ACTION_TYPES: {
|
|
|
88
95
|
filterCategory: EXPENSE_CATEGORY | "";
|
|
89
96
|
filterEnabled: boolean | undefined;
|
|
90
97
|
filterStatus: EXPENSE_STATUS | "";
|
|
98
|
+
filterFromDate: string;
|
|
99
|
+
filterToDate: string;
|
|
100
|
+
appliedFilterCategory: EXPENSE_CATEGORY | "";
|
|
101
|
+
appliedFilterEnabled: boolean | undefined;
|
|
102
|
+
appliedFilterStatus: EXPENSE_STATUS | "";
|
|
103
|
+
appliedFilterFromDate: string;
|
|
104
|
+
appliedFilterToDate: string;
|
|
91
105
|
school: SchoolBE | undefined;
|
|
92
106
|
}, ExpenseProvider: import("react").FC<{
|
|
93
107
|
children: React.ReactNode;
|
|
@@ -123,6 +137,13 @@ export declare const EXPENSE_ACTION_TYPES: {
|
|
|
123
137
|
filterCategory: EXPENSE_CATEGORY | "";
|
|
124
138
|
filterEnabled: boolean | undefined;
|
|
125
139
|
filterStatus: EXPENSE_STATUS | "";
|
|
140
|
+
filterFromDate: string;
|
|
141
|
+
filterToDate: string;
|
|
142
|
+
appliedFilterCategory: EXPENSE_CATEGORY | "";
|
|
143
|
+
appliedFilterEnabled: boolean | undefined;
|
|
144
|
+
appliedFilterStatus: EXPENSE_STATUS | "";
|
|
145
|
+
appliedFilterFromDate: string;
|
|
146
|
+
appliedFilterToDate: string;
|
|
126
147
|
school: SchoolBE | undefined;
|
|
127
148
|
}, action: any) => {
|
|
128
149
|
items: ExpenseBE[];
|
|
@@ -156,6 +177,13 @@ export declare const EXPENSE_ACTION_TYPES: {
|
|
|
156
177
|
filterCategory: EXPENSE_CATEGORY | "";
|
|
157
178
|
filterEnabled: boolean | undefined;
|
|
158
179
|
filterStatus: EXPENSE_STATUS | "";
|
|
180
|
+
filterFromDate: string;
|
|
181
|
+
filterToDate: string;
|
|
182
|
+
appliedFilterCategory: EXPENSE_CATEGORY | "";
|
|
183
|
+
appliedFilterEnabled: boolean | undefined;
|
|
184
|
+
appliedFilterStatus: EXPENSE_STATUS | "";
|
|
185
|
+
appliedFilterFromDate: string;
|
|
186
|
+
appliedFilterToDate: string;
|
|
159
187
|
school: SchoolBE | undefined;
|
|
160
188
|
}, useExpenseContext: () => import("@react-pakistan/util-functions/factory/generic-module-factory").GenericModuleContextWithHandlers<{
|
|
161
189
|
items: ExpenseBE[];
|
|
@@ -189,5 +217,12 @@ export declare const EXPENSE_ACTION_TYPES: {
|
|
|
189
217
|
filterCategory: EXPENSE_CATEGORY | "";
|
|
190
218
|
filterEnabled: boolean | undefined;
|
|
191
219
|
filterStatus: EXPENSE_STATUS | "";
|
|
220
|
+
filterFromDate: string;
|
|
221
|
+
filterToDate: string;
|
|
222
|
+
appliedFilterCategory: EXPENSE_CATEGORY | "";
|
|
223
|
+
appliedFilterEnabled: boolean | undefined;
|
|
224
|
+
appliedFilterStatus: EXPENSE_STATUS | "";
|
|
225
|
+
appliedFilterFromDate: string;
|
|
226
|
+
appliedFilterToDate: string;
|
|
192
227
|
school: SchoolBE | undefined;
|
|
193
228
|
}>;
|
|
@@ -39,7 +39,7 @@ const expenseConfig = {
|
|
|
39
39
|
id: "",
|
|
40
40
|
invoiceNumber: "",
|
|
41
41
|
paidBy: "",
|
|
42
|
-
paymentDate:
|
|
42
|
+
paymentDate: "",
|
|
43
43
|
paymentMethod: PAYMENT_METHOD.CASH,
|
|
44
44
|
receiptNumber: "",
|
|
45
45
|
remarks: "",
|
|
@@ -49,10 +49,18 @@ const expenseConfig = {
|
|
|
49
49
|
transactionId: "",
|
|
50
50
|
vendorContact: "",
|
|
51
51
|
vendorName: "",
|
|
52
|
-
//
|
|
52
|
+
// Staged filters: the drawer edits `filter*`; Apply copies them to
|
|
53
|
+
// `appliedFilter*`, which drives the request.
|
|
53
54
|
filterCategory: "",
|
|
54
|
-
filterEnabled:
|
|
55
|
+
filterEnabled: true,
|
|
55
56
|
filterStatus: "",
|
|
57
|
+
filterFromDate: "",
|
|
58
|
+
filterToDate: "",
|
|
59
|
+
appliedFilterCategory: "",
|
|
60
|
+
appliedFilterEnabled: true,
|
|
61
|
+
appliedFilterStatus: "",
|
|
62
|
+
appliedFilterFromDate: "",
|
|
63
|
+
appliedFilterToDate: "",
|
|
56
64
|
// Relations
|
|
57
65
|
school: undefined,
|
|
58
66
|
},
|
|
@@ -11,7 +11,6 @@ export declare const useExpenseModule: () => {
|
|
|
11
11
|
handleDelete: (row?: TableRow) => void;
|
|
12
12
|
handleEdit: (row?: TableRow) => void;
|
|
13
13
|
handleFilters: () => void;
|
|
14
|
-
handleMoreActions: () => void;
|
|
15
14
|
handlePageChange: (page: number | unknown) => void;
|
|
16
15
|
handlePageLimitChange: (k: string, value: object) => void;
|
|
17
16
|
handleSearch: (query: string) => void;
|
|
@@ -60,6 +59,13 @@ export declare const useExpenseModule: () => {
|
|
|
60
59
|
filterCategory: import("../../../types").EXPENSE_CATEGORY | "";
|
|
61
60
|
filterEnabled: boolean | undefined;
|
|
62
61
|
filterStatus: import("../../../types").EXPENSE_STATUS | "";
|
|
62
|
+
filterFromDate: string;
|
|
63
|
+
filterToDate: string;
|
|
64
|
+
appliedFilterCategory: import("../../../types").EXPENSE_CATEGORY | "";
|
|
65
|
+
appliedFilterEnabled: boolean | undefined;
|
|
66
|
+
appliedFilterStatus: import("../../../types").EXPENSE_STATUS | "";
|
|
67
|
+
appliedFilterFromDate: string;
|
|
68
|
+
appliedFilterToDate: string;
|
|
63
69
|
school: import("../../../types").SchoolBE | undefined;
|
|
64
70
|
};
|
|
65
71
|
dispatch: React.Dispatch<any>;
|
|
@@ -79,12 +79,49 @@ export const useExpenseModule = () => {
|
|
|
79
79
|
const closeDrawer = useCallback(() => {
|
|
80
80
|
resetFormAndCloseDrawer();
|
|
81
81
|
}, [resetFormAndCloseDrawer]);
|
|
82
|
+
const resetFormFields = useCallback(() => {
|
|
83
|
+
dispatch({
|
|
84
|
+
type: EXPENSE_ACTION_TYPES.SET_FORM_DATA,
|
|
85
|
+
payload: {
|
|
86
|
+
form: {
|
|
87
|
+
amount: 0,
|
|
88
|
+
approvedBy: "",
|
|
89
|
+
attachments: [],
|
|
90
|
+
category: "",
|
|
91
|
+
description: "",
|
|
92
|
+
enabled: true,
|
|
93
|
+
expenseDate: new Date().toISOString().slice(0, 10),
|
|
94
|
+
id: "",
|
|
95
|
+
invoiceNumber: "",
|
|
96
|
+
paidBy: "",
|
|
97
|
+
paymentDate: "",
|
|
98
|
+
paymentMethod: "",
|
|
99
|
+
receiptNumber: "",
|
|
100
|
+
remarks: "",
|
|
101
|
+
status: "",
|
|
102
|
+
title: "",
|
|
103
|
+
transactionId: "",
|
|
104
|
+
vendorContact: "",
|
|
105
|
+
vendorName: "",
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
dispatch({
|
|
110
|
+
type: EXPENSE_ACTION_TYPES.SET_ERRORS,
|
|
111
|
+
payload: { errors: {} },
|
|
112
|
+
});
|
|
113
|
+
dispatch({
|
|
114
|
+
type: EXPENSE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
115
|
+
payload: { disabled: false },
|
|
116
|
+
});
|
|
117
|
+
}, [dispatch]);
|
|
82
118
|
const handleCreate = useCallback(() => {
|
|
119
|
+
resetFormFields();
|
|
83
120
|
dispatch({
|
|
84
121
|
type: EXPENSE_ACTION_TYPES.SET_DRAWER,
|
|
85
122
|
payload: { drawer: EXPENSE_DRAWER.FORM_DRAWER },
|
|
86
123
|
});
|
|
87
|
-
}, [dispatch]);
|
|
124
|
+
}, [dispatch, resetFormFields]);
|
|
88
125
|
const handleView = useCallback((row) => {
|
|
89
126
|
byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
|
|
90
127
|
dispatch({
|
|
@@ -103,21 +140,15 @@ export const useExpenseModule = () => {
|
|
|
103
140
|
if (!confirm(t("messagesDeleteConfirmation")))
|
|
104
141
|
return;
|
|
105
142
|
deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
|
|
106
|
-
body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
|
|
143
|
+
body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id, schoolId }),
|
|
107
144
|
});
|
|
108
|
-
}, [deleteFetchNow, t]);
|
|
145
|
+
}, [deleteFetchNow, schoolId, t]);
|
|
109
146
|
const handleFilters = useCallback(() => {
|
|
110
147
|
dispatch({
|
|
111
148
|
type: EXPENSE_ACTION_TYPES.SET_DRAWER,
|
|
112
149
|
payload: { drawer: EXPENSE_DRAWER.FILTER_DRAWER },
|
|
113
150
|
});
|
|
114
151
|
}, [dispatch]);
|
|
115
|
-
const handleMoreActions = useCallback(() => {
|
|
116
|
-
dispatch({
|
|
117
|
-
type: EXPENSE_ACTION_TYPES.SET_DRAWER,
|
|
118
|
-
payload: { drawer: EXPENSE_DRAWER.MORE_ACTIONS_DRAWER },
|
|
119
|
-
});
|
|
120
|
-
}, [dispatch]);
|
|
121
152
|
const handlePageChange = useCallback((page) => {
|
|
122
153
|
const nextPage = typeof page === "number" ? page : state.currentPage + 1;
|
|
123
154
|
dispatch({
|
|
@@ -149,61 +180,39 @@ export const useExpenseModule = () => {
|
|
|
149
180
|
});
|
|
150
181
|
}, [dispatch]);
|
|
151
182
|
const applyFilters = useCallback(() => {
|
|
152
|
-
closeDrawer();
|
|
153
|
-
dispatch({
|
|
154
|
-
type: EXPENSE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
155
|
-
payload: { key: "filterCategory", value: state.filterCategory },
|
|
156
|
-
});
|
|
157
183
|
dispatch({
|
|
158
|
-
type: EXPENSE_ACTION_TYPES.
|
|
159
|
-
payload: {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
184
|
+
type: EXPENSE_ACTION_TYPES.SET_FILTERS,
|
|
185
|
+
payload: {
|
|
186
|
+
filters: {
|
|
187
|
+
appliedFilterEnabled: state.filterEnabled,
|
|
188
|
+
appliedFilterCategory: state.filterCategory,
|
|
189
|
+
appliedFilterStatus: state.filterStatus,
|
|
190
|
+
appliedFilterFromDate: state.filterFromDate,
|
|
191
|
+
appliedFilterToDate: state.filterToDate,
|
|
192
|
+
},
|
|
193
|
+
},
|
|
164
194
|
});
|
|
165
195
|
dispatch({
|
|
166
196
|
type: EXPENSE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
167
197
|
payload: { currentPage: 1 },
|
|
168
198
|
});
|
|
169
|
-
|
|
170
|
-
params: Object.assign(Object.assign(Object.assign({ currentPage: 1, pageLimit: state.pageLimit, schoolId }, (state.filterCategory && { filterCategory: state.filterCategory })), (state.filterStatus && { filterStatus: state.filterStatus })), (state.filterEnabled !== undefined && {
|
|
171
|
-
filterEnabled: state.filterEnabled,
|
|
172
|
-
})),
|
|
173
|
-
});
|
|
199
|
+
closeDrawer();
|
|
174
200
|
}, [
|
|
175
201
|
closeDrawer,
|
|
176
202
|
dispatch,
|
|
177
|
-
listFetchNow,
|
|
178
|
-
schoolId,
|
|
179
203
|
state.filterCategory,
|
|
180
204
|
state.filterEnabled,
|
|
205
|
+
state.filterFromDate,
|
|
181
206
|
state.filterStatus,
|
|
182
|
-
state.
|
|
207
|
+
state.filterToDate,
|
|
183
208
|
]);
|
|
184
209
|
const clearFilters = useCallback(() => {
|
|
210
|
+
dispatch({ type: EXPENSE_ACTION_TYPES.RESET_FORM });
|
|
185
211
|
dispatch({
|
|
186
212
|
type: EXPENSE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
187
213
|
payload: { currentPage: 1 },
|
|
188
214
|
});
|
|
189
|
-
|
|
190
|
-
type: EXPENSE_ACTION_TYPES.SET_FILTERS,
|
|
191
|
-
payload: {
|
|
192
|
-
filters: {
|
|
193
|
-
filterEnabled: undefined,
|
|
194
|
-
filterCategory: "",
|
|
195
|
-
filterStatus: "",
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
listFetchNow(undefined, {
|
|
200
|
-
params: {
|
|
201
|
-
currentPage: 1,
|
|
202
|
-
pageLimit: state.pageLimit,
|
|
203
|
-
schoolId,
|
|
204
|
-
},
|
|
205
|
-
});
|
|
206
|
-
}, [dispatch, listFetchNow, state.pageLimit, schoolId]);
|
|
215
|
+
}, [dispatch]);
|
|
207
216
|
// ============================================================================
|
|
208
217
|
// 1.4.5 NETWORK ACTIONS
|
|
209
218
|
// ============================================================================
|
|
@@ -237,12 +246,6 @@ export const useExpenseModule = () => {
|
|
|
237
246
|
// 1.4.6 HEADER & ROW ACTIONS
|
|
238
247
|
// ============================================================================
|
|
239
248
|
const headerActions = useMemo(() => [
|
|
240
|
-
{
|
|
241
|
-
enabled: true,
|
|
242
|
-
handleOnClick: handleMoreActions,
|
|
243
|
-
label: t("actionsButtonMoreActions"),
|
|
244
|
-
order: 0,
|
|
245
|
-
},
|
|
246
249
|
{
|
|
247
250
|
enabled: true,
|
|
248
251
|
handleOnClick: handleFilters,
|
|
@@ -255,7 +258,7 @@ export const useExpenseModule = () => {
|
|
|
255
258
|
label: t("actionsButtonAdd"),
|
|
256
259
|
order: 2,
|
|
257
260
|
},
|
|
258
|
-
], [handleCreate, handleFilters,
|
|
261
|
+
], [handleCreate, handleFilters, t]);
|
|
259
262
|
const rowActions = useMemo(() => [
|
|
260
263
|
{
|
|
261
264
|
enabled: true,
|
|
@@ -270,10 +273,11 @@ export const useExpenseModule = () => {
|
|
|
270
273
|
order: 2,
|
|
271
274
|
},
|
|
272
275
|
{
|
|
273
|
-
enabled:
|
|
276
|
+
enabled: (row) => (row === null || row === void 0 ? void 0 : row.enabled) === true,
|
|
274
277
|
handleOnClick: handleDelete,
|
|
275
278
|
label: t("actionsButtonDelete"),
|
|
276
279
|
order: 3,
|
|
280
|
+
variant: "destructive",
|
|
277
281
|
},
|
|
278
282
|
], [handleDelete, handleEdit, handleView, t]);
|
|
279
283
|
// ============================================================================
|
|
@@ -290,7 +294,6 @@ export const useExpenseModule = () => {
|
|
|
290
294
|
handleDelete,
|
|
291
295
|
handleEdit,
|
|
292
296
|
handleFilters,
|
|
293
|
-
handleMoreActions,
|
|
294
297
|
handlePageChange,
|
|
295
298
|
handlePageLimitChange,
|
|
296
299
|
handleSearch,
|
|
@@ -3,18 +3,18 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
/**
|
|
4
4
|
* Expense Filter
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* Staged filters: record state, category, status and date range. Applied by
|
|
7
|
+
* the drawer footer.
|
|
8
8
|
*/
|
|
9
|
+
import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
|
|
10
|
+
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
9
11
|
import { EnhancedRadio } from "@appcorp/shadcn/components/enhanced-radio";
|
|
10
|
-
import { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox";
|
|
11
12
|
import { useExpenseModule } from "./context";
|
|
12
13
|
import { EXPENSE_CATEGORY_OPTIONS, EXPENSE_STATUS_OPTIONS } from "./constants";
|
|
13
|
-
import { EXPENSE_API_ROUTES } from "../../constants";
|
|
14
14
|
import { useTranslations } from "next-intl";
|
|
15
15
|
export const ExpenseFilter = () => {
|
|
16
16
|
const { state, handleChange } = useExpenseModule();
|
|
17
|
-
const { filterCategory, filterEnabled, filterStatus } = state;
|
|
17
|
+
const { filterCategory, filterEnabled, filterFromDate, filterStatus, filterToDate, } = state;
|
|
18
18
|
const t = useTranslations("expense");
|
|
19
19
|
const categoryLabelMap = {
|
|
20
20
|
SALARY: t("formOptionSalary"),
|
|
@@ -44,56 +44,24 @@ export const ExpenseFilter = () => {
|
|
|
44
44
|
: filterEnabled
|
|
45
45
|
? "true"
|
|
46
46
|
: "false";
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
value: filterCategory || "",
|
|
68
|
-
});
|
|
69
|
-
const { enhancedComboboxElement: filterStatusCombo } = useEnhancedCombobox({
|
|
70
|
-
emptyText: t("filterNoStatusFoundLabel"),
|
|
71
|
-
id: "filterStatus",
|
|
72
|
-
info: t("filterByStatus"),
|
|
73
|
-
label: t("filterStatusLabel"),
|
|
74
|
-
onValueChange: (value) => handleChange("filterStatus", value),
|
|
75
|
-
options: EXPENSE_STATUS_OPTIONS.map((opt) => ({
|
|
76
|
-
value: opt.value,
|
|
77
|
-
label: statusLabelMap[opt.value] || opt.label,
|
|
78
|
-
})),
|
|
79
|
-
placeholder: t("filterAllStatusesLabel"),
|
|
80
|
-
searchEndpoint: EXPENSE_API_ROUTES.UNIT,
|
|
81
|
-
searchPlaceholder: t("filterSearchStatusLabel"),
|
|
82
|
-
formatSearchResult: (item) => {
|
|
83
|
-
var _a, _b;
|
|
84
|
-
return ({
|
|
85
|
-
label: String((_a = item.label) !== null && _a !== void 0 ? _a : ""),
|
|
86
|
-
value: String((_b = item.value) !== null && _b !== void 0 ? _b : ""),
|
|
87
|
-
});
|
|
88
|
-
},
|
|
89
|
-
value: filterStatus || "",
|
|
90
|
-
});
|
|
91
|
-
return (_jsx("div", { className: "space-y-4", children: _jsxs("div", { className: "grid grid-cols-1 gap-4", children: [filterCategoryCombo, filterStatusCombo, _jsx(EnhancedRadio, { label: t("filterOptionEnabled"), name: "filterEnabled", value: filterEnabledValue, options: [
|
|
92
|
-
{ label: t("filterOptionAll"), value: "undefined" },
|
|
93
|
-
{ label: t("filterOptionEnabled"), value: "true" },
|
|
94
|
-
{ label: t("filterOptionDisabled"), value: "false" },
|
|
95
|
-
], onValueChange: (next) => {
|
|
96
|
-
const parsed = next === "true" ? true : next === "false" ? false : undefined;
|
|
97
|
-
handleChange("filterEnabled", parsed);
|
|
98
|
-
} })] }) }));
|
|
47
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedCombobox, { emptyText: t("filterAllCategoriesLabel"), id: "filterCategory", info: t("filterByCategory"), label: t("filterCategoryLabel"), onValueChange: (value) => handleChange("filterCategory", value || undefined), options: [
|
|
48
|
+
{ value: "", label: t("filterAllCategoriesLabel") },
|
|
49
|
+
...EXPENSE_CATEGORY_OPTIONS.map((opt) => ({
|
|
50
|
+
value: opt.value,
|
|
51
|
+
label: categoryLabelMap[opt.value] || opt.label,
|
|
52
|
+
})),
|
|
53
|
+
], placeholder: t("filterAllCategoriesLabel"), searchPlaceholder: t("filterAllCategoriesLabel"), value: filterCategory || "" }), _jsx(EnhancedCombobox, { emptyText: t("filterAllStatusesLabel"), id: "filterStatus", info: t("filterByStatus"), label: t("filterStatusLabel"), onValueChange: (value) => handleChange("filterStatus", value || undefined), options: [
|
|
54
|
+
{ value: "", label: t("filterAllStatusesLabel") },
|
|
55
|
+
...EXPENSE_STATUS_OPTIONS.map((opt) => ({
|
|
56
|
+
value: opt.value,
|
|
57
|
+
label: statusLabelMap[opt.value] || opt.label,
|
|
58
|
+
})),
|
|
59
|
+
], placeholder: t("filterAllStatusesLabel"), searchPlaceholder: t("filterAllStatusesLabel"), value: filterStatus || "" }), _jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsx(EnhancedInput, { id: "filterFromDate", info: t("filterFromDateInfo"), label: t("filterFromDateLabel"), max: filterToDate || undefined, onChange: (e) => handleChange("filterFromDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: filterFromDate || "" }), _jsx(EnhancedInput, { id: "filterToDate", info: t("filterToDateInfo"), label: t("filterToDateLabel"), min: filterFromDate || undefined, onChange: (e) => handleChange("filterToDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, type: "date", value: filterToDate || "" })] }), _jsx(EnhancedRadio, { label: t("filterRecordStateLabel"), name: "filterEnabled", value: filterEnabledValue, options: [
|
|
60
|
+
{ label: t("filterOptionAll"), value: "undefined" },
|
|
61
|
+
{ label: t("filterOptionEnabled"), value: "true" },
|
|
62
|
+
{ label: t("filterOptionDisabled"), value: "false" },
|
|
63
|
+
], onValueChange: (next) => {
|
|
64
|
+
const parsed = next === "true" ? true : next === "false" ? false : undefined;
|
|
65
|
+
handleChange("filterEnabled", parsed);
|
|
66
|
+
} })] }));
|
|
99
67
|
};
|