@appcorp/fusion-storybook 0.5.27 → 0.5.31

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.
Files changed (47) hide show
  1. package/base-modules/admission/context/use-admission-module.js +23 -29
  2. package/base-modules/admission/form.js +5 -19
  3. package/base-modules/admission/validate.d.ts +3 -2
  4. package/base-modules/admission/validate.js +10 -9
  5. package/base-modules/campus/context/use-campus-module.js +1 -2
  6. package/base-modules/campus/form.js +3 -5
  7. package/base-modules/campus/validate.d.ts +2 -2
  8. package/base-modules/campus/validate.js +3 -8
  9. package/base-modules/family/page.js +2 -1
  10. package/base-modules/family-member/context.js +2 -3
  11. package/base-modules/family-member/form.js +5 -8
  12. package/base-modules/family-member/page.js +6 -1
  13. package/base-modules/family-member/validate.d.ts +3 -2
  14. package/base-modules/family-member/validate.js +4 -3
  15. package/base-modules/push-campaign/form.js +13 -5
  16. package/base-modules/school/context.js +4 -6
  17. package/base-modules/school/form.js +2 -5
  18. package/base-modules/school/validate.d.ts +2 -1
  19. package/base-modules/school/validate.js +3 -6
  20. package/base-modules/student-fee/constants.d.ts +1 -0
  21. package/base-modules/student-fee/constants.js +8 -0
  22. package/base-modules/student-fee/misc-1.js +5 -10
  23. package/base-modules/student-profile/context/use-student-profile-module.js +2 -3
  24. package/base-modules/student-profile/form.js +3 -9
  25. package/base-modules/student-profile/validate.d.ts +2 -2
  26. package/base-modules/student-profile/validate.js +3 -9
  27. package/base-modules/teacher/form.js +5 -8
  28. package/base-modules/teacher/page.js +6 -1
  29. package/base-modules/teacher/validate.d.ts +3 -2
  30. package/base-modules/teacher/validate.js +4 -11
  31. package/base-modules/user/context/use-user-module.js +1 -2
  32. package/base-modules/user/form.js +5 -5
  33. package/base-modules/user/page.js +2 -1
  34. package/base-modules/user/validate.d.ts +1 -1
  35. package/base-modules/user/validate.js +2 -5
  36. package/base-modules/workspace/constants.js +1 -1
  37. package/base-modules/workspace/view.js +5 -4
  38. package/components/phone-input.d.ts +21 -0
  39. package/components/phone-input.js +44 -0
  40. package/package.json +4 -1
  41. package/tsconfig.build.tsbuildinfo +1 -1
  42. package/utils/phone-validation.d.ts +15 -0
  43. package/utils/phone-validation.js +35 -0
  44. package/utils/phone.d.ts +25 -0
  45. package/utils/phone.js +145 -0
  46. package/utils/to-e164-phone.d.ts +9 -0
  47. package/utils/to-e164-phone.js +17 -5
@@ -29,7 +29,6 @@ import { SCHOOL_API_ROUTES } from "../../constants";
29
29
  import { invalidateSchoolCache } from "./cache";
30
30
  import { schoolFormValidation } from "./validate";
31
31
  import { getCachedWorkspaceSync, setCachedWorkspace } from "../workspace/cache";
32
- import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
33
32
  import { toE164Phone } from "../../utils/to-e164-phone";
34
33
  // ============================================================================
35
34
  // 1.1 DRAWER TYPES
@@ -175,7 +174,7 @@ export const useSchoolModule = () => {
175
174
  dispatch({
176
175
  type: SCHOOL_ACTION_TYPES.SET_FORM_DATA,
177
176
  payload: {
178
- form: Object.assign(Object.assign({}, school), { phone: formatPhoneDisplay(school.phone) || "" }),
177
+ form: Object.assign(Object.assign({}, school), { phone: school.phone || "" }),
179
178
  },
180
179
  });
181
180
  }, [dispatch]);
