@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
@@ -79,12 +79,49 @@ export const useExpenseModule = () => {
79
79
  const closeDrawer = useCallback(() => {
80
80
  resetFormAndCloseDrawer();
81
81
  }, [resetFormAndCloseDrawer]);
82
+ const resetFormFields = useCallback(() => {
83
+ dispatch({
84
+ type: EXPENSE_ACTION_TYPES.SET_FORM_DATA,
85
+ payload: {
86
+ form: {
87
+ amount: 0,
88
+ approvedBy: "",
89
+ attachments: [],
90
+ category: "",
91
+ description: "",
92
+ enabled: true,
93
+ expenseDate: new Date().toISOString().slice(0, 10),
94
+ id: "",
95
+ invoiceNumber: "",
96
+ paidBy: "",
97
+ paymentDate: "",
98
+ paymentMethod: "",
99
+ receiptNumber: "",
100
+ remarks: "",
101
+ status: "",
102
+ title: "",
103
+ transactionId: "",
104
+ vendorContact: "",
105
+ vendorName: "",
106
+ },
107
+ },
108
+ });
109
+ dispatch({
110
+ type: EXPENSE_ACTION_TYPES.SET_ERRORS,
111
+ payload: { errors: {} },
112
+ });
113
+ dispatch({
114
+ type: EXPENSE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
115
+ payload: { disabled: false },
116
+ });
117
+ }, [dispatch]);
82
118
  const handleCreate = useCallback(() => {
119
+ resetFormFields();
83
120
  dispatch({
84
121
  type: EXPENSE_ACTION_TYPES.SET_DRAWER,
85
122
  payload: { drawer: EXPENSE_DRAWER.FORM_DRAWER },
86
123
  });
87
- }, [dispatch]);
124
+ }, [dispatch, resetFormFields]);
88
125
  const handleView = useCallback((row) => {
89
126
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, { params: { id: row === null || row === void 0 ? void 0 : row.id } });
90
127
  dispatch({
@@ -103,21 +140,15 @@ export const useExpenseModule = () => {
103
140
  if (!confirm(t("messagesDeleteConfirmation")))
104
141
  return;
105
142
  deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
106
- body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id }),
143
+ body: JSON.stringify({ id: row === null || row === void 0 ? void 0 : row.id, schoolId }),
107
144
  });
108
- }, [deleteFetchNow, t]);
145
+ }, [deleteFetchNow, schoolId, t]);
109
146
  const handleFilters = useCallback(() => {
110
147
  dispatch({
111
148
  type: EXPENSE_ACTION_TYPES.SET_DRAWER,
112
149
  payload: { drawer: EXPENSE_DRAWER.FILTER_DRAWER },
113
150
  });
114
151
  }, [dispatch]);
