@appcorp/stellar-solutions-invoice-module 0.1.57 → 0.1.60

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 (34) hide show
  1. package/base-modules/invoice/actions.d.ts +6 -6
  2. package/base-modules/invoice/context.js +21 -4
  3. package/base-modules/invoice/pricing-form-section.js +51 -28
  4. package/base-modules/invoice/types.d.ts +1 -0
  5. package/base-modules/payment/actions.d.ts +196 -0
  6. package/base-modules/payment/actions.js +49 -0
  7. package/base-modules/payment/constants.d.ts +101 -0
  8. package/base-modules/payment/constants.js +165 -0
  9. package/base-modules/payment/context.d.ts +56 -0
  10. package/base-modules/payment/context.js +421 -0
  11. package/base-modules/payment/drawer.d.ts +6 -0
  12. package/base-modules/payment/drawer.js +39 -0
  13. package/base-modules/payment/form.d.ts +18 -0
  14. package/base-modules/payment/form.js +90 -0
  15. package/base-modules/payment/index.d.ts +0 -0
  16. package/base-modules/payment/index.js +13 -0
  17. package/base-modules/payment/payment.d.ts +8 -0
  18. package/base-modules/payment/payment.js +39 -0
  19. package/base-modules/payment/reducer.d.ts +29 -0
  20. package/base-modules/payment/reducer.js +211 -0
  21. package/base-modules/payment/types.d.ts +82 -0
  22. package/base-modules/payment/types.js +19 -0
  23. package/base-modules/payment/validate.d.ts +20 -0
  24. package/base-modules/payment/validate.js +23 -0
  25. package/base-modules/quote/actions.d.ts +1 -1
  26. package/base-modules/quote/constants.js +1 -1
  27. package/base-modules/quote/context.js +27 -2
  28. package/base-modules/quote/pricing-form-section.js +51 -28
  29. package/base-modules/quote/types.d.ts +1 -0
  30. package/i18n/navigation.d.ts +342 -0
  31. package/i18n/navigation.js +9 -0
  32. package/i18n/routing.d.ts +18 -0
  33. package/i18n/routing.js +9 -0
  34. package/package.json +5 -5