@@ -195,7 +194,7 @@ export const useSchoolModule = () => {
195
194
  dispatch({
196
195
  type: SCHOOL_ACTION_TYPES.SET_FORM_DATA,
197
196
  payload: {
198
- form: Object.assign(Object.assign({}, school), { phone: formatPhoneDisplay(school.phone) || "" }),
197
+ form: Object.assign(Object.assign({}, school), { phone: school.phone || "" }),
199
198
  },
200
199
  });
201
200
  // The sidebar and every module read the workspace cache.
@@ -218,8 +217,7 @@ export const useSchoolModule = () => {
218
217
  dispatch({
219
218
  type: SCHOOL_ACTION_TYPES.SET_FORM_DATA,
220
219
  payload: {
221
- form: Object.assign(Object.assign({}, data), { phone: formatPhoneDisplay(data.phone) ||
222
- "" }),
220
+ form: Object.assign(Object.assign({}, data), { phone: data.phone || "" }),
223
221
  },
224
222
  });
225
223
  }
@@ -333,7 +331,7 @@ export const useSchoolModule = () => {
333
331
  dispatch({
334
332
  type: SCHOOL_ACTION_TYPES.SET_FORM_DATA,
335
333
  payload: {
336
- form: Object.assign(Object.assign({}, workspace.school), { phone: formatPhoneDisplay(workspace.school.phone) || "" }),
334
+ form: Object.assign(Object.assign({}, workspace.school), { phone: workspace.school.phone || "" }),
337
335
  },
338
336
  });
339
337
  }
@@ -11,7 +11,7 @@ import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
11
11
  import { useSchoolModule } from "./context";
12
12
  import { CURRENCY } from "../../type";
13
13
  import { useTranslations } from "next-intl";
14
- import { formatPhone } from "@react-pakistan/util-functions/general/format-phone";
14
+ import { PhoneInput } from "../../components/phone-input";
15
15
  import { getTranslatedError } from "../../utils/get-translated-error";
16
16
  export const SchoolForm = () => {
17
17
  const t = useTranslations("school");
@@ -39,8 +39,5 @@ export const SchoolForm = () => {
39
39
  // searchPlaceholder: t("formPrincipalSearchPlaceholder"),
40
40
  // value: principalId || "",
41
41
  // });
42
- return (_jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { id: "name", label: t("formNameLabel"), value: name, onChange: (e) => handleChange("name", e.target.value), error: getTranslatedError({ errors, key: "name", t }), placeholder: t("formNamePlaceholder"), required: true }), _jsx(EnhancedInput, { id: "code", label: t("formCodeLabel"), value: code, onChange: (e) => handleChange("code", e.target.value), error: getTranslatedError({ errors, key: "code", t }), placeholder: t("formCodePlaceholder"), required: true, info: t("formCodeInfo") }), currencyCombo, _jsx(EnhancedInput, { id: "address", label: t("formAddressLabel"), value: address || "", onChange: (e) => handleChange("address", e.target.value), error: getTranslatedError({ errors, key: "address", t }), placeholder: t("formAddressPlaceholder") }), _jsx(EnhancedInput, { id: "city", label: t("formCityLabel"), value: city || "", onChange: (e) => handleChange("city", e.target.value), error: getTranslatedError({ errors, key: "city", t }), placeholder: t("formCityPlaceholder") }), _jsx(EnhancedInput, { id: "state", label: t("formStateLabel"), value: stateField || "", onChange: (e) => handleChange("state", e.target.value), error: getTranslatedError({ errors, key: "state", t }), placeholder: t("formStatePlaceholder") }), _jsx(EnhancedInput, { id: "country", label: t("formCountryLabel"), value: country || "", onChange: (e) => handleChange("country", e.target.value), error: getTranslatedError({ errors, key: "country", t }), placeholder: t("formCountryPlaceholder") }), _jsx(EnhancedInput, { id: "postalCode", label: t("formPostalCodeLabel"), value: postalCode || "", onChange: (e) => handleChange("postalCode", e.target.value), error: getTranslatedError({ errors, key: "postalCode", t }), placeholder: t("formPostalCodePlaceholder") }), _jsx(EnhancedInput, { id: "phone", label: t("formPhoneLabel"), value: phone || "", onChange: (e) => {
43
- var _a;
44
- return handleChange("phone", ((_a = formatPhone(e.target.value)) === null || _a === void 0 ? void 0 : _a.international) || e.target.value);
45
- }, error: getTranslatedError({ errors, key: "phone", t }), placeholder: t("formPhonePlaceholder"), type: "tel" }), _jsx(EnhancedInput, { id: "email", label: t("formEmailLabel"), value: email || "", onChange: (e) => handleChange("email", e.target.value), error: getTranslatedError({ errors, key: "email", t }), placeholder: t("formEmailPlaceholder"), type: "email" })] }), _jsx(EnhancedInput, { id: "website", label: t("formWebsiteLabel"), value: website || "", onChange: (e) => handleChange("website", e.target.value), error: getTranslatedError({ errors, key: "website", t }), placeholder: t("formWebsitePlaceholder"), type: "url" }), _jsx(EnhancedInput, { id: "logo", label: t("formLogoLabel"), value: logo || "", onChange: (e) => handleChange("logo", e.target.value), error: getTranslatedError({ errors, key: "logo", t }), placeholder: t("formLogoPlaceholder"), type: "url" }), _jsx(EnhancedCheckbox, { id: "enabled", label: t("formEnabledLabel"), checked: enabled, error: getTranslatedError({ errors, key: "enabled", t }), onCheckedChange: (checked) => handleChange("enabled", checked), info: t("formEnabledInfo") })] }));
42
+ return (_jsxs("div", { className: "space-y-6", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { id: "name", label: t("formNameLabel"), value: name, onChange: (e) => handleChange("name", e.target.value), error: getTranslatedError({ errors, key: "name", t }), placeholder: t("formNamePlaceholder"), required: true }), _jsx(EnhancedInput, { id: "code", label: t("formCodeLabel"), value: code, onChange: (e) => handleChange("code", e.target.value), error: getTranslatedError({ errors, key: "code", t }), placeholder: t("formCodePlaceholder"), required: true, info: t("formCodeInfo") }), currencyCombo, _jsx(EnhancedInput, { id: "address", label: t("formAddressLabel"), value: address || "", onChange: (e) => handleChange("address", e.target.value), error: getTranslatedError({ errors, key: "address", t }), placeholder: t("formAddressPlaceholder") }), _jsx(EnhancedInput, { id: "city", label: t("formCityLabel"), value: city || "", onChange: (e) => handleChange("city", e.target.value), error: getTranslatedError({ errors, key: "city", t }), placeholder: t("formCityPlaceholder") }), _jsx(EnhancedInput, { id: "state", label: t("formStateLabel"), value: stateField || "", onChange: (e) => handleChange("state", e.target.value), error: getTranslatedError({ errors, key: "state", t }), placeholder: t("formStatePlaceholder") }), _jsx(EnhancedInput, { id: "country", label: t("formCountryLabel"), value: country || "", onChange: (e) => handleChange("country", e.target.value), error: getTranslatedError({ errors, key: "country", t }), placeholder: t("formCountryPlaceholder") }), _jsx(EnhancedInput, { id: "postalCode", label: t("formPostalCodeLabel"), value: postalCode || "", onChange: (e) => handleChange("postalCode", e.target.value), error: getTranslatedError({ errors, key: "postalCode", t }), placeholder: t("formPostalCodePlaceholder") }), _jsx(PhoneInput, { id: "phone", label: t("formPhoneLabel"), value: phone || "", onChange: (value) => handleChange("phone", value), error: getTranslatedError({ errors, key: "phone", t }), placeholder: t("formPhonePlaceholder"), defaultCountry: country || "PK" }), _jsx(EnhancedInput, { id: "email", label: t("formEmailLabel"), value: email || "", onChange: (e) => handleChange("email", e.target.value), error: getTranslatedError({ errors, key: "email", t }), placeholder: t("formEmailPlaceholder"), type: "email" })] }), _jsx(EnhancedInput, { id: "website", label: t("formWebsiteLabel"), value: website || "", onChange: (e) => handleChange("website", e.target.value), error: getTranslatedError({ errors, key: "website", t }), placeholder: t("formWebsitePlaceholder"), type: "url" }), _jsx(EnhancedInput, { id: "logo", label: t("formLogoLabel"), value: logo || "", onChange: (e) => handleChange("logo", e.target.value), error: getTranslatedError({ errors, key: "logo", t }), placeholder: t("formLogoPlaceholder"), type: "url" }), _jsx(EnhancedCheckbox, { id: "enabled", label: t("formEnabledLabel"), checked: enabled, error: getTranslatedError({ errors, key: "enabled", t }), onCheckedChange: (checked) => handleChange("enabled", checked), info: t("formEnabledInfo") })] }));
46
43
  };
