@agrada_digital/pbm 0.0.116 → 0.0.118
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 +13 -6
- package/dist/index.css +0 -3
- package/dist/index.d.ts +10 -11
- package/dist/index.js +40 -29
- package/dist/vanilla.js +53 -30
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -35,14 +35,21 @@ pnpm add @agrada_digital/pbm
|
|
|
35
35
|
Inclua via `<script>`:
|
|
36
36
|
|
|
37
37
|
```html
|
|
38
|
-
<script src="https://unpkg.com/@agrada_digital/pbm/vanilla"
|
|
38
|
+
<script src="https://unpkg.com/@agrada_digital/pbm/vanilla" defer></script>
|
|
39
|
+
|
|
40
|
+
const TARGET_PRODUCT = {
|
|
41
|
+
id: "*****",
|
|
42
|
+
ean: "********",
|
|
43
|
+
requestedQuantity: "*",
|
|
44
|
+
listPrice: "*****",
|
|
45
|
+
netPrice: "*****",
|
|
46
|
+
}
|
|
39
47
|
|
|
40
48
|
<pbm-component
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
customloginurl="/login"
|
|
49
|
+
tenant_id="******"
|
|
50
|
+
target_product={TARGET_PRODUCT}
|
|
51
|
+
is_authenticated_shopper={BOOLEAN}
|
|
52
|
+
custom_login_url="/login"
|
|
46
53
|
>
|
|
47
54
|
</pbm-component>
|
|
48
55
|
```
|
package/dist/index.css
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -12,7 +12,6 @@ interface PBMTheme {
|
|
|
12
12
|
inputFocusBackgroundColor?: string;
|
|
13
13
|
}
|
|
14
14
|
interface PBMProps {
|
|
15
|
-
original_product_price: number | string;
|
|
16
15
|
tenant_id: string;
|
|
17
16
|
target_product: TargetProduct;
|
|
18
17
|
is_authenticated_shopper: boolean;
|
|
@@ -45,18 +44,18 @@ interface usePBMTypes {
|
|
|
45
44
|
cardID?: string | number;
|
|
46
45
|
}
|
|
47
46
|
interface TargetProduct {
|
|
48
|
-
id:
|
|
49
|
-
ean:
|
|
50
|
-
requestedQuantity:
|
|
51
|
-
listPrice:
|
|
52
|
-
netPrice:
|
|
47
|
+
id: string;
|
|
48
|
+
ean: string;
|
|
49
|
+
requestedQuantity: string;
|
|
50
|
+
listPrice: string;
|
|
51
|
+
netPrice: string;
|
|
53
52
|
}
|
|
54
53
|
interface IProduct {
|
|
55
|
-
id:
|
|
56
|
-
ean:
|
|
57
|
-
listPrice:
|
|
58
|
-
netPrice:
|
|
59
|
-
authorizedQuantity:
|
|
54
|
+
id: string;
|
|
55
|
+
ean: string;
|
|
56
|
+
listPrice: string;
|
|
57
|
+
netPrice: string;
|
|
58
|
+
authorizedQuantity: string;
|
|
60
59
|
discountValue: string;
|
|
61
60
|
suggestedPriceValue: string;
|
|
62
61
|
discountPercentual: string;
|
package/dist/index.js
CHANGED
|
@@ -110,6 +110,9 @@ var maskCPF = (value) => value.replace(/\D/g, "").replace(/(\d{3})(\d{3})(\d{3})
|
|
|
110
110
|
var formatPrice = (price) => Number(String(price).replace(",", "."));
|
|
111
111
|
var transformPrice = (price) => {
|
|
112
112
|
const priceString = String(price);
|
|
113
|
+
if (priceString.includes(".") || priceString.includes(",")) {
|
|
114
|
+
return formatPrice(price);
|
|
115
|
+
}
|
|
113
116
|
const cents = priceString.slice(-2);
|
|
114
117
|
const reais = priceString.slice(0, -2) || "0";
|
|
115
118
|
return Number(`${reais}.${cents}`);
|
|
@@ -119,10 +122,14 @@ var transformPorcent = (porcent) => {
|
|
|
119
122
|
const pre = porcent.slice(0, -2) || "0";
|
|
120
123
|
return Number(`${pre}.${post}`);
|
|
121
124
|
};
|
|
125
|
+
function priceToInteger(value) {
|
|
126
|
+
return String(value).replace(/[.,]/g, "");
|
|
127
|
+
}
|
|
122
128
|
var formaters = {
|
|
123
129
|
phone: (value) => formatPhone(value),
|
|
124
130
|
cep: (value) => formatCEP(value),
|
|
125
131
|
cpf: (value) => maskCPF(value),
|
|
132
|
+
priceToInteger: (value) => priceToInteger(value),
|
|
126
133
|
price: (price) => formatPrice(price),
|
|
127
134
|
transformPrice: (price) => transformPrice(price),
|
|
128
135
|
transformPorcent: (porcent) => transformPorcent(porcent)
|
|
@@ -154,6 +161,13 @@ var LookupConsumer = async ({ product, consumer }) => {
|
|
|
154
161
|
if (!product) {
|
|
155
162
|
throw new Error(`Product information is required`);
|
|
156
163
|
}
|
|
164
|
+
const product_payload = {
|
|
165
|
+
id: product.id,
|
|
166
|
+
ean: product.ean,
|
|
167
|
+
requestedQuantity: product.requestedQuantity,
|
|
168
|
+
listPrice: product.listPrice,
|
|
169
|
+
netPrice: product.netPrice
|
|
170
|
+
};
|
|
157
171
|
try {
|
|
158
172
|
const response = await fetch(
|
|
159
173
|
`${getEnv("VITE_API_URL")}/api/lookup-consumer.ts`,
|
|
@@ -166,7 +180,7 @@ var LookupConsumer = async ({ product, consumer }) => {
|
|
|
166
180
|
},
|
|
167
181
|
body: JSON.stringify({
|
|
168
182
|
tenant_id,
|
|
169
|
-
product,
|
|
183
|
+
product: product_payload,
|
|
170
184
|
table_id: Cookies.get("current-table-id"),
|
|
171
185
|
local_hour: Cookies.get("current-local-hour"),
|
|
172
186
|
consumer
|
|
@@ -230,6 +244,8 @@ function Form({ startTransition }) {
|
|
|
230
244
|
});
|
|
231
245
|
return;
|
|
232
246
|
}
|
|
247
|
+
store.setBenefitsList(consumerHasDiscountEnabled.product);
|
|
248
|
+
store.setState("isActivated");
|
|
233
249
|
};
|
|
234
250
|
const onSubmitDefault = async (values) => {
|
|
235
251
|
if (!store.isAuthenticatedShopper) {
|
|
@@ -577,19 +593,17 @@ var Icons = {
|
|
|
577
593
|
|
|
578
594
|
// src/components/Header/index.tsx
|
|
579
595
|
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
580
|
-
function Header(
|
|
596
|
+
function Header() {
|
|
581
597
|
const { targetProduct, benefitsEnabled, setBenefitsEnabled } = usePBMStore();
|
|
582
|
-
const Price = formaters.transformPrice(
|
|
583
|
-
Number(targetProduct?.listPrice) || originalProductPrice
|
|
584
|
-
);
|
|
598
|
+
const Price = formaters.transformPrice(Number(targetProduct?.listPrice));
|
|
585
599
|
const DiscountValue = formaters.transformPrice(
|
|
586
600
|
Number(targetProduct?.discountValue) || 0
|
|
587
601
|
);
|
|
588
602
|
const DiscountPercentual = formaters.transformPorcent(
|
|
589
|
-
targetProduct?.
|
|
603
|
+
targetProduct?.discountPercentual || "0"
|
|
590
604
|
);
|
|
591
605
|
const DiscountPercentualValue = Price * DiscountPercentual / 100;
|
|
592
|
-
const DiscountApplied = Price -
|
|
606
|
+
const DiscountApplied = Price - DiscountValue || Price - DiscountPercentualValue;
|
|
593
607
|
return /* @__PURE__ */ jsxs3(
|
|
594
608
|
"header",
|
|
595
609
|
{
|
|
@@ -727,7 +741,7 @@ function Title(props) {
|
|
|
727
741
|
var Title_default = Title;
|
|
728
742
|
|
|
729
743
|
// src/components/BenefitsTable/index.tsx
|
|
730
|
-
import { useState as useState2
|
|
744
|
+
import { useState as useState2 } from "react";
|
|
731
745
|
|
|
732
746
|
// src/components/BenefitsTable/Item.tsx
|
|
733
747
|
import { useCallback, useEffect } from "react";
|
|
@@ -746,10 +760,10 @@ function Item({ data, onChange, checked }) {
|
|
|
746
760
|
const DiscountPercentual = formaters.transformPorcent(
|
|
747
761
|
data?.discountPercentual || "0"
|
|
748
762
|
);
|
|
749
|
-
const TotalDiscountValue = DiscountValuePerUnity * data.authorizedQuantity;
|
|
750
|
-
const TotalPricePerQuantity = PricePerUnity * data.authorizedQuantity;
|
|
763
|
+
const TotalDiscountValue = DiscountValuePerUnity * Number(data.authorizedQuantity);
|
|
764
|
+
const TotalPricePerQuantity = PricePerUnity * Number(data.authorizedQuantity);
|
|
751
765
|
const DiscountPercentualValue = TotalPricePerQuantity * DiscountPercentual / 100;
|
|
752
|
-
const AppliedDiscount = TotalPricePerQuantity -
|
|
766
|
+
const AppliedDiscount = TotalPricePerQuantity - TotalDiscountValue || TotalPricePerQuantity - DiscountPercentualValue;
|
|
753
767
|
const updateStorageData = useCallback(() => {
|
|
754
768
|
if (checked) {
|
|
755
769
|
const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
|
|
@@ -758,7 +772,7 @@ function Item({ data, onChange, checked }) {
|
|
|
758
772
|
total: roundToTwoDecimals(TotalDiscountValue),
|
|
759
773
|
unit: roundToTwoDecimals(DiscountValuePerUnity)
|
|
760
774
|
},
|
|
761
|
-
quantity: data.authorizedQuantity,
|
|
775
|
+
quantity: Number(data.authorizedQuantity),
|
|
762
776
|
totalPrice: roundToTwoDecimals(AppliedDiscount),
|
|
763
777
|
grossPrice: data.grossPrice
|
|
764
778
|
});
|
|
@@ -793,8 +807,7 @@ function Item({ data, onChange, checked }) {
|
|
|
793
807
|
"label_benefits w-full flex items-center justify-start bg-zinc-300/60 border border-zinc-400/50 px-4 py-2 transition-colors rounded-lg gap-1",
|
|
794
808
|
{
|
|
795
809
|
"cursor-not-allowed": state === "isPreview",
|
|
796
|
-
"cursor-pointer": state === "isActivated"
|
|
797
|
-
"opacity-80": !checked && state === "isActivated"
|
|
810
|
+
"cursor-pointer": state === "isActivated"
|
|
798
811
|
}
|
|
799
812
|
),
|
|
800
813
|
style: {
|
|
@@ -871,22 +884,15 @@ var APPROVED_BENEFIT_CODE = "N000";
|
|
|
871
884
|
// src/components/BenefitsTable/index.tsx
|
|
872
885
|
import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
873
886
|
function BenefitsTable() {
|
|
874
|
-
const [isPending] = useTransition();
|
|
875
887
|
const {
|
|
876
|
-
// securityNumber,
|
|
877
888
|
setState,
|
|
878
889
|
state,
|
|
879
|
-
// targetProduct,
|
|
880
890
|
customLoginUrl,
|
|
881
891
|
isAuthenticatedShopper,
|
|
882
|
-
// requestId,
|
|
883
892
|
benefitsList
|
|
884
893
|
} = usePBMStore();
|
|
885
894
|
const [selectedDiscout, setSelectedDiscount] = useState2(null);
|
|
886
895
|
const [benefitsItems] = useState2(benefitsList);
|
|
887
|
-
if (isPending) {
|
|
888
|
-
return /* @__PURE__ */ jsx9(Loading_default, { textColor: "var(--pbm-text)" });
|
|
889
|
-
}
|
|
890
896
|
if (benefitsItems?.length && benefitsItems[0]?.returnCode !== APPROVED_BENEFIT_CODE && state === "isActivated") {
|
|
891
897
|
return /* @__PURE__ */ jsx9("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: /* @__PURE__ */ jsx9(
|
|
892
898
|
"p",
|
|
@@ -2007,7 +2013,13 @@ var StepAcceptancesForm = ({
|
|
|
2007
2013
|
type: data.doctor.typeCredential,
|
|
2008
2014
|
name: data.doctor.doctorName
|
|
2009
2015
|
},
|
|
2010
|
-
product:
|
|
2016
|
+
product: {
|
|
2017
|
+
id: targetProduct.id,
|
|
2018
|
+
ean: targetProduct.ean,
|
|
2019
|
+
requestedQuantity: targetProduct.requestedQuantity,
|
|
2020
|
+
listPrice: targetProduct.listPrice,
|
|
2021
|
+
netPrice: targetProduct.netPrice
|
|
2022
|
+
}
|
|
2011
2023
|
};
|
|
2012
2024
|
try {
|
|
2013
2025
|
const response = await EnableDiscount(PAYLOAD);
|
|
@@ -2661,9 +2673,9 @@ var useAppStartup = (props) => {
|
|
|
2661
2673
|
}
|
|
2662
2674
|
setTargetProduct({
|
|
2663
2675
|
...response.product[0],
|
|
2664
|
-
requestedQuantity: 1,
|
|
2665
|
-
listPrice: props.target_product.listPrice,
|
|
2666
|
-
netPrice: props.target_product.netPrice
|
|
2676
|
+
requestedQuantity: "1",
|
|
2677
|
+
listPrice: formaters.priceToInteger(props.target_product.listPrice),
|
|
2678
|
+
netPrice: formaters.priceToInteger(props.target_product.netPrice)
|
|
2667
2679
|
});
|
|
2668
2680
|
setBenefitsList(
|
|
2669
2681
|
response.product.map((prod) => ({
|
|
@@ -2711,15 +2723,14 @@ var useAppStartup = (props) => {
|
|
|
2711
2723
|
var useAppStartup_default = useAppStartup;
|
|
2712
2724
|
|
|
2713
2725
|
// src/PBM.tsx
|
|
2714
|
-
import { useTransition
|
|
2726
|
+
import { useTransition } from "react";
|
|
2715
2727
|
import { Fragment as Fragment3, jsx as jsx27, jsxs as jsxs22 } from "react/jsx-runtime";
|
|
2716
2728
|
function PBM(props) {
|
|
2717
2729
|
const { state } = usePBMStore();
|
|
2718
2730
|
const { IsReady, EanProductExist, IsValid } = useAppStartup_default(props);
|
|
2719
2731
|
const { setErrorMessage } = useError();
|
|
2720
2732
|
const theme = useTheme();
|
|
2721
|
-
const [isPending, startTransition] =
|
|
2722
|
-
const formatedProductPrice = formaters.price(props.original_product_price);
|
|
2733
|
+
const [isPending, startTransition] = useTransition();
|
|
2723
2734
|
if (!IsValid) return;
|
|
2724
2735
|
if (!IsReady) {
|
|
2725
2736
|
return /* @__PURE__ */ jsx27(
|
|
@@ -2755,7 +2766,7 @@ function PBM(props) {
|
|
|
2755
2766
|
},
|
|
2756
2767
|
children: [
|
|
2757
2768
|
/* @__PURE__ */ jsxs22(Container_default, { variant: "main", children: [
|
|
2758
|
-
/* @__PURE__ */ jsx27(Header_default, {
|
|
2769
|
+
/* @__PURE__ */ jsx27(Header_default, {}),
|
|
2759
2770
|
/* @__PURE__ */ jsx27(Container_default, { variant: "simple", children: isPending ? /* @__PURE__ */ jsx27(Loading_default, {}) : /* @__PURE__ */ jsxs22(Fragment3, { children: [
|
|
2760
2771
|
state === "isEmpty" && /* @__PURE__ */ jsx27(Form_default, { startTransition }),
|
|
2761
2772
|
state === "isInvalid" && /* @__PURE__ */ jsx27(SecurityNumberInvalid_default, {}),
|