@appcorp/fusion-storybook 0.3.36 → 0.3.37

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.
@@ -47,6 +47,7 @@ export declare const STUDENT_PROFILE_ACTION_TYPES: {
47
47
  state: string | null;
48
48
  country: string | null;
49
49
  postalCode: string | null;
50
+ discountCodeId: string;
50
51
  filterEnabled: boolean | undefined;
51
52
  filterGender: string | undefined;
52
53
  filterStatus: string | undefined;
@@ -80,6 +81,7 @@ export declare const STUDENT_PROFILE_ACTION_TYPES: {
80
81
  state: string | null;
81
82
  country: string | null;
82
83
  postalCode: string | null;
84
+ discountCodeId: string;
83
85
  filterEnabled: boolean | undefined;
84
86
  filterGender: string | undefined;
85
87
  filterStatus: string | undefined;
@@ -115,6 +117,7 @@ export declare const STUDENT_PROFILE_ACTION_TYPES: {
115
117
  state: string | null;
116
118
  country: string | null;
117
119
  postalCode: string | null;
120
+ discountCodeId: string;
118
121
  filterEnabled: boolean | undefined;
119
122
  filterGender: string | undefined;
120
123
  filterStatus: string | undefined;
@@ -148,6 +151,7 @@ export declare const STUDENT_PROFILE_ACTION_TYPES: {
148
151
  state: string | null;
149
152
  country: string | null;
150
153
  postalCode: string | null;
154
+ discountCodeId: string;
151
155
  filterEnabled: boolean | undefined;
152
156
  filterGender: string | undefined;
153
157
  filterStatus: string | undefined;
@@ -181,6 +185,7 @@ export declare const STUDENT_PROFILE_ACTION_TYPES: {
181
185
  state: string | null;
182
186
  country: string | null;
183
187
  postalCode: string | null;
188
+ discountCodeId: string;
184
189
  filterEnabled: boolean | undefined;
185
190
  filterGender: string | undefined;
186
191
  filterStatus: string | undefined;
@@ -42,6 +42,7 @@ const studentProfileConfig = {
42
42
  state: "",
43
43
  country: "",
44
44
  postalCode: "",
45
+ discountCodeId: "",
45
46
  filterEnabled: undefined,
46
47
  filterGender: undefined,
47
48
  filterStatus: undefined,
@@ -64,6 +64,7 @@ export declare const useStudentProfileModule: () => {
64
64
  state: string | null;
65
65
  country: string | null;
66
66
  postalCode: string | null;
67
+ discountCodeId: string;
67
68
  filterEnabled: boolean | undefined;
68
69
  filterGender: string | undefined;
69
70
  filterStatus: string | undefined;
@@ -42,6 +42,7 @@ export const useStudentProfileModule = () => {
42
42
  avatar: state.avatar,
43
43
  bloodGroup: state.bloodGroup,
44
44
  dateOfBirth: state.dateOfBirth,
45
+ discountCodeId: state.discountCodeId || null,
45
46
  email: state.email,
46
47
  emergencyPhone: toE164Phone(state.emergencyPhone, (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.country),
47
48
  enabled: state.enabled,
@@ -58,6 +59,7 @@ export const useStudentProfileModule = () => {
58
59
  state.avatar,
59
60
  state.bloodGroup,
60
61
  state.dateOfBirth,
62
+ state.discountCodeId,
61
63
  state.email,
62
64
  state.emergencyPhone,
63
65
  state.enabled,
@@ -114,6 +116,7 @@ export const useStudentProfileModule = () => {
114
116
  city: null,
115
117
  country: null,
116
118
  dateOfBirth: null,
119
+ discountCodeId: null,
117
120
  email: null,
118
121
  emergencyPhone: null,
119
122
  enabled: true,
@@ -163,7 +166,7 @@ export const useStudentProfileModule = () => {
163
166
  }
164
167
  }, [resetFormAndCloseDrawer, showToast, t]);
165
168
  const byIdCallback = useCallback(({ data, error }) => {
166
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
169
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
167
170
  if (error) {
168
171
  showToast(t("messagesDetailsFetchFailed"), TOAST_VARIANT.ERROR);
169
172
  return;
@@ -182,21 +185,22 @@ export const useStudentProfileModule = () => {
182
185
  status: sp.status,
183
186
  enabled: sp.enabled,
184
187
  remarks: (_a = sp.remarks) !== null && _a !== void 0 ? _a : null,
185
- firstName: (_b = fm === null || fm === void 0 ? void 0 : fm.firstName) !== null && _b !== void 0 ? _b : "",
186
- lastName: (_c = fm === null || fm === void 0 ? void 0 : fm.lastName) !== null && _c !== void 0 ? _c : "",
187
- dateOfBirth: (_d = fm === null || fm === void 0 ? void 0 : fm.dateOfBirth) !== null && _d !== void 0 ? _d : null,
188
- gender: (_e = fm === null || fm === void 0 ? void 0 : fm.gender) !== null && _e !== void 0 ? _e : null,
189
- bloodGroup: (_f = fm === null || fm === void 0 ? void 0 : fm.bloodGroup) !== null && _f !== void 0 ? _f : null,
190
- phone: (_g = formatPhoneDisplay(fm === null || fm === void 0 ? void 0 : fm.phone)) !== null && _g !== void 0 ? _g : null,
191
- email: (_h = fm === null || fm === void 0 ? void 0 : fm.email) !== null && _h !== void 0 ? _h : null,
192
- emergencyPhone: (_j = formatPhoneDisplay(fm === null || fm === void 0 ? void 0 : fm.emergencyPhone)) !== null && _j !== void 0 ? _j : null,
193
- avatar: (_k = fm === null || fm === void 0 ? void 0 : fm.avatar) !== null && _k !== void 0 ? _k : null,
194
- familyId: (_l = fm === null || fm === void 0 ? void 0 : fm.familyId) !== null && _l !== void 0 ? _l : "",
195
- address: (_m = family === null || family === void 0 ? void 0 : family.address) !== null && _m !== void 0 ? _m : null,
196
- city: (_o = family === null || family === void 0 ? void 0 : family.city) !== null && _o !== void 0 ? _o : null,
197
- state: (_p = family === null || family === void 0 ? void 0 : family.state) !== null && _p !== void 0 ? _p : null,
198
- country: (_q = family === null || family === void 0 ? void 0 : family.country) !== null && _q !== void 0 ? _q : null,
199
- postalCode: (_r = family === null || family === void 0 ? void 0 : family.postalCode) !== null && _r !== void 0 ? _r : null,
188
+ discountCodeId: (_b = sp.discountCodeId) !== null && _b !== void 0 ? _b : null,
189
+ firstName: (_c = fm === null || fm === void 0 ? void 0 : fm.firstName) !== null && _c !== void 0 ? _c : "",
190
+ lastName: (_d = fm === null || fm === void 0 ? void 0 : fm.lastName) !== null && _d !== void 0 ? _d : "",
191
+ dateOfBirth: (_e = fm === null || fm === void 0 ? void 0 : fm.dateOfBirth) !== null && _e !== void 0 ? _e : null,
192
+ gender: (_f = fm === null || fm === void 0 ? void 0 : fm.gender) !== null && _f !== void 0 ? _f : null,
193
+ bloodGroup: (_g = fm === null || fm === void 0 ? void 0 : fm.bloodGroup) !== null && _g !== void 0 ? _g : null,
194
+ phone: (_h = formatPhoneDisplay(fm === null || fm === void 0 ? void 0 : fm.phone)) !== null && _h !== void 0 ? _h : null,
195
+ email: (_j = fm === null || fm === void 0 ? void 0 : fm.email) !== null && _j !== void 0 ? _j : null,
196
+ emergencyPhone: (_k = formatPhoneDisplay(fm === null || fm === void 0 ? void 0 : fm.emergencyPhone)) !== null && _k !== void 0 ? _k : null,
197
+ avatar: (_l = fm === null || fm === void 0 ? void 0 : fm.avatar) !== null && _l !== void 0 ? _l : null,
198
+ familyId: (_m = fm === null || fm === void 0 ? void 0 : fm.familyId) !== null && _m !== void 0 ? _m : "",
199
+ address: (_o = family === null || family === void 0 ? void 0 : family.address) !== null && _o !== void 0 ? _o : null,
200
+ city: (_p = family === null || family === void 0 ? void 0 : family.city) !== null && _p !== void 0 ? _p : null,
201
+ state: (_q = family === null || family === void 0 ? void 0 : family.state) !== null && _q !== void 0 ? _q : null,
202
+ country: (_r = family === null || family === void 0 ? void 0 : family.country) !== null && _r !== void 0 ? _r : null,
203
+ postalCode: (_s = family === null || family === void 0 ? void 0 : family.postalCode) !== null && _s !== void 0 ? _s : null,
200
204
  },
201
205
  },
202
206
  });
@@ -5,12 +5,18 @@ import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
5
5
  import { EnhancedTextarea } from "@appcorp/shadcn/components/enhanced-textarea";
6
6
  import { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox";
7
7
  import { useTranslations } from "next-intl";
8
+ import { useEffect } from "react";
8
9
  import { useStudentProfileModule } from "./context";
9
10
  import { STATUS_OPTIONS, GENDER_OPTIONS } from "./constants";
10
- import { STUDENT_PROFILE_API_ROUTES } from "../../constants";
11
+ import { STUDENT_PROFILE_API_ROUTES, DISCOUNT_CODE_API_ROUTES, } from "../../constants";
11
12
  import { formatPhone } from "@react-pakistan/util-functions/general/format-phone";
12
13
  import { getTranslatedError } from "../../utils/get-translated-error";
14
+ import { getCachedWorkspaceSync } from "../workspace/cache";
15
+ import { API_METHODS } from "@react-pakistan/util-functions";
16
+ import { DISCOUNT_TYPE } from "../../type";
17
+ import { useFetch } from "@react-pakistan/util-functions/hooks/use-fetch";
13
18
  export const StudentProfileForm = () => {
19
+ var _a, _b, _c;
14
20
  const t = useTranslations("studentProfile");
15
21
  const genderLabelMap = {
16
22
  MALE: t("formOptionMale"),
@@ -18,7 +24,7 @@ export const StudentProfileForm = () => {
18
24
  OTHER: t("formOptionOther"),
19
25
  };
20
26
  const context = useStudentProfileModule();
21
- const { address, city, country, dateOfBirth, emergencyPhone, enabled, errors, firstName, gender, lastName, phone, postalCode, remarks, status, } = context.state;
27
+ const { address, city, country, dateOfBirth, discountCodeId, emergencyPhone, enabled, errors, firstName, gender, lastName, phone, postalCode, remarks, status, } = context.state;
22
28
  const stateValue = context.state.state;
23
29
  const { handleChange } = context;
24
30
  const { enhancedComboboxElement: genderCombo } = useEnhancedCombobox({
@@ -62,6 +68,40 @@ export const StudentProfileForm = () => {
62
68
  },
63
69
  value: status,
64
70
  });
71
+ const workspace = getCachedWorkspaceSync();
72
+ const currency = (_b = (_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.currency) !== null && _b !== void 0 ? _b : "";
73
+ const { fetchNow: discountCodeFetchNow, data: discountCodes } = useFetch(DISCOUNT_CODE_API_ROUTES.UNIT, {
74
+ params: { workspaceId: workspace === null || workspace === void 0 ? void 0 : workspace.id },
75
+ method: API_METHODS.GET,
76
+ });
77
+ useEffect(() => {
78
+ discountCodeFetchNow();
79
+ // eslint-disable-next-line
80
+ }, []);
81
+ const { enhancedComboboxElement: discountCodeIdCombo } = useEnhancedCombobox({
82
+ emptyText: "No discount code found",
83
+ id: "discountCodeId",
84
+ info: "Optional discount code to apply",
85
+ label: "Discount Code",
86
+ onValueChange: (value) => handleChange("discountCodeId", value),
87
+ options: ((_c = discountCodes === null || discountCodes === void 0 ? void 0 : discountCodes.items) !== null && _c !== void 0 ? _c : []).map((code) => ({
88
+ value: code.id,
89
+ label: `${code.code} - ${code.discountValue}${code.discountType === DISCOUNT_TYPE.PERCENTAGE ? "%" : currency}`,
90
+ })),
91
+ placeholder: "Select discount code",
92
+ searchEndpoint: DISCOUNT_CODE_API_ROUTES.UNIT,
93
+ searchPlaceholder: "Search discount codes...",
94
+ formatSearchResult: (item) => {
95
+ const discountCode = item;
96
+ return {
97
+ label: `${discountCode.code} - ${discountCode.discountValue}${discountCode.discountType === DISCOUNT_TYPE.PERCENTAGE
98
+ ? "%"
99
+ : currency}`,
100
+ value: discountCode.id,
101
+ };
102
+ },
103
+ value: discountCodeId !== null && discountCodeId !== void 0 ? discountCodeId : "",
104
+ });
65
105
  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
66
106
  ? new Date(dateOfBirth).toISOString().split("formTLabel")[0]
67
107
  : "" }), 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) => {
@@ -70,5 +110,5 @@ export const StudentProfileForm = () => {
70
110
  }, 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) => {
71
111
  var _a;
72
112
  return handleChange("emergencyPhone", ((_a = formatPhone(e.target.value)) === null || _a === void 0 ? void 0 : _a.international) || e.target.value);
73
- }, placeholder: t("formEmergencyPhonePlaceholder"), type: "tel", value: emergencyPhone || "" })] }), _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 || "" }), _jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_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("formStateInfo"), 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 || "" })] })] }), _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, _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) })] })] }));
113
+ }, placeholder: t("formEmergencyPhonePlaceholder"), type: "tel", value: emergencyPhone || "" })] }), _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 || "" }), _jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_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("formStateInfo"), 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 || "" })] })] }), _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) })] })] }));
74
114
  };
@@ -25,5 +25,6 @@ export declare const studentProfileFormValidation: z.ZodObject<{
25
25
  state: z.ZodOptional<z.ZodString>;
26
26
  postalCode: z.ZodOptional<z.ZodString>;
27
27
  country: z.ZodOptional<z.ZodString>;
28
+ discountCodeId: z.ZodOptional<z.ZodString>;
28
29
  enabled: z.ZodOptional<z.ZodBoolean>;
29
30
  }, z.core.$strip>;
@@ -32,5 +32,6 @@ export const studentProfileFormValidation = z.object({
32
32
  state: z.string().optional(),
33
33
  postalCode: z.string().optional(),
34
34
  country: z.string().optional(),
35
+ discountCodeId: z.string().optional(),
35
36
  enabled: z.boolean().optional(),
36
37
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.3.36",
3
+ "version": "0.3.37",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",