@agrada_digital/pbm 0.0.49 → 0.0.51
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/dist/index.d.mts +7 -42
- package/dist/index.d.ts +7 -42
- package/dist/index.js +101 -103
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +86 -88
- package/dist/index.mjs.map +1 -1
- package/dist-wc/pbm-wc.js +81 -81
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as zustand from 'zustand';
|
|
3
|
-
import { StoreApi } from 'zustand';
|
|
4
2
|
|
|
5
3
|
interface PBMProps {
|
|
6
|
-
originalProductPrice: number;
|
|
7
|
-
industryLogo
|
|
4
|
+
originalProductPrice: number | string;
|
|
5
|
+
industryLogo?: string;
|
|
8
6
|
clientID: string;
|
|
9
7
|
eanProduct: string;
|
|
10
8
|
}
|
|
@@ -23,45 +21,11 @@ interface usePBMTypes {
|
|
|
23
21
|
totalPrice: number;
|
|
24
22
|
};
|
|
25
23
|
campaign: "pbm_campaign";
|
|
26
|
-
targetProduct:
|
|
24
|
+
targetProduct: IProduct | null;
|
|
27
25
|
}
|
|
28
|
-
interface
|
|
29
|
-
name: string;
|
|
30
|
-
presentationId: string;
|
|
31
|
-
presentation: string;
|
|
32
|
-
maximumPrice: number;
|
|
33
|
-
salePrice: number;
|
|
34
|
-
discountPercent: number;
|
|
35
|
-
comboAvailable: boolean;
|
|
36
|
-
progressiveDiscount: boolean;
|
|
37
|
-
replacementIndustryPrice: number;
|
|
38
|
-
replacementPurchasePrice: number;
|
|
39
|
-
replacementIndustryDiscount: number;
|
|
40
|
-
commercialGradeId: number;
|
|
41
|
-
commercialGrade: string;
|
|
42
|
-
calculationRuleTypeId: number;
|
|
43
|
-
calculationRuleType: string;
|
|
44
|
-
}
|
|
45
|
-
interface ITargetProductPBM {
|
|
46
|
-
productId: string;
|
|
26
|
+
interface IProduct {
|
|
47
27
|
ean: string;
|
|
48
|
-
|
|
49
|
-
name: string;
|
|
50
|
-
stock: number;
|
|
51
|
-
listPrice: number;
|
|
52
|
-
salesPrice: number;
|
|
53
|
-
availabilityText: string;
|
|
54
|
-
discountMin: number;
|
|
55
|
-
discountMaxNewPatient: number;
|
|
56
|
-
discountMax: number;
|
|
57
|
-
industryName: string;
|
|
58
|
-
informativeMessage: string;
|
|
59
|
-
authorizer: string;
|
|
60
|
-
discountMinNewPatient: number;
|
|
61
|
-
qtyForDiscountMax: number;
|
|
62
|
-
programName: string;
|
|
63
|
-
dataSource: string;
|
|
64
|
-
epharma: IEpharma;
|
|
28
|
+
quantity: number;
|
|
65
29
|
}
|
|
66
30
|
|
|
67
31
|
interface PBMStore extends usePBMTypes {
|
|
@@ -70,6 +34,7 @@ interface PBMStore extends usePBMTypes {
|
|
|
70
34
|
setAvailableDiscountSelected: (availableDiscount: usePBMTypes["availableDiscountSelected"]) => void;
|
|
71
35
|
setTargetProduct: (targetProduct: usePBMTypes["targetProduct"]) => void;
|
|
72
36
|
}
|
|
73
|
-
declare
|
|
37
|
+
declare function usePBMStore(): PBMStore;
|
|
38
|
+
declare function usePBMStore<T>(selector: (state: PBMStore) => T): T;
|
|
74
39
|
|
|
75
40
|
export { PBM, type PBMProps, type PBMStore, usePBMStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import * as zustand from 'zustand';
|
|
3
|
-
import { StoreApi } from 'zustand';
|
|
4
2
|
|
|
5
3
|
interface PBMProps {
|
|
6
|
-
originalProductPrice: number;
|
|
7
|
-
industryLogo
|
|
4
|
+
originalProductPrice: number | string;
|
|
5
|
+
industryLogo?: string;
|
|
8
6
|
clientID: string;
|
|
9
7
|
eanProduct: string;
|
|
10
8
|
}
|
|
@@ -23,45 +21,11 @@ interface usePBMTypes {
|
|
|
23
21
|
totalPrice: number;
|
|
24
22
|
};
|
|
25
23
|
campaign: "pbm_campaign";
|
|
26
|
-
targetProduct:
|
|
24
|
+
targetProduct: IProduct | null;
|
|
27
25
|
}
|
|
28
|
-
interface
|
|
29
|
-
name: string;
|
|
30
|
-
presentationId: string;
|
|
31
|
-
presentation: string;
|
|
32
|
-
maximumPrice: number;
|
|
33
|
-
salePrice: number;
|
|
34
|
-
discountPercent: number;
|
|
35
|
-
comboAvailable: boolean;
|
|
36
|
-
progressiveDiscount: boolean;
|
|
37
|
-
replacementIndustryPrice: number;
|
|
38
|
-
replacementPurchasePrice: number;
|
|
39
|
-
replacementIndustryDiscount: number;
|
|
40
|
-
commercialGradeId: number;
|
|
41
|
-
commercialGrade: string;
|
|
42
|
-
calculationRuleTypeId: number;
|
|
43
|
-
calculationRuleType: string;
|
|
44
|
-
}
|
|
45
|
-
interface ITargetProductPBM {
|
|
46
|
-
productId: string;
|
|
26
|
+
interface IProduct {
|
|
47
27
|
ean: string;
|
|
48
|
-
|
|
49
|
-
name: string;
|
|
50
|
-
stock: number;
|
|
51
|
-
listPrice: number;
|
|
52
|
-
salesPrice: number;
|
|
53
|
-
availabilityText: string;
|
|
54
|
-
discountMin: number;
|
|
55
|
-
discountMaxNewPatient: number;
|
|
56
|
-
discountMax: number;
|
|
57
|
-
industryName: string;
|
|
58
|
-
informativeMessage: string;
|
|
59
|
-
authorizer: string;
|
|
60
|
-
discountMinNewPatient: number;
|
|
61
|
-
qtyForDiscountMax: number;
|
|
62
|
-
programName: string;
|
|
63
|
-
dataSource: string;
|
|
64
|
-
epharma: IEpharma;
|
|
28
|
+
quantity: number;
|
|
65
29
|
}
|
|
66
30
|
|
|
67
31
|
interface PBMStore extends usePBMTypes {
|
|
@@ -70,6 +34,7 @@ interface PBMStore extends usePBMTypes {
|
|
|
70
34
|
setAvailableDiscountSelected: (availableDiscount: usePBMTypes["availableDiscountSelected"]) => void;
|
|
71
35
|
setTargetProduct: (targetProduct: usePBMTypes["targetProduct"]) => void;
|
|
72
36
|
}
|
|
73
|
-
declare
|
|
37
|
+
declare function usePBMStore(): PBMStore;
|
|
38
|
+
declare function usePBMStore<T>(selector: (state: PBMStore) => T): T;
|
|
74
39
|
|
|
75
40
|
export { PBM, type PBMProps, type PBMStore, usePBMStore };
|
package/dist/index.js
CHANGED
|
@@ -89,9 +89,10 @@ function Container({
|
|
|
89
89
|
var Container_default = Container;
|
|
90
90
|
|
|
91
91
|
// src/components/Footer/index.tsx
|
|
92
|
+
var import_classnames2 = __toESM(require("classnames"));
|
|
92
93
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
93
94
|
function Footer({ industryLogo }) {
|
|
94
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("footer", { className: "w-full h-auto relative", id: "footer_pbm", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "flex items-center
|
|
95
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("footer", { className: "w-full h-auto relative", id: "footer_pbm", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: (0, import_classnames2.default)("flex items-center w-full h-auto gap-4", { "justify-center": industryLogo, "justify-start": !industryLogo }), children: [
|
|
95
96
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "w-4/5 h-auto", children: [
|
|
96
97
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "text-start font-semibold text-sm", children: "Economize com o benef\xEDcio do laborat\xF3rio." }),
|
|
97
98
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "text-start font-normal text-sm", children: "Este produto tem pre\xE7o exclusivo para clientes cadastrados no programa." })
|
|
@@ -134,13 +135,14 @@ var toFormat = (value) => {
|
|
|
134
135
|
};
|
|
135
136
|
|
|
136
137
|
// src/components/Form/index.tsx
|
|
137
|
-
var
|
|
138
|
+
var import_classnames3 = __toESM(require("classnames"));
|
|
138
139
|
var import_zod2 = require("@hookform/resolvers/zod");
|
|
139
140
|
var import_react_hook_form = require("react-hook-form");
|
|
140
141
|
var import_lucide_react = require("lucide-react");
|
|
141
142
|
|
|
142
143
|
// src/libs/zustand/usePBM.tsx
|
|
143
144
|
var import_zustand = require("zustand");
|
|
145
|
+
var import_react = require("zustand/react");
|
|
144
146
|
var initialPBMState = {
|
|
145
147
|
securityNumber: "",
|
|
146
148
|
state: "isEmpty",
|
|
@@ -162,13 +164,45 @@ var createPBMStore = (set) => ({
|
|
|
162
164
|
setTargetProduct: (targetProduct) => set({ targetProduct }),
|
|
163
165
|
setAvailableDiscountSelected: (availableDiscount) => set({ availableDiscountSelected: availableDiscount })
|
|
164
166
|
});
|
|
165
|
-
var usePBMStore = (0, import_zustand.create)(createPBMStore);
|
|
166
167
|
var pbmStore = (0, import_zustand.createStore)(createPBMStore);
|
|
168
|
+
function usePBMStore(selector) {
|
|
169
|
+
if (selector) {
|
|
170
|
+
return (0, import_react.useStore)(pbmStore, selector);
|
|
171
|
+
}
|
|
172
|
+
return (0, import_react.useStore)(pbmStore, (state) => state);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/services/validate-document.ts
|
|
176
|
+
var import_js_cookie = __toESM(require("js-cookie"));
|
|
177
|
+
var import_meta = {};
|
|
178
|
+
var ValidateDocument = async ({ document, products }) => {
|
|
179
|
+
const API_URL = import_meta.env.VITE_API_URL;
|
|
180
|
+
if (!API_URL) {
|
|
181
|
+
throw new Error("API URL is not defined in environment variables");
|
|
182
|
+
}
|
|
183
|
+
const AUTH_TOKEN = import_js_cookie.default.get("pbm-token");
|
|
184
|
+
if (!AUTH_TOKEN) {
|
|
185
|
+
throw new Error("Token is not defined in cookies or is expired");
|
|
186
|
+
}
|
|
187
|
+
const response = await fetch(`${API_URL}/transactions/validate`, {
|
|
188
|
+
method: "POST",
|
|
189
|
+
headers: {
|
|
190
|
+
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
191
|
+
"Content-Type": "application/json"
|
|
192
|
+
},
|
|
193
|
+
body: JSON.stringify({ document, products })
|
|
194
|
+
});
|
|
195
|
+
const dataResponse = await response.json();
|
|
196
|
+
if (!dataResponse.success) {
|
|
197
|
+
throw new Error(dataResponse.message || "Failed to fetch document validation");
|
|
198
|
+
}
|
|
199
|
+
return dataResponse;
|
|
200
|
+
};
|
|
167
201
|
|
|
168
202
|
// src/components/Form/index.tsx
|
|
169
203
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
170
204
|
function Form({ setLoading }) {
|
|
171
|
-
const { setSecurityNumber, setState, securityNumber } = usePBMStore();
|
|
205
|
+
const { setSecurityNumber, setState, securityNumber, targetProduct } = usePBMStore();
|
|
172
206
|
const {
|
|
173
207
|
handleSubmit,
|
|
174
208
|
register,
|
|
@@ -180,28 +214,37 @@ function Form({ setLoading }) {
|
|
|
180
214
|
securityNumber: securityNumber || ""
|
|
181
215
|
}
|
|
182
216
|
});
|
|
183
|
-
const onSubmitDefault = (values) => {
|
|
217
|
+
const onSubmitDefault = async (values) => {
|
|
184
218
|
setLoading(true);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
219
|
+
try {
|
|
220
|
+
if (targetProduct === null) {
|
|
221
|
+
console.error("Product is not defined!");
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const response = await ValidateDocument({
|
|
225
|
+
document: values.securityNumber.replace(/\D/g, ""),
|
|
226
|
+
products: [{ ean: targetProduct.ean, quantity: targetProduct.quantity }]
|
|
227
|
+
});
|
|
228
|
+
if (response.success) {
|
|
229
|
+
const status = {
|
|
230
|
+
"active": "isActivated",
|
|
231
|
+
"nonexistent": "isInvalid"
|
|
232
|
+
};
|
|
233
|
+
setSecurityNumber(values.securityNumber);
|
|
234
|
+
setState(status[response.data.process_platform.status]);
|
|
235
|
+
}
|
|
236
|
+
} catch (error) {
|
|
237
|
+
console.error("Error validating document:", error);
|
|
238
|
+
} finally {
|
|
197
239
|
setLoading(false);
|
|
198
|
-
}
|
|
240
|
+
}
|
|
241
|
+
;
|
|
199
242
|
};
|
|
200
243
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
201
244
|
"form",
|
|
202
245
|
{
|
|
203
246
|
onSubmit: handleSubmit(onSubmitDefault),
|
|
204
|
-
className: (0,
|
|
247
|
+
className: (0, import_classnames3.default)(
|
|
205
248
|
"w-full h-auto flex items-center justify-center mb-0 transition-all duration-150",
|
|
206
249
|
{ "mb-4": errors.securityNumber }
|
|
207
250
|
),
|
|
@@ -218,7 +261,7 @@ function Form({ setLoading }) {
|
|
|
218
261
|
"input",
|
|
219
262
|
{
|
|
220
263
|
type: "text",
|
|
221
|
-
className: (0,
|
|
264
|
+
className: (0, import_classnames3.default)(
|
|
222
265
|
"w-full h-8 bg-[#44c2c0]/20 rounded-s-full text-sm font-semibold focus:outline focus:outline-[#339c9b] focus:bg-[#44c2c0]/30 text-zinc-600 placeholder:text-zinc-600 px-4 placeholder:text-sm placeholder:font-semibold",
|
|
223
266
|
{ "outline outline-red-600": errors.securityNumber }
|
|
224
267
|
),
|
|
@@ -282,14 +325,14 @@ function Loading({ textColor }) {
|
|
|
282
325
|
var Loading_default = Loading;
|
|
283
326
|
|
|
284
327
|
// src/components/UI/Button/index.tsx
|
|
285
|
-
var
|
|
328
|
+
var import_classnames4 = __toESM(require("classnames"));
|
|
286
329
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
287
330
|
function Button(props) {
|
|
288
331
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
289
332
|
"button",
|
|
290
333
|
{
|
|
291
334
|
...props,
|
|
292
|
-
className: (0,
|
|
335
|
+
className: (0, import_classnames4.default)(
|
|
293
336
|
"w-3xs cursor-pointer h-10 rounded-full bg-blue-500 hover:bg-blue-400 text-white text-sm font-semibold transition-colors",
|
|
294
337
|
props.className
|
|
295
338
|
),
|
|
@@ -300,7 +343,7 @@ function Button(props) {
|
|
|
300
343
|
var Button_default = Button;
|
|
301
344
|
|
|
302
345
|
// src/components/BenefitsTable/index.tsx
|
|
303
|
-
var
|
|
346
|
+
var import_react3 = require("react");
|
|
304
347
|
|
|
305
348
|
// src/mocks/benefits.ts
|
|
306
349
|
var BENEFITS_ITEMS = [
|
|
@@ -328,13 +371,13 @@ var BENEFITS_ITEMS = [
|
|
|
328
371
|
];
|
|
329
372
|
|
|
330
373
|
// src/components/UI/Title/index.tsx
|
|
331
|
-
var
|
|
374
|
+
var import_classnames5 = __toESM(require("classnames"));
|
|
332
375
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
333
376
|
function Title(props) {
|
|
334
377
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
335
378
|
"h2",
|
|
336
379
|
{
|
|
337
|
-
className: (0,
|
|
380
|
+
className: (0, import_classnames5.default)(
|
|
338
381
|
"text-start font-semibold text-sm text-zinc-900",
|
|
339
382
|
props.className
|
|
340
383
|
),
|
|
@@ -349,7 +392,7 @@ var Title_default = Title;
|
|
|
349
392
|
|
|
350
393
|
// src/components/BenefitsTable/Item.tsx
|
|
351
394
|
var import_lucide_react2 = require("lucide-react");
|
|
352
|
-
var
|
|
395
|
+
var import_react2 = require("react");
|
|
353
396
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
354
397
|
function Item({ data, onChange, checked, originalProductPrice }) {
|
|
355
398
|
const { setAvailableDiscountSelected, securityNumber } = usePBMStore();
|
|
@@ -358,7 +401,7 @@ function Item({ data, onChange, checked, originalProductPrice }) {
|
|
|
358
401
|
const unitDiscountValue = originalProductPrice * decimalDiscount;
|
|
359
402
|
const discountValue = unitDiscountValue * data.authorizedQuantity;
|
|
360
403
|
const totalPriceProductWithDiscountBenefit = originalProductPrice * data.authorizedQuantity - discountValue;
|
|
361
|
-
const updateStorageData = (0,
|
|
404
|
+
const updateStorageData = (0, import_react2.useCallback)(() => {
|
|
362
405
|
if (checked) {
|
|
363
406
|
setAvailableDiscountSelected({
|
|
364
407
|
discount: {
|
|
@@ -377,7 +420,7 @@ function Item({ data, onChange, checked, originalProductPrice }) {
|
|
|
377
420
|
totalPriceProductWithDiscountBenefit,
|
|
378
421
|
unitDiscountValue
|
|
379
422
|
]);
|
|
380
|
-
(0,
|
|
423
|
+
(0, import_react2.useEffect)(() => {
|
|
381
424
|
updateStorageData();
|
|
382
425
|
}, [updateStorageData]);
|
|
383
426
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
@@ -434,7 +477,7 @@ function BenefitsTable({
|
|
|
434
477
|
originalProductPrice
|
|
435
478
|
}) {
|
|
436
479
|
const { securityNumber, setState } = usePBMStore();
|
|
437
|
-
const [selectedDiscout, setSelectedDiscount] = (0,
|
|
480
|
+
const [selectedDiscout, setSelectedDiscount] = (0, import_react3.useState)(null);
|
|
438
481
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
439
482
|
"section",
|
|
440
483
|
{
|
|
@@ -491,13 +534,13 @@ function BenefitsTable({
|
|
|
491
534
|
var BenefitsTable_default = BenefitsTable;
|
|
492
535
|
|
|
493
536
|
// src/components/UI/Text/index.tsx
|
|
494
|
-
var
|
|
537
|
+
var import_classnames6 = __toESM(require("classnames"));
|
|
495
538
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
496
539
|
function Text(props) {
|
|
497
540
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
498
541
|
"p",
|
|
499
542
|
{
|
|
500
|
-
className: (0,
|
|
543
|
+
className: (0, import_classnames6.default)(
|
|
501
544
|
"text-start font-normal text-sm text-zinc-900",
|
|
502
545
|
props.className
|
|
503
546
|
),
|
|
@@ -511,14 +554,14 @@ function Text(props) {
|
|
|
511
554
|
var Text_default = Text;
|
|
512
555
|
|
|
513
556
|
// src/components/Iframe/index.tsx
|
|
514
|
-
var
|
|
557
|
+
var import_classnames7 = __toESM(require("classnames"));
|
|
515
558
|
var import_lucide_react3 = require("lucide-react");
|
|
516
559
|
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
517
560
|
function Iframe({ url, title, openModal, setOpenModal }) {
|
|
518
561
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
|
|
519
562
|
"main",
|
|
520
563
|
{
|
|
521
|
-
className: (0,
|
|
564
|
+
className: (0, import_classnames7.default)(
|
|
522
565
|
"fixed inset-0 flex items-center justify-center z-50 flex-col transition-all shadow",
|
|
523
566
|
{
|
|
524
567
|
"opacity-100 pointer-events-auto": openModal,
|
|
@@ -578,10 +621,10 @@ function Iframe({ url, title, openModal, setOpenModal }) {
|
|
|
578
621
|
var Iframe_default = Iframe;
|
|
579
622
|
|
|
580
623
|
// src/components/SecurityNumberInvalid/index.tsx
|
|
581
|
-
var
|
|
624
|
+
var import_react4 = require("react");
|
|
582
625
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
583
626
|
function SecurityNumberInvalid({ textColor }) {
|
|
584
|
-
const [openModal, setOpenModal] = (0,
|
|
627
|
+
const [openModal, setOpenModal] = (0, import_react4.useState)(false);
|
|
585
628
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
586
629
|
"section",
|
|
587
630
|
{
|
|
@@ -616,10 +659,10 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
616
659
|
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
617
660
|
|
|
618
661
|
// src/PBM.tsx
|
|
619
|
-
var
|
|
662
|
+
var import_react5 = require("react");
|
|
620
663
|
|
|
621
664
|
// src/components/UI/Link/index.tsx
|
|
622
|
-
var
|
|
665
|
+
var import_classnames8 = __toESM(require("classnames"));
|
|
623
666
|
|
|
624
667
|
// src/utils/getParams.ts
|
|
625
668
|
var getParams = (params) => {
|
|
@@ -636,7 +679,7 @@ function Link(props) {
|
|
|
636
679
|
...props,
|
|
637
680
|
target: "_blank",
|
|
638
681
|
href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
|
|
639
|
-
className: (0,
|
|
682
|
+
className: (0, import_classnames8.default)(
|
|
640
683
|
"w-3xs cursor-pointer h-10 rounded-full bg-blue-500 hover:bg-blue-400 text-white text-sm font-semibold transition-colors flex items-center justify-center",
|
|
641
684
|
props.className
|
|
642
685
|
),
|
|
@@ -677,12 +720,12 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
677
720
|
var SecurityNumberRegitered_default = SecurityNumberRegitered;
|
|
678
721
|
|
|
679
722
|
// src/services/authorization.ts
|
|
680
|
-
var
|
|
681
|
-
var
|
|
723
|
+
var import_js_cookie2 = __toESM(require("js-cookie"));
|
|
724
|
+
var import_meta2 = {};
|
|
682
725
|
var GetAuthorization = async ({ clientID }) => {
|
|
683
|
-
const API_URL =
|
|
684
|
-
const STORE_ID =
|
|
685
|
-
const STORE_NAME =
|
|
726
|
+
const API_URL = import_meta2.env.VITE_API_URL;
|
|
727
|
+
const STORE_ID = import_meta2.env.VITE_STORE_ID;
|
|
728
|
+
const STORE_NAME = import_meta2.env.VITE_STORE_NAME;
|
|
686
729
|
if (!API_URL) {
|
|
687
730
|
throw new Error("API URL is not defined in environment variables");
|
|
688
731
|
}
|
|
@@ -704,12 +747,12 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
704
747
|
if (!dataResponse.success) {
|
|
705
748
|
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
706
749
|
}
|
|
707
|
-
|
|
750
|
+
import_js_cookie2.default.set("pbm-token", dataResponse.data.token, {
|
|
708
751
|
expires: parseInt(dataResponse.data.expiresIn, 10) / (60 * 60),
|
|
709
752
|
secure: true,
|
|
710
753
|
sameSite: "Strict"
|
|
711
754
|
});
|
|
712
|
-
|
|
755
|
+
import_js_cookie2.default.set("pbm-token-refresh", dataResponse.data.refreshToken, {
|
|
713
756
|
secure: true,
|
|
714
757
|
sameSite: "Strict"
|
|
715
758
|
});
|
|
@@ -718,42 +761,6 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
718
761
|
|
|
719
762
|
// src/PBM.tsx
|
|
720
763
|
var import_lucide_react4 = require("lucide-react");
|
|
721
|
-
|
|
722
|
-
// src/services/get-product-by-ean.ts
|
|
723
|
-
var import_js_cookie2 = __toESM(require("js-cookie"));
|
|
724
|
-
var import_meta2 = {};
|
|
725
|
-
var GetProductByEAN = async ({ PRODUCT_EAN }) => {
|
|
726
|
-
const API_URL = import_meta2.env.VITE_API_URL;
|
|
727
|
-
const AUTH_TOKEN = import_js_cookie2.default.get("pbm-token");
|
|
728
|
-
if (!AUTH_TOKEN) {
|
|
729
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
730
|
-
}
|
|
731
|
-
const response = await fetch(`${API_URL}/core/products?ean=${PRODUCT_EAN}`, {
|
|
732
|
-
method: "GET",
|
|
733
|
-
headers: {
|
|
734
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
735
|
-
"Content-Type": "application/json"
|
|
736
|
-
}
|
|
737
|
-
});
|
|
738
|
-
const dataResponse = await response.json();
|
|
739
|
-
if (!dataResponse.success) {
|
|
740
|
-
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
741
|
-
}
|
|
742
|
-
return dataResponse;
|
|
743
|
-
};
|
|
744
|
-
|
|
745
|
-
// src/libs/zustand/useTargetProduct.tsx
|
|
746
|
-
var import_zustand2 = require("zustand");
|
|
747
|
-
var initialTargetProductState = {
|
|
748
|
-
targetProductInternal: null
|
|
749
|
-
};
|
|
750
|
-
var createPBMStore2 = (set) => ({
|
|
751
|
-
...initialTargetProductState,
|
|
752
|
-
setTargetProductInternal: (targetProductInternal) => set({ targetProductInternal })
|
|
753
|
-
});
|
|
754
|
-
var useTargetProducts = (0, import_zustand2.create)(createPBMStore2);
|
|
755
|
-
|
|
756
|
-
// src/PBM.tsx
|
|
757
764
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
758
765
|
function PBM({
|
|
759
766
|
originalProductPrice,
|
|
@@ -761,38 +768,29 @@ function PBM({
|
|
|
761
768
|
clientID,
|
|
762
769
|
eanProduct
|
|
763
770
|
}) {
|
|
764
|
-
const
|
|
771
|
+
const formatedOriginalProductPrice = Number(
|
|
772
|
+
String(originalProductPrice).replace(",", ".")
|
|
773
|
+
);
|
|
774
|
+
const [loading, setLoading] = (0, import_react5.useState)(false);
|
|
765
775
|
const { setState, state, setTargetProduct } = usePBMStore();
|
|
766
|
-
const
|
|
767
|
-
const handleGetProductByEAN = (0, import_react4.useCallback)(async () => {
|
|
768
|
-
try {
|
|
769
|
-
const response = await GetProductByEAN({ PRODUCT_EAN: eanProduct });
|
|
770
|
-
if (response.success) {
|
|
771
|
-
const productByEan = response.data.message.products[0];
|
|
772
|
-
setTargetProduct(productByEan);
|
|
773
|
-
setTargetProductInternal(productByEan);
|
|
774
|
-
}
|
|
775
|
-
} catch (error) {
|
|
776
|
-
console.error(error);
|
|
777
|
-
}
|
|
778
|
-
}, [eanProduct, setTargetProduct, setTargetProductInternal]);
|
|
779
|
-
const handleAuthorizationRequest = (0, import_react4.useCallback)(async () => {
|
|
776
|
+
const handleAuthorizationRequest = (0, import_react5.useCallback)(async () => {
|
|
780
777
|
try {
|
|
781
778
|
const response = await GetAuthorization({ clientID });
|
|
782
|
-
if (response.success
|
|
783
|
-
|
|
779
|
+
if (response.success) {
|
|
780
|
+
setTargetProduct({ ean: eanProduct, quantity: 1 });
|
|
781
|
+
console.log("Authorization successful:", response.data);
|
|
784
782
|
} else {
|
|
785
783
|
console.error("Authorization failed:", response.message);
|
|
786
784
|
}
|
|
787
785
|
} catch (error) {
|
|
788
786
|
console.error("Error fetching authorization:", error);
|
|
789
787
|
}
|
|
790
|
-
}, [clientID,
|
|
791
|
-
(0,
|
|
788
|
+
}, [clientID, eanProduct]);
|
|
789
|
+
(0, import_react5.useEffect)(() => {
|
|
792
790
|
handleAuthorizationRequest();
|
|
793
791
|
}, [handleAuthorizationRequest]);
|
|
794
792
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Container_default, { variant: "main", children: [
|
|
795
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Header_default, { originalProductPrice:
|
|
793
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Header_default, { originalProductPrice: formatedOriginalProductPrice || 0 }),
|
|
796
794
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Container_default, { variant: "simple", children: [
|
|
797
795
|
state === "isEmpty" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
|
|
798
796
|
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Form_default, { setLoading }),
|
|
@@ -812,9 +810,9 @@ function PBM({
|
|
|
812
810
|
state === "isEmpty" && loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Loading_default, {}),
|
|
813
811
|
state === "isInvalid" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SecurityNumberInvalid_default, {}),
|
|
814
812
|
state === "isRegistered" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SecurityNumberRegitered_default, {}),
|
|
815
|
-
state === "isActivated" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BenefitsTable_default, { originalProductPrice })
|
|
813
|
+
state === "isActivated" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BenefitsTable_default, { originalProductPrice: formatedOriginalProductPrice })
|
|
816
814
|
] }),
|
|
817
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Footer_default, { industryLogo })
|
|
815
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Footer_default, { industryLogo: industryLogo || void 0 })
|
|
818
816
|
] });
|
|
819
817
|
}
|
|
820
818
|
var PBM_default = PBM;
|