@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.js
CHANGED
|
@@ -90,8 +90,87 @@ var Container_default = Container;
|
|
|
90
90
|
|
|
91
91
|
// src/components/Footer/index.tsx
|
|
92
92
|
var import_classnames2 = __toESM(require("classnames"));
|
|
93
|
+
var import_react2 = require("react");
|
|
94
|
+
|
|
95
|
+
// src/libs/zustand/usePBM.tsx
|
|
96
|
+
var import_zustand = require("zustand");
|
|
97
|
+
var import_react = require("zustand/react");
|
|
98
|
+
var initialPBMState = {
|
|
99
|
+
securityNumber: "",
|
|
100
|
+
state: "isEmpty",
|
|
101
|
+
availableDiscountSelected: {
|
|
102
|
+
quantity: 0,
|
|
103
|
+
discount: {
|
|
104
|
+
unit: 0,
|
|
105
|
+
total: 0
|
|
106
|
+
},
|
|
107
|
+
totalPrice: 0
|
|
108
|
+
},
|
|
109
|
+
targetProduct: null,
|
|
110
|
+
campaign: "pbm_campaign"
|
|
111
|
+
};
|
|
112
|
+
var createPBMStore = (set) => ({
|
|
113
|
+
...initialPBMState,
|
|
114
|
+
setSecurityNumber: (securityNumber) => set({ securityNumber }),
|
|
115
|
+
setState: (state) => set({ state }),
|
|
116
|
+
setTargetProduct: (targetProduct) => set({ targetProduct }),
|
|
117
|
+
setAvailableDiscountSelected: (availableDiscount) => set({ availableDiscountSelected: availableDiscount })
|
|
118
|
+
});
|
|
119
|
+
var pbmStore = (0, import_zustand.createStore)(createPBMStore);
|
|
120
|
+
function usePBMStore(selector) {
|
|
121
|
+
if (selector) {
|
|
122
|
+
return (0, import_react.useStore)(pbmStore, selector);
|
|
123
|
+
}
|
|
124
|
+
return (0, import_react.useStore)(pbmStore, (state) => state);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// src/services/get-product-by-ean.ts
|
|
128
|
+
var import_js_cookie = __toESM(require("js-cookie"));
|
|
129
|
+
var import_meta = {};
|
|
130
|
+
var GetProductByEAN = async ({ PRODUCT_EAN }) => {
|
|
131
|
+
const API_URL = import_meta.env.VITE_API_URL;
|
|
132
|
+
const AUTH_TOKEN = import_js_cookie.default.get("pbm-token");
|
|
133
|
+
if (!AUTH_TOKEN) {
|
|
134
|
+
throw new Error("Token is not defined in cookies or is expired");
|
|
135
|
+
}
|
|
136
|
+
const response = await fetch(`${API_URL}/products/ean/${PRODUCT_EAN}`, {
|
|
137
|
+
method: "GET",
|
|
138
|
+
headers: {
|
|
139
|
+
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
140
|
+
"Content-Type": "application/json"
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const dataResponse = await response.json();
|
|
144
|
+
if (!dataResponse.success) {
|
|
145
|
+
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
146
|
+
}
|
|
147
|
+
return dataResponse;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// src/components/Footer/index.tsx
|
|
93
151
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
94
|
-
function Footer(
|
|
152
|
+
function Footer() {
|
|
153
|
+
const [industryLogo, setIndustryLogo] = (0, import_react2.useState)(null);
|
|
154
|
+
const { targetProduct, setTargetProduct } = usePBMStore();
|
|
155
|
+
(0, import_react2.useEffect)(() => {
|
|
156
|
+
const fetchProductByEan = async () => {
|
|
157
|
+
if (!targetProduct?.ean) return;
|
|
158
|
+
try {
|
|
159
|
+
const response = await GetProductByEAN({ PRODUCT_EAN: targetProduct.ean });
|
|
160
|
+
if (response.success && response.data) {
|
|
161
|
+
setIndustryLogo(response.data.pbm.imageLink);
|
|
162
|
+
const { pbm, sku, ...targetProductNewData } = response.data;
|
|
163
|
+
setTargetProduct({
|
|
164
|
+
...targetProduct,
|
|
165
|
+
...targetProductNewData
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
} catch (error) {
|
|
169
|
+
console.error(error);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
fetchProductByEan();
|
|
173
|
+
}, [targetProduct?.ean]);
|
|
95
174
|
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": industryLogo, "justify-start": !industryLogo }), children: [
|
|
96
175
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "w-4/5 h-auto", children: [
|
|
97
176
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { className: "text-start font-semibold text-sm", children: "Economize com o benef\xEDcio do laborat\xF3rio." }),
|
|
@@ -102,7 +181,7 @@ function Footer({ industryLogo }) {
|
|
|
102
181
|
{
|
|
103
182
|
src: industryLogo,
|
|
104
183
|
alt: "parceiro",
|
|
105
|
-
className: "w-1/5 min-w-20 h-auto aspect-
|
|
184
|
+
className: "w-1/5 min-w-20 h-auto aspect-auto",
|
|
106
185
|
loading: "eager",
|
|
107
186
|
id: "footer_industry_logo_pbm",
|
|
108
187
|
"data-testid": "footer_industry_logo_pbm"
|
|
@@ -114,7 +193,7 @@ var Footer_default = Footer;
|
|
|
114
193
|
|
|
115
194
|
// src/schema/validation-schema.ts
|
|
116
195
|
var import_zod = require("zod");
|
|
117
|
-
var validationSchema = import_zod.z.
|
|
196
|
+
var validationSchema = import_zod.z.object({
|
|
118
197
|
securityNumber: import_zod.z.string({
|
|
119
198
|
required_error: "CPF \xE9 obrigat\xF3rio."
|
|
120
199
|
}).refine((doc) => {
|
|
@@ -123,7 +202,8 @@ var validationSchema = import_zod.z.strictObject({
|
|
|
123
202
|
}, "CPF deve conter no m\xEDnimo 11 caracteres.").refine((doc) => {
|
|
124
203
|
const replacedDoc = doc.replace(/\D/g, "");
|
|
125
204
|
return !!Number(replacedDoc);
|
|
126
|
-
}, "CPF deve conter apenas n\xFAmeros.")
|
|
205
|
+
}, "CPF deve conter apenas n\xFAmeros."),
|
|
206
|
+
coupon: import_zod.z.string({ required_error: "Cupom / ID do Cart\xE3o obrigat\xF3rio." }).optional()
|
|
127
207
|
});
|
|
128
208
|
|
|
129
209
|
// src/utils/format.ts
|
|
@@ -135,52 +215,21 @@ var toFormat = (value) => {
|
|
|
135
215
|
};
|
|
136
216
|
|
|
137
217
|
// src/components/Form/index.tsx
|
|
138
|
-
var
|
|
218
|
+
var import_classnames4 = __toESM(require("classnames"));
|
|
139
219
|
var import_zod2 = require("@hookform/resolvers/zod");
|
|
140
220
|
var import_react_hook_form = require("react-hook-form");
|
|
141
221
|
var import_lucide_react = require("lucide-react");
|
|
142
|
-
|
|
143
|
-
// src/libs/zustand/usePBM.tsx
|
|
144
|
-
var import_zustand = require("zustand");
|
|
145
|
-
var import_react = require("zustand/react");
|
|
146
|
-
var initialPBMState = {
|
|
147
|
-
securityNumber: "",
|
|
148
|
-
state: "isEmpty",
|
|
149
|
-
availableDiscountSelected: {
|
|
150
|
-
quantity: 0,
|
|
151
|
-
discount: {
|
|
152
|
-
unit: 0,
|
|
153
|
-
total: 0
|
|
154
|
-
},
|
|
155
|
-
totalPrice: 0
|
|
156
|
-
},
|
|
157
|
-
targetProduct: null,
|
|
158
|
-
campaign: "pbm_campaign"
|
|
159
|
-
};
|
|
160
|
-
var createPBMStore = (set) => ({
|
|
161
|
-
...initialPBMState,
|
|
162
|
-
setSecurityNumber: (securityNumber) => set({ securityNumber }),
|
|
163
|
-
setState: (state) => set({ state }),
|
|
164
|
-
setTargetProduct: (targetProduct) => set({ targetProduct }),
|
|
165
|
-
setAvailableDiscountSelected: (availableDiscount) => set({ availableDiscountSelected: availableDiscount })
|
|
166
|
-
});
|
|
167
|
-
var pbmStore = (0, import_zustand.createStore)(createPBMStore);
|
|
168
|
-
function usePBMStore(selector) {
|
|
169
|
-
if (selector) {
|
|
170
|
-
return (0, import_react.useStore)(pbmStore, selector);
|
|
171
|
-
}
|
|
172
|
-
return (0, import_react.useStore)(pbmStore, (state) => state);
|
|
173
|
-
}
|
|
222
|
+
var import_react3 = require("react");
|
|
174
223
|
|
|
175
224
|
// src/services/validate-document.ts
|
|
176
|
-
var
|
|
177
|
-
var
|
|
225
|
+
var import_js_cookie2 = __toESM(require("js-cookie"));
|
|
226
|
+
var import_meta2 = {};
|
|
178
227
|
var ValidateDocument = async ({ document, products }) => {
|
|
179
|
-
const API_URL =
|
|
228
|
+
const API_URL = import_meta2.env.VITE_API_URL;
|
|
180
229
|
if (!API_URL) {
|
|
181
230
|
throw new Error("API URL is not defined in environment variables");
|
|
182
231
|
}
|
|
183
|
-
const AUTH_TOKEN =
|
|
232
|
+
const AUTH_TOKEN = import_js_cookie2.default.get("pbm-token");
|
|
184
233
|
if (!AUTH_TOKEN) {
|
|
185
234
|
throw new Error("Token is not defined in cookies or is expired");
|
|
186
235
|
}
|
|
@@ -199,31 +248,57 @@ var ValidateDocument = async ({ document, products }) => {
|
|
|
199
248
|
return dataResponse;
|
|
200
249
|
};
|
|
201
250
|
|
|
202
|
-
// src/components/
|
|
251
|
+
// src/components/UI/Button/index.tsx
|
|
252
|
+
var import_classnames3 = __toESM(require("classnames"));
|
|
203
253
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
254
|
+
function Button(props) {
|
|
255
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
256
|
+
"button",
|
|
257
|
+
{
|
|
258
|
+
...props,
|
|
259
|
+
className: (0, import_classnames3.default)(
|
|
260
|
+
"w-3xs cursor-pointer h-10 rounded-full bg-blue-500 hover:bg-blue-400 text-white text-sm font-semibold transition-colors",
|
|
261
|
+
props.className
|
|
262
|
+
),
|
|
263
|
+
children: props.children
|
|
264
|
+
}
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
var Button_default = Button;
|
|
268
|
+
|
|
269
|
+
// src/components/Form/index.tsx
|
|
270
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
204
271
|
function Form({ setLoading }) {
|
|
205
272
|
const { setSecurityNumber, setState, securityNumber, targetProduct } = usePBMStore();
|
|
273
|
+
const [showCoupoField, setShowCoupoField] = (0, import_react3.useState)(false);
|
|
206
274
|
const {
|
|
207
275
|
handleSubmit,
|
|
208
276
|
register,
|
|
209
277
|
setValue,
|
|
278
|
+
clearErrors,
|
|
279
|
+
unregister,
|
|
210
280
|
formState: { errors }
|
|
211
281
|
} = (0, import_react_hook_form.useForm)({
|
|
212
282
|
resolver: (0, import_zod2.zodResolver)(validationSchema),
|
|
283
|
+
mode: "onSubmit",
|
|
213
284
|
defaultValues: {
|
|
214
|
-
securityNumber: securityNumber || ""
|
|
285
|
+
securityNumber: securityNumber || "",
|
|
286
|
+
coupon: ""
|
|
215
287
|
}
|
|
216
288
|
});
|
|
217
289
|
const onSubmitDefault = async (values) => {
|
|
290
|
+
if (!showCoupoField) {
|
|
291
|
+
setValue("coupon", void 0, { shouldValidate: false });
|
|
292
|
+
}
|
|
218
293
|
setLoading(true);
|
|
219
294
|
try {
|
|
220
295
|
if (targetProduct === null) {
|
|
221
|
-
console.error("Product is not defined!");
|
|
296
|
+
console.error("PBMLOG: Product is not defined!");
|
|
222
297
|
return;
|
|
223
298
|
}
|
|
224
299
|
const response = await ValidateDocument({
|
|
225
300
|
document: values.securityNumber.replace(/\D/g, ""),
|
|
226
|
-
products: [{ ean: targetProduct.ean, quantity:
|
|
301
|
+
products: [{ ean: targetProduct.ean, quantity: 1 }]
|
|
227
302
|
});
|
|
228
303
|
if (response.success) {
|
|
229
304
|
const status = {
|
|
@@ -234,76 +309,132 @@ function Form({ setLoading }) {
|
|
|
234
309
|
setState(status[response.data.process_platform.status]);
|
|
235
310
|
}
|
|
236
311
|
} catch (error) {
|
|
237
|
-
console.error("Error validating document
|
|
312
|
+
console.error("PBMLOG: Error validating document -", error);
|
|
238
313
|
} finally {
|
|
239
314
|
setLoading(false);
|
|
240
315
|
}
|
|
241
316
|
;
|
|
242
317
|
};
|
|
243
|
-
return /* @__PURE__ */ (0,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
id: "form_security_number_pbm",
|
|
252
|
-
children: [
|
|
253
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
254
|
-
"label",
|
|
255
|
-
{
|
|
256
|
-
htmlFor: "cpf",
|
|
257
|
-
className: "w-4/5 h-auto flex items-start flex-col justify-center relative py-2",
|
|
258
|
-
id: "label_security_number_pbm",
|
|
259
|
-
children: [
|
|
260
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
261
|
-
"input",
|
|
262
|
-
{
|
|
263
|
-
type: "text",
|
|
264
|
-
className: (0, import_classnames3.default)(
|
|
265
|
-
"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",
|
|
266
|
-
{ "outline outline-red-600": errors.securityNumber }
|
|
267
|
-
),
|
|
268
|
-
placeholder: "Digite seu CPF aqui...",
|
|
269
|
-
required: true,
|
|
270
|
-
maxLength: 14,
|
|
271
|
-
...register("securityNumber", {
|
|
272
|
-
onChange: (e) => {
|
|
273
|
-
const formatted = toFormat(e.target.value);
|
|
274
|
-
setValue("securityNumber", formatted, {
|
|
275
|
-
shouldValidate: true
|
|
276
|
-
});
|
|
277
|
-
}
|
|
278
|
-
}),
|
|
279
|
-
defaultValue: securityNumber || "",
|
|
280
|
-
id: "input_security_number_pbm"
|
|
281
|
-
}
|
|
282
|
-
),
|
|
283
|
-
errors.securityNumber && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("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 })
|
|
284
|
-
]
|
|
285
|
-
}
|
|
318
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
319
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
320
|
+
"form",
|
|
321
|
+
{
|
|
322
|
+
onSubmit: handleSubmit(onSubmitDefault),
|
|
323
|
+
className: (0, import_classnames4.default)(
|
|
324
|
+
"w-full h-auto flex items-center justify-center mb-0 transition-all duration-150",
|
|
325
|
+
{ "mb-4": errors.securityNumber || errors.coupon && showCoupoField, "gap-2": showCoupoField }
|
|
286
326
|
),
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
327
|
+
id: "form_security_number_pbm",
|
|
328
|
+
children: [
|
|
329
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
330
|
+
"label",
|
|
331
|
+
{
|
|
332
|
+
htmlFor: "cpf",
|
|
333
|
+
className: "w-4/5 h-auto flex items-start flex-col justify-center relative py-2",
|
|
334
|
+
id: "label_security_number_pbm",
|
|
335
|
+
children: [
|
|
336
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
337
|
+
"input",
|
|
338
|
+
{
|
|
339
|
+
type: "text",
|
|
340
|
+
className: (0, import_classnames4.default)(
|
|
341
|
+
"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",
|
|
342
|
+
{ "outline outline-red-600": errors.securityNumber, "rounded-full": showCoupoField }
|
|
343
|
+
),
|
|
344
|
+
placeholder: "Digite seu CPF aqui...",
|
|
345
|
+
required: true,
|
|
346
|
+
maxLength: 14,
|
|
347
|
+
...register("securityNumber", {
|
|
348
|
+
onChange: (e) => {
|
|
349
|
+
const formatted = toFormat(e.target.value);
|
|
350
|
+
setValue("securityNumber", formatted, {
|
|
351
|
+
shouldValidate: true
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
}),
|
|
355
|
+
defaultValue: securityNumber || "",
|
|
356
|
+
id: "input_security_number_pbm"
|
|
357
|
+
}
|
|
358
|
+
),
|
|
359
|
+
errors.securityNumber && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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 })
|
|
360
|
+
]
|
|
361
|
+
}
|
|
362
|
+
),
|
|
363
|
+
showCoupoField && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
364
|
+
"label",
|
|
365
|
+
{
|
|
366
|
+
htmlFor: "coupon",
|
|
367
|
+
className: "w-4/5 h-auto flex items-start flex-col justify-center relative py-2",
|
|
368
|
+
id: "label_coupon_pbm",
|
|
369
|
+
children: [
|
|
370
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
371
|
+
"input",
|
|
372
|
+
{
|
|
373
|
+
type: "text",
|
|
374
|
+
className: (0, import_classnames4.default)(
|
|
375
|
+
"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",
|
|
376
|
+
{ "outline outline-red-600": errors.coupon, "rounded-full": showCoupoField }
|
|
377
|
+
),
|
|
378
|
+
placeholder: "Cupom / ID do Cart\xE3o",
|
|
379
|
+
...register("coupon", {
|
|
380
|
+
required: showCoupoField ? "Cupom / ID do Cart\xE3o obrigat\xF3rio." : false,
|
|
381
|
+
shouldUnregister: !showCoupoField,
|
|
382
|
+
onChange: (e) => {
|
|
383
|
+
setValue("coupon", e.target.value, {
|
|
384
|
+
shouldValidate: showCoupoField
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
}),
|
|
388
|
+
id: "input_coupon_pbm"
|
|
389
|
+
}
|
|
390
|
+
),
|
|
391
|
+
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 })
|
|
392
|
+
]
|
|
393
|
+
}
|
|
394
|
+
),
|
|
395
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
396
|
+
"button",
|
|
397
|
+
{
|
|
398
|
+
type: "submit",
|
|
399
|
+
className: (0, import_classnames4.default)(
|
|
400
|
+
"bg-gray-400 w-1/5 h-8 flex items-center justify-center rounded-e-full cursor-pointer",
|
|
401
|
+
{ "rounded-full": showCoupoField }
|
|
402
|
+
),
|
|
403
|
+
id: "button_submit_security_number_pbm",
|
|
404
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.ArrowRight, { size: 24, color: "white", strokeWidth: 2 })
|
|
405
|
+
}
|
|
406
|
+
)
|
|
407
|
+
]
|
|
408
|
+
}
|
|
409
|
+
),
|
|
410
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
411
|
+
Button_default,
|
|
412
|
+
{
|
|
413
|
+
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",
|
|
414
|
+
onClick: () => {
|
|
415
|
+
const newValue = !showCoupoField;
|
|
416
|
+
setShowCoupoField(newValue);
|
|
417
|
+
if (!newValue) {
|
|
418
|
+
unregister("coupon");
|
|
419
|
+
clearErrors("coupon");
|
|
294
420
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
421
|
+
},
|
|
422
|
+
id: "check_benefits_button",
|
|
423
|
+
children: [
|
|
424
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: !showCoupoField ? "Possui cupom?" : "N\xE3o possui cupom?" }),
|
|
425
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.ArrowRight, { size: 16, className: (0, import_classnames4.default)({ "rotate-0": !showCoupoField, "rotate-180": showCoupoField }) })
|
|
426
|
+
]
|
|
427
|
+
}
|
|
428
|
+
)
|
|
429
|
+
] });
|
|
299
430
|
}
|
|
300
431
|
var Form_default = Form;
|
|
301
432
|
|
|
302
433
|
// src/components/UI/Loading/index.tsx
|
|
303
|
-
var
|
|
434
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
304
435
|
function Loading({ textColor }) {
|
|
305
|
-
return /* @__PURE__ */ (0,
|
|
306
|
-
/* @__PURE__ */ (0,
|
|
436
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
|
|
437
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
307
438
|
"div",
|
|
308
439
|
{
|
|
309
440
|
"data-testid": "test_id_spin",
|
|
@@ -311,7 +442,7 @@ function Loading({ textColor }) {
|
|
|
311
442
|
id: "loading_spin"
|
|
312
443
|
}
|
|
313
444
|
),
|
|
314
|
-
/* @__PURE__ */ (0,
|
|
445
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
315
446
|
"p",
|
|
316
447
|
{
|
|
317
448
|
className: "text-sm font-semibold text-start text-zinc-900",
|
|
@@ -324,51 +455,8 @@ function Loading({ textColor }) {
|
|
|
324
455
|
}
|
|
325
456
|
var Loading_default = Loading;
|
|
326
457
|
|
|
327
|
-
// src/components/UI/Button/index.tsx
|
|
328
|
-
var import_classnames4 = __toESM(require("classnames"));
|
|
329
|
-
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
330
|
-
function Button(props) {
|
|
331
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
332
|
-
"button",
|
|
333
|
-
{
|
|
334
|
-
...props,
|
|
335
|
-
className: (0, import_classnames4.default)(
|
|
336
|
-
"w-3xs cursor-pointer h-10 rounded-full bg-blue-500 hover:bg-blue-400 text-white text-sm font-semibold transition-colors",
|
|
337
|
-
props.className
|
|
338
|
-
),
|
|
339
|
-
children: props.children
|
|
340
|
-
}
|
|
341
|
-
);
|
|
342
|
-
}
|
|
343
|
-
var Button_default = Button;
|
|
344
|
-
|
|
345
458
|
// src/components/BenefitsTable/index.tsx
|
|
346
|
-
var
|
|
347
|
-
|
|
348
|
-
// src/mocks/benefits.ts
|
|
349
|
-
var BENEFITS_ITEMS = [
|
|
350
|
-
{
|
|
351
|
-
id: 1,
|
|
352
|
-
ean: "001",
|
|
353
|
-
authorizedQuantity: 1,
|
|
354
|
-
discountValue: 4800,
|
|
355
|
-
discountPercentual: 2400
|
|
356
|
-
},
|
|
357
|
-
{
|
|
358
|
-
id: 2,
|
|
359
|
-
ean: "002",
|
|
360
|
-
authorizedQuantity: 2,
|
|
361
|
-
discountValue: 4800,
|
|
362
|
-
discountPercentual: 2400
|
|
363
|
-
},
|
|
364
|
-
{
|
|
365
|
-
id: 3,
|
|
366
|
-
ean: "003",
|
|
367
|
-
authorizedQuantity: 3,
|
|
368
|
-
discountValue: 9400,
|
|
369
|
-
discountPercentual: 4700
|
|
370
|
-
}
|
|
371
|
-
];
|
|
459
|
+
var import_react5 = require("react");
|
|
372
460
|
|
|
373
461
|
// src/components/UI/Title/index.tsx
|
|
374
462
|
var import_classnames5 = __toESM(require("classnames"));
|
|
@@ -392,16 +480,16 @@ var Title_default = Title;
|
|
|
392
480
|
|
|
393
481
|
// src/components/BenefitsTable/Item.tsx
|
|
394
482
|
var import_lucide_react2 = require("lucide-react");
|
|
395
|
-
var
|
|
483
|
+
var import_react4 = require("react");
|
|
396
484
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
397
|
-
function Item({ data, onChange, checked
|
|
485
|
+
function Item({ data, onChange, checked }) {
|
|
398
486
|
const { setAvailableDiscountSelected, securityNumber } = usePBMStore();
|
|
399
487
|
const ID_INPUT = "unity_quantity_" + data.authorizedQuantity;
|
|
400
|
-
const decimalDiscount = data.discountPercentual /
|
|
401
|
-
const unitDiscountValue =
|
|
488
|
+
const decimalDiscount = data.discountPercentual / 100;
|
|
489
|
+
const unitDiscountValue = data.grossPrice * decimalDiscount;
|
|
402
490
|
const discountValue = unitDiscountValue * data.authorizedQuantity;
|
|
403
|
-
const totalPriceProductWithDiscountBenefit =
|
|
404
|
-
const updateStorageData = (0,
|
|
491
|
+
const totalPriceProductWithDiscountBenefit = data.grossPrice * data.authorizedQuantity - discountValue;
|
|
492
|
+
const updateStorageData = (0, import_react4.useCallback)(() => {
|
|
405
493
|
if (checked) {
|
|
406
494
|
const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
|
|
407
495
|
setAvailableDiscountSelected({
|
|
@@ -421,7 +509,7 @@ function Item({ data, onChange, checked, originalProductPrice }) {
|
|
|
421
509
|
totalPriceProductWithDiscountBenefit,
|
|
422
510
|
unitDiscountValue
|
|
423
511
|
]);
|
|
424
|
-
(0,
|
|
512
|
+
(0, import_react4.useEffect)(() => {
|
|
425
513
|
updateStorageData();
|
|
426
514
|
}, [updateStorageData]);
|
|
427
515
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
@@ -472,13 +560,104 @@ function Item({ data, onChange, checked, originalProductPrice }) {
|
|
|
472
560
|
}
|
|
473
561
|
var Item_default = Item;
|
|
474
562
|
|
|
563
|
+
// src/services/benefits-without-document.ts
|
|
564
|
+
var import_js_cookie3 = __toESM(require("js-cookie"));
|
|
565
|
+
var import_meta3 = {};
|
|
566
|
+
var CheckBenefistWithoutDocument = async ({ products }) => {
|
|
567
|
+
const API_URL = import_meta3.env.VITE_API_URL;
|
|
568
|
+
if (!API_URL) {
|
|
569
|
+
throw new Error("API URL is not defined in environment variables");
|
|
570
|
+
}
|
|
571
|
+
const AUTH_TOKEN = import_js_cookie3.default.get("pbm-token");
|
|
572
|
+
if (!AUTH_TOKEN) {
|
|
573
|
+
throw new Error("Token is not defined in cookies or is expired");
|
|
574
|
+
}
|
|
575
|
+
const response = await fetch(`${API_URL}/products/genericBenefit`, {
|
|
576
|
+
method: "POST",
|
|
577
|
+
headers: {
|
|
578
|
+
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
579
|
+
"Content-Type": "application/json"
|
|
580
|
+
},
|
|
581
|
+
body: JSON.stringify({ products })
|
|
582
|
+
});
|
|
583
|
+
const dataResponse = await response.json();
|
|
584
|
+
if (!dataResponse.success) {
|
|
585
|
+
throw new Error(dataResponse.message || "Failed to fetch benefits without document");
|
|
586
|
+
}
|
|
587
|
+
return dataResponse;
|
|
588
|
+
};
|
|
589
|
+
|
|
475
590
|
// src/components/BenefitsTable/index.tsx
|
|
476
591
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
477
|
-
function BenefitsTable({
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
const
|
|
481
|
-
const [
|
|
592
|
+
function BenefitsTable() {
|
|
593
|
+
const { securityNumber, setState, targetProduct } = usePBMStore();
|
|
594
|
+
const [selectedDiscout, setSelectedDiscount] = (0, import_react5.useState)(null);
|
|
595
|
+
const [loading, setLoading] = (0, import_react5.useState)(true);
|
|
596
|
+
const [benefitsItems, setBenefitsItems] = (0, import_react5.useState)();
|
|
597
|
+
(0, import_react5.useEffect)(() => {
|
|
598
|
+
const fetchDicountsWithoutDocument = async () => {
|
|
599
|
+
if (!targetProduct?.productId) {
|
|
600
|
+
console.error("PBMLOG: Product ID is not defined on targetProduct");
|
|
601
|
+
return;
|
|
602
|
+
}
|
|
603
|
+
if (!targetProduct.ean) {
|
|
604
|
+
console.error("PBMLOG: EAN is not defined on targetProduct");
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
if (!targetProduct.listPrice) {
|
|
608
|
+
console.error("PBMLOG: List Price is not defined on targetProduct");
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
if (!targetProduct.price) {
|
|
612
|
+
console.error("PBMLOG: Price is not defined on targetProduct");
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
try {
|
|
616
|
+
const data = {
|
|
617
|
+
productId: Number(targetProduct.productId),
|
|
618
|
+
ean: targetProduct.ean,
|
|
619
|
+
requestedQuantity: 1,
|
|
620
|
+
listPrice: targetProduct.listPrice,
|
|
621
|
+
netPrice: targetProduct.price
|
|
622
|
+
};
|
|
623
|
+
const response = await CheckBenefistWithoutDocument({ products: [data] });
|
|
624
|
+
if (response.success && response.data) {
|
|
625
|
+
setBenefitsItems(response.data);
|
|
626
|
+
} else {
|
|
627
|
+
setBenefitsItems(void 0);
|
|
628
|
+
}
|
|
629
|
+
} catch (error) {
|
|
630
|
+
setBenefitsItems(void 0);
|
|
631
|
+
console.error(error);
|
|
632
|
+
} finally {
|
|
633
|
+
setLoading(false);
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
const fetchDiscountWithDocument = async () => {
|
|
637
|
+
console.log("consulta feita com documento");
|
|
638
|
+
};
|
|
639
|
+
securityNumber ? fetchDiscountWithDocument() : fetchDicountsWithoutDocument();
|
|
640
|
+
}, []);
|
|
641
|
+
if (loading) {
|
|
642
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
|
|
643
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
644
|
+
"div",
|
|
645
|
+
{
|
|
646
|
+
"data-testid": "test_id_spin",
|
|
647
|
+
className: "w-8 h-8 border-4 border-t-gray-700 border-gray-300 rounded-full animate-spin",
|
|
648
|
+
id: "loading_spin"
|
|
649
|
+
}
|
|
650
|
+
),
|
|
651
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
652
|
+
"p",
|
|
653
|
+
{
|
|
654
|
+
className: "text-sm font-semibold text-start text-zinc-900",
|
|
655
|
+
id: "loading_label",
|
|
656
|
+
children: "Buscando beneficios dispon\xEDveis..."
|
|
657
|
+
}
|
|
658
|
+
)
|
|
659
|
+
] });
|
|
660
|
+
}
|
|
482
661
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
483
662
|
"section",
|
|
484
663
|
{
|
|
@@ -486,31 +665,34 @@ function BenefitsTable({
|
|
|
486
665
|
id: "benefits_table_pbm",
|
|
487
666
|
children: [
|
|
488
667
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Title_default, { children: "Descontos dispon\xEDveis:" }),
|
|
489
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.
|
|
668
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
490
669
|
"form",
|
|
491
670
|
{
|
|
492
671
|
className: "flex flex-col items-center justify-start w-full gap-3",
|
|
493
672
|
id: "form_benefits_table_pbm",
|
|
494
|
-
children:
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
673
|
+
children: [
|
|
674
|
+
!benefitsItems && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("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." }),
|
|
675
|
+
benefitsItems && benefitsItems.map((item, index) => {
|
|
676
|
+
const ID_INPUT = "unity_quantity_" + item.authorizedQuantity;
|
|
677
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
678
|
+
Item_default,
|
|
679
|
+
{
|
|
680
|
+
data: item,
|
|
681
|
+
checked: selectedDiscout === ID_INPUT,
|
|
682
|
+
onChange: () => setSelectedDiscount(ID_INPUT)
|
|
683
|
+
},
|
|
684
|
+
index
|
|
685
|
+
);
|
|
686
|
+
}),
|
|
687
|
+
benefitsItems && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "w-full text-sm font-semibold text-center text-zinc-600", id: "benefits_empty_pbm", children: benefitsItems[0].informativeMessage })
|
|
688
|
+
]
|
|
507
689
|
}
|
|
508
690
|
),
|
|
509
691
|
!securityNumber && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
510
692
|
Button_default,
|
|
511
693
|
{
|
|
512
694
|
onClick: () => setState("isEmpty"),
|
|
513
|
-
className: "bg-transparent p-0
|
|
695
|
+
className: "bg-transparent p-0 w-auto h-auto text-zinc-600 cursor-pointer hover:text-zinc-900 hover:bg-transparent text-start",
|
|
514
696
|
id: "unauthorized_benefits_button",
|
|
515
697
|
children: [
|
|
516
698
|
"Aten\xE7\xE3o: n\xE3o \xE9 poss\xEDvel utilizar os benef\xEDcos sem realizar a consulta do cpf, por favor",
|
|
@@ -622,10 +804,10 @@ function Iframe({ url, title, openModal, setOpenModal }) {
|
|
|
622
804
|
var Iframe_default = Iframe;
|
|
623
805
|
|
|
624
806
|
// src/components/SecurityNumberInvalid/index.tsx
|
|
625
|
-
var
|
|
807
|
+
var import_react6 = require("react");
|
|
626
808
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
627
809
|
function SecurityNumberInvalid({ textColor }) {
|
|
628
|
-
const [openModal, setOpenModal] = (0,
|
|
810
|
+
const [openModal, setOpenModal] = (0, import_react6.useState)(false);
|
|
629
811
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
630
812
|
"section",
|
|
631
813
|
{
|
|
@@ -660,7 +842,7 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
660
842
|
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
661
843
|
|
|
662
844
|
// src/PBM.tsx
|
|
663
|
-
var
|
|
845
|
+
var import_react7 = require("react");
|
|
664
846
|
|
|
665
847
|
// src/components/UI/Link/index.tsx
|
|
666
848
|
var import_classnames8 = __toESM(require("classnames"));
|
|
@@ -721,12 +903,12 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
721
903
|
var SecurityNumberRegitered_default = SecurityNumberRegitered;
|
|
722
904
|
|
|
723
905
|
// src/services/authorization.ts
|
|
724
|
-
var
|
|
725
|
-
var
|
|
906
|
+
var import_js_cookie4 = __toESM(require("js-cookie"));
|
|
907
|
+
var import_meta4 = {};
|
|
726
908
|
var GetAuthorization = async ({ clientID }) => {
|
|
727
|
-
const API_URL =
|
|
728
|
-
const STORE_ID =
|
|
729
|
-
const STORE_NAME =
|
|
909
|
+
const API_URL = import_meta4.env.VITE_API_URL;
|
|
910
|
+
const STORE_ID = import_meta4.env.VITE_STORE_ID;
|
|
911
|
+
const STORE_NAME = import_meta4.env.VITE_STORE_NAME;
|
|
730
912
|
if (!API_URL) {
|
|
731
913
|
throw new Error("API URL is not defined in environment variables");
|
|
732
914
|
}
|
|
@@ -739,21 +921,22 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
739
921
|
"Content-Type": "application/json"
|
|
740
922
|
},
|
|
741
923
|
body: JSON.stringify({
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
924
|
+
storeId: STORE_ID,
|
|
925
|
+
storeName: STORE_NAME,
|
|
926
|
+
clientId: clientID
|
|
745
927
|
})
|
|
746
928
|
});
|
|
747
929
|
const dataResponse = await response.json();
|
|
748
930
|
if (!dataResponse.success) {
|
|
749
931
|
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
750
932
|
}
|
|
751
|
-
|
|
752
|
-
expires:
|
|
933
|
+
import_js_cookie4.default.set("pbm-token", dataResponse.data.token, {
|
|
934
|
+
expires: dataResponse.data.expiresIn / (60 * 60),
|
|
753
935
|
secure: true,
|
|
754
936
|
sameSite: "Strict"
|
|
755
937
|
});
|
|
756
|
-
|
|
938
|
+
import_js_cookie4.default.set("pbm-token-refresh", dataResponse.data.refreshToken, {
|
|
939
|
+
expires: dataResponse.data.refreshExpiresIn / (60 * 60),
|
|
757
940
|
secure: true,
|
|
758
941
|
sameSite: "Strict"
|
|
759
942
|
});
|
|
@@ -765,33 +948,30 @@ var import_lucide_react4 = require("lucide-react");
|
|
|
765
948
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
766
949
|
function PBM({
|
|
767
950
|
originalProductPrice,
|
|
768
|
-
industryLogo,
|
|
769
951
|
clientID,
|
|
770
952
|
eanProduct
|
|
771
953
|
}) {
|
|
772
954
|
const formatedOriginalProductPrice = Number(
|
|
773
955
|
String(originalProductPrice).replace(",", ".")
|
|
774
956
|
);
|
|
775
|
-
const [loading, setLoading] = (0,
|
|
957
|
+
const [loading, setLoading] = (0, import_react7.useState)(false);
|
|
776
958
|
const { setState, state, setTargetProduct } = usePBMStore();
|
|
777
|
-
(0,
|
|
959
|
+
(0, import_react7.useEffect)(() => {
|
|
778
960
|
if (eanProduct) {
|
|
779
|
-
setTargetProduct({ ean: eanProduct
|
|
961
|
+
setTargetProduct({ ean: eanProduct });
|
|
780
962
|
}
|
|
781
963
|
}, [eanProduct, setTargetProduct]);
|
|
782
|
-
const handleAuthorizationRequest = (0,
|
|
964
|
+
const handleAuthorizationRequest = (0, import_react7.useCallback)(async () => {
|
|
783
965
|
try {
|
|
784
966
|
const response = await GetAuthorization({ clientID });
|
|
785
|
-
if (response.success) {
|
|
786
|
-
console.
|
|
787
|
-
} else {
|
|
788
|
-
console.error("Authorization failed:", response.message);
|
|
967
|
+
if (!response.success) {
|
|
968
|
+
console.error("PBMLOG: Authorization failed!");
|
|
789
969
|
}
|
|
790
970
|
} catch (error) {
|
|
791
971
|
console.error("Error fetching authorization:", error);
|
|
792
972
|
}
|
|
793
973
|
}, [clientID]);
|
|
794
|
-
(0,
|
|
974
|
+
(0, import_react7.useEffect)(() => {
|
|
795
975
|
handleAuthorizationRequest();
|
|
796
976
|
}, [handleAuthorizationRequest]);
|
|
797
977
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Container_default, { variant: "main", children: [
|
|
@@ -815,9 +995,9 @@ function PBM({
|
|
|
815
995
|
state === "isEmpty" && loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Loading_default, {}),
|
|
816
996
|
state === "isInvalid" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SecurityNumberInvalid_default, {}),
|
|
817
997
|
state === "isRegistered" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SecurityNumberRegitered_default, {}),
|
|
818
|
-
state === "isActivated" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BenefitsTable_default, {
|
|
998
|
+
state === "isActivated" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BenefitsTable_default, {})
|
|
819
999
|
] }),
|
|
820
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Footer_default, {
|
|
1000
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Footer_default, {})
|
|
821
1001
|
] });
|
|
822
1002
|
}
|
|
823
1003
|
var PBM_default = PBM;
|