@@ -0,0 +1,165 @@
1
+ /**
2
+ * Payment Module Constants
3
+ *
4
+ * Organization:
5
+ * - Page Configuration
6
+ * - Default Values
7
+ * - Validation Error Keys
8
+ * - API Routes
9
+ * - Table Configuration
10
+ * - Form Configuration
11
+ * - Network Messages
12
+ * - Validation Messages
13
+ * - UI Messages
14
+ */
15
+ "use client";
16
+ "use strict";
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.uiMessages = exports.validationError = exports.formInfo = exports.tableBodyCols = exports.PAYMENT_API_ROUTES = exports.VALIDATION_KEYS = exports.pageLimit = void 0;
19
+ var enhanced_table_1 = require("@appcorp/shadcn/components/enhanced-table");
20
+ var util_functions_1 = require("@react-pakistan/util-functions");
21
+ // ============================================================================
22
+ // PAGE CONFIGURATION
23
+ // ============================================================================
24
+ /**
25
+ * Default page limit for pagination
26
+ */
27
+ exports.pageLimit = Number(process.env.NEXT_PUBLIC_PAGE_LIMIT);
28
+ // ============================================================================
29
+ // VALIDATION ERROR KEYS
30
+ // ============================================================================
31
+ /**
32
+ * Validation error keys for i18n translation
33
+ */
34
+ exports.VALIDATION_KEYS = {
35
+ amount: "validationAmountRequired",
36
+ attachment: "validationAttachmentInvalid",
37
+ balance: "validationBalanceInvalid",
38
+ currency: "validationCurrencyRequired",
39
+ date: "validationDateRequired",
40
+ description: "validationDescriptionInvalid",
41
+ paymentMode: "validationPaymentModeRequired",
42
+ paymentType: "validationPaymentTypeRequired",
43
+ quoteInvoice: "validationQuoteInvoiceRequired",
44
+ ref: "validationRefInvalid",
45
+ };
46
+ // ============================================================================
47
+ // API ROUTES
48
+ // ============================================================================
49
+ /**
50
+ * API routes for payment-related operations
51
+ */
52
+ exports.PAYMENT_API_ROUTES = {
53
+ PAYMENT: "/api/payment",
54
+ PAYMENT_BY_ID: "/api/payment/payment-by-id",
55
+ PAYMENT_MODES: "/api/payment-modes",
56
+ PAYMENTS: "/api/payments",
57
+ QUOTE_INVOICES: "/api/quotes-invoices",
58
+ };
59
+ // ============================================================================
60
+ // TABLE CONFIGURATION
61
+ // ============================================================================
62
+ /**
63
+ * Table body column configuration for payment listing
64
+ */
65
+ exports.tableBodyCols = [
66
+ {
67
+ componentType: enhanced_table_1.COMPONENT_TYPE.ID,
68
+ key: "id",
69
+ },
70
+ {
71
+ componentType: enhanced_table_1.COMPONENT_TYPE.OBJECT,
72
+ key: ["quoteInvoice:ref"],
73
+ },
74
+ {
75
+ componentType: enhanced_table_1.COMPONENT_TYPE.TEXT,
76
+ key: "date",
77
+ textFormatter: function (text) {
78
+ return (0, util_functions_1.formatDate)(text, util_functions_1.DATE_FORMATS.LOCALE_DATE);
79
+ },
80
+ },
81
+ {
82
+ componentType: enhanced_table_1.COMPONENT_TYPE.TEXT,
83
+ key: "amount",
84
+ },
85
+ {
86
+ componentType: enhanced_table_1.COMPONENT_TYPE.TEXT,
87
+ key: "balance",
88
+ },
89
+ {
90
+ componentType: enhanced_table_1.COMPONENT_TYPE.TEXT,
91
+ key: "currency",
92
+ },
93
+ {
94
+ componentType: enhanced_table_1.COMPONENT_TYPE.TEXT,
95
+ key: "paymentType",
96
+ },
97
+ {
98
+ componentType: enhanced_table_1.COMPONENT_TYPE.OBJECT,
99
+ key: ["paymentMode:label"],
100
+ },
101
+ {
102
+ componentType: enhanced_table_1.COMPONENT_TYPE.TEXT,
103
+ key: "ref",
104
+ },
105
+ {
106
+ componentType: enhanced_table_1.COMPONENT_TYPE.ACTIONS,
107
+ key: "action",
108
+ },
109
+ ];
110
+ // ============================================================================
111
+ // FORM CONFIGURATION
112
+ // ============================================================================
113
+ /**
114
+ * Information tooltips for form fields
115
+ */
116
+ exports.formInfo = {
117
+ amount: "Enter the payment amount",
118
+ attachment: "Upload payment receipt or proof",
119
+ balance: "Remaining balance after this payment",
120
+ currency: "Select the currency for the payment",
121
+ date: "Date when payment was made",
122
+ description: "Additional notes about this payment",
123
+ paymentMode: "Select the payment method used",
124
+ paymentType: "Choose full or partial payment",
125
+ quoteInvoice: "Select the invoice this payment is for",
126
+ ref: "Payment reference number",
127
+ };
128
+ // ============================================================================
129
+ // VALIDATION MESSAGES
130
+ // ============================================================================
131
+ exports.validationError = {
132
+ // Required Fields
133
+ amount: "validationAmountRequired",
134
+ currency: "validationCurrencyRequired",
135
+ date: "validationDateRequired",
136
+ paymentModeId: "validationPaymentModeRequired",
137
+ paymentType: "validationPaymentTypeRequired",
138
+ quoteInvoiceId: "validationQuoteInvoiceRequired",
139
+ // Format Validation
140
+ attachmentInvalid: "validationAttachmentInvalid",
141
+ balanceInvalid: "validationBalanceInvalid",
142
+ descriptionInvalid: "validationDescriptionInvalid",
143
+ refInvalid: "validationRefInvalid",
144
+ // General
145
+ general: "validationFormGeneralError",
146
+ requiredField: "validationFormGeneralError",
147
+ };
148
+ // ============================================================================
149
+ // UI MESSAGES
150
+ // ============================================================================
151
+ exports.uiMessages = {
152
+ // Form Actions
153
+ cancel: "drawerButtonCancel",
154
+ delete: "actionsButtonDelete",
155
+ edit: "actionsButtonEdit",
156
+ save: "drawerButtonSave",
157
+ // Search & Filters
158
+ clearFilters: "drawerButtonClearFilter",
159
+ filterByPaymentMode: "drawerFilterLabelPaymentMode",
160
+ searchPlaceholder: "tableSearchPlaceholder",
161
+ // Table Actions
162
+ addPayment: "actionsButtonAddItem",
163
+ loadingPayments: "tableDescription",
164
+ noPaymentsFound: "tableDescription",
165
+ };
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Payment State Context
3
+ *
4
+ * This module provides comprehensive state management for the Payment feature including:
5
+ * - CRUD operations (create, read, update, delete)
6
+ * - Form validation and error handling
7
+ * - Search and filtering functionality
8
+ * - Pagination controls
9
+ * - Payment mode and quote invoice integration
10
+ * - Currency management with default selection
11
+ * - Internationalization support
12
+ * - Theme-aware toast notifications
13
+ *
14
+ * Organization:
15
+ * - Types & Interfaces
16
+ * - Main Hook (usePaymentState)
17
+ * - State & Core Hooks
18
+ * - Debounced Values
19
+ * - API Parameters (memoized)
20
+ * - API Callbacks (with error handling)
21
+ * - Module Entity Hook
22
+ * - Effects (list refresh, currency defaults)
23
+ * - Drawer & Modal Handlers
24
+ * - CRUD Operation Handlers
25
+ * - Form Handlers
26
+ * - Pagination Handlers
27
+ * - Search Handlers
28
+ * - Table Actions (memoized)
29
+ * - Return State
30
+ * - Context Setup
31
+ * - Provider Component
32
+ * - Custom Hook
33
+ */
34
+ import React, { FC, ReactNode } from "react";
35
+ import { PaymentContextType, PaymentState } from "./types";
36
+ type State = PaymentContextType & PaymentState & {
37
+ headerActions: Array<{
38
+ enabled: boolean;
39
+ handleOnClick: () => void;
40
+ label: string;
41
+ order: number;
42
+ }>;
43
+ rowActions: Array<{
44
+ enabled: boolean;
45
+ handleAction: (id: string) => void;
46
+ label: string;
47
+ order: number;
48
+ }>;
49
+ };
50
+ interface StateProviderProps {
51
+ children: ReactNode;
52
+ }
53
+ export declare const PaymentStateContext: React.Context<State>;
54
+ export declare const PaymentStateContextProvider: FC<StateProviderProps>;
55
+ export declare const usePaymentStateContext: () => State;
56
+ export {};
@@ -0,0 +1,421 @@
1
+ /**
2
+ * Payment State Context
3
+ *
4
+ * This module provides comprehensive state management for the Payment feature including:
5
+ * - CRUD operations (create, read, update, delete)
6
+ * - Form validation and error handling
7
+ * - Search and filtering functionality
8
+ * - Pagination controls
9
+ * - Payment mode and quote invoice integration
10
+ * - Currency management with default selection
11
+ * - Internationalization support
12
+ * - Theme-aware toast notifications
13
+ *
14
+ * Organization:
15
+ * - Types & Interfaces
16
+ * - Main Hook (usePaymentState)
17
+ * - State & Core Hooks
18
+ * - Debounced Values
19
+ * - API Parameters (memoized)
20
+ * - API Callbacks (with error handling)
21
+ * - Module Entity Hook
22
+ * - Effects (list refresh, currency defaults)
23
+ * - Drawer & Modal Handlers
24
+ * - CRUD Operation Handlers
25
+ * - Form Handlers
26
+ * - Pagination Handlers
27
+ * - Search Handlers
28
+ * - Table Actions (memoized)
29
+ * - Return State
30
+ * - Context Setup
31
+ * - Provider Component
32
+ * - Custom Hook
33
+ */
34
+ "use client";
35
+ "use strict";
36
+ var __assign = (this && this.__assign) || function () {
37
+ __assign = Object.assign || function(t) {
38
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
39
+ s = arguments[i];
40
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
41
+ t[p] = s[p];
42
+ }
43
+ return t;
44
+ };
45
+ return __assign.apply(this, arguments);
46
+ };
47
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
48
+ if (k2 === undefined) k2 = k;
49
+ var desc = Object.getOwnPropertyDescriptor(m, k);
50
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
51
+ desc = { enumerable: true, get: function() { return m[k]; } };
52
+ }
53
+ Object.defineProperty(o, k2, desc);
54
+ }) : (function(o, m, k, k2) {
55
+ if (k2 === undefined) k2 = k;
56
+ o[k2] = m[k];
57
+ }));
58
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
59
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
60
+ }) : function(o, v) {
61
+ o["default"] = v;
62
+ });
63
+ var __importStar = (this && this.__importStar) || (function () {
64
+ var ownKeys = function(o) {
65
+ ownKeys = Object.getOwnPropertyNames || function (o) {
66
+ var ar = [];
67
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
68
+ return ar;
69
+ };
70
+ return ownKeys(o);
71
+ };
72
+ return function (mod) {
73
+ if (mod && mod.__esModule) return mod;
74
+ var result = {};
75
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
76
+ __setModuleDefault(result, mod);
77
+ return result;
78
+ };
79
+ })();
80
+ Object.defineProperty(exports, "__esModule", { value: true });
81
+ exports.usePaymentStateContext = exports.PaymentStateContextProvider = exports.PaymentStateContext = void 0;
82
+ var react_1 = __importStar(require("react"));
83
+ var next_themes_1 = require("next-themes");
84
+ var next_intl_1 = require("next-intl");
85
+ var util_functions_1 = require("@react-pakistan/util-functions");
86
+ var actions_1 = require("./actions");
87
+ var constants_1 = require("./constants");
88
+ var reducer_1 = require("./reducer");
89
+ var toast_utils_1 = require("@appcorp/shadcn/lib/toast-utils");
90
+ var types_1 = require("./types");
91
+ var validate_1 = require("./validate");
92
+ var context_1 = require("@appcorp/stellar-solutions-modules/global-modules/preferences/context");
93
+ // ============================================================================
94
+ // MAIN HOOK
95
+ // ============================================================================
96
+ var usePaymentState = function () {
97
+ // ---------------------------------------------------------------------------
98
+ // STATE & CORE HOOKS
99
+ // ---------------------------------------------------------------------------
100
+ var _a = (0, react_1.useReducer)(reducer_1.paymentReducer, reducer_1.initialPaymentState), state = _a[0], dispatch = _a[1];
101
+ var currencies = (0, context_1.usePreferenceStateContext)().currencies;
102
+ var theme = (0, next_themes_1.useTheme)().theme;
103
+ var t = (0, next_intl_1.useTranslations)("payment");
104
+ // const tCommon = useTranslations("common");
105
+ // ---------------------------------------------------------------------------
106
+ // DEBOUNCED VALUES
107
+ // ---------------------------------------------------------------------------
108
+ var debouncedQuery = (0, util_functions_1.useDebounce)(state.searchQuery, 800);
109
+ // ---------------------------------------------------------------------------
110
+ // API PARAMETERS
111
+ // ---------------------------------------------------------------------------
112
+ var listParams = (0, react_1.useMemo)(function () { return ({
113
+ currentPage: state.currentPage,
114
+ pageLimit: state.pageLimit,
115
+ searchQuery: state.searchQuery,
116
+ }); }, [state.currentPage, state.pageLimit, state.searchQuery]);
117
+ var updateParams = (0, react_1.useMemo)(function () {
118
+ var _a, _b;
119
+ return ({
120
+ amount: state.amount,
121
+ attachment: state.attachment,
122
+ balance: state.balance,
123
+ currency: state.currency,
124
+ date: state.date,
125
+ description: ((_a = state.description) === null || _a === void 0 ? void 0 : _a.trim()) || "",
126
+ id: state.id,
127
+ paymentModeId: state.paymentModeId,
128
+ paymentType: state.paymentType,
129
+ quoteInvoiceId: state.quoteInvoiceId,
130
+ ref: ((_b = state === null || state === void 0 ? void 0 : state.ref) === null || _b === void 0 ? void 0 : _b.trim()) || "",
131
+ });
132
+ }, [state]);
133
+ var byIdParams = (0, react_1.useMemo)(function () { return ({ id: state.id }); }, [state.id]);
134
+ var deleteParams = (0, react_1.useMemo)(function () { return ({ id: state.id }); }, [state.id]);
135
+ // ---------------------------------------------------------------------------
136
+ // API CALLBACKS
137
+ // ---------------------------------------------------------------------------
138
+ var showErrorToast = (0, react_1.useCallback)(function (description) {
139
+ (0, toast_utils_1.generateThemeToast)({
140
+ description: description,
141
+ theme: theme,
142
+ variant: toast_utils_1.TOAST_VARIANT.ERROR,
143
+ });
144
+ }, [theme]);
145
+ var showSuccessToast = (0, react_1.useCallback)(function (description) {
146
+ (0, toast_utils_1.generateThemeToast)({
147
+ description: description,
148
+ theme: theme,
149
+ variant: toast_utils_1.TOAST_VARIANT.SUCCESS,
150
+ });
151
+ }, [theme]);
152
+ var listCallback = (0, react_1.useCallback)(function (_a) {
153
+ var data = _a.data, error = _a.error;
154
+ console.log("Payment List Callback Data:", data);
155
+ if (error) {
156
+ showErrorToast(t("messagesNetworkError"));
157
+ }
158
+ if (data === null || data === void 0 ? void 0 : data.items) {
159
+ dispatch({
160
+ payload: { payments: data.items },
161
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_PAYMENTS,
162
+ });
163
+ dispatch({
164
+ payload: { count: data === null || data === void 0 ? void 0 : data.count },
165
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_COUNT,
166
+ });
167
+ }
168
+ }, [dispatch, showErrorToast, t]);
169
+ var updateCallback = (0, react_1.useCallback)(function (_a) {
170
+ var data = _a.data, error = _a.error;
171
+ if (error) {
172
+ showErrorToast(t("messagesNetworkError"));
173
+ }
174
+ if (data) {
175
+ showSuccessToast(t("messagesPaymentUpdated"));
176
+ dispatch({
177
+ type: actions_1.PAYMENT_ACTION_TYPES.RESET_FORM,
178
+ });
179
+ dispatch({
180
+ type: actions_1.PAYMENT_ACTION_TYPES.RESET_ERRORS,
181
+ });
182
+ listFetchNow();
183
+ dispatch({
184
+ payload: { drawer: null },
185
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_DRAWER,
186
+ });
187
+ }
188
+ },
189
+ // eslint-disable-next-line react-hooks/exhaustive-deps
190
+ [dispatch, showErrorToast, showSuccessToast, t]);
191
+ var byIdCallback = (0, react_1.useCallback)(function (_a) {
192
+ var data = _a.data, error = _a.error;
193
+ if (error) {
194
+ showErrorToast(t("messagesNetworkError"));
195
+ }
196
+ if (data) {
197
+ var updatedData = __assign({}, data);
198
+ dispatch({
199
+ payload: { form: updatedData },
200
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_FORM,
201
+ });
202
+ dispatch({
203
+ payload: { drawer: types_1.PAYMENT_DRAWER.PAYMENT_FORM_DRAWER },
204
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_DRAWER,
205
+ });
206
+ }
207
+ }, [dispatch, showErrorToast, t]);
208
+ var deleteCallback = (0, react_1.useCallback)(function (_a) {
209
+ var data = _a.data, error = _a.error;
210
+ if (error) {
211
+ showErrorToast(t("messagesNetworkError"));
212
+ }
213
+ if (data) {
214
+ showSuccessToast(t("messagesPaymentDeleted"));
215
+ dispatch({
216
+ type: actions_1.PAYMENT_ACTION_TYPES.RESET_FORM,
217
+ });
218
+ listFetchNow();
219
+ }
220
+ },
221
+ // eslint-disable-next-line react-hooks/exhaustive-deps
222
+ [dispatch, showErrorToast, showSuccessToast, t]);
223
+ // ---------------------------------------------------------------------------
224
+ // MODULE ENTITY HOOK
225
+ // ---------------------------------------------------------------------------
226
+ var _b = (0, util_functions_1.useModuleEntity)({
227
+ byIdCallback: byIdCallback,
228
+ byIdParams: byIdParams,
229
+ deleteCallback: deleteCallback,
230
+ deleteParams: deleteParams,
231
+ listCallback: listCallback,
232
+ listDeps: [dispatch],
233
+ listParams: listParams,
234
+ listUrl: constants_1.PAYMENT_API_ROUTES.PAYMENTS,
235
+ searchQuery: debouncedQuery,
236
+ unitByIdUrl: constants_1.PAYMENT_API_ROUTES.PAYMENT_BY_ID,
237
+ unitUrl: constants_1.PAYMENT_API_ROUTES.PAYMENT,
238
+ updateCallback: updateCallback,
239
+ updateDeps: [state],
240
+ updateParams: updateParams,
241
+ }), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError, deleteFetchNow = _b.deleteFetchNow, deleteLoading = _b.deleteLoading, listError = _b.listError, listFetchNow = _b.listFetchNow, listLoading = _b.listLoading, updateError = _b.updateError, updateFetchNow = _b.updateFetchNow, updateLoading = _b.updateLoading;
242
+ // ---------------------------------------------------------------------------
243
+ // EFFECTS
244
+ // ---------------------------------------------------------------------------
245
+ (0, react_1.useEffect)(function () {
246
+ listFetchNow();
247
+ // eslint-disable-next-line
248
+ }, [debouncedQuery, state.currentPage, state.pageLimit]);
249
+ // ---------------------------------------------------------------------------
250
+ // DRAWER & MODAL HANDLERS
251
+ // ---------------------------------------------------------------------------
252
+ var handleCreate = (0, react_1.useCallback)(function () {
253
+ var _a;
254
+ if (currencies.length > 0) {
255
+ var defaultCurrency = (_a = currencies.filter(function (_a) {
256
+ var isDefault = _a.isDefault;
257
+ return isDefault;
258
+ })) === null || _a === void 0 ? void 0 : _a[0];
259
+ dispatch({
260
+ payload: { key: "currency", value: defaultCurrency.code },
261
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
262
+ });
263
+ }
264
+ dispatch({
265
+ payload: { drawer: types_1.PAYMENT_DRAWER.PAYMENT_FORM_DRAWER },
266
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_DRAWER,
267
+ });
268
+ }, [currencies, dispatch]);
269
+ var closeDrawer = (0, react_1.useCallback)(function () {
270
+ dispatch({
271
+ payload: { drawer: null },
272
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_DRAWER,
273
+ });
274
+ dispatch({
275
+ type: actions_1.PAYMENT_ACTION_TYPES.RESET_FORM,
276
+ });
277
+ dispatch({
278
+ type: actions_1.PAYMENT_ACTION_TYPES.RESET_ERRORS,
279
+ });
280
+ }, [dispatch]);
281
+ // ---------------------------------------------------------------------------
282
+ // CRUD OPERATION HANDLERS
283
+ // ---------------------------------------------------------------------------
284
+ var handleEdit = (0, react_1.useCallback)(function (id) {
285
+ byIdFetchNow(undefined, {
286
+ body: JSON.stringify({ id: id }),
287
+ });
288
+ }, [byIdFetchNow]);
289
+ var handleDelete = (0, react_1.useCallback)(function (id) {
290
+ deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
291
+ body: JSON.stringify({ id: id }),
292
+ });
293
+ }, [deleteFetchNow]);
294
+ var handleSubmit = (0, react_1.useCallback)(function () {
295
+ dispatch({
296
+ payload: { disableSaveButton: true },
297
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
298
+ });
299
+ (0, util_functions_1.validateForm)({
300
+ errorCallback: function (e) {
301
+ dispatch({
302
+ payload: { errors: e },
303
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_ERRORS,
304
+ });
305
+ },
306
+ params: updateParams,
307
+ schema: validate_1.formValidation,
308
+ successCallback: function () {
309
+ updateFetchNow(undefined, {
310
+ body: JSON.stringify(__assign({}, updateParams)),
311
+ });
312
+ },
313
+ });
314
+ }, [updateFetchNow, updateParams, dispatch]);
315
+ // ---------------------------------------------------------------------------
316
+ // FORM HANDLERS
317
+ // ---------------------------------------------------------------------------
318
+ var handleChange = (0, react_1.useCallback)(function (key, value) {
319
+ dispatch({
320
+ payload: { key: key, value: String(value) },
321
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
322
+ });
323
+ dispatch({
324
+ payload: { disableSaveButton: false },
325
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
326
+ });
327
+ dispatch({
328
+ type: actions_1.PAYMENT_ACTION_TYPES.RESET_ERRORS,
329
+ });
330
+ }, [dispatch]);
331
+ // ---------------------------------------------------------------------------
332
+ // PAGINATION HANDLERS
333
+ // ---------------------------------------------------------------------------
334
+ var handleNextClick = (0, react_1.useCallback)(function () {
335
+ dispatch({
336
+ payload: { currentPage: state.currentPage + 1 },
337
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_CURRENT_PAGE,
338
+ });
339
+ }, [state.currentPage, dispatch]);
340
+ var handlePreviousClick = (0, react_1.useCallback)(function () {
341
+ dispatch({
342
+ payload: { currentPage: state.currentPage - 1 },
343
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_CURRENT_PAGE,
344
+ });
345
+ }, [state.currentPage, dispatch]);
346
+ var handlePageLimit = (0, react_1.useCallback)(function (node, value) {
347
+ var val = __assign({}, value);
348
+ dispatch({
349
+ payload: { pageLimit: Number(val.option) },
350
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_PAGE_LIMIT,
351
+ });
352
+ }, [dispatch]);
353
+ // ---------------------------------------------------------------------------
354
+ // SEARCH HANDLERS
355
+ // ---------------------------------------------------------------------------
356
+ var searchOnChange = (0, react_1.useCallback)(function (k, v) {
357
+ dispatch({
358
+ payload: { searchQuery: v },
359
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_SEARCH_QUERY,
360
+ });
361
+ }, [dispatch]);
362
+ var clearSearch = (0, react_1.useCallback)(function () {
363
+ dispatch({
364
+ payload: { searchQuery: "" },
365
+ type: actions_1.PAYMENT_ACTION_TYPES.SET_SEARCH_QUERY,
366
+ });
367
+ }, [dispatch]);
368
+ // ---------------------------------------------------------------------------
369
+ // TABLE ACTIONS
370
+ // ---------------------------------------------------------------------------
371
+ var headerActions = (0, react_1.useMemo)(function () { return [
372
+ {
373
+ enabled: false,
374
+ handleOnClick: handleCreate,
375
+ label: t("actionsButtonAddItem"),
376
+ order: 1,
377
+ },
378
+ ]; }, [handleCreate, t]);
379
+ var rowActions = (0, react_1.useMemo)(function () { return [
380
+ {
381
+ enabled: true,
382
+ handleAction: function (id) { return handleEdit(id); },
383
+ label: t("actionsButtonEdit"),
384
+ order: 1,
385
+ },
386
+ {
387
+ enabled: true,
388
+ handleAction: function (id) { return handleDelete(id); },
389
+ label: t("actionsButtonDelete"),
390
+ order: 2,
391
+ },
392
+ ]; }, [handleEdit, handleDelete, t]);
393
+ // ---------------------------------------------------------------------------
394
+ // RETURN STATE
395
+ // ---------------------------------------------------------------------------
396
+ return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, handleChange: handleChange, handleNextClick: handleNextClick, handlePageLimit: handlePageLimit, handlePreviousClick: handlePreviousClick, handleSubmit: handleSubmit, headerActions: headerActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, rowActions: rowActions, searchOnChange: searchOnChange, updateError: updateError, updateLoading: updateLoading });
397
+ };
398
+ // ============================================================================
399
+ // CONTEXT SETUP
400
+ // ============================================================================
401
+ exports.PaymentStateContext = (0, react_1.createContext)(__assign(__assign({}, reducer_1.initialPaymentState), { byIdError: undefined, byIdLoading: false, clearSearch: function () { return void 0; }, closeDrawer: function () { return void 0; }, deleteError: undefined, deleteLoading: false, dispatch: function () { return void 0; }, handleChange: function () { return void 0; }, handleNextClick: function () { return void 0; }, handlePageLimit: function () { return void 0; }, handlePreviousClick: function () { return void 0; }, handleSubmit: function () { return void 0; }, headerActions: [], listError: undefined, listFetchNow: function () { return void 0; }, listLoading: false, rowActions: [], searchOnChange: function () { return void 0; }, updateError: undefined, updateLoading: false }));
402
+ // ============================================================================
403
+ // PROVIDER COMPONENT
404
+ // ============================================================================
405
+ var PaymentStateContextProvider = function (_a) {
406
+ var children = _a.children;
407
+ var state = usePaymentState();
408
+ return (react_1.default.createElement(exports.PaymentStateContext.Provider, { value: state }, children));
409
+ };
410
+ exports.PaymentStateContextProvider = PaymentStateContextProvider;
411
+ // ============================================================================
412
+ // CUSTOM HOOK
413
+ // ============================================================================
414
+ var usePaymentStateContext = function () {
415
+ var state = (0, react_1.useContext)(exports.PaymentStateContext);
416
+ if (state === undefined) {
417
+ throw new Error("usePaymentStateContext must be used within a PaymentContextProvider");
418
+ }
419
+ return state;
420
+ };
421
+ exports.usePaymentStateContext = usePaymentStateContext;
@@ -0,0 +1,6 @@
1
+ import { FC } from "react";
2
+ interface Props {
3
+ isRTL: boolean;
4
+ }
5
+ export declare const Drawer: FC<Props>;
6
+ export {};