@appcorp/fusion-storybook 0.5.13 → 0.5.17

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 (52) hide show
  1. package/base-modules/class/context/use-class-module.d.ts +55 -0
  2. package/base-modules/class/context/use-class-module.js +421 -0
  3. package/base-modules/class/context.d.ts +27 -52
  4. package/base-modules/class/context.js +18 -415
  5. package/base-modules/class/filter.js +16 -6
  6. package/base-modules/class/form.js +19 -3
  7. package/base-modules/class/more-actions.js +48 -10
  8. package/base-modules/class/page.js +15 -5
  9. package/base-modules/class/validate.d.ts +2 -2
  10. package/base-modules/class/validate.js +7 -3
  11. package/base-modules/class/view.js +2 -4
  12. package/base-modules/discount-code/context/use-discount-code-module.d.ts +65 -0
  13. package/base-modules/discount-code/context/use-discount-code-module.js +402 -0
  14. package/base-modules/discount-code/context.d.ts +32 -80
  15. package/base-modules/discount-code/context.js +14 -430
  16. package/base-modules/discount-code/filter.d.ts +1 -10
  17. package/base-modules/discount-code/filter.js +34 -8
  18. package/base-modules/discount-code/form.js +9 -35
  19. package/base-modules/discount-code/page.js +39 -19
  20. package/base-modules/discount-code/validate.d.ts +2 -1
  21. package/base-modules/discount-code/validate.js +10 -3
  22. package/base-modules/discount-code/view.js +15 -4
  23. package/base-modules/enrollment/context.d.ts +6 -0
  24. package/base-modules/enrollment/context.js +69 -25
  25. package/base-modules/enrollment/date.d.ts +8 -0
  26. package/base-modules/enrollment/date.js +21 -0
  27. package/base-modules/enrollment/filter.js +1 -1
  28. package/base-modules/enrollment/form.js +55 -24
  29. package/base-modules/enrollment/more-actions.js +47 -10
  30. package/base-modules/enrollment/page.js +11 -14
  31. package/base-modules/enrollment/validate.d.ts +1 -0
  32. package/base-modules/enrollment/validate.js +3 -1
  33. package/base-modules/enrollment/view.js +11 -19
  34. package/base-modules/expense/context/expense-api-provider.js +22 -9
  35. package/base-modules/expense/context/shared.d.ts +35 -0
  36. package/base-modules/expense/context/shared.js +11 -3
  37. package/base-modules/expense/context/use-expense-module.d.ts +7 -1
  38. package/base-modules/expense/context/use-expense-module.js +58 -55
  39. package/base-modules/expense/filter.js +25 -57
  40. package/base-modules/expense/form.js +17 -74
  41. package/base-modules/expense/page.js +60 -29
  42. package/base-modules/expense/validate.d.ts +17 -11
  43. package/base-modules/expense/validate.js +35 -14
  44. package/constants.d.ts +1 -3
  45. package/constants.js +0 -2
  46. package/package.json +1 -1
  47. package/tsconfig.build.tsbuildinfo +1 -1
  48. package/utils/resolve-rbac-permissions.js +10 -6
  49. package/base-modules/discount-code/more-actions.d.ts +0 -9
  50. package/base-modules/discount-code/more-actions.js +0 -13
  51. package/base-modules/expense/more-actions.d.ts +0 -1
  52. package/base-modules/expense/more-actions.js +0 -265
@@ -1,14 +1,40 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useTranslations } from "next-intl";
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  /**
4
- * DiscountCodeFilter
4
+ * Discount Code Filter
5
5
  *
6
- * Lightweight filter UI for the discount-code drawer. The generic page
7
- * will render this component inside the filter drawer slot. Keep filters
8
- * minimal and explicit (enabled flag, type select) so caching remains
9
- * predictable.
6
+ * Staged filters: record state + discount type. Applied by the drawer footer.
10
7
  */
8
+ import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
9
+ import { EnhancedRadio } from "@appcorp/shadcn/components/enhanced-radio";
10
+ import { useTranslations } from "next-intl";
11
+ import { useDiscountCodeModule } from "./context";
12
+ import { DISCOUNT_TYPE_OPTIONS } from "./constants";
11
13
  export const DiscountCodeFilter = () => {
12
14
  const t = useTranslations("discountCode");
13
- return (_jsx("div", { className: "space-y-4", children: _jsx("div", { className: "text-sm text-muted-foreground", children: t("filterText") }) }));
15
+ const { state, handleChange } = useDiscountCodeModule();
16
+ const { filterEnabled, filterDiscountType } = state;
17
+ const filterEnabledValue = filterEnabled === undefined
18
+ ? "undefined"
19
+ : filterEnabled
20
+ ? "true"
21
+ : "false";
22
+ const discountTypeLabelMap = {
23
+ PERCENTAGE: t("formOptionPercentage"),
24
+ FIXED: t("formOptionFixed"),
25
+ };
26
+ return (_jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedCombobox, { emptyText: t("filterAllTypes"), id: "filterDiscountType", info: t("filterDiscountTypeInfo"), label: t("filterDiscountTypeLabel"), onValueChange: (value) => handleChange("filterDiscountType", value || undefined), options: [
27
+ { value: "", label: t("filterAllTypes") },
28
+ ...DISCOUNT_TYPE_OPTIONS.map((opt) => ({
29
+ value: opt.value,
30
+ label: discountTypeLabelMap[opt.value] || opt.label,
31
+ })),
32
+ ], placeholder: t("filterAllTypes"), searchPlaceholder: t("filterAllTypes"), value: filterDiscountType !== null && filterDiscountType !== void 0 ? filterDiscountType : "" }), _jsx(EnhancedRadio, { label: t("filterRecordStateLabel"), name: "filterEnabled", value: filterEnabledValue, options: [
33
+ { label: t("filterOptionAll"), value: "undefined" },
34
+ { label: t("filterOptionEnabled"), value: "true" },
35
+ { label: t("filterOptionDisabled"), value: "false" },
36
+ ], onValueChange: (next) => {
37
+ const parsed = next === "true" ? true : next === "false" ? false : undefined;
38
+ handleChange("filterEnabled", parsed);
39
+ } })] }));
14
40
  };
