@agrada_digital/pbm 0.0.55 → 0.0.56
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 +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.js +238 -146
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +230 -139
- package/dist/index.mjs.map +1 -1
- package/dist-wc/pbm-wc.js +92 -92
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2,11 +2,10 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
|
|
3
3
|
interface PBMProps {
|
|
4
4
|
originalProductPrice: number | string;
|
|
5
|
-
industryLogo?: string;
|
|
6
5
|
clientID: string;
|
|
7
6
|
eanProduct: string;
|
|
8
7
|
}
|
|
9
|
-
declare function PBM({ originalProductPrice,
|
|
8
|
+
declare function PBM({ originalProductPrice, clientID, eanProduct, }: PBMProps): react_jsx_runtime.JSX.Element;
|
|
10
9
|
|
|
11
10
|
interface discountTypes {
|
|
12
11
|
unit: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,10 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
|
|
3
3
|
interface PBMProps {
|
|
4
4
|
originalProductPrice: number | string;
|
|
5
|
-
industryLogo?: string;
|
|
6
5
|
clientID: string;
|
|
7
6
|
eanProduct: string;
|
|
8
7
|
}
|
|
9
|
-
declare function PBM({ originalProductPrice,
|
|
8
|
+
declare function PBM({ originalProductPrice, clientID, eanProduct, }: PBMProps): react_jsx_runtime.JSX.Element;
|
|
10
9
|
|
|
11
10
|
interface discountTypes {
|
|
12
11
|
unit: number;
|
package/dist/index.js
CHANGED
|
@@ -90,8 +90,82 @@ 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.sucesso) {
|
|
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)(void 0);
|
|
154
|
+
const { targetProduct } = usePBMStore();
|
|
155
|
+
(0, import_react2.useEffect)(() => {
|
|
156
|
+
const fetchProductByEan = async () => {
|
|
157
|
+
if (!targetProduct) return;
|
|
158
|
+
try {
|
|
159
|
+
const response = await GetProductByEAN({ PRODUCT_EAN: targetProduct.ean });
|
|
160
|
+
if (response.sucesso && response.dados) {
|
|
161
|
+
setIndustryLogo(response.dados.pbm.imageLink);
|
|
162
|
+
}
|
|
163
|
+
} catch (error) {
|
|
164
|
+
console.error(error);
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
fetchProductByEan();
|
|
168
|
+
}, [targetProduct]);
|
|
95
169
|
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
170
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "w-4/5 h-auto", children: [
|
|
97
171
|
/* @__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 +176,7 @@ function Footer({ industryLogo }) {
|
|
|
102
176
|
{
|
|
103
177
|
src: industryLogo,
|
|
104
178
|
alt: "parceiro",
|
|
105
|
-
className: "w-1/5 min-w-20 h-auto aspect-
|
|
179
|
+
className: "w-1/5 min-w-20 h-auto aspect-auto",
|
|
106
180
|
loading: "eager",
|
|
107
181
|
id: "footer_industry_logo_pbm",
|
|
108
182
|
"data-testid": "footer_industry_logo_pbm"
|
|
@@ -123,7 +197,8 @@ var validationSchema = import_zod.z.strictObject({
|
|
|
123
197
|
}, "CPF deve conter no m\xEDnimo 11 caracteres.").refine((doc) => {
|
|
124
198
|
const replacedDoc = doc.replace(/\D/g, "");
|
|
125
199
|
return !!Number(replacedDoc);
|
|
126
|
-
}, "CPF deve conter apenas n\xFAmeros.")
|
|
200
|
+
}, "CPF deve conter apenas n\xFAmeros."),
|
|
201
|
+
coupon: import_zod.z.string().min(0)
|
|
127
202
|
});
|
|
128
203
|
|
|
129
204
|
// src/utils/format.ts
|
|
@@ -135,52 +210,21 @@ var toFormat = (value) => {
|
|
|
135
210
|
};
|
|
136
211
|
|
|
137
212
|
// src/components/Form/index.tsx
|
|
138
|
-
var
|
|
213
|
+
var import_classnames4 = __toESM(require("classnames"));
|
|
139
214
|
var import_zod2 = require("@hookform/resolvers/zod");
|
|
140
215
|
var import_react_hook_form = require("react-hook-form");
|
|
141
216
|
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
|
-
}
|
|
217
|
+
var import_react3 = require("react");
|
|
174
218
|
|
|
175
219
|
// src/services/validate-document.ts
|
|
176
|
-
var
|
|
177
|
-
var
|
|
220
|
+
var import_js_cookie2 = __toESM(require("js-cookie"));
|
|
221
|
+
var import_meta2 = {};
|
|
178
222
|
var ValidateDocument = async ({ document, products }) => {
|
|
179
|
-
const API_URL =
|
|
223
|
+
const API_URL = import_meta2.env.VITE_API_URL;
|
|
180
224
|
if (!API_URL) {
|
|
181
225
|
throw new Error("API URL is not defined in environment variables");
|
|
182
226
|
}
|
|
183
|
-
const AUTH_TOKEN =
|
|
227
|
+
const AUTH_TOKEN = import_js_cookie2.default.get("pbm-token");
|
|
184
228
|
if (!AUTH_TOKEN) {
|
|
185
229
|
throw new Error("Token is not defined in cookies or is expired");
|
|
186
230
|
}
|
|
@@ -199,10 +243,29 @@ var ValidateDocument = async ({ document, products }) => {
|
|
|
199
243
|
return dataResponse;
|
|
200
244
|
};
|
|
201
245
|
|
|
202
|
-
// src/components/
|
|
246
|
+
// src/components/UI/Button/index.tsx
|
|
247
|
+
var import_classnames3 = __toESM(require("classnames"));
|
|
203
248
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
249
|
+
function Button(props) {
|
|
250
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
251
|
+
"button",
|
|
252
|
+
{
|
|
253
|
+
...props,
|
|
254
|
+
className: (0, import_classnames3.default)(
|
|
255
|
+
"w-3xs cursor-pointer h-10 rounded-full bg-blue-500 hover:bg-blue-400 text-white text-sm font-semibold transition-colors",
|
|
256
|
+
props.className
|
|
257
|
+
),
|
|
258
|
+
children: props.children
|
|
259
|
+
}
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
var Button_default = Button;
|
|
263
|
+
|
|
264
|
+
// src/components/Form/index.tsx
|
|
265
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
204
266
|
function Form({ setLoading }) {
|
|
205
267
|
const { setSecurityNumber, setState, securityNumber, targetProduct } = usePBMStore();
|
|
268
|
+
const [showCoupoField, setShowCoupoField] = (0, import_react3.useState)(false);
|
|
206
269
|
const {
|
|
207
270
|
handleSubmit,
|
|
208
271
|
register,
|
|
@@ -218,7 +281,7 @@ function Form({ setLoading }) {
|
|
|
218
281
|
setLoading(true);
|
|
219
282
|
try {
|
|
220
283
|
if (targetProduct === null) {
|
|
221
|
-
console.error("Product is not defined!");
|
|
284
|
+
console.error("PBMLOG: Product is not defined!");
|
|
222
285
|
return;
|
|
223
286
|
}
|
|
224
287
|
const response = await ValidateDocument({
|
|
@@ -234,76 +297,125 @@ function Form({ setLoading }) {
|
|
|
234
297
|
setState(status[response.data.process_platform.status]);
|
|
235
298
|
}
|
|
236
299
|
} catch (error) {
|
|
237
|
-
console.error("Error validating document
|
|
300
|
+
console.error("PBMLOG: Error validating document -", error);
|
|
238
301
|
} finally {
|
|
239
302
|
setLoading(false);
|
|
240
303
|
}
|
|
241
304
|
;
|
|
242
305
|
};
|
|
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
|
-
}
|
|
306
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
307
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
308
|
+
"form",
|
|
309
|
+
{
|
|
310
|
+
onSubmit: handleSubmit(onSubmitDefault),
|
|
311
|
+
className: (0, import_classnames4.default)(
|
|
312
|
+
"w-full h-auto flex items-center justify-center mb-0 transition-all duration-150",
|
|
313
|
+
{ "mb-4": errors.securityNumber || errors.coupon, "gap-2": showCoupoField }
|
|
286
314
|
),
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
315
|
+
id: "form_security_number_pbm",
|
|
316
|
+
children: [
|
|
317
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
318
|
+
"label",
|
|
319
|
+
{
|
|
320
|
+
htmlFor: "cpf",
|
|
321
|
+
className: "w-4/5 h-auto flex items-start flex-col justify-center relative py-2",
|
|
322
|
+
id: "label_security_number_pbm",
|
|
323
|
+
children: [
|
|
324
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
325
|
+
"input",
|
|
326
|
+
{
|
|
327
|
+
type: "text",
|
|
328
|
+
className: (0, import_classnames4.default)(
|
|
329
|
+
"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",
|
|
330
|
+
{ "outline outline-red-600": errors.securityNumber, "rounded-full": showCoupoField }
|
|
331
|
+
),
|
|
332
|
+
placeholder: "Digite seu CPF aqui...",
|
|
333
|
+
required: true,
|
|
334
|
+
maxLength: 14,
|
|
335
|
+
...register("securityNumber", {
|
|
336
|
+
onChange: (e) => {
|
|
337
|
+
const formatted = toFormat(e.target.value);
|
|
338
|
+
setValue("securityNumber", formatted, {
|
|
339
|
+
shouldValidate: true
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
}),
|
|
343
|
+
defaultValue: securityNumber || "",
|
|
344
|
+
id: "input_security_number_pbm"
|
|
345
|
+
}
|
|
346
|
+
),
|
|
347
|
+
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 })
|
|
348
|
+
]
|
|
349
|
+
}
|
|
350
|
+
),
|
|
351
|
+
showCoupoField && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
352
|
+
"label",
|
|
353
|
+
{
|
|
354
|
+
htmlFor: "coupon",
|
|
355
|
+
className: "w-4/5 h-auto flex items-start flex-col justify-center relative py-2",
|
|
356
|
+
id: "label_coupon_pbm",
|
|
357
|
+
children: [
|
|
358
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
359
|
+
"input",
|
|
360
|
+
{
|
|
361
|
+
type: "text",
|
|
362
|
+
className: (0, import_classnames4.default)(
|
|
363
|
+
"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",
|
|
364
|
+
{ "outline outline-red-600": errors.coupon, "rounded-full": showCoupoField }
|
|
365
|
+
),
|
|
366
|
+
placeholder: "Cupom / ID do Cart\xE3o",
|
|
367
|
+
required: true,
|
|
368
|
+
maxLength: 14,
|
|
369
|
+
...register("coupon", {
|
|
370
|
+
onChange: (e) => {
|
|
371
|
+
setValue("coupon", e.target.value, {
|
|
372
|
+
shouldValidate: true
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}),
|
|
376
|
+
id: "input_coupon_pbm"
|
|
377
|
+
}
|
|
378
|
+
),
|
|
379
|
+
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 })
|
|
380
|
+
]
|
|
381
|
+
}
|
|
382
|
+
),
|
|
383
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
384
|
+
"button",
|
|
385
|
+
{
|
|
386
|
+
type: "submit",
|
|
387
|
+
className: (0, import_classnames4.default)(
|
|
388
|
+
"bg-gray-400 w-1/5 h-8 flex items-center justify-center rounded-e-full cursor-pointer",
|
|
389
|
+
{ "rounded-full": showCoupoField }
|
|
390
|
+
),
|
|
391
|
+
id: "button_submit_security_number_pbm",
|
|
392
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.ArrowRight, { size: 24, color: "white", strokeWidth: 2 })
|
|
393
|
+
}
|
|
394
|
+
)
|
|
395
|
+
]
|
|
396
|
+
}
|
|
397
|
+
),
|
|
398
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
399
|
+
Button_default,
|
|
400
|
+
{
|
|
401
|
+
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",
|
|
402
|
+
onClick: () => setShowCoupoField(!showCoupoField),
|
|
403
|
+
id: "check_benefits_button",
|
|
404
|
+
children: [
|
|
405
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: !showCoupoField ? "Possui cupom?" : "N\xE3o possui cupom?" }),
|
|
406
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react.ArrowRight, { size: 16, className: (0, import_classnames4.default)({ "rotate-0": !showCoupoField, "rotate-180": showCoupoField }) })
|
|
407
|
+
]
|
|
408
|
+
}
|
|
409
|
+
)
|
|
410
|
+
] });
|
|
299
411
|
}
|
|
300
412
|
var Form_default = Form;
|
|
301
413
|
|
|
302
414
|
// src/components/UI/Loading/index.tsx
|
|
303
|
-
var
|
|
415
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
304
416
|
function Loading({ textColor }) {
|
|
305
|
-
return /* @__PURE__ */ (0,
|
|
306
|
-
/* @__PURE__ */ (0,
|
|
417
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
|
|
418
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
307
419
|
"div",
|
|
308
420
|
{
|
|
309
421
|
"data-testid": "test_id_spin",
|
|
@@ -311,7 +423,7 @@ function Loading({ textColor }) {
|
|
|
311
423
|
id: "loading_spin"
|
|
312
424
|
}
|
|
313
425
|
),
|
|
314
|
-
/* @__PURE__ */ (0,
|
|
426
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
315
427
|
"p",
|
|
316
428
|
{
|
|
317
429
|
className: "text-sm font-semibold text-start text-zinc-900",
|
|
@@ -324,26 +436,8 @@ function Loading({ textColor }) {
|
|
|
324
436
|
}
|
|
325
437
|
var Loading_default = Loading;
|
|
326
438
|
|
|
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
439
|
// src/components/BenefitsTable/index.tsx
|
|
346
|
-
var
|
|
440
|
+
var import_react5 = require("react");
|
|
347
441
|
|
|
348
442
|
// src/mocks/benefits.ts
|
|
349
443
|
var BENEFITS_ITEMS = [
|
|
@@ -392,7 +486,7 @@ var Title_default = Title;
|
|
|
392
486
|
|
|
393
487
|
// src/components/BenefitsTable/Item.tsx
|
|
394
488
|
var import_lucide_react2 = require("lucide-react");
|
|
395
|
-
var
|
|
489
|
+
var import_react4 = require("react");
|
|
396
490
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
397
491
|
function Item({ data, onChange, checked, originalProductPrice }) {
|
|
398
492
|
const { setAvailableDiscountSelected, securityNumber } = usePBMStore();
|
|
@@ -401,7 +495,7 @@ function Item({ data, onChange, checked, originalProductPrice }) {
|
|
|
401
495
|
const unitDiscountValue = originalProductPrice * decimalDiscount;
|
|
402
496
|
const discountValue = unitDiscountValue * data.authorizedQuantity;
|
|
403
497
|
const totalPriceProductWithDiscountBenefit = originalProductPrice * data.authorizedQuantity - discountValue;
|
|
404
|
-
const updateStorageData = (0,
|
|
498
|
+
const updateStorageData = (0, import_react4.useCallback)(() => {
|
|
405
499
|
if (checked) {
|
|
406
500
|
const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
|
|
407
501
|
setAvailableDiscountSelected({
|
|
@@ -421,7 +515,7 @@ function Item({ data, onChange, checked, originalProductPrice }) {
|
|
|
421
515
|
totalPriceProductWithDiscountBenefit,
|
|
422
516
|
unitDiscountValue
|
|
423
517
|
]);
|
|
424
|
-
(0,
|
|
518
|
+
(0, import_react4.useEffect)(() => {
|
|
425
519
|
updateStorageData();
|
|
426
520
|
}, [updateStorageData]);
|
|
427
521
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
|
@@ -478,7 +572,7 @@ function BenefitsTable({
|
|
|
478
572
|
originalProductPrice
|
|
479
573
|
}) {
|
|
480
574
|
const { securityNumber, setState } = usePBMStore();
|
|
481
|
-
const [selectedDiscout, setSelectedDiscount] = (0,
|
|
575
|
+
const [selectedDiscout, setSelectedDiscount] = (0, import_react5.useState)(null);
|
|
482
576
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
483
577
|
"section",
|
|
484
578
|
{
|
|
@@ -622,10 +716,10 @@ function Iframe({ url, title, openModal, setOpenModal }) {
|
|
|
622
716
|
var Iframe_default = Iframe;
|
|
623
717
|
|
|
624
718
|
// src/components/SecurityNumberInvalid/index.tsx
|
|
625
|
-
var
|
|
719
|
+
var import_react6 = require("react");
|
|
626
720
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
627
721
|
function SecurityNumberInvalid({ textColor }) {
|
|
628
|
-
const [openModal, setOpenModal] = (0,
|
|
722
|
+
const [openModal, setOpenModal] = (0, import_react6.useState)(false);
|
|
629
723
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
630
724
|
"section",
|
|
631
725
|
{
|
|
@@ -660,7 +754,7 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
660
754
|
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
661
755
|
|
|
662
756
|
// src/PBM.tsx
|
|
663
|
-
var
|
|
757
|
+
var import_react7 = require("react");
|
|
664
758
|
|
|
665
759
|
// src/components/UI/Link/index.tsx
|
|
666
760
|
var import_classnames8 = __toESM(require("classnames"));
|
|
@@ -721,12 +815,12 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
721
815
|
var SecurityNumberRegitered_default = SecurityNumberRegitered;
|
|
722
816
|
|
|
723
817
|
// src/services/authorization.ts
|
|
724
|
-
var
|
|
725
|
-
var
|
|
818
|
+
var import_js_cookie3 = __toESM(require("js-cookie"));
|
|
819
|
+
var import_meta3 = {};
|
|
726
820
|
var GetAuthorization = async ({ clientID }) => {
|
|
727
|
-
const API_URL =
|
|
728
|
-
const STORE_ID =
|
|
729
|
-
const STORE_NAME =
|
|
821
|
+
const API_URL = import_meta3.env.VITE_API_URL;
|
|
822
|
+
const STORE_ID = import_meta3.env.VITE_STORE_ID;
|
|
823
|
+
const STORE_NAME = import_meta3.env.VITE_STORE_NAME;
|
|
730
824
|
if (!API_URL) {
|
|
731
825
|
throw new Error("API URL is not defined in environment variables");
|
|
732
826
|
}
|
|
@@ -748,12 +842,13 @@ var GetAuthorization = async ({ clientID }) => {
|
|
|
748
842
|
if (!dataResponse.success) {
|
|
749
843
|
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
750
844
|
}
|
|
751
|
-
|
|
752
|
-
expires:
|
|
845
|
+
import_js_cookie3.default.set("pbm-token", dataResponse.data.Token, {
|
|
846
|
+
expires: dataResponse.data.ExpiresIn / (60 * 60),
|
|
753
847
|
secure: true,
|
|
754
848
|
sameSite: "Strict"
|
|
755
849
|
});
|
|
756
|
-
|
|
850
|
+
import_js_cookie3.default.set("pbm-token-refresh", dataResponse.data.RefreshToken, {
|
|
851
|
+
expires: dataResponse.data.RefreshExpiresIn / (60 * 60),
|
|
757
852
|
secure: true,
|
|
758
853
|
sameSite: "Strict"
|
|
759
854
|
});
|
|
@@ -765,33 +860,30 @@ var import_lucide_react4 = require("lucide-react");
|
|
|
765
860
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
766
861
|
function PBM({
|
|
767
862
|
originalProductPrice,
|
|
768
|
-
industryLogo,
|
|
769
863
|
clientID,
|
|
770
864
|
eanProduct
|
|
771
865
|
}) {
|
|
772
866
|
const formatedOriginalProductPrice = Number(
|
|
773
867
|
String(originalProductPrice).replace(",", ".")
|
|
774
868
|
);
|
|
775
|
-
const [loading, setLoading] = (0,
|
|
869
|
+
const [loading, setLoading] = (0, import_react7.useState)(false);
|
|
776
870
|
const { setState, state, setTargetProduct } = usePBMStore();
|
|
777
|
-
(0,
|
|
871
|
+
(0, import_react7.useEffect)(() => {
|
|
778
872
|
if (eanProduct) {
|
|
779
873
|
setTargetProduct({ ean: eanProduct, quantity: 1 });
|
|
780
874
|
}
|
|
781
875
|
}, [eanProduct, setTargetProduct]);
|
|
782
|
-
const handleAuthorizationRequest = (0,
|
|
876
|
+
const handleAuthorizationRequest = (0, import_react7.useCallback)(async () => {
|
|
783
877
|
try {
|
|
784
878
|
const response = await GetAuthorization({ clientID });
|
|
785
|
-
if (response.success) {
|
|
786
|
-
console.
|
|
787
|
-
} else {
|
|
788
|
-
console.error("Authorization failed:", response.message);
|
|
879
|
+
if (!response.success) {
|
|
880
|
+
console.error("PBMLOG: Authorization failed!");
|
|
789
881
|
}
|
|
790
882
|
} catch (error) {
|
|
791
883
|
console.error("Error fetching authorization:", error);
|
|
792
884
|
}
|
|
793
885
|
}, [clientID]);
|
|
794
|
-
(0,
|
|
886
|
+
(0, import_react7.useEffect)(() => {
|
|
795
887
|
handleAuthorizationRequest();
|
|
796
888
|
}, [handleAuthorizationRequest]);
|
|
797
889
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(Container_default, { variant: "main", children: [
|
|
@@ -817,7 +909,7 @@ function PBM({
|
|
|
817
909
|
state === "isRegistered" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(SecurityNumberRegitered_default, {}),
|
|
818
910
|
state === "isActivated" && !loading && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(BenefitsTable_default, { originalProductPrice: formatedOriginalProductPrice })
|
|
819
911
|
] }),
|
|
820
|
-
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Footer_default, {
|
|
912
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)(Footer_default, {})
|
|
821
913
|
] });
|
|
822
914
|
}
|
|
823
915
|
var PBM_default = PBM;
|