@agrada_digital/pbm 0.0.117 → 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 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"> defer></script>
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
- originalproductprice="100.90"
42
- eanproduct="*********"
43
- clientid="*********"
44
- isauthenticatedshopper="true"
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
@@ -963,9 +963,6 @@
963
963
  .opacity-75 {
964
964
  opacity: 75%;
965
965
  }
966
- .opacity-80 {
967
- opacity: 80%;
968
- }
969
966
  .opacity-100 {
970
967
  opacity: 100%;
971
968
  }
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;
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}`);
@@ -120,7 +123,7 @@ var transformPorcent = (porcent) => {
120
123
  return Number(`${pre}.${post}`);
121
124
  };
122
125
  function priceToInteger(value) {
123
- return value.replace(/[.,]/g, "");
126
+ return String(value).replace(/[.,]/g, "");
124
127
  }
125
128
  var formaters = {
126
129
  phone: (value) => formatPhone(value),
@@ -158,6 +161,13 @@ var LookupConsumer = async ({ product, consumer }) => {
158
161
  if (!product) {
159
162
  throw new Error(`Product information is required`);
160
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
+ };
161
171
  try {
162
172
  const response = await fetch(
163
173
  `${getEnv("VITE_API_URL")}/api/lookup-consumer.ts`,
@@ -170,7 +180,7 @@ var LookupConsumer = async ({ product, consumer }) => {
170
180
  },
171
181
  body: JSON.stringify({
172
182
  tenant_id,
173
- product,
183
+ product: product_payload,
174
184
  table_id: Cookies.get("current-table-id"),
175
185
  local_hour: Cookies.get("current-local-hour"),
176
186
  consumer
@@ -234,6 +244,8 @@ function Form({ startTransition }) {
234
244
  });
235
245
  return;
236
246
  }
247
+ store.setBenefitsList(consumerHasDiscountEnabled.product);
248
+ store.setState("isActivated");
237
249
  };
238
250
  const onSubmitDefault = async (values) => {
239
251
  if (!store.isAuthenticatedShopper) {
@@ -581,19 +593,17 @@ var Icons = {
581
593
 
582
594
  // src/components/Header/index.tsx
583
595
  import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
584
- function Header({ originalProductPrice }) {
596
+ function Header() {
585
597
  const { targetProduct, benefitsEnabled, setBenefitsEnabled } = usePBMStore();
586
- const Price = formaters.transformPrice(
587
- Number(targetProduct?.listPrice) || originalProductPrice
588
- );
598
+ const Price = formaters.transformPrice(Number(targetProduct?.listPrice));
589
599
  const DiscountValue = formaters.transformPrice(
590
600
  Number(targetProduct?.discountValue) || 0
591
601
  );
592
602
  const DiscountPercentual = formaters.transformPorcent(
593
- targetProduct?.discountMaxNewPatient || "0"
603
+ targetProduct?.discountPercentual || "0"
594
604
  );
595
605
  const DiscountPercentualValue = Price * DiscountPercentual / 100;
596
- const DiscountApplied = Price - DiscountPercentualValue || Price - DiscountValue;
606
+ const DiscountApplied = Price - DiscountValue || Price - DiscountPercentualValue;
597
607
  return /* @__PURE__ */ jsxs3(
598
608
  "header",
599
609
  {
@@ -731,7 +741,7 @@ function Title(props) {
731
741
  var Title_default = Title;
732
742
 
733
743
  // src/components/BenefitsTable/index.tsx
734
- import { useState as useState2, useTransition } from "react";
744
+ import { useState as useState2 } from "react";
735
745
 
736
746
  // src/components/BenefitsTable/Item.tsx
737
747
  import { useCallback, useEffect } from "react";
@@ -750,10 +760,10 @@ function Item({ data, onChange, checked }) {
750
760
  const DiscountPercentual = formaters.transformPorcent(
751
761
  data?.discountPercentual || "0"
752
762
  );
753
- const TotalDiscountValue = DiscountValuePerUnity * data.authorizedQuantity;
754
- const TotalPricePerQuantity = PricePerUnity * data.authorizedQuantity;
763
+ const TotalDiscountValue = DiscountValuePerUnity * Number(data.authorizedQuantity);
764
+ const TotalPricePerQuantity = PricePerUnity * Number(data.authorizedQuantity);
755
765
  const DiscountPercentualValue = TotalPricePerQuantity * DiscountPercentual / 100;
756
- const AppliedDiscount = TotalPricePerQuantity - DiscountPercentualValue || TotalPricePerQuantity - TotalDiscountValue;
766
+ const AppliedDiscount = TotalPricePerQuantity - TotalDiscountValue || TotalPricePerQuantity - DiscountPercentualValue;
757
767
  const updateStorageData = useCallback(() => {
758
768
  if (checked) {
759
769
  const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
@@ -762,7 +772,7 @@ function Item({ data, onChange, checked }) {
762
772
  total: roundToTwoDecimals(TotalDiscountValue),
763
773
  unit: roundToTwoDecimals(DiscountValuePerUnity)
764
774
  },
765
- quantity: data.authorizedQuantity,
775
+ quantity: Number(data.authorizedQuantity),
766
776
  totalPrice: roundToTwoDecimals(AppliedDiscount),
767
777
  grossPrice: data.grossPrice
768
778
  });
@@ -797,8 +807,7 @@ function Item({ data, onChange, checked }) {
797
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",
798
808
  {
799
809
  "cursor-not-allowed": state === "isPreview",
800
- "cursor-pointer": state === "isActivated",
801
- "opacity-80": !checked && state === "isActivated"
810
+ "cursor-pointer": state === "isActivated"
802
811
  }
803
812
  ),
804
813
  style: {
@@ -875,22 +884,15 @@ var APPROVED_BENEFIT_CODE = "N000";
875
884
  // src/components/BenefitsTable/index.tsx
876
885
  import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
877
886
  function BenefitsTable() {
878
- const [isPending] = useTransition();
879
887
  const {
880
- // securityNumber,
881
888
  setState,
882
889
  state,
883
- // targetProduct,
884
890
  customLoginUrl,
885
891
  isAuthenticatedShopper,
886
- // requestId,
887
892
  benefitsList
888
893
  } = usePBMStore();
889
894
  const [selectedDiscout, setSelectedDiscount] = useState2(null);
890
895
  const [benefitsItems] = useState2(benefitsList);
891
- if (isPending) {
892
- return /* @__PURE__ */ jsx9(Loading_default, { textColor: "var(--pbm-text)" });
893
- }
894
896
  if (benefitsItems?.length && benefitsItems[0]?.returnCode !== APPROVED_BENEFIT_CODE && state === "isActivated") {
895
897
  return /* @__PURE__ */ jsx9("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: /* @__PURE__ */ jsx9(
896
898
  "p",
@@ -2011,7 +2013,13 @@ var StepAcceptancesForm = ({
2011
2013
  type: data.doctor.typeCredential,
2012
2014
  name: data.doctor.doctorName
2013
2015
  },
2014
- product: targetProduct
2016
+ product: {
2017
+ id: targetProduct.id,
2018
+ ean: targetProduct.ean,
2019
+ requestedQuantity: targetProduct.requestedQuantity,
2020
+ listPrice: targetProduct.listPrice,
2021
+ netPrice: targetProduct.netPrice
2022
+ }
2015
2023
  };
2016
2024
  try {
2017
2025
  const response = await EnableDiscount(PAYLOAD);
@@ -2715,15 +2723,14 @@ var useAppStartup = (props) => {
2715
2723
  var useAppStartup_default = useAppStartup;
2716
2724
 
2717
2725
  // src/PBM.tsx
2718
- import { useTransition as useTransition2 } from "react";
2726
+ import { useTransition } from "react";
2719
2727
  import { Fragment as Fragment3, jsx as jsx27, jsxs as jsxs22 } from "react/jsx-runtime";
2720
2728
  function PBM(props) {
2721
2729
  const { state } = usePBMStore();
2722
2730
  const { IsReady, EanProductExist, IsValid } = useAppStartup_default(props);
2723
2731
  const { setErrorMessage } = useError();
2724
2732
  const theme = useTheme();
2725
- const [isPending, startTransition] = useTransition2();
2726
- const formatedProductPrice = formaters.price(props.original_product_price);
2733
+ const [isPending, startTransition] = useTransition();
2727
2734
  if (!IsValid) return;
2728
2735
  if (!IsReady) {
2729
2736
  return /* @__PURE__ */ jsx27(
@@ -2759,7 +2766,7 @@ function PBM(props) {
2759
2766
  },
2760
2767
  children: [
2761
2768
  /* @__PURE__ */ jsxs22(Container_default, { variant: "main", children: [
2762
- /* @__PURE__ */ jsx27(Header_default, { originalProductPrice: formatedProductPrice || 0 }),
2769
+ /* @__PURE__ */ jsx27(Header_default, {}),
2763
2770
  /* @__PURE__ */ jsx27(Container_default, { variant: "simple", children: isPending ? /* @__PURE__ */ jsx27(Loading_default, {}) : /* @__PURE__ */ jsxs22(Fragment3, { children: [
2764
2771
  state === "isEmpty" && /* @__PURE__ */ jsx27(Form_default, { startTransition }),
2765
2772
  state === "isInvalid" && /* @__PURE__ */ jsx27(SecurityNumberInvalid_default, {}),