@agrada_digital/pbm 0.0.55 → 0.0.57
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 +12 -3
- package/dist/index.d.ts +12 -3
- package/dist/index.js +381 -201
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +372 -194
- package/dist/index.mjs.map +1 -1
- package/dist-wc/pbm-wc.js +99 -99
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -53,8 +53,86 @@ 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.success) {
|
|
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(null);
|
|
116
|
+
const { targetProduct, setTargetProduct } = usePBMStore();
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
const fetchProductByEan = async () => {
|
|
119
|
+
if (!targetProduct?.ean) return;
|
|
120
|
+
try {
|
|
121
|
+
const response = await GetProductByEAN({ PRODUCT_EAN: targetProduct.ean });
|
|
122
|
+
if (response.success && response.data) {
|
|
123
|
+
setIndustryLogo(response.data.pbm.imageLink);
|
|
124
|
+
const { pbm, sku, ...targetProductNewData } = response.data;
|
|
125
|
+
setTargetProduct({
|
|
126
|
+
...targetProduct,
|
|
127
|
+
...targetProductNewData
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.error(error);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
fetchProductByEan();
|
|
135
|
+
}, [targetProduct?.ean]);
|
|
58
136
|
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
137
|
/* @__PURE__ */ jsxs2("section", { className: "w-4/5 h-auto", children: [
|
|
60
138
|
/* @__PURE__ */ jsx3("h3", { className: "text-start font-semibold text-sm", children: "Economize com o benef\xEDcio do laborat\xF3rio." }),
|
|
@@ -65,7 +143,7 @@ function Footer({ industryLogo }) {
|
|
|
65
143
|
{
|
|
66
144
|
src: industryLogo,
|
|
67
145
|
alt: "parceiro",
|
|
68
|
-
className: "w-1/5 min-w-20 h-auto aspect-
|
|
146
|
+
className: "w-1/5 min-w-20 h-auto aspect-auto",
|
|
69
147
|
loading: "eager",
|
|
70
148
|
id: "footer_industry_logo_pbm",
|
|
71
149
|
"data-testid": "footer_industry_logo_pbm"
|
|
@@ -77,7 +155,7 @@ var Footer_default = Footer;
|
|
|
77
155
|
|
|
78
156
|
// src/schema/validation-schema.ts
|
|
79
157
|
import { z } from "zod";
|
|
80
|
-
var validationSchema = z.
|
|
158
|
+
var validationSchema = z.object({
|
|
81
159
|
securityNumber: z.string({
|
|
82
160
|
required_error: "CPF \xE9 obrigat\xF3rio."
|
|
83
161
|
}).refine((doc) => {
|
|
@@ -86,7 +164,8 @@ var validationSchema = z.strictObject({
|
|
|
86
164
|
}, "CPF deve conter no m\xEDnimo 11 caracteres.").refine((doc) => {
|
|
87
165
|
const replacedDoc = doc.replace(/\D/g, "");
|
|
88
166
|
return !!Number(replacedDoc);
|
|
89
|
-
}, "CPF deve conter apenas n\xFAmeros.")
|
|
167
|
+
}, "CPF deve conter apenas n\xFAmeros."),
|
|
168
|
+
coupon: z.string({ required_error: "Cupom / ID do Cart\xE3o obrigat\xF3rio." }).optional()
|
|
90
169
|
});
|
|
91
170
|
|
|
92
171
|
// src/utils/format.ts
|
|
@@ -98,51 +177,20 @@ var toFormat = (value) => {
|
|
|
98
177
|
};
|
|
99
178
|
|
|
100
179
|
// src/components/Form/index.tsx
|
|
101
|
-
import
|
|
180
|
+
import classNames4 from "classnames";
|
|
102
181
|
import { zodResolver } from "@hookform/resolvers/zod";
|
|
103
182
|
import { useForm } from "react-hook-form";
|
|
104
183
|
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
|
-
}
|
|
184
|
+
import { useState as useState2 } from "react";
|
|
137
185
|
|
|
138
186
|
// src/services/validate-document.ts
|
|
139
|
-
import
|
|
187
|
+
import Cookies2 from "js-cookie";
|
|
140
188
|
var ValidateDocument = async ({ document, products }) => {
|
|
141
189
|
const API_URL = import.meta.env.VITE_API_URL;
|
|
142
190
|
if (!API_URL) {
|
|
143
191
|
throw new Error("API URL is not defined in environment variables");
|
|
144
192
|
}
|
|
145
|
-
const AUTH_TOKEN =
|
|
193
|
+
const AUTH_TOKEN = Cookies2.get("pbm-token");
|
|
146
194
|
if (!AUTH_TOKEN) {
|
|
147
195
|
throw new Error("Token is not defined in cookies or is expired");
|
|
148
196
|
}
|
|
@@ -161,31 +209,57 @@ var ValidateDocument = async ({ document, products }) => {
|
|
|
161
209
|
return dataResponse;
|
|
162
210
|
};
|
|
163
211
|
|
|
212
|
+
// src/components/UI/Button/index.tsx
|
|
213
|
+
import classNames3 from "classnames";
|
|
214
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
215
|
+
function Button(props) {
|
|
216
|
+
return /* @__PURE__ */ jsx4(
|
|
217
|
+
"button",
|
|
218
|
+
{
|
|
219
|
+
...props,
|
|
220
|
+
className: classNames3(
|
|
221
|
+
"w-3xs cursor-pointer h-10 rounded-full bg-blue-500 hover:bg-blue-400 text-white text-sm font-semibold transition-colors",
|
|
222
|
+
props.className
|
|
223
|
+
),
|
|
224
|
+
children: props.children
|
|
225
|
+
}
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
var Button_default = Button;
|
|
229
|
+
|
|
164
230
|
// src/components/Form/index.tsx
|
|
165
|
-
import { jsx as
|
|
231
|
+
import { Fragment, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
166
232
|
function Form({ setLoading }) {
|
|
167
233
|
const { setSecurityNumber, setState, securityNumber, targetProduct } = usePBMStore();
|
|
234
|
+
const [showCoupoField, setShowCoupoField] = useState2(false);
|
|
168
235
|
const {
|
|
169
236
|
handleSubmit,
|
|
170
237
|
register,
|
|
171
238
|
setValue,
|
|
239
|
+
clearErrors,
|
|
240
|
+
unregister,
|
|
172
241
|
formState: { errors }
|
|
173
242
|
} = useForm({
|
|
174
243
|
resolver: zodResolver(validationSchema),
|
|
244
|
+
mode: "onSubmit",
|
|
175
245
|
defaultValues: {
|
|
176
|
-
securityNumber: securityNumber || ""
|
|
246
|
+
securityNumber: securityNumber || "",
|
|
247
|
+
coupon: ""
|
|
177
248
|
}
|
|
178
249
|
});
|
|
179
250
|
const onSubmitDefault = async (values) => {
|
|
251
|
+
if (!showCoupoField) {
|
|
252
|
+
setValue("coupon", void 0, { shouldValidate: false });
|
|
253
|
+
}
|
|
180
254
|
setLoading(true);
|
|
181
255
|
try {
|
|
182
256
|
if (targetProduct === null) {
|
|
183
|
-
console.error("Product is not defined!");
|
|
257
|
+
console.error("PBMLOG: Product is not defined!");
|
|
184
258
|
return;
|
|
185
259
|
}
|
|
186
260
|
const response = await ValidateDocument({
|
|
187
261
|
document: values.securityNumber.replace(/\D/g, ""),
|
|
188
|
-
products: [{ ean: targetProduct.ean, quantity:
|
|
262
|
+
products: [{ ean: targetProduct.ean, quantity: 1 }]
|
|
189
263
|
});
|
|
190
264
|
if (response.success) {
|
|
191
265
|
const status = {
|
|
@@ -196,76 +270,132 @@ function Form({ setLoading }) {
|
|
|
196
270
|
setState(status[response.data.process_platform.status]);
|
|
197
271
|
}
|
|
198
272
|
} catch (error) {
|
|
199
|
-
console.error("Error validating document
|
|
273
|
+
console.error("PBMLOG: Error validating document -", error);
|
|
200
274
|
} finally {
|
|
201
275
|
setLoading(false);
|
|
202
276
|
}
|
|
203
277
|
;
|
|
204
278
|
};
|
|
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
|
-
}
|
|
279
|
+
return /* @__PURE__ */ jsxs3(Fragment, { children: [
|
|
280
|
+
/* @__PURE__ */ jsxs3(
|
|
281
|
+
"form",
|
|
282
|
+
{
|
|
283
|
+
onSubmit: handleSubmit(onSubmitDefault),
|
|
284
|
+
className: classNames4(
|
|
285
|
+
"w-full h-auto flex items-center justify-center mb-0 transition-all duration-150",
|
|
286
|
+
{ "mb-4": errors.securityNumber || errors.coupon && showCoupoField, "gap-2": showCoupoField }
|
|
248
287
|
),
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
288
|
+
id: "form_security_number_pbm",
|
|
289
|
+
children: [
|
|
290
|
+
/* @__PURE__ */ jsxs3(
|
|
291
|
+
"label",
|
|
292
|
+
{
|
|
293
|
+
htmlFor: "cpf",
|
|
294
|
+
className: "w-4/5 h-auto flex items-start flex-col justify-center relative py-2",
|
|
295
|
+
id: "label_security_number_pbm",
|
|
296
|
+
children: [
|
|
297
|
+
/* @__PURE__ */ jsx5(
|
|
298
|
+
"input",
|
|
299
|
+
{
|
|
300
|
+
type: "text",
|
|
301
|
+
className: classNames4(
|
|
302
|
+
"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",
|
|
303
|
+
{ "outline outline-red-600": errors.securityNumber, "rounded-full": showCoupoField }
|
|
304
|
+
),
|
|
305
|
+
placeholder: "Digite seu CPF aqui...",
|
|
306
|
+
required: true,
|
|
307
|
+
maxLength: 14,
|
|
308
|
+
...register("securityNumber", {
|
|
309
|
+
onChange: (e) => {
|
|
310
|
+
const formatted = toFormat(e.target.value);
|
|
311
|
+
setValue("securityNumber", formatted, {
|
|
312
|
+
shouldValidate: true
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
}),
|
|
316
|
+
defaultValue: securityNumber || "",
|
|
317
|
+
id: "input_security_number_pbm"
|
|
318
|
+
}
|
|
319
|
+
),
|
|
320
|
+
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 })
|
|
321
|
+
]
|
|
322
|
+
}
|
|
323
|
+
),
|
|
324
|
+
showCoupoField && /* @__PURE__ */ jsxs3(
|
|
325
|
+
"label",
|
|
326
|
+
{
|
|
327
|
+
htmlFor: "coupon",
|
|
328
|
+
className: "w-4/5 h-auto flex items-start flex-col justify-center relative py-2",
|
|
329
|
+
id: "label_coupon_pbm",
|
|
330
|
+
children: [
|
|
331
|
+
/* @__PURE__ */ jsx5(
|
|
332
|
+
"input",
|
|
333
|
+
{
|
|
334
|
+
type: "text",
|
|
335
|
+
className: classNames4(
|
|
336
|
+
"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",
|
|
337
|
+
{ "outline outline-red-600": errors.coupon, "rounded-full": showCoupoField }
|
|
338
|
+
),
|
|
339
|
+
placeholder: "Cupom / ID do Cart\xE3o",
|
|
340
|
+
...register("coupon", {
|
|
341
|
+
required: showCoupoField ? "Cupom / ID do Cart\xE3o obrigat\xF3rio." : false,
|
|
342
|
+
shouldUnregister: !showCoupoField,
|
|
343
|
+
onChange: (e) => {
|
|
344
|
+
setValue("coupon", e.target.value, {
|
|
345
|
+
shouldValidate: showCoupoField
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
}),
|
|
349
|
+
id: "input_coupon_pbm"
|
|
350
|
+
}
|
|
351
|
+
),
|
|
352
|
+
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 })
|
|
353
|
+
]
|
|
354
|
+
}
|
|
355
|
+
),
|
|
356
|
+
/* @__PURE__ */ jsx5(
|
|
357
|
+
"button",
|
|
358
|
+
{
|
|
359
|
+
type: "submit",
|
|
360
|
+
className: classNames4(
|
|
361
|
+
"bg-gray-400 w-1/5 h-8 flex items-center justify-center rounded-e-full cursor-pointer",
|
|
362
|
+
{ "rounded-full": showCoupoField }
|
|
363
|
+
),
|
|
364
|
+
id: "button_submit_security_number_pbm",
|
|
365
|
+
children: /* @__PURE__ */ jsx5(ArrowRight, { size: 24, color: "white", strokeWidth: 2 })
|
|
366
|
+
}
|
|
367
|
+
)
|
|
368
|
+
]
|
|
369
|
+
}
|
|
370
|
+
),
|
|
371
|
+
/* @__PURE__ */ jsxs3(
|
|
372
|
+
Button_default,
|
|
373
|
+
{
|
|
374
|
+
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",
|
|
375
|
+
onClick: () => {
|
|
376
|
+
const newValue = !showCoupoField;
|
|
377
|
+
setShowCoupoField(newValue);
|
|
378
|
+
if (!newValue) {
|
|
379
|
+
unregister("coupon");
|
|
380
|
+
clearErrors("coupon");
|
|
256
381
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
382
|
+
},
|
|
383
|
+
id: "check_benefits_button",
|
|
384
|
+
children: [
|
|
385
|
+
/* @__PURE__ */ jsx5("span", { children: !showCoupoField ? "Possui cupom?" : "N\xE3o possui cupom?" }),
|
|
386
|
+
/* @__PURE__ */ jsx5(ArrowRight, { size: 16, className: classNames4({ "rotate-0": !showCoupoField, "rotate-180": showCoupoField }) })
|
|
387
|
+
]
|
|
388
|
+
}
|
|
389
|
+
)
|
|
390
|
+
] });
|
|
261
391
|
}
|
|
262
392
|
var Form_default = Form;
|
|
263
393
|
|
|
264
394
|
// src/components/UI/Loading/index.tsx
|
|
265
|
-
import { jsx as
|
|
395
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
266
396
|
function Loading({ textColor }) {
|
|
267
397
|
return /* @__PURE__ */ jsxs4("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
|
|
268
|
-
/* @__PURE__ */
|
|
398
|
+
/* @__PURE__ */ jsx6(
|
|
269
399
|
"div",
|
|
270
400
|
{
|
|
271
401
|
"data-testid": "test_id_spin",
|
|
@@ -273,7 +403,7 @@ function Loading({ textColor }) {
|
|
|
273
403
|
id: "loading_spin"
|
|
274
404
|
}
|
|
275
405
|
),
|
|
276
|
-
/* @__PURE__ */
|
|
406
|
+
/* @__PURE__ */ jsx6(
|
|
277
407
|
"p",
|
|
278
408
|
{
|
|
279
409
|
className: "text-sm font-semibold text-start text-zinc-900",
|
|
@@ -286,51 +416,8 @@ function Loading({ textColor }) {
|
|
|
286
416
|
}
|
|
287
417
|
var Loading_default = Loading;
|
|
288
418
|
|
|
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
419
|
// src/components/BenefitsTable/index.tsx
|
|
308
|
-
import { useState } from "react";
|
|
309
|
-
|
|
310
|
-
// src/mocks/benefits.ts
|
|
311
|
-
var BENEFITS_ITEMS = [
|
|
312
|
-
{
|
|
313
|
-
id: 1,
|
|
314
|
-
ean: "001",
|
|
315
|
-
authorizedQuantity: 1,
|
|
316
|
-
discountValue: 4800,
|
|
317
|
-
discountPercentual: 2400
|
|
318
|
-
},
|
|
319
|
-
{
|
|
320
|
-
id: 2,
|
|
321
|
-
ean: "002",
|
|
322
|
-
authorizedQuantity: 2,
|
|
323
|
-
discountValue: 4800,
|
|
324
|
-
discountPercentual: 2400
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
id: 3,
|
|
328
|
-
ean: "003",
|
|
329
|
-
authorizedQuantity: 3,
|
|
330
|
-
discountValue: 9400,
|
|
331
|
-
discountPercentual: 4700
|
|
332
|
-
}
|
|
333
|
-
];
|
|
420
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
334
421
|
|
|
335
422
|
// src/components/UI/Title/index.tsx
|
|
336
423
|
import classNames5 from "classnames";
|
|
@@ -354,15 +441,15 @@ var Title_default = Title;
|
|
|
354
441
|
|
|
355
442
|
// src/components/BenefitsTable/Item.tsx
|
|
356
443
|
import { Badge, BadgeCheck } from "lucide-react";
|
|
357
|
-
import { useCallback, useEffect } from "react";
|
|
444
|
+
import { useCallback, useEffect as useEffect2 } from "react";
|
|
358
445
|
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
359
|
-
function Item({ data, onChange, checked
|
|
446
|
+
function Item({ data, onChange, checked }) {
|
|
360
447
|
const { setAvailableDiscountSelected, securityNumber } = usePBMStore();
|
|
361
448
|
const ID_INPUT = "unity_quantity_" + data.authorizedQuantity;
|
|
362
|
-
const decimalDiscount = data.discountPercentual /
|
|
363
|
-
const unitDiscountValue =
|
|
449
|
+
const decimalDiscount = data.discountPercentual / 100;
|
|
450
|
+
const unitDiscountValue = data.grossPrice * decimalDiscount;
|
|
364
451
|
const discountValue = unitDiscountValue * data.authorizedQuantity;
|
|
365
|
-
const totalPriceProductWithDiscountBenefit =
|
|
452
|
+
const totalPriceProductWithDiscountBenefit = data.grossPrice * data.authorizedQuantity - discountValue;
|
|
366
453
|
const updateStorageData = useCallback(() => {
|
|
367
454
|
if (checked) {
|
|
368
455
|
const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
|
|
@@ -383,7 +470,7 @@ function Item({ data, onChange, checked, originalProductPrice }) {
|
|
|
383
470
|
totalPriceProductWithDiscountBenefit,
|
|
384
471
|
unitDiscountValue
|
|
385
472
|
]);
|
|
386
|
-
|
|
473
|
+
useEffect2(() => {
|
|
387
474
|
updateStorageData();
|
|
388
475
|
}, [updateStorageData]);
|
|
389
476
|
return /* @__PURE__ */ jsxs5(
|
|
@@ -434,13 +521,103 @@ function Item({ data, onChange, checked, originalProductPrice }) {
|
|
|
434
521
|
}
|
|
435
522
|
var Item_default = Item;
|
|
436
523
|
|
|
524
|
+
// src/services/benefits-without-document.ts
|
|
525
|
+
import Cookies3 from "js-cookie";
|
|
526
|
+
var CheckBenefistWithoutDocument = async ({ products }) => {
|
|
527
|
+
const API_URL = import.meta.env.VITE_API_URL;
|
|
528
|
+
if (!API_URL) {
|
|
529
|
+
throw new Error("API URL is not defined in environment variables");
|
|
530
|
+
}
|
|
531
|
+
const AUTH_TOKEN = Cookies3.get("pbm-token");
|
|
532
|
+
if (!AUTH_TOKEN) {
|
|
533
|
+
throw new Error("Token is not defined in cookies or is expired");
|
|
534
|
+
}
|
|
535
|
+
const response = await fetch(`${API_URL}/products/genericBenefit`, {
|
|
536
|
+
method: "POST",
|
|
537
|
+
headers: {
|
|
538
|
+
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
539
|
+
"Content-Type": "application/json"
|
|
540
|
+
},
|
|
541
|
+
body: JSON.stringify({ products })
|
|
542
|
+
});
|
|
543
|
+
const dataResponse = await response.json();
|
|
544
|
+
if (!dataResponse.success) {
|
|
545
|
+
throw new Error(dataResponse.message || "Failed to fetch benefits without document");
|
|
546
|
+
}
|
|
547
|
+
return dataResponse;
|
|
548
|
+
};
|
|
549
|
+
|
|
437
550
|
// src/components/BenefitsTable/index.tsx
|
|
438
551
|
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
439
|
-
function BenefitsTable({
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
const
|
|
443
|
-
const [
|
|
552
|
+
function BenefitsTable() {
|
|
553
|
+
const { securityNumber, setState, targetProduct } = usePBMStore();
|
|
554
|
+
const [selectedDiscout, setSelectedDiscount] = useState3(null);
|
|
555
|
+
const [loading, setLoading] = useState3(true);
|
|
556
|
+
const [benefitsItems, setBenefitsItems] = useState3();
|
|
557
|
+
useEffect3(() => {
|
|
558
|
+
const fetchDicountsWithoutDocument = async () => {
|
|
559
|
+
if (!targetProduct?.productId) {
|
|
560
|
+
console.error("PBMLOG: Product ID is not defined on targetProduct");
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
if (!targetProduct.ean) {
|
|
564
|
+
console.error("PBMLOG: EAN is not defined on targetProduct");
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
if (!targetProduct.listPrice) {
|
|
568
|
+
console.error("PBMLOG: List Price is not defined on targetProduct");
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
if (!targetProduct.price) {
|
|
572
|
+
console.error("PBMLOG: Price is not defined on targetProduct");
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
try {
|
|
576
|
+
const data = {
|
|
577
|
+
productId: Number(targetProduct.productId),
|
|
578
|
+
ean: targetProduct.ean,
|
|
579
|
+
requestedQuantity: 1,
|
|
580
|
+
listPrice: targetProduct.listPrice,
|
|
581
|
+
netPrice: targetProduct.price
|
|
582
|
+
};
|
|
583
|
+
const response = await CheckBenefistWithoutDocument({ products: [data] });
|
|
584
|
+
if (response.success && response.data) {
|
|
585
|
+
setBenefitsItems(response.data);
|
|
586
|
+
} else {
|
|
587
|
+
setBenefitsItems(void 0);
|
|
588
|
+
}
|
|
589
|
+
} catch (error) {
|
|
590
|
+
setBenefitsItems(void 0);
|
|
591
|
+
console.error(error);
|
|
592
|
+
} finally {
|
|
593
|
+
setLoading(false);
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
const fetchDiscountWithDocument = async () => {
|
|
597
|
+
console.log("consulta feita com documento");
|
|
598
|
+
};
|
|
599
|
+
securityNumber ? fetchDiscountWithDocument() : fetchDicountsWithoutDocument();
|
|
600
|
+
}, []);
|
|
601
|
+
if (loading) {
|
|
602
|
+
return /* @__PURE__ */ jsxs6("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
|
|
603
|
+
/* @__PURE__ */ jsx9(
|
|
604
|
+
"div",
|
|
605
|
+
{
|
|
606
|
+
"data-testid": "test_id_spin",
|
|
607
|
+
className: "w-8 h-8 border-4 border-t-gray-700 border-gray-300 rounded-full animate-spin",
|
|
608
|
+
id: "loading_spin"
|
|
609
|
+
}
|
|
610
|
+
),
|
|
611
|
+
/* @__PURE__ */ jsx9(
|
|
612
|
+
"p",
|
|
613
|
+
{
|
|
614
|
+
className: "text-sm font-semibold text-start text-zinc-900",
|
|
615
|
+
id: "loading_label",
|
|
616
|
+
children: "Buscando beneficios dispon\xEDveis..."
|
|
617
|
+
}
|
|
618
|
+
)
|
|
619
|
+
] });
|
|
620
|
+
}
|
|
444
621
|
return /* @__PURE__ */ jsxs6(
|
|
445
622
|
"section",
|
|
446
623
|
{
|
|
@@ -448,31 +625,34 @@ function BenefitsTable({
|
|
|
448
625
|
id: "benefits_table_pbm",
|
|
449
626
|
children: [
|
|
450
627
|
/* @__PURE__ */ jsx9(Title_default, { children: "Descontos dispon\xEDveis:" }),
|
|
451
|
-
/* @__PURE__ */
|
|
628
|
+
/* @__PURE__ */ jsxs6(
|
|
452
629
|
"form",
|
|
453
630
|
{
|
|
454
631
|
className: "flex flex-col items-center justify-start w-full gap-3",
|
|
455
632
|
id: "form_benefits_table_pbm",
|
|
456
|
-
children:
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
633
|
+
children: [
|
|
634
|
+
!benefitsItems && /* @__PURE__ */ jsx9("p", { className: "text-sm font-semibold text-start text-zinc-900", id: "benefits_empty_pbm", children: "N\xE3o foi poss\xEDvel encontrar benef\xEDcios para esse produto." }),
|
|
635
|
+
benefitsItems && benefitsItems.map((item, index) => {
|
|
636
|
+
const ID_INPUT = "unity_quantity_" + item.authorizedQuantity;
|
|
637
|
+
return /* @__PURE__ */ jsx9(
|
|
638
|
+
Item_default,
|
|
639
|
+
{
|
|
640
|
+
data: item,
|
|
641
|
+
checked: selectedDiscout === ID_INPUT,
|
|
642
|
+
onChange: () => setSelectedDiscount(ID_INPUT)
|
|
643
|
+
},
|
|
644
|
+
index
|
|
645
|
+
);
|
|
646
|
+
}),
|
|
647
|
+
benefitsItems && /* @__PURE__ */ jsx9("p", { className: "w-full text-sm font-semibold text-center text-zinc-600", id: "benefits_empty_pbm", children: benefitsItems[0].informativeMessage })
|
|
648
|
+
]
|
|
469
649
|
}
|
|
470
650
|
),
|
|
471
651
|
!securityNumber && /* @__PURE__ */ jsxs6(
|
|
472
652
|
Button_default,
|
|
473
653
|
{
|
|
474
654
|
onClick: () => setState("isEmpty"),
|
|
475
|
-
className: "bg-transparent p-0
|
|
655
|
+
className: "bg-transparent p-0 w-auto h-auto text-zinc-600 cursor-pointer hover:text-zinc-900 hover:bg-transparent text-start",
|
|
476
656
|
id: "unauthorized_benefits_button",
|
|
477
657
|
children: [
|
|
478
658
|
"Aten\xE7\xE3o: n\xE3o \xE9 poss\xEDvel utilizar os benef\xEDcos sem realizar a consulta do cpf, por favor",
|
|
@@ -584,10 +764,10 @@ function Iframe({ url, title, openModal, setOpenModal }) {
|
|
|
584
764
|
var Iframe_default = Iframe;
|
|
585
765
|
|
|
586
766
|
// src/components/SecurityNumberInvalid/index.tsx
|
|
587
|
-
import { useState as
|
|
767
|
+
import { useState as useState4 } from "react";
|
|
588
768
|
import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
589
769
|
function SecurityNumberInvalid({ textColor }) {
|
|
590
|
-
const [openModal, setOpenModal] =
|
|
770
|
+
const [openModal, setOpenModal] = useState4(false);
|
|
591
771
|
return /* @__PURE__ */ jsxs8(
|
|
592
772
|
"section",
|
|
593
773
|
{
|
|
@@ -622,7 +802,7 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
622
802
|
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
623
803
|
|
|
624
804
|
// src/PBM.tsx
|
|
625
|
-
import { useCallback as useCallback2, useEffect as
|
|
805
|
+
import { useCallback as useCallback2, useEffect as useEffect4, useState as useState5 } from "react";
|
|
626
806
|
|
|
627
807
|
// src/components/UI/Link/index.tsx
|
|
628
808
|
import classNames8 from "classnames";
|
|
@@ -683,7 +863,7 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
683
863
|
var SecurityNumberRegitered_default = SecurityNumberRegitered;
|
|
684
864
|
|
|
685
865
|
// src/services/authorization.ts
|
|
686
|
-
import
|
|
866
|
+
import Cookies4 from "js-cookie";
|
|
687
867
|
var GetAuthorization = async ({ clientID }) => {
|
|
688
868
|
const API_URL = import.meta.env.VITE_API_URL;
|
|
689
869
|
const STORE_ID = import.meta.env.VITE_STORE_ID;
|
|
@@ -700,21 +880,22 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
700
880
|
"Content-Type": "application/json"
|
|
701
881
|
},
|
|
702
882
|
body: JSON.stringify({
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
883
|
+
storeId: STORE_ID,
|
|
884
|
+
storeName: STORE_NAME,
|
|
885
|
+
clientId: clientID
|
|
706
886
|
})
|
|
707
887
|
});
|
|
708
888
|
const dataResponse = await response.json();
|
|
709
889
|
if (!dataResponse.success) {
|
|
710
890
|
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
711
891
|
}
|
|
712
|
-
|
|
713
|
-
expires:
|
|
892
|
+
Cookies4.set("pbm-token", dataResponse.data.token, {
|
|
893
|
+
expires: dataResponse.data.expiresIn / (60 * 60),
|
|
714
894
|
secure: true,
|
|
715
895
|
sameSite: "Strict"
|
|
716
896
|
});
|
|
717
|
-
|
|
897
|
+
Cookies4.set("pbm-token-refresh", dataResponse.data.refreshToken, {
|
|
898
|
+
expires: dataResponse.data.refreshExpiresIn / (60 * 60),
|
|
718
899
|
secure: true,
|
|
719
900
|
sameSite: "Strict"
|
|
720
901
|
});
|
|
@@ -723,42 +904,39 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
723
904
|
|
|
724
905
|
// src/PBM.tsx
|
|
725
906
|
import { ArrowRight as ArrowRight2 } from "lucide-react";
|
|
726
|
-
import { Fragment, jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
907
|
+
import { Fragment as Fragment2, jsx as jsx15, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
727
908
|
function PBM({
|
|
728
909
|
originalProductPrice,
|
|
729
|
-
industryLogo,
|
|
730
910
|
clientID,
|
|
731
911
|
eanProduct
|
|
732
912
|
}) {
|
|
733
913
|
const formatedOriginalProductPrice = Number(
|
|
734
914
|
String(originalProductPrice).replace(",", ".")
|
|
735
915
|
);
|
|
736
|
-
const [loading, setLoading] =
|
|
916
|
+
const [loading, setLoading] = useState5(false);
|
|
737
917
|
const { setState, state, setTargetProduct } = usePBMStore();
|
|
738
|
-
|
|
918
|
+
useEffect4(() => {
|
|
739
919
|
if (eanProduct) {
|
|
740
|
-
setTargetProduct({ ean: eanProduct
|
|
920
|
+
setTargetProduct({ ean: eanProduct });
|
|
741
921
|
}
|
|
742
922
|
}, [eanProduct, setTargetProduct]);
|
|
743
923
|
const handleAuthorizationRequest = useCallback2(async () => {
|
|
744
924
|
try {
|
|
745
925
|
const response = await GetAuthorization({ clientID });
|
|
746
|
-
if (response.success) {
|
|
747
|
-
console.
|
|
748
|
-
} else {
|
|
749
|
-
console.error("Authorization failed:", response.message);
|
|
926
|
+
if (!response.success) {
|
|
927
|
+
console.error("PBMLOG: Authorization failed!");
|
|
750
928
|
}
|
|
751
929
|
} catch (error) {
|
|
752
930
|
console.error("Error fetching authorization:", error);
|
|
753
931
|
}
|
|
754
932
|
}, [clientID]);
|
|
755
|
-
|
|
933
|
+
useEffect4(() => {
|
|
756
934
|
handleAuthorizationRequest();
|
|
757
935
|
}, [handleAuthorizationRequest]);
|
|
758
936
|
return /* @__PURE__ */ jsxs10(Container_default, { variant: "main", children: [
|
|
759
937
|
/* @__PURE__ */ jsx15(Header_default, { originalProductPrice: formatedOriginalProductPrice || 0 }),
|
|
760
938
|
/* @__PURE__ */ jsxs10(Container_default, { variant: "simple", children: [
|
|
761
|
-
state === "isEmpty" && !loading && /* @__PURE__ */ jsxs10(
|
|
939
|
+
state === "isEmpty" && !loading && /* @__PURE__ */ jsxs10(Fragment2, { children: [
|
|
762
940
|
/* @__PURE__ */ jsx15(Form_default, { setLoading }),
|
|
763
941
|
/* @__PURE__ */ jsxs10(
|
|
764
942
|
Button_default,
|
|
@@ -776,9 +954,9 @@ function PBM({
|
|
|
776
954
|
state === "isEmpty" && loading && /* @__PURE__ */ jsx15(Loading_default, {}),
|
|
777
955
|
state === "isInvalid" && !loading && /* @__PURE__ */ jsx15(SecurityNumberInvalid_default, {}),
|
|
778
956
|
state === "isRegistered" && !loading && /* @__PURE__ */ jsx15(SecurityNumberRegitered_default, {}),
|
|
779
|
-
state === "isActivated" && !loading && /* @__PURE__ */ jsx15(BenefitsTable_default, {
|
|
957
|
+
state === "isActivated" && !loading && /* @__PURE__ */ jsx15(BenefitsTable_default, {})
|
|
780
958
|
] }),
|
|
781
|
-
/* @__PURE__ */ jsx15(Footer_default, {
|
|
959
|
+
/* @__PURE__ */ jsx15(Footer_default, {})
|
|
782
960
|
] });
|
|
783
961
|
}
|
|
784
962
|
var PBM_default = PBM;
|