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

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.
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Payment State Reducer
3
+ *
4
+ * This module manages the state transitions for the Payment feature using the reducer pattern.
5
+ * Handles all state updates in a predictable and optimized manner.
6
+ *
7
+ * Features:
8
+ * - Form state management (create/edit payment data)
9
+ * - UI state management (drawers, modals, loading states)
10
+ * - Search and pagination state
11
+ * - Error handling state
12
+ *
13
+ * Performance Optimizations:
14
+ * - Grouped related actions for better readability and maintainability
15
+ * - Helper functions for common operations (form reset, array updates, error merging)
16
+ * - Optimized object spreading patterns with shallow copies
17
+ * - Immutable state updates to prevent reference issues
18
+ * - Clear action-to-state mapping with logical grouping
19
+ */
20
+ import { PaymentActions } from "./actions";
21
+ import { PaymentState } from "./types";
22
+ export declare const initialPaymentState: PaymentState;
23
+ /**
24
+ * Payment Reducer
25
+ *
26
+ * Handles all state transitions for the payment module.
27
+ * Maps actions to state updates in a predictable and optimized manner.
28
+ */
29
+ export declare function paymentReducer(state: PaymentState, action: PaymentActions): PaymentState;
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ /**
3
+ * Payment State Reducer
4
+ *
5
+ * This module manages the state transitions for the Payment feature using the reducer pattern.
6
+ * Handles all state updates in a predictable and optimized manner.
7
+ *
8
+ * Features:
9
+ * - Form state management (create/edit payment data)
10
+ * - UI state management (drawers, modals, loading states)
11
+ * - Search and pagination state
12
+ * - Error handling state
13
+ *
14
+ * Performance Optimizations:
15
+ * - Grouped related actions for better readability and maintainability
16
+ * - Helper functions for common operations (form reset, array updates, error merging)
17
+ * - Optimized object spreading patterns with shallow copies
18
+ * - Immutable state updates to prevent reference issues
19
+ * - Clear action-to-state mapping with logical grouping
20
+ */
21
+ var __assign = (this && this.__assign) || function () {
22
+ __assign = Object.assign || function(t) {
23
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
24
+ s = arguments[i];
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
26
+ t[p] = s[p];
27
+ }
28
+ return t;
29
+ };
30
+ return __assign.apply(this, arguments);
31
+ };
32
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
33
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
34
+ if (ar || !(i in from)) {
35
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
36
+ ar[i] = from[i];
37
+ }
38
+ }
39
+ return to.concat(ar || Array.prototype.slice.call(from));
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.initialPaymentState = void 0;
43
+ exports.paymentReducer = paymentReducer;
44
+ var actions_1 = require("./actions");
45
+ var types_1 = require("./types");
46
+ var pageLimit = Number(process.env.NEXT_PUBLIC_PAGE_LIMIT) || 10;
47
+ // ============================================================================
48
+ // HELPER FUNCTIONS
49
+ // ============================================================================
50
+ /**
51
+ * Helper function to reset form fields to their initial values
52
+ */
53
+ var getFormResetState = function () { return ({
54
+ amount: "",
55
+ attachment: "",
56
+ balance: "",
57
+ currency: "",
58
+ date: new Date().toISOString(),
59
+ description: "",
60
+ disableSaveButton: false,
61
+ errors: {},
62
+ id: "",
63
+ mode: "Create",
64
+ paymentModeId: "",
65
+ paymentType: types_1.PAYMENT_TYPE.FULL_AMOUNT,
66
+ quoteInvoiceId: "",
67
+ ref: "",
68
+ }); };
69
+ /**
70
+ * Helper function to safely update array state with immutability
71
+ */
72
+ var updateArrayState = function (array) { return __spreadArray([], array, true); };
73
+ /**
74
+ * Helper function to safely merge errors with existing state
75
+ */
76
+ var mergeErrors = function (errors) { return (__assign({}, errors)); };
77
+ // ============================================================================
78
+ // INITIAL STATE
79
+ // ============================================================================
80
+ exports.initialPaymentState = {
81
+ // Form data
82
+ amount: "",
83
+ attachment: "",
84
+ balance: "",
85
+ currency: "",
86
+ date: new Date().toISOString(),
87
+ description: "",
88
+ id: "",
89
+ mode: "Create",
90
+ paymentModeId: "",
91
+ paymentType: types_1.PAYMENT_TYPE.FULL_AMOUNT,
92
+ quoteInvoiceId: "",
93
+ ref: "",
94
+ // List data
95
+ count: 0,
96
+ paymentModes: [],
97
+ payments: [],
98
+ quoteInvoices: [],
99
+ // Search & Pagination
100
+ currentPage: 1,
101
+ pageLimit: pageLimit,
102
+ paymentModeQuery: "",
103
+ quoteInvoiceQuery: "",
104
+ searchQuery: "",
105
+ // UI state
106
+ disableSaveButton: true,
107
+ drawer: types_1.PAYMENT_DRAWER.PAYMENT_FORM_DRAWER,
108
+ // Errors
109
+ errors: {},
110
+ };
111
+ // ============================================================================
112
+ // REDUCER FUNCTION
113
+ // ============================================================================
114
+ /**
115
+ * Payment Reducer
116
+ *
117
+ * Handles all state transitions for the payment module.
118
+ * Maps actions to state updates in a predictable and optimized manner.
119
+ */
120
+ function paymentReducer(state, action) {
121
+ var _a;
122
+ switch (action.type) {
123
+ // ------------------------------------------------------------------------
124
+ // FORM RESET ACTIONS
125
+ // ------------------------------------------------------------------------
126
+ case actions_1.PAYMENT_ACTION_TYPES.RESET_ERRORS:
127
+ return __assign(__assign({}, state), { errors: {} });
128
+ case actions_1.PAYMENT_ACTION_TYPES.RESET_FORM:
129
+ return __assign(__assign(__assign({}, state), getFormResetState()), {
130
+ // Preserve lists when resetting form
131
+ paymentModes: state.paymentModes, payments: state.payments, quoteInvoices: state.quoteInvoices, count: state.count });
132
+ // ------------------------------------------------------------------------
133
+ // FORM INPUT ACTIONS
134
+ // ------------------------------------------------------------------------
135
+ case actions_1.PAYMENT_ACTION_TYPES.SET_INPUT_FIELD:
136
+ return __assign(__assign({}, state), (_a = {}, _a[action.payload.key] = action.payload.value, _a));
137
+ case actions_1.PAYMENT_ACTION_TYPES.SET_FORM:
138
+ return __assign(__assign(__assign({}, state), action.payload.form), { mode: "Edit" });
139
+ // ------------------------------------------------------------------------
140
+ // ERROR HANDLING ACTIONS
141
+ // ------------------------------------------------------------------------
142
+ case actions_1.PAYMENT_ACTION_TYPES.SET_ERRORS:
143
+ return __assign(__assign({}, state), { disableSaveButton: false, errors: mergeErrors(action.payload.errors) });
144
+ case actions_1.PAYMENT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON:
145
+ return __assign(__assign({}, state), { disableSaveButton: action.payload.disableSaveButton });
146
+ // ------------------------------------------------------------------------
147
+ // UI STATE ACTIONS
148
+ // ------------------------------------------------------------------------
149
+ case actions_1.PAYMENT_ACTION_TYPES.SET_DRAWER:
150
+ return __assign(__assign({}, state), { drawer: action.payload.drawer });
151
+ // ------------------------------------------------------------------------
152
+ // LIST DATA ACTIONS
153
+ // ------------------------------------------------------------------------
154
+ case actions_1.PAYMENT_ACTION_TYPES.SET_PAYMENTS:
155
+ return __assign(__assign({}, state), { payments: updateArrayState(action.payload.payments) });
156
+ case actions_1.PAYMENT_ACTION_TYPES.SET_PAYMENT_MODES:
157
+ return __assign(__assign({}, state), { paymentModes: updateArrayState(action.payload.paymentModes) });
158
+ case actions_1.PAYMENT_ACTION_TYPES.SET_QUOTE_INVOICES:
159
+ return __assign(__assign({}, state), { quoteInvoices: updateArrayState(action.payload.quoteInvoices) });
160
+ case actions_1.PAYMENT_ACTION_TYPES.SET_COUNT:
161
+ return __assign(__assign({}, state), { count: action.payload.count });
162
+ // ------------------------------------------------------------------------
163
+ // SEARCH ACTIONS
164
+ // ------------------------------------------------------------------------
165
+ case actions_1.PAYMENT_ACTION_TYPES.SET_PAYMENT_MODE_QUERY:
166
+ return __assign(__assign({}, state), { paymentModeQuery: action.payload.paymentModeQuery });
167
+ case actions_1.PAYMENT_ACTION_TYPES.SET_QUOTE_INVOICE_QUERY:
168
+ return __assign(__assign({}, state), { quoteInvoiceQuery: action.payload.quoteInvoiceQuery });
169
+ case actions_1.PAYMENT_ACTION_TYPES.SET_SEARCH_QUERY:
170
+ return __assign(__assign({}, state), { searchQuery: action.payload.searchQuery });
171
+ // ------------------------------------------------------------------------
172
+ // PAGINATION ACTIONS
173
+ // ------------------------------------------------------------------------
174
+ case actions_1.PAYMENT_ACTION_TYPES.SET_CURRENT_PAGE:
175
+ return __assign(__assign({}, state), { currentPage: action.payload.currentPage });
176
+ case actions_1.PAYMENT_ACTION_TYPES.SET_PAGE_LIMIT:
177
+ return __assign(__assign({}, state), { pageLimit: action.payload.pageLimit });
178
+ // ------------------------------------------------------------------------
179
+ // DEFAULT CASE
180
+ // ------------------------------------------------------------------------
181
+ default:
182
+ return state;
183
+ }
184
+ }
185
+ // ============================================================================
186
+ // OPTIMIZATION SUMMARY
187
+ // ============================================================================
188
+ /*
189
+ * Reducer Optimizations Applied:
190
+ *
191
+ * 1. Structural Organization
192
+ * - Grouped related actions into logical sections
193
+ * - Added comprehensive documentation and comments
194
+ * - Organized initial state by functionality
195
+ *
196
+ * 2. Performance Improvements
197
+ * - Helper functions for common operations (getFormResetState, updateArrayState, mergeErrors)
198
+ * - Immutable state updates using spread operator
199
+ * - Optimized object creation patterns
200
+ * - Consistent shallow copying for arrays
201
+ *
202
+ * 3. Code Quality
203
+ * - Clear section headers for better navigation
204
+ * - Consistent action handling patterns
205
+ * - Improved readability with logical grouping
206
+ *
207
+ * 4. Maintainability
208
+ * - Predictable state update patterns
209
+ * - Easy-to-locate action handlers
210
+ * - Self-documenting code structure
211
+ */
@@ -0,0 +1,82 @@
1
+ import { Dispatch } from "react";
2
+ import { PaymentModeTypeBE } from "@appcorp/stellar-solutions-modules/global-modules/payment-mode/types";
3
+ import { QuoteInvoiceTypeBE } from "../invoice/types";
4
+ import { PaymentActions } from "./actions";
5
+ import { HeaderAction, RowAction } from "@appcorp/shadcn/components/enhanced-table";
6
+ export declare enum PAYMENT_TYPE {
7
+ FULL_AMOUNT = "FULL_AMOUNT",
8
+ PARTIAL_AMOUNT = "PARTIAL_AMOUNT"
9
+ }
10
+ export declare enum PAYMENT_DRAWER {
11
+ PAYMENT_FORM_DRAWER = "PAYMENT_FORM_DRAWER"
12
+ }
13
+ export declare enum PAYMENT_MODAL {
14
+ DUMMY = "DUMMY"
15
+ }
16
+ /**
17
+ * Payment Backend Entity
18
+ */
19
+ export interface PaymentTypeBE {
20
+ amount: string;
21
+ attachment?: string;
22
+ balance: string;
23
+ createdAt: string;
24
+ currency: string;
25
+ date: string;
26
+ description?: string;
27
+ id: string;
28
+ paymentMode?: PaymentModeTypeBE;
29
+ paymentModeId: string;
30
+ paymentType: PAYMENT_TYPE;
31
+ quoteInvoice?: QuoteInvoiceTypeBE;
32
+ quoteInvoiceId: string;
33
+ ref?: string;
34
+ updatedAt: string;
35
+ }
36
+ export type { PaymentModeTypeBE };
37
+ export interface PaymentContextType {
38
+ byIdError?: Error;
39
+ byIdLoading: boolean;
40
+ clearSearch: () => void;
41
+ closeDrawer: () => void;
42
+ deleteError?: Error;
43
+ deleteLoading: boolean;
44
+ dispatch: Dispatch<PaymentActions>;
45
+ handleChange: (field: string, value: string | number | number[]) => void;
46
+ handleNextClick: () => void;
47
+ handlePageLimit: (node: string, value: object) => void;
48
+ handlePreviousClick: () => void;
49
+ handleSubmit: () => void;
50
+ headerActions: HeaderAction[];
51
+ listError?: Error;
52
+ listFetchNow: () => void;
53
+ listLoading: boolean;
54
+ rowActions: RowAction[];
55
+ searchOnChange: (k: string, v: string) => void;
56
+ updateError?: Error;
57
+ updateLoading: boolean;
58
+ }
59
+ export interface PaymentState extends Omit<PaymentTypeBE, "createdAt" | "updatedAt" | "paymentMode" | "quoteInvoice"> {
60
+ count: number;
61
+ currentPage: number;
62
+ disableSaveButton: boolean;
63
+ drawer: null | PAYMENT_DRAWER;
64
+ errors: {
65
+ [key: string]: string;
66
+ };
67
+ mode: "Create" | "Edit";
68
+ pageLimit: number;
69
+ paymentMode?: PaymentModeTypeBE;
70
+ paymentModeQuery: string;
71
+ paymentModes: PaymentModeTypeBE[];
72
+ payments: PaymentTypeBE[];
73
+ quoteInvoice?: QuoteInvoiceTypeBE;
74
+ quoteInvoiceQuery: string;
75
+ quoteInvoices: QuoteInvoiceTypeBE[];
76
+ searchQuery: string;
77
+ }
78
+ export interface FetchPaymentsArgs {
79
+ currentPage: number;
80
+ pageLimit: number;
81
+ searchQuery?: string;
82
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PAYMENT_MODAL = exports.PAYMENT_DRAWER = exports.PAYMENT_TYPE = void 0;
4
+ // ============================================================================
5
+ // ENUMS
6
+ // ============================================================================
7
+ var PAYMENT_TYPE;
8
+ (function (PAYMENT_TYPE) {
9
+ PAYMENT_TYPE["FULL_AMOUNT"] = "FULL_AMOUNT";
10
+ PAYMENT_TYPE["PARTIAL_AMOUNT"] = "PARTIAL_AMOUNT";
11
+ })(PAYMENT_TYPE || (exports.PAYMENT_TYPE = PAYMENT_TYPE = {}));
12
+ var PAYMENT_DRAWER;
13
+ (function (PAYMENT_DRAWER) {
14
+ PAYMENT_DRAWER["PAYMENT_FORM_DRAWER"] = "PAYMENT_FORM_DRAWER";
15
+ })(PAYMENT_DRAWER || (exports.PAYMENT_DRAWER = PAYMENT_DRAWER = {}));
16
+ var PAYMENT_MODAL;
17
+ (function (PAYMENT_MODAL) {
18
+ PAYMENT_MODAL["DUMMY"] = "DUMMY";
19
+ })(PAYMENT_MODAL || (exports.PAYMENT_MODAL = PAYMENT_MODAL = {}));
@@ -0,0 +1,20 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Validation schema for payment form
4
+ */
5
+ export declare const formValidation: z.ZodObject<{
6
+ amount: z.ZodString;
7
+ attachment: z.ZodOptional<z.ZodString>;
8
+ balance: z.ZodOptional<z.ZodString>;
9
+ currency: z.ZodString;
10
+ date: z.ZodString;
11
+ description: z.ZodOptional<z.ZodString>;
12
+ paymentModeId: z.ZodString;
13
+ paymentType: z.ZodString;
14
+ quoteInvoiceId: z.ZodString;
15
+ ref: z.ZodOptional<z.ZodString>;
16
+ }, z.core.$strip>;
17
+ /**
18
+ * Type definition for payment form validation
19
+ */
20
+ export type FormValidate = z.infer<typeof formValidation>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formValidation = void 0;
4
+ var zod_1 = require("zod");
5
+ var constants_1 = require("./constants");
6
+ // ============================================================================
7
+ // FORM VALIDATION SCHEMA
8
+ // ============================================================================
9
+ /**
10
+ * Validation schema for payment form
11
+ */
12
+ exports.formValidation = zod_1.z.object({
13
+ amount: zod_1.z.string().nonempty(constants_1.VALIDATION_KEYS.amount),
14
+ attachment: zod_1.z.string().optional(),
15
+ balance: zod_1.z.string().optional(),
16
+ currency: zod_1.z.string().nonempty(constants_1.VALIDATION_KEYS.currency),
17
+ date: zod_1.z.string().nonempty(constants_1.VALIDATION_KEYS.date),
18
+ description: zod_1.z.string().optional(),
19
+ paymentModeId: zod_1.z.string().nonempty(constants_1.VALIDATION_KEYS.paymentMode),
20
+ paymentType: zod_1.z.string().nonempty(constants_1.VALIDATION_KEYS.paymentType),
21
+ quoteInvoiceId: zod_1.z.string().nonempty(constants_1.VALIDATION_KEYS.quoteInvoice),
22
+ ref: zod_1.z.string().optional(),
23
+ });