@appcorp/stellar-solutions-invoice-module 0.1.1
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 +36 -0
- package/base-modules/invoice/actions.d.ts +134 -0
- package/base-modules/invoice/actions.js +29 -0
- package/base-modules/invoice/add-service-product-section.d.ts +2 -0
- package/base-modules/invoice/add-service-product-section.js +21 -0
- package/base-modules/invoice/calculate-subtotal.d.ts +2 -0
- package/base-modules/invoice/calculate-subtotal.js +20 -0
- package/base-modules/invoice/constants.d.ts +42 -0
- package/base-modules/invoice/constants.js +450 -0
- package/base-modules/invoice/context.d.ts +10 -0
- package/base-modules/invoice/context.js +661 -0
- package/base-modules/invoice/drawer.d.ts +8 -0
- package/base-modules/invoice/drawer.js +19 -0
- package/base-modules/invoice/form.d.ts +8 -0
- package/base-modules/invoice/form.js +67 -0
- package/base-modules/invoice/invoice.d.ts +10 -0
- package/base-modules/invoice/invoice.js +90 -0
- package/base-modules/invoice/pricing-form-elements.d.ts +3 -0
- package/base-modules/invoice/pricing-form-elements.js +41 -0
- package/base-modules/invoice/pricing-form-section.d.ts +2 -0
- package/base-modules/invoice/pricing-form-section.js +20 -0
- package/base-modules/invoice/products-form-elements.d.ts +4 -0
- package/base-modules/invoice/products-form-elements.js +41 -0
- package/base-modules/invoice/products-form-section.d.ts +2 -0
- package/base-modules/invoice/products-form-section.js +17 -0
- package/base-modules/invoice/reducer.d.ts +4 -0
- package/base-modules/invoice/reducer.js +138 -0
- package/base-modules/invoice/services-form-elements.d.ts +4 -0
- package/base-modules/invoice/services-form-elements.js +41 -0
- package/base-modules/invoice/services-form-section.d.ts +2 -0
- package/base-modules/invoice/services-form-section.js +17 -0
- package/base-modules/invoice/types.d.ts +163 -0
- package/base-modules/invoice/types.js +40 -0
- package/base-modules/invoice/validate.d.ts +36 -0
- package/base-modules/invoice/validate.js +17 -0
- package/base-modules/product/actions.d.ts +113 -0
- package/base-modules/product/actions.js +22 -0
- package/base-modules/product/constants.d.ts +33 -0
- package/base-modules/product/constants.js +204 -0
- package/base-modules/product/context.d.ts +10 -0
- package/base-modules/product/context.js +557 -0
- package/base-modules/product/drawer.d.ts +8 -0
- package/base-modules/product/drawer.js +19 -0
- package/base-modules/product/form-elements.d.ts +2 -0
- package/base-modules/product/form-elements.js +41 -0
- package/base-modules/product/form.d.ts +8 -0
- package/base-modules/product/form.js +107 -0
- package/base-modules/product/product.d.ts +10 -0
- package/base-modules/product/product.js +80 -0
- package/base-modules/product/reducer.d.ts +4 -0
- package/base-modules/product/reducer.js +88 -0
- package/base-modules/product/types.d.ts +87 -0
- package/base-modules/product/types.js +28 -0
- package/base-modules/product/validate.d.ts +36 -0
- package/base-modules/product/validate.js +17 -0
- package/base-modules/product-category/actions.d.ts +90 -0
- package/base-modules/product-category/actions.js +19 -0
- package/base-modules/product-category/constants.d.ts +28 -0
- package/base-modules/product-category/constants.js +74 -0
- package/base-modules/product-category/context.d.ts +10 -0
- package/base-modules/product-category/context.js +390 -0
- package/base-modules/product-category/drawer.d.ts +8 -0
- package/base-modules/product-category/drawer.js +19 -0
- package/base-modules/product-category/form-elements.d.ts +2 -0
- package/base-modules/product-category/form-elements.js +41 -0
- package/base-modules/product-category/form.d.ts +8 -0
- package/base-modules/product-category/form.js +81 -0
- package/base-modules/product-category/product-category.d.ts +10 -0
- package/base-modules/product-category/product-category.js +53 -0
- package/base-modules/product-category/reducer.d.ts +4 -0
- package/base-modules/product-category/reducer.js +73 -0
- package/base-modules/product-category/types.d.ts +59 -0
- package/base-modules/product-category/types.js +11 -0
- package/base-modules/product-category/validate.d.ts +12 -0
- package/base-modules/product-category/validate.js +11 -0
- package/package.json +60 -0
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __assign = (this && this.__assign) || function () {
|
|
4
|
+
__assign = Object.assign || function(t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
8
|
+
t[p] = s[p];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
return __assign.apply(this, arguments);
|
|
13
|
+
};
|
|
14
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
17
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
18
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
19
|
+
}
|
|
20
|
+
Object.defineProperty(o, k2, desc);
|
|
21
|
+
}) : (function(o, m, k, k2) {
|
|
22
|
+
if (k2 === undefined) k2 = k;
|
|
23
|
+
o[k2] = m[k];
|
|
24
|
+
}));
|
|
25
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
26
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
27
|
+
}) : function(o, v) {
|
|
28
|
+
o["default"] = v;
|
|
29
|
+
});
|
|
30
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
31
|
+
var ownKeys = function(o) {
|
|
32
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
33
|
+
var ar = [];
|
|
34
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
35
|
+
return ar;
|
|
36
|
+
};
|
|
37
|
+
return ownKeys(o);
|
|
38
|
+
};
|
|
39
|
+
return function (mod) {
|
|
40
|
+
if (mod && mod.__esModule) return mod;
|
|
41
|
+
var result = {};
|
|
42
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
43
|
+
__setModuleDefault(result, mod);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
48
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
49
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
50
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
51
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
52
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
53
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
57
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
58
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
59
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
60
|
+
function step(op) {
|
|
61
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
62
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
63
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
64
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
65
|
+
switch (op[0]) {
|
|
66
|
+
case 0: case 1: t = op; break;
|
|
67
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
68
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
69
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
70
|
+
default:
|
|
71
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
72
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
73
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
74
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
75
|
+
if (t[2]) _.ops.pop();
|
|
76
|
+
_.trys.pop(); continue;
|
|
77
|
+
}
|
|
78
|
+
op = body.call(thisArg, _);
|
|
79
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
80
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
84
|
+
exports.useProductStateContext = exports.ProductStateContextProvider = exports.ProductStateContext = void 0;
|
|
85
|
+
var react_1 = __importStar(require("react"));
|
|
86
|
+
var util_functions_1 = require("@react-pakistan/util-functions");
|
|
87
|
+
var form_schema_1 = require("@appcorp/app-corp-vista/utils/form-schema");
|
|
88
|
+
var vista_notification_type_1 = require("@appcorp/app-corp-vista/type/vista-notification-type");
|
|
89
|
+
var supabase_1 = require("@appcorp/stellar-solutions-modules/supabase/supabase");
|
|
90
|
+
var actions_1 = require("./actions");
|
|
91
|
+
var constants_1 = require("./constants");
|
|
92
|
+
var constants_2 = require("../product-category/constants");
|
|
93
|
+
var reducer_1 = require("./reducer");
|
|
94
|
+
var types_1 = require("./types");
|
|
95
|
+
var validate_1 = require("./validate");
|
|
96
|
+
var webp_converter_browser_1 = require("webp-converter-browser");
|
|
97
|
+
var uuid_1 = require("uuid");
|
|
98
|
+
var context_1 = require("../product-category/context");
|
|
99
|
+
var generate_toast_1 = require("@appcorp/app-corp-vista/utils/generate-toast");
|
|
100
|
+
var useProductState = function () {
|
|
101
|
+
var productCategories = (0, context_1.useProductCategoryStateContext)().productCategories;
|
|
102
|
+
var _a = (0, react_1.useReducer)(reducer_1.productReducer, reducer_1.initialProductState), state = _a[0], dispatch = _a[1];
|
|
103
|
+
var debouncedQuery = (0, util_functions_1.useDebounce)(state.searchQuery, 800);
|
|
104
|
+
var debouncedList = (0, util_functions_1.useDebounce)(state.productCategoryQuery, 800);
|
|
105
|
+
var listParams = {
|
|
106
|
+
currentPage: state.currentPage,
|
|
107
|
+
includeProductCategory: true,
|
|
108
|
+
pageLimit: state.pageLimit,
|
|
109
|
+
searchQuery: state.searchQuery,
|
|
110
|
+
};
|
|
111
|
+
var listCallback = function (_a) {
|
|
112
|
+
var data = _a.data, error = _a.error;
|
|
113
|
+
if (error) {
|
|
114
|
+
(0, generate_toast_1.generateToast)({
|
|
115
|
+
variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
|
|
116
|
+
description: constants_1.messages.error,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (data === null || data === void 0 ? void 0 : data.items) {
|
|
120
|
+
dispatch({
|
|
121
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_PRODUCTS,
|
|
122
|
+
payload: { products: data.items },
|
|
123
|
+
});
|
|
124
|
+
dispatch({
|
|
125
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_COUNT,
|
|
126
|
+
payload: { count: data === null || data === void 0 ? void 0 : data.count },
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var updateParams = (0, react_1.useMemo)(function () { return ({
|
|
131
|
+
buyPrice: state.buyPrice,
|
|
132
|
+
currency: state.currency,
|
|
133
|
+
description: state.description,
|
|
134
|
+
id: state.id,
|
|
135
|
+
images: state.images,
|
|
136
|
+
name: state.name,
|
|
137
|
+
productCategoryId: state.productCategoryId,
|
|
138
|
+
quantity: state.quantity,
|
|
139
|
+
ref: state.ref,
|
|
140
|
+
salePrice: state.salePrice,
|
|
141
|
+
}); }, [state]);
|
|
142
|
+
var updateCallback = function (_a) {
|
|
143
|
+
var data = _a.data, error = _a.error;
|
|
144
|
+
if (error) {
|
|
145
|
+
(0, generate_toast_1.generateToast)({
|
|
146
|
+
description: constants_1.messages.error,
|
|
147
|
+
variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
if (data) {
|
|
151
|
+
(0, generate_toast_1.generateToast)({
|
|
152
|
+
description: constants_1.messages.success,
|
|
153
|
+
variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.SUCCESS,
|
|
154
|
+
});
|
|
155
|
+
dispatch({
|
|
156
|
+
type: actions_1.PRODUCT_ACTION_TYPES.RESET_FORM,
|
|
157
|
+
});
|
|
158
|
+
listFetchNow();
|
|
159
|
+
dispatch({
|
|
160
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_DRAWER,
|
|
161
|
+
payload: { drawer: null },
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
var byIdParams = {
|
|
166
|
+
id: state.id,
|
|
167
|
+
};
|
|
168
|
+
var byIdCallback = function (_a) {
|
|
169
|
+
var data = _a.data, error = _a.error;
|
|
170
|
+
if (error) {
|
|
171
|
+
(0, generate_toast_1.generateToast)({
|
|
172
|
+
description: constants_1.messages.error,
|
|
173
|
+
variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
if (data) {
|
|
177
|
+
var updatedData = __assign(__assign(__assign(__assign({}, data), (!data.description && { description: '' })), (!data.ref && { ref: '' })), (!data.image && { image: [] }));
|
|
178
|
+
dispatch({
|
|
179
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_FORM,
|
|
180
|
+
payload: { form: updatedData },
|
|
181
|
+
});
|
|
182
|
+
dispatch({
|
|
183
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_DRAWER,
|
|
184
|
+
payload: { drawer: types_1.PRODUCT_DRAWER.PRODUCT_FORM_DRAWER },
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
var deleteParams = {
|
|
189
|
+
id: state.id,
|
|
190
|
+
};
|
|
191
|
+
var deleteCallback = function (_a) {
|
|
192
|
+
var data = _a.data, error = _a.error;
|
|
193
|
+
if (error) {
|
|
194
|
+
(0, generate_toast_1.generateToast)({
|
|
195
|
+
description: constants_1.messages.error,
|
|
196
|
+
variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (data) {
|
|
200
|
+
(0, generate_toast_1.generateToast)({
|
|
201
|
+
description: constants_1.messages.success,
|
|
202
|
+
variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.SUCCESS,
|
|
203
|
+
});
|
|
204
|
+
dispatch({
|
|
205
|
+
type: actions_1.PRODUCT_ACTION_TYPES.RESET_FORM,
|
|
206
|
+
});
|
|
207
|
+
listFetchNow();
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
var _b = (0, util_functions_1.useModuleEntity)({
|
|
211
|
+
byIdCallback: byIdCallback,
|
|
212
|
+
byIdParams: byIdParams,
|
|
213
|
+
deleteCallback: deleteCallback,
|
|
214
|
+
deleteParams: deleteParams,
|
|
215
|
+
listCallback: listCallback,
|
|
216
|
+
listParams: listParams,
|
|
217
|
+
listUrl: constants_1.PRODUCT_API_ROUTES.PRODUCTS,
|
|
218
|
+
searchQuery: debouncedQuery,
|
|
219
|
+
unitByIdUrl: constants_1.PRODUCT_API_ROUTES.PRODUCT_BY_ID,
|
|
220
|
+
unitUrl: constants_1.PRODUCT_API_ROUTES.PRODUCT,
|
|
221
|
+
updateCallback: updateCallback,
|
|
222
|
+
updateDeps: [state],
|
|
223
|
+
updateParams: updateParams,
|
|
224
|
+
}), 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;
|
|
225
|
+
(0, react_1.useEffect)(function () {
|
|
226
|
+
listFetchNow();
|
|
227
|
+
// eslint-disable-next-line
|
|
228
|
+
}, [
|
|
229
|
+
debouncedQuery,
|
|
230
|
+
state.currentPage,
|
|
231
|
+
state.pageLimit,
|
|
232
|
+
]);
|
|
233
|
+
var handleCreate = function () {
|
|
234
|
+
dispatch({
|
|
235
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_DRAWER,
|
|
236
|
+
payload: { drawer: types_1.PRODUCT_DRAWER.PRODUCT_FORM_DRAWER },
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
var handleEdit = function (id) {
|
|
240
|
+
byIdFetchNow(undefined, {
|
|
241
|
+
body: JSON.stringify({ id: id }),
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
var handleDelete = function (id) {
|
|
245
|
+
deleteFetchNow === null || deleteFetchNow === void 0 ? void 0 : deleteFetchNow(undefined, {
|
|
246
|
+
body: JSON.stringify({ id: id }),
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
var handleUploadImage = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
250
|
+
var urls;
|
|
251
|
+
var _a;
|
|
252
|
+
return __generator(this, function (_b) {
|
|
253
|
+
switch (_b.label) {
|
|
254
|
+
case 0:
|
|
255
|
+
urls = [];
|
|
256
|
+
if (!((_a = state === null || state === void 0 ? void 0 : state.images) === null || _a === void 0 ? void 0 : _a.some(function (u) { return u.startsWith('blob:'); }))) return [3 /*break*/, 2];
|
|
257
|
+
return [4 /*yield*/, Promise.all(state.images.map(function (url) { return __awaiter(void 0, void 0, void 0, function () {
|
|
258
|
+
var blob, webpBlob, data;
|
|
259
|
+
return __generator(this, function (_a) {
|
|
260
|
+
switch (_a.label) {
|
|
261
|
+
case 0: return [4 /*yield*/, fetch(url).then(function (r) { return r.blob(); })];
|
|
262
|
+
case 1:
|
|
263
|
+
blob = _a.sent();
|
|
264
|
+
return [4 /*yield*/, (0, webp_converter_browser_1.blobToWebP)(blob, { quality: 1 })];
|
|
265
|
+
case 2:
|
|
266
|
+
webpBlob = _a.sent();
|
|
267
|
+
return [4 /*yield*/, (0, util_functions_1.uploadBlobToPublicSupabase)({
|
|
268
|
+
blob: webpBlob,
|
|
269
|
+
supabase: supabase_1.supabaseClient,
|
|
270
|
+
fileRef: "products/".concat((0, uuid_1.v4)(), ".webp"),
|
|
271
|
+
contentType: 'image/webp',
|
|
272
|
+
upsert: true,
|
|
273
|
+
})];
|
|
274
|
+
case 3:
|
|
275
|
+
data = (_a.sent()).data;
|
|
276
|
+
if (data) {
|
|
277
|
+
urls.push("".concat(supabase_1.supabasePublicStorageUrl, "/").concat(data.path));
|
|
278
|
+
}
|
|
279
|
+
return [2 /*return*/, urls];
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}); }))];
|
|
283
|
+
case 1:
|
|
284
|
+
_b.sent();
|
|
285
|
+
_b.label = 2;
|
|
286
|
+
case 2:
|
|
287
|
+
if (urls.length) {
|
|
288
|
+
dispatch({
|
|
289
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
290
|
+
payload: { key: 'images', value: urls },
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
return [2 /*return*/, urls];
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}); }, [state.images]);
|
|
297
|
+
var handleSubmit = (0, react_1.useCallback)(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
298
|
+
var urls, validationResult, validationErrors_1;
|
|
299
|
+
var _a;
|
|
300
|
+
return __generator(this, function (_b) {
|
|
301
|
+
switch (_b.label) {
|
|
302
|
+
case 0:
|
|
303
|
+
if (!((_a = state.images) === null || _a === void 0 ? void 0 : _a.length)) return [3 /*break*/, 2];
|
|
304
|
+
return [4 /*yield*/, handleUploadImage()];
|
|
305
|
+
case 1:
|
|
306
|
+
urls = _b.sent();
|
|
307
|
+
_b.label = 2;
|
|
308
|
+
case 2:
|
|
309
|
+
dispatch({
|
|
310
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
311
|
+
payload: { disableSaveButton: true },
|
|
312
|
+
});
|
|
313
|
+
try {
|
|
314
|
+
validationResult = validate_1.formValidation === null || validate_1.formValidation === void 0 ? void 0 : validate_1.formValidation.safeParse(__assign(__assign({}, updateParams), { images: urls || state.images }));
|
|
315
|
+
if (validationResult === null || validationResult === void 0 ? void 0 : validationResult.error) {
|
|
316
|
+
validationErrors_1 = {};
|
|
317
|
+
validationResult === null || validationResult === void 0 ? void 0 : validationResult.error.errors.forEach(function (err) {
|
|
318
|
+
validationErrors_1[err.path[0]] = err.message;
|
|
319
|
+
});
|
|
320
|
+
dispatch({
|
|
321
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_ERRORS,
|
|
322
|
+
payload: validationErrors_1,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
if (validationResult === null || validationResult === void 0 ? void 0 : validationResult.success) {
|
|
326
|
+
updateFetchNow(undefined, {
|
|
327
|
+
body: JSON.stringify(__assign({}, updateParams)),
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
// eslint-disable-next-line
|
|
331
|
+
}
|
|
332
|
+
catch (err) {
|
|
333
|
+
(0, generate_toast_1.generateToast)({
|
|
334
|
+
description: constants_1.messages.error,
|
|
335
|
+
variant: vista_notification_type_1.VISTA_NOTIFICATION_V1_VARIANT.ERROR,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
dispatch({
|
|
339
|
+
type: actions_1.PRODUCT_ACTION_TYPES.RESET_FORM,
|
|
340
|
+
});
|
|
341
|
+
dispatch({
|
|
342
|
+
type: actions_1.PRODUCT_ACTION_TYPES.CLEAR_ERRORS,
|
|
343
|
+
});
|
|
344
|
+
return [2 /*return*/];
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}); }, [updateFetchNow, updateParams, handleUploadImage, state.images]);
|
|
348
|
+
var handleFileChange = function (e) {
|
|
349
|
+
if (!e.target.files)
|
|
350
|
+
return;
|
|
351
|
+
var array = Array.from(e.target.files);
|
|
352
|
+
var toReturn = [];
|
|
353
|
+
array.forEach(function (item) {
|
|
354
|
+
toReturn.push(URL.createObjectURL(item));
|
|
355
|
+
});
|
|
356
|
+
dispatch({
|
|
357
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_INPUT_IMAGES,
|
|
358
|
+
payload: { key: 'images', value: toReturn },
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
var handleChange = function (key, value) {
|
|
362
|
+
dispatch({
|
|
363
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
364
|
+
payload: { key: key, value: String(value).trim(), },
|
|
365
|
+
});
|
|
366
|
+
dispatch({
|
|
367
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_DISABLE_SAVE_BUTTON,
|
|
368
|
+
payload: { disableSaveButton: false },
|
|
369
|
+
});
|
|
370
|
+
dispatch({
|
|
371
|
+
type: actions_1.PRODUCT_ACTION_TYPES.CLEAR_ERRORS,
|
|
372
|
+
});
|
|
373
|
+
};
|
|
374
|
+
var handleSelectInputChange = (0, react_1.useCallback)(function (key, value) { return __awaiter(void 0, void 0, void 0, function () {
|
|
375
|
+
var response, result;
|
|
376
|
+
return __generator(this, function (_a) {
|
|
377
|
+
switch (_a.label) {
|
|
378
|
+
case 0: return [4 /*yield*/, fetch(constants_2.PRODUCT_CATEGORY_API_ROUTES.PRODUCT_CATEGORIES, {
|
|
379
|
+
method: util_functions_1.API_METHODS.POST,
|
|
380
|
+
body: JSON.stringify({
|
|
381
|
+
searchQuery: debouncedList,
|
|
382
|
+
pageLimit: 1000,
|
|
383
|
+
currentPage: 1,
|
|
384
|
+
}),
|
|
385
|
+
})];
|
|
386
|
+
case 1:
|
|
387
|
+
response = _a.sent();
|
|
388
|
+
return [4 /*yield*/, response.json()];
|
|
389
|
+
case 2:
|
|
390
|
+
result = _a.sent();
|
|
391
|
+
dispatch({
|
|
392
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_PRODUCT_CATEGORIES,
|
|
393
|
+
payload: { productCategories: result },
|
|
394
|
+
});
|
|
395
|
+
dispatch({
|
|
396
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_PRODUCT_CATEGORY_QUERY,
|
|
397
|
+
payload: { productCategoryQuery: value },
|
|
398
|
+
});
|
|
399
|
+
return [2 /*return*/];
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}); }, [debouncedList]);
|
|
403
|
+
var handleSelectChange = function (key, value) {
|
|
404
|
+
var val = __assign({}, value);
|
|
405
|
+
if (key === 'currency') {
|
|
406
|
+
dispatch({
|
|
407
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
408
|
+
payload: {
|
|
409
|
+
key: key,
|
|
410
|
+
value: val['option'],
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
415
|
+
dispatch({
|
|
416
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
417
|
+
payload: {
|
|
418
|
+
key: key,
|
|
419
|
+
value: val['id'],
|
|
420
|
+
},
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
var handleNextClick = function () {
|
|
424
|
+
dispatch({
|
|
425
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
426
|
+
payload: { currentPage: state.currentPage + 1 },
|
|
427
|
+
});
|
|
428
|
+
};
|
|
429
|
+
var handlePreviousClick = function () {
|
|
430
|
+
dispatch({
|
|
431
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_CURRENT_PAGE,
|
|
432
|
+
payload: { currentPage: state.currentPage - 1 },
|
|
433
|
+
});
|
|
434
|
+
};
|
|
435
|
+
var handlePageLimit = function (node, value) {
|
|
436
|
+
dispatch({
|
|
437
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_PAGE_LIMIT,
|
|
438
|
+
payload: { pageLimit: Number(value.option) },
|
|
439
|
+
});
|
|
440
|
+
};
|
|
441
|
+
var searchOnChange = function (k, v) {
|
|
442
|
+
dispatch({
|
|
443
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_SEARCH_QUERY,
|
|
444
|
+
payload: { searchQuery: v },
|
|
445
|
+
});
|
|
446
|
+
};
|
|
447
|
+
var clearSearch = function () {
|
|
448
|
+
dispatch({
|
|
449
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_SEARCH_QUERY,
|
|
450
|
+
payload: { searchQuery: '' },
|
|
451
|
+
});
|
|
452
|
+
};
|
|
453
|
+
var closeDrawer = function () {
|
|
454
|
+
dispatch({
|
|
455
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_DRAWER,
|
|
456
|
+
payload: { drawer: null },
|
|
457
|
+
});
|
|
458
|
+
dispatch({
|
|
459
|
+
type: actions_1.PRODUCT_ACTION_TYPES.RESET_FORM,
|
|
460
|
+
});
|
|
461
|
+
dispatch({
|
|
462
|
+
type: actions_1.PRODUCT_ACTION_TYPES.CLEAR_ERRORS,
|
|
463
|
+
});
|
|
464
|
+
};
|
|
465
|
+
var dynamicFormElements = (0, react_1.useMemo)(function () {
|
|
466
|
+
var _a, _b, _c, _d, _e;
|
|
467
|
+
var elements = __assign({}, constants_1.staticFormElements);
|
|
468
|
+
var textInputElements = (_a = elements[form_schema_1.VISTA_FORM_ELEMENTS.TEXT_INPUT_V1]) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return a.order - b.order; });
|
|
469
|
+
if (textInputElements) {
|
|
470
|
+
textInputElements === null || textInputElements === void 0 ? void 0 : textInputElements.map(function (_a, i) {
|
|
471
|
+
var id = _a.id;
|
|
472
|
+
textInputElements[i].value = state[id];
|
|
473
|
+
textInputElements[i].handleOnChange = handleChange;
|
|
474
|
+
textInputElements[i].error = state.errors[id];
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
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; });
|
|
478
|
+
if (textAreaElements) {
|
|
479
|
+
textAreaElements === null || textAreaElements === void 0 ? void 0 : textAreaElements.forEach(function (_a, i) {
|
|
480
|
+
var id = _a.id;
|
|
481
|
+
textAreaElements[i].value = state[id];
|
|
482
|
+
textAreaElements[i].handleOnChange = handleChange;
|
|
483
|
+
textAreaElements[i].error = state.errors.description;
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
var selectElements = (_c = elements[form_schema_1.VISTA_FORM_ELEMENTS.SELECT_V1]) === null || _c === void 0 ? void 0 : _c.sort(function (a, b) { return a.order - b.order; });
|
|
487
|
+
if (selectElements) {
|
|
488
|
+
selectElements === null || selectElements === void 0 ? void 0 : selectElements.forEach(function (_a, i) {
|
|
489
|
+
var nodeSelectKey = _a.nodeSelectKey;
|
|
490
|
+
selectElements[i].handleOnChange = handleSelectChange;
|
|
491
|
+
selectElements[i].selectedItem = { option: state[nodeSelectKey] };
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
var comboboxElements = (_d = elements[form_schema_1.VISTA_FORM_ELEMENTS.COMBOBOX_V1]) === null || _d === void 0 ? void 0 : _d.sort(function (a, b) { return a.order - b.order; });
|
|
495
|
+
if (comboboxElements) {
|
|
496
|
+
comboboxElements === null || comboboxElements === void 0 ? void 0 : comboboxElements.forEach(function (_a, i) {
|
|
497
|
+
var nodeSelectKey = _a.nodeSelectKey;
|
|
498
|
+
comboboxElements[i].handleOnChange = handleSelectChange;
|
|
499
|
+
comboboxElements[i].selectedItem = { id: state[nodeSelectKey] };
|
|
500
|
+
comboboxElements[i].listItems = productCategories.map(function (item) { return (__assign(__assign({}, item), { option: item.name })); });
|
|
501
|
+
comboboxElements[i].query = state.productCategoryQuery;
|
|
502
|
+
comboboxElements[i].handleInputOnChange = handleSelectInputChange;
|
|
503
|
+
comboboxElements[i].handleOnBlur = handleSelectInputChange;
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
var uploadElements = (_e = elements[form_schema_1.VISTA_FORM_ELEMENTS.UPLOAD_V1]) === null || _e === void 0 ? void 0 : _e.sort(function (a, b) { return a.order - b.order; });
|
|
507
|
+
if (uploadElements) {
|
|
508
|
+
uploadElements === null || uploadElements === void 0 ? void 0 : uploadElements.forEach(function (_, i) {
|
|
509
|
+
uploadElements[i].imageUrls = state.images;
|
|
510
|
+
uploadElements[i].handleOnChange = handleFileChange;
|
|
511
|
+
uploadElements[i].handleClearImage = function () { return dispatch({
|
|
512
|
+
type: actions_1.PRODUCT_ACTION_TYPES.SET_INPUT_FIELD,
|
|
513
|
+
payload: { key: 'images', value: [] },
|
|
514
|
+
}); };
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
return elements;
|
|
518
|
+
}, [state, productCategories, handleSelectInputChange]);
|
|
519
|
+
var headerActions = [
|
|
520
|
+
{
|
|
521
|
+
enabled: true,
|
|
522
|
+
handleOnClick: handleCreate,
|
|
523
|
+
label: 'Add Item',
|
|
524
|
+
order: 1,
|
|
525
|
+
},
|
|
526
|
+
];
|
|
527
|
+
var rowActions = [
|
|
528
|
+
{
|
|
529
|
+
enabled: true,
|
|
530
|
+
handleAction: function (id) { return handleEdit(id); },
|
|
531
|
+
label: 'Edit',
|
|
532
|
+
order: 1,
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
enabled: true,
|
|
536
|
+
handleAction: function (id) { return handleDelete(id); },
|
|
537
|
+
label: 'Delete',
|
|
538
|
+
order: 2,
|
|
539
|
+
},
|
|
540
|
+
];
|
|
541
|
+
return __assign(__assign({}, state), { byIdError: byIdError, byIdLoading: byIdLoading, clearSearch: clearSearch, closeDrawer: closeDrawer, deleteError: deleteError, deleteLoading: deleteLoading, dispatch: dispatch, dynamicFormElements: dynamicFormElements, handleChange: handleChange, handleNextClick: handleNextClick, handlePageLimit: handlePageLimit, handlePreviousClick: handlePreviousClick, handleSubmit: handleSubmit, handleUploadImage: handleUploadImage, headerActions: headerActions, listError: listError, listFetchNow: listFetchNow, listLoading: listLoading, rowActions: rowActions, searchOnChange: searchOnChange, updateError: updateError, updateLoading: updateLoading });
|
|
542
|
+
};
|
|
543
|
+
exports.ProductStateContext = (0, react_1.createContext)(__assign(__assign({}, reducer_1.initialProductState), { byIdError: undefined, byIdLoading: false, clearSearch: function () { return void 0; }, closeDrawer: function () { return void 0; }, deleteError: undefined, deleteLoading: false, dispatch: function () { return void 0; }, dynamicFormElements: {}, handleChange: function () { return void 0; }, handleNextClick: function () { return void 0; }, handlePageLimit: function () { return void 0; }, handlePreviousClick: function () { return void 0; }, handleSubmit: function () { return void 0; }, handleUploadImage: function () { return void 0; }, headerActions: [], listError: undefined, listFetchNow: function () { return void 0; }, listLoading: false, rowActions: [], searchOnChange: function () { return void 0; }, updateError: undefined, updateLoading: false }));
|
|
544
|
+
var ProductStateContextProvider = function (_a) {
|
|
545
|
+
var children = _a.children;
|
|
546
|
+
var state = useProductState();
|
|
547
|
+
return (react_1.default.createElement(exports.ProductStateContext.Provider, { value: state }, children));
|
|
548
|
+
};
|
|
549
|
+
exports.ProductStateContextProvider = ProductStateContextProvider;
|
|
550
|
+
var useProductStateContext = function () {
|
|
551
|
+
var state = (0, react_1.useContext)(exports.ProductStateContext);
|
|
552
|
+
if (state === undefined) {
|
|
553
|
+
throw new Error('useProductStateContext must be used within an ProductContextProvider');
|
|
554
|
+
}
|
|
555
|
+
return state;
|
|
556
|
+
};
|
|
557
|
+
exports.useProductStateContext = useProductStateContext;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Drawer = void 0;
|
|
7
|
+
var react_1 = __importDefault(require("react"));
|
|
8
|
+
var vista_drawer_v1_1 = require("@appcorp/app-corp-vista/molecules/vista-drawer-v1/vista-drawer-v1");
|
|
9
|
+
var vista_drawer_type_1 = require("@appcorp/app-corp-vista/type/vista-drawer-type");
|
|
10
|
+
var vista_button_type_1 = require("@appcorp/app-corp-vista/type/vista-button-type");
|
|
11
|
+
var context_1 = require("./context");
|
|
12
|
+
var form_1 = require("./form");
|
|
13
|
+
var Drawer = function (_a) {
|
|
14
|
+
var translationMap = _a.translationMap;
|
|
15
|
+
var _b = (0, context_1.useProductStateContext)(), closeDrawer = _b.closeDrawer, disableSaveButton = _b.disableSaveButton, drawer = _b.drawer, handleSubmit = _b.handleSubmit;
|
|
16
|
+
return (react_1.default.createElement(vista_drawer_v1_1.VistaDrawerV1, { cancelLabel: "Cancel", cancelRounded: vista_button_type_1.VISTA_BUTTON_ROUNDED.MD, cancelSize: vista_button_type_1.VISTA_BUTTON_SIZE.LG, handleCancelOnClick: closeDrawer, handleSaveOnClick: handleSubmit, handleSetIsOpen: closeDrawer, isOpen: !!drawer, saveDisabled: disableSaveButton, saveLabel: 'Save', saveRounded: vista_button_type_1.VISTA_BUTTON_ROUNDED.MD, saveSize: vista_button_type_1.VISTA_BUTTON_SIZE.LG, size: vista_drawer_type_1.VISTA_DRAWER_SIZE.MD, title: 'Product' },
|
|
17
|
+
react_1.default.createElement(form_1.ProductForm, { translationMap: translationMap })));
|
|
18
|
+
};
|
|
19
|
+
exports.Drawer = Drawer;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
var __assign = (this && this.__assign) || function () {
|
|
4
|
+
__assign = Object.assign || function(t) {
|
|
5
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
+
s = arguments[i];
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
8
|
+
t[p] = s[p];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
return __assign.apply(this, arguments);
|
|
13
|
+
};
|
|
14
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
15
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
16
|
+
};
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.renderProductFormElements = void 0;
|
|
19
|
+
var react_1 = __importDefault(require("react"));
|
|
20
|
+
var form_schema_1 = require("@appcorp/app-corp-vista/utils/form-schema");
|
|
21
|
+
var renderProductFormElements = function (elementProps) {
|
|
22
|
+
var _a;
|
|
23
|
+
var elementsArray = (_a = Object.entries(form_schema_1.vistaFormSchema)
|
|
24
|
+
.flatMap(function (_a) {
|
|
25
|
+
var _b, _c;
|
|
26
|
+
var key = _a[0], config = _a[1];
|
|
27
|
+
var Component = config;
|
|
28
|
+
return (_c = (_b = (elementProps[key] || [])) === null || _b === void 0 ? void 0 : _b.filter(function (props) { return props.enabled; })) === null || _c === void 0 ? void 0 : _c.map(function (props) { return ({
|
|
29
|
+
Component: Component,
|
|
30
|
+
key: key,
|
|
31
|
+
order: props.order,
|
|
32
|
+
props: props,
|
|
33
|
+
}); });
|
|
34
|
+
})) === null || _a === void 0 ? void 0 : _a.sort(function (a, b) { return a.order - b.order; });
|
|
35
|
+
return (react_1.default.createElement("div", { className: "grid grid-cols-1 gap-4" }, elementsArray === null || elementsArray === void 0 ? void 0 : elementsArray.map(function (_a, index) {
|
|
36
|
+
var key = _a.key, Component = _a.Component, props = _a.props;
|
|
37
|
+
return (react_1.default.createElement("div", { key: "".concat(key, "-").concat(index) },
|
|
38
|
+
react_1.default.createElement(Component, __assign({}, props))));
|
|
39
|
+
})));
|
|
40
|
+
};
|
|
41
|
+
exports.renderProductFormElements = renderProductFormElements;
|