@@ -3,24 +3,16 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  /**
4
4
  * Discount Code Form
5
5
  *
6
- * Controlled form component used inside the generic module drawer.
7
- * Fields in this form map directly to the `accountDiscountCodeFormValidation`
8
- * schema in `validate.ts` and to the `update` payload sent to the API.
9
- *
10
- * Guidelines:
11
- * - Use `handleChange(field, value)` from `useDiscountCodeModule()` to
12
- * update the local module state.
13
- * - Keep input `id` props stable to preserve accessibility and testing hooks.
6
+ * Fields map to `accountDiscountCodeFormValidation` and the PUT payload.
14
7
  */
15
8
  import { useDiscountCodeModule } from "./context";
16
9
  import { useTranslations } from "next-intl";
17
10
  import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
18
11
  import { EnhancedTextarea } from "@appcorp/shadcn/components/enhanced-textarea";
19
- import { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox";
12
+ import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
20
13
  import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
21
14
  import { DISCOUNT_TYPE } from "../../type";
22
15
  import { DISCOUNT_TYPE_OPTIONS } from "./constants";
23
- import { DISCOUNT_CODE_API_ROUTES } from "../../constants";
24
16
  import { getTranslatedError } from "../../utils/get-translated-error";
25
17
  export const DiscountCodeForm = () => {
26
18
  const { state, handleChange } = useDiscountCodeModule();
@@ -30,30 +22,12 @@ export const DiscountCodeForm = () => {
30
22
  FIXED: t("formOptionFixed"),
31
23
  };
32
24
  const { code, description, discountType, discountValue, enabled, errors } = state;
33
- const { enhancedComboboxElement: discountTypeCombo } = useEnhancedCombobox({
34
- id: "discountType",
35
- info: t("formDiscountTypeInfo"),
36
- label: t("formDiscountTypeLabel"),
37
- onValueChange: (value) => handleChange("discountType", value),
38
- options: DISCOUNT_TYPE_OPTIONS.map((opt) => ({
39
- value: opt.value,
40
- label: discountTypeLabelMap[opt.value] || opt.label,
41
- })),
42
- placeholder: t("formDiscountTypePlaceholder"),
43
- required: true,
44
- searchEndpoint: DISCOUNT_CODE_API_ROUTES.UNIT,
45
- formatSearchResult: (item) => {
46
- var _a, _b;
47
- return ({
48
- label: String((_a = item.label) !== null && _a !== void 0 ? _a : ""),
49
- value: String((_b = item.value) !== null && _b !== void 0 ? _b : ""),
50
- });
51
- },
52
- value: discountType,
53
- });
54
- return (_jsx("div", { className: "space-y-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "code", t }), id: "code", info: t("formDiscountCodeInfo"), label: t("formDiscountCodeLabel"), onChange: (e) => handleChange("code", e.target.value.toUpperCase()), placeholder: t("formDiscountCodePlaceholder"), required: true, value: code }), _jsx(EnhancedTextarea, { error: errors.description, id: "description", info: t("formDescriptionInfo"), label: t("formDescriptionLabel"), onChange: (e) => handleChange("description", e.target.value), placeholder: t("formDescriptionPlaceholder"), rows: 3, value: description || "" }), discountTypeCombo, _jsx(EnhancedInput, { id: "discountValue", label: t("formDiscountValueLabel"), type: "number", value: (discountValue === null || discountValue === void 0 ? void 0 : discountValue.toString()) || "", onChange: (e) => handleChange("discountValue", parseFloat(e.target.value) || 0), error: getTranslatedError({ errors, key: "discountValue", t }), placeholder: discountType === DISCOUNT_TYPE.PERCENTAGE
55
- ? t("formDiscountValuePlaceholderPercentage")
56
- : t("formDiscountValuePlaceholderFixed"), required: true, min: 0, max: discountType === DISCOUNT_TYPE.PERCENTAGE ? 100 : undefined, step: discountType === DISCOUNT_TYPE.PERCENTAGE ? 0.1 : 0.01, info: discountType === DISCOUNT_TYPE.PERCENTAGE
25
+ return (_jsx("div", { className: "space-y-6", children: _jsxs("div", { className: "grid grid-cols-1 gap-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "code", t }), id: "code", info: t("formDiscountCodeInfo"), label: t("formDiscountCodeLabel"), maxLength: 50, onChange: (e) => handleChange("code", e.target.value.toUpperCase()), placeholder: t("formDiscountCodePlaceholder"), required: true, value: code }), _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "description", t }), id: "description", info: t("formDescriptionInfo"), label: t("formDescriptionLabel"), maxLength: 500, onChange: (e) => handleChange("description", e.target.value), placeholder: t("formDescriptionPlaceholder"), rows: 3, value: description || "" }), _jsx(EnhancedCombobox, { emptyText: t("formDiscountTypePlaceholder"), error: getTranslatedError({ errors, key: "discountType", t }), id: "discountType", info: t("formDiscountTypeInfo"), label: t("formDiscountTypeLabel"), onValueChange: (value) => handleChange("discountType", value), options: DISCOUNT_TYPE_OPTIONS.map((opt) => ({
26
+ value: opt.value,
27
+ label: discountTypeLabelMap[opt.value] || opt.label,
28
+ })), placeholder: t("formDiscountTypePlaceholder"), required: true, searchPlaceholder: t("formDiscountTypePlaceholder"), value: discountType }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "discountValue", t }), id: "discountValue", info: discountType === DISCOUNT_TYPE.PERCENTAGE
57
29
  ? t("formDiscountValueInfoPercentage")
58
- : t("formDiscountValueInfoFixed") }), _jsx(EnhancedCheckbox, { checked: enabled, id: "enabled", info: t("formEnabledInfo"), label: t("formEnabledLabel"), onCheckedChange: (checked) => handleChange("enabled", checked) })] }) }));
30
+ : t("formDiscountValueInfoFixed"), label: t("formDiscountValueLabel"), max: discountType === DISCOUNT_TYPE.PERCENTAGE ? 100 : undefined, min: 0, onChange: (e) => handleChange("discountValue", parseFloat(e.target.value) || 0), placeholder: discountType === DISCOUNT_TYPE.PERCENTAGE
31
+ ? t("formDiscountValuePlaceholderPercentage")
32
+ : t("formDiscountValuePlaceholderFixed"), required: true, step: discountType === DISCOUNT_TYPE.PERCENTAGE ? 0.1 : 0.01, type: "number", value: discountValue ? discountValue.toString() : "" }), _jsx(EnhancedCheckbox, { checked: enabled, id: "enabled", info: t("formEnabledInfo"), label: t("formEnabledLabel"), onCheckedChange: (checked) => handleChange("enabled", checked) })] }) }));
59
33
  };
