@appcorp/stellar-solutions-invoice-module 0.1.74 → 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.
Files changed (89) hide show
  1. package/base-modules/invoice/add-service-product-section.d.ts +1 -5
  2. package/base-modules/invoice/add-service-product-section.js +3 -3
  3. package/base-modules/invoice/cache.d.ts +15 -0
  4. package/base-modules/invoice/cache.js +50 -0
  5. package/base-modules/invoice/calculate-subtotal.d.ts +6 -1
  6. package/base-modules/invoice/calculate-subtotal.js +2 -2
  7. package/base-modules/invoice/calculate-total.d.ts +1 -1
  8. package/base-modules/invoice/calculate-total.js +8 -8
  9. package/base-modules/invoice/company-form-section.d.ts +1 -5
  10. package/base-modules/invoice/company-form-section.js +25 -22
  11. package/base-modules/invoice/constants.d.ts +2 -3
  12. package/base-modules/invoice/constants.js +2 -3
  13. package/base-modules/invoice/context.d.ts +556 -20
  14. package/base-modules/invoice/context.js +530 -342
  15. package/base-modules/invoice/customer-form-section.d.ts +1 -5
  16. package/base-modules/invoice/customer-form-section.js +25 -9
  17. package/base-modules/invoice/form.d.ts +1 -5
  18. package/base-modules/invoice/form.js +9 -9
  19. package/base-modules/invoice/page.d.ts +8 -0
  20. package/base-modules/invoice/page.js +171 -0
  21. package/base-modules/invoice/pricing-form-section.d.ts +1 -5
  22. package/base-modules/invoice/pricing-form-section.js +16 -11
  23. package/base-modules/invoice/products-form-section.d.ts +1 -5
  24. package/base-modules/invoice/products-form-section.js +49 -40
  25. package/base-modules/invoice/services-form-section.d.ts +1 -5
  26. package/base-modules/invoice/services-form-section.js +10 -9
  27. package/base-modules/invoice/validate.d.ts +83 -25
  28. package/base-modules/invoice/validate.js +4 -4
  29. package/base-modules/payment/cache.d.ts +15 -0
  30. package/base-modules/payment/cache.js +52 -0
  31. package/base-modules/payment/constants.d.ts +1 -14
  32. package/base-modules/payment/constants.js +2 -15
  33. package/base-modules/payment/context.d.ts +214 -48
  34. package/base-modules/payment/context.js +266 -237
  35. package/base-modules/payment/drawer.d.ts +0 -6
  36. package/base-modules/payment/drawer.js +89 -44
  37. package/base-modules/payment/form.js +3 -2
  38. package/base-modules/payment/{payment.js → page.js} +2 -5
  39. package/base-modules/payment/types.d.ts +0 -85
  40. package/base-modules/payment/types.js +74 -21
  41. package/base-modules/payment/validate.d.ts +12 -0
  42. package/base-modules/payment/validate.js +19 -8
  43. package/base-modules/payment/view.d.ts +1 -5
  44. package/base-modules/payment/view.js +4 -3
  45. package/base-modules/quote/add-service-product-section.js +1 -1
  46. package/base-modules/quote/cache.d.ts +15 -0
  47. package/base-modules/quote/cache.js +50 -0
  48. package/base-modules/quote/company-form-section.d.ts +1 -1
  49. package/base-modules/quote/company-form-section.js +14 -12
  50. package/base-modules/quote/constants.js +1 -0
  51. package/base-modules/quote/context.d.ts +656 -46
  52. package/base-modules/quote/context.js +413 -289
  53. package/base-modules/quote/customer-form-section.d.ts +1 -1
  54. package/base-modules/quote/customer-form-section.js +24 -9
  55. package/base-modules/quote/form.d.ts +1 -5
  56. package/base-modules/quote/form.js +8 -9
  57. package/base-modules/quote/page.d.ts +8 -0
  58. package/base-modules/quote/page.js +163 -0
  59. package/base-modules/quote/pricing-form-section.js +9 -8
  60. package/base-modules/quote/products-form-section.js +2 -2
  61. package/base-modules/quote/services-form-section.js +1 -1
  62. package/base-modules/quote/types.d.ts +0 -127
  63. package/base-modules/quote/types.js +92 -35
  64. package/base-modules/quote/validate.d.ts +82 -25
  65. package/base-modules/quote/validate.js +3 -4
  66. package/package.json +8 -8
  67. package/base-modules/invoice/actions.d.ts +0 -215
  68. package/base-modules/invoice/actions.js +0 -38
  69. package/base-modules/invoice/drawer.d.ts +0 -13
  70. package/base-modules/invoice/drawer.js +0 -46
  71. package/base-modules/invoice/invoice.d.ts +0 -8
  72. package/base-modules/invoice/invoice.js +0 -69
  73. package/base-modules/invoice/reducer.d.ts +0 -4
  74. package/base-modules/invoice/reducer.js +0 -180
  75. package/base-modules/invoice/types.d.ts +0 -211
  76. package/base-modules/invoice/types.js +0 -43
  77. package/base-modules/payment/actions.d.ts +0 -203
  78. package/base-modules/payment/actions.js +0 -50
  79. package/base-modules/payment/reducer.d.ts +0 -29
  80. package/base-modules/payment/reducer.js +0 -215
  81. package/base-modules/quote/actions.d.ts +0 -215
  82. package/base-modules/quote/actions.js +0 -38
  83. package/base-modules/quote/drawer.d.ts +0 -13
  84. package/base-modules/quote/drawer.js +0 -46
  85. package/base-modules/quote/quote.d.ts +0 -8
  86. package/base-modules/quote/quote.js +0 -69
  87. package/base-modules/quote/reducer.d.ts +0 -4
  88. package/base-modules/quote/reducer.js +0 -181
  89. /package/base-modules/payment/{payment.d.ts → page.d.ts} +0 -0
@@ -1,42 +1,8 @@
1
1
  /**
2
- * Invoice State Context
2
+ * Quote State Context - Using Generic Module Factory
3
3
  *
4
- * This module provides comprehensive state management for the Invoice feature including:
5
- * - CRUD operations (create, read, update, delete)
6
- * - Form validation and error handling
7
- * - Multi-section forms (company, customer, pricing, products, services)
8
- * - Complex calculations (subtotal, tax, discount, total)
9
- * - Dynamic product and service row management
10
- * - Search and filtering functionality
11
- * - Pagination controls
12
- * - Company and customer integration
13
- * - Currency and tax management
14
- * - Internationalization support
15
- * - Theme-aware toast notifications
16
- *
17
- * Organization:
18
- * - Types & Interfaces
19
- * - Main Hook (useInvoiceState)
20
- * - State & Core Hooks
21
- * - Theme Support
22
- * - Toast Helpers
23
- * - Debounced Values
24
- * - Tax & Currency Defaults
25
- * - API Parameters (memoized)
26
- * - API Callbacks (with error handling)
27
- * - Module Entity Hook
28
- * - Effects (list refresh, defaults, calculations)
29
- * - Drawer & Modal Handlers
30
- * - CRUD Operation Handlers
31
- * - Form Handlers (products, services, pricing)
32
- * - Calculation Handlers
33
- * - Pagination Handlers
34
- * - Search Handlers
35
- * - Table Actions (memoized)
36
- * - Return State
37
- * - Context Setup
38
- * - Provider Component
39
- * - Custom Hook
4
+ * This module provides comprehensive state management for the Quote feature using
5
+ * the createGenericModule factory pattern.
40
6
  */