115
- const handleMoreActions = useCallback(() => {
116
- dispatch({
117
- type: EXPENSE_ACTION_TYPES.SET_DRAWER,
118
- payload: { drawer: EXPENSE_DRAWER.MORE_ACTIONS_DRAWER },
119
- });
120
- }, [dispatch]);
121
152
  const handlePageChange = useCallback((page) => {
122
153
  const nextPage = typeof page === "number" ? page : state.currentPage + 1;
123
154
  dispatch({
@@ -149,61 +180,39 @@ export const useExpenseModule = () => {
149
180
  });
150
181
  }, [dispatch]);
151
182
  const applyFilters = useCallback(() => {
152
- closeDrawer();
153
- dispatch({
154
- type: EXPENSE_ACTION_TYPES.SET_INPUT_FIELD,
155
- payload: { key: "filterCategory", value: state.filterCategory },
156
- });
157
183
  dispatch({
158
- type: EXPENSE_ACTION_TYPES.SET_INPUT_FIELD,
159
- payload: { key: "filterStatus", value: state.filterStatus },
160
- });
161
- dispatch({
162
- type: EXPENSE_ACTION_TYPES.SET_INPUT_FIELD,
163
- payload: { key: "filterEnabled", value: state.filterEnabled },
184
+ type: EXPENSE_ACTION_TYPES.SET_FILTERS,
185
+ payload: {
186
+ filters: {
187
+ appliedFilterEnabled: state.filterEnabled,
188
+ appliedFilterCategory: state.filterCategory,
189
+ appliedFilterStatus: state.filterStatus,
190
+ appliedFilterFromDate: state.filterFromDate,
191
+ appliedFilterToDate: state.filterToDate,
192
+ },
193
+ },
164
194
  });
165
195
  dispatch({
166
196
  type: EXPENSE_ACTION_TYPES.SET_CURRENT_PAGE,
167
197
  payload: { currentPage: 1 },
168
198
  });
169
- listFetchNow === null || listFetchNow === void 0 ? void 0 : listFetchNow(undefined, {
170
- params: Object.assign(Object.assign(Object.assign({ currentPage: 1, pageLimit: state.pageLimit, schoolId }, (state.filterCategory && { filterCategory: state.filterCategory })), (state.filterStatus && { filterStatus: state.filterStatus })), (state.filterEnabled !== undefined && {
171
- filterEnabled: state.filterEnabled,
172
- })),
173
- });
199
+ closeDrawer();
174
200
  }, [
175
201
  closeDrawer,
176
202
  dispatch,
177
- listFetchNow,
178
- schoolId,
179
203
  state.filterCategory,
180
204
  state.filterEnabled,
205
+ state.filterFromDate,
181
206
  state.filterStatus,
182
- state.pageLimit,
207
+ state.filterToDate,
183
208
  ]);
184
209
  const clearFilters = useCallback(() => {
210
+ dispatch({ type: EXPENSE_ACTION_TYPES.RESET_FORM });
185
211
  dispatch({
186
212
  type: EXPENSE_ACTION_TYPES.SET_CURRENT_PAGE,
187
213
  payload: { currentPage: 1 },
188
214
  });
189
- dispatch({
190
- type: EXPENSE_ACTION_TYPES.SET_FILTERS,
191
- payload: {
192
- filters: {
193
- filterEnabled: undefined,
194
- filterCategory: "",
195
- filterStatus: "",
196
- },
197
- },
198
- });
199
- listFetchNow(undefined, {
200
- params: {
201
- currentPage: 1,
202
- pageLimit: state.pageLimit,
203
- schoolId,
204
- },
205
- });
206
- }, [dispatch, listFetchNow, state.pageLimit, schoolId]);
215
+ }, [dispatch]);
207
216
  // ============================================================================
208
217
  // 1.4.5 NETWORK ACTIONS
209
218
  // ============================================================================
