@appcorp/fusion-storybook 0.5.13 → 0.5.15
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/class/context/use-class-module.d.ts +55 -0
- package/base-modules/class/context/use-class-module.js +421 -0
- package/base-modules/class/context.d.ts +27 -52
- package/base-modules/class/context.js +18 -415
- package/base-modules/class/filter.js +16 -6
- package/base-modules/class/form.js +19 -3
- package/base-modules/class/more-actions.js +48 -10
- package/base-modules/class/page.js +15 -5
- package/base-modules/class/validate.d.ts +2 -2
- package/base-modules/class/validate.js +7 -3
- package/base-modules/class/view.js +2 -4
- package/base-modules/discount-code/context/use-discount-code-module.d.ts +65 -0
- package/base-modules/discount-code/context/use-discount-code-module.js +402 -0
- package/base-modules/discount-code/context.d.ts +32 -80
- package/base-modules/discount-code/context.js +14 -430
- package/base-modules/discount-code/filter.d.ts +1 -10
- package/base-modules/discount-code/filter.js +34 -8
- package/base-modules/discount-code/form.js +9 -35
- package/base-modules/discount-code/page.js +39 -19
- package/base-modules/discount-code/validate.d.ts +2 -1
- package/base-modules/discount-code/validate.js +10 -3
- package/base-modules/discount-code/view.js +15 -4
- package/constants.d.ts +1 -1
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/resolve-rbac-permissions.js +5 -3
- package/base-modules/discount-code/more-actions.d.ts +0 -9
- package/base-modules/discount-code/more-actions.js +0 -13
|
@@ -1,14 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Discount Code Filter
|
|
5
5
|
*
|
|
6
|
-
*
|
|
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
|
-
|
|
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
|
-
*
|
|
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 {
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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")
|
|
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
|
|
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 = ({
|
|
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:
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
};
|
package/constants.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare const COURSE_API_ROUTES: {
|
|
|
35
35
|
readonly UNIT: "/api/v1/course";
|
|
36
36
|
};
|
|
37
37
|
export declare const DISCOUNT_CODE_API_ROUTES: {
|
|
38
|
-
UNIT:
|
|
38
|
+
readonly UNIT: "/api/v1/discount-code";
|
|
39
39
|
};
|
|
40
40
|
export declare const ENROLLMENT_API_ROUTES: {
|
|
41
41
|
readonly LIST: "/api/v1/enrollment";
|