41
7
  "use client";
42
8
  "use strict";
@@ -51,39 +17,6 @@ var __assign = (this && this.__assign) || function () {
51
17
  };
52
18
  return __assign.apply(this, arguments);
53
19
  };
54
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
55
- if (k2 === undefined) k2 = k;
56
- var desc = Object.getOwnPropertyDescriptor(m, k);
57
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
58
- desc = { enumerable: true, get: function() { return m[k]; } };
59
- }
60
- Object.defineProperty(o, k2, desc);
61
- }) : (function(o, m, k, k2) {
62
- if (k2 === undefined) k2 = k;
63
- o[k2] = m[k];
64
- }));
65
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
66
- Object.defineProperty(o, "default", { enumerable: true, value: v });
67
- }) : function(o, v) {
68
- o["default"] = v;
69
- });
70
- var __importStar = (this && this.__importStar) || (function () {
71
- var ownKeys = function(o) {
72
- ownKeys = Object.getOwnPropertyNames || function (o) {
73
- var ar = [];
74
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
75
- return ar;
76
- };
77
- return ownKeys(o);
78
- };
79
- return function (mod) {
80
- if (mod && mod.__esModule) return mod;
81
- var result = {};
82
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
83
- __setModuleDefault(result, mod);
84
- return result;
85
- };
86
- })();
87
20
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
88
21
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
89
22
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -129,34 +62,161 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
129
62
  }
130
63
  return to.concat(ar || Array.prototype.slice.call(from));
131
64
  };
65
+ var _a;
132
66
  Object.defineProperty(exports, "__esModule", { value: true });
133
- exports.useQuoteStateContext = exports.QuoteStateContextProvider = exports.QuoteStateContext = void 0;
134
- var react_1 = __importStar(require("react"));
67
+ exports.useQuoteModule = exports.initialQuoteState = exports.QUOTE_ACTION_TYPES = exports.quoteModuleConfig = exports.useQuoteContext = exports.QuoteProvider = exports.quoteReducer = void 0;
68
+ var react_1 = require("react");
69
+ var date_fns_1 = require("date-fns");
135
70
  var next_themes_1 = require("next-themes");
136
71
  var next_intl_1 = require("next-intl");
137
72
  var util_functions_1 = require("@react-pakistan/util-functions");
73
+ var generic_module_factory_1 = require("@react-pakistan/util-functions/factory/generic-module-factory");
74
+ var generic_component_factory_1 = require("@react-pakistan/util-functions/factory/generic-component-factory");
138
75
  var toast_utils_1 = require("@appcorp/shadcn/lib/toast-utils");
139
- var actions_1 = require("./actions");
76
+ // import { CompanyTypeBE } from "@appcorp/stellar-solutions-company-module/base-modules/company/types";
77
+ // import { CustomerTypeBE } from "@appcorp/stellar-solutions-company-module/base-modules/customer/types";
78
+ // import { ContactTypeBE } from "@appcorp/stellar-solutions-company-module/base-modules/contact/types";
79
+ // import { ProductTypeBE } from "@appcorp/stellar-solutions-product-module/base-modules/product/types";
80
+ // import { TaxTypeBE } from "@appcorp/stellar-solutions-modules/global-modules/preferences/types";
140
81
  var constants_1 = require("./constants");
141
- var reducer_1 = require("./reducer");
142
- var types_1 = require("./types");
82
+ // import {
83
+ // DISCOUNT_UNIT,
84
+ // INVOICE_MODE,
85
+ // INVOICE_STATUS,
86
+ // Product,
87
+ // QUOTE_INVOICE_CATEGORY,
88
+ // QUOTE_STATUS,
89
+ // QuoteInvoiceTypeBE,
90
+ // QuoteInvoiceTypeFE,
91
+ // Service,
92
+ // } from "../invoice/types";
93
+ var cache_1 = require("./cache");
143
94
  var validate_1 = require("./validate");
144
95
  var calculate_subtotal_1 = require("./calculate-subtotal");
145
96
  var calculate_total_1 = require("./calculate-total");
146
97
  var context_1 = require("@appcorp/stellar-solutions-modules/global-modules/tax/context");
147
98
  var context_2 = require("@appcorp/stellar-solutions-modules/global-modules/preferences/context");
148
99
  // ============================================================================
149
- // MAIN HOOK
100
+ // MODULE CONFIGURATION
101
+ // ============================================================================
102
+ var quoteConfig = {
103
+ name: "Quote",
104
+ displayName: "Quote",
105
+ initialState: {
106
+ // List Data
107
+ items: [],
108
+ count: 0,
109
+ // Search & Pagination
110
+ currentPage: 1,
111
+ pageLimit: constants_1.pageLimit,
112
+ searchQuery: "",
113
+ // UI State
114
+ disableSaveButton: false,
115
+ drawer: null,
116
+ quoteMode: null,
117
+ modal: null,
118
+ loading: true,
119
+ // Form Fields
120
+ afterDiscount: "0",
121
+ category: util_functions_1.QUOTE_INVOICE_CATEGORY.QUOTE,
122
+ companiesList: [],
123
+ companyId: "",
124
+ companyQuery: "",
125
+ contactsList: [],
126
+ countryQuery: "",
127
+ currency: "",
128
+ customerId: "",
129
+ date: new Date().toISOString(),
130
+ discount: "0",
131
+ discountUnit: util_functions_1.DISCOUNT_UNIT.FIXED_VALUE,
132
+ errors: {},
133
+ expiryDate: (0, date_fns_1.addDays)(new Date(), 7).toISOString(),
134
+ getProducts: [],
135
+ id: "",
136
+ invoiceStatus: util_functions_1.INVOICE_STATUS.UNPAID,
137
+ mode: "Create",
138
+ netTotal: "",
139
+ note: "",
140
+ payments: [],
141
+ products: [],
142
+ productQuery: "",
143
+ productsList: [
144
+ {
145
+ id: "",
146
+ mode: "Create",
147
+ price: "",
148
+ quantity: "1",
149
+ rowTotal: "",
150
+ },
151
+ ],
152
+ quoteStatus: util_functions_1.QUOTE_STATUS.DRAFT,
153
+ ref: "",
154
+ servicesList: [
155
+ {
156
+ description: "",
157
+ mode: "Create",
158
+ name: "",
159
+ price: "",
160
+ quantity: "1",
161
+ rowTotal: "",
162
+ },
163
+ ],
164
+ services: [],
165
+ subTotal: "",
166
+ tax: "",
167
+ taxQuery: "",
168
+ taxRate: "",
169
+ taxes: [],
170
+ total: "",
171
+ customer: {
172
+ address: "",
173
+ city: "",
174
+ country: "",
175
+ createdAt: "",
176
+ email: "",
177
+ firstName: "",
178
+ id: "",
179
+ lastName: "",
180
+ phone: "",
181
+ quotesInvoices: [],
182
+ updatedAt: "",
183
+ },
184
+ company: {
185
+ contacts: [],
186
+ country: "",
187
+ createdAt: "",
188
+ email: "",
189
+ id: "",
190
+ name: "",
191
+ phone: "",
192
+ quotesInvoices: [],
193
+ updatedAt: "",
194
+ website: "",
195
+ },
196
+ },
197
+ drawerTypes: __assign({}, generic_component_factory_1.DRAWER_TYPES),
198
+ };
199
+ // ============================================================================
200
+ // CREATE QUOTE MODULE
201
+ // ============================================================================
202
+ exports.quoteReducer = (_a = (0, generic_module_factory_1.createGenericModule)(quoteConfig), _a.reducer), exports.QuoteProvider = _a.Provider, exports.useQuoteContext = _a.useContext, exports.quoteModuleConfig = _a.config, exports.QUOTE_ACTION_TYPES = _a.actionTypes, exports.initialQuoteState = _a.initialState;
203
+ // ============================================================================
204
+ // ENHANCED QUOTE HOOK WITH API INTEGRATION
150
205
  // ============================================================================