@@ -11,6 +11,7 @@ export declare const VALIDATION_KEYS: {
11
11
  readonly email: "validationSchoolEmailInvalid";
12
12
  readonly website: "validationSchoolWebsiteInvalid";
13
13
  readonly currency: "validationSchoolCurrencyRequired";
14
+ readonly phoneInvalid: "validationSchoolPhoneInvalid";
14
15
  };
15
16
  export declare const schoolFormValidation: z.ZodObject<{
16
17
  workspaceId: z.ZodString;
@@ -21,7 +22,7 @@ export declare const schoolFormValidation: z.ZodObject<{
21
22
  state: z.ZodOptional<z.ZodNullable<z.ZodString>>;
22
23
  country: z.ZodOptional<z.ZodNullable<z.ZodString>>;
23
24
  postalCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
24
- phone: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>;
25
+ phone: z.ZodPreprocess<z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>, unknown>;
25
26
  email: z.ZodOptional<z.ZodNullable<z.ZodString>>;
26
27
  website: z.ZodOptional<z.ZodNullable<z.ZodString>>;
27
28
  logo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -4,7 +4,7 @@
4
4
  * Zod validation schemas for account-school form data.
5
5
  */
6
6
  import { z } from "zod";
7
- import { toE164Phone } from "../../utils/to-e164-phone";
7
+ import { phoneSchema } from "../../utils/phone-validation";
8
8
  // ============================================================================
9
9
  // VALIDATION KEYS
10
10
  // ============================================================================
@@ -15,6 +15,7 @@ export const VALIDATION_KEYS = {
15
15
  email: "validationSchoolEmailInvalid",
16
16
  website: "validationSchoolWebsiteInvalid",
17
17
  currency: "validationSchoolCurrencyRequired",
18
+ phoneInvalid: "validationSchoolPhoneInvalid",
18
19
  };
19
20
  // ============================================================================
20
21
  // VALIDATION SCHEMA
@@ -28,11 +29,7 @@ export const schoolFormValidation = z.object({
28
29
  state: z.string().nullable().optional(),
29
30
  country: z.string().nullable().optional(),
30
31
  postalCode: z.string().nullable().optional(),
31
- phone: z
32
- .string()
33
- .nullable()
34
- .optional()
35
- .transform((val) => { var _a; return (val ? (_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val : val); }),
32
+ phone: phoneSchema(VALIDATION_KEYS.phoneInvalid),
36
33
  email: z.string().email(VALIDATION_KEYS.email).nullable().optional(),
37
34
  website: z.string().url(VALIDATION_KEYS.website).nullable().optional(),
38
35
  logo: z.string().nullable().optional(),
@@ -8,6 +8,7 @@
8
8
  */
9
9
  import { PAYMENT_STATUS } from "../../type";
10
10
  export declare const pageLimit: number;
11
+ export declare const MONTHLY_CHECKBOX_KEYS: readonly ["formMonthlyCheckStudentProfile", "formMonthlyCheckFeeStructure", "formMonthlyCheckReady"];
11
12
  export declare const filterDateDefaults: () => {
12
13
  filterFromDate: string;
13
14
  filterToDate: string;
@@ -12,6 +12,14 @@ import { PAYMENT_STATUS } from "../../type";
12
12
  // ============================================================================
13
13
  export const pageLimit = Number(process.env.NEXT_PUBLIC_PAGE_LIMIT) || 10;
14
14
  // ============================================================================
15
+ // MONTHLY CREATION CHECKLIST
16
+ // ============================================================================
17
+ export const MONTHLY_CHECKBOX_KEYS = [
18
+ "formMonthlyCheckStudentProfile",
19
+ "formMonthlyCheckFeeStructure",
20
+ "formMonthlyCheckReady",
21
+ ];
22
+ // ============================================================================
15
23
  // FILTER DATE DEFAULTS
16
24
  // ============================================================================
17
25
  export const filterDateDefaults = () => {
@@ -10,24 +10,19 @@ import { useCallback, useState } from "react";
10
10
  import { STUDENT_FEE_ACTION_TYPES, useStudentFeeModule } from "./context";
11
11
  import { useTranslations } from "next-intl";
12
12
  import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
13
- const CHECKBOX_KEYS = [
14
- "formMonthlyCheckStudentProfile",
15
- "formMonthlyCheckFeeStructure",
16
- "formMonthlyCheckGmail",
17
- "formMonthlyCheckReady",
18
- ];
13
+ import { MONTHLY_CHECKBOX_KEYS } from "./constants";
19
14
  export const StudentFeeMonthly = () => {
20
15
  const t = useTranslations("studentFee");
21
16
  const { dispatch } = useStudentFeeModule();
22
- const [checked, setChecked] = useState(Object.fromEntries(CHECKBOX_KEYS.map((key) => [key, false])));
23
- // const allChecked = CHECKBOX_KEYS.every((key) => checked[key]);
17
+ const [checked, setChecked] = useState(Object.fromEntries(MONTHLY_CHECKBOX_KEYS.map((key) => [key, false])));
18
+ // const allChecked = MONTHLY_CHECKBOX_KEYS.every((key) => checked[key]);
24
19
  const handleCheckChange = useCallback((key, value) => {
25
20
  const next = Object.assign(Object.assign({}, checked), { [key]: value });
26
21
  setChecked(next);
27
22
  dispatch({
28
23
  type: STUDENT_FEE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
29
- payload: { disabled: !CHECKBOX_KEYS.every((k) => next[k]) },
24
+ payload: { disabled: !MONTHLY_CHECKBOX_KEYS.every((k) => next[k]) },
30
25
  });
31
26
  }, [checked, dispatch]);
32
- return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx("p", { className: "text-foreground text-sm", children: t("formMonthlyWarningMessage") }), _jsx("div", { className: "flex flex-col gap-3", children: CHECKBOX_KEYS.map((key) => (_jsx(EnhancedCheckbox, { checked: checked[key], id: key, label: t(key), onCheckedChange: (value) => handleCheckChange(key, value) }, key))) })] }));
27
+ return (_jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx("p", { className: "text-foreground text-sm", children: t("formMonthlyWarningMessage") }), _jsx("div", { className: "flex flex-col gap-3", children: MONTHLY_CHECKBOX_KEYS.map((key) => (_jsx(EnhancedCheckbox, { checked: checked[key], id: key, label: t(key), onCheckedChange: (value) => handleCheckChange(key, value) }, key))) })] }));
33
28
  };
