@appcorp/fusion-storybook 0.5.36 → 0.5.39
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/admission/context/use-admission-module.d.ts +1 -1
- package/base-modules/admission/context/use-admission-module.js +23 -36
- package/base-modules/admission/form.js +117 -54
- package/base-modules/expense/context/shared.d.ts +5 -0
- package/base-modules/expense/context/shared.js +1 -0
- package/base-modules/expense/context/use-expense-module.d.ts +2 -1
- package/base-modules/expense/context/use-expense-module.js +49 -5
- package/base-modules/expense/form.js +4 -2
- package/base-modules/school/context.d.ts +13 -7
- package/base-modules/school/context.js +46 -5
- package/base-modules/school/form.js +11 -1
- package/base-modules/teacher/context.js +9 -37
- package/base-modules/user/context/use-user-module.d.ts +1 -0
- package/base-modules/user/context/use-user-module.js +22 -43
- package/base-modules/user/context.d.ts +5 -0
- package/base-modules/user/context.js +1 -0
- package/base-modules/workspace/context.d.ts +7 -1
- package/base-modules/workspace/context.js +46 -5
- package/base-modules/workspace/form.js +11 -1
- package/constants.d.ts +0 -4
- package/constants.js +0 -4
- package/package.json +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/upload-file.d.ts +42 -0
- package/utils/upload-file.js +116 -0
- package/base-modules/teacher/avatar-upload.d.ts +0 -36
- package/base-modules/teacher/avatar-upload.js +0 -104
- package/utils/file-to-base64.d.ts +0 -1
- package/utils/file-to-base64.js +0 -10
|
@@ -37,7 +37,7 @@ export declare const useAdmissionModule: () => {
|
|
|
37
37
|
listLoading: boolean;
|
|
38
38
|
rowActions: RowAction[];
|
|
39
39
|
updateLoading: boolean;
|
|
40
|
-
uploadAdmissionDocuments: (files: File[]
|
|
40
|
+
uploadAdmissionDocuments: (files: File[]) => Promise<string[]>;
|
|
41
41
|
state: {
|
|
42
42
|
items: AdmissionBE[];
|
|
43
43
|
count: number;
|
|
@@ -11,12 +11,12 @@ import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
|
|
|
11
11
|
import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
|
|
12
12
|
import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
|
|
13
13
|
import { ADMISSION_STATUS, GENDER, } from "../../../type";
|
|
14
|
-
import { ADMISSION_API_ROUTES, DISCOUNT_CODE_API_ROUTES,
|
|
14
|
+
import { ADMISSION_API_ROUTES, DISCOUNT_CODE_API_ROUTES, } from "../../../constants";
|
|
15
15
|
import { admissionFormValidation } from "../validate";
|
|
16
16
|
import { getCachedWorkspaceSync } from "../../workspace/cache";
|
|
17
17
|
import { downloadAdmissionFormPDF, } from "../../../utils/admission-pdf";
|
|
18
|
-
import { fileToBase64 } from "../../../utils/file-to-base64";
|
|
19
18
|
import { compressPdf, DocumentTooLargeError, isPdfFile, MAX_DOCUMENT_SIZE_BYTES, } from "../../../utils/compress-pdf";
|
|
19
|
+
import { uploadFiles } from "../../../utils/upload-file";
|
|
20
20
|
import { wakeStorageServer } from "../../../utils/wake-storage";
|
|
21
21
|
import { normalizeIdNumber } from "../../../utils/id-number";
|
|
22
22
|
import { isGovernmentIdType, } from "../../../utils/government-id";
|
|
@@ -24,7 +24,7 @@ import { toE164Phone } from "../../../utils/to-e164-phone";
|
|
|
24
24
|
import { Filter, Plus } from "lucide-react";
|
|
25
25
|
import { ADMISSION_DRAWER, ADMISSION_ACTION_TYPES, useAdmissionContext, } from "../context";
|
|
26
26
|
export const useAdmissionModule = () => {
|
|
27
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p
|
|
27
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
|
|
28
28
|
// ============================================================================
|
|
29
29
|
// 1.4.1 STATE & CORE HOOKS
|
|
30
30
|
// ============================================================================
|
|
@@ -330,11 +330,9 @@ export const useAdmissionModule = () => {
|
|
|
330
330
|
(_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
|
|
331
331
|
}
|
|
332
332
|
}, [showToast, t]);
|
|
333
|
-
const uploadAdmissionDocuments = useCallback(async (files
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (!schoolId) {
|
|
337
|
-
throw new Error("School context is not available");
|
|
333
|
+
const uploadAdmissionDocuments = useCallback(async (files) => {
|
|
334
|
+
if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id)) {
|
|
335
|
+
throw new Error("Workspace context is not available");
|
|
338
336
|
}
|
|
339
337
|
const prepared = await Promise.all(files.map(async (file) => isPdfFile(file) ? await compressPdf(file) : file));
|
|
340
338
|
for (const file of prepared) {
|
|
@@ -342,24 +340,13 @@ export const useAdmissionModule = () => {
|
|
|
342
340
|
throw new DocumentTooLargeError(file.name, file.size);
|
|
343
341
|
}
|
|
344
342
|
}
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
})));
|
|
350
|
-
const { data, error } = await fetchData({
|
|
351
|
-
url: DOCUMENT_UPLOAD_API_ROUTES.UNIT,
|
|
352
|
-
method: API_METHODS.POST,
|
|
353
|
-
headers: {
|
|
354
|
-
"Content-Type": "application/json",
|
|
355
|
-
},
|
|
356
|
-
body: JSON.stringify({ schoolId, registrationCode, files: payload }),
|
|
343
|
+
const uploaded = await uploadFiles(prepared, {
|
|
344
|
+
workspaceId: workspace.id,
|
|
345
|
+
formName: "admission",
|
|
346
|
+
maxSizeBytes: MAX_DOCUMENT_SIZE_BYTES,
|
|
357
347
|
});
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
return data.urls;
|
|
362
|
-
}, [(_g = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _g === void 0 ? void 0 : _g.id]);
|
|
348
|
+
return uploaded.map((file) => file.url);
|
|
349
|
+
}, [workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
363
350
|
// ============================================================================
|
|
364
351
|
// 1.4.5 API HOOKS
|
|
365
352
|
// ============================================================================
|
|
@@ -431,7 +418,7 @@ export const useAdmissionModule = () => {
|
|
|
431
418
|
schoolId: (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id,
|
|
432
419
|
}),
|
|
433
420
|
});
|
|
434
|
-
}, [t, deleteFetchNow, (
|
|
421
|
+
}, [t, deleteFetchNow, (_g = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _g === void 0 ? void 0 : _g.id]);
|
|
435
422
|
const handleRemoveDocument = useCallback(async (url) => {
|
|
436
423
|
var _a;
|
|
437
424
|
const next = (state.documents || []).filter((d) => d !== url);
|
|
@@ -461,7 +448,7 @@ export const useAdmissionModule = () => {
|
|
|
461
448
|
}
|
|
462
449
|
}, [
|
|
463
450
|
dispatch,
|
|
464
|
-
(
|
|
451
|
+
(_h = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _h === void 0 ? void 0 : _h.id,
|
|
465
452
|
state.documents,
|
|
466
453
|
state.id,
|
|
467
454
|
state.classForAdmission,
|
|
@@ -619,7 +606,7 @@ export const useAdmissionModule = () => {
|
|
|
619
606
|
status,
|
|
620
607
|
}),
|
|
621
608
|
});
|
|
622
|
-
}, [updateFetchNow, (
|
|
609
|
+
}, [updateFetchNow, (_j = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _j === void 0 ? void 0 : _j.id]);
|
|
623
610
|
const handleApprove = useCallback((row) => {
|
|
624
611
|
handleUpdateStatus(row, ADMISSION_STATUS.APPROVED, t("messagesApproveConfirmation"));
|
|
625
612
|
}, [handleUpdateStatus, t]);
|
|
@@ -657,7 +644,7 @@ export const useAdmissionModule = () => {
|
|
|
657
644
|
if (data) {
|
|
658
645
|
showToast(t("messagesAdmitSuccess"), TOAST_VARIANT.SUCCESS);
|
|
659
646
|
}
|
|
660
|
-
}, [t, showToast, (
|
|
647
|
+
}, [t, showToast, (_k = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _k === void 0 ? void 0 : _k.id]);
|
|
661
648
|
// ============================================================================
|
|
662
649
|
// 1.4.7 NETWORK ACTIONS
|
|
663
650
|
// ============================================================================
|
|
@@ -754,7 +741,7 @@ export const useAdmissionModule = () => {
|
|
|
754
741
|
return;
|
|
755
742
|
}
|
|
756
743
|
showToast(t("messagesAnalyzeSuccess"), TOAST_VARIANT.SUCCESS);
|
|
757
|
-
}, [(
|
|
744
|
+
}, [(_l = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _l === void 0 ? void 0 : _l.id, t, showToast, byIdFetchNow, dispatch]);
|
|
758
745
|
const handleSubmit = useCallback(() => {
|
|
759
746
|
dispatch({
|
|
760
747
|
type: ADMISSION_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
@@ -769,25 +756,25 @@ export const useAdmissionModule = () => {
|
|
|
769
756
|
const merged = state.documentsFiles.length
|
|
770
757
|
? [
|
|
771
758
|
...(state.documents || []),
|
|
772
|
-
...(await uploadAdmissionDocuments(state.documentsFiles
|
|
759
|
+
...(await uploadAdmissionDocuments(state.documentsFiles)),
|
|
773
760
|
]
|
|
774
761
|
: state.documents || [];
|
|
775
762
|
const studentIdImages = state.studentIdImagesFiles.length
|
|
776
763
|
? [
|
|
777
764
|
...(state.studentIdImages || []),
|
|
778
|
-
...(await uploadAdmissionDocuments(state.studentIdImagesFiles
|
|
765
|
+
...(await uploadAdmissionDocuments(state.studentIdImagesFiles)),
|
|
779
766
|
]
|
|
780
767
|
: state.studentIdImages || [];
|
|
781
768
|
const fatherIdImages = state.fatherIdImagesFiles.length
|
|
782
769
|
? [
|
|
783
770
|
...(state.fatherIdImages || []),
|
|
784
|
-
...(await uploadAdmissionDocuments(state.fatherIdImagesFiles
|
|
771
|
+
...(await uploadAdmissionDocuments(state.fatherIdImagesFiles)),
|
|
785
772
|
]
|
|
786
773
|
: state.fatherIdImages || [];
|
|
787
774
|
const motherIdImages = state.motherIdImagesFiles.length
|
|
788
775
|
? [
|
|
789
776
|
...(state.motherIdImages || []),
|
|
790
|
-
...(await uploadAdmissionDocuments(state.motherIdImagesFiles
|
|
777
|
+
...(await uploadAdmissionDocuments(state.motherIdImagesFiles)),
|
|
791
778
|
]
|
|
792
779
|
: state.motherIdImages || [];
|
|
793
780
|
const studentIdType = isGovernmentIdType(updateParams.studentIdType)
|
|
@@ -926,12 +913,12 @@ export const useAdmissionModule = () => {
|
|
|
926
913
|
state.motherIdImages,
|
|
927
914
|
state.motherIdImagesFiles,
|
|
928
915
|
uploadAdmissionDocuments,
|
|
929
|
-
(
|
|
916
|
+
(_m = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _m === void 0 ? void 0 : _m.id,
|
|
930
917
|
]);
|
|
931
918
|
// ============================================================================
|
|
932
919
|
// 1.4.8 HEADER & ROW ACTIONS
|
|
933
920
|
// ============================================================================
|
|
934
|
-
const hasGeminiSecrets = Boolean(((
|
|
921
|
+
const hasGeminiSecrets = Boolean(((_o = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _o === void 0 ? void 0 : _o.GEMINI_API_KEY) && ((_p = workspace === null || workspace === void 0 ? void 0 : workspace.secrets) === null || _p === void 0 ? void 0 : _p.GEMINI_MODEL));
|
|
935
922
|
const headerActions = useMemo(() => [
|
|
936
923
|
{
|
|
937
924
|
enabled: true,
|
|
@@ -17,7 +17,8 @@ import { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox
|
|
|
17
17
|
import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
|
|
18
18
|
import { Separator } from "@appcorp/shadcn/components/ui/separator";
|
|
19
19
|
import { useAdmissionModule, ADMISSION_ACTION_TYPES } from "./context";
|
|
20
|
-
import { useEffect } from "react";
|
|
20
|
+
import { useEffect, } from "react";
|
|
21
|
+
import { FileText, GraduationCap, Home, IdCard, StickyNote, User, UserRound, } from "lucide-react";
|
|
21
22
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
22
23
|
import { PhoneInput } from "../../components/phone-input";
|
|
23
24
|
import { GovernmentIdTypeSelect } from "../../components/government-id-type-select";
|
|
@@ -27,6 +28,11 @@ import { GENDER_OPTIONS } from "./constants";
|
|
|
27
28
|
import { DISCOUNT_CODE_API_ROUTES } from "../../constants";
|
|
28
29
|
import { useTranslations } from "next-intl";
|
|
29
30
|
import { getTranslatedError } from "../../utils/get-translated-error";
|
|
31
|
+
const ID_IMAGE_DROPZONE_CLASS = "[&>div:first-of-type]:min-h-36! [&>div:first-of-type]:p-3!";
|
|
32
|
+
const DOCUMENT_DROPZONE_CLASS = "[&>div:first-of-type]:min-h-48!";
|
|
33
|
+
const SectionHeading = ({ icon: Icon, children, }) => (_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("span", { className: "bg-primary/10 text-primary flex h-7 w-7 items-center justify-center rounded-md", children: _jsx(Icon, { className: "h-4 w-4" }) }), _jsx("h4", { className: "text-muted-foreground m-0 p-0 text-sm font-semibold tracking-wide uppercase", children: children })] }));
|
|
34
|
+
const IdentityDocumentCard = ({ title, children, }) => (_jsxs("div", { className: "bg-muted/20 flex h-full flex-col gap-4 rounded-lg border p-4", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx(IdCard, { className: "text-muted-foreground h-4 w-4" }), _jsx("h5", { className: "m-0 text-sm font-semibold", children: title })] }), children] }));
|
|
35
|
+
const IdImageField = ({ id, label, info, value, onChange, onRemoveRemote, }) => (_jsx(EnhancedDropzone, { accept: ["application/pdf", "image/jpeg", "image/png", "image/webp"], className: ID_IMAGE_DROPZONE_CLASS, id: id, info: info, label: label, maxFiles: 4, maxSize: 10 * 1024 * 1024, onChange: onChange, onRemoveRemote: onRemoveRemote, value: value }));
|
|
30
36
|
export const AdmissionForm = () => {
|
|
31
37
|
var _a, _b, _c;
|
|
32
38
|
const { state, handleChange, dispatch, discountCodes } = useAdmissionModule();
|
|
@@ -98,57 +104,114 @@ export const AdmissionForm = () => {
|
|
|
98
104
|
}
|
|
99
105
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
100
106
|
}, [id, dispatch]);
|
|
101
|
-
return (_jsxs("div", { className: "
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
107
|
+
return (_jsxs("div", { className: "space-y-6", children: [_jsxs("section", { className: "bg-card/40 space-y-4 rounded-xl border p-4 sm:p-5", children: [_jsx(SectionHeading, { icon: UserRound, children: t("formSectionStudentInformation") }), _jsxs("div", { className: "grid gap-4 lg:grid-cols-12", children: [_jsxs("div", { className: "space-y-4 lg:col-span-7", children: [_jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "firstName", t }), id: "firstName", info: t("formFirstNameInfo"), label: t("formFirstNameLabel"), onChange: (e) => handleChange("firstName", e.target.value), placeholder: t("formFirstNamePlaceholder"), required: true, type: "text", value: firstName || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "lastName", t }), id: "lastName", info: t("formLastNameInfo"), label: t("formLastNameLabel"), onChange: (e) => handleChange("lastName", e.target.value), placeholder: t("formLastNamePlaceholder"), required: true, type: "text", value: lastName || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "dob", t }), id: "dob", info: t("formDobInfo"), label: t("formDobLabel"), onChange: (e) => handleChange("dob", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, placeholder: t("formDobPlaceholder"), required: true, type: "date", value: dob || "" }), genderCombo] }), _jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsx(EnhancedInput, { error: getTranslatedError({
|
|
108
|
+
errors,
|
|
109
|
+
key: "registrationCode",
|
|
110
|
+
t,
|
|
111
|
+
}), id: "registrationCode", info: t("formRegistrationCodeInfo"), label: t("formRegistrationCodeLabel"), onChange: (e) => handleChange("registrationCode", e.target.value), placeholder: t("formRegistrationCodePlaceholder"), required: true, type: "text", value: registrationCode || "", disabled: true }), discountCodeCombo] }), _jsxs("div", { className: "flex flex-wrap items-center gap-6", children: [_jsx(EnhancedCheckbox, { label: t("formHafizLabel"), id: "hafiz", info: t("formHafizInfo"), onCheckedChange: (checked) => handleChange("hafiz", checked) }), _jsx(EnhancedCheckbox, { label: t("formOrphanLabel"), id: "orphan", info: t("formOrphanInfo"), onCheckedChange: (checked) => handleChange("orphan", checked) })] })] }), _jsx("div", { className: "lg:col-span-5", children: _jsxs(IdentityDocumentCard, { title: t("formIdentityDocumentLabel"), children: [_jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsx(GovernmentIdTypeSelect, { error: getTranslatedError({
|
|
112
|
+
errors,
|
|
113
|
+
key: "studentIdType",
|
|
114
|
+
t,
|
|
115
|
+
}), id: "studentIdType", onChange: (value) => handleChange("studentIdType", value), required: true, value: studentIdType }), _jsx(EnhancedInput, { error: getTranslatedError({
|
|
116
|
+
errors,
|
|
117
|
+
key: "studentIdNumber",
|
|
118
|
+
t,
|
|
119
|
+
}), id: "studentIdNumber", info: t("formStudentIdNumberInfo"), label: t("formStudentIdNumberLabel"), onChange: (e) => handleChange("studentIdNumber", e.target.value), placeholder: t("formStudentIdNumberPlaceholder"), required: true, type: "text", value: studentIdNumber || "" })] }), _jsx(IdImageField, { id: "studentIdImages", info: t("formStudentIdImagesInfo"), label: t("formStudentIdImagesLabel"), onChange: (files) => dispatch({
|
|
120
|
+
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
121
|
+
payload: { key: "studentIdImagesFiles", value: files },
|
|
122
|
+
}), onRemoveRemote: (url) => dispatch({
|
|
123
|
+
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
124
|
+
payload: {
|
|
125
|
+
key: "studentIdImages",
|
|
126
|
+
value: (studentIdImages || []).filter((item) => item !== url),
|
|
127
|
+
},
|
|
128
|
+
}), value: studentIdImages || [] })] }) })] })] }), _jsx(Separator, {}), _jsxs("section", { className: "bg-card/40 space-y-4 rounded-xl border p-4 sm:p-5", children: [_jsx(SectionHeading, { icon: User, children: t("formSectionFatherInformation") }), _jsxs("div", { className: "grid gap-4 lg:grid-cols-12", children: [_jsxs("div", { className: "space-y-4 lg:col-span-7", children: [_jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsx(EnhancedInput, { error: getTranslatedError({
|
|
129
|
+
errors,
|
|
130
|
+
key: "fatherFirstName",
|
|
131
|
+
t,
|
|
132
|
+
}), id: "fatherFirstName", info: t("formFatherFirstNameInfo"), label: t("formFirstNameLabel"), onChange: (e) => handleChange("fatherFirstName", e.target.value), placeholder: t("formFirstNamePlaceholder"), required: true, type: "text", value: fatherFirstName || "" }), _jsx(EnhancedInput, { error: getTranslatedError({
|
|
133
|
+
errors,
|
|
134
|
+
key: "fatherLastName",
|
|
135
|
+
t,
|
|
136
|
+
}), id: "fatherLastName", info: t("formFatherLastNameInfo"), label: t("formLastNameLabel"), onChange: (e) => handleChange("fatherLastName", e.target.value), placeholder: t("formLastNamePlaceholder"), required: true, type: "text", value: fatherLastName || "" }), _jsx(PhoneInput, { error: getTranslatedError({
|
|
137
|
+
errors,
|
|
138
|
+
key: "fatherMobile",
|
|
139
|
+
t,
|
|
140
|
+
}), id: "fatherMobile", info: t("formFatherMobileInfo"), label: t("formMobileLabel"), onChange: (value) => handleChange("fatherMobile", value), placeholder: t("formPhonePlaceholder"), required: true, value: fatherMobile || "", defaultCountry: country || ((_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.country) || "PK", className: "sm:col-span-2" }), _jsx(EnhancedInput, { error: getTranslatedError({
|
|
141
|
+
errors,
|
|
142
|
+
key: "fatherOccupation",
|
|
143
|
+
t,
|
|
144
|
+
}), id: "fatherOccupation", info: t("formFatherOccupationInfo"), label: t("formOccupationLabel"), onChange: (e) => handleChange("fatherOccupation", e.target.value), placeholder: t("formOccupationPlaceholder"), required: false, type: "text", value: fatherOccupation || "" }), _jsx(EnhancedInput, { error: getTranslatedError({
|
|
145
|
+
errors,
|
|
146
|
+
key: "fatherOrganization",
|
|
147
|
+
t,
|
|
148
|
+
}), id: "fatherOrganization", info: t("formFatherOrganizationInfo"), label: t("formOrganizationLabel"), onChange: (e) => handleChange("fatherOrganization", e.target.value), placeholder: t("formOrganizationPlaceholder"), required: false, type: "text", value: fatherOrganization || "" })] }), _jsx(EnhancedCheckbox, { label: t("formEmergencyContactLabel"), id: "emergencyContactFather", info: t("formFatherEmergencyContactInfo"), checked: emergencyContact === "Father", onCheckedChange: (checked) => handleChange("emergencyContact", checked ? "Father" : "") })] }), _jsx("div", { className: "lg:col-span-5", children: _jsxs(IdentityDocumentCard, { title: t("formIdentityDocumentLabel"), children: [_jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsx(GovernmentIdTypeSelect, { error: getTranslatedError({
|
|
149
|
+
errors,
|
|
150
|
+
key: "fatherIdType",
|
|
151
|
+
t,
|
|
152
|
+
}), id: "fatherIdType", onChange: (value) => handleChange("fatherIdType", value), required: true, value: fatherIdType }), _jsx(EnhancedInput, { error: getTranslatedError({
|
|
153
|
+
errors,
|
|
154
|
+
key: "fatherIdNumber",
|
|
155
|
+
t,
|
|
156
|
+
}), id: "fatherIdNumber", info: t("formFatherIdNumberInfo"), label: t("formIdNumberLabel"), onChange: (e) => handleChange("fatherIdNumber", e.target.value), placeholder: t("formIdNumberPlaceholder"), required: true, type: "text", value: fatherIdNumber || "" })] }), _jsx(IdImageField, { id: "fatherIdImages", info: t("formFatherIdImagesInfo"), label: t("formFatherIdImagesLabel"), onChange: (files) => dispatch({
|
|
157
|
+
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
158
|
+
payload: { key: "fatherIdImagesFiles", value: files },
|
|
159
|
+
}), onRemoveRemote: (url) => dispatch({
|
|
160
|
+
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
161
|
+
payload: {
|
|
162
|
+
key: "fatherIdImages",
|
|
163
|
+
value: (fatherIdImages || []).filter((item) => item !== url),
|
|
164
|
+
},
|
|
165
|
+
}), value: fatherIdImages || [] })] }) })] })] }), _jsx(Separator, {}), _jsxs("section", { className: "bg-card/40 space-y-4 rounded-xl border p-4 sm:p-5", children: [_jsx(SectionHeading, { icon: User, children: t("formSectionMotherInformation") }), _jsxs("div", { className: "grid gap-4 lg:grid-cols-12", children: [_jsxs("div", { className: "space-y-4 lg:col-span-7", children: [_jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsx(EnhancedInput, { error: getTranslatedError({
|
|
166
|
+
errors,
|
|
167
|
+
key: "motherFirstName",
|
|
168
|
+
t,
|
|
169
|
+
}), id: "motherFirstName", info: t("formMotherFirstNameInfo"), label: t("formFirstNameLabel"), onChange: (e) => handleChange("motherFirstName", e.target.value), placeholder: t("formFirstNamePlaceholder"), required: true, type: "text", value: motherFirstName || "" }), _jsx(EnhancedInput, { error: getTranslatedError({
|
|
170
|
+
errors,
|
|
171
|
+
key: "motherLastName",
|
|
172
|
+
t,
|
|
173
|
+
}), id: "motherLastName", info: t("formMotherLastNameInfo"), label: t("formLastNameLabel"), onChange: (e) => handleChange("motherLastName", e.target.value), placeholder: t("formLastNamePlaceholder"), required: true, type: "text", value: motherLastName || "" }), _jsx(PhoneInput, { error: getTranslatedError({
|
|
174
|
+
errors,
|
|
175
|
+
key: "motherMobile",
|
|
176
|
+
t,
|
|
177
|
+
}), id: "motherMobile", info: t("formMotherMobileInfo"), label: t("formMobileLabel"), onChange: (value) => handleChange("motherMobile", value), placeholder: t("formPhonePlaceholder"), required: true, value: motherMobile || "", defaultCountry: country || ((_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.country) || "PK", className: "sm:col-span-2" })] }), _jsx(EnhancedCheckbox, { label: t("formEmergencyContactLabel"), id: "emergencyContactMother", info: t("formMotherEmergencyContactInfo"), checked: emergencyContact === "Mother", onCheckedChange: (checked) => handleChange("emergencyContact", checked ? "Mother" : "") })] }), _jsx("div", { className: "lg:col-span-5", children: _jsxs(IdentityDocumentCard, { title: t("formIdentityDocumentLabel"), children: [_jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsx(GovernmentIdTypeSelect, { error: getTranslatedError({
|
|
178
|
+
errors,
|
|
179
|
+
key: "motherIdType",
|
|
180
|
+
t,
|
|
181
|
+
}), id: "motherIdType", onChange: (value) => handleChange("motherIdType", value), required: true, value: motherIdType }), _jsx(EnhancedInput, { error: getTranslatedError({
|
|
182
|
+
errors,
|
|
183
|
+
key: "motherIdNumber",
|
|
184
|
+
t,
|
|
185
|
+
}), id: "motherIdNumber", info: t("formMotherIdNumberInfo"), label: t("formIdNumberLabel"), onChange: (e) => handleChange("motherIdNumber", e.target.value), placeholder: t("formIdNumberPlaceholder"), required: true, type: "text", value: motherIdNumber || "" })] }), _jsx(IdImageField, { id: "motherIdImages", info: t("formMotherIdImagesInfo"), label: t("formMotherIdImagesLabel"), onChange: (files) => dispatch({
|
|
186
|
+
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
187
|
+
payload: { key: "motherIdImagesFiles", value: files },
|
|
188
|
+
}), onRemoveRemote: (url) => dispatch({
|
|
189
|
+
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
190
|
+
payload: {
|
|
191
|
+
key: "motherIdImages",
|
|
192
|
+
value: (motherIdImages || []).filter((item) => item !== url),
|
|
193
|
+
},
|
|
194
|
+
}), value: motherIdImages || [] })] }) })] })] }), _jsx(Separator, {}), _jsxs("section", { className: "space-y-4", children: [_jsx(SectionHeading, { icon: Home, children: t("formSectionHomeInformation") }), _jsxs("div", { className: "grid gap-4 sm:grid-cols-2 xl:grid-cols-4", children: [_jsx("div", { className: "sm:col-span-2 xl:col-span-4", children: _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "address", t }), id: "homeAddress", info: t("formHomeAddressInfo"), label: t("formHomeAddressLabel"), onChange: (e) => handleChange("address", e.target.value), placeholder: t("formHomeAddressPlaceholder"), required: true, rows: 2, value: address || "" }) }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "city", t }), id: "city", info: t("formCityInfo"), label: t("formCityLabel"), onChange: (e) => handleChange("city", e.target.value), placeholder: t("formCityPlaceholder"), required: true, type: "text", value: city || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "state", t }), id: "state", info: t("formStateInfo"), label: t("formStateLabel"), onChange: (e) => handleChange("state", e.target.value), placeholder: t("formStatePlaceholder"), required: true, type: "text", value: provinceState || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "country", t }), id: "country", info: t("formCountryInfo"), label: t("formCountryLabel"), onChange: (e) => handleChange("country", e.target.value), placeholder: t("formCountryPlaceholder"), required: true, type: "text", value: country || "" })] })] }), _jsx(Separator, {}), _jsxs("section", { className: "space-y-4", children: [_jsx(SectionHeading, { icon: GraduationCap, children: t("formSectionAdmissionInformation") }), _jsxs("div", { className: "grid gap-4 sm:grid-cols-2", children: [_jsx(EnhancedInput, { error: getTranslatedError({
|
|
195
|
+
errors,
|
|
196
|
+
key: "classForAdmission",
|
|
197
|
+
t,
|
|
198
|
+
}), id: "classForAdmission", info: t("formClassForAdmissionInfo"), label: t("formClassForAdmissionLabel"), onChange: (e) => handleChange("classForAdmission", e.target.value), placeholder: t("formClassForAdmissionPlaceholder"), required: true, type: "text", value: classForAdmission || "" }), _jsx(EnhancedInput, { error: getTranslatedError({
|
|
199
|
+
errors,
|
|
200
|
+
key: "previousSchool",
|
|
201
|
+
t,
|
|
202
|
+
}), id: "previousSchool", info: t("formPreviousSchoolInfo"), label: t("formPreviousSchoolLabel"), onChange: (e) => handleChange("previousSchool", e.target.value), placeholder: t("formPreviousSchoolPlaceholder"), type: "text", value: previousSchool || "" }), _jsx("div", { className: "sm:col-span-2", children: _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "siblings", t }), id: "siblings", info: t("formSiblingsInfo"), label: t("formSiblingsLabel"), onChange: (e) => handleChange("siblings", e.target.value), placeholder: t("formSiblingsPlaceholder"), rows: 3, value: siblings || "" }) })] })] }), _jsx(Separator, {}), _jsxs("section", { className: "space-y-4", children: [_jsx(SectionHeading, { icon: StickyNote, children: t("formSectionOfficeUse") }), _jsxs("div", { className: "grid gap-4 md:grid-cols-2", children: [_jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "notes", t }), id: "notes", info: t("formNotesInfo"), label: t("formNotesLabel"), onChange: (e) => handleChange("notes", e.target.value), placeholder: t("formNotesPlaceholder"), rows: 3, value: notes || "" }), _jsx(EnhancedTextarea, { error: getTranslatedError({
|
|
203
|
+
errors,
|
|
204
|
+
key: "admissionNotes",
|
|
205
|
+
t,
|
|
206
|
+
}), id: "admissionNotes", info: t("formAdmissionNotesInfo"), label: t("formAdmissionNotesLabel"), onChange: (e) => handleChange("admissionNotes", e.target.value), placeholder: t("formAdmissionNotesPlaceholder"), rows: 3, value: admissionNotes || "" })] })] }), _jsx(Separator, {}), _jsxs("section", { className: "space-y-4", children: [_jsx(SectionHeading, { icon: FileText, children: t("formSectionDocumentsLabel") }), _jsx(EnhancedDropzone, { accept: [
|
|
207
|
+
"application/pdf",
|
|
208
|
+
"image/jpeg",
|
|
209
|
+
"image/png",
|
|
210
|
+
"image/webp",
|
|
211
|
+
"application/msword",
|
|
212
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
213
|
+
], className: DOCUMENT_DROPZONE_CLASS, error: undefined, id: "documents", info: t("formDocumentsInfo"), label: t("formDocumentsLabel"), maxFiles: 10, maxSize: 10 * 1024 * 1024, onChange: (files) => dispatch({
|
|
214
|
+
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
215
|
+
payload: { key: "documentsFiles", value: files },
|
|
216
|
+
}), value: documents || [] })] })] }));
|
|
154
217
|
};
|
|
@@ -35,6 +35,7 @@ export declare const EXPENSE_ACTION_TYPES: {
|
|
|
35
35
|
amount: number;
|
|
36
36
|
approvedBy: string;
|
|
37
37
|
attachments: string[];
|
|
38
|
+
attachmentsFiles: File[];
|
|
38
39
|
category: EXPENSE_CATEGORY | "";
|
|
39
40
|
description: string;
|
|
40
41
|
enabled: boolean;
|
|
@@ -75,6 +76,7 @@ export declare const EXPENSE_ACTION_TYPES: {
|
|
|
75
76
|
amount: number;
|
|
76
77
|
approvedBy: string;
|
|
77
78
|
attachments: string[];
|
|
79
|
+
attachmentsFiles: File[];
|
|
78
80
|
category: EXPENSE_CATEGORY | "";
|
|
79
81
|
description: string;
|
|
80
82
|
enabled: boolean;
|
|
@@ -117,6 +119,7 @@ export declare const EXPENSE_ACTION_TYPES: {
|
|
|
117
119
|
amount: number;
|
|
118
120
|
approvedBy: string;
|
|
119
121
|
attachments: string[];
|
|
122
|
+
attachmentsFiles: File[];
|
|
120
123
|
category: EXPENSE_CATEGORY | "";
|
|
121
124
|
description: string;
|
|
122
125
|
enabled: boolean;
|
|
@@ -157,6 +160,7 @@ export declare const EXPENSE_ACTION_TYPES: {
|
|
|
157
160
|
amount: number;
|
|
158
161
|
approvedBy: string;
|
|
159
162
|
attachments: string[];
|
|
163
|
+
attachmentsFiles: File[];
|
|
160
164
|
category: EXPENSE_CATEGORY | "";
|
|
161
165
|
description: string;
|
|
162
166
|
enabled: boolean;
|
|
@@ -197,6 +201,7 @@ export declare const EXPENSE_ACTION_TYPES: {
|
|
|
197
201
|
amount: number;
|
|
198
202
|
approvedBy: string;
|
|
199
203
|
attachments: string[];
|
|
204
|
+
attachmentsFiles: File[];
|
|
200
205
|
category: EXPENSE_CATEGORY | "";
|
|
201
206
|
description: string;
|
|
202
207
|
enabled: boolean;
|
|
@@ -6,7 +6,7 @@ export declare const useExpenseModule: () => {
|
|
|
6
6
|
clearSearch: () => void;
|
|
7
7
|
closeDrawer: () => void;
|
|
8
8
|
deleteLoading: boolean;
|
|
9
|
-
handleChange: (field: string, value: string | number | boolean | string[] | undefined) => void;
|
|
9
|
+
handleChange: (field: string, value: string | number | boolean | string[] | File[] | undefined) => void;
|
|
10
10
|
handleCreate: () => void;
|
|
11
11
|
handleDelete: (row?: TableRow) => void;
|
|
12
12
|
handleEdit: (row?: TableRow) => void;
|
|
@@ -39,6 +39,7 @@ export declare const useExpenseModule: () => {
|
|
|
39
39
|
amount: number;
|
|
40
40
|
approvedBy: string;
|
|
41
41
|
attachments: string[];
|
|
42
|
+
attachmentsFiles: File[];
|
|
42
43
|
category: import("../../../types").EXPENSE_CATEGORY | "";
|
|
43
44
|
description: string;
|
|
44
45
|
enabled: boolean;
|
|
@@ -5,6 +5,7 @@ import { useTranslations } from "next-intl";
|
|
|
5
5
|
import { validateForm } from "@react-pakistan/util-functions/general/validate-form";
|
|
6
6
|
import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
|
|
7
7
|
import { getCachedWorkspaceSync } from "../../workspace/cache";
|
|
8
|
+
import { uploadFiles } from "../../../utils/upload-file";
|
|
8
9
|
import { expenseFormValidation } from "../validate";
|
|
9
10
|
import { EXPENSE_ACTION_TYPES, EXPENSE_DRAWER, useExpenseContext, } from "./shared";
|
|
10
11
|
import { useExpenseApiContext } from "./expense-api-provider";
|
|
@@ -87,6 +88,7 @@ export const useExpenseModule = () => {
|
|
|
87
88
|
amount: 0,
|
|
88
89
|
approvedBy: "",
|
|
89
90
|
attachments: [],
|
|
91
|
+
attachmentsFiles: [],
|
|
90
92
|
category: "",
|
|
91
93
|
description: "",
|
|
92
94
|
enabled: true,
|
|
@@ -224,10 +226,43 @@ export const useExpenseModule = () => {
|
|
|
224
226
|
validateForm({
|
|
225
227
|
params: updateParams,
|
|
226
228
|
schema: expenseFormValidation,
|
|
227
|
-
successCallback: () => {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
229
|
+
successCallback: async () => {
|
|
230
|
+
try {
|
|
231
|
+
let attachments = state.attachments || [];
|
|
232
|
+
if (state.attachmentsFiles.length > 0) {
|
|
233
|
+
if (!(workspace === null || workspace === void 0 ? void 0 : workspace.id)) {
|
|
234
|
+
throw new Error("Workspace context is not available");
|
|
235
|
+
}
|
|
236
|
+
const uploaded = await uploadFiles(state.attachmentsFiles, {
|
|
237
|
+
workspaceId: workspace.id,
|
|
238
|
+
formName: "expense",
|
|
239
|
+
});
|
|
240
|
+
attachments = [
|
|
241
|
+
...attachments.filter((url) => !url.startsWith("blob:")),
|
|
242
|
+
...uploaded.map((file) => file.url),
|
|
243
|
+
];
|
|
244
|
+
dispatch({
|
|
245
|
+
type: EXPENSE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
246
|
+
payload: { key: "attachments", value: attachments },
|
|
247
|
+
});
|
|
248
|
+
dispatch({
|
|
249
|
+
type: EXPENSE_ACTION_TYPES.SET_INPUT_FIELD,
|
|
250
|
+
payload: { key: "attachmentsFiles", value: [] },
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
updateFetchNow(undefined, {
|
|
254
|
+
body: JSON.stringify(Object.assign(Object.assign({}, updateParams), { attachments })),
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
catch (error) {
|
|
258
|
+
dispatch({
|
|
259
|
+
type: EXPENSE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
260
|
+
payload: { disabled: false },
|
|
261
|
+
});
|
|
262
|
+
showToast(error instanceof Error
|
|
263
|
+
? error.message
|
|
264
|
+
: t("messagesAttachmentsUploadFailed"), TOAST_VARIANT.ERROR);
|
|
265
|
+
}
|
|
231
266
|
},
|
|
232
267
|
errorCallback: (errors) => {
|
|
233
268
|
dispatch({
|
|
@@ -241,7 +276,16 @@ export const useExpenseModule = () => {
|
|
|
241
276
|
showToast(t("messagesFormErrors"), TOAST_VARIANT.ERROR);
|
|
242
277
|
},
|
|
243
278
|
});
|
|
244
|
-
}, [
|
|
279
|
+
}, [
|
|
280
|
+
dispatch,
|
|
281
|
+
updateParams,
|
|
282
|
+
updateFetchNow,
|
|
283
|
+
t,
|
|
284
|
+
showToast,
|
|
285
|
+
state.attachments,
|
|
286
|
+
state.attachmentsFiles,
|
|
287
|
+
workspace === null || workspace === void 0 ? void 0 : workspace.id,
|
|
288
|
+
]);
|
|
245
289
|
// ============================================================================
|
|
246
290
|
// 1.4.6 HEADER & ROW ACTIONS
|
|
247
291
|
// ============================================================================
|
|
@@ -66,8 +66,10 @@ export const ExpenseForm = () => {
|
|
|
66
66
|
value: opt.value,
|
|
67
67
|
label: paymentMethodLabelMap[opt.value] || opt.label,
|
|
68
68
|
})), placeholder: t("formPaymentMethodPlaceholder"), searchPlaceholder: t("formPaymentMethodPlaceholder"), value: paymentMethod || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "paymentDate", t }), id: "paymentDate", info: t("formPaymentDateInfo"), label: t("formPaymentDateLabel"), onChange: (e) => handleChange("paymentDate", 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: paymentDate || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "receiptNumber", t }), id: "receiptNumber", info: t("formReceiptNumberInfo"), label: t("formReceiptNumberLabel"), maxLength: 100, onChange: (e) => handleChange("receiptNumber", e.target.value), placeholder: t("formReceiptNumberPlaceholder"), type: "text", value: receiptNumber || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "transactionId", t }), id: "transactionId", info: t("formTransactionIdInfo"), label: t("formTransactionIdLabel"), maxLength: 100, onChange: (e) => handleChange("transactionId", e.target.value), placeholder: t("formTransactionIdPlaceholder"), type: "text", value: transactionId || "" })] })) : null, _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "remarks", t }), id: "remarks", label: t("formRemarksLabel"), maxLength: 1000, onChange: (e) => handleChange("remarks", e.target.value), placeholder: t("formRemarksPlaceholder"), rows: 3, value: remarks || "" }), _jsx(EnhancedDropzone, { accept: ["image/*", "application/pdf"], error: getTranslatedError({ errors, key: "attachments", t }), id: "attachments", info: t("formAttachmentsInfo"), label: t("formAttachmentsLabel"), maxFiles: 10, onChange: (files) => {
|
|
69
|
-
const
|
|
70
|
-
|
|
69
|
+
const remoteUrls = (attachments || []).filter((url) => !url.startsWith("blob:"));
|
|
70
|
+
const previewUrls = files.map((file) => URL.createObjectURL(file));
|
|
71
|
+
handleChange("attachments", [...remoteUrls, ...previewUrls]);
|
|
72
|
+
handleChange("attachmentsFiles", files);
|
|
71
73
|
}, onRemoveRemote: (url) => {
|
|
72
74
|
const newList = (attachments || []).filter((a) => a !== url);
|
|
73
75
|
handleChange("attachments", newList);
|