@appcorp/fusion-storybook 0.5.15 → 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.
- package/base-modules/enrollment/context.d.ts +6 -0
- package/base-modules/enrollment/context.js +69 -25
- package/base-modules/enrollment/date.d.ts +8 -0
- package/base-modules/enrollment/date.js +21 -0
- package/base-modules/enrollment/filter.js +1 -1
- package/base-modules/enrollment/form.js +55 -24
- package/base-modules/enrollment/more-actions.js +47 -10
- package/base-modules/enrollment/page.js +11 -14
- package/base-modules/enrollment/validate.d.ts +1 -0
- package/base-modules/enrollment/validate.js +3 -1
- package/base-modules/enrollment/view.js +11 -19
- package/base-modules/expense/context/expense-api-provider.js +22 -9
- package/base-modules/expense/context/shared.d.ts +35 -0
- package/base-modules/expense/context/shared.js +11 -3
- package/base-modules/expense/context/use-expense-module.d.ts +7 -1
- package/base-modules/expense/context/use-expense-module.js +58 -55
- package/base-modules/expense/filter.js +25 -57
- package/base-modules/expense/form.js +17 -74
- package/base-modules/expense/page.js +60 -29
- package/base-modules/expense/validate.d.ts +17 -11
- package/base-modules/expense/validate.js +35 -14
- package/constants.d.ts +0 -2
- package/constants.js +0 -2
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/utils/resolve-rbac-permissions.js +5 -3
- package/base-modules/expense/more-actions.d.ts +0 -1
- package/base-modules/expense/more-actions.js +0 -265
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
/**
|
|
4
4
|
* Expense Form
|
|
5
5
|
*
|
|
6
|
-
* Create / update form for an expense record.
|
|
6
|
+
* Create / update form for an expense record. Enum pickers are static —
|
|
7
|
+
* attaching a remote search would replace their options with expense rows.
|
|
7
8
|
*/
|
|
8
9
|
import { EnhancedCheckbox } from "@appcorp/shadcn/components/enhanced-checkbox";
|
|
9
|
-
import {
|
|
10
|
+
import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
|
|
10
11
|
import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
|
|
11
12
|
import { EnhancedTextarea } from "@appcorp/shadcn/components/enhanced-textarea";
|
|
12
13
|
import { EnhancedDropzone } from "@appcorp/shadcn/components/enhanced-dropzone";
|
|
13
14
|
import { useExpenseModule } from "./context";
|
|
14
15
|
import { EXPENSE_CATEGORY_OPTIONS, EXPENSE_STATUS_OPTIONS, PAYMENT_METHOD_OPTIONS, } from "./constants";
|
|
15
|
-
import { EXPENSE_API_ROUTES } from "../../constants";
|
|
16
16
|
import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
17
|
+
import { getTranslatedError } from "../../utils/get-translated-error";
|
|
17
18
|
import { useTranslations } from "next-intl";
|
|
18
19
|
export const ExpenseForm = () => {
|
|
19
20
|
var _a, _b;
|
|
@@ -54,79 +55,21 @@ export const ExpenseForm = () => {
|
|
|
54
55
|
ONLINE: t("formOptionOnline"),
|
|
55
56
|
MOBILE_WALLET: t("formOptionMobileWallet"),
|
|
56
57
|
};
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
required: true,
|
|
69
|
-
searchEndpoint: EXPENSE_API_ROUTES.UNIT,
|
|
70
|
-
searchPlaceholder: t("formSearchCategoriesPlaceholder"),
|
|
71
|
-
formatSearchResult: (item) => {
|
|
72
|
-
var _a, _b;
|
|
73
|
-
return ({
|
|
74
|
-
label: String((_a = item.label) !== null && _a !== void 0 ? _a : ""),
|
|
75
|
-
value: String((_b = item.value) !== null && _b !== void 0 ? _b : ""),
|
|
76
|
-
});
|
|
77
|
-
},
|
|
78
|
-
value: category || "",
|
|
79
|
-
});
|
|
80
|
-
const { enhancedComboboxElement: statusCombo } = useEnhancedCombobox({
|
|
81
|
-
emptyText: t("formNoStatusEmpty"),
|
|
82
|
-
id: "status",
|
|
83
|
-
info: t("formStatusInfo"),
|
|
84
|
-
label: t("formStatusLabel"),
|
|
85
|
-
onValueChange: (value) => handleChange("status", value),
|
|
86
|
-
options: EXPENSE_STATUS_OPTIONS.map((opt) => ({
|
|
87
|
-
value: opt.value,
|
|
88
|
-
label: statusLabelMap[opt.value] || opt.label,
|
|
89
|
-
})),
|
|
90
|
-
placeholder: t("formStatusPlaceholder"),
|
|
91
|
-
required: true,
|
|
92
|
-
searchEndpoint: EXPENSE_API_ROUTES.UNIT,
|
|
93
|
-
searchPlaceholder: t("formSearchStatusPlaceholder"),
|
|
94
|
-
formatSearchResult: (item) => {
|
|
95
|
-
var _a, _b;
|
|
96
|
-
return ({
|
|
97
|
-
label: String((_a = item.label) !== null && _a !== void 0 ? _a : ""),
|
|
98
|
-
value: String((_b = item.value) !== null && _b !== void 0 ? _b : ""),
|
|
99
|
-
});
|
|
100
|
-
},
|
|
101
|
-
value: status || "",
|
|
102
|
-
});
|
|
103
|
-
const { enhancedComboboxElement: paymentMethodCombo } = useEnhancedCombobox({
|
|
104
|
-
emptyText: t("formNoPaymentMethodEmpty"),
|
|
105
|
-
id: "paymentMethod",
|
|
106
|
-
info: t("formPaymentMethodInfo"),
|
|
107
|
-
label: t("formPaymentMethodLabel"),
|
|
108
|
-
onValueChange: (value) => handleChange("paymentMethod", value),
|
|
109
|
-
options: PAYMENT_METHOD_OPTIONS.map((opt) => ({
|
|
110
|
-
value: opt.value,
|
|
111
|
-
label: paymentMethodLabelMap[opt.value] || opt.label,
|
|
112
|
-
})),
|
|
113
|
-
placeholder: t("formPaymentMethodPlaceholder"),
|
|
114
|
-
searchEndpoint: EXPENSE_API_ROUTES.UNIT,
|
|
115
|
-
searchPlaceholder: t("formSearchPaymentMethodsPlaceholder"),
|
|
116
|
-
formatSearchResult: (item) => {
|
|
117
|
-
var _a, _b;
|
|
118
|
-
return ({
|
|
119
|
-
label: String((_a = item.label) !== null && _a !== void 0 ? _a : ""),
|
|
120
|
-
value: String((_b = item.value) !== null && _b !== void 0 ? _b : ""),
|
|
121
|
-
});
|
|
122
|
-
},
|
|
123
|
-
value: paymentMethod || "",
|
|
124
|
-
});
|
|
125
|
-
return (_jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedInput, { error: errors.title ? t(errors.title) : undefined, id: "title", info: t("formTitleInfo"), label: t("formTitleLabel"), onChange: (e) => handleChange("title", e.target.value), placeholder: t("formTitlePlaceholder"), required: true, type: "text", value: title || "" }), categoryCombo, statusCombo, _jsx(EnhancedInput, { error: errors.amount ? t(errors.amount) : undefined, id: "amount", info: t("formAmountInfo", { currency }), label: t("formAmountLabel"), min: "0", onChange: (e) => handleChange("amount", Number(e.target.value)), placeholder: "0.00", required: true, step: "0.01", type: "number", value: amount }), _jsx(EnhancedInput, { error: errors.expenseDate ? t(errors.expenseDate) : undefined, id: "expenseDate", info: t("formExpenseDateInfo"), label: t("formExpenseDateLabel"), onChange: (e) => handleChange("expenseDate", 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: expenseDate || "" }), _jsx(EnhancedTextarea, { error: errors.description, id: "description", label: t("formDescriptionLabel"), onChange: (e) => handleChange("description", e.target.value), placeholder: t("formDescriptionPlaceholder"), rows: 3, value: description || "" }), _jsx(EnhancedInput, { error: errors.vendorName ? t(errors.vendorName) : undefined, id: "vendorName", info: t("formVendorNameInfo"), label: t("formVendorNameLabel"), onChange: (e) => handleChange("vendorName", e.target.value), placeholder: t("formVendorNamePlaceholder"), type: "text", value: vendorName || "" }), _jsx(EnhancedInput, { error: errors.vendorContact ? t(errors.vendorContact) : undefined, id: "vendorContact", info: t("formVendorContactInfo"), label: t("formVendorContactLabel"), onChange: (e) => handleChange("vendorContact", e.target.value), placeholder: t("formVendorContactPlaceholder"), type: "text", value: vendorContact || "" }), _jsx(EnhancedInput, { error: errors.invoiceNumber ? t(errors.invoiceNumber) : undefined, id: "invoiceNumber", info: t("formInvoiceNumberInfo"), label: t("formInvoiceNumberLabel"), onChange: (e) => handleChange("invoiceNumber", e.target.value), placeholder: t("formInvoiceNumberPlaceholder"), type: "text", value: invoiceNumber || "" }), paymentMethodCombo, _jsx(EnhancedInput, { error: errors.paymentDate ? t(errors.paymentDate) : undefined, id: "paymentDate", info: t("formPaymentDateInfo"), label: t("formPaymentDateLabel"), onChange: (e) => handleChange("paymentDate", 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: paymentDate || "" }), _jsx(EnhancedInput, { error: errors.receiptNumber ? t(errors.receiptNumber) : undefined, id: "receiptNumber", info: t("formReceiptNumberInfo"), label: t("formReceiptNumberLabel"), onChange: (e) => handleChange("receiptNumber", e.target.value), placeholder: t("formReceiptNumberPlaceholder"), type: "text", value: receiptNumber || "" }), _jsx(EnhancedInput, { error: errors.transactionId ? t(errors.transactionId) : undefined, id: "transactionId", info: t("formTransactionIdInfo"), label: t("formTransactionIdLabel"), onChange: (e) => handleChange("transactionId", e.target.value), placeholder: t("formTransactionIdPlaceholder"), type: "text", value: transactionId || "" }), _jsx(EnhancedTextarea, { error: errors.remarks, id: "remarks", label: t("formRemarksLabel"), onChange: (e) => handleChange("remarks", e.target.value), placeholder: t("formRemarksPlaceholder"), rows: 3, value: remarks || "" }), _jsx(EnhancedDropzone, { accept: ["image/*", "application/pdf"], error: errors.attachments ? t(errors.attachments) : undefined, id: "attachments", info: t("formAttachmentsInfo"), label: t("formAttachmentsLabel"), maxFiles: 10, onChange: (files) => {
|
|
58
|
+
const isPaid = status === "PAID";
|
|
59
|
+
return (_jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "title", t }), id: "title", info: t("formTitleInfo"), label: t("formTitleLabel"), maxLength: 200, onChange: (e) => handleChange("title", e.target.value), placeholder: t("formTitlePlaceholder"), required: true, type: "text", value: title || "" }), _jsx(EnhancedCombobox, { emptyText: t("formNoCategoryEmpty"), error: getTranslatedError({ errors, key: "category", t }), id: "category", info: t("formCategoryInfo"), label: t("formCategoryLabel"), onValueChange: (value) => handleChange("category", value), options: EXPENSE_CATEGORY_OPTIONS.map((opt) => ({
|
|
60
|
+
value: opt.value,
|
|
61
|
+
label: categoryLabelMap[opt.value] || opt.label,
|
|
62
|
+
})), placeholder: t("formCategoryPlaceholder"), required: true, searchPlaceholder: t("formCategoryPlaceholder"), value: category || "" }), _jsx(EnhancedCombobox, { emptyText: t("formNoStatusEmpty"), error: getTranslatedError({ errors, key: "status", t }), id: "status", info: t("formStatusInfo"), label: t("formStatusLabel"), onValueChange: (value) => handleChange("status", value), options: EXPENSE_STATUS_OPTIONS.map((opt) => ({
|
|
63
|
+
value: opt.value,
|
|
64
|
+
label: statusLabelMap[opt.value] || opt.label,
|
|
65
|
+
})), placeholder: t("formStatusPlaceholder"), required: true, searchPlaceholder: t("formStatusPlaceholder"), value: status || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "amount", t }), id: "amount", info: t("formAmountInfo", { currency }), label: t("formAmountLabel"), min: "0", onChange: (e) => handleChange("amount", Number(e.target.value)), placeholder: "0.00", required: true, step: "0.01", type: "number", value: amount }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "expenseDate", t }), id: "expenseDate", info: t("formExpenseDateInfo"), label: t("formExpenseDateLabel"), onChange: (e) => handleChange("expenseDate", 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: expenseDate || "" }), _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "description", t }), id: "description", label: t("formDescriptionLabel"), maxLength: 1000, onChange: (e) => handleChange("description", e.target.value), placeholder: t("formDescriptionPlaceholder"), rows: 3, value: description || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "vendorName", t }), id: "vendorName", info: t("formVendorNameInfo"), label: t("formVendorNameLabel"), maxLength: 200, onChange: (e) => handleChange("vendorName", e.target.value), placeholder: t("formVendorNamePlaceholder"), type: "text", value: vendorName || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "vendorContact", t }), id: "vendorContact", info: t("formVendorContactInfo"), label: t("formVendorContactLabel"), maxLength: 200, onChange: (e) => handleChange("vendorContact", e.target.value), placeholder: t("formVendorContactPlaceholder"), type: "text", value: vendorContact || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "invoiceNumber", t }), id: "invoiceNumber", info: t("formInvoiceNumberInfo"), label: t("formInvoiceNumberLabel"), maxLength: 100, onChange: (e) => handleChange("invoiceNumber", e.target.value), placeholder: t("formInvoiceNumberPlaceholder"), type: "text", value: invoiceNumber || "" }), isPaid ? (_jsxs(_Fragment, { children: [_jsx(EnhancedCombobox, { emptyText: t("formNoPaymentMethodEmpty"), id: "paymentMethod", info: t("formPaymentMethodInfo"), label: t("formPaymentMethodLabel"), onValueChange: (value) => handleChange("paymentMethod", value), options: PAYMENT_METHOD_OPTIONS.map((opt) => ({
|
|
66
|
+
value: opt.value,
|
|
67
|
+
label: paymentMethodLabelMap[opt.value] || opt.label,
|
|
68
|
+
})), placeholder: t("formPaymentMethodPlaceholder"), searchPlaceholder: t("formPaymentMethodPlaceholder"), value: paymentMethod || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "paymentDate", t }), id: "paymentDate", info: t("formPaymentDateInfo"), label: t("formPaymentDateLabel"), onChange: (e) => handleChange("paymentDate", 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: paymentDate || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "receiptNumber", t }), id: "receiptNumber", info: t("formReceiptNumberInfo"), label: t("formReceiptNumberLabel"), maxLength: 100, onChange: (e) => handleChange("receiptNumber", e.target.value), placeholder: t("formReceiptNumberPlaceholder"), type: "text", value: receiptNumber || "" }), _jsx(EnhancedInput, { error: getTranslatedError({ errors, key: "transactionId", t }), id: "transactionId", info: t("formTransactionIdInfo"), label: t("formTransactionIdLabel"), maxLength: 100, onChange: (e) => handleChange("transactionId", e.target.value), placeholder: t("formTransactionIdPlaceholder"), type: "text", value: transactionId || "" })] })) : null, _jsx(EnhancedTextarea, { error: getTranslatedError({ errors, key: "remarks", t }), id: "remarks", label: t("formRemarksLabel"), maxLength: 1000, onChange: (e) => handleChange("remarks", e.target.value), placeholder: t("formRemarksPlaceholder"), rows: 3, value: remarks || "" }), _jsx(EnhancedDropzone, { accept: ["image/*", "application/pdf"], error: getTranslatedError({ errors, key: "attachments", t }), id: "attachments", info: t("formAttachmentsInfo"), label: t("formAttachmentsLabel"), maxFiles: 10, onChange: (files) => {
|
|
126
69
|
const urls = files.map((f) => URL.createObjectURL(f));
|
|
127
70
|
handleChange("attachments", urls);
|
|
128
71
|
}, onRemoveRemote: (url) => {
|
|
129
72
|
const newList = (attachments || []).filter((a) => a !== url);
|
|
130
73
|
handleChange("attachments", newList);
|
|
131
|
-
}, value: attachments || [] }), _jsx(EnhancedCheckbox, { checked: enabled, error: errors
|
|
74
|
+
}, value: attachments || [] }), _jsx(EnhancedCheckbox, { checked: enabled, error: getTranslatedError({ errors, key: "enabled", t }), id: "enabled", info: t("formEnabledInfo"), label: t("badgeActive"), onCheckedChange: (checked) => handleChange("enabled", !!checked) })] }));
|
|
132
75
|
};
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"use client";
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
17
|
import { useMemo } from "react";
|
|
18
|
+
import { useTranslations } from "next-intl";
|
|
18
19
|
import { COMPONENT_TYPE } from "@appcorp/shadcn/components/enhanced-table";
|
|
19
20
|
import { createGenericModulePage, } from "@react-pakistan/util-functions/factory/generic-component-factory";
|
|
20
21
|
import { DATE_FORMATS, formatDate, } from "@react-pakistan/util-functions/general/format-date";
|
|
21
22
|
import { useExpenseModule, ExpenseProvider, ExpenseApiProvider, } from "./context";
|
|
22
23
|
import { ExpenseFilter } from "./filter";
|
|
23
24
|
import { ExpenseForm } from "./form";
|
|
24
|
-
import { ExpenseMoreActions } from "./more-actions";
|
|
25
25
|
import { ExpenseView } from "./view";
|
|
26
26
|
import { resolveRbacPermissions } from "../../utils/resolve-rbac-permissions";
|
|
27
27
|
import { RbacNoAccess } from "../../components/rbac-no-access";
|
|
@@ -29,39 +29,12 @@ import { getCachedWorkspaceSync } from "../workspace/cache";
|
|
|
29
29
|
// ============================================================================
|
|
30
30
|
// TABLE COLUMN CONFIGURATION (static — lazy workspace currency per row)
|
|
31
31
|
// ============================================================================
|
|
32
|
-
const tableBodyCols = [
|
|
33
|
-
{ componentType: COMPONENT_TYPE.ID, key: "id" },
|
|
34
|
-
{ componentType: COMPONENT_TYPE.BOLD_TEXT, key: "title" },
|
|
35
|
-
{ componentType: COMPONENT_TYPE.TEXT, key: "category" },
|
|
36
|
-
{
|
|
37
|
-
componentType: COMPONENT_TYPE.TEXT,
|
|
38
|
-
key: "amount",
|
|
39
|
-
textFormatter: (_, row) => {
|
|
40
|
-
var _a, _b, _c, _d;
|
|
41
|
-
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 : "";
|
|
42
|
-
return `${currency} ${((_d = row.amount) !== null && _d !== void 0 ? _d : 0).toFixed(2)}`;
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
componentType: COMPONENT_TYPE.TEXT,
|
|
47
|
-
key: "expenseDate",
|
|
48
|
-
textFormatter: (_, row) => formatDate(row.expenseDate, DATE_FORMATS.LOCALE_DATE),
|
|
49
|
-
},
|
|
50
|
-
{ componentType: COMPONENT_TYPE.TEXT, key: "status" },
|
|
51
|
-
{
|
|
52
|
-
componentType: COMPONENT_TYPE.TEXT,
|
|
53
|
-
key: "vendorName",
|
|
54
|
-
textFormatter: (_, row) => row.vendorName || "N/A",
|
|
55
|
-
},
|
|
56
|
-
{ componentType: COMPONENT_TYPE.ACTIONS },
|
|
57
|
-
];
|
|
58
32
|
// ============================================================================
|
|
59
33
|
// COMPONENT FACTORY (creates JSX elements when config is created, not during render)
|
|
60
34
|
// ============================================================================
|
|
61
35
|
const createComponentInstances = () => ({
|
|
62
36
|
filter: _jsx(ExpenseFilter, {}),
|
|
63
37
|
form: _jsx(ExpenseForm, {}),
|
|
64
|
-
moreActions: _jsx(ExpenseMoreActions, {}),
|
|
65
38
|
view: _jsx(ExpenseView, {}),
|
|
66
39
|
});
|
|
67
40
|
const createExpenseConfig = ({ clearFilters, drawerButtonCancel, drawerButtonSave, drawerFilterDescription, drawerFilterTitle, drawerFormDescription, drawerFormTitle, drawerMoreActionsDescription, drawerMoreActionsTitle, drawerViewDescription, drawerViewTitle, tableColumnHeaderActions, tableColumnHeaderAmount, tableColumnHeaderCategory, tableColumnHeaderExpenseDate, tableColumnHeaderId, tableColumnHeaderStatus, tableColumnHeaderTitle, tableColumnHeaderVendorName, tableDescription, tableSearchPlaceholder, tableTitle, }) => {
|
|
@@ -89,7 +62,7 @@ const createExpenseConfig = ({ clearFilters, drawerButtonCancel, drawerButtonSav
|
|
|
89
62
|
drawerViewTitle,
|
|
90
63
|
filterContent: components.filter,
|
|
91
64
|
formContent: components.form,
|
|
92
|
-
moreActionsContent:
|
|
65
|
+
moreActionsContent: null,
|
|
93
66
|
saveLabel: drawerButtonSave,
|
|
94
67
|
searchPlaceholder: tableSearchPlaceholder,
|
|
95
68
|
tableDescription,
|
|
@@ -107,6 +80,64 @@ const GenericExpensePage = createGenericModulePage();
|
|
|
107
80
|
// ============================================================================
|
|
108
81
|
const ExpensePageInner = (props) => {
|
|
109
82
|
const context = useExpenseModule();
|
|
83
|
+
const t = useTranslations("expense");
|
|
84
|
+
const categoryLabels = useMemo(() => ({
|
|
85
|
+
SALARY: t("formOptionSalary"),
|
|
86
|
+
UTILITIES: t("formOptionUtilities"),
|
|
87
|
+
MAINTENANCE: t("formOptionMaintenance"),
|
|
88
|
+
SUPPLIES: t("formOptionSupplies"),
|
|
89
|
+
TRANSPORT: t("formOptionTransport"),
|
|
90
|
+
MARKETING: t("formOptionMarketing"),
|
|
91
|
+
INSURANCE: t("formOptionInsurance"),
|
|
92
|
+
RENT: t("formOptionRent"),
|
|
93
|
+
TECHNOLOGY: t("formOptionTechnology"),
|
|
94
|
+
PROFESSIONAL: t("formOptionProfessional"),
|
|
95
|
+
TRAINING: t("formOptionTraining"),
|
|
96
|
+
EVENTS: t("formOptionEvents"),
|
|
97
|
+
FOOD: t("formOptionFood"),
|
|
98
|
+
MISCELLANEOUS: t("formOptionMiscellaneous"),
|
|
99
|
+
}), [t]);
|
|
100
|
+
const statusLabels = useMemo(() => ({
|
|
101
|
+
PENDING: t("formOptionPending"),
|
|
102
|
+
APPROVED: t("formOptionApproved"),
|
|
103
|
+
PAID: t("formOptionPaid"),
|
|
104
|
+
REJECTED: t("formOptionRejected"),
|
|
105
|
+
CANCELLED: t("formOptionCancelled"),
|
|
106
|
+
}), [t]);
|
|
107
|
+
const tableBodyCols = useMemo(() => [
|
|
108
|
+
{ componentType: COMPONENT_TYPE.ID, key: "id" },
|
|
109
|
+
{ componentType: COMPONENT_TYPE.BOLD_TEXT, key: "title" },
|
|
110
|
+
{
|
|
111
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
112
|
+
key: "category",
|
|
113
|
+
textFormatter: (value) => { var _a; return (_a = categoryLabels[String(value !== null && value !== void 0 ? value : "")]) !== null && _a !== void 0 ? _a : "—"; },
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
117
|
+
key: "amount",
|
|
118
|
+
textFormatter: (_, row) => {
|
|
119
|
+
var _a, _b, _c, _d;
|
|
120
|
+
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 : "";
|
|
121
|
+
return `${currency} ${((_d = row.amount) !== null && _d !== void 0 ? _d : 0).toFixed(2)}`.trim();
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
126
|
+
key: "expenseDate",
|
|
127
|
+
textFormatter: (value) => value ? formatDate(value, DATE_FORMATS.LOCALE_DATE) : "—",
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
131
|
+
key: "status",
|
|
132
|
+
textFormatter: (value) => { var _a; return (_a = statusLabels[String(value !== null && value !== void 0 ? value : "")]) !== null && _a !== void 0 ? _a : "—"; },
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
componentType: COMPONENT_TYPE.TEXT,
|
|
136
|
+
key: "vendorName",
|
|
137
|
+
textFormatter: (value) => value || "—",
|
|
138
|
+
},
|
|
139
|
+
{ componentType: COMPONENT_TYPE.ACTIONS },
|
|
140
|
+
], [categoryLabels, statusLabels]);
|
|
110
141
|
// Memoize config creation - destructure props to avoid object reference changes
|
|
111
142
|
const expenseConfig = useMemo(() => createExpenseConfig({
|
|
112
143
|
clearFilters: context.clearFilters,
|
|
@@ -1,31 +1,37 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Expense Module Validation
|
|
3
3
|
*
|
|
4
|
-
* Zod validation schemas for expense forms.
|
|
4
|
+
* Zod validation schemas for expense forms. Optional text fields accept
|
|
5
|
+
* `null` because the API returns `null` for empty values.
|
|
5
6
|
*/
|
|
6
7
|
import { z } from "zod";
|
|
7
8
|
import { EXPENSE_CATEGORY, EXPENSE_STATUS, PAYMENT_METHOD } from "../../type";
|
|
8
9
|
export declare const VALIDATION_KEYS: {
|
|
9
10
|
readonly titleRequired: "validationExpenseTitleRequired";
|
|
11
|
+
readonly titleMaxLength: "validationExpenseTitleMaxLength";
|
|
10
12
|
readonly amountRequired: "validationExpenseAmountRequired";
|
|
11
13
|
readonly categoryRequired: "validationExpenseCategoryRequired";
|
|
12
14
|
readonly expenseDateRequired: "validationExpenseExpenseDateRequired";
|
|
15
|
+
readonly invalidDate: "validationExpenseInvalidDate";
|
|
13
16
|
readonly statusRequired: "validationExpenseStatusRequired";
|
|
14
|
-
readonly idForUpdateRequired: "validationExpenseIdForUpdateRequired";
|
|
15
17
|
};
|
|
16
18
|
export declare const expenseFormValidation: z.ZodObject<{
|
|
17
19
|
amount: z.ZodNumber;
|
|
18
20
|
category: z.ZodEnum<typeof EXPENSE_CATEGORY>;
|
|
19
|
-
description: z.ZodOptional<z.ZodString
|
|
21
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
20
22
|
expenseDate: z.ZodString;
|
|
21
|
-
invoiceNumber: z.ZodOptional<z.ZodString
|
|
22
|
-
paymentDate: z.ZodOptional<z.ZodString
|
|
23
|
-
paymentMethod: z.ZodOptional<z.ZodEnum<typeof PAYMENT_METHOD
|
|
24
|
-
receiptNumber: z.ZodOptional<z.ZodString
|
|
25
|
-
remarks: z.ZodOptional<z.ZodString
|
|
23
|
+
invoiceNumber: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
24
|
+
paymentDate: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
25
|
+
paymentMethod: z.ZodOptional<z.ZodNullable<z.ZodEnum<typeof PAYMENT_METHOD>>>;
|
|
26
|
+
receiptNumber: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
27
|
+
remarks: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
26
28
|
status: z.ZodEnum<typeof EXPENSE_STATUS>;
|
|
27
29
|
title: z.ZodString;
|
|
28
|
-
transactionId: z.ZodOptional<z.ZodString
|
|
29
|
-
vendorContact: z.ZodOptional<z.ZodString
|
|
30
|
-
vendorName: z.ZodOptional<z.ZodString
|
|
30
|
+
transactionId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
31
|
+
vendorContact: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
32
|
+
vendorName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
33
|
+
approvedBy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
34
|
+
paidBy: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
35
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
36
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
31
37
|
}, z.core.$strip>;
|
|
@@ -1,35 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Expense Module Validation
|
|
3
3
|
*
|
|
4
|
-
* Zod validation schemas for expense forms.
|
|
4
|
+
* Zod validation schemas for expense forms. Optional text fields accept
|
|
5
|
+
* `null` because the API returns `null` for empty values.
|
|
5
6
|
*/
|
|
6
7
|
import { z } from "zod";
|
|
7
8
|
import { EXPENSE_CATEGORY, EXPENSE_STATUS, PAYMENT_METHOD } from "../../type";
|
|
8
9
|
export const VALIDATION_KEYS = {
|
|
9
10
|
titleRequired: "validationExpenseTitleRequired",
|
|
11
|
+
titleMaxLength: "validationExpenseTitleMaxLength",
|
|
10
12
|
amountRequired: "validationExpenseAmountRequired",
|
|
11
13
|
categoryRequired: "validationExpenseCategoryRequired",
|
|
12
14
|
expenseDateRequired: "validationExpenseExpenseDateRequired",
|
|
15
|
+
invalidDate: "validationExpenseInvalidDate",
|
|
13
16
|
statusRequired: "validationExpenseStatusRequired",
|
|
14
|
-
idForUpdateRequired: "validationExpenseIdForUpdateRequired",
|
|
15
17
|
};
|
|
18
|
+
const optionalText = z.string().nullable().optional();
|
|
19
|
+
const validDate = (value) => !Number.isNaN(new Date(value).getTime());
|
|
16
20
|
export const expenseFormValidation = z.object({
|
|
17
|
-
amount: z
|
|
21
|
+
amount: z
|
|
22
|
+
.number({ error: VALIDATION_KEYS.amountRequired })
|
|
23
|
+
.positive(VALIDATION_KEYS.amountRequired),
|
|
18
24
|
category: z.nativeEnum(EXPENSE_CATEGORY, {
|
|
19
25
|
error: VALIDATION_KEYS.categoryRequired,
|
|
20
26
|
}),
|
|
21
|
-
description:
|
|
22
|
-
expenseDate: z
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
description: optionalText,
|
|
28
|
+
expenseDate: z
|
|
29
|
+
.string()
|
|
30
|
+
.min(1, VALIDATION_KEYS.expenseDateRequired)
|
|
31
|
+
.refine(validDate, VALIDATION_KEYS.invalidDate),
|
|
32
|
+
invoiceNumber: optionalText,
|
|
33
|
+
paymentDate: z
|
|
34
|
+
.string()
|
|
35
|
+
.nullable()
|
|
36
|
+
.optional()
|
|
37
|
+
.refine((value) => !value || validDate(value), VALIDATION_KEYS.invalidDate),
|
|
38
|
+
paymentMethod: z.nativeEnum(PAYMENT_METHOD).nullable().optional(),
|
|
39
|
+
receiptNumber: optionalText,
|
|
40
|
+
remarks: optionalText,
|
|
28
41
|
status: z.nativeEnum(EXPENSE_STATUS, {
|
|
29
42
|
error: VALIDATION_KEYS.statusRequired,
|
|
30
43
|
}),
|
|
31
|
-
title: z
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
44
|
+
title: z
|
|
45
|
+
.string()
|
|
46
|
+
.trim()
|
|
47
|
+
.min(1, VALIDATION_KEYS.titleRequired)
|
|
48
|
+
.max(200, VALIDATION_KEYS.titleMaxLength),
|
|
49
|
+
transactionId: optionalText,
|
|
50
|
+
vendorContact: optionalText,
|
|
51
|
+
vendorName: optionalText,
|
|
52
|
+
approvedBy: optionalText,
|
|
53
|
+
paidBy: optionalText,
|
|
54
|
+
attachments: z.array(z.string()).optional(),
|
|
55
|
+
enabled: z.boolean().optional(),
|
|
35
56
|
});
|
package/constants.d.ts
CHANGED
|
@@ -45,8 +45,6 @@ export declare const ENROLLMENT_API_ROUTES: {
|
|
|
45
45
|
};
|
|
46
46
|
export declare const EXPENSE_API_ROUTES: {
|
|
47
47
|
readonly UNIT: "/api/v1/expense";
|
|
48
|
-
readonly BULK: "/api/v1/expense/bulk";
|
|
49
|
-
readonly BULK_STATUS: (jobId: string) => string;
|
|
50
48
|
};
|
|
51
49
|
export declare const FAMILY_API_ROUTES: {
|
|
52
50
|
readonly UNIT: "/api/v1/family";
|
package/constants.js
CHANGED
|
@@ -48,8 +48,6 @@ export const ENROLLMENT_API_ROUTES = {
|
|
|
48
48
|
};
|
|
49
49
|
export const EXPENSE_API_ROUTES = {
|
|
50
50
|
UNIT: "/api/v1/expense",
|
|
51
|
-
BULK: "/api/v1/expense/bulk",
|
|
52
|
-
BULK_STATUS: (jobId) => `/api/v1/expense/bulk/${jobId}`,
|
|
53
51
|
};
|
|
54
52
|
export const FAMILY_API_ROUTES = {
|
|
55
53
|
UNIT: "/api/v1/family",
|