@agrada_digital/pbm 0.0.55 → 0.0.56
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 +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +238 -146
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +230 -139
- package/dist/index.mjs.map +1 -1
- package/dist-wc/pbm-wc.js +92 -92
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -53,8 +53,81 @@ var Container_default = Container;
|
|
|
53
53
|
|
|
54
54
|
// src/components/Footer/index.tsx
|
|
55
55
|
import classNames2 from "classnames";
|
|
56
|
+
import { useEffect, useState } from "react";
|
|
57
|
+
|
|
58
|
+
// src/libs/zustand/usePBM.tsx
|
|
59
|
+
import { createStore } from "zustand";
|
|
60
|
+
import { useStore } from "zustand/react";
|
|
61
|
+
var initialPBMState = {
|
|
62
|
+
securityNumber: "",
|
|
63
|
+
state: "isEmpty",
|
|
64
|
+
availableDiscountSelected: {
|
|
65
|
+
quantity: 0,
|
|
66
|
+
discount: {
|
|
67
|
+
unit: 0,
|
|
68
|
+
total: 0
|
|
69
|
+
},
|
|
70
|
+
totalPrice: 0
|
|
71
|
+
},
|
|
72
|
+
targetProduct: null,
|
|
73
|
+
campaign: "pbm_campaign"
|
|
74
|
+
};
|
|
75
|
+
var createPBMStore = (set) => ({
|
|
76
|
+
...initialPBMState,
|
|
77
|
+
setSecurityNumber: (securityNumber) => set({ securityNumber }),
|
|
78
|
+
setState: (state) => set({ state }),
|
|
79
|
+
setTargetProduct: (targetProduct) => set({ targetProduct }),
|
|
80
|
+
setAvailableDiscountSelected: (availableDiscount) => set({ availableDiscountSelected: availableDiscount })
|
|
81
|
+
});
|
|
82
|
+
var pbmStore = createStore(createPBMStore);
|
|
83
|
+
function usePBMStore(selector) {
|
|
84
|
+
if (selector) {
|
|
85
|
+
return useStore(pbmStore, selector);
|
|
86
|
+
}
|
|
87
|
+
return useStore(pbmStore, (state) => state);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/services/get-product-by-ean.ts
|
|
91
|
+
import Cookies from "js-cookie";
|
|
92
|
+
var GetProductByEAN = async ({ PRODUCT_EAN }) => {
|
|
93
|
+
const API_URL = import.meta.env.VITE_API_URL;
|
|
94
|
+
const AUTH_TOKEN = Cookies.get("pbm-token");
|
|
95
|
+
if (!AUTH_TOKEN) {
|
|
96
|
+
throw new Error("Token is not defined in cookies or is expired");
|
|
97
|
+
}
|
|
98
|
+
const response = await fetch(`${API_URL}/products/ean/${PRODUCT_EAN}`, {
|
|
99
|
+
method: "GET",
|
|
100
|
+
headers: {
|
|
101
|
+
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
102
|
+
"Content-Type": "application/json"
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
const dataResponse = await response.json();
|
|
106
|
+
if (!dataResponse.sucesso) {
|
|
107
|
+
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
108
|
+
}
|
|
109
|
+
return dataResponse;
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
// src/components/Footer/index.tsx
|
|
56
113
|
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
57
|
-
function Footer(
|
|
114
|
+
function Footer() {
|
|
115
|
+
const [industryLogo, setIndustryLogo] = useState(void 0);
|
|
116
|
+
const { targetProduct } = usePBMStore();
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
const fetchProductByEan = async () => {
|
|
119
|
+
if (!targetProduct) return;
|
|
120
|
+
try {
|
|
121
|
+
const response = await GetProductByEAN({ PRODUCT_EAN: targetProduct.ean });
|
|
122
|
+
if (response.sucesso && response.dados) {
|
|
123
|
+
setIndustryLogo(response.dados.pbm.imageLink);
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
console.error(error);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
fetchProductByEan();
|
|
130
|
+
}, [targetProduct]);
|
|
58
131
|
return /* @__PURE__ */ jsx3("footer", { className: "w-full h-auto relative", id: "footer_pbm", children: /* @__PURE__ */ jsxs2("section", { className: classNames2("flex items-center w-full h-auto gap-4", { "justify-center": industryLogo, "justify-start": !industryLogo }), children: [
|
|
59
132
|
/* @__PURE__ */ jsxs2("section", { className: "w-4/5 h-auto", children: [
|
|
60
133
|
/* @__PURE__ */ jsx3("h3", { className: "text-start font-semibold text-sm", children: "Economize com o benef\xEDcio do laborat\xF3rio." }),
|
|
@@ -65,7 +138,7 @@ function Footer({ industryLogo }) {
|
|
|
65
138
|
{
|
|
66
139
|
src: industryLogo,
|
|
67
140
|
alt: "parceiro",
|
|
68
|
-
className: "w-1/5 min-w-20 h-auto aspect-
|
|
141
|
+
className: "w-1/5 min-w-20 h-auto aspect-auto",
|
|
69
142
|
loading: "eager",
|
|
70
143
|
id: "footer_industry_logo_pbm",
|
|
71
144
|
"data-testid": "footer_industry_logo_pbm"
|
|
@@ -86,7 +159,8 @@ var validationSchema = z.strictObject({
|
|
|
86
159
|
}, "CPF deve conter no m\xEDnimo 11 caracteres.").refine((doc) => {
|
|
87
160
|
const replacedDoc = doc.replace(/\D/g, "");
|
|
88
161
|
return !!Number(replacedDoc);
|
|
89
|
-
}, "CPF deve conter apenas n\xFAmeros.")
|
|
162
|
+
}, "CPF deve conter apenas n\xFAmeros."),
|
|
163
|
+
coupon: z.string().min(0)
|
|
90
164
|
});
|
|
91
165
|
|
|
92
166
|
// src/utils/format.ts
|
|
@@ -98,51 +172,20 @@ var toFormat = (value) => {
|
|
|
98
172
|
};
|
|
99
173
|
|
|
100
174
|
// src/components/Form/index.tsx
|
|
101
|
-
import
|
|
175
|
+
import classNames4 from "classnames";
|
|
102
176
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
103
177
|
import { useForm } from "react-hook-form";
|
|
104
178
|
import { ArrowRight } from "lucide-react";
|
|
105
|
-
|
|
106
|
-
// src/libs/zustand/usePBM.tsx
|
|
107
|
-
import { createStore } from "zustand";
|
|
108
|
-
import { useStore } from "zustand/react";
|
|
109
|
-
var initialPBMState = {
|
|
110
|
-
securityNumber: "",
|
|
111
|
-
state: "isEmpty",
|
|
112
|
-
availableDiscountSelected: {
|
|
113
|
-
quantity: 0,
|
|
114
|
-
discount: {
|
|
115
|
-
unit: 0,
|
|
116
|
-
total: 0
|
|
117
|
-
},
|
|
118
|
-
totalPrice: 0
|
|
119
|
-
},
|
|
120
|
-
targetProduct: null,
|
|
121
|
-
campaign: "pbm_campaign"
|
|
122
|
-
};
|
|
123
|
-
var createPBMStore = (set) => ({
|
|
124
|
-
...initialPBMState,
|
|
125
|
-
setSecurityNumber: (securityNumber) => set({ securityNumber }),
|
|
126
|
-
setState: (state) => set({ state }),
|
|
127
|
-
setTargetProduct: (targetProduct) => set({ targetProduct }),
|
|
128
|
-
setAvailableDiscountSelected: (availableDiscount) => set({ availableDiscountSelected: availableDiscount })
|
|
129
|
-
});
|
|
130
|
-
var pbmStore = createStore(createPBMStore);
|
|
131
|
-
function usePBMStore(selector) {
|
|
132
|
-
if (selector) {
|
|
133
|
-
return useStore(pbmStore, selector);
|
|
134
|
-
}
|
|
135
|
-
return useStore(pbmStore, (state) => state);
|
|
136
|
-
}
|
|
179
|
+
import { useState as useState2 } from "react";
|
|
137
180
|
|
|
138
181
|
// src/services/validate-document.ts
|
|
139
|
-
import
|
|
182
|
+
import Cookies2 from "js-cookie";
|
|
140
183
|
var ValidateDocument = async ({ document, products }) => {
|
|
141
184
|
const API_URL = import.meta.env.VITE_API_URL;
|
|
142
185
|
if (!API_URL) {
|
|
143
186
|
throw new Error("API URL is not defined in environment variables");
|
|
144
187
|
}
|
|
145
|
-
const AUTH_TOKEN =
|
|
188
|
+
const AUTH_TOKEN = Cookies2.get("pbm-token");
|
|
146
189
|
if (!AUTH_TOKEN) {
|
|
147
190
|
throw new Error("Token is not defined in cookies or is expired");
|
|
148
191
|
}
|
|
@@ -161,10 +204,29 @@ var ValidateDocument = async ({ document, products }) => {
|
|
|
161
204
|
return dataResponse;
|
|
162
205
|
};
|
|
163
206
|
|
|
207
|
+
// src/components/UI/Button/index.tsx
|
|
208
|
+
import classNames3 from "classnames";
|
|
209
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
210
|
+
function Button(props) {
|
|
211
|
+
return /* @__PURE__ */ jsx4(
|
|
212
|
+
"button",
|
|
213
|
+
{
|
|
214
|
+
...props,
|
|
215
|
+
className: classNames3(
|
|
216
|
+
"w-3xs cursor-pointer h-10 rounded-full bg-blue-500 hover:bg-blue-400 text-white text-sm font-semibold transition-colors",
|
|
217
|
+
props.className
|
|
218
|
+
),
|
|
219
|
+
children: props.children
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
var Button_default = Button;
|
|
224
|
+
|
|
164
225
|
// src/components/Form/index.tsx
|
|
165
|
-
import { jsx as
|
|
226
|
+
import { Fragment, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
166
227
|
function Form({ setLoading }) {
|
|
167
228
|
const { setSecurityNumber, setState, securityNumber, targetProduct } = usePBMStore();
|
|
229
|
+
const [showCoupoField, setShowCoupoField] = useState2(false);
|
|
168
230
|
const {
|
|
169
231
|
handleSubmit,
|
|
170
232
|
register,
|
|
@@ -180,7 +242,7 @@ function Form({ setLoading }) {
|
|
|
180
242
|
setLoading(true);
|
|
181
243
|
try {
|
|
182
244
|
if (targetProduct === null) {
|
|
183
|
-
console.error("Product is not defined!");
|
|
245
|
+
console.error("PBMLOG: Product is not defined!");
|
|
184
246
|
return;
|
|
185
247
|
}
|
|
186
248
|
const response = await ValidateDocument({
|
|
@@ -196,76 +258,125 @@ function Form({ setLoading }) {
|
|
|
196
258
|
setState(status[response.data.process_platform.status]);
|
|
197
259
|
}
|
|
198
260
|
} catch (error) {
|
|
199
|
-
console.error("Error validating document
|
|
261
|
+
console.error("PBMLOG: Error validating document -", error);
|
|
200
262
|
} finally {
|
|
201
263
|
setLoading(false);
|
|
202
264
|
}
|
|
203
265
|
;
|
|
204
266
|
};
|
|
205
|
-
return /* @__PURE__ */ jsxs3(
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
id: "form_security_number_pbm",
|
|
214
|
-
children: [
|
|
215
|
-
/* @__PURE__ */ jsxs3(
|
|
216
|
-
"label",
|
|
217
|
-
{
|
|
218
|
-
htmlFor: "cpf",
|
|
219
|
-
className: "w-4/5 h-auto flex items-start flex-col justify-center relative py-2",
|
|
220
|
-
id: "label_security_number_pbm",
|
|
221
|
-
children: [
|
|
222
|
-
/* @__PURE__ */ jsx4(
|
|
223
|
-
"input",
|
|
224
|
-
{
|
|
225
|
-
type: "text",
|
|
226
|
-
className: classNames3(
|
|
227
|
-
"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",
|
|
228
|
-
{ "outline outline-red-600": errors.securityNumber }
|
|
229
|
-
),
|
|
230
|
-
placeholder: "Digite seu CPF aqui...",
|
|
231
|
-
required: true,
|
|
232
|
-
maxLength: 14,
|
|
233
|
-
...register("securityNumber", {
|
|
234
|
-
onChange: (e) => {
|
|
235
|
-
const formatted = toFormat(e.target.value);
|
|
236
|
-
setValue("securityNumber", formatted, {
|
|
237
|
-
shouldValidate: true
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
}),
|
|
241
|
-
defaultValue: securityNumber || "",
|
|
242
|
-
id: "input_security_number_pbm"
|
|
243
|
-
}
|
|
244
|
-
),
|
|
245
|
-
errors.securityNumber && /* @__PURE__ */ jsx4("span", { className: "text-red-400 text-xs font-semibold absolute -bottom-3 left-2 text-nowrap", id: "security_number_form_error", children: errors.securityNumber.message })
|
|
246
|
-
]
|
|
247
|
-
}
|
|
267
|
+
return /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
268
|
+
/* @__PURE__ */ jsxs3(
|
|
269
|
+
"form",
|
|
270
|
+
{
|
|
271
|
+
onSubmit: handleSubmit(onSubmitDefault),
|
|
272
|
+
className: classNames4(
|
|
273
|
+
"w-full h-auto flex items-center justify-center mb-0 transition-all duration-150",
|
|
274
|
+
{ "mb-4": errors.securityNumber || errors.coupon, "gap-2": showCoupoField }
|
|
248
275
|
),
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
276
|
+
id: "form_security_number_pbm",
|
|
277
|
+
children: [
|
|
278
|
+
/* @__PURE__ */ jsxs3(
|
|
279
|
+
"label",
|
|
280
|
+
{
|
|
281
|
+
htmlFor: "cpf",
|
|
282
|
+
className: "w-4/5 h-auto flex items-start flex-col justify-center relative py-2",
|
|
283
|
+
id: "label_security_number_pbm",
|
|
284
|
+
children: [
|
|
285
|
+
/* @__PURE__ */ jsx5(
|
|
286
|
+
"input",
|
|
287
|
+
{
|
|
288
|
+
type: "text",
|
|
289
|
+
className: classNames4(
|
|
290
|
+
"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",
|
|
291
|
+
{ "outline outline-red-600": errors.securityNumber, "rounded-full": showCoupoField }
|
|
292
|
+
),
|
|
293
|
+
placeholder: "Digite seu CPF aqui...",
|
|
294
|
+
required: true,
|
|
295
|
+
maxLength: 14,
|
|
296
|
+
...register("securityNumber", {
|
|
297
|
+
onChange: (e) => {
|
|
298
|
+
const formatted = toFormat(e.target.value);
|
|
299
|
+
setValue("securityNumber", formatted, {
|
|
300
|
+
shouldValidate: true
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
}),
|
|
304
|
+
defaultValue: securityNumber || "",
|
|
305
|
+
id: "input_security_number_pbm"
|
|
306
|
+
}
|
|
307
|
+
),
|
|
308
|
+
errors.securityNumber && /* @__PURE__ */ jsx5("span", { className: "text-red-400 text-xs font-semibold absolute -bottom-3 left-2 text-nowrap", id: "security_number_form_error", children: errors.securityNumber.message })
|
|
309
|
+
]
|
|
310
|
+
}
|
|
311
|
+
),
|
|
312
|
+
showCoupoField && /* @__PURE__ */ jsxs3(
|
|
313
|
+
"label",
|
|
314
|
+
{
|
|
315
|
+
htmlFor: "coupon",
|
|
316
|
+
className: "w-4/5 h-auto flex items-start flex-col justify-center relative py-2",
|
|
317
|
+
id: "label_coupon_pbm",
|
|
318
|
+
children: [
|
|
319
|
+
/* @__PURE__ */ jsx5(
|
|
320
|
+
"input",
|
|
321
|
+
{
|
|
322
|
+
type: "text",
|
|
323
|
+
className: classNames4(
|
|
324
|
+
"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",
|
|
325
|
+
{ "outline outline-red-600": errors.coupon, "rounded-full": showCoupoField }
|
|
326
|
+
),
|
|
327
|
+
placeholder: "Cupom / ID do Cart\xE3o",
|
|
328
|
+
required: true,
|
|
329
|
+
maxLength: 14,
|
|
330
|
+
...register("coupon", {
|
|
331
|
+
onChange: (e) => {
|
|
332
|
+
setValue("coupon", e.target.value, {
|
|
333
|
+
shouldValidate: true
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}),
|
|
337
|
+
id: "input_coupon_pbm"
|
|
338
|
+
}
|
|
339
|
+
),
|
|
340
|
+
errors.coupon && /* @__PURE__ */ jsx5("span", { className: "text-red-400 text-xs font-semibold absolute -bottom-3 left-2 text-nowrap", id: "coupon_form_error", children: errors.coupon.message })
|
|
341
|
+
]
|
|
342
|
+
}
|
|
343
|
+
),
|
|
344
|
+
/* @__PURE__ */ jsx5(
|
|
345
|
+
"button",
|
|
346
|
+
{
|
|
347
|
+
type: "submit",
|
|
348
|
+
className: classNames4(
|
|
349
|
+
"bg-gray-400 w-1/5 h-8 flex items-center justify-center rounded-e-full cursor-pointer",
|
|
350
|
+
{ "rounded-full": showCoupoField }
|
|
351
|
+
),
|
|
352
|
+
id: "button_submit_security_number_pbm",
|
|
353
|
+
children: /* @__PURE__ */ jsx5(ArrowRight, { size: 24, color: "white", strokeWidth: 2 })
|
|
354
|
+
}
|
|
355
|
+
)
|
|
356
|
+
]
|
|
357
|
+
}
|
|
358
|
+
),
|
|
359
|
+
/* @__PURE__ */ jsxs3(
|
|
360
|
+
Button_default,
|
|
361
|
+
{
|
|
362
|
+
className: "bg-transparent p-0 pl-2 w-auto h-auto text-zinc-600 underline cursor-pointer hover:text-zinc-900 hover:bg-transparent flex items-center justify-start gap-1",
|
|
363
|
+
onClick: () => setShowCoupoField(!showCoupoField),
|
|
364
|
+
id: "check_benefits_button",
|
|
365
|
+
children: [
|
|
366
|
+
/* @__PURE__ */ jsx5("span", { children: !showCoupoField ? "Possui cupom?" : "N\xE3o possui cupom?" }),
|
|
367
|
+
/* @__PURE__ */ jsx5(ArrowRight, { size: 16, className: classNames4({ "rotate-0": !showCoupoField, "rotate-180": showCoupoField }) })
|
|
368
|
+
]
|
|
369
|
+
}
|
|
370
|
+
)
|
|
371
|
+
] });
|
|
261
372
|
}
|
|
262
373
|
var Form_default = Form;
|
|
263
374
|
|
|
264
375
|
// src/components/UI/Loading/index.tsx
|
|
265
|
-
import { jsx as
|
|
376
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
266
377
|
function Loading({ textColor }) {
|
|
267
378
|
return /* @__PURE__ */ jsxs4("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
|
|
268
|
-
/* @__PURE__ */
|
|
379
|
+
/* @__PURE__ */ jsx6(
|
|
269
380
|
"div",
|
|
270
381
|
{
|
|
271
382
|
"data-testid": "test_id_spin",
|
|
@@ -273,7 +384,7 @@ function Loading({ textColor }) {
|
|
|
273
384
|
id: "loading_spin"
|
|
274
385
|
}
|
|
275
386
|
),
|
|
276
|
-
/* @__PURE__ */
|
|
387
|
+
/* @__PURE__ */ jsx6(
|
|
277
388
|
"p",
|
|
278
389
|
{
|
|
279
390
|
className: "text-sm font-semibold text-start text-zinc-900",
|
|
@@ -286,26 +397,8 @@ function Loading({ textColor }) {
|
|
|
286
397
|
}
|
|
287
398
|
var Loading_default = Loading;
|
|
288
399
|
|
|
289
|
-
// src/components/UI/Button/index.tsx
|
|
290
|
-
import classNames4 from "classnames";
|
|
291
|
-
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
292
|
-
function Button(props) {
|
|
293
|
-
return /* @__PURE__ */ jsx6(
|
|
294
|
-
"button",
|
|
295
|
-
{
|
|
296
|
-
...props,
|
|
297
|
-
className: classNames4(
|
|
298
|
-
"w-3xs cursor-pointer h-10 rounded-full bg-blue-500 hover:bg-blue-400 text-white text-sm font-semibold transition-colors",
|
|
299
|
-
props.className
|
|
300
|
-
),
|
|
301
|
-
children: props.children
|
|
302
|
-
}
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
var Button_default = Button;
|
|
306
|
-
|
|
307
400
|
// src/components/BenefitsTable/index.tsx
|
|
308
|
-
import { useState } from "react";
|
|
401
|
+
import { useState as useState3 } from "react";
|
|
309
402
|
|
|
310
403
|
// src/mocks/benefits.ts
|
|
311
404
|
var BENEFITS_ITEMS = [
|
|
@@ -354,7 +447,7 @@ var Title_default = Title;
|
|
|
354
447
|
|
|
355
448
|
// src/components/BenefitsTable/Item.tsx
|
|
356
449
|
import { Badge, BadgeCheck } from "lucide-react";
|
|
357
|
-
import { useCallback, useEffect } from "react";
|
|
450
|
+
import { useCallback, useEffect as useEffect2 } from "react";
|
|
358
451
|
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
359
452
|
function Item({ data, onChange, checked, originalProductPrice }) {
|
|
360
453
|
const { setAvailableDiscountSelected, securityNumber } = usePBMStore();
|
|
@@ -383,7 +476,7 @@ function Item({ data, onChange, checked, originalProductPrice }) {
|
|
|
383
476
|
totalPriceProductWithDiscountBenefit,
|
|
384
477
|
unitDiscountValue
|
|
385
478
|
]);
|
|
386
|
-
|
|
479
|
+
useEffect2(() => {
|
|
387
480
|
updateStorageData();
|
|
388
481
|
}, [updateStorageData]);
|
|
389
482
|
return /* @__PURE__ */ jsxs5(
|
|
@@ -440,7 +533,7 @@ function BenefitsTable({
|
|
|
440
533
|
originalProductPrice
|
|
441
534
|
}) {
|
|
442
535
|
const { securityNumber, setState } = usePBMStore();
|
|
443
|
-
const [selectedDiscout, setSelectedDiscount] =
|
|
536
|
+
const [selectedDiscout, setSelectedDiscount] = useState3(null);
|
|
444
537
|
return /* @__PURE__ */ jsxs6(
|
|
445
538
|
"section",
|
|
446
539
|
{
|
|
@@ -584,10 +677,10 @@ function Iframe({ url, title, openModal, setOpenModal }) {
|
|
|
584
677
|
var Iframe_default = Iframe;
|
|
585
678
|
|
|
586
679
|
// src/components/SecurityNumberInvalid/index.tsx
|
|
587
|
-
import { useState as
|
|
680
|
+
import { useState as useState4 } from "react";
|
|
588
681
|
import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
589
682
|
function SecurityNumberInvalid({ textColor }) {
|
|
590
|
-
const [openModal, setOpenModal] =
|
|
683
|
+
const [openModal, setOpenModal] = useState4(false);
|
|
591
684
|
return /* @__PURE__ */ jsxs8(
|
|
592
685
|
"section",
|
|
593
686
|
{
|
|
@@ -622,7 +715,7 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
622
715
|
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
623
716
|
|
|
624
717
|
// src/PBM.tsx
|
|
625
|
-
import { useCallback as useCallback2, useEffect as
|
|
718
|
+
import { useCallback as useCallback2, useEffect as useEffect3, useState as useState5 } from "react";
|
|
626
719
|
|
|
627
720
|
// src/components/UI/Link/index.tsx
|
|
628
721
|
import classNames8 from "classnames";
|
|
@@ -683,7 +776,7 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
683
776
|
var SecurityNumberRegitered_default = SecurityNumberRegitered;
|
|
684
777
|
|
|
685
778
|
// src/services/authorization.ts
|
|
686
|
-
import
|
|
779
|
+
import Cookies3 from "js-cookie";
|
|
687
780
|
var GetAuthorization = async ({ clientID }) => {
|
|
688
781
|
const API_URL = import.meta.env.VITE_API_URL;
|
|
689
782
|
const STORE_ID = import.meta.env.VITE_STORE_ID;
|
|
@@ -709,12 +802,13 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
709
802
|
if (!dataResponse.success) {
|
|
710
803
|
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
711
804
|
}
|
|
712
|
-
|
|
713
|
-
expires:
|
|
805
|
+
Cookies3.set("pbm-token", dataResponse.data.Token, {
|
|
806
|
+
expires: dataResponse.data.ExpiresIn / (60 * 60),
|
|
714
807
|
secure: true,
|
|
715
808
|
sameSite: "Strict"
|
|
716
809
|
});
|
|
717
|
-
|
|
810
|
+
Cookies3.set("pbm-token-refresh", dataResponse.data.RefreshToken, {
|
|
811
|
+
expires: dataResponse.data.RefreshExpiresIn / (60 * 60),
|
|
718
812
|
secure: true,
|
|
719
813
|
sameSite: "Strict"
|
|
720
814
|
});
|
|
@@ -723,19 +817,18 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
723
817
|
|
|
724
818
|
// src/PBM.tsx
|
|
725
819
|
import { ArrowRight as ArrowRight2 } from "lucide-react";
|
|
726
|
-
import { Fragment, jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
820
|
+
import { Fragment as Fragment2, jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
727
821
|
function PBM({
|
|
728
822
|
originalProductPrice,
|
|
729
|
-
industryLogo,
|
|
730
823
|
clientID,
|
|
731
824
|
eanProduct
|
|
732
825
|
}) {
|
|
733
826
|
const formatedOriginalProductPrice = Number(
|
|
734
827
|
String(originalProductPrice).replace(",", ".")
|
|
735
828
|
);
|
|
736
|
-
const [loading, setLoading] =
|
|
829
|
+
const [loading, setLoading] = useState5(false);
|
|
737
830
|
const { setState, state, setTargetProduct } = usePBMStore();
|
|
738
|
-
|
|
831
|
+
useEffect3(() => {
|
|
739
832
|
if (eanProduct) {
|
|
740
833
|
setTargetProduct({ ean: eanProduct, quantity: 1 });
|
|
741
834
|
}
|
|
@@ -743,22 +836,20 @@ function PBM({
|
|
|
743
836
|
const handleAuthorizationRequest = useCallback2(async () => {
|
|
744
837
|
try {
|
|
745
838
|
const response = await GetAuthorization({ clientID });
|
|
746
|
-
if (response.success) {
|
|
747
|
-
console.
|
|
748
|
-
} else {
|
|
749
|
-
console.error("Authorization failed:", response.message);
|
|
839
|
+
if (!response.success) {
|
|
840
|
+
console.error("PBMLOG: Authorization failed!");
|
|
750
841
|
}
|
|
751
842
|
} catch (error) {
|
|
752
843
|
console.error("Error fetching authorization:", error);
|
|
753
844
|
}
|
|
754
845
|
}, [clientID]);
|
|
755
|
-
|
|
846
|
+
useEffect3(() => {
|
|
756
847
|
handleAuthorizationRequest();
|
|
757
848
|
}, [handleAuthorizationRequest]);
|
|
758
849
|
return /* @__PURE__ */ jsxs10(Container_default, { variant: "main", children: [
|
|
759
850
|
/* @__PURE__ */ jsx15(Header_default, { originalProductPrice: formatedOriginalProductPrice || 0 }),
|
|
760
851
|
/* @__PURE__ */ jsxs10(Container_default, { variant: "simple", children: [
|
|
761
|
-
state === "isEmpty" && !loading && /* @__PURE__ */ jsxs10(
|
|
852
|
+
state === "isEmpty" && !loading && /* @__PURE__ */ jsxs10(Fragment2, { children: [
|
|
762
853
|
/* @__PURE__ */ jsx15(Form_default, { setLoading }),
|
|
763
854
|
/* @__PURE__ */ jsxs10(
|
|
764
855
|
Button_default,
|
|
@@ -778,7 +869,7 @@ function PBM({
|
|
|
778
869
|
state === "isRegistered" && !loading && /* @__PURE__ */ jsx15(SecurityNumberRegitered_default, {}),
|
|
779
870
|
state === "isActivated" && !loading && /* @__PURE__ */ jsx15(BenefitsTable_default, { originalProductPrice: formatedOriginalProductPrice })
|
|
780
871
|
] }),
|
|
781
|
-
/* @__PURE__ */ jsx15(Footer_default, {
|
|
872
|
+
/* @__PURE__ */ jsx15(Footer_default, {})
|
|
782
873
|
] });
|
|
783
874
|
}
|
|
784
875
|
var PBM_default = PBM;
|