@appcorp/stellar-solutions-invoice-module 0.1.73 → 0.1.75
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/invoice/add-service-product-section.d.ts +1 -5
- package/base-modules/invoice/add-service-product-section.js +3 -3
- package/base-modules/invoice/cache.d.ts +15 -0
- package/base-modules/invoice/cache.js +50 -0
- package/base-modules/invoice/calculate-subtotal.d.ts +6 -1
- package/base-modules/invoice/calculate-subtotal.js +2 -2
- package/base-modules/invoice/calculate-total.d.ts +1 -1
- package/base-modules/invoice/calculate-total.js +8 -8
- package/base-modules/invoice/company-form-section.d.ts +1 -5
- package/base-modules/invoice/company-form-section.js +25 -22
- package/base-modules/invoice/constants.d.ts +2 -3
- package/base-modules/invoice/constants.js +2 -3
- package/base-modules/invoice/context.d.ts +556 -20
- package/base-modules/invoice/context.js +542 -340
- package/base-modules/invoice/customer-form-section.d.ts +1 -5
- package/base-modules/invoice/customer-form-section.js +25 -9
- package/base-modules/invoice/form.d.ts +1 -5
- package/base-modules/invoice/form.js +9 -9
- package/base-modules/invoice/page.d.ts +8 -0
- package/base-modules/invoice/page.js +171 -0
- package/base-modules/invoice/pricing-form-section.d.ts +1 -5
- package/base-modules/invoice/pricing-form-section.js +16 -11
- package/base-modules/invoice/products-form-section.d.ts +1 -5
- package/base-modules/invoice/products-form-section.js +49 -41
- package/base-modules/invoice/services-form-section.d.ts +1 -5
- package/base-modules/invoice/services-form-section.js +10 -9
- package/base-modules/invoice/validate.d.ts +83 -25
- package/base-modules/invoice/validate.js +4 -4
- package/base-modules/payment/cache.d.ts +15 -0
- package/base-modules/payment/cache.js +52 -0
- package/base-modules/payment/constants.d.ts +1 -14
- package/base-modules/payment/constants.js +2 -15
- package/base-modules/payment/context.d.ts +214 -48
- package/base-modules/payment/context.js +312 -240
- package/base-modules/payment/drawer.d.ts +0 -6
- package/base-modules/payment/drawer.js +89 -44
- package/base-modules/payment/form.js +3 -2
- package/base-modules/payment/{payment.js → page.js} +2 -5
- package/base-modules/payment/types.d.ts +0 -85
- package/base-modules/payment/types.js +74 -21
- package/base-modules/payment/validate.d.ts +12 -0
- package/base-modules/payment/validate.js +19 -8
- package/base-modules/payment/view.d.ts +1 -5
- package/base-modules/payment/view.js +4 -3
- package/base-modules/quote/add-service-product-section.js +1 -1
- package/base-modules/quote/cache.d.ts +15 -0
- package/base-modules/quote/cache.js +50 -0
- package/base-modules/quote/company-form-section.d.ts +1 -1
- package/base-modules/quote/company-form-section.js +14 -12
- package/base-modules/quote/constants.js +1 -0
- package/base-modules/quote/context.d.ts +656 -46
- package/base-modules/quote/context.js +431 -293
- package/base-modules/quote/customer-form-section.d.ts +1 -1
- package/base-modules/quote/customer-form-section.js +24 -9
- package/base-modules/quote/form.d.ts +1 -5
- package/base-modules/quote/form.js +8 -9
- package/base-modules/quote/page.d.ts +8 -0
- package/base-modules/quote/page.js +163 -0
- package/base-modules/quote/pricing-form-section.js +9 -8
- package/base-modules/quote/products-form-section.js +2 -3
- package/base-modules/quote/services-form-section.js +1 -1
- package/base-modules/quote/types.d.ts +0 -127
- package/base-modules/quote/types.js +92 -35
- package/base-modules/quote/validate.d.ts +82 -25
- package/base-modules/quote/validate.js +3 -4
- package/package.json +12 -11
- package/base-modules/invoice/actions.d.ts +0 -215
- package/base-modules/invoice/actions.js +0 -38
- package/base-modules/invoice/drawer.d.ts +0 -13
- package/base-modules/invoice/drawer.js +0 -46
- package/base-modules/invoice/invoice.d.ts +0 -8
- package/base-modules/invoice/invoice.js +0 -69
- package/base-modules/invoice/reducer.d.ts +0 -4
- package/base-modules/invoice/reducer.js +0 -180
- package/base-modules/invoice/types.d.ts +0 -211
- package/base-modules/invoice/types.js +0 -43
- package/base-modules/payment/actions.d.ts +0 -203
- package/base-modules/payment/actions.js +0 -50
- package/base-modules/payment/reducer.d.ts +0 -29
- package/base-modules/payment/reducer.js +0 -215
- package/base-modules/quote/actions.d.ts +0 -215
- package/base-modules/quote/actions.js +0 -38
- package/base-modules/quote/drawer.d.ts +0 -13
- package/base-modules/quote/drawer.js +0 -46
- package/base-modules/quote/quote.d.ts +0 -8
- package/base-modules/quote/quote.js +0 -69
- package/base-modules/quote/reducer.d.ts +0 -4
- package/base-modules/quote/reducer.js +0 -181
- /package/base-modules/payment/{payment.d.ts → page.d.ts} +0 -0
|
@@ -1,35 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Payment State Context
|
|
2
|
+
* Payment State Context - Using Generic Module Factory
|
|
3
3
|
*
|
|
4
|
-
* This module provides comprehensive state management for the Payment feature
|
|
5
|
-
*
|
|
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
|
|
4
|
+
* This module provides comprehensive state management for the Payment feature using
|
|
5
|
+
* the createGenericModule factory pattern.
|
|
33
6
|
*/
|
|
34
7
|
"use client";
|
|
35
8
|
"use strict";
|
|
@@ -44,86 +17,165 @@ var __assign = (this && this.__assign) || function () {
|
|
|
44
17
|
};
|
|
45
18
|
return __assign.apply(this, arguments);
|
|
46
19
|
};
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
20
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
21
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
22
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
23
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
24
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
25
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
26
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
30
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
31
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
32
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
33
|
+
function step(op) {
|
|
34
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
35
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
36
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
37
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
38
|
+
switch (op[0]) {
|
|
39
|
+
case 0: case 1: t = op; break;
|
|
40
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
41
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
42
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
43
|
+
default:
|
|
44
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
45
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
46
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
47
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
48
|
+
if (t[2]) _.ops.pop();
|
|
49
|
+
_.trys.pop(); continue;
|
|
50
|
+
}
|
|
51
|
+
op = body.call(thisArg, _);
|
|
52
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
53
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
})();
|
|
55
|
+
};
|
|
56
|
+
var _a;
|
|
80
57
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
81
|
-
exports.
|
|
82
|
-
var react_1 =
|
|
58
|
+
exports.usePaymentModule = exports.initialPaymentState = exports.PAYMENT_ACTION_TYPES = exports.paymentModuleConfig = exports.usePaymentCoreContext = exports.PaymentCoreProvider = exports.paymentReducer = void 0;
|
|
59
|
+
var react_1 = require("react");
|
|
83
60
|
var next_themes_1 = require("next-themes");
|
|
84
61
|
var next_intl_1 = require("next-intl");
|
|
85
62
|
var util_functions_1 = require("@react-pakistan/util-functions");
|
|
86
|
-
var
|
|
63
|
+
var generic_module_factory_1 = require("@react-pakistan/util-functions/factory/generic-module-factory");
|
|
64
|
+
var generic_component_factory_1 = require("@react-pakistan/util-functions/factory/generic-component-factory");
|
|
65
|
+
var context_1 = require("@appcorp/stellar-solutions-modules/global-modules/preferences/context");
|
|
87
66
|
var constants_1 = require("./constants");
|
|
88
|
-
var reducer_1 = require("./reducer");
|
|
89
67
|
var toast_utils_1 = require("@appcorp/shadcn/lib/toast-utils");
|
|
90
|
-
|
|
68
|
+
// import { PAYMENT_DRAWER, PAYMENT_TYPE, PaymentTypeBE } from "./types";
|
|
69
|
+
// import { PaymentModeTypeBE } from "@appcorp/stellar-solutions-modules/global-modules/payment-mode/types";
|
|
70
|
+
// import { QuoteInvoiceTypeBE } from "../invoice/types";
|
|
91
71
|
var validate_1 = require("./validate");
|
|
92
|
-
var
|
|
72
|
+
var cache_1 = require("./cache");
|
|
73
|
+
var context_2 = require("../invoice/context");
|
|
74
|
+
// ============================================================================
|
|
75
|
+
// MODULE CONFIGURATION
|
|
76
|
+
// ============================================================================
|
|
77
|
+
var paymentConfig = {
|
|
78
|
+
name: "Payment",
|
|
79
|
+
displayName: "Payment",
|
|
80
|
+
initialState: {
|
|
81
|
+
// List data
|
|
82
|
+
items: [],
|
|
83
|
+
count: 0,
|
|
84
|
+
// Search & Pagination
|
|
85
|
+
currentPage: 1,
|
|
86
|
+
pageLimit: constants_1.pageLimit,
|
|
87
|
+
searchQuery: "",
|
|
88
|
+
// UI state
|
|
89
|
+
disableSaveButton: true,
|
|
90
|
+
drawer: null,
|
|
91
|
+
modal: null,
|
|
92
|
+
// Errors
|
|
93
|
+
errors: {},
|
|
94
|
+
// Form data
|
|
95
|
+
amount: "",
|
|
96
|
+
attachment: "",
|
|
97
|
+
balance: "",
|
|
98
|
+
currency: "",
|
|
99
|
+
date: new Date().toISOString(),
|
|
100
|
+
description: "",
|
|
101
|
+
id: "",
|
|
102
|
+
mode: "Create",
|
|
103
|
+
paymentModeId: "",
|
|
104
|
+
paymentModeQuery: "",
|
|
105
|
+
paymentType: util_functions_1.PAYMENT_TYPE.FULL_AMOUNT,
|
|
106
|
+
quoteInvoiceId: "",
|
|
107
|
+
quoteInvoiceQuery: "",
|
|
108
|
+
ref: "",
|
|
109
|
+
invoice: null,
|
|
110
|
+
// Related entities
|
|
111
|
+
paymentModes: [],
|
|
112
|
+
quoteInvoices: [],
|
|
113
|
+
paymentMode: undefined,
|
|
114
|
+
quoteInvoice: undefined,
|
|
115
|
+
},
|
|
116
|
+
drawerTypes: __assign({}, generic_component_factory_1.DRAWER_TYPES),
|
|
117
|
+
};
|
|
93
118
|
// ============================================================================
|
|
94
|
-
//
|
|
119
|
+
// CREATE PAYMENT MODULE
|
|
95
120
|
// ============================================================================
|
|
96
|
-
|
|
121
|
+
exports.paymentReducer = (_a = (0, generic_module_factory_1.createGenericModule)(paymentConfig), _a.reducer), exports.PaymentCoreProvider = _a.Provider, exports.usePaymentCoreContext = _a.useContext, exports.paymentModuleConfig = _a.config, exports.PAYMENT_ACTION_TYPES = _a.actionTypes, exports.initialPaymentState = _a.initialState;
|
|
122
|
+
// ============================================================================
|
|
123
|
+
// ENHANCED PAYMENT HOOK WITH API INTEGRATION
|
|
124
|
+
// ============================================================================
|
|
125
|
+
// interface StateProviderProps {
|
|
126
|
+
// children: ReactNode;
|
|
127
|
+
// }
|
|
128
|
+
var usePaymentModule = function () {
|
|
129
|
+
var _a;
|
|
97
130
|
// ---------------------------------------------------------------------------
|
|
98
|
-
//
|
|
131
|
+
// State via factory context
|
|
99
132
|
// ---------------------------------------------------------------------------
|
|
100
|
-
var
|
|
101
|
-
var
|
|
133
|
+
var context = (0, exports.usePaymentCoreContext)();
|
|
134
|
+
var state = context.state;
|
|
135
|
+
var invoiceState = (0, context_2.useInvoiceModule)().state;
|
|
136
|
+
var invoices = (_a = invoiceState === null || invoiceState === void 0 ? void 0 : invoiceState.items) !== null && _a !== void 0 ? _a : [];
|
|
102
137
|
var theme = (0, next_themes_1.useTheme)().theme;
|
|
103
138
|
var t = (0, next_intl_1.useTranslations)("payment");
|
|
104
|
-
|
|
139
|
+
var currencies = (0, context_1.usePreferenceStateContext)().currencies;
|
|
105
140
|
// ---------------------------------------------------------------------------
|
|
106
|
-
//
|
|
141
|
+
// Toast Helpers
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
var showErrorToast = (0, react_1.useCallback)(function (description) {
|
|
144
|
+
(0, toast_utils_1.generateThemeToast)({
|
|
145
|
+
description: description,
|
|
146
|
+
theme: theme,
|
|
147
|
+
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
148
|
+
});
|
|
149
|
+
}, [theme]);
|
|
150
|
+
var showSuccessToast = (0, react_1.useCallback)(function (description) {
|
|
151
|
+
(0, toast_utils_1.generateThemeToast)({
|
|
152
|
+
description: description,
|
|
153
|
+
theme: theme,
|
|
154
|
+
variant: toast_utils_1.TOAST_VARIANT.SUCCESS,
|
|
155
|
+
});
|
|
156
|
+
}, [theme]);
|
|
157
|
+
// ---------------------------------------------------------------------------
|
|
158
|
+
// Debounced Values
|
|
107
159
|
// ---------------------------------------------------------------------------
|
|
108
160
|
var debouncedQuery = (0, util_functions_1.useDebounce)(state.searchQuery, 800);
|
|
109
161
|
// ---------------------------------------------------------------------------
|
|
110
|
-
// API
|
|
162
|
+
// API Parameters
|
|
111
163
|
// ---------------------------------------------------------------------------
|
|
112
164
|
var listParams = (0, react_1.useMemo)(function () { return ({
|
|
113
165
|
currentPage: state.currentPage,
|
|
166
|
+
includePaymentMode: true,
|
|
167
|
+
includeQuoteInvoice: true,
|
|
114
168
|
pageLimit: state.pageLimit,
|
|
115
169
|
searchQuery: state.searchQuery,
|
|
116
|
-
includeQuoteInvoice: true,
|
|
117
|
-
includePaymentMode: true,
|
|
118
170
|
}); }, [state.currentPage, state.pageLimit, state.searchQuery]);
|
|
119
171
|
var updateParams = (0, react_1.useMemo)(function () {
|
|
120
172
|
var _a, _b;
|
|
121
173
|
return ({
|
|
122
|
-
amount: state.amount,
|
|
174
|
+
amount: parseFloat(state.amount),
|
|
123
175
|
attachment: state.attachment,
|
|
124
|
-
balance: state.balance,
|
|
176
|
+
balance: parseFloat(state.balance),
|
|
125
177
|
currency: state.currency,
|
|
126
|
-
date: state.date,
|
|
178
|
+
date: new Date(state.date),
|
|
127
179
|
description: ((_a = state.description) === null || _a === void 0 ? void 0 : _a.trim()) || "",
|
|
128
180
|
id: state.id,
|
|
129
181
|
paymentModeId: state.paymentModeId,
|
|
@@ -135,290 +187,333 @@ var usePaymentState = function () {
|
|
|
135
187
|
var byIdParams = (0, react_1.useMemo)(function () { return ({ id: state.id }); }, [state.id]);
|
|
136
188
|
var deleteParams = (0, react_1.useMemo)(function () { return ({ id: state.id }); }, [state.id]);
|
|
137
189
|
// ---------------------------------------------------------------------------
|
|
138
|
-
//
|
|
190
|
+
// Currency Default
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
var defaultCurrency = (0, react_1.useMemo)(function () {
|
|
193
|
+
return currencies.filter(function (_a) {
|
|
194
|
+
var isDefault = _a.isDefault;
|
|
195
|
+
return isDefault;
|
|
196
|
+
})[0];
|
|
197
|
+
}, [currencies]);
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
// API Callbacks
|
|
139
200
|
// ---------------------------------------------------------------------------
|
|
140
|
-
var showErrorToast = (0, react_1.useCallback)(function (description) {
|
|
141
|
-
(0, toast_utils_1.generateThemeToast)({
|
|
142
|
-
description: description,
|
|
143
|
-
theme: theme,
|
|
144
|
-
variant: toast_utils_1.TOAST_VARIANT.ERROR,
|
|
145
|
-
});
|
|
146
|
-
}, [theme]);
|
|
147
|
-
var showSuccessToast = (0, react_1.useCallback)(function (description) {
|
|
148
|
-
(0, toast_utils_1.generateThemeToast)({
|
|
149
|
-
description: description,
|
|
150
|
-
theme: theme,
|
|
151
|
-
variant: toast_utils_1.TOAST_VARIANT.SUCCESS,
|
|
152
|
-
});
|
|
153
|
-
}, [theme]);
|
|
154
201
|
var listCallback = (0, react_1.useCallback)(function (_a) {
|
|
202
|
+
var _b;
|
|
155
203
|
var data = _a.data, error = _a.error;
|
|
156
204
|
if (error) {
|
|
157
205
|
showErrorToast(t("messagesNetworkError"));
|
|
158
206
|
}
|
|
159
207
|
if (data === null || data === void 0 ? void 0 : data.items) {
|
|
160
|
-
dispatch({
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
});
|
|
164
|
-
dispatch({
|
|
165
|
-
payload: { count: data === null || data === void 0 ? void 0 : data.count },
|
|
166
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_COUNT,
|
|
208
|
+
context.dispatch({
|
|
209
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_ITEMS,
|
|
210
|
+
payload: { items: data.items, count: (_b = data === null || data === void 0 ? void 0 : data.count) !== null && _b !== void 0 ? _b : 0 },
|
|
167
211
|
});
|
|
168
212
|
}
|
|
169
|
-
}, [
|
|
213
|
+
}, [t, showErrorToast]);
|
|
170
214
|
var updateCallback = (0, react_1.useCallback)(function (_a) {
|
|
171
215
|
var data = _a.data, error = _a.error;
|
|
172
216
|
if (error) {
|
|
173
217
|
showErrorToast(t("messagesNetworkError"));
|
|
174
218
|
}
|
|
175
219
|
if (data) {
|
|
220
|
+
(0, cache_1.invalidatePaymentsCache)();
|
|
176
221
|
showSuccessToast(t("messagesPaymentUpdated"));
|
|
177
|
-
dispatch({
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
type: actions_1.PAYMENT_ACTION_TYPES.RESET_ERRORS,
|
|
222
|
+
context.dispatch({ type: exports.PAYMENT_ACTION_TYPES.RESET_FORM });
|
|
223
|
+
context.dispatch({
|
|
224
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_ERRORS,
|
|
225
|
+
payload: { errors: {} },
|
|
182
226
|
});
|
|
183
227
|
listFetchNow();
|
|
184
|
-
dispatch({
|
|
228
|
+
context.dispatch({
|
|
229
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_DRAWER,
|
|
185
230
|
payload: { drawer: null },
|
|
186
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_DRAWER,
|
|
187
231
|
});
|
|
188
232
|
}
|
|
189
233
|
},
|
|
190
234
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
191
|
-
[
|
|
235
|
+
[t, showErrorToast, showSuccessToast]);
|
|
192
236
|
var byIdCallback = (0, react_1.useCallback)(function (_a) {
|
|
193
237
|
var data = _a.data, error = _a.error;
|
|
194
238
|
if (error) {
|
|
195
239
|
showErrorToast(t("messagesNetworkError"));
|
|
196
240
|
}
|
|
197
241
|
if (data) {
|
|
198
|
-
|
|
199
|
-
|
|
242
|
+
// Normalize currency to id if API returns code
|
|
243
|
+
var normalizedCurrency_1 = data.currency;
|
|
244
|
+
if (normalizedCurrency_1) {
|
|
245
|
+
var foundById = currencies.find(function (_a) {
|
|
246
|
+
var id = _a.id;
|
|
247
|
+
return id === normalizedCurrency_1;
|
|
248
|
+
});
|
|
249
|
+
if (!foundById) {
|
|
250
|
+
var foundByCode = currencies.find(function (_a) {
|
|
251
|
+
var code = _a.code;
|
|
252
|
+
return code === normalizedCurrency_1;
|
|
253
|
+
});
|
|
254
|
+
if (foundByCode)
|
|
255
|
+
normalizedCurrency_1 = foundByCode.id;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
var updatedData = __assign(__assign({}, data), (normalizedCurrency_1 && { currency: normalizedCurrency_1 }));
|
|
259
|
+
context.dispatch({
|
|
260
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_FORM_DATA,
|
|
200
261
|
payload: { form: updatedData },
|
|
201
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_FORM,
|
|
202
262
|
});
|
|
203
|
-
dispatch({
|
|
204
|
-
|
|
205
|
-
|
|
263
|
+
context.dispatch({
|
|
264
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_DRAWER,
|
|
265
|
+
payload: { drawer: paymentConfig.drawerTypes.FORM_DRAWER },
|
|
206
266
|
});
|
|
207
267
|
}
|
|
208
|
-
}, [
|
|
268
|
+
}, [t, showErrorToast, currencies]);
|
|
209
269
|
var deleteCallback = (0, react_1.useCallback)(function (_a) {
|
|
210
270
|
var data = _a.data, error = _a.error;
|
|
211
271
|
if (error) {
|
|
212
272
|
showErrorToast(t("messagesNetworkError"));
|
|
213
273
|
}
|
|
214
274
|
if (data) {
|
|
275
|
+
(0, cache_1.invalidatePaymentsCache)();
|
|
215
276
|
showSuccessToast(t("messagesPaymentDeleted"));
|
|
216
|
-
dispatch({
|
|
217
|
-
type: actions_1.PAYMENT_ACTION_TYPES.RESET_FORM,
|
|
218
|
-
});
|
|
277
|
+
context.dispatch({ type: exports.PAYMENT_ACTION_TYPES.RESET_FORM });
|
|
219
278
|
listFetchNow();
|
|
220
279
|
}
|
|
221
280
|
},
|
|
222
281
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
223
|
-
[
|
|
282
|
+
[t, showErrorToast, showSuccessToast]);
|
|
224
283
|
// ---------------------------------------------------------------------------
|
|
225
|
-
//
|
|
284
|
+
// Module Entity Hook
|
|
226
285
|
// ---------------------------------------------------------------------------
|
|
227
|
-
var _b = (0, util_functions_1.
|
|
286
|
+
var _b = (0, util_functions_1.useModuleEntityV2)({
|
|
228
287
|
byIdCallback: byIdCallback,
|
|
229
288
|
byIdParams: byIdParams,
|
|
230
289
|
deleteCallback: deleteCallback,
|
|
231
290
|
deleteParams: deleteParams,
|
|
232
291
|
listCallback: listCallback,
|
|
233
|
-
listDeps: [dispatch],
|
|
292
|
+
listDeps: [context.dispatch],
|
|
234
293
|
listParams: listParams,
|
|
235
|
-
listUrl: constants_1.PAYMENT_API_ROUTES.
|
|
294
|
+
listUrl: constants_1.PAYMENT_API_ROUTES.UNIT,
|
|
236
295
|
searchQuery: debouncedQuery,
|
|
237
|
-
unitByIdUrl: constants_1.PAYMENT_API_ROUTES.
|
|
238
|
-
unitUrl: constants_1.PAYMENT_API_ROUTES.
|
|
296
|
+
unitByIdUrl: constants_1.PAYMENT_API_ROUTES.UNIT,
|
|
297
|
+
unitUrl: constants_1.PAYMENT_API_ROUTES.UNIT,
|
|
239
298
|
updateCallback: updateCallback,
|
|
240
|
-
updateDeps: [state],
|
|
241
299
|
updateParams: updateParams,
|
|
242
|
-
}), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError,
|
|
243
|
-
// deleteFetchNow,
|
|
244
|
-
deleteLoading = _b.deleteLoading, listError = _b.listError, listFetchNow = _b.listFetchNow, listLoading = _b.listLoading, updateError = _b.updateError, updateFetchNow = _b.updateFetchNow, updateLoading = _b.updateLoading;
|
|
300
|
+
}), byIdError = _b.byIdError, byIdFetchNow = _b.byIdFetchNow, byIdLoading = _b.byIdLoading, deleteError = _b.deleteError, deleteLoading = _b.deleteLoading, listError = _b.listError, listFetchNow = _b.listFetchNow, listLoading = _b.listLoading, updateError = _b.updateError, updateFetchNow = _b.updateFetchNow, updateLoading = _b.updateLoading;
|
|
245
301
|
// ---------------------------------------------------------------------------
|
|
246
|
-
//
|
|
302
|
+
// Effects
|
|
247
303
|
// ---------------------------------------------------------------------------
|
|
304
|
+
(0, react_1.useEffect)(function () {
|
|
305
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
306
|
+
var _a, count, items, _b;
|
|
307
|
+
return __generator(this, function (_c) {
|
|
308
|
+
switch (_c.label) {
|
|
309
|
+
case 0:
|
|
310
|
+
_c.trys.push([0, 2, , 3]);
|
|
311
|
+
return [4 /*yield*/, (0, cache_1.getCachedPayments)({
|
|
312
|
+
params: listParams,
|
|
313
|
+
})];
|
|
314
|
+
case 1:
|
|
315
|
+
_a = _c.sent(), count = _a.count, items = _a.items;
|
|
316
|
+
context.dispatch({
|
|
317
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_ITEMS,
|
|
318
|
+
payload: { items: items || [], count: count || 0 },
|
|
319
|
+
});
|
|
320
|
+
return [3 /*break*/, 3];
|
|
321
|
+
case 2:
|
|
322
|
+
_b = _c.sent();
|
|
323
|
+
showErrorToast(t("messagesNetworkError"));
|
|
324
|
+
return [3 /*break*/, 3];
|
|
325
|
+
case 3: return [2 /*return*/];
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
}); })();
|
|
329
|
+
}, [listParams]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
248
330
|
(0, react_1.useEffect)(function () {
|
|
249
331
|
listFetchNow();
|
|
250
332
|
// eslint-disable-next-line
|
|
251
333
|
}, [debouncedQuery, state.currentPage, state.pageLimit]);
|
|
252
334
|
(0, react_1.useEffect)(function () {
|
|
253
335
|
var invoiceId = (0, util_functions_1.getStorageValue)("paymentInvoiceId");
|
|
254
|
-
console.log("_>>>", invoiceId);
|
|
255
336
|
if (invoiceId) {
|
|
256
337
|
var invoice = invoices.filter(function (_a) {
|
|
257
338
|
var id = _a.id;
|
|
258
339
|
return id === invoiceId;
|
|
259
340
|
})[0];
|
|
260
341
|
if (invoice) {
|
|
261
|
-
dispatch({
|
|
262
|
-
type:
|
|
342
|
+
context.dispatch({
|
|
343
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
263
344
|
payload: { key: "quoteInvoiceId", value: invoiceId },
|
|
264
345
|
});
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
346
|
+
// Normalize invoice currency to id (API may return id or code)
|
|
347
|
+
var invoiceCurrency_1 = invoice === null || invoice === void 0 ? void 0 : invoice.currency;
|
|
348
|
+
if (invoiceCurrency_1) {
|
|
349
|
+
var foundById = currencies.find(function (_a) {
|
|
350
|
+
var id = _a.id;
|
|
351
|
+
return id === invoiceCurrency_1;
|
|
352
|
+
});
|
|
353
|
+
if (!foundById) {
|
|
354
|
+
var foundByCode = currencies.find(function (_a) {
|
|
355
|
+
var code = _a.code;
|
|
356
|
+
return code === invoiceCurrency_1;
|
|
357
|
+
});
|
|
358
|
+
if (foundByCode)
|
|
359
|
+
invoiceCurrency_1 = foundByCode.id;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
context.dispatch({
|
|
363
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
364
|
+
payload: {
|
|
365
|
+
key: "currency",
|
|
366
|
+
value: invoiceCurrency_1 || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id),
|
|
367
|
+
},
|
|
268
368
|
});
|
|
269
|
-
dispatch({
|
|
270
|
-
type:
|
|
369
|
+
context.dispatch({
|
|
370
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
271
371
|
payload: { key: "amount", value: invoice === null || invoice === void 0 ? void 0 : invoice.total },
|
|
272
372
|
});
|
|
273
|
-
dispatch({
|
|
274
|
-
type:
|
|
373
|
+
context.dispatch({
|
|
374
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
275
375
|
payload: { key: "balance", value: "0.00" },
|
|
276
376
|
});
|
|
277
|
-
dispatch({
|
|
278
|
-
type:
|
|
279
|
-
payload: { invoice: invoice },
|
|
377
|
+
context.dispatch({
|
|
378
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
379
|
+
payload: { key: "invoice", value: invoice },
|
|
280
380
|
});
|
|
281
|
-
dispatch({
|
|
282
|
-
type:
|
|
283
|
-
payload: { drawer:
|
|
381
|
+
context.dispatch({
|
|
382
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_DRAWER,
|
|
383
|
+
payload: { drawer: paymentConfig.drawerTypes.FORM_DRAWER },
|
|
284
384
|
});
|
|
285
385
|
}
|
|
286
386
|
}
|
|
287
|
-
}, [invoices]);
|
|
387
|
+
}, [invoices, currencies, defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
288
388
|
// ---------------------------------------------------------------------------
|
|
289
|
-
//
|
|
389
|
+
// Drawer & Modal Handlers
|
|
290
390
|
// ---------------------------------------------------------------------------
|
|
291
391
|
var closeDrawer = (0, react_1.useCallback)(function () {
|
|
292
|
-
dispatch({
|
|
392
|
+
context.dispatch({
|
|
393
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_DRAWER,
|
|
293
394
|
payload: { drawer: null },
|
|
294
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_DRAWER,
|
|
295
|
-
});
|
|
296
|
-
dispatch({
|
|
297
|
-
type: actions_1.PAYMENT_ACTION_TYPES.RESET_FORM,
|
|
298
395
|
});
|
|
299
|
-
dispatch({
|
|
300
|
-
|
|
396
|
+
context.dispatch({ type: exports.PAYMENT_ACTION_TYPES.RESET_FORM });
|
|
397
|
+
context.dispatch({
|
|
398
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_ERRORS,
|
|
399
|
+
payload: { errors: {} },
|
|
301
400
|
});
|
|
302
|
-
}, [
|
|
401
|
+
}, [context]);
|
|
303
402
|
// ---------------------------------------------------------------------------
|
|
304
|
-
// CRUD
|
|
403
|
+
// CRUD Operation Handlers
|
|
305
404
|
// ---------------------------------------------------------------------------
|
|
306
405
|
var handleView = (0, react_1.useCallback)(function (id) {
|
|
307
406
|
byIdFetchNow(undefined, {
|
|
308
|
-
|
|
407
|
+
params: {
|
|
309
408
|
id: id,
|
|
310
|
-
includeQuoteInvoice: true,
|
|
311
409
|
includePaymentMode: true,
|
|
312
|
-
|
|
410
|
+
includeQuoteInvoice: true,
|
|
411
|
+
},
|
|
313
412
|
});
|
|
314
413
|
}, [byIdFetchNow]);
|
|
315
|
-
//
|
|
316
|
-
//
|
|
317
|
-
//
|
|
318
|
-
// body: JSON.stringify({ id }),
|
|
319
|
-
// });
|
|
320
|
-
// },
|
|
321
|
-
// [deleteFetchNow]
|
|
322
|
-
// );
|
|
414
|
+
// ---------------------------------------------------------------------------
|
|
415
|
+
// Form Submission Handler
|
|
416
|
+
// ---------------------------------------------------------------------------
|
|
323
417
|
var handleSubmit = (0, react_1.useCallback)(function () {
|
|
324
|
-
dispatch({
|
|
418
|
+
context.dispatch({
|
|
419
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
325
420
|
payload: { disableSaveButton: true },
|
|
326
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
327
421
|
});
|
|
328
422
|
(0, util_functions_1.validateForm)({
|
|
329
423
|
errorCallback: function (e) {
|
|
330
|
-
dispatch({
|
|
424
|
+
context.dispatch({
|
|
425
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_ERRORS,
|
|
331
426
|
payload: { errors: e },
|
|
332
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_ERRORS,
|
|
333
427
|
});
|
|
334
428
|
},
|
|
335
|
-
params: updateParams,
|
|
429
|
+
params: __assign(__assign({}, updateParams), { currency: updateParams.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id) }),
|
|
336
430
|
schema: validate_1.formValidation,
|
|
337
431
|
successCallback: function () {
|
|
338
432
|
updateFetchNow(undefined, {
|
|
339
|
-
body: JSON.stringify(__assign({}, updateParams)),
|
|
433
|
+
body: JSON.stringify(__assign(__assign({}, updateParams), { currency: updateParams.currency || (defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id) })),
|
|
340
434
|
});
|
|
341
435
|
},
|
|
342
436
|
});
|
|
343
437
|
(0, util_functions_1.removeStorageValue)("paymentInvoiceId");
|
|
344
|
-
}, [updateFetchNow, updateParams,
|
|
438
|
+
}, [context, updateFetchNow, updateParams, defaultCurrency === null || defaultCurrency === void 0 ? void 0 : defaultCurrency.id]);
|
|
345
439
|
// ---------------------------------------------------------------------------
|
|
346
|
-
//
|
|
440
|
+
// Form Change Handlers
|
|
347
441
|
// ---------------------------------------------------------------------------
|
|
348
442
|
var handleChange = (0, react_1.useCallback)(function (key, value) {
|
|
349
443
|
var _a, _b, _c;
|
|
350
444
|
if (key === "amount" && typeof value === "string") {
|
|
351
445
|
if (Number((_a = state === null || state === void 0 ? void 0 : state.invoice) === null || _a === void 0 ? void 0 : _a.total) > Number(value)) {
|
|
352
|
-
dispatch({
|
|
353
|
-
type:
|
|
354
|
-
payload: { key: "paymentType", value:
|
|
446
|
+
context.dispatch({
|
|
447
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
448
|
+
payload: { key: "paymentType", value: util_functions_1.PAYMENT_TYPE.PARTIAL_AMOUNT },
|
|
355
449
|
});
|
|
356
450
|
}
|
|
357
451
|
if (Number((_b = state === null || state === void 0 ? void 0 : state.invoice) === null || _b === void 0 ? void 0 : _b.total) === Number(value)) {
|
|
358
|
-
dispatch({
|
|
359
|
-
type:
|
|
360
|
-
payload: { key: "paymentType", value:
|
|
452
|
+
context.dispatch({
|
|
453
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
454
|
+
payload: { key: "paymentType", value: util_functions_1.PAYMENT_TYPE.FULL_AMOUNT },
|
|
361
455
|
});
|
|
362
456
|
}
|
|
363
|
-
dispatch({
|
|
364
|
-
type:
|
|
457
|
+
context.dispatch({
|
|
458
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
365
459
|
payload: {
|
|
366
460
|
key: "balance",
|
|
367
461
|
value: Number(Number((_c = state === null || state === void 0 ? void 0 : state.invoice) === null || _c === void 0 ? void 0 : _c.total) - Number(value)).toFixed(2),
|
|
368
462
|
},
|
|
369
463
|
});
|
|
370
464
|
}
|
|
371
|
-
dispatch({
|
|
465
|
+
context.dispatch({
|
|
466
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
372
467
|
payload: { key: key, value: String(value) },
|
|
373
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
374
468
|
});
|
|
375
|
-
dispatch({
|
|
469
|
+
context.dispatch({
|
|
470
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
376
471
|
payload: { disableSaveButton: false },
|
|
377
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
378
472
|
});
|
|
379
|
-
dispatch({
|
|
380
|
-
type:
|
|
473
|
+
context.dispatch({
|
|
474
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_ERRORS,
|
|
475
|
+
payload: { errors: {} },
|
|
381
476
|
});
|
|
382
|
-
}, [
|
|
477
|
+
}, [context, state === null || state === void 0 ? void 0 : state.invoice]);
|
|
383
478
|
// ---------------------------------------------------------------------------
|
|
384
|
-
//
|
|
479
|
+
// Pagination Handlers
|
|
385
480
|
// ---------------------------------------------------------------------------
|
|
386
481
|
var handleNextClick = (0, react_1.useCallback)(function () {
|
|
387
|
-
dispatch({
|
|
482
|
+
context.dispatch({
|
|
483
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
388
484
|
payload: { currentPage: state.currentPage + 1 },
|
|
389
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
390
485
|
});
|
|
391
|
-
}, [state.currentPage
|
|
486
|
+
}, [context, state.currentPage]);
|
|
392
487
|
var handlePreviousClick = (0, react_1.useCallback)(function () {
|
|
393
|
-
dispatch({
|
|
488
|
+
context.dispatch({
|
|
489
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
394
490
|
payload: { currentPage: state.currentPage - 1 },
|
|
395
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
396
491
|
});
|
|
397
|
-
}, [state.currentPage
|
|
492
|
+
}, [context, state.currentPage]);
|
|
398
493
|
var handlePageLimit = (0, react_1.useCallback)(function (node, value) {
|
|
399
494
|
var val = __assign({}, value);
|
|
400
|
-
dispatch({
|
|
495
|
+
context.dispatch({
|
|
496
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_PAGE_LIMIT,
|
|
401
497
|
payload: { pageLimit: Number(val.option) },
|
|
402
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_PAGE_LIMIT,
|
|
403
498
|
});
|
|
404
|
-
}, [
|
|
499
|
+
}, [context]);
|
|
405
500
|
// ---------------------------------------------------------------------------
|
|
406
|
-
//
|
|
501
|
+
// Search Handlers
|
|
407
502
|
// ---------------------------------------------------------------------------
|
|
408
503
|
var searchOnChange = (0, react_1.useCallback)(function (k, v) {
|
|
409
|
-
dispatch({
|
|
504
|
+
context.dispatch({
|
|
505
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_SEARCH_QUERY,
|
|
410
506
|
payload: { searchQuery: v },
|
|
411
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_SEARCH_QUERY,
|
|
412
507
|
});
|
|
413
|
-
}, [
|
|
508
|
+
}, [context]);
|
|
414
509
|
var clearSearch = (0, react_1.useCallback)(function () {
|
|
415
|
-
dispatch({
|
|
510
|
+
context.dispatch({
|
|
511
|
+
type: exports.PAYMENT_ACTION_TYPES.SET_SEARCH_QUERY,
|
|
416
512
|
payload: { searchQuery: "" },
|
|
417
|
-
type: actions_1.PAYMENT_ACTION_TYPES.SET_SEARCH_QUERY,
|
|
418
513
|
});
|
|
419
|
-
}, [
|
|
514
|
+
}, [context]);
|
|
420
515
|
// ---------------------------------------------------------------------------
|
|
421
|
-
//
|
|
516
|
+
// Table Actions
|
|
422
517
|
// ---------------------------------------------------------------------------
|
|
423
518
|
var headerActions = (0, react_1.useMemo)(function () { return []; }, []);
|
|
424
519
|
var rowActions = (0, react_1.useMemo)(function () { return [
|
|
@@ -428,33 +523,10 @@ var usePaymentState = function () {
|
|
|
428
523
|
label: t("actionsButtonView"),
|
|
429
524
|
order: 1,
|
|
430
525
|
},
|
|
431
|
-
]; }, []);
|
|
526
|
+
]; }, [handleView, t]);
|
|
432
527
|
// ---------------------------------------------------------------------------
|
|
433
|
-
//
|
|
528
|
+
// Return State (flat, backward-compatible)
|
|
434
529
|
// ---------------------------------------------------------------------------
|
|
435
|
-
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 });
|
|
436
|
-
};
|
|
437
|
-
// ============================================================================
|
|
438
|
-
// CONTEXT SETUP
|
|
439
|
-
// ============================================================================
|
|
440
|
-
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 }));
|
|
441
|
-
// ============================================================================
|
|
442
|
-
// PROVIDER COMPONENT
|
|
443
|
-
// ============================================================================
|
|
444
|
-
var PaymentStateContextProvider = function (_a) {
|
|
445
|
-
var children = _a.children;
|
|
446
|
-
var state = usePaymentState();
|
|
447
|
-
return (react_1.default.createElement(exports.PaymentStateContext.Provider, { value: state }, children));
|
|
448
|
-
};
|
|
449
|
-
exports.PaymentStateContextProvider = PaymentStateContextProvider;
|
|
450
|
-
// ============================================================================
|
|
451
|
-
// CUSTOM HOOK
|
|
452
|
-
// ============================================================================
|
|
453
|
-
var usePaymentStateContext = function () {
|
|
454
|
-
var state = (0, react_1.useContext)(exports.PaymentStateContext);
|
|
455
|
-
if (state === undefined) {
|
|
456
|
-
throw new Error("usePaymentStateContext must be used within a PaymentContextProvider");
|
|
457
|
-
}
|
|
458
|
-
return state;
|
|
530
|
+
return __assign(__assign({}, state), { payments: state.items, byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: context.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 });
|
|
459
531
|
};
|
|
460
|
-
exports.
|
|
532
|
+
exports.usePaymentModule = usePaymentModule;
|