@@ -18,37 +18,29 @@
18
18
  "use client";
19
19
  import { jsx as _jsx } from "react/jsx-runtime";
20
20
  import { useMemo } from "react";
21
+ import { useTranslations } from "next-intl";
21
22
  import { COMPONENT_TYPE } from "@appcorp/shadcn/components/enhanced-table";
22
23
  import { createGenericModulePage, } from "@react-pakistan/util-functions/factory/generic-component-factory";
23
- import { useDiscountCodeModule, DiscountCodeProvider, DISCOUNT_CODE_ACTION_TYPES, } from "./context";
24
+ import { useDiscountCodeModule, DiscountCodeProvider } from "./context";
24
25
  import { DiscountCodeFilter } from "./filter";
25
26
  import { DiscountCodeForm } from "./form";
26
- import { DiscountCodeMoreActions } from "./more-actions";
27
27
  import { DiscountCodeView } from "./view";
28
28
  import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
29
+ import { DISCOUNT_TYPE } from "../../type";
30
+ import { getCachedWorkspaceSync } from "../workspace/cache";
29
31
  import { RbacNoAccess } from "../../components/rbac-no-access";
30
32
  // ============================================================================
31
33
  // TABLE COLUMN CONFIGURATION (static — no runtime deps)
32
34
  // ============================================================================