@@ -9,7 +9,6 @@ import { useModuleEntityV2, } from "@react-pakistan/util-functions/hooks/use-mod
9
9
  import { useDebounce } from "@react-pakistan/util-functions/hooks/use-debounce";
10
10
  import { generateThemeToast, TOAST_VARIANT, } from "@appcorp/shadcn/lib/toast-utils";
11
11
  import { STUDENT_STATUS } from "../../../type";
12
- import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
13
12
  import { toE164Phone } from "../../../utils/to-e164-phone";
14
13
  import { STUDENT_PROFILE_API_ROUTES } from "../../../constants";
15
14
  import { studentProfileFormValidation } from "../validate";
@@ -213,9 +212,9 @@ export const useStudentProfileModule = () => {
213
212
  dateOfBirth: (_f = fm === null || fm === void 0 ? void 0 : fm.dateOfBirth) !== null && _f !== void 0 ? _f : null,
214
213
  gender: (_g = fm === null || fm === void 0 ? void 0 : fm.gender) !== null && _g !== void 0 ? _g : null,
215
214
  bloodGroup: (_h = fm === null || fm === void 0 ? void 0 : fm.bloodGroup) !== null && _h !== void 0 ? _h : null,
216
- phone: (_j = formatPhoneDisplay(fm === null || fm === void 0 ? void 0 : fm.phone)) !== null && _j !== void 0 ? _j : null,
215
+ phone: (_j = fm === null || fm === void 0 ? void 0 : fm.phone) !== null && _j !== void 0 ? _j : null,
217
216
  email: (_k = fm === null || fm === void 0 ? void 0 : fm.email) !== null && _k !== void 0 ? _k : null,
218
- emergencyPhone: (_l = formatPhoneDisplay(fm === null || fm === void 0 ? void 0 : fm.emergencyPhone)) !== null && _l !== void 0 ? _l : null,
217
+ emergencyPhone: (_l = fm === null || fm === void 0 ? void 0 : fm.emergencyPhone) !== null && _l !== void 0 ? _l : null,
219
218
  avatar: (_m = fm === null || fm === void 0 ? void 0 : fm.avatar) !== null && _m !== void 0 ? _m : null,
220
219
  familyId: (_o = fm === null || fm === void 0 ? void 0 : fm.familyId) !== null && _o !== void 0 ? _o : "",
221
220
  address: (_p = family === null || family === void 0 ? void 0 : family.address) !== null && _p !== void 0 ? _p : null,
@@ -10,14 +10,14 @@ import { useEffect } from "react";
10
10
  import { useStudentProfileModule } from "./context";
11
11
  import { STATUS_OPTIONS, GENDER_OPTIONS } from "./constants";
12
12
  import { DISCOUNT_CODE_API_ROUTES } from "../../constants";
13
- import { formatPhone } from "@react-pakistan/util-functions/general/format-phone";
13
+ import { PhoneInput } from "../../components/phone-input";
14
14
  import { getTranslatedError } from "../../utils/get-translated-error";
15
15
  import { getCachedWorkspaceSync } from "../workspace/cache";
16
16
  import { API_METHODS } from "@react-pakistan/util-functions/constants/api-methods";
17
17
  import { DISCOUNT_TYPE } from "../../type";
18
18
  import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
19
19
  export const StudentProfileForm = () => {
20
- var _a, _b, _c, _d, _e;
20
+ var _a, _b, _c, _d, _e, _f, _g;
21
21
  const t = useTranslations("studentProfile");
22
22
  const genderLabelMap = {
23
23
  MALE: t("formOptionMale"),
@@ -80,11 +80,5 @@ export const StudentProfileForm = () => {
80
80
  });
81
81
  return (_jsxs("div", { className: "space-y-4", children: [_jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: t("formSectionPersonalInformation") }), _jsxs("div", { className: "grid grid-cols-1 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, 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, value: lastName }), _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); }, type: "date", value: dateOfBirth
82
82
  ? new Date(dateOfBirth).toISOString().split("T")[0]
83
- : "" }), genderCombo] })] }), _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", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "phone", t }), id: "phone", info: t("formPhoneInfo"), label: t("formPhoneLabel"), onChange: (e) => {
84
- var _a;
85
- return handleChange("phone", ((_a = formatPhone(e.target.value)) === null || _a === void 0 ? void 0 : _a.international) || e.target.value);
86
- }, placeholder: t("formPhonePlaceholder"), type: "tel", value: phone || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "emergencyPhone", t }), id: "emergencyPhone", info: t("formEmergencyPhoneInfo"), label: t("formEmergencyPhoneLabel"), onChange: (e) => {
87
- var _a;
88
- return handleChange("emergencyPhone", ((_a = formatPhone(e.target.value)) === null || _a === void 0 ? void 0 : _a.international) || e.target.value);
89
- }, placeholder: t("formEmergencyPhonePlaceholder"), type: "tel", value: emergencyPhone || "" })] })] }), _jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: t("formSectionAcademicInformation") }), _jsxs("div", { className: "grid grid-cols-1 gap-4", children: [statusCombo, discountCodeIdCombo, _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "remarks", t }), id: "remarks", info: t("formRemarksInfo"), label: t("formRemarksLabel"), onChange: (e) => handleChange("remarks", e.target.value), placeholder: t("formRemarksPlaceholder"), rows: 4, value: remarks || "" })] }), _jsx(EnhancedCheckbox, { checked: enabled, info: t("formEnabledInfo"), label: t("formEnabledLabel"), onCheckedChange: (checked) => handleChange("enabled", checked) })] })] }));
83
+ : "" }), genderCombo] })] }), _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", 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: ((_f = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _f === void 0 ? void 0 : _f.country) || "PK" }), _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: ((_g = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _g === void 0 ? void 0 : _g.country) || "PK" })] })] }), _jsxs("div", { className: "space-y-4", children: [_jsx("h3", { className: "text-lg font-semibold", children: t("formSectionAcademicInformation") }), _jsxs("div", { className: "grid grid-cols-1 gap-4", children: [statusCombo, discountCodeIdCombo, _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "remarks", t }), id: "remarks", info: t("formRemarksInfo"), label: t("formRemarksLabel"), onChange: (e) => handleChange("remarks", e.target.value), placeholder: t("formRemarksPlaceholder"), rows: 4, value: remarks || "" })] }), _jsx(EnhancedCheckbox, { checked: enabled, info: t("formEnabledInfo"), label: t("formEnabledLabel"), onCheckedChange: (checked) => handleChange("enabled", checked) })] })] }));
90
84
  };
