@appcorp/stellar-solutions-modules 0.1.34 → 0.1.36
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/README.md +128 -19
- package/components/theme-provider.d.ts +9 -0
- package/components/theme-provider.js +122 -0
- package/components/theme-switcher.d.ts +4 -0
- package/components/theme-switcher.js +60 -0
- package/components/ui/badge.d.ts +9 -0
- package/components/ui/badge.js +82 -0
- package/components/ui/button.d.ts +10 -0
- package/components/ui/button.js +91 -0
- package/components/ui/card.d.ts +9 -0
- package/components/ui/card.js +94 -0
- package/components/ui/checkbox.d.ts +9 -0
- package/components/ui/checkbox.js +87 -0
- package/components/ui/combobox.d.ts +70 -0
- package/components/ui/combobox.js +315 -0
- package/components/ui/command.d.ts +18 -0
- package/components/ui/command.js +115 -0
- package/components/ui/dialog.d.ts +15 -0
- package/components/ui/dialog.js +118 -0
- package/components/ui/drawer.d.ts +13 -0
- package/components/ui/drawer.js +115 -0
- package/components/ui/dropdown-menu.d.ts +25 -0
- package/components/ui/dropdown-menu.js +148 -0
- package/components/ui/enhanced-table-footer-action.d.ts +34 -0
- package/components/ui/enhanced-table-footer-action.js +117 -0
- package/components/ui/enhanced-table-footer-page.d.ts +32 -0
- package/components/ui/enhanced-table-footer-page.js +140 -0
- package/components/ui/enhanced-table-footer-pagination.d.ts +36 -0
- package/components/ui/enhanced-table-footer-pagination.js +122 -0
- package/components/ui/enhanced-table-header-action.d.ts +7 -0
- package/components/ui/enhanced-table-header-action.js +21 -0
- package/components/ui/enhanced-table-header-search.d.ts +12 -0
- package/components/ui/enhanced-table-header-search.js +17 -0
- package/components/ui/enhanced-table.d.ts +65 -0
- package/components/ui/enhanced-table.js +87 -0
- package/components/ui/form.d.ts +24 -0
- package/components/ui/form.js +125 -0
- package/components/ui/input.d.ts +8 -0
- package/components/ui/input.js +86 -0
- package/components/ui/label.d.ts +7 -0
- package/components/ui/label.js +68 -0
- package/components/ui/popover.d.ts +7 -0
- package/components/ui/popover.js +82 -0
- package/components/ui/select.d.ts +15 -0
- package/components/ui/select.js +127 -0
- package/components/ui/separator.d.ts +4 -0
- package/components/ui/separator.js +66 -0
- package/components/ui/sonner.d.ts +4 -0
- package/components/ui/sonner.js +54 -0
- package/components/ui/switch.d.ts +9 -0
- package/components/ui/switch.js +89 -0
- package/components/ui/table.d.ts +10 -0
- package/components/ui/table.js +101 -0
- package/components/ui/textarea.d.ts +8 -0
- package/components/ui/textarea.js +86 -0
- package/global-modules/bank/actions.d.ts +200 -0
- package/global-modules/bank/actions.js +124 -0
- package/global-modules/bank/bank.d.ts +2 -0
- package/global-modules/bank/bank.js +87 -0
- package/global-modules/bank/constants.d.ts +45 -0
- package/global-modules/bank/constants.js +98 -0
- package/global-modules/bank/context.d.ts +41 -0
- package/global-modules/bank/context.js +419 -0
- package/global-modules/bank/drawer.d.ts +31 -0
- package/global-modules/bank/drawer.js +114 -0
- package/global-modules/bank/form.d.ts +22 -0
- package/global-modules/bank/form.js +68 -0
- package/global-modules/bank/reducer.d.ts +25 -0
- package/global-modules/bank/reducer.js +161 -0
- package/global-modules/bank/types.d.ts +217 -0
- package/global-modules/bank/types.js +81 -0
- package/global-modules/bank/validate.d.ts +13 -0
- package/global-modules/bank/validate.js +22 -0
- package/global-modules/branch/actions.d.ts +154 -37
- package/global-modules/branch/actions.js +148 -6
- package/global-modules/branch/branch.d.ts +2 -2
- package/global-modules/branch/branch.js +46 -32
- package/global-modules/branch/constants.d.ts +34 -24
- package/global-modules/branch/constants.js +101 -122
- package/global-modules/branch/context.d.ts +33 -2
- package/global-modules/branch/context.js +195 -164
- package/global-modules/branch/drawer.d.ts +26 -3
- package/global-modules/branch/drawer.js +101 -6
- package/global-modules/branch/form.d.ts +15 -1
- package/global-modules/branch/form.js +54 -71
- package/global-modules/branch/reducer.d.ts +23 -2
- package/global-modules/branch/reducer.js +148 -118
- package/global-modules/branch/types.d.ts +196 -69
- package/global-modules/branch/types.js +66 -7
- package/global-modules/branch/validate.d.ts +1 -1
- package/global-modules/branch/validate.js +15 -11
- package/global-modules/payment-mode/actions.d.ts +154 -37
- package/global-modules/payment-mode/actions.js +148 -6
- package/global-modules/payment-mode/constants.d.ts +34 -17
- package/global-modules/payment-mode/constants.js +90 -66
- package/global-modules/payment-mode/context.d.ts +33 -2
- package/global-modules/payment-mode/context.js +185 -163
- package/global-modules/payment-mode/drawer.d.ts +26 -3
- package/global-modules/payment-mode/drawer.js +104 -9
- package/global-modules/payment-mode/form.d.ts +16 -2
- package/global-modules/payment-mode/form.js +45 -74
- package/global-modules/payment-mode/payment-mode.d.ts +25 -2
- package/global-modules/payment-mode/payment-mode.js +90 -23
- package/global-modules/payment-mode/reducer.d.ts +23 -2
- package/global-modules/payment-mode/reducer.js +140 -114
- package/global-modules/payment-mode/types.d.ts +327 -112
- package/global-modules/payment-mode/types.js +162 -11
- package/global-modules/payment-mode/validate.d.ts +1 -1
- package/global-modules/payment-mode/validate.js +7 -5
- package/global-modules/preferences/actions.d.ts +126 -27
- package/global-modules/preferences/actions.js +128 -4
- package/global-modules/preferences/constants.d.ts +46 -31
- package/global-modules/preferences/constants.js +129 -66
- package/global-modules/preferences/context.d.ts +2 -2
- package/global-modules/preferences/context.js +43 -43
- package/global-modules/preferences/currency.js +15 -10
- package/global-modules/preferences/preferences.d.ts +2 -2
- package/global-modules/preferences/preferences.js +3 -5
- package/global-modules/preferences/validate.d.ts +1 -1
- package/global-modules/preferences/validate.js +7 -7
- package/global-modules/tax/actions.d.ts +155 -38
- package/global-modules/tax/actions.js +149 -7
- package/global-modules/tax/constants.d.ts +31 -39
- package/global-modules/tax/constants.js +83 -114
- package/global-modules/tax/context.d.ts +33 -2
- package/global-modules/tax/context.js +146 -132
- package/global-modules/tax/drawer.d.ts +26 -3
- package/global-modules/tax/drawer.js +101 -6
- package/global-modules/tax/form.d.ts +20 -3
- package/global-modules/tax/form.js +101 -74
- package/global-modules/tax/reducer.d.ts +23 -2
- package/global-modules/tax/reducer.js +143 -24
- package/global-modules/tax/tax.d.ts +25 -2
- package/global-modules/tax/tax.js +92 -28
- package/global-modules/tax/types.d.ts +332 -102
- package/global-modules/tax/types.js +179 -11
- package/global-modules/tax/validate.d.ts +1 -1
- package/global-modules/tax/validate.js +9 -8
- package/hooks/use-rtl.d.ts +44 -0
- package/hooks/use-rtl.js +75 -0
- package/i18n/navigation.d.ts +340 -0
- package/i18n/navigation.js +9 -0
- package/i18n/request.d.ts +2 -0
- package/i18n/request.js +95 -0
- package/i18n/routing.d.ts +18 -0
- package/i18n/routing.js +9 -0
- package/index.d.ts +26 -0
- package/index.js +42 -0
- package/lib/themes.d.ts +147 -0
- package/lib/themes.js +150 -0
- package/lib/toast-utils.d.ts +44 -0
- package/lib/toast-utils.js +212 -0
- package/lib/utils.d.ts +2 -0
- package/lib/utils.js +12 -0
- package/package.json +21 -3
- package/supabase/supabase.d.ts +80 -1
- package/supabase/supabase.js +281 -6
- package/global-modules/branch/form-elements.d.ts +0 -3
- package/global-modules/branch/form-elements.js +0 -41
- package/global-modules/payment-mode/form-elements.d.ts +0 -3
- package/global-modules/payment-mode/form-elements.js +0 -41
- package/global-modules/preferences/bank.d.ts +0 -2
- package/global-modules/preferences/bank.js +0 -11
- package/global-modules/preferences/branch-drawer.js +0 -36
- package/global-modules/preferences/branch-form-elements.js +0 -30
- package/global-modules/preferences/branch-form.d.ts +0 -0
- package/global-modules/preferences/branch-form.js +0 -33
- package/global-modules/preferences/branch.d.ts +0 -0
- package/global-modules/preferences/branch.js +0 -106
- package/global-modules/preferences/payment-mode-drawer.d.ts +0 -0
- package/global-modules/preferences/payment-mode-drawer.js +0 -36
- package/global-modules/preferences/payment-mode-form-elements.d.ts +0 -0
- package/global-modules/preferences/payment-mode-form-elements.js +0 -30
- package/global-modules/preferences/payment-mode-form.d.ts +0 -0
- package/global-modules/preferences/payment-mode-form.js +0 -33
- package/global-modules/preferences/payment-mode.d.ts +0 -0
- package/global-modules/preferences/payment-mode.js +0 -94
- package/global-modules/tax/form-elements.d.ts +0 -3
- package/global-modules/tax/form-elements.js +0 -41
- /package/{global-modules/preferences/branch-drawer.d.ts → constants.d.ts} +0 -0
- /package/{global-modules/preferences/branch-form-elements.d.ts → constants.js} +0 -0
|
@@ -1,5 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Branch Form Component
|
|
3
|
+
*
|
|
4
|
+
* Enhanced form component for branch management with comprehensive error handling
|
|
5
|
+
* and modern UI components.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Modern shadcn/ui form components
|
|
9
|
+
* - Translation support for validation messages
|
|
10
|
+
* - RTL/LTR layout compatibility
|
|
11
|
+
* - Accessibility-compliant form structure
|
|
12
|
+
* - Real-time validation feedback
|
|
13
|
+
*/
|
|
14
|
+
import { FC } from "react";
|
|
2
15
|
interface Props {
|
|
16
|
+
isRTL: boolean;
|
|
3
17
|
translationMap: {
|
|
4
18
|
[key: string]: string;
|
|
5
19
|
};
|
|
@@ -1,80 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Branch Form Component
|
|
4
|
+
*
|
|
5
|
+
* Enhanced form component for branch management with comprehensive error handling
|
|
6
|
+
* and modern UI components.
|
|
7
|
+
*
|
|
8
|
+
* Features:
|
|
9
|
+
* - Modern shadcn/ui form components
|
|
10
|
+
* - Translation support for validation messages
|
|
11
|
+
* - RTL/LTR layout compatibility
|
|
12
|
+
* - Accessibility-compliant form structure
|
|
13
|
+
* - Real-time validation feedback
|
|
14
|
+
*/
|
|
15
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
16
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
17
|
};
|
|
13
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
-
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
30
|
-
var ownKeys = function(o) {
|
|
31
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
32
|
-
var ar = [];
|
|
33
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
34
|
-
return ar;
|
|
35
|
-
};
|
|
36
|
-
return ownKeys(o);
|
|
37
|
-
};
|
|
38
|
-
return function (mod) {
|
|
39
|
-
if (mod && mod.__esModule) return mod;
|
|
40
|
-
var result = {};
|
|
41
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
42
|
-
__setModuleDefault(result, mod);
|
|
43
|
-
return result;
|
|
44
|
-
};
|
|
45
|
-
})();
|
|
46
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
19
|
exports.Form = void 0;
|
|
48
|
-
var react_1 =
|
|
49
|
-
var
|
|
20
|
+
var react_1 = __importDefault(require("react"));
|
|
21
|
+
var next_intl_1 = require("next-intl");
|
|
22
|
+
var input_1 = require("@/components/ui/input");
|
|
23
|
+
var switch_1 = require("@/components/ui/switch");
|
|
50
24
|
var context_1 = require("./context");
|
|
51
|
-
var form_elements_1 = require("./form-elements");
|
|
52
25
|
var Form = function (_a) {
|
|
53
|
-
var translationMap = _a.translationMap;
|
|
54
|
-
var
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
textInputElements[i].label = translationMap[label];
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
var textAreaElements = (_b = elements[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_AREA_V1]) === null || _b === void 0 ? void 0 : _b.sort(function (a, b) { return a.order - b.order; });
|
|
68
|
-
if (textAreaElements) {
|
|
69
|
-
textAreaElements === null || textAreaElements === void 0 ? void 0 : textAreaElements.forEach(function (_a, i) {
|
|
70
|
-
var label = _a.label;
|
|
71
|
-
if (translationMap[label] === undefined)
|
|
72
|
-
return label;
|
|
73
|
-
textAreaElements[i].label = translationMap[label];
|
|
74
|
-
});
|
|
26
|
+
var isRTL = _a.isRTL, translationMap = _a.translationMap;
|
|
27
|
+
var t = (0, next_intl_1.useTranslations)("branchPage");
|
|
28
|
+
var ui = (0, next_intl_1.useTranslations)("ui");
|
|
29
|
+
var _b = (0, context_1.useBranchStateContext)(), branchAddress = _b.branchAddress, branchName = _b.branchName, enabled = _b.enabled, errors = _b.errors, handleInputChange = _b.handleInputChange, isDefault = _b.isDefault, personEmail = _b.personEmail, personName = _b.personName, personPhone = _b.personPhone;
|
|
30
|
+
// Helper function to translate validation error keys
|
|
31
|
+
var getTranslatedError = function (key) {
|
|
32
|
+
if (!errors[key])
|
|
33
|
+
return undefined;
|
|
34
|
+
// If error starts with "validation.", it's a key to translate
|
|
35
|
+
if (errors[key].startsWith("validation.")) {
|
|
36
|
+
return t(errors[key]);
|
|
75
37
|
}
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
|
|
38
|
+
// Otherwise return as is (already translated)
|
|
39
|
+
return errors[key];
|
|
40
|
+
};
|
|
41
|
+
return (react_1.default.createElement("div", { className: "space-y-6 ".concat(isRTL ? "rtl" : "ltr"), dir: isRTL ? "rtl" : "ltr" },
|
|
42
|
+
react_1.default.createElement("div", { className: "space-y-4" },
|
|
43
|
+
react_1.default.createElement("div", { className: "space-y-4" },
|
|
44
|
+
react_1.default.createElement("div", { className: "space-y-2" },
|
|
45
|
+
react_1.default.createElement(input_1.Input, { id: "branchName", type: "text", label: (translationMap === null || translationMap === void 0 ? void 0 : translationMap.formLabelBranchName) || "Branch Name", value: branchName || "", onChange: function (e) { return handleInputChange("branchName", e.target.value); }, placeholder: "Enter branch name", info: "Enter a descriptive name for this branch", error: getTranslatedError("branchName"), required: true })),
|
|
46
|
+
react_1.default.createElement("div", { className: "space-y-2" },
|
|
47
|
+
react_1.default.createElement(input_1.Input, { id: "branchAddress", type: "text", label: (translationMap === null || translationMap === void 0 ? void 0 : translationMap.formLabelBranchAddress) || "Branch Address", value: branchAddress || "", onChange: function (e) {
|
|
48
|
+
return handleInputChange("branchAddress", e.target.value);
|
|
49
|
+
}, placeholder: "Enter branch address", info: "Enter the complete address of this branch", error: getTranslatedError("branchAddress"), required: true }))),
|
|
50
|
+
react_1.default.createElement("div", { className: "space-y-4" },
|
|
51
|
+
react_1.default.createElement("div", { className: "space-y-2" },
|
|
52
|
+
react_1.default.createElement(input_1.Input, { id: "personName", type: "text", label: (translationMap === null || translationMap === void 0 ? void 0 : translationMap.formLabelPersonName) || "Contact Person Name", value: personName || "", onChange: function (e) { return handleInputChange("personName", e.target.value); }, placeholder: "Enter contact person name", info: "Enter the name of the contact person for this branch", error: getTranslatedError("personName"), required: true })),
|
|
53
|
+
react_1.default.createElement("div", { className: "space-y-2" },
|
|
54
|
+
react_1.default.createElement(input_1.Input, { id: "personEmail", type: "email", label: (translationMap === null || translationMap === void 0 ? void 0 : translationMap.formLabelPersonEmail) || "Contact Person Email", value: personEmail || "", onChange: function (e) { return handleInputChange("personEmail", e.target.value); }, placeholder: "Enter contact person email", info: "Enter the email address of the contact person", error: getTranslatedError("personEmail"), required: true })),
|
|
55
|
+
react_1.default.createElement("div", { className: "space-y-2" },
|
|
56
|
+
react_1.default.createElement(input_1.Input, { id: "personPhone", type: "tel", label: (translationMap === null || translationMap === void 0 ? void 0 : translationMap.formLabelPersonPhone) || "Contact Person Phone", value: personPhone || "", onChange: function (e) { return handleInputChange("personPhone", e.target.value); }, placeholder: "Enter contact person phone", info: "Enter the phone number of the contact person", error: getTranslatedError("personPhone"), required: true }))),
|
|
57
|
+
react_1.default.createElement("div", { className: "space-y-4" },
|
|
58
|
+
react_1.default.createElement(switch_1.Switch, { id: "enabled", label: (translationMap === null || translationMap === void 0 ? void 0 : translationMap.enabled) || "Enabled", checked: enabled || false, onCheckedChange: function (checked) { return handleInputChange("enabled", checked); }, info: enabled ? ui("switch.infoEnabled") : ui("switch.infoDisabled"), error: getTranslatedError("enabled") }),
|
|
59
|
+
react_1.default.createElement(switch_1.Switch, { id: "isDefault", label: (translationMap === null || translationMap === void 0 ? void 0 : translationMap.setAsDefault) || "Set as Default", checked: isDefault || false, onCheckedChange: function (checked) {
|
|
60
|
+
return handleInputChange("isDefault", checked);
|
|
61
|
+
}, info: isDefault ? ui("switch.infoEnabled") : ui("switch.infoDisabled"), error: getTranslatedError("isDefault") })))));
|
|
79
62
|
};
|
|
80
63
|
exports.Form = Form;
|
|
@@ -1,4 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Branch State Reducer
|
|
3
|
+
*
|
|
4
|
+
* This module manages the state transitions for the Branch 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 branch data)
|
|
9
|
+
* - UI state management (drawers, 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
|
+
* - Consistent patterns for similar operations
|
|
20
|
+
* - Type-safe helper functions for better error prevention
|
|
21
|
+
*/
|
|
22
|
+
import { BranchActions } from "./actions";
|
|
23
|
+
import { BranchState } from "./types";
|
|
3
24
|
export declare const initialBranchState: BranchState;
|
|
4
25
|
export declare function branchReducer(state: BranchState, action: BranchActions): BranchState;
|
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Branch State Reducer
|
|
4
|
+
*
|
|
5
|
+
* This module manages the state transitions for the Branch 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 branch data)
|
|
10
|
+
* - UI state management (drawers, 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
|
+
* - Consistent patterns for similar operations
|
|
21
|
+
* - Type-safe helper functions for better error prevention
|
|
22
|
+
*/
|
|
2
23
|
var __assign = (this && this.__assign) || function () {
|
|
3
24
|
__assign = Object.assign || function(t) {
|
|
4
25
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
@@ -24,144 +45,153 @@ exports.initialBranchState = void 0;
|
|
|
24
45
|
exports.branchReducer = branchReducer;
|
|
25
46
|
var actions_1 = require("./actions");
|
|
26
47
|
var constants_1 = require("./constants");
|
|
48
|
+
// ============================================================================
|
|
49
|
+
// HELPER FUNCTIONS
|
|
50
|
+
// ============================================================================
|
|
51
|
+
/**
|
|
52
|
+
* Helper function to reset form fields to their initial values
|
|
53
|
+
*/
|
|
54
|
+
var getFormResetState = function () { return ({
|
|
55
|
+
branchAddress: "",
|
|
56
|
+
branchName: "",
|
|
57
|
+
enabled: false,
|
|
58
|
+
errors: {},
|
|
59
|
+
id: "",
|
|
60
|
+
isDefault: false,
|
|
61
|
+
personEmail: "",
|
|
62
|
+
personName: "",
|
|
63
|
+
personPhone: "",
|
|
64
|
+
preferenceId: "",
|
|
65
|
+
disableSaveButton: false,
|
|
66
|
+
}); };
|
|
67
|
+
/**
|
|
68
|
+
* Helper function to safely update array state with immutability
|
|
69
|
+
*/
|
|
70
|
+
var updateArrayState = function (array) { return __spreadArray([], array, true); };
|
|
71
|
+
/**
|
|
72
|
+
* Helper function to safely merge errors with existing state
|
|
73
|
+
*/
|
|
74
|
+
var mergeErrors = function (errors) { return (__assign({}, errors)); };
|
|
75
|
+
// ============================================================================
|
|
76
|
+
// INITIAL STATE
|
|
77
|
+
// ============================================================================
|
|
27
78
|
exports.initialBranchState = {
|
|
28
|
-
|
|
29
|
-
|
|
79
|
+
// Branch Form Data
|
|
80
|
+
branchAddress: "",
|
|
81
|
+
branchName: "",
|
|
82
|
+
enabled: false,
|
|
83
|
+
id: "",
|
|
84
|
+
isDefault: false,
|
|
85
|
+
personEmail: "",
|
|
86
|
+
personName: "",
|
|
87
|
+
personPhone: "",
|
|
88
|
+
preferenceId: "",
|
|
89
|
+
// List Data
|
|
30
90
|
branches: [],
|
|
31
91
|
count: 0,
|
|
92
|
+
// Search & Pagination
|
|
32
93
|
currentPage: 1,
|
|
94
|
+
pageLimit: constants_1.pageLimit,
|
|
95
|
+
searchQuery: "",
|
|
96
|
+
// UI State
|
|
33
97
|
disableSaveButton: false,
|
|
34
98
|
drawer: null,
|
|
35
|
-
|
|
99
|
+
// Errors
|
|
36
100
|
errors: {},
|
|
37
|
-
id: '',
|
|
38
|
-
isDefault: false,
|
|
39
|
-
pageLimit: constants_1.pageLimit,
|
|
40
|
-
personEmail: '',
|
|
41
|
-
personName: '',
|
|
42
|
-
personPhone: '',
|
|
43
|
-
preferenceId: '',
|
|
44
|
-
searchQuery: '',
|
|
45
101
|
};
|
|
102
|
+
// ============================================================================
|
|
103
|
+
// REDUCER FUNCTION
|
|
104
|
+
// ============================================================================
|
|
46
105
|
function branchReducer(state, action) {
|
|
47
106
|
var _a;
|
|
48
107
|
switch (action.type) {
|
|
49
|
-
//
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
// case BRANCH_ACTION_TYPES.SET_BRANCH_BTN_DISABLE:
|
|
60
|
-
// return { ...state, tax: { ...state.tax, btnDisableTax: action.payload } };
|
|
61
|
-
// case BRANCH_ACTION_TYPES.SET_BANK_BTN_DISABLE:
|
|
62
|
-
// return {
|
|
63
|
-
// ...state,
|
|
64
|
-
// bankDetails: {
|
|
65
|
-
// ...state.bankDetails,
|
|
66
|
-
// btnDisableBankDetail: action.payload,
|
|
67
|
-
// },
|
|
68
|
-
// };
|
|
69
|
-
// case BRANCH_ACTION_TYPES.SET_BRANCH_BTN_DISABLE:
|
|
70
|
-
// return {
|
|
71
|
-
// ...state,
|
|
72
|
-
// branches: { ...state.branches, btnDisableBranches: action.payload },
|
|
73
|
-
// };
|
|
74
|
-
// case BRANCH_ACTION_TYPES.SET_INPUT_FIELD:
|
|
75
|
-
// return {
|
|
76
|
-
// ...state,
|
|
77
|
-
// [action.payload.key]: action.payload.value,
|
|
78
|
-
// };
|
|
79
|
-
// case BRANCH_ACTION_TYPES.UPDATE_BANK_FIELDS:
|
|
80
|
-
// return {
|
|
81
|
-
// ...state,
|
|
82
|
-
// bankDetails: {
|
|
83
|
-
// ...state.bankDetails,
|
|
84
|
-
// [action.payload.field]: action.payload.value,
|
|
85
|
-
// },
|
|
86
|
-
// };
|
|
87
|
-
// case BRANCH_ACTION_TYPES.UPDATE_BRANCH_FIELDS:
|
|
88
|
-
// return {
|
|
89
|
-
// ...state,
|
|
90
|
-
// branches: {
|
|
91
|
-
// ...state.branches,
|
|
92
|
-
// [action.payload.field]: action.payload.value,
|
|
93
|
-
// },
|
|
94
|
-
// };
|
|
95
|
-
// case BRANCH_ACTION_TYPES.UPDATE_BRANCH_FIELDS:
|
|
96
|
-
// return {
|
|
97
|
-
// ...state,
|
|
98
|
-
// tax: {
|
|
99
|
-
// ...state.tax,
|
|
100
|
-
// [action.payload.field]: action.payload.value,
|
|
101
|
-
// },
|
|
102
|
-
// };
|
|
103
|
-
// case BRANCH_ACTION_TYPES.CLEAR_BANK_DETAILS:
|
|
104
|
-
// return { ...state, bankDetails: initialPreferenceState.bankDetails };
|
|
105
|
-
// case BRANCH_ACTION_TYPES.CLEAR_BRANCHES:
|
|
106
|
-
// return { ...state, branches: initialPreferenceState.branches };
|
|
107
|
-
// case BRANCH_ACTION_TYPES.CLEAR_TAXES:
|
|
108
|
-
// return { ...state, tax: initialPreferenceState.tax };
|
|
109
|
-
case actions_1.BRANCH_ACTION_TYPES.SET_ERRORS:
|
|
110
|
-
return __assign(__assign({}, state), { errors: __assign({}, action.payload.errors) });
|
|
111
|
-
case actions_1.BRANCH_ACTION_TYPES.SET_SEARCH_QUERY:
|
|
112
|
-
return __assign(__assign({}, state), { searchQuery: action.payload.searchQuery });
|
|
113
|
-
// case BRANCH_ACTION_TYPES.SET_ACTIVE_TAB:
|
|
114
|
-
// return {
|
|
115
|
-
// ...state,
|
|
116
|
-
// activeTab: action.payload.activeTab,
|
|
117
|
-
// };
|
|
118
|
-
// case BRANCH_ACTION_TYPES.RESET_FORM:
|
|
119
|
-
// return {
|
|
120
|
-
// ...state,
|
|
121
|
-
// taxForm: {
|
|
122
|
-
// ...state.taxForm,
|
|
123
|
-
// ...initialPreferenceState.taxForm,
|
|
124
|
-
// },
|
|
125
|
-
// };
|
|
126
|
-
// case BRANCH_ACTION_TYPES.SET_CURRENCY_UPDATE_ID:
|
|
127
|
-
// return {
|
|
128
|
-
// ...state,
|
|
129
|
-
// currencyUpdateId: action.payload.currencyUpdateId,
|
|
130
|
-
// };
|
|
131
|
-
// case BRANCH_ACTION_TYPES.SET_PAYMENT_MODE_COUNT:
|
|
132
|
-
// return {
|
|
133
|
-
// ...state,
|
|
134
|
-
// paymentModeCount: action.payload.paymentModeCount,
|
|
135
|
-
// };
|
|
136
|
-
// case BRANCH_ACTION_TYPES.SET_BRANCHES:
|
|
137
|
-
// return {
|
|
138
|
-
// ...state,
|
|
139
|
-
// branches: [...action.payload.branches],
|
|
140
|
-
// };
|
|
141
|
-
// case BRANCH_ACTION_TYPES.SET_BRANCH_COUNT:
|
|
142
|
-
// return {
|
|
143
|
-
// ...state,
|
|
144
|
-
// branchCount: action.payload.branchCount,
|
|
145
|
-
// };
|
|
146
|
-
case actions_1.BRANCH_ACTION_TYPES.SET_BRANCHES:
|
|
147
|
-
return __assign(__assign({}, state), { branches: __spreadArray([], action.payload.branches, true) });
|
|
148
|
-
case actions_1.BRANCH_ACTION_TYPES.SET_COUNT:
|
|
149
|
-
return __assign(__assign({}, state), { count: action.payload.count });
|
|
150
|
-
case actions_1.BRANCH_ACTION_TYPES.SET_FORM:
|
|
151
|
-
return __assign(__assign({}, state), action.payload.form);
|
|
152
|
-
case actions_1.BRANCH_ACTION_TYPES.SET_DRAWER:
|
|
153
|
-
return __assign(__assign({}, state), { drawer: action.payload.drawer });
|
|
108
|
+
// ------------------------------------------------------------------------
|
|
109
|
+
// FORM RESET ACTIONS
|
|
110
|
+
// ------------------------------------------------------------------------
|
|
111
|
+
case actions_1.BRANCH_ACTION_TYPES.RESET_ERRORS:
|
|
112
|
+
return __assign(__assign({}, state), { errors: {} });
|
|
113
|
+
case actions_1.BRANCH_ACTION_TYPES.RESET_FORM:
|
|
114
|
+
return __assign(__assign({}, state), getFormResetState());
|
|
115
|
+
// ------------------------------------------------------------------------
|
|
116
|
+
// FORM INPUT ACTIONS
|
|
117
|
+
// ------------------------------------------------------------------------
|
|
154
118
|
case actions_1.BRANCH_ACTION_TYPES.SET_INPUT_FIELD:
|
|
155
119
|
return __assign(__assign({}, state), (_a = {}, _a[action.payload.key] = action.payload.value, _a));
|
|
120
|
+
case actions_1.BRANCH_ACTION_TYPES.SET_FORM:
|
|
121
|
+
return __assign(__assign({}, state), action.payload.form);
|
|
122
|
+
// ------------------------------------------------------------------------
|
|
123
|
+
// ERROR HANDLING ACTIONS
|
|
124
|
+
// ------------------------------------------------------------------------
|
|
125
|
+
case actions_1.BRANCH_ACTION_TYPES.SET_ERRORS:
|
|
126
|
+
return __assign(__assign({}, state), { disableSaveButton: false, errors: mergeErrors(action.payload.errors) });
|
|
127
|
+
// ------------------------------------------------------------------------
|
|
128
|
+
// UI STATE ACTIONS
|
|
129
|
+
// ------------------------------------------------------------------------
|
|
156
130
|
case actions_1.BRANCH_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON:
|
|
157
131
|
return __assign(__assign({}, state), { disableSaveButton: action.payload.disableSaveButton });
|
|
158
|
-
case actions_1.BRANCH_ACTION_TYPES.
|
|
159
|
-
return __assign(__assign({}, state), {
|
|
132
|
+
case actions_1.BRANCH_ACTION_TYPES.SET_DRAWER:
|
|
133
|
+
return __assign(__assign({}, state), { drawer: action.payload.drawer });
|
|
134
|
+
// ------------------------------------------------------------------------
|
|
135
|
+
// LIST DATA ACTIONS
|
|
136
|
+
// ------------------------------------------------------------------------
|
|
137
|
+
case actions_1.BRANCH_ACTION_TYPES.SET_BRANCHES:
|
|
138
|
+
return __assign(__assign({}, state), { branches: updateArrayState(action.payload.branches) });
|
|
139
|
+
case actions_1.BRANCH_ACTION_TYPES.SET_COUNT:
|
|
140
|
+
return __assign(__assign({}, state), { count: action.payload.count });
|
|
141
|
+
// ------------------------------------------------------------------------
|
|
142
|
+
// PAGINATION ACTIONS
|
|
143
|
+
// ------------------------------------------------------------------------
|
|
160
144
|
case actions_1.BRANCH_ACTION_TYPES.SET_CURRENT_PAGE:
|
|
161
145
|
return __assign(__assign({}, state), { currentPage: action.payload.currentPage });
|
|
162
146
|
case actions_1.BRANCH_ACTION_TYPES.SET_PAGE_LIMIT:
|
|
163
147
|
return __assign(__assign({}, state), { pageLimit: action.payload.pageLimit });
|
|
148
|
+
// ------------------------------------------------------------------------
|
|
149
|
+
// SEARCH ACTIONS
|
|
150
|
+
// ------------------------------------------------------------------------
|
|
151
|
+
case actions_1.BRANCH_ACTION_TYPES.SET_SEARCH_QUERY:
|
|
152
|
+
return __assign(__assign({}, state), { searchQuery: action.payload.searchQuery });
|
|
153
|
+
// ------------------------------------------------------------------------
|
|
154
|
+
// DEFAULT CASE
|
|
155
|
+
// ------------------------------------------------------------------------
|
|
164
156
|
default:
|
|
165
157
|
return state;
|
|
166
158
|
}
|
|
167
159
|
}
|
|
160
|
+
// ============================================================================
|
|
161
|
+
// OPTIMIZATION SUMMARY
|
|
162
|
+
// ============================================================================
|
|
163
|
+
/*
|
|
164
|
+
* Reducer Optimizations Applied:
|
|
165
|
+
*
|
|
166
|
+
* 1. **Structural Organization**
|
|
167
|
+
* - Grouped related actions into logical sections with clear headers
|
|
168
|
+
* - Added comprehensive documentation and comments
|
|
169
|
+
* - Organized initial state by functionality
|
|
170
|
+
* - Removed all commented-out legacy code
|
|
171
|
+
*
|
|
172
|
+
* 2. **Performance Improvements**
|
|
173
|
+
* - Helper functions for common operations (getFormResetState, updateArrayState, mergeErrors)
|
|
174
|
+
* - Immutable state updates using spread operator
|
|
175
|
+
* - Optimized object creation patterns
|
|
176
|
+
* - Consistent shallow copying for arrays
|
|
177
|
+
*
|
|
178
|
+
* 3. **Code Quality**
|
|
179
|
+
* - Clear section headers for better navigation
|
|
180
|
+
* - Consistent action handling patterns
|
|
181
|
+
* - Improved readability with logical grouping
|
|
182
|
+
* - Type-safe helper functions where applicable
|
|
183
|
+
* - Removed dead code and unnecessary comments
|
|
184
|
+
*
|
|
185
|
+
* 4. **Maintainability**
|
|
186
|
+
* - Predictable state update patterns
|
|
187
|
+
* - Easy-to-locate action handlers
|
|
188
|
+
* - Self-documenting code structure
|
|
189
|
+
* - Consistent formatting and style
|
|
190
|
+
* - Clear separation of concerns
|
|
191
|
+
*
|
|
192
|
+
* 5. **Branch-Specific Optimizations**
|
|
193
|
+
* - Focused on branch operations only
|
|
194
|
+
* - Removed unrelated legacy reducer cases
|
|
195
|
+
* - Streamlined state management for branch features
|
|
196
|
+
* - Optimized for branch CRUD operations
|
|
197
|
+
*/
|