33
- const tableBodyCols = [
34
- { componentType: COMPONENT_TYPE.ID, key: "id" },
35
- { componentType: COMPONENT_TYPE.BOLD_TEXT, key: "code" },
36
- { componentType: COMPONENT_TYPE.TEXT, key: "description" },
37
- { componentType: COMPONENT_TYPE.TEXT, key: "discountType" },
38
- { componentType: COMPONENT_TYPE.TEXT, key: "discountValue" },
39
- { componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
40
- { componentType: COMPONENT_TYPE.ACTIONS },
41
- ];
42
35
  // ============================================================================
43
36
  // COMPONENT FACTORY (creates JSX elements when config is created, not during render)
44
37
  // ============================================================================
45
38
  const createComponentInstances = () => ({
46
39
  filter: _jsx(DiscountCodeFilter, {}),
47
40
  form: _jsx(DiscountCodeForm, {}),
48
- moreActions: _jsx(DiscountCodeMoreActions, {}),
49
41
  view: _jsx(DiscountCodeView, {}),
50
42
  });
51
- const createDiscountCodeConfig = ({ dispatch, drawerButtonCancel, drawerButtonSave, drawerFilterDescription, drawerFilterTitle, drawerFormDescription, drawerFormTitle, drawerMoreActionsDescription, drawerMoreActionsTitle, drawerViewDescription, drawerViewTitle, tableColumnHeaderActions, tableColumnHeaderCode, tableColumnHeaderDescription, tableColumnHeaderDiscountType, tableColumnHeaderDiscountValue, tableColumnHeaderEnabled, tableColumnHeaderId, tableDescription, tableSearchPlaceholder, tableTitle, }) => {
43
+ const createDiscountCodeConfig = ({ onClearFilters, drawerButtonCancel, drawerButtonSave, drawerFilterDescription, drawerFilterTitle, drawerFormDescription, drawerFormTitle, drawerMoreActionsDescription, drawerMoreActionsTitle, drawerViewDescription, drawerViewTitle, tableColumnHeaderActions, tableColumnHeaderCode, tableColumnHeaderDescription, tableColumnHeaderDiscountType, tableColumnHeaderDiscountValue, tableColumnHeaderEnabled, tableColumnHeaderId, tableDescription, tableSearchPlaceholder, tableTitle, }) => {
52
44
  const components = createComponentInstances();
53
45
  return {
54
46
  moduleName: "discountCode",
@@ -72,15 +64,13 @@ const createDiscountCodeConfig = ({ dispatch, drawerButtonCancel, drawerButtonSa
72
64
  drawerViewTitle,
73
65
  filterContent: components.filter,
74
66
  formContent: components.form,
75
- moreActionsContent: components.moreActions,
67
+ moreActionsContent: null,
76
68
  saveLabel: drawerButtonSave,
77
69
  searchPlaceholder: tableSearchPlaceholder,
78
70
  tableDescription,
79
71
  tableTitle,
80
72
  viewContent: components.view,
81
- onClearFilters: () => {
82
- dispatch({ type: DISCOUNT_CODE_ACTION_TYPES.RESET_FORM });
83
- },
73
+ onClearFilters: onClearFilters,
84
74
  };
85
75
  };
86
76
  // ============================================================================
@@ -91,10 +81,40 @@ const GenericDiscountCodePage = createGenericModulePage();
91
81
  // INNER PAGE (requires DiscountCodeProvider context)
92
82
  // ============================================================================
93
83
  const DiscountCodePageInner = (props) => {
84
+ var _a, _b, _c;
94
85
  const context = useDiscountCodeModule();
86
+ const t = useTranslations("discountCode");
87
+ const currency = (_c = (_b = (_a = getCachedWorkspaceSync()) === null || _a === void 0 ? void 0 : _a.school) === null || _b === void 0 ? void 0 : _b.currency) !== null && _c !== void 0 ? _c : "";
88
+ const typeLabels = useMemo(() => ({
89
+ PERCENTAGE: t("formOptionPercentage"),
90
+ FIXED: t("formOptionFixed"),
91
+ }), [t]);
92
+ const tableBodyCols = useMemo(() => [
93
+ { componentType: COMPONENT_TYPE.ID, key: "id" },
94
+ { componentType: COMPONENT_TYPE.BOLD_TEXT, key: "code" },
95
+ { componentType: COMPONENT_TYPE.TEXT, key: "description" },
96
+ {
97
+ componentType: COMPONENT_TYPE.TEXT,
98
+ key: "discountType",
99
+ textFormatter: (value) => { var _a; return (_a = typeLabels[String(value !== null && value !== void 0 ? value : "")]) !== null && _a !== void 0 ? _a : "—"; },
100
+ },
101
+ {
102
+ componentType: COMPONENT_TYPE.TEXT,
103
+ key: "discountValue",
104
+ textFormatter: (_, row) => {
105
+ const record = row;
106
+ const value = Number(record.discountValue);
107
+ return record.discountType === DISCOUNT_TYPE.PERCENTAGE
108
+ ? `${value}%`
109
+ : `${value.toLocaleString()} ${currency}`.trim();
110
+ },
111
+ },
112
+ { componentType: COMPONENT_TYPE.BOOLEAN, key: "enabled" },
113
+ { componentType: COMPONENT_TYPE.ACTIONS },
114
+ ], [currency, typeLabels]);
95
115
  // Memoize config creation - destructure props to avoid object reference changes
96
116
  const discountCodeConfig = useMemo(() => createDiscountCodeConfig({
97
- dispatch: context.dispatch,
117
+ onClearFilters: context.clearFilters,
98
118
  drawerButtonCancel: props.drawerButtonCancel,
99
119
  drawerButtonSave: props.drawerButtonSave,
100
120
  drawerFormTitle: props.drawerFormTitle,
@@ -116,7 +136,7 @@ const DiscountCodePageInner = (props) => {
116
136
  tableSearchPlaceholder: props.tableSearchPlaceholder,
117
137
  tableTitle: props.tableTitle,
118
138
  }), [
119
- context.dispatch,
139
+ context.clearFilters,
120
140
  props.drawerButtonCancel,
121
141
  props.drawerButtonSave,
122
142
  props.drawerFormTitle,
@@ -13,11 +13,12 @@ import { DISCOUNT_TYPE } from "../../type";
13
13
  export declare const VALIDATION_KEYS: {
14
14
  readonly codeRequired: "validationDiscountCodeCodeRequired";
15
15
  readonly codeMaxLength: "validationDiscountCodeCodeMaxLength";
16
+ readonly discountTypeRequired: "validationDiscountCodeTypeRequired";
16
17
  readonly discountValueInvalid: "validationDiscountCodeValueInvalid";
17
18
  };
18
19
  export declare const accountDiscountCodeFormValidation: z.ZodObject<{
19
20
  code: z.ZodString;
20
- description: z.ZodOptional<z.ZodString>;
21
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
21
22
  discountType: z.ZodEnum<typeof DISCOUNT_TYPE>;
22
23
  discountValue: z.ZodNumber;
23
24
  enabled: z.ZodOptional<z.ZodBoolean>;
@@ -16,17 +16,24 @@ import { DISCOUNT_TYPE } from "../../type";
16
16
  export const VALIDATION_KEYS = {
17
17
  codeRequired: "validationDiscountCodeCodeRequired",
18
18
  codeMaxLength: "validationDiscountCodeCodeMaxLength",
19
+ discountTypeRequired: "validationDiscountCodeTypeRequired",
19
20
  discountValueInvalid: "validationDiscountCodeValueInvalid",
20
21
  };
21
22
  export const accountDiscountCodeFormValidation = z
22
23
  .object({
23
24
  code: z
24
25
  .string()
26
+ .trim()
27
+ .toUpperCase()
25
28
  .min(1, VALIDATION_KEYS.codeRequired)
26
29
  .max(50, VALIDATION_KEYS.codeMaxLength),
27
- description: z.string().optional(),
28
- discountType: z.nativeEnum(DISCOUNT_TYPE),
29
- discountValue: z.number(),
30
+ description: z.string().nullable().optional(),
31
+ discountType: z.nativeEnum(DISCOUNT_TYPE, {
32
+ error: VALIDATION_KEYS.discountTypeRequired,
33
+ }),
34
+ discountValue: z
35
+ .number({ error: VALIDATION_KEYS.discountValueInvalid })
36
+ .finite(VALIDATION_KEYS.discountValueInvalid),
30
37
  enabled: z.boolean().optional(),
31
38
  })
32
39
  .refine((data) => {
@@ -16,11 +16,22 @@ import { Separator } from "@appcorp/shadcn/components/ui/separator";
16
16
  import { CheckCircle2, XCircle } from "lucide-react";
17
17
  import { DISCOUNT_TYPE } from "../../type";
18
18
  import { formatValue } from "@react-pakistan/util-functions/general/format-value";
19
+ import { getCachedWorkspaceSync } from "../workspace/cache";
19
20
  export const DiscountCodeView = () => {
21
+ var _a, _b, _c;
20
22
  const { state } = useDiscountCodeModule();
21
23
  const t = useTranslations("discountCode");
22
- const { code, description, discountType, enabled } = state;
23
- return (_jsx("div", { className: "space-y-6", children: _jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "flex items-center gap-2", children: t("viewSectionDiscountCode") }), _jsx(CardDescription, { children: t("viewSectionDiscountCodeDescription") })] }), _jsxs(CardContent, { className: "space-y-4", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: [_jsxs("div", { children: [_jsx("label", { className: "text-sm font-medium text-gray-700", children: t("viewFieldDiscountCode") }), _jsx("p", { className: "mt-1 font-mono text-lg font-semibold", children: formatValue(code) })] }), _jsxs("div", { children: [_jsx("label", { className: "text-sm font-medium text-gray-700", children: t("viewFieldStatus") }), _jsx("div", { className: "mt-1", children: _jsx(Badge, { variant: enabled ? "default" : "secondary", children: enabled ? (_jsxs(_Fragment, { children: [_jsx(CheckCircle2, { className: "mr-1 h-3 w-3" }), t("badgeEnabled")] })) : (_jsxs(_Fragment, { children: [_jsx(XCircle, { className: "mr-1 h-3 w-3" }), t("badgeDisabled")] })) }) })] }), _jsxs("div", { children: [_jsx("label", { className: "text-sm font-medium text-gray-700", children: t("viewFieldDiscountType") }), _jsx("p", { className: "mt-1 font-medium text-gray-900", children: discountType === DISCOUNT_TYPE.PERCENTAGE
24
- ? t("formOptionPercentage")
25
- : t("viewOptionDiscountTypeFixed") })] }), _jsxs("div", { children: [_jsx("label", { className: "text-sm font-medium text-gray-700", children: t("viewFieldDiscountValue") }), _jsx("p", { className: "text-primary mt-1 text-xl font-semibold" })] })] }), _jsx(Separator, {}), _jsxs("div", { children: [_jsx("label", { className: "text-sm font-medium text-gray-700", children: t("viewFieldDescription") }), _jsx("p", { className: "mt-1 text-gray-900", children: formatValue(description) })] })] })] }) }));
24
+ const { code, description, discountType, discountValue, enabled } = state;
25
+ const currency = (_c = (_b = (_a = getCachedWorkspaceSync()) === null || _a === void 0 ? void 0 : _a.school) === null || _b === void 0 ? void 0 : _b.currency) !== null && _c !== void 0 ? _c : "";
26
+ const typeLabel = discountType === DISCOUNT_TYPE.PERCENTAGE
27
+ ? t("formOptionPercentage")
28
+ : discountType === DISCOUNT_TYPE.FIXED
29
+ ? t("formOptionFixed")
30
+ : "—";
31
+ const valueLabel = discountType === DISCOUNT_TYPE.PERCENTAGE
32
+ ? `${discountValue}%`
33
+ : discountType === DISCOUNT_TYPE.FIXED
34
+ ? `${Number(discountValue).toLocaleString()} ${currency}`.trim()
35
+ : "—";
36
+ return (_jsx("div", { className: "space-y-6", children: _jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { className: "flex items-center gap-2", children: t("viewSectionDiscountCode") }), _jsx(CardDescription, { children: t("viewSectionDiscountCodeDescription") })] }), _jsxs(CardContent, { className: "space-y-4", children: [_jsxs("div", { className: "grid grid-cols-1 gap-4 md:grid-cols-2", children: [_jsxs("div", { children: [_jsx("label", { className: "text-sm font-medium text-gray-700", children: t("viewFieldDiscountCode") }), _jsx("p", { className: "mt-1 font-mono text-lg font-semibold", children: formatValue(code) })] }), _jsxs("div", { children: [_jsx("label", { className: "text-sm font-medium text-gray-700", children: t("viewFieldStatus") }), _jsx("div", { className: "mt-1", children: _jsx(Badge, { variant: enabled ? "default" : "secondary", children: enabled ? (_jsxs(_Fragment, { children: [_jsx(CheckCircle2, { className: "mr-1 h-3 w-3" }), t("badgeEnabled")] })) : (_jsxs(_Fragment, { children: [_jsx(XCircle, { className: "mr-1 h-3 w-3" }), t("badgeDisabled")] })) }) })] }), _jsxs("div", { children: [_jsx("label", { className: "text-sm font-medium text-gray-700", children: t("viewFieldDiscountType") }), _jsx("p", { className: "mt-1 font-medium text-gray-900", children: typeLabel })] }), _jsxs("div", { children: [_jsx("label", { className: "text-sm font-medium text-gray-700", children: t("viewFieldDiscountValue") }), _jsx("p", { className: "text-primary mt-1 text-xl font-semibold", children: valueLabel })] })] }), _jsx(Separator, {}), _jsxs("div", { children: [_jsx("label", { className: "text-sm font-medium text-gray-700", children: t("viewFieldDescription") }), _jsx("p", { className: "mt-1 text-gray-900", children: formatValue(description) })] })] })] }) }));
26
37
  };