151
- var useQuoteState = function () {
206
+ // interface StateProviderProps {
207
+ // children: ReactNode;
208
+ // }
209
+ var useQuoteModule = function () {
152
210
  var _a;
153
211
  // ---------------------------------------------------------------------------
154
- // State & Core Hooks
212
+ // State via factory context
155
213
  // ---------------------------------------------------------------------------
156
- var _b = (0, react_1.useReducer)(reducer_1.quoteReducer, reducer_1.initialQuoteState), state = _b[0], dispatch = _b[1];
214
+ var context = (0, exports.useQuoteContext)();
215
+ var state = context.state;
157
216
  var t = (0, next_intl_1.useTranslations)("quote");
158
217
  var theme = (0, next_themes_1.useTheme)().theme;
159
- var taxes = (0, context_1.useTaxStateContext)().taxes;
218
+ var taxModule = (0, context_1.useTaxModule)();
219
+ var taxes = taxModule.state.items;
160
220
  var currencies = (0, context_2.usePreferenceStateContext)().currencies;
161
221
  // ---------------------------------------------------------------------------
162
222
  // Toast Helpers
@@ -199,10 +259,10 @@ var useQuoteState = function () {
199
259
  })[0];
200
260
  }, [currencies]);
201
261
  // ---------------------------------------------------------------------------
202
- // API PARAMETERS
262
+ // API Parameters
203
263
  // ---------------------------------------------------------------------------
