@appcorp/fusion-storybook 0.5.9 → 0.5.13
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/attendance/context/use-attendance-module.d.ts +60 -0
- package/base-modules/attendance/context/use-attendance-module.js +449 -0
- package/base-modules/attendance/context.d.ts +36 -52
- package/base-modules/attendance/context.js +22 -376
- package/base-modules/attendance/date.d.ts +10 -0
- package/base-modules/attendance/date.js +23 -0
- package/base-modules/attendance/filter.js +22 -6
- package/base-modules/attendance/form.js +53 -42
- package/base-modules/attendance/more-actions.js +10 -233
- package/base-modules/attendance/page.js +45 -31
- package/base-modules/attendance/validate.d.ts +3 -1
- package/base-modules/attendance/validate.js +7 -2
- package/base-modules/attendance/view.js +18 -9
- package/base-modules/campus/context/use-campus-module.d.ts +57 -0
- package/base-modules/campus/context/use-campus-module.js +447 -0
- package/base-modules/campus/context.d.ts +21 -54
- package/base-modules/campus/context.js +18 -442
- package/base-modules/campus/filter.js +1 -1
- package/base-modules/campus/form.js +6 -4
- package/base-modules/campus/page.d.ts +0 -2
- package/base-modules/campus/page.js +10 -18
- package/base-modules/campus/validate.js +4 -1
- package/base-modules/campus/view.js +2 -2
- package/constants.d.ts +3 -3
- package/constants.js +0 -2
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/user-management.d.ts +0 -1
- package/utils/resolve-rbac-permissions.js +5 -4
- package/base-modules/campus/more-actions.d.ts +0 -1
- package/base-modules/campus/more-actions.js +0 -40
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type RowAction, type TableRow } from "@appcorp/shadcn/components/enhanced-table";
|
|
2
|
+
import { AttendanceBE, ATTENDANCE_STATUS } from "../../../type";
|
|
3
|
+
export declare const useAttendanceModule: () => {
|
|
4
|
+
applyFilters: () => void;
|
|
5
|
+
byIdLoading: boolean;
|
|
6
|
+
clearFilters: () => void;
|
|
7
|
+
clearSearch: () => void;
|
|
8
|
+
closeDrawer: () => void;
|
|
9
|
+
deleteLoading: boolean;
|
|
10
|
+
handleChange: (field: string, value: string | number | boolean | undefined) => void;
|
|
11
|
+
handleCreate: () => void;
|
|
12
|
+
handleDelete: (row?: TableRow) => void;
|
|
13
|
+
handleEdit: (row?: TableRow) => void;
|
|
14
|
+
handleFilters: () => void;
|
|
15
|
+
handleMoreActions: () => void;
|
|
16
|
+
handlePageChange: (pageOrEvent?: unknown) => void;
|
|
17
|
+
handlePageLimitChange: (k: string, value: object) => void;
|
|
18
|
+
handleSearch: (query: string) => void;
|
|
19
|
+
handleSubmit: () => void;
|
|
20
|
+
handleView: (row?: TableRow) => void;
|
|
21
|
+
headerActions: {
|
|
22
|
+
enabled: boolean;
|
|
23
|
+
handleOnClick: () => void;
|
|
24
|
+
label: string;
|
|
25
|
+
order: number;
|
|
26
|
+
}[];
|
|
27
|
+
listFetchNow: (url?: string, config?: import("@react-pakistan/util-functions/hooks/use-fetch").FetchConfig) => void;
|
|
28
|
+
listLoading: boolean;
|
|
29
|
+
rowActions: RowAction[];
|
|
30
|
+
updateLoading: boolean;
|
|
31
|
+
handleCloseDrawer?: () => void;
|
|
32
|
+
state: {
|
|
33
|
+
items: AttendanceBE[];
|
|
34
|
+
count: number;
|
|
35
|
+
currentPage: number;
|
|
36
|
+
pageLimit: number;
|
|
37
|
+
searchQuery: string;
|
|
38
|
+
disableSaveButton: boolean;
|
|
39
|
+
drawer: string | null;
|
|
40
|
+
date: string;
|
|
41
|
+
enabled: boolean;
|
|
42
|
+
errors: Record<string, string>;
|
|
43
|
+
filterEnabled: boolean | undefined;
|
|
44
|
+
filterStatus: string | undefined;
|
|
45
|
+
filterStartDate: string | undefined;
|
|
46
|
+
filterEndDate: string | undefined;
|
|
47
|
+
appliedFilterEnabled: boolean | undefined;
|
|
48
|
+
appliedFilterStatus: string | undefined;
|
|
49
|
+
appliedFilterStartDate: string | undefined;
|
|
50
|
+
appliedFilterEndDate: string | undefined;
|
|
51
|
+
id: string;
|
|
52
|
+
remarks: string;
|
|
53
|
+
schoolId: string;
|
|
54
|
+
status: ATTENDANCE_STATUS;
|
|
55
|
+
studentProfileId: string;
|
|
56
|
+
school: import("../../../types").SchoolBE | undefined;
|
|
57
|
+
studentProfile: import("../../../types").StudentProfileBE | undefined;
|
|
58
|
+
};
|
|
59
|
+
dispatch: React.Dispatch<any>;
|
|
60
|
+
};
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Attendance module business logic.
|
|
15
|
+
*
|
|
16
|
+
* Lives beside the module config so it can be unit-tested without pulling in
|
|
17
|
+
* the page/components (and their ESM-only UI package).
|
|
18
|
+
*/
|
|
19
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
20
|
+
import { useTheme } from "next-themes";
|
|
21
|
+
import { useTranslations } from "next-intl";
|
|
22
|
+
import { isCreatedOrUpdated } from "@react-pakistan/util-functions/general/is-created-or-updated";
|
|
23
|
+
import { validateForm } from "@react-pakistan/util-functions/general/validate-form";
|
|
24
|
+
import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
|
|
25
|
+
import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
|
|
26
|
+
import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
|
|
27
|
+
import { ATTENDANCE_API_ROUTES } from "../../../constants";
|
|
28
|
+
import { attendanceFormValidation } from "../validate";
|
|
29
|
+
import { ATTENDANCE_STATUS } from "../../../type";
|
|
30
|
+
import { getCachedWorkspaceSync } from "../../workspace/cache";
|
|
31
|
+
import { toDateInput } from "../date";
|
|
32
|
+
import { ATTENDANCE_ACTION_TYPES, ATTENDANCE_DRAWER, useAttendanceContext, } from "../context";
|
|
33
|
+
// ============================================================================
|
|
34
|
+
// ENHANCED ATTENDANCE HOOK WITH API INTEGRATION
|
|
35
|
+
// ============================================================================
|
|
36
|
+
export const useAttendanceModule = () => {
|
|
37
|
+
var _a, _b;
|
|
38
|
+
const context = useAttendanceContext();
|
|
39
|
+
const { dispatch } = context;
|
|
40
|
+
const state = context.state;
|
|
41
|
+
// ==========================================================================
|
|
42
|
+
// 1.4.1 STATE & CORE HOOKS
|
|
43
|
+
// ==========================================================================
|
|
44
|
+
const t = useTranslations("attendance");
|
|
45
|
+
const { theme } = useTheme();
|
|
46
|
+
const workspace = getCachedWorkspaceSync();
|
|
47
|
+
const schoolId = ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "";
|
|
48
|
+
const listFetchNowRef = useRef(null);
|
|
49
|
+
const debouncedQuery = useDebounce(state.searchQuery, 800);
|
|
50
|
+
// ==========================================================================
|
|
51
|
+
// 1.4.2 API PARAMETERS
|
|
52
|
+
// ==========================================================================
|
|
53
|
+
const listParams = useMemo(() => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.appliedFilterEnabled !== undefined
|
|
54
|
+
? { filterEnabled: String(state.appliedFilterEnabled) }
|
|
55
|
+
: {})), (state.appliedFilterStatus
|
|
56
|
+
? { filterStatus: state.appliedFilterStatus }
|
|
57
|
+
: {})), (state.appliedFilterStartDate
|
|
58
|
+
? { fromDate: state.appliedFilterStartDate }
|
|
59
|
+
: {})), (state.appliedFilterEndDate
|
|
60
|
+
? { toDate: state.appliedFilterEndDate }
|
|
61
|
+
: {}))), [
|
|
62
|
+
state.appliedFilterEnabled,
|
|
63
|
+
state.appliedFilterEndDate,
|
|
64
|
+
state.appliedFilterStartDate,
|
|
65
|
+
state.appliedFilterStatus,
|
|
66
|
+
state.currentPage,
|
|
67
|
+
state.pageLimit,
|
|
68
|
+
debouncedQuery,
|
|
69
|
+
schoolId,
|
|
70
|
+
]);
|
|
71
|
+
const updateParams = useMemo(() => ({
|
|
72
|
+
date: state.date,
|
|
73
|
+
enabled: state.enabled,
|
|
74
|
+
id: state.id,
|
|
75
|
+
remarks: state.remarks,
|
|
76
|
+
schoolId,
|
|
77
|
+
status: state.status,
|
|
78
|
+
studentProfileId: state.studentProfileId,
|
|
79
|
+
}), [state, schoolId]);
|
|
80
|
+
// Single-record calls must carry the tenant: the API/tenant guard cannot
|
|
81
|
+
// scope an id-only request.
|
|
82
|
+
const byIdParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
|
|
83
|
+
const deleteParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
|
|
84
|
+
// ==========================================================================
|
|
85
|
+
// 1.4.3 UTILITIES
|
|
86
|
+
// ==========================================================================
|
|
87
|
+
const showToast = useCallback((description, variant) => {
|
|
88
|
+
generateThemeToast({
|
|
89
|
+
description,
|
|
90
|
+
theme: theme,
|
|
91
|
+
variant,
|
|
92
|
+
});
|
|
93
|
+
}, [theme]);
|
|
94
|
+
/**
|
|
95
|
+
* Clear the form fields without touching the list filters — RESET_FORM
|
|
96
|
+
* would also reset applied filters, so saving one record would silently
|
|
97
|
+
* drop the user's filter selection.
|
|
98
|
+
*/
|
|
99
|
+
const resetFormFields = useCallback(() => {
|
|
100
|
+
dispatch({
|
|
101
|
+
type: ATTENDANCE_ACTION_TYPES.SET_FORM_DATA,
|
|
102
|
+
payload: {
|
|
103
|
+
form: {
|
|
104
|
+
date: toDateInput(new Date()),
|
|
105
|
+
enabled: true,
|
|
106
|
+
id: "",
|
|
107
|
+
remarks: "",
|
|
108
|
+
status: ATTENDANCE_STATUS.PRESENT,
|
|
109
|
+
studentProfileId: "",
|
|
110
|
+
studentProfile: undefined,
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
dispatch({
|
|
115
|
+
type: ATTENDANCE_ACTION_TYPES.SET_ERRORS,
|
|
116
|
+
payload: { errors: {} },
|
|
117
|
+
});
|
|
118
|
+
dispatch({
|
|
119
|
+
type: ATTENDANCE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
120
|
+
payload: { disabled: false },
|
|
121
|
+
});
|
|
122
|
+
}, [dispatch]);
|
|
123
|
+
const resetFormAndCloseDrawer = useCallback(() => {
|
|
124
|
+
resetFormFields();
|
|
125
|
+
dispatch({
|
|
126
|
+
type: ATTENDANCE_ACTION_TYPES.SET_DRAWER,
|
|
127
|
+
payload: { drawer: null },
|
|
128
|
+
});
|
|
129
|
+
}, [dispatch, resetFormFields]);
|
|
130
|
+
// ==========================================================================
|
|
131
|
+
// 1.4.4 API CALLBACKS
|
|
132
|
+
// ==========================================================================
|
|
133
|
+
const listCallback = useCallback(({ data, error }) => {
|
|
134
|
+
var _a;
|
|
135
|
+
if (error) {
|
|
136
|
+
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (data) {
|
|
140
|
+
const response = data;
|
|
141
|
+
dispatch({
|
|
142
|
+
type: ATTENDANCE_ACTION_TYPES.SET_ITEMS,
|
|
143
|
+
payload: {
|
|
144
|
+
items: (_a = response.items) !== null && _a !== void 0 ? _a : [],
|
|
145
|
+
count: typeof response.count === "number" ? response.count : 0,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}, [dispatch, showToast, t]);
|
|
150
|
+
const updateCallback = useCallback(({ data, error }) => {
|
|
151
|
+
if (error) {
|
|
152
|
+
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (data) {
|
|
156
|
+
showToast(isCreatedOrUpdated(data)
|
|
157
|
+
? t("messagesAttendanceCreated")
|
|
158
|
+
: t("messagesAttendanceUpdated"), TOAST_VARIANT.SUCCESS);
|
|
159
|
+
// `useModuleEntityV2` already schedules a debounced list refresh.
|
|
160
|
+
resetFormAndCloseDrawer();
|
|
161
|
+
}
|
|
162
|
+
}, [resetFormAndCloseDrawer, showToast, t]);
|
|
163
|
+
const byIdCallback = useCallback(({ data, error }) => {
|
|
164
|
+
if (error) {
|
|
165
|
+
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (data) {
|
|
169
|
+
const record = data;
|
|
170
|
+
dispatch({
|
|
171
|
+
type: ATTENDANCE_ACTION_TYPES.SET_FORM_DATA,
|
|
172
|
+
payload: {
|
|
173
|
+
form: Object.assign(Object.assign({}, record), {
|
|
174
|
+
// ISO → the `YYYY-MM-DD` value a date input expects.
|
|
175
|
+
date: toDateInput(record.date) }),
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}, [dispatch, showToast, t]);
|
|
180
|
+
const deleteCallback = useCallback(({ data, error }) => {
|
|
181
|
+
if (error) {
|
|
182
|
+
showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
if (data) {
|
|
186
|
+
showToast(t("messagesAttendanceDeleted"), TOAST_VARIANT.SUCCESS);
|
|
187
|
+
}
|
|
188
|
+
}, [showToast, t]);
|
|
189
|
+
// ==========================================================================
|
|
190
|
+
// 1.4.5 API HOOKS
|
|
191
|
+
// ==========================================================================
|
|
192
|
+
const { listFetchNow, listLoading, updateFetchNow, updateLoading, byIdFetchNow, deleteFetchNow, deleteLoading, byIdLoading, } = useModuleEntityV2({
|
|
193
|
+
byIdCallback,
|
|
194
|
+
byIdParams,
|
|
195
|
+
deleteCallback,
|
|
196
|
+
deleteParams,
|
|
197
|
+
listCallback,
|
|
198
|
+
listParams,
|
|
199
|
+
listUrl: ATTENDANCE_API_ROUTES.UNIT,
|
|
200
|
+
searchQuery: debouncedQuery,
|
|
201
|
+
unitByIdUrl: ATTENDANCE_API_ROUTES.UNIT,
|
|
202
|
+
unitUrl: ATTENDANCE_API_ROUTES.UNIT,
|
|
203
|
+
updateCallback,
|
|
204
|
+
updateParams,
|
|
205
|
+
headers: {
|
|
206
|
+
"Content-Type": "application/json",
|
|
207
|
+
// "x-api-token": process.env.NEXT_PUBLIC_API_KEY!,
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
// ==========================================================================
|
|
211
|
+
// 1.4.6 HANDLERS
|
|
212
|
+
// ==========================================================================
|
|
213
|
+
const handleChange = useCallback((field, value) => {
|
|
214
|
+
dispatch({
|
|
215
|
+
type: ATTENDANCE_ACTION_TYPES.SET_ERRORS,
|
|
216
|
+
payload: { errors: {} },
|
|
217
|
+
});
|
|
218
|
+
dispatch({
|
|
219
|
+
type: ATTENDANCE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
220
|
+
payload: { disabled: false },
|
|
221
|
+
});
|
|
222
|
+
dispatch({
|
|
223
|
+
type: ATTENDANCE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
224
|
+
payload: { key: field, value },
|
|
225
|
+
});
|
|
226
|
+
}, [dispatch]);
|
|
227
|
+
const handlePageChange = useCallback((pageOrEvent) => {
|
|
228
|
+
const page = typeof pageOrEvent === "number" && !isNaN(pageOrEvent)
|
|
229
|
+
? pageOrEvent
|
|
230
|
+
: state.currentPage + 1;
|
|
231
|
+
dispatch({
|
|
232
|
+
type: ATTENDANCE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
233
|
+
payload: { currentPage: page },
|
|
234
|
+
});
|
|
235
|
+
}, [dispatch, state.currentPage]);
|
|
236
|
+
const handlePageLimitChange = useCallback((k, value) => {
|
|
237
|
+
const val = Object.assign({}, value);
|
|
238
|
+
dispatch({
|
|
239
|
+
type: ATTENDANCE_ACTION_TYPES.SET_PAGE_LIMIT,
|
|
240
|
+
payload: { pageLimit: Number(val.option) },
|
|
241
|
+
});
|
|
242
|
+
dispatch({
|
|
243
|
+
type: ATTENDANCE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
244
|
+
payload: { currentPage: 1 },
|
|
245
|
+
});
|
|
246
|
+
}, [dispatch]);
|
|
247
|
+
const closeDrawer = useCallback(() => {
|
|
248
|
+
resetFormAndCloseDrawer();
|
|
249
|
+
}, [resetFormAndCloseDrawer]);
|
|
250
|
+
const handleCreate = useCallback(() => {
|
|
251
|
+
// Never carry a previous record's id/values into a new entry.
|
|
252
|
+
resetFormFields();
|
|
253
|
+
dispatch({
|
|
254
|
+
type: ATTENDANCE_ACTION_TYPES.SET_DRAWER,
|
|
255
|
+
payload: { drawer: ATTENDANCE_DRAWER.FORM_DRAWER },
|
|
256
|
+
});
|
|
257
|
+
}, [dispatch, resetFormFields]);
|
|
258
|
+
const handleFilters = useCallback(() => {
|
|
259
|
+
dispatch({
|
|
260
|
+
type: ATTENDANCE_ACTION_TYPES.SET_DRAWER,
|
|
261
|
+
payload: { drawer: ATTENDANCE_DRAWER.FILTER_DRAWER },
|
|
262
|
+
});
|
|
263
|
+
}, [dispatch]);
|
|
264
|
+
const handleMoreActions = useCallback(() => {
|
|
265
|
+
dispatch({
|
|
266
|
+
type: ATTENDANCE_ACTION_TYPES.SET_DRAWER,
|
|
267
|
+
payload: { drawer: ATTENDANCE_DRAWER.MORE_ACTIONS_DRAWER },
|
|
268
|
+
});
|
|
269
|
+
}, [dispatch]);
|
|
270
|
+
const handleSearch = useCallback((query) => {
|
|
271
|
+
var _a;
|
|
272
|
+
dispatch({
|
|
273
|
+
type: ATTENDANCE_ACTION_TYPES.SET_SEARCH_QUERY,
|
|
274
|
+
payload: { searchQuery: query, schoolId: ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "" },
|
|
275
|
+
});
|
|
276
|
+
}, [dispatch, (_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.id]);
|
|
277
|
+
const clearFilters = useCallback(() => {
|
|
278
|
+
// RESET_FORM restores the initial filter values (enabled only) and keeps
|
|
279
|
+
// the currently loaded page/items, so the list reloads with the defaults.
|
|
280
|
+
dispatch({ type: ATTENDANCE_ACTION_TYPES.RESET_FORM });
|
|
281
|
+
dispatch({
|
|
282
|
+
type: ATTENDANCE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
283
|
+
payload: { currentPage: 1 },
|
|
284
|
+
});
|
|
285
|
+
}, [dispatch]);
|
|
286
|
+
const clearSearch = useCallback(() => {
|
|
287
|
+
dispatch({
|
|
288
|
+
type: ATTENDANCE_ACTION_TYPES.SET_SEARCH_QUERY,
|
|
289
|
+
payload: { searchQuery: "" },
|
|
290
|
+
});
|
|
291
|
+
}, [dispatch]);
|
|
292
|
+
const handleView = useCallback((row) => {
|
|
293
|
+
byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
|
|
294
|
+
dispatch({
|
|
295
|
+
type: ATTENDANCE_ACTION_TYPES.SET_DRAWER,
|
|
296
|
+
payload: { drawer: ATTENDANCE_DRAWER.VIEW_DRAWER },
|
|
297
|
+
});
|
|
298
|
+
}, [byIdFetchNow, dispatch]);
|
|
299
|
+
const handleEdit = useCallback((row) => {
|
|
300
|
+
byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
|
|
301
|
+
dispatch({
|
|
302
|
+
type: ATTENDANCE_ACTION_TYPES.SET_DRAWER,
|
|
303
|
+
payload: { drawer: ATTENDANCE_DRAWER.FORM_DRAWER },
|
|
304
|
+
});
|
|
305
|
+
}, [byIdFetchNow, dispatch]);
|
|
306
|
+
const handleDelete = useCallback((row) => {
|
|
307
|
+
if (!confirm(t("messagesDeleteConfirmation")))
|
|
308
|
+
return;
|
|
309
|
+
deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
|
|
310
|
+
body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id, schoolId }),
|
|
311
|
+
});
|
|
312
|
+
}, [deleteFetchNow, schoolId, t]);
|
|
313
|
+
// ==========================================================================
|
|
314
|
+
// 1.4.7 NETWORK ACTIONS
|
|
315
|
+
// ==========================================================================
|
|
316
|
+
const handleSubmit = useCallback(() => {
|
|
317
|
+
dispatch({
|
|
318
|
+
type: ATTENDANCE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
319
|
+
payload: { disabled: true },
|
|
320
|
+
});
|
|
321
|
+
validateForm({
|
|
322
|
+
params: updateParams,
|
|
323
|
+
schema: attendanceFormValidation,
|
|
324
|
+
successCallback: () => {
|
|
325
|
+
// `id` is only present when editing; a blank one would make the API
|
|
326
|
+
// treat the request as a create.
|
|
327
|
+
const { id } = updateParams, createParams = __rest(updateParams, ["id"]);
|
|
328
|
+
updateFetchNow(undefined, {
|
|
329
|
+
body: JSON.stringify(id ? updateParams : createParams),
|
|
330
|
+
});
|
|
331
|
+
},
|
|
332
|
+
errorCallback: (errors) => {
|
|
333
|
+
dispatch({
|
|
334
|
+
type: ATTENDANCE_ACTION_TYPES.SET_ERRORS,
|
|
335
|
+
payload: { errors },
|
|
336
|
+
});
|
|
337
|
+
dispatch({
|
|
338
|
+
type: ATTENDANCE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
339
|
+
payload: { disabled: false },
|
|
340
|
+
});
|
|
341
|
+
showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
}, [dispatch, updateParams, updateFetchNow, showToast, t]);
|
|
345
|
+
// ==========================================================================
|
|
346
|
+
// 1.4.8 HEADER & ROW ACTIONS
|
|
347
|
+
// ==========================================================================
|
|
348
|
+
const headerActions = useMemo(() => [
|
|
349
|
+
{
|
|
350
|
+
enabled: true,
|
|
351
|
+
handleOnClick: handleMoreActions,
|
|
352
|
+
label: t("actionsButtonMoreActions"),
|
|
353
|
+
order: 0,
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
enabled: true,
|
|
357
|
+
handleOnClick: handleFilters,
|
|
358
|
+
label: t("actionsButtonFilters"),
|
|
359
|
+
order: 1,
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
enabled: true,
|
|
363
|
+
handleOnClick: handleCreate,
|
|
364
|
+
label: t("actionsButtonAdd"),
|
|
365
|
+
order: 2,
|
|
366
|
+
},
|
|
367
|
+
], [handleCreate, handleFilters, handleMoreActions, t]);
|
|
368
|
+
const rowActions = useMemo(() => [
|
|
369
|
+
{
|
|
370
|
+
enabled: true,
|
|
371
|
+
handleOnClick: handleView,
|
|
372
|
+
label: t("actionsButtonView"),
|
|
373
|
+
order: 0,
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
enabled: true,
|
|
377
|
+
handleOnClick: handleEdit,
|
|
378
|
+
label: t("actionsButtonEdit"),
|
|
379
|
+
order: 1,
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
enabled: true,
|
|
383
|
+
handleOnClick: handleDelete,
|
|
384
|
+
label: t("actionsButtonDelete"),
|
|
385
|
+
order: 2,
|
|
386
|
+
variant: "destructive",
|
|
387
|
+
},
|
|
388
|
+
], [handleDelete, handleEdit, handleView, t]);
|
|
389
|
+
const applyFilters = useCallback(() => {
|
|
390
|
+
dispatch({
|
|
391
|
+
type: ATTENDANCE_ACTION_TYPES.SET_FILTERS,
|
|
392
|
+
payload: {
|
|
393
|
+
filters: {
|
|
394
|
+
appliedFilterEnabled: state.filterEnabled,
|
|
395
|
+
appliedFilterStatus: state.filterStatus,
|
|
396
|
+
appliedFilterStartDate: state.filterStartDate,
|
|
397
|
+
appliedFilterEndDate: state.filterEndDate,
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
});
|
|
401
|
+
dispatch({
|
|
402
|
+
type: ATTENDANCE_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
403
|
+
payload: { currentPage: 1 },
|
|
404
|
+
});
|
|
405
|
+
closeDrawer();
|
|
406
|
+
}, [
|
|
407
|
+
dispatch,
|
|
408
|
+
closeDrawer,
|
|
409
|
+
state.filterEnabled,
|
|
410
|
+
state.filterStatus,
|
|
411
|
+
state.filterStartDate,
|
|
412
|
+
state.filterEndDate,
|
|
413
|
+
]);
|
|
414
|
+
// ==========================================================================
|
|
415
|
+
// 1.4.9 EFFECTS
|
|
416
|
+
// ==========================================================================
|
|
417
|
+
useEffect(() => {
|
|
418
|
+
listFetchNowRef.current = listFetchNow;
|
|
419
|
+
}, [listFetchNow]);
|
|
420
|
+
useEffect(() => {
|
|
421
|
+
var _a;
|
|
422
|
+
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
423
|
+
}, [listParams]);
|
|
424
|
+
// ==========================================================================
|
|
425
|
+
// 1.4.10 RETURN
|
|
426
|
+
// ==========================================================================
|
|
427
|
+
return Object.assign(Object.assign({}, context), { applyFilters,
|
|
428
|
+
byIdLoading,
|
|
429
|
+
clearFilters,
|
|
430
|
+
clearSearch,
|
|
431
|
+
closeDrawer,
|
|
432
|
+
deleteLoading,
|
|
433
|
+
handleChange,
|
|
434
|
+
handleCreate,
|
|
435
|
+
handleDelete,
|
|
436
|
+
handleEdit,
|
|
437
|
+
handleFilters,
|
|
438
|
+
handleMoreActions,
|
|
439
|
+
handlePageChange,
|
|
440
|
+
handlePageLimitChange,
|
|
441
|
+
handleSearch,
|
|
442
|
+
handleSubmit,
|
|
443
|
+
handleView,
|
|
444
|
+
headerActions,
|
|
445
|
+
listFetchNow,
|
|
446
|
+
listLoading,
|
|
447
|
+
rowActions,
|
|
448
|
+
updateLoading });
|
|
449
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type RowAction, type TableRow } from "@appcorp/shadcn/components/enhanced-table";
|
|
2
1
|
import { AttendanceBE, ATTENDANCE_STATUS, SchoolBE, StudentProfileBE } from "../../type";
|
|
3
2
|
export declare const ATTENDANCE_DRAWER: {
|
|
4
3
|
readonly FILTER_DRAWER: string;
|
|
@@ -30,6 +29,13 @@ export declare const ATTENDANCE_ACTION_TYPES: {
|
|
|
30
29
|
enabled: boolean;
|
|
31
30
|
errors: Record<string, string>;
|
|
32
31
|
filterEnabled: boolean | undefined;
|
|
32
|
+
filterStatus: string | undefined;
|
|
33
|
+
filterStartDate: string | undefined;
|
|
34
|
+
filterEndDate: string | undefined;
|
|
35
|
+
appliedFilterEnabled: boolean | undefined;
|
|
36
|
+
appliedFilterStatus: string | undefined;
|
|
37
|
+
appliedFilterStartDate: string | undefined;
|
|
38
|
+
appliedFilterEndDate: string | undefined;
|
|
33
39
|
id: string;
|
|
34
40
|
remarks: string;
|
|
35
41
|
schoolId: string;
|
|
@@ -49,6 +55,13 @@ export declare const ATTENDANCE_ACTION_TYPES: {
|
|
|
49
55
|
enabled: boolean;
|
|
50
56
|
errors: Record<string, string>;
|
|
51
57
|
filterEnabled: boolean | undefined;
|
|
58
|
+
filterStatus: string | undefined;
|
|
59
|
+
filterStartDate: string | undefined;
|
|
60
|
+
filterEndDate: string | undefined;
|
|
61
|
+
appliedFilterEnabled: boolean | undefined;
|
|
62
|
+
appliedFilterStatus: string | undefined;
|
|
63
|
+
appliedFilterStartDate: string | undefined;
|
|
64
|
+
appliedFilterEndDate: string | undefined;
|
|
52
65
|
id: string;
|
|
53
66
|
remarks: string;
|
|
54
67
|
schoolId: string;
|
|
@@ -70,6 +83,13 @@ export declare const ATTENDANCE_ACTION_TYPES: {
|
|
|
70
83
|
enabled: boolean;
|
|
71
84
|
errors: Record<string, string>;
|
|
72
85
|
filterEnabled: boolean | undefined;
|
|
86
|
+
filterStatus: string | undefined;
|
|
87
|
+
filterStartDate: string | undefined;
|
|
88
|
+
filterEndDate: string | undefined;
|
|
89
|
+
appliedFilterEnabled: boolean | undefined;
|
|
90
|
+
appliedFilterStatus: string | undefined;
|
|
91
|
+
appliedFilterStartDate: string | undefined;
|
|
92
|
+
appliedFilterEndDate: string | undefined;
|
|
73
93
|
id: string;
|
|
74
94
|
remarks: string;
|
|
75
95
|
schoolId: string;
|
|
@@ -89,6 +109,13 @@ export declare const ATTENDANCE_ACTION_TYPES: {
|
|
|
89
109
|
enabled: boolean;
|
|
90
110
|
errors: Record<string, string>;
|
|
91
111
|
filterEnabled: boolean | undefined;
|
|
112
|
+
filterStatus: string | undefined;
|
|
113
|
+
filterStartDate: string | undefined;
|
|
114
|
+
filterEndDate: string | undefined;
|
|
115
|
+
appliedFilterEnabled: boolean | undefined;
|
|
116
|
+
appliedFilterStatus: string | undefined;
|
|
117
|
+
appliedFilterStartDate: string | undefined;
|
|
118
|
+
appliedFilterEndDate: string | undefined;
|
|
92
119
|
id: string;
|
|
93
120
|
remarks: string;
|
|
94
121
|
schoolId: string;
|
|
@@ -108,6 +135,13 @@ export declare const ATTENDANCE_ACTION_TYPES: {
|
|
|
108
135
|
enabled: boolean;
|
|
109
136
|
errors: Record<string, string>;
|
|
110
137
|
filterEnabled: boolean | undefined;
|
|
138
|
+
filterStatus: string | undefined;
|
|
139
|
+
filterStartDate: string | undefined;
|
|
140
|
+
filterEndDate: string | undefined;
|
|
141
|
+
appliedFilterEnabled: boolean | undefined;
|
|
142
|
+
appliedFilterStatus: string | undefined;
|
|
143
|
+
appliedFilterStartDate: string | undefined;
|
|
144
|
+
appliedFilterEndDate: string | undefined;
|
|
111
145
|
id: string;
|
|
112
146
|
remarks: string;
|
|
113
147
|
schoolId: string;
|
|
@@ -116,54 +150,4 @@ export declare const ATTENDANCE_ACTION_TYPES: {
|
|
|
116
150
|
school: SchoolBE | undefined;
|
|
117
151
|
studentProfile: StudentProfileBE | undefined;
|
|
118
152
|
}>;
|
|
119
|
-
export
|
|
120
|
-
applyFilters: () => void;
|
|
121
|
-
byIdLoading: boolean;
|
|
122
|
-
clearFilters: () => void;
|
|
123
|
-
clearSearch: () => void;
|
|
124
|
-
closeDrawer: () => void;
|
|
125
|
-
deleteLoading: boolean;
|
|
126
|
-
handleChange: (field: string, value: string | number | boolean | undefined) => void;
|
|
127
|
-
handleCreate: () => void;
|
|
128
|
-
handleDelete: (row?: TableRow) => void;
|
|
129
|
-
handleEdit: (row?: TableRow) => void;
|
|
130
|
-
handleFilters: () => void;
|
|
131
|
-
handleMoreActions: () => void;
|
|
132
|
-
handlePageChange: (pageOrEvent?: unknown) => void;
|
|
133
|
-
handlePageLimitChange: (k: string, value: object) => void;
|
|
134
|
-
handleSearch: (query: string) => void;
|
|
135
|
-
handleSubmit: () => void;
|
|
136
|
-
handleView: (row?: TableRow) => void;
|
|
137
|
-
headerActions: {
|
|
138
|
-
enabled: boolean;
|
|
139
|
-
handleOnClick: () => void;
|
|
140
|
-
label: string;
|
|
141
|
-
order: number;
|
|
142
|
-
}[];
|
|
143
|
-
listFetchNow: (url?: string, config?: import("@react-pakistan/util-functions/hooks/use-fetch").FetchConfig) => void;
|
|
144
|
-
listLoading: boolean;
|
|
145
|
-
rowActions: RowAction[];
|
|
146
|
-
updateLoading: boolean;
|
|
147
|
-
handleCloseDrawer?: () => void;
|
|
148
|
-
state: {
|
|
149
|
-
items: AttendanceBE[];
|
|
150
|
-
count: number;
|
|
151
|
-
currentPage: number;
|
|
152
|
-
pageLimit: number;
|
|
153
|
-
searchQuery: string;
|
|
154
|
-
disableSaveButton: boolean;
|
|
155
|
-
drawer: string | null;
|
|
156
|
-
date: string;
|
|
157
|
-
enabled: boolean;
|
|
158
|
-
errors: Record<string, string>;
|
|
159
|
-
filterEnabled: boolean | undefined;
|
|
160
|
-
id: string;
|
|
161
|
-
remarks: string;
|
|
162
|
-
schoolId: string;
|
|
163
|
-
status: ATTENDANCE_STATUS;
|
|
164
|
-
studentProfileId: string;
|
|
165
|
-
school: SchoolBE | undefined;
|
|
166
|
-
studentProfile: StudentProfileBE | undefined;
|
|
167
|
-
};
|
|
168
|
-
dispatch: React.Dispatch<any>;
|
|
169
|
-
};
|
|
153
|
+
export { useAttendanceModule } from "./context/use-attendance-module";
|