@@ -31,6 +31,7 @@ export declare const ENROLLMENT_ACTION_TYPES: {
31
31
  enrollmentDate: string;
32
32
  errors: Record<string, string>;
33
33
  filterEnabled: boolean | undefined;
34
+ appliedFilterEnabled: boolean | undefined;
34
35
  id: string;
35
36
  sectionId: string;
36
37
  studentProfileId: string;
@@ -50,6 +51,7 @@ export declare const ENROLLMENT_ACTION_TYPES: {
50
51
  enrollmentDate: string;
51
52
  errors: Record<string, string>;
52
53
  filterEnabled: boolean | undefined;
54
+ appliedFilterEnabled: boolean | undefined;
53
55
  id: string;
54
56
  sectionId: string;
55
57
  studentProfileId: string;
@@ -71,6 +73,7 @@ export declare const ENROLLMENT_ACTION_TYPES: {
71
73
  enrollmentDate: string;
72
74
  errors: Record<string, string>;
73
75
  filterEnabled: boolean | undefined;
76
+ appliedFilterEnabled: boolean | undefined;
74
77
  id: string;
75
78
  sectionId: string;
76
79
  studentProfileId: string;
@@ -90,6 +93,7 @@ export declare const ENROLLMENT_ACTION_TYPES: {
90
93
  enrollmentDate: string;
91
94
  errors: Record<string, string>;
92
95
  filterEnabled: boolean | undefined;
96
+ appliedFilterEnabled: boolean | undefined;
93
97
  id: string;
94
98
  sectionId: string;
95
99
  studentProfileId: string;
@@ -109,6 +113,7 @@ export declare const ENROLLMENT_ACTION_TYPES: {
109
113
  enrollmentDate: string;
110
114
  errors: Record<string, string>;
111
115
  filterEnabled: boolean | undefined;
116
+ appliedFilterEnabled: boolean | undefined;
112
117
  id: string;
113
118
  sectionId: string;
114
119
  studentProfileId: string;
@@ -158,6 +163,7 @@ export declare const useEnrollmentModule: () => {
158
163
  enrollmentDate: string;
159
164
  errors: Record<string, string>;
160
165
  filterEnabled: boolean | undefined;
166
+ appliedFilterEnabled: boolean | undefined;
161
167
  id: string;
162
168
  sectionId: string;
163
169
  studentProfileId: string;
@@ -1,4 +1,15 @@
1
1
  "use client";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
2
13
  /**
3
14
  * Enrollment Module — business logic + API integration
4
15
  *
@@ -30,6 +41,7 @@ import { ENROLLMENT_API_ROUTES } from "../../constants";
30
41
  import { enrollmentFormValidation } from "./validate";
31
42
  import { TOAST_VARIANT, generateThemeToast, } from "@appcorp/shadcn/lib/toast-utils";
32
43
  import { getCachedWorkspaceSync } from "../workspace/cache";
44
+ import { toDateInput } from "./date";
33
45
  // ============================================================================
34
46
  // 1.1 DRAWER TYPES
35
47
  // ============================================================================
@@ -57,9 +69,12 @@ const enrollmentConfig = {
57
69
  // Form State
58
70
  classId: "",
59
71
  enabled: true,
60
- enrollmentDate: new Date().toISOString().split("T")[0],
72
+ enrollmentDate: toDateInput(new Date()),
61
73
  errors: {},
62
- filterEnabled: undefined,
74
+ // Staged filter: the drawer edits `filterEnabled`; Apply copies it to
75
+ // `appliedFilterEnabled`, which drives the request.
76
+ filterEnabled: true,
77
+ appliedFilterEnabled: true,
63
78
  id: "",
64
79
  sectionId: "",
65
80
  studentProfileId: "",
@@ -93,11 +108,11 @@ export const useEnrollmentModule = () => {
93
108
  // ==========================================================================
94
109
  // 1.4.2 API PARAMETERS
95
110
  // ==========================================================================
96
- const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.filterEnabled !== undefined
97
- ? { filterEnabled: String(state.filterEnabled) }
111
+ const listParams = useMemo(() => (Object.assign(Object.assign({ currentPage: state.currentPage, pageLimit: state.pageLimit, schoolId }, (debouncedQuery ? { searchQuery: debouncedQuery } : {})), (state.appliedFilterEnabled !== undefined
112
+ ? { filterEnabled: String(state.appliedFilterEnabled) }
98
113
  : {}))), [
114
+ state.appliedFilterEnabled,
99
115
  state.currentPage,
100
- state.filterEnabled,
101
116
  state.pageLimit,
102
117
  schoolId,
103
118
  debouncedQuery,
@@ -111,8 +126,9 @@ export const useEnrollmentModule = () => {
111
126
  schoolId,
112
127
  studentProfileId: state.studentProfileId,
113
128
  }), [state, schoolId]);
114
- const byIdParams = useMemo(() => ({ id: state.id }), [state.id]);
115
- const deleteParams = useMemo(() => ({ id: state.id }), [state.id]);
129
+ // Single-record calls must carry the tenant.
130
+ const byIdParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
131
+ const deleteParams = useMemo(() => ({ id: state.id, schoolId }), [state.id, schoolId]);
116
132
  // ==========================================================================
117
133
  // 1.4.3 UTILITIES
118
134
  // ==========================================================================
@@ -123,8 +139,24 @@ export const useEnrollmentModule = () => {
123
139
  variant,
124
140
  });
125
141
  }, [theme]);
126
- const resetFormAndCloseDrawer = useCallback(() => {
127
- dispatch({ type: ENROLLMENT_ACTION_TYPES.RESET_FORM });
142
+ /** Clear the form without touching the applied filter. */
143
+ const resetFormFields = useCallback(() => {
144
+ dispatch({
145
+ type: ENROLLMENT_ACTION_TYPES.SET_FORM_DATA,
146
+ payload: {
147
+ form: {
148
+ class: undefined,
149
+ classId: "",
150
+ enabled: true,
151
+ enrollmentDate: toDateInput(new Date()),
152
+ id: "",
153
+ section: undefined,
154
+ sectionId: "",
155
+ studentProfile: undefined,
156
+ studentProfileId: "",
157
+ },
158
+ },
159
+ });
128
160
  dispatch({
129
161
  type: ENROLLMENT_ACTION_TYPES.SET_ERRORS,
130
162
  payload: { errors: {} },
@@ -133,11 +165,14 @@ export const useEnrollmentModule = () => {
133
165
  type: ENROLLMENT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
134
166
  payload: { disabled: false },
135
167
  });
168
+ }, [dispatch]);
169
+ const resetFormAndCloseDrawer = useCallback(() => {
170
+ resetFormFields();
136
171
  dispatch({
137
172
  type: ENROLLMENT_ACTION_TYPES.SET_DRAWER,
138
173
  payload: { drawer: null },
139
174
  });
140
- }, [dispatch]);
175
+ }, [dispatch, resetFormFields]);
141
176
  // ==========================================================================
142
177
  // 1.4.4 API CALLBACKS
143
178
  // ==========================================================================
@@ -159,7 +194,6 @@ export const useEnrollmentModule = () => {
159
194
  }
160
195
  }, [dispatch, showToast, t]);
161
196
  const updateCallback = useCallback(({ data, error }) => {
162
- var _a;
163
197
  if (error) {
164
198
  showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
165
199
  return;
@@ -168,7 +202,7 @@ export const useEnrollmentModule = () => {
168
202
  showToast(isCreatedOrUpdated(data)
169
203
  ? t("messagesEnrollmentCreated")
170
204
  : t("messagesEnrollmentUpdated"), TOAST_VARIANT.SUCCESS);
171
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
205
+ // `useModuleEntityV2` schedules the list refresh.
172
206
  resetFormAndCloseDrawer();
173
207
  }
174
208
  }, [resetFormAndCloseDrawer, showToast, t]);
@@ -178,21 +212,24 @@ export const useEnrollmentModule = () => {
178
212
  return;
179
213
  }
180
214
  if (data) {
215
+ const record = data;
181
216
  dispatch({
182
217
  type: ENROLLMENT_ACTION_TYPES.SET_FORM_DATA,
183
- payload: { form: Object.assign(Object.assign({}, data), { filterEnabled: undefined }) },
218
+ payload: {
219
+ form: Object.assign(Object.assign({}, record), {
220
+ // ISO → the `YYYY-MM-DD` a date input expects.
221
+ enrollmentDate: toDateInput(record.enrollmentDate) }),
222
+ },
184
223
  });
185
224
  }
186
225
  }, [dispatch, showToast, t]);
187
226
  const deleteCallback = useCallback(({ data, error }) => {
188
- var _a;
189
227
  if (error) {
190
228
  showToast(t("messagesNetworkError"), TOAST_VARIANT.ERROR);
191
229
  return;
192
230
  }
193
231
  if (data) {
194
232
  showToast(t("messagesEnrollmentDeleted"), TOAST_VARIANT.SUCCESS);
195
- (_a = listFetchNowRef.current) === null || _a === void 0 ? void 0 : _a.call(listFetchNowRef);
196
233
  }
197
234
  }, [showToast, t]);
198
235
  // ==========================================================================
@@ -269,11 +306,13 @@ export const useEnrollmentModule = () => {
269
306
  });
270
307
  }, [dispatch]);
