@appcorp/fusion-storybook 0.5.29 → 0.5.33
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.js +23 -29
- package/base-modules/admission/form.js +5 -19
- package/base-modules/admission/validate.d.ts +3 -2
- package/base-modules/admission/validate.js +10 -9
- package/base-modules/campus/context/use-campus-module.js +1 -2
- package/base-modules/campus/form.js +3 -5
- package/base-modules/campus/validate.d.ts +2 -2
- package/base-modules/campus/validate.js +3 -8
- package/base-modules/family/page.js +2 -1
- package/base-modules/family-member/context.js +2 -3
- package/base-modules/family-member/form.js +5 -8
- package/base-modules/family-member/page.js +6 -1
- package/base-modules/family-member/validate.d.ts +3 -2
- package/base-modules/family-member/validate.js +4 -3
- package/base-modules/push-campaign/form.js +13 -5
- package/base-modules/school/context.js +4 -6
- package/base-modules/school/form.js +2 -5
- package/base-modules/school/validate.d.ts +2 -1
- package/base-modules/school/validate.js +3 -6
- package/base-modules/student-profile/context/use-student-profile-module.js +2 -3
- package/base-modules/student-profile/form.js +3 -9
- package/base-modules/student-profile/validate.d.ts +2 -2
- package/base-modules/student-profile/validate.js +3 -9
- package/base-modules/teacher/form.js +5 -8
- package/base-modules/teacher/page.js +6 -1
- package/base-modules/teacher/validate.d.ts +3 -2
- package/base-modules/teacher/validate.js +4 -11
- package/base-modules/user/context/use-user-module.js +1 -2
- package/base-modules/user/form.js +5 -5
- package/base-modules/user/page.js +2 -1
- package/base-modules/user/validate.d.ts +1 -1
- package/base-modules/user/validate.js +2 -5
- package/components/phone-input.d.ts +21 -0
- package/components/phone-input.js +51 -0
- package/package.json +4 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/phone-validation.d.ts +15 -0
- package/utils/phone-validation.js +35 -0
- package/utils/phone.d.ts +25 -0
- package/utils/phone.js +145 -0
- package/utils/to-e164-phone.d.ts +9 -0
- package/utils/to-e164-phone.js +17 -5
|
@@ -20,7 +20,6 @@ import { compressPdf, DocumentTooLargeError, isPdfFile, MAX_DOCUMENT_SIZE_BYTES,
|
|
|
20
20
|
import { wakeStorageServer } from "../../../utils/wake-storage";
|
|
21
21
|
import { normalizeIdNumber } from "../../../utils/id-number";
|
|
22
22
|
import { toE164Phone } from "../../../utils/to-e164-phone";
|
|
23
|
-
import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
|
|
24
23
|
import { Filter, Plus } from "lucide-react";
|
|
25
24
|
import { ADMISSION_DRAWER, ADMISSION_ACTION_TYPES, useAdmissionContext, } from "../context";
|
|
26
25
|
export const useAdmissionModule = () => {
|
|
@@ -161,14 +160,9 @@ export const useAdmissionModule = () => {
|
|
|
161
160
|
});
|
|
162
161
|
}, [theme]);
|
|
163
162
|
const setField = useCallback((key, value) => {
|
|
164
|
-
|
|
165
|
-
let formatted = value === null
|
|
163
|
+
const formatted = value === null
|
|
166
164
|
? undefined
|
|
167
165
|
: value;
|
|
168
|
-
if ((key === "fatherMobile" || key === "motherMobile") &&
|
|
169
|
-
typeof value === "string") {
|
|
170
|
-
formatted = (_a = formatPhoneDisplay(value)) !== null && _a !== void 0 ? _a : value;
|
|
171
|
-
}
|
|
172
166
|
dispatch({
|
|
173
167
|
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
174
168
|
payload: { key, value: formatted || value },
|
|
@@ -218,7 +212,7 @@ export const useAdmissionModule = () => {
|
|
|
218
212
|
}
|
|
219
213
|
}, [resetFormAndCloseDrawer, showToast, t]);
|
|
220
214
|
const byIdCallback = useCallback(({ data, error }) => {
|
|
221
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12
|
|
215
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
|
|
222
216
|
if (error) {
|
|
223
217
|
showToast(t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
|
|
224
218
|
return;
|
|
@@ -253,35 +247,35 @@ export const useAdmissionModule = () => {
|
|
|
253
247
|
setField("fatherFirstName", (_m = admission.fatherDetails) === null || _m === void 0 ? void 0 : _m.fatherFirstName);
|
|
254
248
|
setField("fatherLastName", (_o = admission.fatherDetails) === null || _o === void 0 ? void 0 : _o.fatherLastName);
|
|
255
249
|
setField("fatherIdNumber", (_p = admission.fatherDetails) === null || _p === void 0 ? void 0 : _p.fatherIdNumber);
|
|
256
|
-
setField("fatherMobile", (_r =
|
|
257
|
-
setField("fatherOccupation", (
|
|
258
|
-
setField("fatherOrganization", (
|
|
259
|
-
setField("motherFirstName", (
|
|
260
|
-
setField("motherLastName", (
|
|
261
|
-
setField("motherIdNumber", (
|
|
262
|
-
setField("motherMobile", (
|
|
263
|
-
setField("address", (
|
|
264
|
-
setField("city", (
|
|
265
|
-
setField("country", (
|
|
266
|
-
setField("postalCode", (
|
|
267
|
-
setField("state", (
|
|
268
|
-
setField("notes", (
|
|
269
|
-
setField("admissionNotes", (
|
|
270
|
-
setField("previousSchool", (
|
|
271
|
-
setField("siblings", (
|
|
250
|
+
setField("fatherMobile", (_r = (_q = admission.fatherDetails) === null || _q === void 0 ? void 0 : _q.fatherMobile) !== null && _r !== void 0 ? _r : undefined);
|
|
251
|
+
setField("fatherOccupation", (_s = admission.fatherDetails) === null || _s === void 0 ? void 0 : _s.fatherOccupation);
|
|
252
|
+
setField("fatherOrganization", (_t = admission.fatherDetails) === null || _t === void 0 ? void 0 : _t.fatherOrganization);
|
|
253
|
+
setField("motherFirstName", (_u = admission.motherDetails) === null || _u === void 0 ? void 0 : _u.motherFirstName);
|
|
254
|
+
setField("motherLastName", (_v = admission.motherDetails) === null || _v === void 0 ? void 0 : _v.motherLastName);
|
|
255
|
+
setField("motherIdNumber", (_w = admission.motherDetails) === null || _w === void 0 ? void 0 : _w.motherIdNumber);
|
|
256
|
+
setField("motherMobile", (_y = (_x = admission.motherDetails) === null || _x === void 0 ? void 0 : _x.motherMobile) !== null && _y !== void 0 ? _y : undefined);
|
|
257
|
+
setField("address", (_z = admission.homeDetails) === null || _z === void 0 ? void 0 : _z.address);
|
|
258
|
+
setField("city", (_0 = admission.homeDetails) === null || _0 === void 0 ? void 0 : _0.city);
|
|
259
|
+
setField("country", (_1 = admission.homeDetails) === null || _1 === void 0 ? void 0 : _1.country);
|
|
260
|
+
setField("postalCode", (_2 = admission.homeDetails) === null || _2 === void 0 ? void 0 : _2.postalCode);
|
|
261
|
+
setField("state", (_3 = admission.homeDetails) === null || _3 === void 0 ? void 0 : _3.state);
|
|
262
|
+
setField("notes", (_4 = admission.officeUse) === null || _4 === void 0 ? void 0 : _4.notes);
|
|
263
|
+
setField("admissionNotes", (_5 = admission.officeUse) === null || _5 === void 0 ? void 0 : _5.admissionNotes);
|
|
264
|
+
setField("previousSchool", (_6 = admission.admissionDetails) === null || _6 === void 0 ? void 0 : _6.previousSchool);
|
|
265
|
+
setField("siblings", (_7 = admission.admissionDetails) === null || _7 === void 0 ? void 0 : _7.siblings);
|
|
272
266
|
dispatch({
|
|
273
267
|
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
274
268
|
payload: {
|
|
275
269
|
key: "documents",
|
|
276
|
-
value: (
|
|
270
|
+
value: (_9 = (_8 = admission.admissionDetails) === null || _8 === void 0 ? void 0 : _8.documents) !== null && _9 !== void 0 ? _9 : [],
|
|
277
271
|
},
|
|
278
272
|
});
|
|
279
|
-
setField("classForAdmission", (
|
|
273
|
+
setField("classForAdmission", (_10 = admission.admissionDetails) === null || _10 === void 0 ? void 0 : _10.classForAdmission);
|
|
280
274
|
setField("status", admission.status || ADMISSION_STATUS.PENDING);
|
|
281
|
-
setField("enabled", (
|
|
275
|
+
setField("enabled", (_11 = admission.enabled) !== null && _11 !== void 0 ? _11 : true);
|
|
282
276
|
// Populate AI analysis if present
|
|
283
|
-
const aiAnalysis = (
|
|
284
|
-
.aiAnalysis) !== null &&
|
|
277
|
+
const aiAnalysis = (_12 = admission
|
|
278
|
+
.aiAnalysis) !== null && _12 !== void 0 ? _12 : null;
|
|
285
279
|
dispatch({
|
|
286
280
|
type: ADMISSION_ACTION_TYPES.SET_FORM_DATA,
|
|
287
281
|
payload: { form: { aiAnalysis } },
|
|
@@ -19,7 +19,7 @@ import { Separator } from "@appcorp/shadcn/components/ui/separator";
|
|
|
19
19
|
import { useAdmissionModule, ADMISSION_ACTION_TYPES } from "./context";
|
|
20
20
|
import { useEffect } from "react";
|
|
21
21
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
22
|
-
import {
|
|
22
|
+
import { PhoneInput } from "../../components/phone-input";
|
|
23
23
|
import { VALUE_DELIMITER } from "@react-pakistan/util-functions/constants/select-value-delimiter";
|
|
24
24
|
import { v4 as uuidv4 } from "uuid";
|
|
25
25
|
import { GENDER_OPTIONS } from "./constants";
|
|
@@ -27,7 +27,7 @@ import { DISCOUNT_CODE_API_ROUTES } from "../../constants";
|
|
|
27
27
|
import { useTranslations } from "next-intl";
|
|
28
28
|
import { getTranslatedError } from "../../utils/get-translated-error";
|
|
29
29
|
export const AdmissionForm = () => {
|
|
30
|
-
var _a;
|
|
30
|
+
var _a, _b, _c;
|
|
31
31
|
const { state, handleChange, dispatch, discountCodes } = useAdmissionModule();
|
|
32
32
|
const { address, admissionNotes, studentIdNumber, city, classForAdmission, country, discountCodeId, dob, documents, emergencyContact, errors, fatherIdNumber, fatherFirstName, fatherLastName, fatherMobile, fatherOccupation, fatherOrganization, firstName, gender, id, lastName, motherIdNumber, motherFirstName, motherLastName, motherMobile, notes, previousSchool, registrationCode, siblings, state: provinceState, } = state;
|
|
33
33
|
const t = useTranslations("admission");
|
|
@@ -71,7 +71,7 @@ export const AdmissionForm = () => {
|
|
|
71
71
|
value: discountCodeId || "",
|
|
72
72
|
});
|
|
73
73
|
useEffect(() => {
|
|
74
|
-
var _a, _b, _c, _d
|
|
74
|
+
var _a, _b, _c, _d;
|
|
75
75
|
if (!id) {
|
|
76
76
|
dispatch({
|
|
77
77
|
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
@@ -85,25 +85,11 @@ export const AdmissionForm = () => {
|
|
|
85
85
|
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
86
86
|
payload: { key: "country", value: ((_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.country) || "" },
|
|
87
87
|
});
|
|
88
|
-
dispatch({
|
|
89
|
-
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
90
|
-
payload: {
|
|
91
|
-
key: "fatherMobile",
|
|
92
|
-
value: getDialCode(((_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.country) || "PK") || "",
|
|
93
|
-
},
|
|
94
|
-
});
|
|
95
|
-
dispatch({
|
|
96
|
-
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
97
|
-
payload: {
|
|
98
|
-
key: "motherMobile",
|
|
99
|
-
value: getDialCode(((_e = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _e === void 0 ? void 0 : _e.country) || "PK") || "",
|
|
100
|
-
},
|
|
101
|
-
});
|
|
102
88
|
dispatch({
|
|
103
89
|
type: ADMISSION_ACTION_TYPES.SET_INPUT_FIELD,
|
|
104
90
|
payload: {
|
|
105
91
|
key: "registrationCode",
|
|
106
|
-
value: `${(
|
|
92
|
+
value: `${(_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.code}${VALUE_DELIMITER.COLON}${uuidv4()
|
|
107
93
|
.slice(0, 8)
|
|
108
94
|
.toUpperCase()}`,
|
|
109
95
|
},
|
|
@@ -111,7 +97,7 @@ export const AdmissionForm = () => {
|
|
|
111
97
|
}
|
|
112
98
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
113
99
|
}, [id, dispatch]);
|
|
114
|
-
return (_jsxs("div", { className: "grid grid-cols-1 gap-2 space-y-2", children: [_jsx("h4", { className: "m-0 p-0", children: t("formSectionStudentInformation") }), _jsxs("div", { className: "grid grid-cols-5 gap-4", 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: "studentIdNumber", t }), id: "studentIdNumber", info: t("formStudentIdNumberInfo"), label: t("formStudentIdNumberLabel"), onChange: (e) => handleChange("studentIdNumber", e.target.value), placeholder: t("formStudentIdNumberPlaceholder"), required: true, type: "text", value: studentIdNumber || "" }), genderCombo, _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 || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "registrationCode", t }), 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, _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(Separator, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionFatherInformation") }), _jsxs("div", { className: "grid grid-cols-6 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "fatherFirstName", t }), 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({ errors, key: "fatherLastName", t }), 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(EnhancedInput, { error: getTranslatedError({ errors, key: "fatherIdNumber", t }), 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(EnhancedInput, { error: getTranslatedError({ errors, key: "fatherMobile", t }), id: "fatherMobile", info: t("formFatherMobileInfo"), label: t("formMobileLabel"), onChange: (e) => handleChange("fatherMobile", e.target.value), placeholder: "+923001234567", required: true, type: "text", value: fatherMobile || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "fatherOccupation", t }), 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({ errors, key: "fatherOrganization", t }), 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(Separator, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionMotherInformation") }), _jsxs("div", { className: "grid grid-cols-6 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "motherFirstName", t }), 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({ errors, key: "motherLastName", t }), 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(EnhancedInput, { error: getTranslatedError({ errors, key: "motherIdNumber", t }), 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(EnhancedInput, { error: getTranslatedError({ errors, key: "motherMobile", t }), id: "motherMobile", info: t("formMotherMobileInfo"), label: t("formMobileLabel"), onChange: (e) => handleChange("motherMobile", e.target.value), placeholder: "+923001234567", required: true, type: "text", value: motherMobile || "" }), _jsx(EnhancedCheckbox, { label: t("formEmergencyContactLabel"), id: "emergencyContactMother", info: t("formMotherEmergencyContactInfo"), checked: emergencyContact === "Mother", onCheckedChange: (checked) => handleChange("emergencyContact", checked ? "Mother" : "") })] }), _jsx(Separator, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionHomeInformation") }), _jsxs("div", { className: "grid grid-cols-6 gap-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, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionAdmissionInformation") }), _jsxs("div", { className: "grid grid-cols-6 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "classForAdmission", t }), 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({ errors, key: "previousSchool", t }), id: "previousSchool", info: t("formPreviousSchoolInfo"), label: t("formPreviousSchoolLabel"), onChange: (e) => handleChange("previousSchool", e.target.value), placeholder: t("formPreviousSchoolPlaceholder"), type: "text", value: previousSchool || "" }), _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, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionOfficeUse") }), _jsxs("div", { className: "grid grid-cols-4 gap-4", 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({ errors, key: "admissionNotes", t }), id: "admissionNotes", info: t("formAdmissionNotesInfo"), label: t("formAdmissionNotesLabel"), onChange: (e) => handleChange("admissionNotes", e.target.value), placeholder: t("formAdmissionNotesPlaceholder"), rows: 3, value: admissionNotes || "" })] }), _jsx(Separator, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionDocumentsLabel") }), _jsx(EnhancedDropzone, { accept: [
|
|
100
|
+
return (_jsxs("div", { className: "grid grid-cols-1 gap-2 space-y-2", children: [_jsx("h4", { className: "m-0 p-0", children: t("formSectionStudentInformation") }), _jsxs("div", { className: "grid grid-cols-5 gap-4", 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: "studentIdNumber", t }), id: "studentIdNumber", info: t("formStudentIdNumberInfo"), label: t("formStudentIdNumberLabel"), onChange: (e) => handleChange("studentIdNumber", e.target.value), placeholder: t("formStudentIdNumberPlaceholder"), required: true, type: "text", value: studentIdNumber || "" }), genderCombo, _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 || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "registrationCode", t }), 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, _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(Separator, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionFatherInformation") }), _jsxs("div", { className: "grid grid-cols-6 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "fatherFirstName", t }), 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({ errors, key: "fatherLastName", t }), 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(EnhancedInput, { error: getTranslatedError({ errors, key: "fatherIdNumber", t }), 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(PhoneInput, { error: getTranslatedError({ errors, key: "fatherMobile", t }), 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: "col-span-2" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "fatherOccupation", t }), 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({ errors, key: "fatherOrganization", t }), 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(Separator, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionMotherInformation") }), _jsxs("div", { className: "grid grid-cols-6 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "motherFirstName", t }), 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({ errors, key: "motherLastName", t }), 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(EnhancedInput, { error: getTranslatedError({ errors, key: "motherIdNumber", t }), 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(PhoneInput, { error: getTranslatedError({ errors, key: "motherMobile", t }), 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: "col-span-2" }), _jsx(EnhancedCheckbox, { label: t("formEmergencyContactLabel"), id: "emergencyContactMother", info: t("formMotherEmergencyContactInfo"), checked: emergencyContact === "Mother", onCheckedChange: (checked) => handleChange("emergencyContact", checked ? "Mother" : "") })] }), _jsx(Separator, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionHomeInformation") }), _jsxs("div", { className: "grid grid-cols-6 gap-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, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionAdmissionInformation") }), _jsxs("div", { className: "grid grid-cols-6 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "classForAdmission", t }), 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({ errors, key: "previousSchool", t }), id: "previousSchool", info: t("formPreviousSchoolInfo"), label: t("formPreviousSchoolLabel"), onChange: (e) => handleChange("previousSchool", e.target.value), placeholder: t("formPreviousSchoolPlaceholder"), type: "text", value: previousSchool || "" }), _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, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionOfficeUse") }), _jsxs("div", { className: "grid grid-cols-4 gap-4", 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({ errors, key: "admissionNotes", t }), id: "admissionNotes", info: t("formAdmissionNotesInfo"), label: t("formAdmissionNotesLabel"), onChange: (e) => handleChange("admissionNotes", e.target.value), placeholder: t("formAdmissionNotesPlaceholder"), rows: 3, value: admissionNotes || "" })] }), _jsx(Separator, {}), _jsx("h4", { className: "m-0 p-0", children: t("formSectionDocumentsLabel") }), _jsx(EnhancedDropzone, { accept: [
|
|
115
101
|
"application/pdf",
|
|
116
102
|
"image/jpeg",
|
|
117
103
|
"image/png",
|
|
@@ -26,6 +26,7 @@ export declare const VALIDATION_KEYS: {
|
|
|
26
26
|
readonly state: "validationRequiredState";
|
|
27
27
|
readonly country: "validationRequiredCountry";
|
|
28
28
|
readonly classForAdmission: "validationRequiredClassForAdmission";
|
|
29
|
+
readonly phoneInvalid: "validationAdmissionPhoneInvalid";
|
|
29
30
|
};
|
|
30
31
|
export declare const admissionFormValidation: z.ZodObject<{
|
|
31
32
|
registrationCode: z.ZodString;
|
|
@@ -40,13 +41,13 @@ export declare const admissionFormValidation: z.ZodObject<{
|
|
|
40
41
|
fatherFirstName: z.ZodString;
|
|
41
42
|
fatherLastName: z.ZodString;
|
|
42
43
|
fatherIdNumber: z.ZodPipe<z.ZodString, z.ZodTransform<string | null | undefined, string>>;
|
|
43
|
-
fatherMobile: z.ZodPipe<z.ZodString
|
|
44
|
+
fatherMobile: z.ZodPreprocess<z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>, unknown>;
|
|
44
45
|
fatherOccupation: z.ZodOptional<z.ZodString>;
|
|
45
46
|
fatherOrganization: z.ZodOptional<z.ZodString>;
|
|
46
47
|
motherFirstName: z.ZodString;
|
|
47
48
|
motherLastName: z.ZodString;
|
|
48
49
|
motherIdNumber: z.ZodPipe<z.ZodString, z.ZodTransform<string | null | undefined, string>>;
|
|
49
|
-
motherMobile: z.ZodPipe<z.ZodString
|
|
50
|
+
motherMobile: z.ZodPreprocess<z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>, unknown>;
|
|
50
51
|
address: z.ZodString;
|
|
51
52
|
city: z.ZodString;
|
|
52
53
|
state: z.ZodString;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { GENDER } from "../../type";
|
|
8
8
|
import { normalizeIdNumber } from "../../utils/id-number";
|
|
9
|
-
import {
|
|
9
|
+
import { phoneSchema } from "../../utils/phone-validation";
|
|
10
10
|
// ============================================================================
|
|
11
11
|
// VALIDATION KEYS
|
|
12
12
|
// ============================================================================
|
|
@@ -31,6 +31,7 @@ export const VALIDATION_KEYS = {
|
|
|
31
31
|
state: "validationRequiredState",
|
|
32
32
|
country: "validationRequiredCountry",
|
|
33
33
|
classForAdmission: "validationRequiredClassForAdmission",
|
|
34
|
+
phoneInvalid: "validationAdmissionPhoneInvalid",
|
|
34
35
|
};
|
|
35
36
|
// ============================================================================
|
|
36
37
|
// VALIDATION SCHEMA
|
|
@@ -70,10 +71,10 @@ export const admissionFormValidation = z.object({
|
|
|
70
71
|
.string()
|
|
71
72
|
.min(1, VALIDATION_KEYS.fatherIdNumber)
|
|
72
73
|
.transform(normalizeIdNumber),
|
|
73
|
-
fatherMobile:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
fatherMobile: phoneSchema(VALIDATION_KEYS.phoneInvalid, {
|
|
75
|
+
required: true,
|
|
76
|
+
requiredErrorKey: VALIDATION_KEYS.fatherMobile,
|
|
77
|
+
}),
|
|
77
78
|
fatherOccupation: z.string().optional(),
|
|
78
79
|
fatherOrganization: z.string().optional(),
|
|
79
80
|
// Mother Information
|
|
@@ -83,10 +84,10 @@ export const admissionFormValidation = z.object({
|
|
|
83
84
|
.string()
|
|
84
85
|
.min(1, VALIDATION_KEYS.motherIdNumber)
|
|
85
86
|
.transform(normalizeIdNumber),
|
|
86
|
-
motherMobile:
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
motherMobile: phoneSchema(VALIDATION_KEYS.phoneInvalid, {
|
|
88
|
+
required: true,
|
|
89
|
+
requiredErrorKey: VALIDATION_KEYS.motherMobile,
|
|
90
|
+
}),
|
|
90
91
|
// Home Information
|
|
91
92
|
address: z.string().min(1, VALIDATION_KEYS.address),
|
|
92
93
|
city: z.string().min(1, VALIDATION_KEYS.city),
|
|
@@ -24,7 +24,6 @@ import { validateForm } from "@react-pakistan/util-functions/general/validate-fo
|
|
|
24
24
|
import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-module-entity-v2";
|
|
25
25
|
import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
|
|
26
26
|
import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
|
|
27
|
-
import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
|
|
28
27
|
import { toE164Phone } from "../../../utils/to-e164-phone";
|
|
29
28
|
import { CAMPUS_API_ROUTES } from "../../../constants";
|
|
30
29
|
import { campusFormValidation } from "../validate";
|
|
@@ -187,7 +186,7 @@ export const useCampusModule = () => {
|
|
|
187
186
|
dispatch({
|
|
188
187
|
type: CAMPUS_ACTION_TYPES.SET_FORM_DATA,
|
|
189
188
|
payload: {
|
|
190
|
-
form: Object.assign(Object.assign({}, campus), { classCount: (_b = (_a = campus._count) === null || _a === void 0 ? void 0 : _a.classes) !== null && _b !== void 0 ? _b : 0, teacherCount: (_d = (_c = campus._count) === null || _c === void 0 ? void 0 : _c.teachers) !== null && _d !== void 0 ? _d : 0, studentCount: (_f = (_e = campus._count) === null || _e === void 0 ? void 0 : _e.studentProfiles) !== null && _f !== void 0 ? _f : 0, phone:
|
|
189
|
+
form: Object.assign(Object.assign({}, campus), { classCount: (_b = (_a = campus._count) === null || _a === void 0 ? void 0 : _a.classes) !== null && _b !== void 0 ? _b : 0, teacherCount: (_d = (_c = campus._count) === null || _c === void 0 ? void 0 : _c.teachers) !== null && _d !== void 0 ? _d : 0, studentCount: (_f = (_e = campus._count) === null || _e === void 0 ? void 0 : _e.studentProfiles) !== null && _f !== void 0 ? _f : 0, phone: campus.phone || "" }),
|
|
191
190
|
},
|
|
192
191
|
});
|
|
193
192
|
}
|
|
@@ -7,18 +7,16 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
7
7
|
*/
|
|
8
8
|
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
9
9
|
import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
|
|
10
|
+
import { PhoneInput } from "../../components/phone-input";
|
|
10
11
|
import { useCampusModule } from "./context";
|
|
11
12
|
import { useTranslations } from "next-intl";
|
|
12
|
-
import { formatPhone } from "@react-pakistan/util-functions/general/format-phone";
|
|
13
13
|
import { getTranslatedError } from "../../utils/get-translated-error";
|
|
14
14
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
15
15
|
export const CampusForm = () => {
|
|
16
|
+
var _a;
|
|
16
17
|
const { state, handleChange } = useCampusModule();
|
|
17
18
|
const { address, city, code, country, enabled, errors, name, phone, state: campusState, } = state;
|
|
18
19
|
const t = useTranslations("campus");
|
|
19
20
|
const workspace = getCachedWorkspaceSync();
|
|
20
|
-
return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "name", t }), id: "name", info: t("formCampusNameInfo"), label: t("formCampusNameLabel"), maxLength: 100, onChange: (e) => handleChange("name", e.target.value), placeholder: t("formCampusNamePlaceholder"), required: true, value: name }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "code", t }), id: "code", info: t("formCampusCodeInfo"), label: t("formCampusCodeLabel"), maxLength: 20, onChange: (e) => handleChange("code", e.target.value), placeholder: t("formCampusCodePlaceholder"), required: true, value: code }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "address", t }), id: "address", info: t("formAddressInfo"), label: t("formAddressLabel"), maxLength: 255, onChange: (e) => handleChange("address", e.target.value), placeholder: t("formAddressPlaceholder"), value: address || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "city", t }), id: "city", info: t("formCityInfo"), label: t("formCityLabel"), maxLength: 100, onChange: (e) => handleChange("city", e.target.value), placeholder: t("formCityPlaceholder"), value: city || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "state", t }), id: "state", info: t("formStateInfo"), label: t("formStateLabel"), maxLength: 100, onChange: (e) => handleChange("state", e.target.value), placeholder: t("formStatePlaceholder"), value: campusState || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "country", t }), id: "country", info: t("formCountryInfo"), label: t("formCountryLabel"), maxLength: 100, onChange: (e) => handleChange("country", e.target.value), placeholder: t("formCountryPlaceholder"), value: country || "" }), _jsx(
|
|
21
|
-
var _a, _b;
|
|
22
|
-
return handleChange("phone", ((_b = formatPhone(e.target.value, (((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.country) || "PK"))) === null || _b === void 0 ? void 0 : _b.international) || e.target.value);
|
|
23
|
-
}, placeholder: t("formPhonePlaceholder"), value: phone || "" }), _jsx(EnhancedCheckbox, { checked: enabled, id: "enabled", info: t("formActiveCampusInfo"), label: t("formActiveCampusLabel"), onCheckedChange: (checked) => handleChange("enabled", checked) })] }));
|
|
21
|
+
return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "name", t }), id: "name", info: t("formCampusNameInfo"), label: t("formCampusNameLabel"), maxLength: 100, onChange: (e) => handleChange("name", e.target.value), placeholder: t("formCampusNamePlaceholder"), required: true, value: name }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "code", t }), id: "code", info: t("formCampusCodeInfo"), label: t("formCampusCodeLabel"), maxLength: 20, onChange: (e) => handleChange("code", e.target.value), placeholder: t("formCampusCodePlaceholder"), required: true, value: code }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "address", t }), id: "address", info: t("formAddressInfo"), label: t("formAddressLabel"), maxLength: 255, onChange: (e) => handleChange("address", e.target.value), placeholder: t("formAddressPlaceholder"), value: address || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "city", t }), id: "city", info: t("formCityInfo"), label: t("formCityLabel"), maxLength: 100, onChange: (e) => handleChange("city", e.target.value), placeholder: t("formCityPlaceholder"), value: city || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "state", t }), id: "state", info: t("formStateInfo"), label: t("formStateLabel"), maxLength: 100, onChange: (e) => handleChange("state", e.target.value), placeholder: t("formStatePlaceholder"), value: campusState || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "country", t }), id: "country", info: t("formCountryInfo"), label: t("formCountryLabel"), maxLength: 100, onChange: (e) => handleChange("country", e.target.value), placeholder: t("formCountryPlaceholder"), value: country || "" }), _jsx(PhoneInput, { error: getTranslatedError({ errors, key: "phone", t }), id: "phone", info: t("formPhoneInfo"), label: t("formPhoneLabel"), onChange: (value) => handleChange("phone", value), placeholder: t("formPhonePlaceholder"), value: phone || "", defaultCountry: country || ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.country) || "PK" }), _jsx(EnhancedCheckbox, { checked: enabled, id: "enabled", info: t("formActiveCampusInfo"), label: t("formActiveCampusLabel"), onCheckedChange: (checked) => handleChange("enabled", checked) })] }));
|
|
24
22
|
};
|
|
@@ -10,7 +10,7 @@ export declare const VALIDATION_KEYS: {
|
|
|
10
10
|
readonly cityMaxLength: "validationCampusCityMaxLength";
|
|
11
11
|
readonly stateMaxLength: "validationCampusStateMaxLength";
|
|
12
12
|
readonly countryMaxLength: "validationCampusCountryMaxLength";
|
|
13
|
-
readonly
|
|
13
|
+
readonly phoneInvalid: "validationCampusPhoneInvalid";
|
|
14
14
|
};
|
|
15
15
|
export declare const campusFormValidation: z.ZodObject<{
|
|
16
16
|
name: z.ZodString;
|
|
@@ -19,6 +19,6 @@ export declare const campusFormValidation: z.ZodObject<{
|
|
|
19
19
|
city: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
20
20
|
state: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
21
21
|
country: z.ZodNullable<z.ZodOptional<z.ZodString>>;
|
|
22
|
-
phone: z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined
|
|
22
|
+
phone: z.ZodPreprocess<z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>, unknown>;
|
|
23
23
|
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
24
24
|
}, z.core.$strip>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { phoneSchema } from "../../utils/phone-validation";
|
|
3
3
|
export const VALIDATION_KEYS = {
|
|
4
4
|
nameRequired: "validationCampusNameRequired",
|
|
5
5
|
nameMaxLength: "validationCampusNameMaxLength",
|
|
@@ -11,7 +11,7 @@ export const VALIDATION_KEYS = {
|
|
|
11
11
|
cityMaxLength: "validationCampusCityMaxLength",
|
|
12
12
|
stateMaxLength: "validationCampusStateMaxLength",
|
|
13
13
|
countryMaxLength: "validationCampusCountryMaxLength",
|
|
14
|
-
|
|
14
|
+
phoneInvalid: "validationCampusPhoneInvalid",
|
|
15
15
|
};
|
|
16
16
|
export const campusFormValidation = z.object({
|
|
17
17
|
name: z
|
|
@@ -47,11 +47,6 @@ export const campusFormValidation = z.object({
|
|
|
47
47
|
.max(100, VALIDATION_KEYS.countryMaxLength)
|
|
48
48
|
.optional()
|
|
49
49
|
.nullable(),
|
|
50
|
-
phone:
|
|
51
|
-
.string()
|
|
52
|
-
.max(30, VALIDATION_KEYS.phoneMaxLength)
|
|
53
|
-
.optional()
|
|
54
|
-
.nullable()
|
|
55
|
-
.transform((val) => { var _a; return (val ? ((_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val) : val); }),
|
|
50
|
+
phone: phoneSchema(VALIDATION_KEYS.phoneInvalid),
|
|
56
51
|
enabled: z.boolean().optional(),
|
|
57
52
|
});
|
|
@@ -22,6 +22,7 @@ import { FamilyFilter } from "./filter";
|
|
|
22
22
|
import { FamilyForm } from "./form";
|
|
23
23
|
import { FamilyView } from "./view";
|
|
24
24
|
import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
|
|
25
|
+
import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
|
|
25
26
|
import { RbacNoAccess } from "../../components/rbac-no-access";
|
|
26
27
|
// ============================================================================
|
|
27
28
|
// TABLE COLUMN CONFIGURATION (static — no runtime deps)
|
|
@@ -36,7 +37,7 @@ const tableBodyCols = [
|
|
|
36
37
|
var _a, _b;
|
|
37
38
|
const members = (_a = row.members) !== null && _a !== void 0 ? _a : [];
|
|
38
39
|
const contact = (_b = members.find((member) => member.isPrimary && member.enabled)) !== null && _b !== void 0 ? _b : members.find((member) => member.enabled && member.role !== "STUDENT");
|
|
39
|
-
return (contact === null || contact === void 0 ? void 0 : contact.email) || (contact === null || contact === void 0 ? void 0 : contact.phone) || "—";
|
|
40
|
+
return (contact === null || contact === void 0 ? void 0 : contact.email) || formatPhoneDisplay(contact === null || contact === void 0 ? void 0 : contact.phone) || "—";
|
|
40
41
|
},
|
|
41
42
|
},
|
|
42
43
|
{ componentType: COMPONENT_TYPE.TEXT, key: "address" },
|
|
@@ -31,7 +31,6 @@ import { normalizeIdNumber } from "../../utils/id-number";
|
|
|
31
31
|
import { FAMILY_MEMBER_API_ROUTES } from "../../constants";
|
|
32
32
|
import { familyMemberFormValidation } from "./validate";
|
|
33
33
|
import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
|
|
34
|
-
import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
|
|
35
34
|
import { toE164Phone } from "../../utils/to-e164-phone";
|
|
36
35
|
import { useTranslations } from "next-intl";
|
|
37
36
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
@@ -256,7 +255,7 @@ export const useFamilyMemberModule = () => {
|
|
|
256
255
|
bloodGroup: (_b = member.bloodGroup) !== null && _b !== void 0 ? _b : "",
|
|
257
256
|
dateOfBirth: toDateInput(member.dateOfBirth),
|
|
258
257
|
email: (_c = member.email) !== null && _c !== void 0 ? _c : "",
|
|
259
|
-
emergencyPhone:
|
|
258
|
+
emergencyPhone: member.emergencyPhone || "",
|
|
260
259
|
enabled: member.enabled,
|
|
261
260
|
familyId: member.familyId,
|
|
262
261
|
firstName: member.firstName,
|
|
@@ -267,7 +266,7 @@ export const useFamilyMemberModule = () => {
|
|
|
267
266
|
isPrimary: member.isPrimary,
|
|
268
267
|
lastName: member.lastName,
|
|
269
268
|
occupation: (_d = member.occupation) !== null && _d !== void 0 ? _d : "",
|
|
270
|
-
phone:
|
|
269
|
+
phone: member.phone || "",
|
|
271
270
|
relationship: member.relationship,
|
|
272
271
|
role: member.role,
|
|
273
272
|
},
|
|
@@ -10,14 +10,17 @@ import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
|
|
|
10
10
|
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
11
11
|
import { useFamilyMemberModule } from "./context";
|
|
12
12
|
import { useTranslations } from "next-intl";
|
|
13
|
-
import {
|
|
13
|
+
import { PhoneInput } from "../../components/phone-input";
|
|
14
|
+
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
14
15
|
import { getTranslatedError } from "../../utils/get-translated-error";
|
|
15
16
|
import { FAMILY_MEMBER_ROLE_OPTIONS, GENDER_OPTIONS } from "./constants";
|
|
16
17
|
import { toDateInput } from "./date";
|
|
17
18
|
export const FamilyMemberForm = () => {
|
|
19
|
+
var _a, _b;
|
|
18
20
|
const { handleChange, state } = useFamilyMemberModule();
|
|
19
21
|
const { bloodGroup, dateOfBirth, email, emergencyPhone, enabled, errors, firstName, gender, hasStudentProfile, idNumber, isPrimary, lastName, occupation, phone, relationship, role, } = state;
|
|
20
22
|
const t = useTranslations("familyMember");
|
|
23
|
+
const workspace = getCachedWorkspaceSync();
|
|
21
24
|
const roleLabelMap = {
|
|
22
25
|
FATHER: t("formRoleOptionFather"),
|
|
23
26
|
MOTHER: t("formRoleOptionMother"),
|
|
@@ -38,11 +41,5 @@ export const FamilyMemberForm = () => {
|
|
|
38
41
|
})), placeholder: t("formRolePlaceholder"), required: true, searchPlaceholder: t("formRolePlaceholder"), value: role }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "dateOfBirth", t }), id: "dateOfBirth", info: t("formDateOfBirthInfo"), label: t("formDateOfBirthLabel"), onChange: (e) => handleChange("dateOfBirth", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, placeholder: "YYYY-MM-DD", type: "date", value: toDateInput(dateOfBirth) })] }), _jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: [_jsx(EnhancedCombobox, { emptyText: t("formNoGenderEmpty"), error: getTranslatedError({ errors, key: "gender", t }), id: "gender", info: t("formGenderInfo"), label: t("formGenderLabel"), onValueChange: (value) => handleChange("gender", value), options: GENDER_OPTIONS.map((opt) => ({
|
|
39
42
|
value: opt.value,
|
|
40
43
|
label: genderLabelMap[opt.value] || opt.label,
|
|
41
|
-
})), placeholder: t("formGenderPlaceholder"), searchPlaceholder: t("formGenderPlaceholder"), value: gender }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "bloodGroup", t }), id: "bloodGroup", info: t("formBloodGroupInfo"), label: t("formBloodGroupLabel"), onChange: (e) => handleChange("bloodGroup", e.target.value), placeholder: t("formBloodGroupPlaceholder"), value: bloodGroup })] }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "idNumber", t }), id: "idNumber", info: t("formIdNumberInfo"), label: t("formIdNumberLabel"), onChange: (e) => handleChange("idNumber", e.target.value), placeholder: t("formIdNumberPlaceholder"), value: idNumber })] }), _jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: t("formSectionContactInformation") }), _jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: [_jsx(
|
|
42
|
-
var _a;
|
|
43
|
-
return handleChange("phone", ((_a = formatPhone(e.target.value)) === null || _a === void 0 ? void 0 : _a.international) || e.target.value);
|
|
44
|
-
}, placeholder: t("formPhonePlaceholder"), type: "tel", value: phone }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "email", t }), id: "email", info: t("formEmailInfo"), label: t("formEmailLabel"), onChange: (e) => handleChange("email", e.target.value), placeholder: t("formEmailPlaceholder"), type: "email", value: email })] }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "emergencyPhone", t }), id: "emergencyPhone", info: t("formEmergencyPhoneInfo"), label: t("formEmergencyPhoneLabel"), onChange: (e) => {
|
|
45
|
-
var _a;
|
|
46
|
-
return handleChange("emergencyPhone", ((_a = formatPhone(e.target.value)) === null || _a === void 0 ? void 0 : _a.international) || e.target.value);
|
|
47
|
-
}, placeholder: t("formEmergencyPhonePlaceholder"), type: "tel", value: emergencyPhone })] }), _jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: t("formSectionAdditionalInformation") }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "relationship", t }), id: "relationship", info: t("formRelationshipInfo"), label: t("formRelationshipLabel"), onChange: (e) => handleChange("relationship", e.target.value), placeholder: t("formRelationshipPlaceholder"), value: relationship }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "occupation", t }), id: "occupation", info: t("formOccupationInfo"), label: t("formOccupationLabel"), onChange: (e) => handleChange("occupation", e.target.value), placeholder: t("formOccupationPlaceholder"), value: occupation })] }), _jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: t("formSectionStatus") }), _jsxs("div", { className: "flex items-center gap-4", children: [_jsx(EnhancedCheckbox, { checked: isPrimary, id: "isPrimary", label: t("formPrimaryContactLabel"), onCheckedChange: (checked) => handleChange("isPrimary", checked === true) }), _jsx(EnhancedCheckbox, { checked: enabled, id: "enabled", label: t("badgeActive"), onCheckedChange: (checked) => handleChange("enabled", checked === true) })] })] })] }));
|
|
44
|
+
})), placeholder: t("formGenderPlaceholder"), searchPlaceholder: t("formGenderPlaceholder"), value: gender }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "bloodGroup", t }), id: "bloodGroup", info: t("formBloodGroupInfo"), label: t("formBloodGroupLabel"), onChange: (e) => handleChange("bloodGroup", e.target.value), placeholder: t("formBloodGroupPlaceholder"), value: bloodGroup })] }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "idNumber", t }), id: "idNumber", info: t("formIdNumberInfo"), label: t("formIdNumberLabel"), onChange: (e) => handleChange("idNumber", e.target.value), placeholder: t("formIdNumberPlaceholder"), value: idNumber })] }), _jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: t("formSectionContactInformation") }), _jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: [_jsx(PhoneInput, { error: getTranslatedError({ errors, key: "phone", t }), id: "phone", info: t("formPhoneInfo"), label: t("formPhoneLabel"), onChange: (value) => handleChange("phone", value), placeholder: t("formPhonePlaceholder"), value: phone || "", defaultCountry: ((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.country) || "PK" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "email", t }), id: "email", info: t("formEmailInfo"), label: t("formEmailLabel"), onChange: (e) => handleChange("email", e.target.value), placeholder: t("formEmailPlaceholder"), type: "email", value: email })] }), _jsx(PhoneInput, { error: getTranslatedError({ errors, key: "emergencyPhone", t }), id: "emergencyPhone", info: t("formEmergencyPhoneInfo"), label: t("formEmergencyPhoneLabel"), onChange: (value) => handleChange("emergencyPhone", value), placeholder: t("formEmergencyPhonePlaceholder"), value: emergencyPhone || "", defaultCountry: ((_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.country) || "PK" })] }), _jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: t("formSectionAdditionalInformation") }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "relationship", t }), id: "relationship", info: t("formRelationshipInfo"), label: t("formRelationshipLabel"), onChange: (e) => handleChange("relationship", e.target.value), placeholder: t("formRelationshipPlaceholder"), value: relationship }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "occupation", t }), id: "occupation", info: t("formOccupationInfo"), label: t("formOccupationLabel"), onChange: (e) => handleChange("occupation", e.target.value), placeholder: t("formOccupationPlaceholder"), value: occupation })] }), _jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: t("formSectionStatus") }), _jsxs("div", { className: "flex items-center gap-4", children: [_jsx(EnhancedCheckbox, { checked: isPrimary, id: "isPrimary", label: t("formPrimaryContactLabel"), onCheckedChange: (checked) => handleChange("isPrimary", checked === true) }), _jsx(EnhancedCheckbox, { checked: enabled, id: "enabled", label: t("badgeActive"), onCheckedChange: (checked) => handleChange("enabled", checked === true) })] })] })] }));
|
|
48
45
|
};
|
|
@@ -22,6 +22,7 @@ import { FamilyMemberFilter } from "./filter";
|
|
|
22
22
|
import { FamilyMemberForm } from "./form";
|
|
23
23
|
import { FamilyMemberView } from "./view";
|
|
24
24
|
import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
|
|
25
|
+
import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
|
|
25
26
|
import { RbacNoAccess } from "../../components/rbac-no-access";
|
|
26
27
|
// ============================================================================
|
|
27
28
|
// TABLE COLUMN CONFIGURATION (static — no runtime deps)
|
|
@@ -41,7 +42,11 @@ const tableBodyCols = [
|
|
|
41
42
|
textFormatter: formatRole,
|
|
42
43
|
},
|
|
43
44
|
{ componentType: COMPONENT_TYPE.TEXT, key: "email" },
|
|
44
|
-
{
|
|
45
|
+
{
|
|
46
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
47
|
+
key: "phone",
|
|
48
|
+
textFormatter: (_, row) => formatPhoneDisplay(row === null || row === void 0 ? void 0 : row.phone),
|
|
49
|
+
},
|
|
45
50
|
{ componentType: COMPONENT_TYPE.BOOLEAN, key: "isPrimary" },
|
|
46
51
|
{ componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
|
|
47
52
|
{ componentType: COMPONENT_TYPE.ACTIONS },
|
|
@@ -11,6 +11,7 @@ export declare const VALIDATION_KEYS: {
|
|
|
11
11
|
readonly role: "validationFamilyMemberRoleRequired";
|
|
12
12
|
readonly emailInvalid: "validationFamilyMemberEmailInvalid";
|
|
13
13
|
readonly idForUpdate: "validationFamilyMemberIdForUpdateRequired";
|
|
14
|
+
readonly phoneInvalid: "validationFamilyMemberPhoneInvalid";
|
|
14
15
|
};
|
|
15
16
|
export declare const familyMemberFormValidation: z.ZodObject<{
|
|
16
17
|
familyId: z.ZodString;
|
|
@@ -20,11 +21,11 @@ export declare const familyMemberFormValidation: z.ZodObject<{
|
|
|
20
21
|
dateOfBirth: z.ZodOptional<z.ZodString>;
|
|
21
22
|
gender: z.ZodOptional<z.ZodString>;
|
|
22
23
|
bloodGroup: z.ZodOptional<z.ZodString>;
|
|
23
|
-
phone: z.ZodPipe<z.ZodOptional<z.ZodString
|
|
24
|
+
phone: z.ZodPreprocess<z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>, unknown>;
|
|
24
25
|
email: z.ZodUnion<[z.ZodOptional<z.ZodString>, z.ZodLiteral<"">]>;
|
|
25
26
|
relationship: z.ZodOptional<z.ZodString>;
|
|
26
27
|
occupation: z.ZodOptional<z.ZodString>;
|
|
27
|
-
emergencyPhone: z.ZodPipe<z.ZodOptional<z.ZodString
|
|
28
|
+
emergencyPhone: z.ZodPreprocess<z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>, unknown>;
|
|
28
29
|
idNumber: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | null | undefined, string | undefined>>;
|
|
29
30
|
avatar: z.ZodOptional<z.ZodString>;
|
|
30
31
|
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { normalizeIdNumber } from "../../utils/id-number";
|
|
8
|
-
import {
|
|
8
|
+
import { phoneSchema } from "../../utils/phone-validation";
|
|
9
9
|
// ============================================================================
|
|
10
10
|
// VALIDATION KEYS (used as Zod error messages, translated via getTranslatedError)
|
|
11
11
|
// ============================================================================
|
|
@@ -16,6 +16,7 @@ export const VALIDATION_KEYS = {
|
|
|
16
16
|
role: "validationFamilyMemberRoleRequired",
|
|
17
17
|
emailInvalid: "validationFamilyMemberEmailInvalid",
|
|
18
18
|
idForUpdate: "validationFamilyMemberIdForUpdateRequired",
|
|
19
|
+
phoneInvalid: "validationFamilyMemberPhoneInvalid",
|
|
19
20
|
};
|
|
20
21
|
// ============================================================================
|
|
21
22
|
// VALIDATION SCHEMA
|
|
@@ -28,7 +29,7 @@ export const familyMemberFormValidation = z.object({
|
|
|
28
29
|
dateOfBirth: z.string().optional(),
|
|
29
30
|
gender: z.string().optional(),
|
|
30
31
|
bloodGroup: z.string().optional(),
|
|
31
|
-
phone:
|
|
32
|
+
phone: phoneSchema(VALIDATION_KEYS.phoneInvalid),
|
|
32
33
|
email: z
|
|
33
34
|
.string()
|
|
34
35
|
.email(VALIDATION_KEYS.emailInvalid)
|
|
@@ -36,7 +37,7 @@ export const familyMemberFormValidation = z.object({
|
|
|
36
37
|
.or(z.literal("")),
|
|
37
38
|
relationship: z.string().optional(),
|
|
38
39
|
occupation: z.string().optional(),
|
|
39
|
-
emergencyPhone:
|
|
40
|
+
emergencyPhone: phoneSchema(VALIDATION_KEYS.phoneInvalid),
|
|
40
41
|
idNumber: z.string().optional().transform((val) => (val ? normalizeIdNumber(val) : val)),
|
|
41
42
|
avatar: z.string().optional(),
|
|
42
43
|
isPrimary: z.boolean().optional(),
|
|
@@ -23,16 +23,24 @@ export const PushCampaignForm = () => {
|
|
|
23
23
|
const { allStudents, audience, body, errors, enabled, name, scheduledAt, status, title, aiCheckLoading, aiCheckPassed, aiCheckScore, aiSuggestions, } = context.state;
|
|
24
24
|
const { handleAiCheck, handleChange, } = context;
|
|
25
25
|
const workspace = getCachedWorkspaceSync();
|
|
26
|
-
const
|
|
27
|
-
|
|
26
|
+
const classConfig = useMemo(() => ({
|
|
27
|
+
method: API_METHODS.GET,
|
|
28
|
+
params: { workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id },
|
|
29
|
+
}), [workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
30
|
+
const sectionConfig = useMemo(() => ({
|
|
31
|
+
method: API_METHODS.GET,
|
|
32
|
+
params: { workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id },
|
|
33
|
+
}), [workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
34
|
+
const { fetchNow: classFetchNow, data: classData } = useFetch(CLASS_API_ROUTES.UNIT, classConfig);
|
|
35
|
+
const { fetchNow: sectionFetchNow, data: sectionData } = useFetch(SECTION_API_ROUTES.UNIT, sectionConfig);
|
|
28
36
|
useEffect(() => {
|
|
29
37
|
if (workspace === null || workspace === void 0 ? void 0 : workspace.id) {
|
|
30
38
|
classFetchNow();
|
|
31
39
|
sectionFetchNow();
|
|
32
40
|
}
|
|
33
|
-
}, [workspace === null || workspace === void 0 ? void 0 : workspace.id]);
|
|
34
|
-
const classes = (classData === null || classData === void 0 ? void 0 : classData.items) || [];
|
|
35
|
-
const sections = (sectionData === null || sectionData === void 0 ? void 0 : sectionData.items) || [];
|
|
41
|
+
}, [workspace === null || workspace === void 0 ? void 0 : workspace.id, classFetchNow, sectionFetchNow]);
|
|
42
|
+
const classes = useMemo(() => (classData === null || classData === void 0 ? void 0 : classData.items) || [], [classData === null || classData === void 0 ? void 0 : classData.items]);
|
|
43
|
+
const sections = useMemo(() => (sectionData === null || sectionData === void 0 ? void 0 : sectionData.items) || [], [sectionData === null || sectionData === void 0 ? void 0 : sectionData.items]);
|
|
36
44
|
const sectionsByClass = useMemo(() => {
|
|
37
45
|
const map = {};
|
|
38
46
|
sections.forEach((s) => {
|