204
264
  var listParams = (0, react_1.useMemo)(function () { return ({
205
- category: types_1.QUOTE_INVOICE_CATEGORY.QUOTE,
265
+ category: util_functions_1.QUOTE_INVOICE_CATEGORY.QUOTE,
206
266
  currentPage: state.currentPage,
207
267
  includeCompany: true,
208
268
  includeCustomer: true,
@@ -216,11 +276,10 @@ var useQuoteState = function () {
216
276
  companyId: state.companyId,
217
277
  currency: state.currency,
218
278
  customerId: state.customerId,
219
- date: state.date,
220
- discount: (_a = state === null || state === void 0 ? void 0 : state.discount) === null || _a === void 0 ? void 0 : _a.trim(),
279
+ date: new Date(state.date),
280
+ discount: Number((_a = state === null || state === void 0 ? void 0 : state.discount) === null || _a === void 0 ? void 0 : _a.trim()),
221
281
  discountUnit: state.discountUnit,
222
- drawer: state.drawer,
223
- expiryDate: state.expiryDate,
282
+ expiryDate: new Date(state.expiryDate),
224
283
  id: state.id,
225
284
  invoiceStatus: state.invoiceStatus,
226
285
  mode: state.mode,
@@ -235,9 +294,9 @@ var useQuoteState = function () {
235
294
  var name = _a.name;
236
295
  return name;
237
296
  }),
238
- subTotal: state.subTotal,
239
- taxRate: state.taxRate,
240
- total: state.total,
297
+ subTotal: Number(state.subTotal),
298
+ taxRate: Number(state.taxRate),
299
+ total: Number(state.total),
241
300
  phone: (_b = state.customer) === null || _b === void 0 ? void 0 : _b.phone,
242
301
  firstName: (_c = state.customer) === null || _c === void 0 ? void 0 : _c.firstName,
243
302
  lastName: (_d = state.customer) === null || _d === void 0 ? void 0 : _d.lastName,
@@ -250,22 +309,19 @@ var useQuoteState = function () {
250
309
  var byIdParams = (0, react_1.useMemo)(function () { return ({ id: state.id }); }, [state.id]);
251
310
  var deleteParams = (0, react_1.useMemo)(function () { return ({ id: state.id }); }, [state.id]);
252
311
  // ---------------------------------------------------------------------------
253
- // API CALLBACKS
312
+ // API Callbacks
254
313
  // ---------------------------------------------------------------------------
255
314
  var listCallback = (0, react_1.useCallback)(function (_a) {
315
+ var _b;
256
316
  var data = _a.data, error = _a.error;
257
317
  if (error) {
258
318
  showErrorToast(t("messagesNetworkError"));
259
319
  return;
260
320
  }
261
321
  if (data === null || data === void 0 ? void 0 : data.items) {
262
- dispatch({
263
- type: actions_1.QUOTE_ACTION_TYPES.SET_QUOTES,
264
- payload: { quotes: data.items },
265
- });
266
- dispatch({
267
- type: actions_1.QUOTE_ACTION_TYPES.SET_COUNT,
268
- payload: { count: data === null || data === void 0 ? void 0 : data.count },
322
+ context.dispatch({
323
+ type: exports.QUOTE_ACTION_TYPES.SET_ITEMS,
324
+ payload: { items: data.items, count: (_b = data === null || data === void 0 ? void 0 : data.count) !== null && _b !== void 0 ? _b : 0 },
269
325
  });
270
326
  }
271
327
  }, [t, showErrorToast]);
@@ -276,14 +332,18 @@ var useQuoteState = function () {
276
332
  return;
277
333
  }
278
334
  if (data) {
335
+ (0, cache_1.invalidateQuotesCache)();
279
336
  showSuccessToast(state.mode === "Edit"
280
337
  ? t("messagesQuoteUpdated")
281
338
  : t("messagesQuoteCreated"));
282
- dispatch({ type: actions_1.QUOTE_ACTION_TYPES.RESET_FORM });
283
- dispatch({ type: actions_1.QUOTE_ACTION_TYPES.RESET_ERRORS });
339
+ context.dispatch({ type: exports.QUOTE_ACTION_TYPES.RESET_FORM });
340
+ context.dispatch({
341
+ type: exports.QUOTE_ACTION_TYPES.SET_ERRORS,
342
+ payload: { errors: {} },
343
+ });
284
344
  listFetchNow();
285
- dispatch({
286
- type: actions_1.QUOTE_ACTION_TYPES.SET_DRAWER,
345
+ context.dispatch({
346
+ type: exports.QUOTE_ACTION_TYPES.SET_DRAWER,
287
347
  payload: { drawer: null },
288
348
  });
289
349
  }
@@ -291,7 +351,7 @@ var useQuoteState = function () {
291
351
  // eslint-disable-next-line react-hooks/exhaustive-deps
292
352
  [t, state.mode, showErrorToast, showSuccessToast]);
293
353
  var byIdCallback = (0, react_1.useCallback)(function (_a) {
294
- var _b, _c, _d, _e, _f;
354
+ var _b, _c, _d;
295
355
  var data = _a.data, error = _a.error;
296
356
  if (error) {
297
357
  showErrorToast(t("messagesQuoteFetchError"));
@@ -325,36 +385,34 @@ var useQuoteState = function () {
325
385
  var updatedData = __assign(__assign(__assign(__assign(__assign({}, data), (normalizedCurrency_1 && { currency: normalizedCurrency_1 })), { mode: "Edit", companyId: (data === null || data === void 0 ? void 0 : data.companyId) || "", customerId: (data === null || data === void 0 ? void 0 : data.customerId) || "" }), (((_b = data === null || data === void 0 ? void 0 : data.customer) === null || _b === void 0 ? void 0 : _b.id) && {
326
386
  customer: __assign({}, data.customer),
327
387
  })), { servicesList: __spreadArray([], updatedServices, true).filter(function (item) { return item.name; }), productsList: __spreadArray([], updatedProducts, true).filter(function (item) { return item.id; }), companiesList: [__assign({}, data.company)] });
388
+ context.dispatch({
389
+ type: exports.QUOTE_ACTION_TYPES.SET_FORM_DATA,
390
+ payload: { form: updatedData },
391
+ });
328
392
  if ((_c = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _c === void 0 ? void 0 : _c.name) {
329
- dispatch({
330
- type: actions_1.QUOTE_ACTION_TYPES.SET_DRAWER,
331
- payload: { drawer: types_1.QUOTE_DRAWER.QUOTE_COMPANY_FORM_DRAWER },
393
+ context.dispatch({
394
+ type: exports.QUOTE_ACTION_TYPES.SET_DRAWER,
395
+ payload: { drawer: generic_component_factory_1.DRAWER_TYPES.FORM_DRAWER },
396
+ });
397
+ context.dispatch({
398
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
399
+ payload: { key: "quoteMode", value: "INVOICE_MODE.COMPANY" },
332
400
  });
333
401
  }
334
402
  if ((_d = updatedData === null || updatedData === void 0 ? void 0 : updatedData.customer) === null || _d === void 0 ? void 0 : _d.firstName) {
335
- dispatch({
336
- type: actions_1.QUOTE_ACTION_TYPES.SET_DRAWER,
337
- payload: { drawer: types_1.QUOTE_DRAWER.QUOTE_CUSTOMER_FORM_DRAWER },
403
+ context.dispatch({
404
+ type: exports.QUOTE_ACTION_TYPES.SET_DRAWER,
405
+ payload: { drawer: generic_component_factory_1.DRAWER_TYPES.FORM_DRAWER },
338
406
  });
339
- }
340
- dispatch({
341
- type: actions_1.QUOTE_ACTION_TYPES.SET_FORM,
342
- payload: { form: updatedData },
343
- });
344
- if ((_e = updatedData === null || updatedData === void 0 ? void 0 : updatedData.company) === null || _e === void 0 ? void 0 : _e.name) {
345
- dispatch({
346
- type: actions_1.QUOTE_ACTION_TYPES.SET_DRAWER,
347
- payload: { drawer: types_1.QUOTE_DRAWER.QUOTE_COMPANY_FORM_DRAWER },
348
- });
349
- }
350
- if ((_f = updatedData === null || updatedData === void 0 ? void 0 : updatedData.customer) === null || _f === void 0 ? void 0 : _f.firstName) {
351
- dispatch({
352
- type: actions_1.QUOTE_ACTION_TYPES.SET_DRAWER,
353
- payload: { drawer: types_1.QUOTE_DRAWER.QUOTE_CUSTOMER_FORM_DRAWER },
407
+ context.dispatch({
408
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
409
+ payload: { key: "quoteMode", value: "INVOICE_MODE.CUSTOMER" },
354
410
  });
355
411
  }
356
412
  }
357
- }, [t, showErrorToast, currencies]);
413
+ },
414
+ // eslint-disable-next-line react-hooks/exhaustive-deps
415
+ [t, showErrorToast, currencies]);
358
416
  var deleteCallback = (0, react_1.useCallback)(function (_a) {
359
417
  var data = _a.data, error = _a.error;
360
418
  if (error) {
@@ -362,8 +420,9 @@ var useQuoteState = function () {
362
420
  return;
363
421
  }
364
422
  if (data) {
423
+ (0, cache_1.invalidateQuotesCache)();
365
424
  showSuccessToast(t("messagesQuoteDeleted"));
366
- dispatch({ type: actions_1.QUOTE_ACTION_TYPES.RESET_FORM });
425
+ context.dispatch({ type: exports.QUOTE_ACTION_TYPES.RESET_FORM });
367
426
  listFetchNow();
368
427
  }
369
428
  },
@@ -372,7 +431,7 @@ var useQuoteState = function () {
372
431
  // ---------------------------------------------------------------------------
373
432
  // Module Entity Hook
374
433
  // ---------------------------------------------------------------------------
375
- var _c = (0, util_functions_1.useModuleEntity)({
434
+ var _b = (0, util_functions_1.useModuleEntityV2)({
376
435
  byIdCallback: byIdCallback,
377
436
  byIdParams: byIdParams,
378
437
  deleteCallback: deleteCallback,
@@ -384,13 +443,37 @@ var useQuoteState = function () {
384
443
  unitByIdUrl: constants_1.QUOTE_API_ROUTES.QUOTE_BY_ID,
385
444
  unitUrl: constants_1.QUOTE_API_ROUTES.QUOTE,
386
445
  updateCallback: updateCallback,
387
- updateDeps: [state],
388
- listDeps: [debouncedQuery, state.currentPage, state.pageLimit],
389
446
  updateParams: __assign(__assign({}, updateParams), { mode: "Create" }),
390
- }), byIdError = _c.byIdError, byIdFetchNow = _c.byIdFetchNow, byIdLoading = _c.byIdLoading, deleteError = _c.deleteError, deleteFetchNow = _c.deleteFetchNow, deleteLoading = _c.deleteLoading, listError = _c.listError, listFetchNow = _c.listFetchNow, listLoading = _c.listLoading, updateError = _c.updateError, updateFetchNow = _c.updateFetchNow, updateLoading = _c.updateLoading;
447
+ }), 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;
391
448
  // ---------------------------------------------------------------------------
392
449
  // Effects
393
450
  // ---------------------------------------------------------------------------
451
+ (0, react_1.useEffect)(function () {
452
+ (function () { return __awaiter(void 0, void 0, void 0, function () {
453
+ var _a, count, items, _b;
454
+ return __generator(this, function (_c) {
455
+ switch (_c.label) {
456
+ case 0:
457
+ _c.trys.push([0, 2, , 3]);
458
+ return [4 /*yield*/, (0, cache_1.getCachedQuotes)({
459
+ params: listParams,
460
+ })];
461
+ case 1:
462
+ _a = _c.sent(), count = _a.count, items = _a.items;
463
+ context.dispatch({
464
+ type: exports.QUOTE_ACTION_TYPES.SET_ITEMS,
465
+ payload: { items: items || [], count: count || 0 },
466
+ });
467
+ return [3 /*break*/, 3];
468
+ case 2:
469
+ _b = _c.sent();
470
+ showErrorToast(t("messagesNetworkError"));
471
+ return [3 /*break*/, 3];
472
+ case 3: return [2 /*return*/];
473
+ }
474
+ });
475
+ }); })();
476
+ }, [listParams]); // eslint-disable-line react-hooks/exhaustive-deps
394
477
  (0, react_1.useEffect)(function () {
395
478
  listFetchNow();
396
479
  // eslint-disable-next-line
@@ -412,19 +495,18 @@ var useQuoteState = function () {
412
495
  case 1:
413
496
  data = (_a.sent()).data;
414
497
  if (data === null || data === void 0 ? void 0 : data.items) {
415
- dispatch({
416
- type: actions_1.QUOTE_ACTION_TYPES.SET_PRODUCTS_LIST,
417
- payload: { list: data.items },
498
+ context.dispatch({
499
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
500
+ payload: { key: "getProducts", value: data.items },
418
501
  });
419
502
  }
420
503
  return [2 /*return*/];
421
504
  }
422
505
  });
423
506
  }); })();
424
- }, [debouncedProductList]);
507
+ }, [debouncedProductList]); // eslint-disable-line react-hooks/exhaustive-deps
425
508
  (0, react_1.useEffect)(function () {
426
- if (state.drawer === types_1.QUOTE_DRAWER.QUOTE_CUSTOMER_FORM_DRAWER &&
427
- debouncedCustomer) {
509
+ if (state.quoteMode === "INVOICE_MODE.CUSTOMER" && debouncedCustomer) {
428
510
  (function () { return __awaiter(void 0, void 0, void 0, function () {
429
511
  var data;
430
512
  return __generator(this, function (_a) {
@@ -439,9 +521,16 @@ var useQuoteState = function () {
439
521
  case 1:
440
522
  data = (_a.sent()).data;
441
523
  if (data) {
442
- dispatch({
443
- type: actions_1.QUOTE_ACTION_TYPES.SET_CUSTOMER,
444
- payload: { customer: __assign({}, data), customerId: data.id },
524
+ context.dispatch({
525
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
526
+ payload: {
527
+ key: "customer",
528
+ value: __assign(__assign({}, state.customer), data),
529
+ },
530
+ });
531
+ context.dispatch({
532
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
533
+ payload: { key: "customerId", value: data.id },
445
534
  });
446
535
  }
447
536
  return [2 /*return*/];
@@ -449,10 +538,9 @@ var useQuoteState = function () {
449
538
  });
450
539
  }); })();
451
540
  }
452
- }, [debouncedCustomer, state.drawer]);
541
+ }, [debouncedCustomer, state.drawer]); // eslint-disable-line react-hooks/exhaustive-deps
453
542
  (0, react_1.useEffect)(function () {
454
- if (state.drawer === types_1.QUOTE_DRAWER.QUOTE_COMPANY_FORM_DRAWER &&
455
- debouncedCompanyList) {
543
+ if (state.quoteMode === "INVOICE_MODE.COMPANY" && debouncedCompanyList) {
456
544
  (function () { return __awaiter(void 0, void 0, void 0, function () {
457
545
  var data;
458
546
  return __generator(this, function (_a) {
@@ -469,9 +557,9 @@ var useQuoteState = function () {
469
557
  case 1:
470
558
  data = (_a.sent()).data;
471
559
  if (data === null || data === void 0 ? void 0 : data.items) {
472
- dispatch({
473
- type: actions_1.QUOTE_ACTION_TYPES.SET_COMPANIES_LIST,
474
- payload: { companiesList: data.items },
560
+ context.dispatch({
561
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
562
+ payload: { key: "companiesList", value: data.items },
475
563
  });
476
564
  }
477
565
  return [2 /*return*/];
@@ -479,7 +567,7 @@ var useQuoteState = function () {
479
567
  });
480
568
  }); })();
481
569
  }
482
- }, [debouncedCompanyList, state.drawer]);
570
+ }, [debouncedCompanyList, state.drawer]); // eslint-disable-line react-hooks/exhaustive-deps
483
571
  (0, react_1.useEffect)(function () {
484
572
  (function () { return __awaiter(void 0, void 0, void 0, function () {
485
573
  var data;
@@ -499,9 +587,9 @@ var useQuoteState = function () {
499
587
  case 1:
500
588
  data = (_a.sent()).data;
501
589
  if (data.items) {
502
- dispatch({
503
- type: actions_1.QUOTE_ACTION_TYPES.SET_TAXES,
504
- payload: { taxes: data.items },
590
+ context.dispatch({
591
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
592
+ payload: { key: "taxes", value: data.items },
505
593
  });
506
594
  }
507
595
  _a.label = 2;
@@ -509,25 +597,22 @@ var useQuoteState = function () {
509
597
  }
510
598
  });
511
599
  }); })();
512
- }, [debouncedTaxList]);
600
+ }, [debouncedTaxList]); // eslint-disable-line react-hooks/exhaustive-deps
513
601
  (0, react_1.useEffect)(function () {
514
602
  var _a = (0, calculate_total_1.calculateTotal)(state.subTotal, state.taxRate, state.discountUnit, state.discount || "0"), afterDiscount = _a.afterDiscount, tax = _a.tax, total = _a.total;
515
- dispatch({
516
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
517
- payload: {
518
- key: "total",
519
- value: total,
520
- },
603
+ context.dispatch({
604
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
605
+ payload: { key: "total", value: total },
521
606
  });
522
- dispatch({
523
- type: actions_1.QUOTE_ACTION_TYPES.SET_TAX,
524
- payload: { tax: tax },
607
+ context.dispatch({
608
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
609
+ payload: { key: "tax", value: tax },
525
610
  });
526
- dispatch({
527
- type: actions_1.QUOTE_ACTION_TYPES.SET_AFTER_DISCOUNT,
528
- payload: { afterDiscount: String(afterDiscount) },
611
+ context.dispatch({
612
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
613
+ payload: { key: "afterDiscount", value: String(afterDiscount) },
529
614
  });
530
- }, [state.discountUnit, state.discount, state.subTotal, state.taxRate]);
615
+ }, [state.discountUnit, state.discount, state.subTotal, state.taxRate]); // eslint-disable-line react-hooks/exhaustive-deps
531
616
  // ---------------------------------------------------------------------------
532
617
  // Item Management Handlers
533
618
  // ---------------------------------------------------------------------------
@@ -540,11 +625,11 @@ var useQuoteState = function () {
540
625
  price: "",
541
626
  rowTotal: "",
542
627
  };
543
- dispatch({
544
- type: actions_1.QUOTE_ACTION_TYPES.ADD_ITEM_SERVICE,
545
- payload: { servicesList: __spreadArray(__spreadArray([], state.servicesList, true), [newItem], false) },
628
+ context.dispatch({
629
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
630
+ payload: { key: "servicesList", value: __spreadArray(__spreadArray([], state.servicesList, true), [newItem], false) },
546
631
  });
547
- }, [state.servicesList]);
632
+ }, [context, state.servicesList]);
548
633
  var handleAddItemProduct = (0, react_1.useCallback)(function () {
549
634
  var newItem = {
550
635
  id: "",
@@ -553,17 +638,17 @@ var useQuoteState = function () {
553
638
  quantity: "1",
554
639
  rowTotal: "",
555
640
  };
556
- dispatch({
557
- type: actions_1.QUOTE_ACTION_TYPES.ADD_ITEM_PRODUCT,
558
- payload: { productsList: __spreadArray(__spreadArray([], state.productsList, true), [newItem], false) },
641
+ context.dispatch({
642
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
643
+ payload: { key: "productsList", value: __spreadArray(__spreadArray([], state.productsList, true), [newItem], false) },
559
644
  });
560
- }, [state.productsList]);
645
+ }, [context, state.productsList]);
561
646
  // ---------------------------------------------------------------------------
562
647
  // Drawer & Modal Handlers
563
648
  // ---------------------------------------------------------------------------
564
649
  var handleCreate = (0, react_1.useCallback)(function (text) {
565
- dispatch({
566
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
650
+ context.dispatch({
651
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
567
652
  payload: {
568
653
  key: "ref",
569
654
  value: (0, util_functions_1.generateRef)({
@@ -571,25 +656,41 @@ var useQuoteState = function () {
571
656
  }),
572
657
  },
573
658
  });
574
- if (text === "company") {
575
- dispatch({
576
- type: actions_1.QUOTE_ACTION_TYPES.SET_DRAWER,
577
- payload: { drawer: types_1.QUOTE_DRAWER.QUOTE_COMPANY_FORM_DRAWER },
578
- });
579
- }
580
- if (text === "customer") {
581
- dispatch({
582
- type: actions_1.QUOTE_ACTION_TYPES.SET_DRAWER,
583
- payload: { drawer: types_1.QUOTE_DRAWER.QUOTE_CUSTOMER_FORM_DRAWER },
584
- });
585
- }
586
- }, []);
659
+ context.dispatch({
660
+ type: exports.QUOTE_ACTION_TYPES.SET_DRAWER,
661
+ payload: { drawer: generic_component_factory_1.DRAWER_TYPES.FORM_DRAWER },
662
+ });
663
+ context.dispatch({
664
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
665
+ payload: {
666
+ key: "quoteMode",
667
+ value: text === "company"
668
+ ? "INVOICE_MODE.COMPANY"
669
+ : "INVOICE_MODE.CUSTOMER",
670
+ },
671
+ });
672
+ }, [context]);
587
673
  // ---------------------------------------------------------------------------
588
674
  // CRUD Operation Handlers
589
675
  // ---------------------------------------------------------------------------
590
- var handleEdit = (0, react_1.useCallback)(function (id) {
676
+ var handleEdit = (0, react_1.useCallback)(function (row) {
677
+ var record = row;
678
+ byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, {
679
+ params: { id: record === null || record === void 0 ? void 0 : record.id },
680
+ body: JSON.stringify({
681
+ includeCompany: true,
682
+ includeCustomer: true,
683
+ includePayments: true,
684
+ includeProducts: true,
685
+ includeServices: true,
686
+ }),
687
+ });
688
+ // eslint-disable-next-line react-hooks/exhaustive-deps
689
+ }, []);
690
+ var handleView = (0, react_1.useCallback)(function (row) {
691
+ var record = row;
591
692
  byIdFetchNow === null || byIdFetchNow === void 0 ? void 0 : byIdFetchNow(undefined, {
592
- params: { id: id },
693
+ params: { id: record === null || record === void 0 ? void 0 : record.id },
593
694
  body: JSON.stringify({
594
695
  includeCompany: true,
595
696
  includeCustomer: true,
@@ -600,8 +701,9 @@ var useQuoteState = function () {
600
701
  });
601
702
  // eslint-disable-next-line react-hooks/exhaustive-deps
602
703
  }, []);
603
- var handleDelete = (0, react_1.useCallback)(function (id) {
604
- deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, { params: { id: id } });
704
+ var handleDelete = (0, react_1.useCallback)(function (row) {
705
+ var record = row;
706
+ deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, { params: { id: record === null || record === void 0 ? void 0 : record.id } });
605
707
  // eslint-disable-next-line react-hooks/exhaustive-deps
606
708
  }, []);
607
709
  // ---------------------------------------------------------------------------
@@ -609,18 +711,18 @@ var useQuoteState = function () {
609
711
  // ---------------------------------------------------------------------------
610
712
  var handleSubmit = (0, react_1.useCallback)(function () {
611
713
  if (!state.servicesList[0].name && !state.productsList[0].id) {
612
- dispatch({
613
- type: actions_1.QUOTE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
714
+ context.dispatch({
715
+ type: exports.QUOTE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
614
716
  payload: { disableSaveButton: true },
615
717
  });
616
718
  return;
617
719
  }
618
- dispatch({
619
- type: actions_1.QUOTE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
720
+ context.dispatch({
721
+ type: exports.QUOTE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
620
722
  payload: { disableSaveButton: true },
621
723
  });
622
724
  (0, util_functions_1.validateForm)({
623
- params: __assign(__assign({}, updateParams), { currency: updateParams.currency || defaultCurrency.id, taxRate: updateParams.taxRate || defaultTax.taxRate }),
725
+ params: __assign(__assign({}, updateParams), { quoteMode: state.quoteMode, currency: updateParams.currency || defaultCurrency.id, taxRate: updateParams.taxRate || defaultTax.taxRate }),
624
726
  schema: validate_1.formValid,
625
727
  successCallback: function () {
626
728
  updateFetchNow(undefined, {
@@ -628,13 +730,15 @@ var useQuoteState = function () {
628
730
  });
629
731
  },
630
732
  errorCallback: function (e) {
631
- dispatch({
632
- type: actions_1.QUOTE_ACTION_TYPES.SET_ERRORS,
733
+ context.dispatch({
734
+ type: exports.QUOTE_ACTION_TYPES.SET_ERRORS,
633
735
  payload: { errors: e },
634
736
  });
635
737
  },
636
738
  });
739
+ // eslint-disable-next-line react-hooks/exhaustive-deps
637
740
  }, [
741
+ context,
638
742
  updateFetchNow,
639
743
  updateParams,
640
744
  defaultCurrency,
@@ -647,44 +751,44 @@ var useQuoteState = function () {
647
751
  // ---------------------------------------------------------------------------
648
752
  var handleChange = (0, react_1.useCallback)(function (key, value) {
649
753
  if (key === "companyQuery") {
650
- dispatch({
651
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
754
+ context.dispatch({
755
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
652
756
  payload: { key: key, value: value },
653
757
  });
654
758
  return;
655
759
  }
656
760
  if (key === "taxRate") {
657
- dispatch({
658
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
761
+ context.dispatch({
762
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
659
763
  payload: { key: key, value: Number(value) },
660
764
  });
661
765
  return;
662
766
  }
663
767
  if (key === "discountUnit") {
664
- dispatch({
665
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
768
+ context.dispatch({
769
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
666
770
  payload: { key: key, value: value },
667
771
  });
668
772
  return;
669
773
  }
670
- // Dispatch the input field change
671
- dispatch({
672
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
774
+ context.dispatch({
775
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
673
776
  payload: { key: key, value: value },
674
777
  });
675
- dispatch({
676
- type: actions_1.QUOTE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
778
+ context.dispatch({
779
+ type: exports.QUOTE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
677
780
  payload: { disableSaveButton: false },
678
781
  });
679
- dispatch({
680
- type: actions_1.QUOTE_ACTION_TYPES.RESET_ERRORS,
782
+ context.dispatch({
783
+ type: exports.QUOTE_ACTION_TYPES.SET_ERRORS,
784
+ payload: { errors: {} },
681
785
  });
682
- }, []);
786
+ }, [context]);
683
787
  var handleItemChangeServices = (0, react_1.useCallback)(function (_a) {
684
788
  var _b;
685
789
  var index = _a.index, key = _a.key, value = _a.value;
686
- dispatch({
687
- type: actions_1.QUOTE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
790
+ context.dispatch({
791
+ type: exports.QUOTE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
688
792
  payload: { disableSaveButton: false },
689
793
  });
690
794
  var updatedItems = __spreadArray([], state.servicesList, true);
@@ -695,21 +799,21 @@ var useQuoteState = function () {
695
799
  updatedItems[index].rowTotal = rowTotal;
696
800
  var allProducts = state.productsList;
697
801
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(updatedItems, allProducts);
698
- dispatch({
699
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
802
+ context.dispatch({
803
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
700
804
  payload: { key: "subTotal", value: subtotal },
701
805
  });
702
- dispatch({
703
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
806
+ context.dispatch({
807
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
704
808
  payload: { key: "servicesList", value: updatedItems },
705
809
  });
706
- }, [state.productsList, state.servicesList]);
810
+ }, [context, state.productsList, state.servicesList]);
707
811
  var handleItemChangeProducts = (0, react_1.useCallback)(function (_a) {
708
812
  var _b, _c, _d;
709
813
  var _e;
710
814
  var index = _a.index, key = _a.key, value = _a.value;
711
- dispatch({
712
- type: actions_1.QUOTE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
815
+ context.dispatch({
816
+ type: exports.QUOTE_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
713
817
  payload: { disableSaveButton: false },
714
818
  });
715
819
  var updatedItems = __spreadArray([], state.productsList, true);
@@ -717,12 +821,13 @@ var useQuoteState = function () {
717
821
  var matchingProduct = (_e = state.getProducts) === null || _e === void 0 ? void 0 : _e.find(function (product) { return product.id === value; });
718
822
  if (matchingProduct) {
719
823
  var quantity = parseFloat(String(updatedItems[index].quantity)) || 0;
720
- var rowTotal = (quantity * parseFloat(matchingProduct.salePrice)).toFixed(2);
721
- updatedItems[index] = __assign(__assign({}, updatedItems[index]), (_b = {}, _b[key] = value, _b.price = matchingProduct.salePrice, _b.mode = updatedItems[index].mode === "Create" ? "Create" : "Edit", _b.rowTotal = rowTotal, _b));
824
+ var rowTotal = (quantity *
825
+ parseFloat(String(matchingProduct.price))).toFixed(2);
826
+ updatedItems[index] = __assign(__assign({}, updatedItems[index]), (_b = {}, _b[key] = value, _b.price = String(matchingProduct.price), _b.mode = updatedItems[index].mode === "Create" ? "Create" : "Edit", _b.rowTotal = rowTotal, _b));
722
827
  var allServices = state.servicesList;
723
828
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(allServices, updatedItems);
724
- dispatch({
725
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
829
+ context.dispatch({
830
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
726
831
  payload: { key: "subTotal", value: subtotal },
727
832
  });
728
833
  }
@@ -738,98 +843,106 @@ var useQuoteState = function () {
738
843
  updatedItems[index] = __assign(__assign({}, updatedItems[index]), { rowTotal: rowTotal });
739
844
  var allServices = state.servicesList;
740
845
  var subtotal = (0, calculate_subtotal_1.calculateSubtotal)(allServices, updatedItems);
741
- dispatch({
742
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
846
+ context.dispatch({
847
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
743
848
  payload: { key: "subTotal", value: subtotal },
744
849
  });
745
850
  }
746
- dispatch({
747
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
851
+ context.dispatch({
852
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
748
853
  payload: { key: "productsList", value: updatedItems },
749
854
  });
750
- }, [state.servicesList, state.productsList, state.getProducts]);
855
+ }, [context, state.servicesList, state.productsList, state.getProducts]);
751
856
  // ---------------------------------------------------------------------------
752
- // PAGINATION HANDLERS
857
+ // Pagination Handlers
753
858
  // ---------------------------------------------------------------------------
754
859
  var handleNextClick = (0, react_1.useCallback)(function () {
755
- dispatch({
756
- type: actions_1.QUOTE_ACTION_TYPES.SET_CURRENT_PAGE,
860
+ context.dispatch({
861
+ type: exports.QUOTE_ACTION_TYPES.SET_CURRENT_PAGE,
757
862
  payload: { currentPage: state.currentPage + 1 },
758
863
  });
759
- }, [state.currentPage]);
864
+ }, [context, state.currentPage]);
760
865
  var handlePreviousClick = (0, react_1.useCallback)(function () {
761
- dispatch({
762
- type: actions_1.QUOTE_ACTION_TYPES.SET_CURRENT_PAGE,
866
+ context.dispatch({
867
+ type: exports.QUOTE_ACTION_TYPES.SET_CURRENT_PAGE,
763
868
  payload: { currentPage: state.currentPage - 1 },
764
869
  });
765
- }, [state.currentPage]);
870
+ }, [context, state.currentPage]);
766
871
  var handlePageLimit = (0, react_1.useCallback)(function (k, value) {
767
872
  var val = __assign({}, value);
768
- dispatch({
769
- type: actions_1.QUOTE_ACTION_TYPES.SET_PAGE_LIMIT,
873
+ context.dispatch({
874
+ type: exports.QUOTE_ACTION_TYPES.SET_PAGE_LIMIT,
770
875
  payload: { pageLimit: Number(val.option) },
771
876
  });
772
- // Reset to page 1 when page limit changes
773
- dispatch({
774
- type: actions_1.QUOTE_ACTION_TYPES.SET_CURRENT_PAGE,
877
+ context.dispatch({
878
+ type: exports.QUOTE_ACTION_TYPES.SET_CURRENT_PAGE,
775
879
  payload: { currentPage: 1 },
776
880
  });
777
- }, []);
881
+ }, [context]);
778
882
  var searchOnChange = (0, react_1.useCallback)(function (k, v) {
779
- dispatch({
780
- type: actions_1.QUOTE_ACTION_TYPES.SET_SEARCH_QUERY,
883
+ context.dispatch({
884
+ type: exports.QUOTE_ACTION_TYPES.SET_SEARCH_QUERY,
781
885
  payload: { searchQuery: v },
782
886
  });
783
- }, []);
887
+ }, [context]);
784
888
  var clearSearch = (0, react_1.useCallback)(function () {
785
- dispatch({
786
- type: actions_1.QUOTE_ACTION_TYPES.SET_SEARCH_QUERY,
889
+ context.dispatch({
890
+ type: exports.QUOTE_ACTION_TYPES.SET_SEARCH_QUERY,
787
891
  payload: { searchQuery: "" },
788
892
  });
789
- }, []);
893
+ }, [context]);
790
894
  // ---------------------------------------------------------------------------
791
- // SEARCH HANDLERS
895
+ // Search Handlers
792
896
  // ---------------------------------------------------------------------------
793
897
  var handleTaxSearch = (0, react_1.useCallback)(function (searchQuery) {
794
- dispatch({
795
- type: actions_1.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
898
+ context.dispatch({
899
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
796
900
  payload: { key: "taxQuery", value: searchQuery },
797
901
  });
798
- }, []);
902
+ }, [context]);
799
903
  // ---------------------------------------------------------------------------
800
- // DRAWER & MODAL HANDLERS
904
+ // Drawer & Modal Handlers
801
905
  // ---------------------------------------------------------------------------
802
906
  var closeDrawer = (0, react_1.useCallback)(function () {
803
- dispatch({
804
- type: actions_1.QUOTE_ACTION_TYPES.SET_DRAWER,
907
+ context.dispatch({
908
+ type: exports.QUOTE_ACTION_TYPES.SET_DRAWER,
805
909
  payload: { drawer: null },
806
910
  });
807
- dispatch({ type: actions_1.QUOTE_ACTION_TYPES.RESET_FORM });
808
- dispatch({ type: actions_1.QUOTE_ACTION_TYPES.RESET_ERRORS });
809
- }, []);
911
+ context.dispatch({
912
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
913
+ payload: { key: "quoteMode", value: null },
914
+ });
915
+ context.dispatch({ type: exports.QUOTE_ACTION_TYPES.RESET_FORM });
916
+ context.dispatch({
917
+ type: exports.QUOTE_ACTION_TYPES.SET_ERRORS,
918
+ payload: { errors: {} },
919
+ });
920
+ }, [context]);
810
921
  // ---------------------------------------------------------------------------
811
- // FORM HANDLERS
922
+ // Form Row Handlers
812
923
  // ---------------------------------------------------------------------------
813
924
  var handleDeleteServiceRow = (0, react_1.useCallback)(function (i) {
814
925
  if (state.servicesList.length > 1) {
815
- var res = state.servicesList.splice(i, 1);
816
- dispatch({
817
- type: actions_1.QUOTE_ACTION_TYPES.DELETE_ITEM_SERVICE,
818
- payload: { servicesList: __spreadArray([], res, true) },
926
+ var updatedList = __spreadArray([], state.servicesList, true);
927
+ updatedList.splice(i, 1);
928
+ context.dispatch({
929
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
930
+ payload: { key: "servicesList", value: updatedList },
819
931
  });
820
932
  }
821
- }, [state.servicesList]);
933
+ }, [context, state.servicesList]);
822
934
  var handleDeleteProductRow = (0, react_1.useCallback)(function (i) {
823
935
  if (state.productsList.length > 1) {
824
- var res = state.productsList.splice(i, 1);
825
- dispatch({
826
- type: actions_1.QUOTE_ACTION_TYPES.DELETE_ITEM_PRODUCT,
827
- payload: { productsList: __spreadArray([], res, true) },
936
+ var updatedList = __spreadArray([], state.productsList, true);
937
+ updatedList.splice(i, 1);
938
+ context.dispatch({
939
+ type: exports.QUOTE_ACTION_TYPES.SET_INPUT_FIELD,
940
+ payload: { key: "productsList", value: updatedList },
828
941
  });
829
942
  }
830
- }, [state.productsList]);
943
+ }, [context, state.productsList]);
831
944
  // ---------------------------------------------------------------------------
832
- // TABLE ACTIONS
945
+ // Table Actions
833
946
  // ---------------------------------------------------------------------------
834
947
  var headerActions = (0, react_1.useMemo)(function () { return [
835
948
  {
@@ -846,36 +959,47 @@ var useQuoteState = function () {
846
959
  },
847
960
  ]; }, [t, handleCreate]);
848
961
  var rowActions = (0, react_1.useMemo)(function () { return [
962
+ {
963
+ enabled: true,
964
+ handleAction: function (id) { return handleView(id); },
965
+ label: t("actionsButtonView"),
966
+ order: 1,
967
+ },
849
968
  {
850
969
  enabled: true,
851
970
  handleAction: function (id) { return handleEdit(id); },
852
971
  label: t("actionsButtonEdit"),
853
- order: 1,
972
+ order: 2,
854
973
  },
855
974
  {
856
975
  enabled: true,
857
976
  handleAction: function (id) { return handleDelete(id); },
858
977
  label: t("actionsButtonDelete"),
859
- order: 2,
978
+ order: 3,
860
979
  },
861
- ]; }, [t, handleEdit, handleDelete]);
980
+ ]; }, [t, handleEdit, handleDelete, handleView]);
862
981
  // ---------------------------------------------------------------------------
863
- // RETURN STATE
982
+ // Return State (flat, backward-compatible + factory-compatible)
864
983
  // ---------------------------------------------------------------------------
865
- return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, handleAddItemProduct: handleAddItemProduct, handleAddItemService: handleAddItemService, handleChange: handleChange, handleDeleteProductRow: handleDeleteProductRow, handleDeleteServiceRow: handleDeleteServiceRow, handleItemChangeProducts: handleItemChangeProducts, handleItemChangeServices: handleItemChangeServices, handleNextClick: handleNextClick, handlePageLimit: handlePageLimit, handlePreviousClick: handlePreviousClick, handleSubmit: handleSubmit, handleTaxSearch: handleTaxSearch, headerActions: headerActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, rowActions: rowActions, searchOnChange: searchOnChange, updateError: updateError, updateLoading: updateLoading });
866
- };
867
- exports.QuoteStateContext = (0, react_1.createContext)(__assign(__assign({}, reducer_1.initialQuoteState), { byIdError: undefined, byIdLoading: false, clearSearch: function () { return void 0; }, closeDrawer: function () { return void 0; }, deleteError: undefined, deleteLoading: false, dispatch: function () { return void 0; }, handleAddItemProduct: function () { return void 0; }, handleAddItemService: function () { return void 0; }, handleChange: function () { return void 0; }, handleDeleteProductRow: function () { return void 0; }, handleDeleteServiceRow: function () { return void 0; }, handleItemChangeProducts: function () { return void 0; }, handleItemChangeServices: function () { return void 0; }, handleNextClick: function () { return void 0; }, handlePageLimit: function () { return void 0; }, handlePreviousClick: function () { return void 0; }, handleSubmit: function () { return void 0; }, handleTaxSearch: function () { return void 0; }, headerActions: [], listError: undefined, listFetchNow: function () { return void 0; }, listLoading: false, rowActions: [], searchOnChange: function () { return void 0; }, updateError: undefined, updateLoading: false }));
868
- var QuoteStateContextProvider = function (_a) {
869
- var children = _a.children;
870
- var state = useQuoteState();
871
- return (react_1.default.createElement(exports.QuoteStateContext.Provider, { value: state }, children));
872
- };
873
- exports.QuoteStateContextProvider = QuoteStateContextProvider;
874
- var useQuoteStateContext = function () {
875
- var state = (0, react_1.useContext)(exports.QuoteStateContext);
876
- if (state === undefined) {
877
- throw new Error("useQuoteStateContext must be used within a QuoteContextProvider");
878
- }
879
- return state;
984
+ return __assign(__assign(__assign({}, context), state), { quotes: state.items, byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: context.dispatch, handleAddItemProduct: handleAddItemProduct, handleAddItemService: handleAddItemService, handleChange: handleChange, handleCloseDrawer: closeDrawer, handleCreate: handleCreate, handleDelete: handleDelete, handleDeleteProductRow: handleDeleteProductRow, handleDeleteServiceRow: handleDeleteServiceRow, handleEdit: handleEdit, handleItemChangeProducts: handleItemChangeProducts, handleItemChangeServices: handleItemChangeServices, handleNextClick: handleNextClick, handlePageChange: function (page) {
985
+ context.dispatch({
986
+ type: exports.QUOTE_ACTION_TYPES.SET_CURRENT_PAGE,
987
+ payload: { currentPage: page },
988
+ });
989
+ }, handlePageLimit: handlePageLimit, handlePageLimitChange: function (limit) {
990
+ context.dispatch({
991
+ type: exports.QUOTE_ACTION_TYPES.SET_PAGE_LIMIT,
992
+ payload: { pageLimit: limit },
993
+ });
994
+ context.dispatch({
995
+ type: exports.QUOTE_ACTION_TYPES.SET_CURRENT_PAGE,
996
+ payload: { currentPage: 1 },
997
+ });
998
+ }, handlePreviousClick: handlePreviousClick, handleSearch: function (query) {
999
+ context.dispatch({
1000
+ type: exports.QUOTE_ACTION_TYPES.SET_SEARCH_QUERY,
1001
+ payload: { searchQuery: query },
1002
+ });
1003
+ }, handleSubmit: handleSubmit, handleTaxSearch: handleTaxSearch, handleView: handleView, headerActions: headerActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, rowActions: rowActions, searchOnChange: searchOnChange, updateError: updateError, updateLoading: updateLoading });
880
1004
  };
881
- exports.useQuoteStateContext = useQuoteStateContext;
1005
+ exports.useQuoteModule = useQuoteModule;