271
308
  const handleCreate = useCallback(() => {
309
+ // Never carry a previous record's id/values into a new entry.
310
+ resetFormFields();
272
311
  dispatch({
273
312
  type: ENROLLMENT_ACTION_TYPES.SET_DRAWER,
274
313
  payload: { drawer: ENROLLMENT_DRAWER.FORM_DRAWER },
275
314
  });
276
- }, [dispatch]);
315
+ }, [dispatch, resetFormFields]);
277
316
  const handleView = useCallback((row) => {
278
317
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
279
318
  dispatch({
@@ -292,9 +331,9 @@ export const useEnrollmentModule = () => {
292
331
  if (!confirm(t("messagesDeleteConfirmation")))
293
332
  return;
294
333
  deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
295
- body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
334
+ body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id, schoolId }),
296
335
  });
297
- }, [t, deleteFetchNow]);
336
+ }, [t, deleteFetchNow, schoolId]);
298
337
  const handleFilters = useCallback(() => {
299
338
  dispatch({
300
339
  type: ENROLLMENT_ACTION_TYPES.SET_DRAWER,
@@ -308,10 +347,8 @@ export const useEnrollmentModule = () => {
308
347
  });
309
348
  }, [dispatch]);
310
349
  const clearFilters = useCallback(() => {
311
- dispatch({
312
- type: ENROLLMENT_ACTION_TYPES.SET_FILTERS,
313
- payload: { filters: { filterEnabled: undefined } },
314
- });
350
+ // RESET_FORM restores the default filter (enabled only).
351
+ dispatch({ type: ENROLLMENT_ACTION_TYPES.RESET_FORM });
315
352
  dispatch({
316
353
  type: ENROLLMENT_ACTION_TYPES.SET_CURRENT_PAGE,
317
354
  payload: { currentPage: 1 },
@@ -329,8 +366,9 @@ export const useEnrollmentModule = () => {
329
366
  params: updateParams,
330
367
  schema: enrollmentFormValidation,
331
368
  successCallback: () => {
369
+ const { id } = updateParams, createParams = __rest(updateParams, ["id"]);
332
370
  updateFetchNow(undefined, {
333
- body: JSON.stringify(updateParams),
371
+ body: JSON.stringify(id ? updateParams : createParams),
334
372
  });
335
373
  },
336
374
  errorCallback: (errors) => {
@@ -383,7 +421,7 @@ export const useEnrollmentModule = () => {
383
421
  order: 1,
384
422
  },
385
423
  {
386
- enabled: false,
424
+ enabled: (row) => (row === null || row === void 0 ? void 0 : row.enabled) === true,
387
425
  handleOnClick: handleDelete,
388
426
  label: t("actionsButtonDelete"),
389
427
  order: 3,
@@ -391,12 +429,18 @@ export const useEnrollmentModule = () => {
391
429
  },
392
430
  ], [handleDelete, handleEdit, handleView, t]);
393
431
  const applyFilters = useCallback(() => {
432
+ dispatch({
433
+ type: ENROLLMENT_ACTION_TYPES.SET_FILTERS,
434
+ payload: {
435
+ filters: { appliedFilterEnabled: state.filterEnabled },
436
+ },
437
+ });
394
438
  dispatch({
395
439
  type: ENROLLMENT_ACTION_TYPES.SET_CURRENT_PAGE,
396
440
  payload: { currentPage: 1 },
397
441
  });
398
442
  closeDrawer();
399
- }, [dispatch, closeDrawer]);
443
+ }, [dispatch, closeDrawer, state.filterEnabled]);
400
444
  // ==========================================================================
401
445
  // 1.4.9 EFFECTS
402
446
  // ==========================================================================
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Enrollment dates are stored at UTC midnight by the API. Formatting them with
3
+ * the local timezone shifts the day in negative-offset zones.
4
+ */
5
+ /** `YYYY-MM-DD` for `<input type="date">`; empty string when invalid. */
6
+ export declare const toDateInput: (value?: string | Date | null) => string;
7
+ /** Locale date without the timezone shift. */
8
+ export declare const formatEnrollmentDate: (value?: string | Date | null) => string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Enrollment dates are stored at UTC midnight by the API. Formatting them with
3
+ * the local timezone shifts the day in negative-offset zones.
4
+ */
5
+ /** `YYYY-MM-DD` for `<input type="date">`; empty string when invalid. */
6
+ export const toDateInput = (value) => {
7
+ if (!value)
8
+ return "";
9
+ const date = new Date(value);
10
+ if (Number.isNaN(date.getTime()))
11
+ return "";
12
+ return date.toISOString().slice(0, 10);
13
+ };
14
+ /** Locale date without the timezone shift. */
15
+ export const formatEnrollmentDate = (value) => {
16
+ const day = toDateInput(value);
17
+ if (!day)
18
+ return "—";
19
+ const [year, month, date] = day.split("-").map(Number);
20
+ return new Date(Date.UTC(year, month - 1, date)).toLocaleDateString(undefined, { timeZone: "UTC" });
21
+ };
@@ -19,7 +19,7 @@ export const EnrollmentFilter = () => {
19
19
  : state.filterEnabled
20
20
  ? "true"
21
21
  : "false";
22
- return (_jsx("div", { className: "space-y-4", children: _jsx("div", { className: "grid grid-cols-1 gap-4", children: _jsx(EnhancedRadio, { label: t("filterOptionEnabled"), name: "filterEnabled", value: filterEnabledValue, options: [
22
+ return (_jsx("div", { className: "space-y-4", children: _jsx("div", { className: "grid grid-cols-1 gap-4", children: _jsx(EnhancedRadio, { label: t("filterRecordStateLabel"), name: "filterEnabled", value: filterEnabledValue, options: [
23
23
  { label: t("filterOptionAll"), value: "undefined" },
24
24
  { label: t("filterOptionEnabled"), value: "true" },
25
25
  { label: t("filterOptionDisabled"), value: "false" },