@@ -237,12 +246,6 @@ export const useExpenseModule = () => {
237
246
  // 1.4.6 HEADER & ROW ACTIONS
238
247
  // ============================================================================
239
248
  const headerActions = useMemo(() => [
240
- {
241
- enabled: true,
242
- handleOnClick: handleMoreActions,
243
- label: t("actionsButtonMoreActions"),
244
- order: 0,
245
- },
246
249
  {
247
250
  enabled: true,
248
251
  handleOnClick: handleFilters,
@@ -255,7 +258,7 @@ export const useExpenseModule = () => {
255
258
  label: t("actionsButtonAdd"),
256
259
  order: 2,
257
260
  },
258
- ], [handleCreate, handleFilters, handleMoreActions, t]);
261
+ ], [handleCreate, handleFilters, t]);
259
262
  const rowActions = useMemo(() => [
260
263
  {
261
264
  enabled: true,
@@ -270,10 +273,11 @@ export const useExpenseModule = () => {
270
273
  order: 2,
271
274
  },
272
275
  {
273
- enabled: false,
276
+ enabled: (row) => (row === null || row === void 0 ? void 0 : row.enabled) === true,
274
277
  handleOnClick: handleDelete,
275
278
  label: t("actionsButtonDelete"),
276
279
  order: 3,
280
+ variant: "destructive",
277
281
  },
278
282
  ], [handleDelete, handleEdit, handleView, t]);
279
283
  // ============================================================================
@@ -290,7 +294,6 @@ export const useExpenseModule = () => {
290
294
  handleDelete,
291
295
  handleEdit,
292
296
  handleFilters,
293
- handleMoreActions,
294
297
  handlePageChange,
295
298
  handlePageLimitChange,
296
299
  handleSearch,
@@ -3,18 +3,18 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  /**
4
4
  * Expense Filter
5
5
  *
6
- * Filter UI for the expense list. Supports filterEnabled (radio),
7
- * filterCategory (combobox), and filterStatus (combobox).
6
+ * Staged filters: record state, category, status and date range. Applied by
7
+ * the drawer footer.
8
8
  */
9
+ import { EnhancedCombobox } from "@appcorp/shadcn/components/enhanced-combobox";
10
+ import { EnhancedInput } from "@appcorp/shadcn/components/enhanced-input";
9
11
  import { EnhancedRadio } from "@appcorp/shadcn/components/enhanced-radio";
10
- import { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox";
11
12
  import { useExpenseModule } from "./context";
12
13
  import { EXPENSE_CATEGORY_OPTIONS, EXPENSE_STATUS_OPTIONS } from "./constants";
13
- import { EXPENSE_API_ROUTES } from "../../constants";
14
14
  import { useTranslations } from "next-intl";
15
15
  export const ExpenseFilter = () => {
16
16
  const { state, handleChange } = useExpenseModule();
17
- const { filterCategory, filterEnabled, filterStatus } = state;
17
+ const { filterCategory, filterEnabled, filterFromDate, filterStatus, filterToDate, } = state;
18
18
  const t = useTranslations("expense");
19
19
  const categoryLabelMap = {
20
20
  SALARY: t("formOptionSalary"),
@@ -44,56 +44,24 @@ export const ExpenseFilter = () => {
44
44
  : filterEnabled
45
45
  ? "true"
46
46
  : "false";
47
- const { enhancedComboboxElement: filterCategoryCombo } = useEnhancedCombobox({
48
- emptyText: t("filterNoCategoryFoundLabel"),
49
- id: "filterCategory",
50
- info: t("filterByCategory"),
51
- label: t("filterCategoryLabel"),
52
- onValueChange: (value) => handleChange("filterCategory", value),
53
- options: EXPENSE_CATEGORY_OPTIONS.map((opt) => ({
54
- value: opt.value,
55
- label: categoryLabelMap[opt.value] || opt.label,
56
- })),
57
- placeholder: t("filterAllCategoriesLabel"),
58
- searchEndpoint: EXPENSE_API_ROUTES.UNIT,
59
- searchPlaceholder: t("filterSearchCategoriesLabel"),
60
- formatSearchResult: (item) => {
61
- var _a, _b;
62
- return ({
63
- label: String((_a = item.label) !== null && _a !== void 0 ? _a : ""),
64
- value: String((_b = item.value) !== null && _b !== void 0 ? _b : ""),
65
- });
66
- },
67
- value: filterCategory || "",
68
- });
69
- const { enhancedComboboxElement: filterStatusCombo } = useEnhancedCombobox({
70
- emptyText: t("filterNoStatusFoundLabel"),
71
- id: "filterStatus",
72
- info: t("filterByStatus"),
73
- label: t("filterStatusLabel"),
74
- onValueChange: (value) => handleChange("filterStatus", value),
75
- options: EXPENSE_STATUS_OPTIONS.map((opt) => ({
76
- value: opt.value,
77
- label: statusLabelMap[opt.value] || opt.label,
78
- })),
79
- placeholder: t("filterAllStatusesLabel"),
80
- searchEndpoint: EXPENSE_API_ROUTES.UNIT,
81
- searchPlaceholder: t("filterSearchStatusLabel"),
82
- formatSearchResult: (item) => {
83
- var _a, _b;
84
- return ({
85
- label: String((_a = item.label) !== null && _a !== void 0 ? _a : ""),
86
- value: String((_b = item.value) !== null && _b !== void 0 ? _b : ""),
87
- });
88
- },
89
- value: filterStatus || "",
90
- });
91
- return (_jsx("div", { className: "space-y-4", children: _jsxs("div", { className: "grid grid-cols-1 gap-4", children: [filterCategoryCombo, filterStatusCombo, _jsx(EnhancedRadio, { label: t("filterOptionEnabled"), name: "filterEnabled", value: filterEnabledValue, options: [
92
- { label: t("filterOptionAll"), value: "undefined" },
93
- { label: t("filterOptionEnabled"), value: "true" },
94
- { label: t("filterOptionDisabled"), value: "false" },
95
- ], onValueChange: (next) => {
96
- const parsed = next === "true" ? true : next === "false" ? false : undefined;
97
- handleChange("filterEnabled", parsed);
98
- } })] }) }));
47
+ return (_jsxs("div", { className: "space-y-4", children: [_jsx(EnhancedCombobox, { emptyText: t("filterAllCategoriesLabel"), id: "filterCategory", info: t("filterByCategory"), label: t("filterCategoryLabel"), onValueChange: (value) => handleChange("filterCategory", value || undefined), options: [
48
+ { value: "", label: t("filterAllCategoriesLabel") },
49
+ ...EXPENSE_CATEGORY_OPTIONS.map((opt) => ({
50
+ value: opt.value,
51
+ label: categoryLabelMap[opt.value] || opt.label,
52
+ })),
53
+ ], placeholder: t("filterAllCategoriesLabel"), searchPlaceholder: t("filterAllCategoriesLabel"), value: filterCategory || "" }), _jsx(EnhancedCombobox, { emptyText: t("filterAllStatusesLabel"), id: "filterStatus", info: t("filterByStatus"), label: t("filterStatusLabel"), onValueChange: (value) => handleChange("filterStatus", value || undefined), options: [
54
+ { value: "", label: t("filterAllStatusesLabel") },
55
+ ...EXPENSE_STATUS_OPTIONS.map((opt) => ({
56
+ value: opt.value,
57
+ label: statusLabelMap[opt.value] || opt.label,
58
+ })),
59
+ ], placeholder: t("filterAllStatusesLabel"), searchPlaceholder: t("filterAllStatusesLabel"), value: filterStatus || "" }), _jsxs("div", { className: "grid grid-cols-1 gap-4 sm:grid-cols-2", children: [_jsx(EnhancedInput, { id: "filterFromDate", info: t("filterFromDateInfo"), label: t("filterFromDateLabel"), max: filterToDate || undefined, onChange: (e) => handleChange("filterFromDate", 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: filterFromDate || "" }), _jsx(EnhancedInput, { id: "filterToDate", info: t("filterToDateInfo"), label: t("filterToDateLabel"), min: filterFromDate || undefined, onChange: (e) => handleChange("filterToDate", 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: filterToDate || "" })] }), _jsx(EnhancedRadio, { label: t("filterRecordStateLabel"), name: "filterEnabled", value: filterEnabledValue, options: [
60
+ { label: t("filterOptionAll"), value: "undefined" },
61
+ { label: t("filterOptionEnabled"), value: "true" },
62
+ { label: t("filterOptionDisabled"), value: "false" },
63
+ ], onValueChange: (next) => {
64
+ const parsed = next === "true" ? true : next === "false" ? false : undefined;
65
+ handleChange("filterEnabled", parsed);
66
+ } })] }));
99
67
  };
@@ -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 { useEnhancedCombobox } from "@appcorp/shadcn/hooks/use-enhanced-combobox";
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 { enhancedComboboxElement: categoryCombo } = useEnhancedCombobox({
58
- emptyText: t("formNoCategoryEmpty"),
59
- id: "category",
60
- info: t("formCategoryInfo"),
61
- label: t("formCategoryLabel"),
62
- onValueChange: (value) => handleChange("category", value),
63
- options: EXPENSE_CATEGORY_OPTIONS.map((opt) => ({
64
- value: opt.value,
65
- label: categoryLabelMap[opt.value] || opt.label,
66
- })),
67
- placeholder: t("formCategoryPlaceholder"),
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.enabled ? t(errors.enabled) : undefined, id: "enabled", info: t("formEnabledInfo"), label: t("badgeActive"), onCheckedChange: (checked) => handleChange("enabled", !!checked) })] }));
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: components.moreActions,
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>;