@@ -13,8 +13,8 @@ export declare const VALIDATION_KEYS: {
13
13
  export declare const studentProfileFormValidation: z.ZodObject<{
14
14
  firstName: z.ZodString;
15
15
  lastName: z.ZodString;
16
- phone: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>;
17
- emergencyPhone: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>;
16
+ phone: z.ZodPreprocess<z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>, unknown>;
17
+ emergencyPhone: z.ZodPreprocess<z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>, unknown>;
18
18
  status: z.ZodString;
19
19
  dateOfBirth: z.ZodOptional<z.ZodNullable<z.ZodString>>;
20
20
  enrollmentDate: z.ZodOptional<z.ZodNullable<z.ZodString>>;
@@ -4,7 +4,7 @@
4
4
  * Zod validation schemas for student profile form data.
5
5
  */
6
6
  import { z } from "zod";
7
- import { toE164Phone } from "../../utils/to-e164-phone";
7
+ import { phoneSchema } from "../../utils/phone-validation";
8
8
  export const VALIDATION_KEYS = {
9
9
  firstNameRequired: "validationStudentProfileFirstNameRequired",
10
10
  lastNameRequired: "validationStudentProfileLastNameRequired",
@@ -14,14 +14,8 @@ export const VALIDATION_KEYS = {
14
14
  export const studentProfileFormValidation = z.object({
15
15
  firstName: z.string().min(1, VALIDATION_KEYS.firstNameRequired),
16
16
  lastName: z.string().min(1, VALIDATION_KEYS.lastNameRequired),
17
- phone: z
18
- .string()
19
- .nullish()
20
- .transform((val) => { var _a; return (val ? (_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val : val); }),
21
- emergencyPhone: z
22
- .string()
23
- .nullish()
24
- .transform((val) => { var _a; return (val ? (_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val : val); }),
17
+ phone: phoneSchema(VALIDATION_KEYS.phoneInvalid),
18
+ emergencyPhone: phoneSchema(VALIDATION_KEYS.phoneInvalid),
25
19
  status: z.string().min(1, VALIDATION_KEYS.statusRequired),
26
20
  dateOfBirth: z.string().nullish(),
27
21
  enrollmentDate: z.string().nullish(),
@@ -9,9 +9,11 @@ import { useTranslations } from "next-intl";
9
9
  import { useTeacherModule } from "./context";
10
10
  import { GENDER_OPTIONS } from "./constants";
11
11
  import { toDateInput } from "./date";
12
- import { formatPhone } from "@react-pakistan/util-functions/general/format-phone";
12
+ import { PhoneInput } from "../../components/phone-input";
13
+ import { getCachedWorkspaceSync } from "../workspace/cache";
13
14
  import { getTranslatedError } from "../../utils/get-translated-error";
14
15
  export const TeacherForm = () => {
16
+ var _a, _b;
15
17
  const t = useTranslations("teacher");
16
18
  const genderLabelMap = {
17
19
  MALE: t("formOptionMale"),
@@ -23,17 +25,12 @@ export const TeacherForm = () => {
23
25
  const { address, avatar, bio, city, country, dateOfBirth, emergencyPhone, enabled, errors, experience, firstName, gender, joiningDate, lastName, phone, postalCode, qualification, specialization, } = context.state;
24
26
  const stateValue = context.state.state;
25
27
  const { handleChange, handleAvatarUpload } = context;
28
+ const workspace = getCachedWorkspaceSync();
26
29
  const genderCombo = (_jsx(EnhancedCombobox, { emptyText: t("formGenderPlaceholder"), error: getTranslatedError({ errors, key: "gender", t }), id: "gender", info: t("formGenderInfo"), label: t("formGenderLabel"), onValueChange: (value) => handleChange("gender", value || null), options: GENDER_OPTIONS.map((opt) => ({
27
30
  value: opt.value,
28
31
  label: genderLabelMap[opt.value] || opt.label,
29
32
  })), placeholder: t("formGenderPlaceholder"), value: gender || "" }));
30
- return (_jsxs("div", { className: "space-y-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, 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, value: lastName }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "joiningDate", t }), id: "joiningDate", info: t("formJoiningDateInfo"), label: t("formJoiningDateLabel"), onChange: (e) => handleChange("joiningDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, required: true, type: "date", value: toDateInput(joiningDate) }), genderCombo, _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); }, type: "date", value: toDateInput(dateOfBirth) }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "phone", t }), id: "phone", info: t("formPhoneInfo"), label: t("formPhoneLabel"), onChange: (e) => {
31
- var _a;
32
- return handleChange("phone", ((_a = formatPhone(e.target.value)) === null || _a === void 0 ? void 0 : _a.international) || e.target.value);
33
- }, placeholder: t("formPhonePlaceholder"), type: "tel", value: phone || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "emergencyPhone", t }), id: "emergencyPhone", info: t("formEmergencyPhoneInfo"), label: t("formEmergencyPhoneLabel"), onChange: (e) => {
34
- var _a;
35
- return handleChange("emergencyPhone", ((_a = formatPhone(e.target.value)) === null || _a === void 0 ? void 0 : _a.international) || e.target.value);
36
- }, placeholder: t("formEmergencyPhonePlaceholder"), type: "tel", value: emergencyPhone || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "qualification", t }), id: "qualification", info: t("formQualificationInfo"), label: t("formQualificationLabel"), onChange: (e) => handleChange("qualification", e.target.value), placeholder: t("formQualificationPlaceholder"), value: qualification || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "specialization", t }), id: "specialization", info: t("formSpecializationInfo"), label: t("formSpecializationLabel"), onChange: (e) => handleChange("specialization", e.target.value), placeholder: t("formSpecializationPlaceholder"), value: specialization || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "experience", t }), id: "experience", info: t("formExperienceInfo"), label: t("formExperienceLabel"), onChange: (e) => handleChange("experience", parseInt(e.target.value) || null), placeholder: t("formExperiencePlaceholder"), type: "number", value: (experience === null || experience === void 0 ? void 0 : experience.toString()) || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "address", t }), id: "address", info: t("formAddressInfo"), label: t("formAddressLabel"), 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"), onChange: (e) => handleChange("city", e.target.value), placeholder: t("formCityPlaceholder"), value: city || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "state", t }), id: "state", info: t("formStateProvinceInfo"), label: t("formStateProvinceLabel"), onChange: (e) => handleChange("state", e.target.value), placeholder: t("formStatePlaceholder"), value: stateValue || "" }), _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"), value: country || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "postalCode", t }), id: "postalCode", info: t("formPostalCodeInfo"), label: t("formPostalCodeLabel"), onChange: (e) => handleChange("postalCode", e.target.value), placeholder: t("formPostalCodePlaceholder"), value: postalCode || "" }), _jsx(EnhancedDropzone, { accept: ["image/*"], error: getTranslatedError({ errors, key: "avatar", t }), id: "avatar", info: t("formAvatarInfo"), label: t("formAvatarLabel"), maxFiles: 1, maxSize: 100 * 1024, onChange: (files) => {
33
+ return (_jsxs("div", { className: "space-y-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, 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, value: lastName }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "joiningDate", t }), id: "joiningDate", info: t("formJoiningDateInfo"), label: t("formJoiningDateLabel"), onChange: (e) => handleChange("joiningDate", e.target.value), onClick: (e) => { var _a, _b; return (_b = (_a = e.currentTarget).showPicker) === null || _b === void 0 ? void 0 : _b.call(_a); }, required: true, type: "date", value: toDateInput(joiningDate) }), genderCombo, _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); }, type: "date", value: toDateInput(dateOfBirth) }), _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(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: country || ((_b = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _b === void 0 ? void 0 : _b.country) || "PK" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "qualification", t }), id: "qualification", info: t("formQualificationInfo"), label: t("formQualificationLabel"), onChange: (e) => handleChange("qualification", e.target.value), placeholder: t("formQualificationPlaceholder"), value: qualification || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "specialization", t }), id: "specialization", info: t("formSpecializationInfo"), label: t("formSpecializationLabel"), onChange: (e) => handleChange("specialization", e.target.value), placeholder: t("formSpecializationPlaceholder"), value: specialization || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "experience", t }), id: "experience", info: t("formExperienceInfo"), label: t("formExperienceLabel"), onChange: (e) => handleChange("experience", parseInt(e.target.value) || null), placeholder: t("formExperiencePlaceholder"), type: "number", value: (experience === null || experience === void 0 ? void 0 : experience.toString()) || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "address", t }), id: "address", info: t("formAddressInfo"), label: t("formAddressLabel"), 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"), onChange: (e) => handleChange("city", e.target.value), placeholder: t("formCityPlaceholder"), value: city || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "state", t }), id: "state", info: t("formStateProvinceInfo"), label: t("formStateProvinceLabel"), onChange: (e) => handleChange("state", e.target.value), placeholder: t("formStatePlaceholder"), value: stateValue || "" }), _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"), value: country || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "postalCode", t }), id: "postalCode", info: t("formPostalCodeInfo"), label: t("formPostalCodeLabel"), onChange: (e) => handleChange("postalCode", e.target.value), placeholder: t("formPostalCodePlaceholder"), value: postalCode || "" }), _jsx(EnhancedDropzone, { accept: ["image/*"], error: getTranslatedError({ errors, key: "avatar", t }), id: "avatar", info: t("formAvatarInfo"), label: t("formAvatarLabel"), maxFiles: 1, maxSize: 100 * 1024, onChange: (files) => {
37
34
  if (files.length > 0) {
38
35
  handleAvatarUpload === null || handleAvatarUpload === void 0 ? void 0 : handleAvatarUpload(files[0]);
39
36
  }
@@ -26,6 +26,7 @@ import { TeacherForm } from "./form";
26
26
  import { TeacherMoreActions } from "./more-actions";
27
27
  import { TeacherView } from "./view";
28
28
  import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
29
+ import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
29
30
  import { RbacNoAccess } from "../../components/rbac-no-access";
30
31
  // ============================================================================
31
32
  // TABLE COLUMN CONFIGURATION (static — no runtime deps)
@@ -41,7 +42,11 @@ const tableBodyCols = [
41
42
  "N/A");
42
43
  },
43
44
  },
44
- { componentType: COMPONENT_TYPE.TEXT, key: "phone" },
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.TEXT, key: "specialization" },
46
51
  { componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
47
52
  { componentType: COMPONENT_TYPE.ACTIONS },
@@ -7,6 +7,7 @@ import { z } from "zod";
7
7
  export declare const VALIDATION_KEYS: {
8
8
  readonly firstName: "validationTeacherFirstNameRequired";
9
9
  readonly lastName: "validationTeacherLastNameRequired";
10
+ readonly phoneInvalid: "validationTeacherPhoneInvalid";
10
11
  };
11
12
  export declare const teacherFormValidation: z.ZodObject<{
12
13
  address: z.ZodNullable<z.ZodOptional<z.ZodString>>;
@@ -15,7 +16,7 @@ export declare const teacherFormValidation: z.ZodObject<{
15
16
  city: z.ZodNullable<z.ZodOptional<z.ZodString>>;
16
17
  country: z.ZodNullable<z.ZodOptional<z.ZodString>>;
17
18
  dateOfBirth: z.ZodNullable<z.ZodOptional<z.ZodString>>;
18
- emergencyPhone: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>;
19
+ emergencyPhone: z.ZodPreprocess<z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>, unknown>;
19
20
  campusId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
20
21
  experience: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
21
22
  firstName: z.ZodString;
@@ -27,7 +28,7 @@ export declare const teacherFormValidation: z.ZodObject<{
27
28
  }>>>, unknown>;
28
29
  joiningDate: z.ZodOptional<z.ZodString>;
29
30
  lastName: z.ZodString;
30
- phone: z.ZodPipe<z.ZodOptional<z.ZodNullable<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>;
31
+ phone: z.ZodPreprocess<z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>, unknown>;
31
32
  postalCode: z.ZodNullable<z.ZodOptional<z.ZodString>>;
32
33
  qualification: z.ZodNullable<z.ZodOptional<z.ZodString>>;
33
34
  specialization: z.ZodNullable<z.ZodOptional<z.ZodString>>;
@@ -4,13 +4,14 @@
4
4
  * Zod validation schemas for teacher form data with i18n-ready error keys.
5
5
  */
6
6
  import { z } from "zod";
7
- import { toE164Phone } from "../../utils/to-e164-phone";
7
+ import { phoneSchema } from "../../utils/phone-validation";
8
8
  // ============================================================================
9
9
  // VALIDATION KEYS
10
10
  // ============================================================================
11
11
  export const VALIDATION_KEYS = {
12
12
  firstName: "validationTeacherFirstNameRequired",
13
13
  lastName: "validationTeacherLastNameRequired",
14
+ phoneInvalid: "validationTeacherPhoneInvalid",
14
15
  };
15
16
  // ============================================================================
16
17
  // VALIDATION SCHEMA
@@ -22,11 +23,7 @@ export const teacherFormValidation = z.object({
22
23
  city: z.string().optional().nullable(),
23
24
  country: z.string().optional().nullable(),
24
25
  dateOfBirth: z.string().optional().nullable(),
25
- emergencyPhone: z
26
- .string()
27
- .nullable()
28
- .optional()
29
- .transform((val) => { var _a; return (val ? ((_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val) : val); }),
26
+ emergencyPhone: phoneSchema(VALIDATION_KEYS.phoneInvalid),
30
27
  campusId: z.string().optional().nullable(),
31
28
  experience: z.number().int().min(0).max(80).optional().nullable(),
32
29
  firstName: z.string().trim().min(1, VALIDATION_KEYS.firstName).max(100),
@@ -36,11 +33,7 @@ export const teacherFormValidation = z.object({
36
33
  .nullable()),
37
34
  joiningDate: z.string().optional(),
38
35
  lastName: z.string().trim().min(1, VALIDATION_KEYS.lastName).max(100),
39
- phone: z
40
- .string()
41
- .nullable()
42
- .optional()
43
- .transform((val) => { var _a; return (val ? ((_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val) : val); }),
36
+ phone: phoneSchema(VALIDATION_KEYS.phoneInvalid),
44
37
  postalCode: z.string().optional().nullable(),
45
38
  qualification: z.string().optional().nullable(),
46
39
  specialization: z.string().optional().nullable(),
@@ -15,7 +15,6 @@ import { getCachedWorkspaceSync } from "../../workspace/cache";
15
15
  import { blobToWebP } from "webp-converter-browser";
16
16
  import { supabasePublicStorageUrl } from "../../../constants";
17
17
  import { toastNetworkError } from "../../../utils/toast-network-error";
18
- import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
19
18
  import { toE164Phone } from "../../../utils/to-e164-phone";
20
19
  import { useUserContext, USER_ACTION_TYPES, USER_DRAWER } from "../context";
21
20
  export const useUserModule = () => {
@@ -179,7 +178,7 @@ export const useUserModule = () => {
179
178
  id: user.id,
180
179
  name: user.name || "",
181
180
  email: user.email,
182
- phone: formatPhoneDisplay(user.phone) || "",
181
+ phone: user.phone || "",
183
182
  avatar: user.avatar || "",
184
183
  enabled: user.enabled,
185
184
  userRole: parsedUserRole,
@@ -7,16 +7,19 @@ import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
7
7
  import { EnhancedDropzone } from "@appcorp/shadcn/components/enhanced-dropzone";
8
8
  import { useUserModule } from "./context";
9
9
  import { USER_ROLE } from "../../type";
10
- import { formatPhone } from "@react-pakistan/util-functions/general/format-phone";
10
+ import { PhoneInput } from "../../components/phone-input";
11
+ import { getCachedWorkspaceSync } from "../workspace/cache";
11
12
  import { useState } from "react";
12
13
  import { Eye, EyeOff } from "lucide-react";
13
14
  import { getTranslatedError } from "../../utils/get-translated-error";
14
15
  import { MIN_PASSWORD_LENGTH } from "./validate";
15
16
  export const UserForm = () => {
17
+ var _a;
16
18
  const t = useTranslations("user");
17
19
  const { handleAvatar, handleChange, state } = useUserModule();
18
20
  const { avatar, email, enabled, errors, name, password, phone, userRole } = state;
19
21
  const isEdit = Boolean(state.id);
22
+ const workspace = getCachedWorkspaceSync();
20
23
  const roleLabelMap = {
21
24
  SCHOOL_ADMIN: t("formOptionAdmin"),
22
25
  TEACHER: t("formOptionTeacher"),
@@ -34,10 +37,7 @@ export const UserForm = () => {
34
37
  }));
35
38
  return (_jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "name", t }), id: "name", info: t("formNameInfo"), label: t("formNameLabel"), onChange: (e) => handleChange("name", e.target.value), placeholder: t("formNamePlaceholder"), required: true, value: name || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "email", t }), id: "email", info: isEdit ? t("formEmailImmutableInfo") : t("formEmailInfo"), label: t("formEmailLabel"), onChange: (e) => handleChange("email", e.target.value), placeholder: t("formEmailPlaceholder"), readOnly: isEdit, required: true, type: "email", value: email }), _jsxs("div", { className: "relative", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "password", t }), id: "password", info: isEdit
36
39
  ? t("formPasswordEditInfo", { length: MIN_PASSWORD_LENGTH })
37
- : t("formPasswordCreateInfo", { length: MIN_PASSWORD_LENGTH }), label: t("formPasswordLabel"), onChange: (e) => handleChange("password", e.target.value), placeholder: t("formPasswordPlaceholder"), required: !isEdit, type: passwordVisible ? "text" : "password", value: password || "" }), _jsx("button", { type: "button", "aria-label": passwordVisible ? t("actionHidePassword") : t("actionShowPassword"), onClick: () => setPasswordVisible(!passwordVisible), className: "text-muted-foreground hover:text-foreground absolute inset-y-0 top-1 right-3 flex items-center justify-center p-1 text-sm", children: passwordVisible ? (_jsx(EyeOff, { className: "h-4 w-4" })) : (_jsx(Eye, { className: "h-4 w-4" })) })] }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "phone", t }), id: "phone", info: t("formPhoneInfo"), label: t("formPhoneLabel"), onChange: (e) => {
38
- var _a;
39
- return handleChange("phone", ((_a = formatPhone(e.target.value)) === null || _a === void 0 ? void 0 : _a.international) || e.target.value);
40
- }, placeholder: t("formPhonePlaceholder"), type: "tel", value: phone || "" }), _jsx(EnhancedDropzone, { accept: ["image/*"], error: getTranslatedError({ errors, key: "avatar", t }), id: "avatar", info: t("formAvatarInfo"), label: t("formAvatarLabel"), maxFiles: 1, maxSize: 0.25 * 1024 * 1024, onChange: handleAvatar, onRemoveRemote: () => handleChange("avatar", ""), resize: true, value: avatar ? [avatar] : [] }), _jsx(EnhancedCheckbox, { checked: enabled, error: getTranslatedError({ errors, key: "enabled", t }), id: "enabled", info: t("formEnabledInfo"), label: t("formEnabledLabel"), onCheckedChange: (checked) => handleChange("enabled", checked) }), _jsx(EnhancedCombobox, { emptyText: t("formNoRoleEmpty"), error: getTranslatedError({ errors, key: "userRole", t }), id: "userRole", info: t("formRoleIdInfo"), label: t("formRoleIdLabel"), onValueChange: (value) => handleChange("userRole", value), options: roleOptions.map((opt) => ({
40
+ : t("formPasswordCreateInfo", { length: MIN_PASSWORD_LENGTH }), label: t("formPasswordLabel"), onChange: (e) => handleChange("password", e.target.value), placeholder: t("formPasswordPlaceholder"), required: !isEdit, type: passwordVisible ? "text" : "password", value: password || "" }), _jsx("button", { type: "button", "aria-label": passwordVisible ? t("actionHidePassword") : t("actionShowPassword"), onClick: () => setPasswordVisible(!passwordVisible), className: "text-muted-foreground hover:text-foreground absolute inset-y-0 top-1 right-3 flex items-center justify-center p-1 text-sm", children: passwordVisible ? (_jsx(EyeOff, { className: "h-4 w-4" })) : (_jsx(Eye, { className: "h-4 w-4" })) })] }), _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(EnhancedDropzone, { accept: ["image/*"], error: getTranslatedError({ errors, key: "avatar", t }), id: "avatar", info: t("formAvatarInfo"), label: t("formAvatarLabel"), maxFiles: 1, maxSize: 0.25 * 1024 * 1024, onChange: handleAvatar, onRemoveRemote: () => handleChange("avatar", ""), resize: true, value: avatar ? [avatar] : [] }), _jsx(EnhancedCheckbox, { checked: enabled, error: getTranslatedError({ errors, key: "enabled", t }), id: "enabled", info: t("formEnabledInfo"), label: t("formEnabledLabel"), onCheckedChange: (checked) => handleChange("enabled", checked) }), _jsx(EnhancedCombobox, { emptyText: t("formNoRoleEmpty"), error: getTranslatedError({ errors, key: "userRole", t }), id: "userRole", info: t("formRoleIdInfo"), label: t("formRoleIdLabel"), onValueChange: (value) => handleChange("userRole", value), options: roleOptions.map((opt) => ({
41
41
  value: opt.id,
42
42
  label: opt.name,
43
43
  })), placeholder: t("formRoleIdPlaceholder"), required: true, searchPlaceholder: t("formSearchRolePlaceholder"), value: userRole !== null && userRole !== void 0 ? userRole : "" })] }));
