@appcorp/fusion-storybook 0.5.29 → 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.
- 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 +44 -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
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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 {
|
|
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(
|
|
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.
|
|
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 {
|
|
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:
|
|
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(),
|
|
@@ -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 =
|
|
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 =
|
|
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 {
|
|
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(
|
|
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.
|
|
17
|
-
emergencyPhone: z.
|
|
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 {
|
|
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:
|
|
18
|
-
|
|
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 {
|
|
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(
|
|
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
|
-
{
|
|
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.
|
|
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.
|
|
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 {
|
|
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:
|
|
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:
|
|
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:
|
|
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 {
|
|
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(
|
|
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
|
|
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 {
|
|
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:
|
|
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
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface PhoneInputProps {
|
|
2
|
+
id: string;
|
|
3
|
+
label?: string;
|
|
4
|
+
info?: string;
|
|
5
|
+
error?: string;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
/** Full E.164 value, e.g. `+923212434302`. */
|
|
9
|
+
value?: string | null;
|
|
10
|
+
/** Receives the full E.164 value (or `""` when empty). */
|
|
11
|
+
onChange: (value: string) => void;
|
|
12
|
+
/** ISO-2 code, country name, or empty. Defaults to `PK`. */
|
|
13
|
+
defaultCountry?: string | null;
|
|
14
|
+
placeholder?: string;
|
|
15
|
+
className?: string;
|
|
16
|
+
countryAriaLabel?: string;
|
|
17
|
+
countrySearchPlaceholder?: string;
|
|
18
|
+
countryEmptyText?: string;
|
|
19
|
+
testId?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function PhoneInput({ id, label, info, error, required, disabled, value, onChange, defaultCountry, placeholder, className, countryAriaLabel, countrySearchPlaceholder, countryEmptyText, testId, }: PhoneInputProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { Check, ChevronsUpDown } from "lucide-react";
|
|
5
|
+
import { dialCodes } from "@react-pakistan/util-functions/constants/dial-codes";
|
|
6
|
+
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
7
|
+
import { EnhancedLabel } from "@appcorp/shadcn/components/enhanced-label";
|
|
8
|
+
import { Button } from "@appcorp/shadcn/components/ui/button";
|
|
9
|
+
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, } from "@appcorp/shadcn/components/ui/command";
|
|
10
|
+
import { Popover, PopoverContent, PopoverTrigger, } from "@appcorp/shadcn/components/ui/popover";
|
|
11
|
+
import { cn } from "@appcorp/shadcn/lib/utils";
|
|
12
|
+
import { countryNameFor, dialCodeFor, flagForCountry, formatNationalNumber, isDialCodeCompatible, joinPhoneValue, splitPhoneValue, toIsoCountry, } from "../utils/phone";
|
|
13
|
+
export function PhoneInput({ id, label, info, error, required = false, disabled = false, value, onChange, defaultCountry, placeholder, className, countryAriaLabel = "Country code", countrySearchPlaceholder = "Search country...", countryEmptyText = "No country found.", testId, }) {
|
|
14
|
+
const fallback = toIsoCountry(defaultCountry);
|
|
15
|
+
const parsed = splitPhoneValue(value, fallback);
|
|
16
|
+
const [selectedCountry, setSelectedCountry] = useState(parsed.country);
|
|
17
|
+
const [open, setOpen] = useState(false);
|
|
18
|
+
const country = selectedCountry && isDialCodeCompatible(value, selectedCountry)
|
|
19
|
+
? selectedCountry
|
|
20
|
+
: parsed.country;
|
|
21
|
+
const national = parsed.national;
|
|
22
|
+
const countries = useMemo(() => dialCodes
|
|
23
|
+
.map((entry) => (Object.assign(Object.assign({}, entry), { displayName: countryNameFor(entry.code, entry.name), flag: flagForCountry(entry.code) })))
|
|
24
|
+
.sort((a, b) => a.displayName.localeCompare(b.displayName)), []);
|
|
25
|
+
const selectedDial = dialCodeFor(country);
|
|
26
|
+
const displayValue = formatNationalNumber(country, national);
|
|
27
|
+
const handleCountryChange = (nextCountry) => {
|
|
28
|
+
setSelectedCountry(nextCountry);
|
|
29
|
+
setOpen(false);
|
|
30
|
+
onChange(joinPhoneValue(nextCountry, national));
|
|
31
|
+
};
|
|
32
|
+
const handleNationalChange = (input) => {
|
|
33
|
+
if (input.trim().startsWith("+")) {
|
|
34
|
+
const split = splitPhoneValue(input, country);
|
|
35
|
+
setSelectedCountry(split.country);
|
|
36
|
+
onChange(joinPhoneValue(split.country, split.national));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const digits = input.replace(/\D/g, "");
|
|
40
|
+
setSelectedCountry(country);
|
|
41
|
+
onChange(joinPhoneValue(country, digits));
|
|
42
|
+
};
|
|
43
|
+
return (_jsxs("div", { className: cn("space-y-2", className), children: [label && (_jsx(EnhancedLabel, { htmlFor: id, required: required, children: label })), _jsxs("div", { className: "flex items-start gap-2", children: [_jsxs(Popover, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsxs(Button, { type: "button", variant: "outline", role: "combobox", "aria-expanded": open, "aria-label": countryAriaLabel, disabled: disabled, className: cn("h-9 w-[112px] shrink-0 justify-between px-2 font-normal", error && "border-destructive"), children: [_jsxs("span", { className: "truncate", children: [flagForCountry(country), " ", selectedDial] }), _jsx(ChevronsUpDown, { className: "ml-1 h-4 w-4 shrink-0 opacity-50" })] }) }), _jsx(PopoverContent, { className: "w-[320px] max-w-[calc(100vw-2rem)] p-0", align: "start", children: _jsxs(Command, { children: [_jsx(CommandInput, { placeholder: countrySearchPlaceholder }), _jsxs(CommandList, { children: [_jsx(CommandEmpty, { children: countryEmptyText }), _jsx(CommandGroup, { children: countries.map((entry) => (_jsxs(CommandItem, { value: `${entry.displayName} ${entry.code} ${entry.dial_code}`, onSelect: () => handleCountryChange(entry.code), children: [_jsx("span", { className: "mr-2", children: entry.flag }), _jsx("span", { className: "flex-1 truncate", children: entry.displayName }), _jsx("span", { className: "text-muted-foreground ml-2", children: entry.dial_code }), _jsx(Check, { className: cn("ml-2 h-4 w-4", country === entry.code ? "opacity-100" : "opacity-0") })] }, entry.code))) })] })] }) })] }), _jsx("div", { className: "min-w-0 flex-1", children: _jsx(EnhancedInput, { id: id, type: "tel", inputMode: "tel", autoComplete: "tel-national", value: displayValue, onChange: (event) => handleNationalChange(event.target.value), error: error, info: info, placeholder: placeholder, disabled: disabled, required: required, testIdWrapper: testId, testIdInput: testId ? `${testId}-input` : undefined }) })] })] }));
|
|
44
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appcorp/fusion-storybook",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.31",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build-storybook": "storybook build",
|
|
6
6
|
"build:next": "next build",
|
|
@@ -36,6 +36,9 @@
|
|
|
36
36
|
"prettier --write"
|
|
37
37
|
]
|
|
38
38
|
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"libphonenumber-js": "^1.13.0"
|
|
41
|
+
},
|
|
39
42
|
"devDependencies": {
|
|
40
43
|
"@appcorp/shadcn": "^2.0.21",
|
|
41
44
|
"@chromatic-com/storybook": "^5.1.2",
|