@agrada_digital/pbm 0.0.91 → 0.0.92
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +224 -236
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +223 -235
- package/dist/index.mjs.map +1 -1
- package/dist-wc/pbm-wc.js +81 -81
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -131,7 +131,7 @@ function Container({
|
|
|
131
131
|
"main",
|
|
132
132
|
{
|
|
133
133
|
className: (0, import_classnames.default)({
|
|
134
|
-
"border-3 border-[#44c2c0] flex flex-col items-center justify-center min-w-
|
|
134
|
+
"border-3 border-[#44c2c0] flex flex-col items-center justify-center min-w-(--min-container) max-w-(--max-container) w-full h-auto rounded-xl p-4 bg-white gap-4 relative": variant === "main",
|
|
135
135
|
"w-full h-auto relative": variant === "simple"
|
|
136
136
|
}),
|
|
137
137
|
"data-testid": "test_id_container",
|
|
@@ -147,7 +147,7 @@ var Container_default = Container;
|
|
|
147
147
|
var import_classnames2 = __toESM(require("classnames"));
|
|
148
148
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
149
149
|
function Footer() {
|
|
150
|
-
const { targetProduct
|
|
150
|
+
const { targetProduct } = usePBMStore();
|
|
151
151
|
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": targetProduct?.industryLogo, "justify-start": !targetProduct?.industryLogo }), children: [
|
|
152
152
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "w-4/5 h-auto", children: [
|
|
153
153
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "text-start font-semibold text-sm", children: "Economize com o benef\xEDcio do laborat\xF3rio." }),
|
|
@@ -183,7 +183,7 @@ var validationSchema = import_zod.z.object({
|
|
|
183
183
|
coupon: import_zod.z.string({ required_error: "Cupom / ID do Cart\xE3o obrigat\xF3rio." }).optional()
|
|
184
184
|
});
|
|
185
185
|
|
|
186
|
-
// src/utils/format.ts
|
|
186
|
+
// src/utils/format-security-number.ts
|
|
187
187
|
var toFormat = (value) => {
|
|
188
188
|
const cleanedValue = value.replace(/\D/g, "");
|
|
189
189
|
if (cleanedValue.length <= 11) {
|
|
@@ -191,12 +191,15 @@ var toFormat = (value) => {
|
|
|
191
191
|
}
|
|
192
192
|
};
|
|
193
193
|
|
|
194
|
-
// src/
|
|
195
|
-
var
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
194
|
+
// src/utils/mapping-internal-states.ts
|
|
195
|
+
var mappingInternalStates = (outContextState) => {
|
|
196
|
+
const status = {
|
|
197
|
+
"acceptance": "isInvalid",
|
|
198
|
+
"industry registration": "isRegistered",
|
|
199
|
+
"active": "isActivated"
|
|
200
|
+
};
|
|
201
|
+
return status[outContextState];
|
|
202
|
+
};
|
|
200
203
|
|
|
201
204
|
// src/services/benefits-with-document.ts
|
|
202
205
|
var import_js_cookie = __toESM(require("js-cookie"));
|
|
@@ -244,9 +247,14 @@ function Button(props) {
|
|
|
244
247
|
var Button_default = Button;
|
|
245
248
|
|
|
246
249
|
// src/components/Form/index.tsx
|
|
250
|
+
var import_zod2 = require("@hookform/resolvers/zod");
|
|
251
|
+
var import_react_hook_form = require("react-hook-form");
|
|
252
|
+
var import_lucide_react = require("lucide-react");
|
|
253
|
+
var import_classnames4 = __toESM(require("classnames"));
|
|
254
|
+
var import_react2 = require("react");
|
|
247
255
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
248
|
-
function Form({
|
|
249
|
-
const
|
|
256
|
+
function Form({ startTransition }) {
|
|
257
|
+
const store = usePBMStore();
|
|
250
258
|
const [showCardIDField, setShowCardIDField] = (0, import_react2.useState)(false);
|
|
251
259
|
const {
|
|
252
260
|
handleSubmit,
|
|
@@ -259,64 +267,62 @@ function Form({ setLoading }) {
|
|
|
259
267
|
resolver: (0, import_zod2.zodResolver)(validationSchema),
|
|
260
268
|
mode: "onSubmit",
|
|
261
269
|
defaultValues: {
|
|
262
|
-
securityNumber: securityNumber || "",
|
|
270
|
+
securityNumber: store.securityNumber || "",
|
|
263
271
|
coupon: ""
|
|
264
272
|
}
|
|
265
273
|
});
|
|
266
|
-
const
|
|
267
|
-
if (!showCardIDField) {
|
|
268
|
-
setValue("coupon", void 0, { shouldValidate: false });
|
|
269
|
-
}
|
|
270
|
-
if (showCardIDField && values.coupon != void 0) {
|
|
271
|
-
setCardID(values.coupon);
|
|
272
|
-
}
|
|
273
|
-
setLoading(true);
|
|
274
|
+
const checkSecurityNumberBenefits = async (values) => {
|
|
274
275
|
try {
|
|
275
|
-
if (targetProduct === null) {
|
|
276
|
+
if (store.targetProduct === null) {
|
|
276
277
|
console.error("PBMLOG: Product is not defined!");
|
|
277
278
|
return;
|
|
278
279
|
}
|
|
279
|
-
if (!targetProduct.productId) {
|
|
280
|
+
if (!store.targetProduct.productId) {
|
|
280
281
|
console.error("PBMLOG: Product ID is not defined!");
|
|
281
282
|
return;
|
|
282
283
|
}
|
|
283
|
-
if (!targetProduct.listPrice) {
|
|
284
|
+
if (!store.targetProduct.listPrice) {
|
|
284
285
|
console.error("PBMLOG: List Price is not defined!");
|
|
285
286
|
return;
|
|
286
287
|
}
|
|
288
|
+
const product = {
|
|
289
|
+
productId: store.targetProduct.productId,
|
|
290
|
+
ean: store.targetProduct.ean,
|
|
291
|
+
requestedQuantity: 1,
|
|
292
|
+
listPrice: store.targetProduct.listPrice,
|
|
293
|
+
netPrice: store.targetProduct.netPrice ?? store.targetProduct.listPrice
|
|
294
|
+
};
|
|
287
295
|
const response = await BenefitsWithDocument({
|
|
288
296
|
document: values.securityNumber.replace(/\D/g, ""),
|
|
289
|
-
products: [
|
|
290
|
-
productId: targetProduct.productId,
|
|
291
|
-
ean: targetProduct.ean,
|
|
292
|
-
requestedQuantity: 1,
|
|
293
|
-
listPrice: targetProduct.listPrice,
|
|
294
|
-
netPrice: targetProduct.netPrice ?? targetProduct.listPrice
|
|
295
|
-
}]
|
|
297
|
+
products: [product]
|
|
296
298
|
});
|
|
297
299
|
if (response.success) {
|
|
298
|
-
const status =
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
setSecurityNumber(values.securityNumber);
|
|
304
|
-
setState(status[response.data.product[0].statusCustomer]);
|
|
305
|
-
if (status[response.data.product[0].statusCustomer] === "isInvalid") {
|
|
306
|
-
setUrlAcceptTerms(response.data.product[0].urlAcceptTerm || void 0);
|
|
300
|
+
const status = mappingInternalStates(response.data.product[0].statusCustomer);
|
|
301
|
+
store.setSecurityNumber(values.securityNumber);
|
|
302
|
+
store.setState(status);
|
|
303
|
+
if (status === "isInvalid") {
|
|
304
|
+
store.setUrlAcceptTerms(response.data.product[0].urlAcceptTerm || void 0);
|
|
307
305
|
return;
|
|
308
306
|
}
|
|
309
|
-
if (status
|
|
310
|
-
setUrlRegisterIndustry(response.data.product[0].informativeLink);
|
|
307
|
+
if (status === "isRegistered") {
|
|
308
|
+
store.setUrlRegisterIndustry(response.data.product[0].informativeLink);
|
|
311
309
|
return;
|
|
312
310
|
}
|
|
313
311
|
}
|
|
314
312
|
} catch (error) {
|
|
315
313
|
console.error("PBMLOG: Error validating document -", error);
|
|
316
|
-
} finally {
|
|
317
|
-
setLoading(false);
|
|
318
314
|
}
|
|
319
|
-
|
|
315
|
+
};
|
|
316
|
+
const onSubmitDefault = async (values) => {
|
|
317
|
+
if (!showCardIDField) {
|
|
318
|
+
setValue("coupon", void 0, { shouldValidate: false });
|
|
319
|
+
}
|
|
320
|
+
if (showCardIDField && values.coupon != void 0) {
|
|
321
|
+
store.setCardID(values.coupon);
|
|
322
|
+
}
|
|
323
|
+
startTransition(async () => {
|
|
324
|
+
await checkSecurityNumberBenefits(values);
|
|
325
|
+
});
|
|
320
326
|
};
|
|
321
327
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
322
328
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
@@ -355,7 +361,7 @@ function Form({ setLoading }) {
|
|
|
355
361
|
});
|
|
356
362
|
}
|
|
357
363
|
}),
|
|
358
|
-
defaultValue: securityNumber || "",
|
|
364
|
+
defaultValue: store.securityNumber || "",
|
|
359
365
|
id: "input_security_number_pbm"
|
|
360
366
|
}
|
|
361
367
|
),
|
|
@@ -363,7 +369,7 @@ function Form({ setLoading }) {
|
|
|
363
369
|
]
|
|
364
370
|
}
|
|
365
371
|
),
|
|
366
|
-
showCardIDField
|
|
372
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react2.Activity, { mode: showCardIDField ? "visible" : "hidden", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
367
373
|
"label",
|
|
368
374
|
{
|
|
369
375
|
htmlFor: "coupon",
|
|
@@ -394,7 +400,7 @@ function Form({ setLoading }) {
|
|
|
394
400
|
errors.coupon && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-red-400 text-xs font-semibold absolute -bottom-3 left-2 text-nowrap", id: "coupon_form_error", children: errors.coupon.message })
|
|
395
401
|
]
|
|
396
402
|
}
|
|
397
|
-
),
|
|
403
|
+
) }),
|
|
398
404
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
399
405
|
"button",
|
|
400
406
|
{
|
|
@@ -434,7 +440,7 @@ function Form({ setLoading }) {
|
|
|
434
440
|
Button_default,
|
|
435
441
|
{
|
|
436
442
|
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",
|
|
437
|
-
onClick: () => setState("isPreview"),
|
|
443
|
+
onClick: () => store.setState("isPreview"),
|
|
438
444
|
id: "check_benefits_button",
|
|
439
445
|
children: [
|
|
440
446
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Consultar Benef\xEDcios" }),
|
|
@@ -472,9 +478,6 @@ function Loading({ textColor }) {
|
|
|
472
478
|
}
|
|
473
479
|
var Loading_default = Loading;
|
|
474
480
|
|
|
475
|
-
// src/components/BenefitsTable/index.tsx
|
|
476
|
-
var import_react4 = require("react");
|
|
477
|
-
|
|
478
481
|
// src/components/UI/Title/index.tsx
|
|
479
482
|
var import_classnames5 = __toESM(require("classnames"));
|
|
480
483
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
@@ -495,6 +498,36 @@ function Title(props) {
|
|
|
495
498
|
}
|
|
496
499
|
var Title_default = Title;
|
|
497
500
|
|
|
501
|
+
// src/services/benefits-without-document.ts
|
|
502
|
+
var import_js_cookie2 = __toESM(require("js-cookie"));
|
|
503
|
+
var import_meta2 = {};
|
|
504
|
+
var CheckBenefistWithoutDocument = async ({ products }) => {
|
|
505
|
+
const API_URL = import_meta2.env.VITE_API_URL;
|
|
506
|
+
if (!API_URL) {
|
|
507
|
+
throw new Error("API URL is not defined in environment variables");
|
|
508
|
+
}
|
|
509
|
+
const AUTH_TOKEN = import_js_cookie2.default.get("pbm-token");
|
|
510
|
+
if (!AUTH_TOKEN) {
|
|
511
|
+
throw new Error("Token is not defined in cookies or is expired");
|
|
512
|
+
}
|
|
513
|
+
const response = await fetch(`${API_URL}/products/genericBenefit`, {
|
|
514
|
+
method: "POST",
|
|
515
|
+
headers: {
|
|
516
|
+
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
517
|
+
"Content-Type": "application/json"
|
|
518
|
+
},
|
|
519
|
+
body: JSON.stringify({ products })
|
|
520
|
+
});
|
|
521
|
+
const dataResponse = await response.json();
|
|
522
|
+
if (!dataResponse.success) {
|
|
523
|
+
throw new Error(dataResponse.message || "Failed to fetch benefits without document");
|
|
524
|
+
}
|
|
525
|
+
return dataResponse;
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// src/components/BenefitsTable/index.tsx
|
|
529
|
+
var import_react4 = require("react");
|
|
530
|
+
|
|
498
531
|
// src/libs/zustand/useModal.tsx
|
|
499
532
|
var import_zustand2 = require("zustand");
|
|
500
533
|
var initialModalState = {
|
|
@@ -595,7 +628,7 @@ function Item({ data, onChange, checked }) {
|
|
|
595
628
|
(0, import_react3.useEffect)(() => {
|
|
596
629
|
updateStorageData();
|
|
597
630
|
}, [updateStorageData]);
|
|
598
|
-
const handleChange = (
|
|
631
|
+
const handleChange = () => {
|
|
599
632
|
if (!isAuthenticatedShopper && state === "isActivated") {
|
|
600
633
|
setModal({
|
|
601
634
|
id: "ShopperIsNotAuthenticated",
|
|
@@ -656,58 +689,31 @@ function Item({ data, onChange, checked }) {
|
|
|
656
689
|
}
|
|
657
690
|
var Item_default = Item;
|
|
658
691
|
|
|
659
|
-
// src/services/benefits-without-document.ts
|
|
660
|
-
var import_js_cookie2 = __toESM(require("js-cookie"));
|
|
661
|
-
var import_meta2 = {};
|
|
662
|
-
var CheckBenefistWithoutDocument = async ({ products }) => {
|
|
663
|
-
const API_URL = import_meta2.env.VITE_API_URL;
|
|
664
|
-
if (!API_URL) {
|
|
665
|
-
throw new Error("API URL is not defined in environment variables");
|
|
666
|
-
}
|
|
667
|
-
const AUTH_TOKEN = import_js_cookie2.default.get("pbm-token");
|
|
668
|
-
if (!AUTH_TOKEN) {
|
|
669
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
670
|
-
}
|
|
671
|
-
const response = await fetch(`${API_URL}/products/genericBenefit`, {
|
|
672
|
-
method: "POST",
|
|
673
|
-
headers: {
|
|
674
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
675
|
-
"Content-Type": "application/json"
|
|
676
|
-
},
|
|
677
|
-
body: JSON.stringify({ products })
|
|
678
|
-
});
|
|
679
|
-
const dataResponse = await response.json();
|
|
680
|
-
if (!dataResponse.success) {
|
|
681
|
-
throw new Error(dataResponse.message || "Failed to fetch benefits without document");
|
|
682
|
-
}
|
|
683
|
-
return dataResponse;
|
|
684
|
-
};
|
|
685
|
-
|
|
686
692
|
// src/components/BenefitsTable/index.tsx
|
|
687
693
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
688
694
|
function BenefitsTable() {
|
|
695
|
+
const [isPending, startTransition] = (0, import_react4.useTransition)();
|
|
689
696
|
const { securityNumber, setState, state, targetProduct, customLoginUrl, isAuthenticatedShopper } = usePBMStore();
|
|
690
697
|
const [selectedDiscout, setSelectedDiscount] = (0, import_react4.useState)(null);
|
|
691
|
-
const [loading, setLoading] = (0, import_react4.useState)(true);
|
|
692
698
|
const [benefitsItems, setBenefitsItems] = (0, import_react4.useState)();
|
|
693
699
|
(0, import_react4.useEffect)(() => {
|
|
700
|
+
if (!targetProduct?.productId) {
|
|
701
|
+
console.error("PBMLOG: Product ID is not defined on targetProduct");
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
if (!targetProduct.ean) {
|
|
705
|
+
console.error("PBMLOG: EAN is not defined on targetProduct");
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
if (!targetProduct.listPrice) {
|
|
709
|
+
console.error("PBMLOG: List Price is not defined on targetProduct");
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
if (!targetProduct.price) {
|
|
713
|
+
console.error("PBMLOG: Price is not defined on targetProduct");
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
694
716
|
const fetchDicountsWithoutDocument = async () => {
|
|
695
|
-
if (!targetProduct?.productId) {
|
|
696
|
-
console.error("PBMLOG: Product ID is not defined on targetProduct");
|
|
697
|
-
return;
|
|
698
|
-
}
|
|
699
|
-
if (!targetProduct.ean) {
|
|
700
|
-
console.error("PBMLOG: EAN is not defined on targetProduct");
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
if (!targetProduct.listPrice) {
|
|
704
|
-
console.error("PBMLOG: List Price is not defined on targetProduct");
|
|
705
|
-
return;
|
|
706
|
-
}
|
|
707
|
-
if (!targetProduct.price) {
|
|
708
|
-
console.error("PBMLOG: Price is not defined on targetProduct");
|
|
709
|
-
return;
|
|
710
|
-
}
|
|
711
717
|
try {
|
|
712
718
|
const data = {
|
|
713
719
|
productId: Number(targetProduct.productId),
|
|
@@ -725,8 +731,6 @@ function BenefitsTable() {
|
|
|
725
731
|
} catch (error) {
|
|
726
732
|
setBenefitsItems(void 0);
|
|
727
733
|
console.error(error);
|
|
728
|
-
} finally {
|
|
729
|
-
setLoading(false);
|
|
730
734
|
}
|
|
731
735
|
};
|
|
732
736
|
const fetchDiscountWithDocument = async () => {
|
|
@@ -734,22 +738,6 @@ function BenefitsTable() {
|
|
|
734
738
|
console.error("PBMLOG: Document is not defined");
|
|
735
739
|
return;
|
|
736
740
|
}
|
|
737
|
-
if (!targetProduct?.productId) {
|
|
738
|
-
console.error("PBMLOG: Product ID is not defined on targetProduct");
|
|
739
|
-
return;
|
|
740
|
-
}
|
|
741
|
-
if (!targetProduct.ean) {
|
|
742
|
-
console.error("PBMLOG: EAN is not defined on targetProduct");
|
|
743
|
-
return;
|
|
744
|
-
}
|
|
745
|
-
if (!targetProduct.listPrice) {
|
|
746
|
-
console.error("PBMLOG: List Price is not defined on targetProduct");
|
|
747
|
-
return;
|
|
748
|
-
}
|
|
749
|
-
if (!targetProduct.price) {
|
|
750
|
-
console.error("PBMLOG: Price is not defined on targetProduct");
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
741
|
try {
|
|
754
742
|
const data = {
|
|
755
743
|
productId: Number(targetProduct.productId),
|
|
@@ -767,13 +755,13 @@ function BenefitsTable() {
|
|
|
767
755
|
} catch (error) {
|
|
768
756
|
setBenefitsItems(void 0);
|
|
769
757
|
console.error(error);
|
|
770
|
-
} finally {
|
|
771
|
-
setLoading(false);
|
|
772
758
|
}
|
|
773
759
|
};
|
|
774
|
-
|
|
760
|
+
startTransition(async () => {
|
|
761
|
+
state === "isActivated" ? await fetchDiscountWithDocument() : await fetchDicountsWithoutDocument();
|
|
762
|
+
});
|
|
775
763
|
}, []);
|
|
776
|
-
if (
|
|
764
|
+
if (isPending) {
|
|
777
765
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
|
|
778
766
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
779
767
|
"div",
|
|
@@ -932,22 +920,13 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
932
920
|
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("br", {}),
|
|
933
921
|
"Ao clicar em \u201CAceitar os termos\u201D, voc\xEA ir\xE1 para uma p\xE1gina externa. Aceite os termos e volte para continuar."
|
|
934
922
|
] }),
|
|
935
|
-
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
936
|
-
Link_default,
|
|
937
|
-
{
|
|
938
|
-
href: urlAcceptTerms || "",
|
|
939
|
-
children: "Aceitar os termos"
|
|
940
|
-
}
|
|
941
|
-
)
|
|
923
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Link_default, { href: urlAcceptTerms || "", children: "Aceitar os termos" })
|
|
942
924
|
]
|
|
943
925
|
}
|
|
944
926
|
);
|
|
945
927
|
}
|
|
946
928
|
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
947
929
|
|
|
948
|
-
// src/PBM.tsx
|
|
949
|
-
var import_react5 = require("react");
|
|
950
|
-
|
|
951
930
|
// src/components/SecurityNumberRegitered/index.tsx
|
|
952
931
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
953
932
|
function SecurityNumberRegitered({ textColor }) {
|
|
@@ -961,19 +940,87 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
961
940
|
children: [
|
|
962
941
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Title_default, { className: "w-full", textColor, children: "Ops, seu CPF ainda n\xE3o est\xE1 habilitado para este produto." }),
|
|
963
942
|
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Text_default, { className: "w-full", textColor, children: "Para ativar o benef\xEDcio, clique em \u201CAtivar CPF\u201D e conclua a etapa na p\xE1gina externa. Depois, \xE9 s\xF3 voltar para continuar \u2014 vamos aguardar voc\xEA aqui." }),
|
|
964
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
965
|
-
Link_default,
|
|
966
|
-
{
|
|
967
|
-
href: urlRegisterIndustry || "",
|
|
968
|
-
children: "Ativar CPF"
|
|
969
|
-
}
|
|
970
|
-
)
|
|
943
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(Link_default, { href: urlRegisterIndustry || "", children: "Ativar CPF" })
|
|
971
944
|
]
|
|
972
945
|
}
|
|
973
946
|
);
|
|
974
947
|
}
|
|
975
948
|
var SecurityNumberRegitered_default = SecurityNumberRegitered;
|
|
976
949
|
|
|
950
|
+
// src/components/Errors/ErrorToApplyBenefits.tsx
|
|
951
|
+
var import_lucide_react2 = require("lucide-react");
|
|
952
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
953
|
+
var ErrorToApplyBenefits = () => {
|
|
954
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Container_default, { variant: "main", children: [
|
|
955
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Title_default, { children: "Erro ao Aplicar o Benef\xEDcio" }),
|
|
956
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Text_default, { textAlign: "center", children: [
|
|
957
|
+
"O produto n\xE3o foi encontrado no sistema. ",
|
|
958
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("br", {}),
|
|
959
|
+
" Por favor, tente novamente mais tarde ou contate o suporte."
|
|
960
|
+
] }),
|
|
961
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
|
|
962
|
+
Button_default,
|
|
963
|
+
{
|
|
964
|
+
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",
|
|
965
|
+
onClick: () => window.location.reload(),
|
|
966
|
+
id: "check_benefits_button",
|
|
967
|
+
children: [
|
|
968
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("span", { children: "Tentar novamente" }),
|
|
969
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_lucide_react2.RefreshCw, { size: 16 })
|
|
970
|
+
]
|
|
971
|
+
}
|
|
972
|
+
)
|
|
973
|
+
] });
|
|
974
|
+
};
|
|
975
|
+
var ErrorToApplyBenefits_default = ErrorToApplyBenefits;
|
|
976
|
+
|
|
977
|
+
// src/components/Modal/index.tsx
|
|
978
|
+
var import_classnames9 = __toESM(require("classnames"));
|
|
979
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
980
|
+
var Modal = ({ ID }) => {
|
|
981
|
+
const { customLoginUrl } = usePBMStore();
|
|
982
|
+
const { modal, setModal } = useModal();
|
|
983
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("main", { className: (0, import_classnames9.default)(
|
|
984
|
+
"fixed inset-0 flex items-center justify-center z-50 flex-col transition-all shadow bg-black/40",
|
|
985
|
+
{
|
|
986
|
+
"opacity-100 pointer-events-auto": modal.id === ID && modal.open,
|
|
987
|
+
"opacity-0 pointer-events-none": modal.id != ID || !modal.open
|
|
988
|
+
}
|
|
989
|
+
), children: [
|
|
990
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("div", { className: "absolute inset-0", onClick: () => setModal({ id: "", open: false }) }),
|
|
991
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("section", { className: "z-10 bg-white gap-2 flex-col items-center-safe justify-center-safe p-8 rounded-xl", children: [
|
|
992
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Title_default, { textColor: "tomato", textSize: "18px", textAlign: "center", className: "mb-2", children: "Opa! Parece que voc\xEA n\xE3o est\xE1 Logado" }),
|
|
993
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(Text_default, { className: "mb-2", textAlign: "center", children: [
|
|
994
|
+
"Para aproveitar os benef\xEDcios \xE9 necess\xE1rio realizar o ",
|
|
995
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("strong", { children: "Login" }),
|
|
996
|
+
" ou ",
|
|
997
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("strong", { children: "Cadastro" }),
|
|
998
|
+
" no site!"
|
|
999
|
+
] }),
|
|
1000
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)("section", { className: "flex items-center-safe justify-center-safe gap-4", children: [
|
|
1001
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Button_default, { className: "bg-gray-600 hover:bg-gray-500", onClick: () => setModal({ id: "", open: false }), children: "Seguir sem Benef\xEDcios" }),
|
|
1002
|
+
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Link_default, { href: customLoginUrl || "/login", children: "Aproveitar Benef\xEDcios" })
|
|
1003
|
+
] })
|
|
1004
|
+
] })
|
|
1005
|
+
] });
|
|
1006
|
+
};
|
|
1007
|
+
var Modal_default = Modal;
|
|
1008
|
+
|
|
1009
|
+
// src/PBM.tsx
|
|
1010
|
+
var import_Skeleton = __toESM(require("@mui/material/Skeleton"));
|
|
1011
|
+
|
|
1012
|
+
// src/utils/format-price.ts
|
|
1013
|
+
var formatedPrice = (price) => {
|
|
1014
|
+
const result = Number(String(price).replace(",", "."));
|
|
1015
|
+
return result;
|
|
1016
|
+
};
|
|
1017
|
+
|
|
1018
|
+
// src/PBM.tsx
|
|
1019
|
+
var import_react6 = require("react");
|
|
1020
|
+
|
|
1021
|
+
// src/hooks/useAppStartup.tsx
|
|
1022
|
+
var import_react5 = require("react");
|
|
1023
|
+
|
|
977
1024
|
// src/services/authorization.ts
|
|
978
1025
|
var import_js_cookie3 = __toESM(require("js-cookie"));
|
|
979
1026
|
var GetAuthorization = async ({ clientID }) => {
|
|
@@ -1005,9 +1052,6 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
1005
1052
|
return data;
|
|
1006
1053
|
};
|
|
1007
1054
|
|
|
1008
|
-
// src/PBM.tsx
|
|
1009
|
-
var import_lucide_react2 = require("lucide-react");
|
|
1010
|
-
|
|
1011
1055
|
// src/services/get-product-by-ean.ts
|
|
1012
1056
|
var import_js_cookie4 = __toESM(require("js-cookie"));
|
|
1013
1057
|
var import_meta3 = {};
|
|
@@ -1031,41 +1075,6 @@ var GetProductByEAN = async ({ PRODUCT_EAN }) => {
|
|
|
1031
1075
|
return dataResponse;
|
|
1032
1076
|
};
|
|
1033
1077
|
|
|
1034
|
-
// src/PBM.tsx
|
|
1035
|
-
var import_Skeleton = __toESM(require("@mui/material/Skeleton"));
|
|
1036
|
-
|
|
1037
|
-
// src/components/Modal/index.tsx
|
|
1038
|
-
var import_classnames9 = __toESM(require("classnames"));
|
|
1039
|
-
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1040
|
-
var Modal = ({ ID }) => {
|
|
1041
|
-
const { customLoginUrl } = usePBMStore();
|
|
1042
|
-
const { modal, setModal } = useModal();
|
|
1043
|
-
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("main", { className: (0, import_classnames9.default)(
|
|
1044
|
-
"fixed inset-0 flex items-center justify-center z-50 flex-col transition-all shadow bg-black/40",
|
|
1045
|
-
{
|
|
1046
|
-
"opacity-100 pointer-events-auto": modal.id === ID && modal.open,
|
|
1047
|
-
"opacity-0 pointer-events-none": modal.id != ID || !modal.open
|
|
1048
|
-
}
|
|
1049
|
-
), children: [
|
|
1050
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: "absolute inset-0", onClick: () => setModal({ id: "", open: false }) }),
|
|
1051
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("section", { className: "z-10 bg-white gap-2 flex-col items-center-safe justify-center-safe p-8 rounded-xl", children: [
|
|
1052
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Title_default, { textColor: "tomato", textSize: "18px", textAlign: "center", className: "mb-2", children: "Opa! Parece que voc\xEA n\xE3o est\xE1 Logado" }),
|
|
1053
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Text_default, { className: "mb-2", textAlign: "center", children: [
|
|
1054
|
-
"Para aproveitar os benef\xEDcios \xE9 necess\xE1rio realizar o ",
|
|
1055
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("strong", { children: "Login" }),
|
|
1056
|
-
" ou ",
|
|
1057
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("strong", { children: "Cadastro" }),
|
|
1058
|
-
" no site!"
|
|
1059
|
-
] }),
|
|
1060
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("section", { className: "flex items-center-safe justify-center-safe gap-4", children: [
|
|
1061
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Button_default, { className: "bg-gray-600 hover:bg-gray-500", onClick: () => setModal({ id: "", open: false }), children: "Seguir sem Benef\xEDcios" }),
|
|
1062
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Link_default, { href: customLoginUrl || "/login", children: "Aproveitar Benef\xEDcios" })
|
|
1063
|
-
] })
|
|
1064
|
-
] })
|
|
1065
|
-
] });
|
|
1066
|
-
};
|
|
1067
|
-
var Modal_default = Modal;
|
|
1068
|
-
|
|
1069
1078
|
// src/services/get-list-products.ts
|
|
1070
1079
|
var import_js_cookie5 = __toESM(require("js-cookie"));
|
|
1071
1080
|
var import_meta4 = {};
|
|
@@ -1089,44 +1098,33 @@ var GetProductsWithBenefits = async () => {
|
|
|
1089
1098
|
return dataResponse;
|
|
1090
1099
|
};
|
|
1091
1100
|
|
|
1092
|
-
// src/
|
|
1093
|
-
var
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
clientID,
|
|
1097
|
-
eanProduct,
|
|
1098
|
-
isAuthenticatedShopper,
|
|
1099
|
-
customLoginUrl
|
|
1100
|
-
}) {
|
|
1101
|
-
const formatedOriginalProductPrice = Number(
|
|
1102
|
-
String(originalProductPrice).replace(",", ".")
|
|
1103
|
-
);
|
|
1104
|
-
const [isReady, setIsReady] = (0, import_react5.useState)(false);
|
|
1105
|
-
const [loading, setLoading] = (0, import_react5.useState)(false);
|
|
1106
|
-
const { state, setTargetProduct, targetProduct, setIsAuthenticatedShopper, setCustomLoginUrl } = usePBMStore();
|
|
1107
|
-
const [EanProductExist, setEanProductExist] = (0, import_react5.useState)(true);
|
|
1101
|
+
// src/hooks/useAppStartup.tsx
|
|
1102
|
+
var useAppStartup = (props) => {
|
|
1103
|
+
const { setTargetProduct, targetProduct, setIsAuthenticatedShopper, setCustomLoginUrl } = usePBMStore();
|
|
1104
|
+
const [IsReady, setIsReady] = (0, import_react5.useState)(false);
|
|
1108
1105
|
const [IsValid, setIsValid] = (0, import_react5.useState)(false);
|
|
1106
|
+
const [EanProductExist, setEanProductExist] = (0, import_react5.useState)(true);
|
|
1109
1107
|
const fetchValidateProduct = (0, import_react5.useCallback)(async () => {
|
|
1110
1108
|
try {
|
|
1111
1109
|
const response = await GetProductsWithBenefits();
|
|
1112
1110
|
if (response.success) {
|
|
1113
1111
|
const data = response.data;
|
|
1114
|
-
const hasProductInList = data.some((product) => product.ean == eanProduct);
|
|
1112
|
+
const hasProductInList = data.some((product) => product.ean == props.eanProduct);
|
|
1115
1113
|
setIsValid(hasProductInList);
|
|
1116
1114
|
}
|
|
1117
1115
|
} catch (error) {
|
|
1118
1116
|
console.error(error);
|
|
1119
1117
|
}
|
|
1120
|
-
}, [eanProduct, IsValid]);
|
|
1118
|
+
}, [props.eanProduct, IsValid]);
|
|
1121
1119
|
const fetchProductByEan = async () => {
|
|
1122
1120
|
try {
|
|
1123
1121
|
if (!IsValid) return;
|
|
1124
|
-
if (!eanProduct) {
|
|
1122
|
+
if (!props.eanProduct) {
|
|
1125
1123
|
console.error("PBMLOG: Ean is not defined.");
|
|
1126
1124
|
setEanProductExist(false);
|
|
1127
1125
|
return;
|
|
1128
1126
|
}
|
|
1129
|
-
const response = await GetProductByEAN({ PRODUCT_EAN: eanProduct });
|
|
1127
|
+
const response = await GetProductByEAN({ PRODUCT_EAN: props.eanProduct });
|
|
1130
1128
|
if (response.success && response.data) {
|
|
1131
1129
|
setEanProductExist(true);
|
|
1132
1130
|
const { pbm, sku, ...targetProductNewData } = response.data;
|
|
@@ -1137,10 +1135,10 @@ function PBM({
|
|
|
1137
1135
|
informativeMessage: pbm.informativeMessage ?? "",
|
|
1138
1136
|
discountMax: pbm.discountMax ?? 0,
|
|
1139
1137
|
industryLogo: pbm.imageLink ?? void 0,
|
|
1140
|
-
ean: eanProduct
|
|
1138
|
+
ean: props.eanProduct
|
|
1141
1139
|
});
|
|
1142
|
-
setIsAuthenticatedShopper(isAuthenticatedShopper);
|
|
1143
|
-
setCustomLoginUrl(customLoginUrl);
|
|
1140
|
+
setIsAuthenticatedShopper(props.isAuthenticatedShopper);
|
|
1141
|
+
setCustomLoginUrl(props.customLoginUrl);
|
|
1144
1142
|
}
|
|
1145
1143
|
} catch (error) {
|
|
1146
1144
|
console.error(error);
|
|
@@ -1148,9 +1146,9 @@ function PBM({
|
|
|
1148
1146
|
setIsReady(true);
|
|
1149
1147
|
}
|
|
1150
1148
|
};
|
|
1151
|
-
const
|
|
1149
|
+
const fetchAuthorizationRequest = (0, import_react5.useCallback)(async () => {
|
|
1152
1150
|
try {
|
|
1153
|
-
const response = await GetAuthorization({ clientID });
|
|
1151
|
+
const response = await GetAuthorization({ clientID: props.clientID });
|
|
1154
1152
|
if (response.success) {
|
|
1155
1153
|
fetchValidateProduct();
|
|
1156
1154
|
fetchProductByEan();
|
|
@@ -1160,50 +1158,40 @@ function PBM({
|
|
|
1160
1158
|
} catch (error) {
|
|
1161
1159
|
console.error("Error fetching authorization:", error);
|
|
1162
1160
|
}
|
|
1163
|
-
}, [clientID, IsValid]);
|
|
1161
|
+
}, [props.clientID, IsValid]);
|
|
1164
1162
|
(0, import_react5.useEffect)(() => {
|
|
1165
|
-
|
|
1166
|
-
}, [
|
|
1167
|
-
|
|
1168
|
-
|
|
1163
|
+
fetchAuthorizationRequest();
|
|
1164
|
+
}, [fetchAuthorizationRequest]);
|
|
1165
|
+
return { IsReady, IsValid, EanProductExist };
|
|
1166
|
+
};
|
|
1167
|
+
var useAppStartup_default = useAppStartup;
|
|
1168
|
+
|
|
1169
|
+
// src/PBM.tsx
|
|
1170
|
+
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
1171
|
+
function PBM(props) {
|
|
1172
|
+
const { state } = usePBMStore();
|
|
1173
|
+
const { IsReady, EanProductExist, IsValid } = useAppStartup_default(props);
|
|
1174
|
+
const [isPending, startTransition] = (0, import_react6.useTransition)();
|
|
1175
|
+
const formatedProductPrice = formatedPrice(props.originalProductPrice);
|
|
1176
|
+
if (!IsReady) {
|
|
1177
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_Skeleton.default, { variant: "rectangular", style: { borderRadius: "12px" }, width: 460, height: 358 });
|
|
1169
1178
|
}
|
|
1170
1179
|
if (!EanProductExist) {
|
|
1171
|
-
return /* @__PURE__ */ (0,
|
|
1172
|
-
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(Title_default, { children: "Erro ao Aplicar o Benef\xEDcio" }),
|
|
1173
|
-
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(Text_default, { textAlign: "center", children: [
|
|
1174
|
-
"O produto n\xE3o foi encontrado no sistema. ",
|
|
1175
|
-
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("br", {}),
|
|
1176
|
-
" Por favor, tente novamente mais tarde ou contate o suporte."
|
|
1177
|
-
] }),
|
|
1178
|
-
/* @__PURE__ */ (0, import_jsx_runtime16.jsxs)(
|
|
1179
|
-
Button_default,
|
|
1180
|
-
{
|
|
1181
|
-
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",
|
|
1182
|
-
onClick: () => window.location.reload(),
|
|
1183
|
-
id: "check_benefits_button",
|
|
1184
|
-
children: [
|
|
1185
|
-
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)("span", { children: "Tentar novamente" }),
|
|
1186
|
-
/* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_lucide_react2.RefreshCw, { size: 16 })
|
|
1187
|
-
]
|
|
1188
|
-
}
|
|
1189
|
-
)
|
|
1190
|
-
] }) });
|
|
1191
|
-
}
|
|
1192
|
-
if (!IsValid) {
|
|
1193
|
-
return;
|
|
1180
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", { id: "pbm-library-root", children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ErrorToApplyBenefits_default, {}) });
|
|
1194
1181
|
}
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
/* @__PURE__ */ (0,
|
|
1199
|
-
|
|
1200
|
-
state === "
|
|
1201
|
-
state === "
|
|
1202
|
-
|
|
1182
|
+
if (!IsValid) return;
|
|
1183
|
+
return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("div", { id: "pbm-library-root", children: [
|
|
1184
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Container_default, { variant: "main", children: [
|
|
1185
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Header_default, { originalProductPrice: formatedProductPrice || 0 }),
|
|
1186
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Container_default, { variant: "simple", children: isPending ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Loading_default, {}) : /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_jsx_runtime17.Fragment, { children: [
|
|
1187
|
+
state === "isEmpty" && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Form_default, { startTransition }),
|
|
1188
|
+
state === "isInvalid" && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SecurityNumberInvalid_default, {}),
|
|
1189
|
+
state === "isRegistered" && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(SecurityNumberRegitered_default, {}),
|
|
1190
|
+
(state === "isActivated" || state === "isPreview") && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(BenefitsTable_default, {})
|
|
1203
1191
|
] }) }),
|
|
1204
|
-
/* @__PURE__ */ (0,
|
|
1192
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Footer_default, {})
|
|
1205
1193
|
] }),
|
|
1206
|
-
/* @__PURE__ */ (0,
|
|
1194
|
+
/* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Modal_default, { ID: "ShopperIsNotAuthenticated" })
|
|
1207
1195
|
] });
|
|
1208
1196
|
}
|
|
1209
1197
|
var PBM_default = PBM;
|