@@ -26,6 +26,7 @@ import { UserFilter } from "./filter";
26
26
  import { UserForm } from "./form";
27
27
  import { UserView } from "./view";
28
28
  import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
29
+ import { formatPhoneDisplay } from "@react-pakistan/util-functions/general/format-phone-display";
29
30
  import { RbacNoAccess } from "../../components/rbac-no-access";
30
31
  // ============================================================================
31
32
  // TABLE COLUMN CONFIGURATION (static — no runtime deps)
@@ -35,7 +36,7 @@ const tableBodyCols = [
35
36
  { componentType: COMPONENT_TYPE.TEXT, key: "name" },
36
37
  { componentType: COMPONENT_TYPE.TEXT, key: "email" },
37
38
  { componentType: COMPONENT_TYPE.TEXT, key: "userRole" },
38
- { componentType: COMPONENT_TYPE.TEXT, key: "phone" },
39
+ { componentType: COMPONENT_TYPE.TEXT, key: "phone", textFormatter: (_, row) => formatPhoneDisplay(row.phone) },
39
40
  { componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
40
41
  { componentType: COMPONENT_TYPE.ACTIONS },
41
42
  ];
@@ -25,7 +25,7 @@ export declare const userFormValidation: z.ZodObject<{
25
25
  name: z.ZodString;
26
26
  email: z.ZodEmail;
27
27
  password: z.ZodOptional<z.ZodString>;
28
- phone: z.ZodPipe<z.ZodOptional<z.ZodString>, z.ZodTransform<string | undefined, string | undefined>>;
28
+ phone: z.ZodPreprocess<z.ZodPipe<z.ZodNullable<z.ZodOptional<z.ZodString>>, z.ZodTransform<string | null | undefined, string | null | undefined>>, unknown>;
29
29
  avatar: z.ZodOptional<z.ZodString>;
30
30
  enabled: z.ZodOptional<z.ZodBoolean>;
31
31
  userRole: z.ZodEnum<typeof USER_ROLE> & z.ZodType<USER_ROLE.SUPER_ADMIN | USER_ROLE.TEACHER | USER_ROLE.STUDENT | USER_ROLE.PARENT | USER_ROLE.STAFF, USER_ROLE, z.core.$ZodTypeInternals<USER_ROLE.SUPER_ADMIN | USER_ROLE.TEACHER | USER_ROLE.STUDENT | USER_ROLE.PARENT | USER_ROLE.STAFF, USER_ROLE>>;
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import { z } from "zod";
12
12
  import { USER_ROLE } from "../../type";
13
- import { toE164Phone } from "../../utils/to-e164-phone";
13
+ import { phoneSchema } from "../../utils/phone-validation";
14
14
  // ============================================================================
15
15
  // VALIDATION KEYS
16
16
  // ============================================================================
@@ -33,10 +33,7 @@ export const userFormValidation = z
33
33
  name: z.string().min(1, VALIDATION_KEYS.name),
34
34
  email: z.email(VALIDATION_KEYS.emailInvalid),
35
35
  password: z.string().optional(),
36
- phone: z
37
- .string()
38
- .optional()
39
- .transform((val) => { var _a; return (val ? ((_a = toE164Phone(val)) !== null && _a !== void 0 ? _a : val) : val); }),
36
+ phone: phoneSchema(VALIDATION_KEYS.phoneInvalid),
40
37
  avatar: z.string().optional(),
41
38
  enabled: z.boolean().optional(),
42
39
  userRole: z
@@ -9,4 +9,4 @@
9
9
  // PAGE CONFIGURATION
10
10
  // ============================================================================
11
11
  export const pageLimit = Number(process.env.NEXT_PUBLIC_PAGE_LIMIT) || 10;
12
- export const secretKeys = ["GOOGLE_SMTP", "GEMINI_API_KEY", "GEMINI_MODEL"];
12
+ export const secretKeys = ["GEMINI_API_KEY", "GEMINI_MODEL"];