@agrada_digital/pbm 0.0.128 → 0.0.129
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +130 -27
- package/package.json +3 -20
- package/dist/index.cjs +0 -2828
- package/dist/index.cjs.map +0 -1
- package/dist/index.css +0 -1432
- package/dist/index.css.map +0 -1
- package/dist/index.d.cts +0 -100
- package/dist/index.d.ts +0 -100
- package/dist/index.js +0 -2789
- package/dist/index.js.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,2789 +0,0 @@
|
|
|
1
|
-
// src/schema/validation-schema.ts
|
|
2
|
-
import { z } from "zod";
|
|
3
|
-
var validationSchema = z.object({
|
|
4
|
-
securityNumber: z.string({
|
|
5
|
-
required_error: "CPF \xE9 obrigat\xF3rio."
|
|
6
|
-
}).refine((doc) => {
|
|
7
|
-
const replacedDoc = doc.replace(/\D/g, "");
|
|
8
|
-
return replacedDoc.length >= 11;
|
|
9
|
-
}, "CPF deve conter no m\xEDnimo 11 caracteres.").refine((doc) => {
|
|
10
|
-
const replacedDoc = doc.replace(/\D/g, "");
|
|
11
|
-
return !!Number(replacedDoc);
|
|
12
|
-
}, "CPF deve conter apenas n\xFAmeros."),
|
|
13
|
-
coupon: z.string({ required_error: "Cupom / ID do Cart\xE3o obrigat\xF3rio." }).optional()
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
// src/components/UI/Button/index.tsx
|
|
17
|
-
import classNames from "classnames";
|
|
18
|
-
import { jsx } from "react/jsx-runtime";
|
|
19
|
-
function Button(props) {
|
|
20
|
-
return /* @__PURE__ */ jsx(
|
|
21
|
-
"button",
|
|
22
|
-
{
|
|
23
|
-
...props,
|
|
24
|
-
className: classNames(
|
|
25
|
-
"w-3xs cursor-pointer h-10 rounded-lg text-white text-sm font-semibold transition-colors",
|
|
26
|
-
props.className
|
|
27
|
-
),
|
|
28
|
-
style: { ...props.style },
|
|
29
|
-
children: props.children
|
|
30
|
-
}
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
var Button_default = Button;
|
|
34
|
-
|
|
35
|
-
// src/libs/zustand/usePBM.tsx
|
|
36
|
-
import { createStore } from "zustand";
|
|
37
|
-
import { useStore } from "zustand/react";
|
|
38
|
-
var initialPBMState = {
|
|
39
|
-
securityNumber: "",
|
|
40
|
-
requestId: "",
|
|
41
|
-
cardID: "",
|
|
42
|
-
state: "isEmpty",
|
|
43
|
-
availableDiscountSelected: {
|
|
44
|
-
quantity: 0,
|
|
45
|
-
discount: {
|
|
46
|
-
unit: 0,
|
|
47
|
-
total: 0
|
|
48
|
-
},
|
|
49
|
-
totalPrice: 0,
|
|
50
|
-
grossPrice: 0
|
|
51
|
-
},
|
|
52
|
-
benefitsEnabled: true,
|
|
53
|
-
benefitsList: null,
|
|
54
|
-
targetProduct: null,
|
|
55
|
-
campaign: "pbm_campaign",
|
|
56
|
-
isAuthenticatedShopper: false,
|
|
57
|
-
customLoginUrl: "/login"
|
|
58
|
-
};
|
|
59
|
-
var createPBMStore = (set) => ({
|
|
60
|
-
...initialPBMState,
|
|
61
|
-
setSecurityNumber: (securityNumber) => set({ securityNumber }),
|
|
62
|
-
setRequestId: (requestId) => set({ requestId }),
|
|
63
|
-
setState: (state) => set({ state }),
|
|
64
|
-
setTargetProduct: (targetProduct) => set({ targetProduct }),
|
|
65
|
-
setAvailableDiscountSelected: (availableDiscount) => set({ availableDiscountSelected: availableDiscount }),
|
|
66
|
-
setUrlAcceptTerms: (urlAcceptTerms) => set({ urlAcceptTerms }),
|
|
67
|
-
setUrlRegisterIndustry: (urlRegisterIndustry) => set({ urlRegisterIndustry }),
|
|
68
|
-
setIsAuthenticatedShopper: (isAuthenticatedShopper) => set({ isAuthenticatedShopper }),
|
|
69
|
-
setCustomLoginUrl: (customLoginUrl) => set({ customLoginUrl }),
|
|
70
|
-
setCardID: (cardID) => set({ cardID }),
|
|
71
|
-
setBenefitsEnabled: (benefitsEnabled) => set({ benefitsEnabled }),
|
|
72
|
-
setBenefitsList: (benefitsList) => set({ benefitsList })
|
|
73
|
-
});
|
|
74
|
-
var pbmStore = createStore(createPBMStore);
|
|
75
|
-
function usePBMStore(selector) {
|
|
76
|
-
return useStore(
|
|
77
|
-
pbmStore,
|
|
78
|
-
selector ?? ((state) => state)
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// src/components/Form/index.tsx
|
|
83
|
-
import { zodResolver } from "@hookform/resolvers/zod";
|
|
84
|
-
import { useForm } from "react-hook-form";
|
|
85
|
-
import { ArrowRight } from "lucide-react";
|
|
86
|
-
import classNames2 from "classnames";
|
|
87
|
-
import { Activity, useState } from "react";
|
|
88
|
-
|
|
89
|
-
// src/libs/zustand/useModal.tsx
|
|
90
|
-
import { create } from "zustand";
|
|
91
|
-
var initialModalState = {
|
|
92
|
-
modal: {
|
|
93
|
-
id: "",
|
|
94
|
-
open: false,
|
|
95
|
-
label: "",
|
|
96
|
-
url: ""
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
var createModalStore = (set) => ({
|
|
100
|
-
...initialModalState,
|
|
101
|
-
setModal: (modal) => set({ modal }),
|
|
102
|
-
resetModal: () => set({ modal: initialModalState.modal })
|
|
103
|
-
});
|
|
104
|
-
var useModal = create(createModalStore);
|
|
105
|
-
|
|
106
|
-
// src/utils/formaters.ts
|
|
107
|
-
var formatPhone = (value) => value.replace(/\D/g, "").slice(0, 11).replace(/^(\d{2})(\d{5})(\d{0,4})/, "($1) $2-$3").trim();
|
|
108
|
-
var formatCEP = (value) => value.replace(/\D/g, "").slice(0, 8).replace(/^(\d{5})(\d{0,3})/, "$1-$2");
|
|
109
|
-
var maskCPF = (value) => value.replace(/\D/g, "").replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4");
|
|
110
|
-
var formatPrice = (price) => Number(String(price).replace(",", "."));
|
|
111
|
-
var transformPrice = (price) => {
|
|
112
|
-
const priceString = String(price);
|
|
113
|
-
if (priceString.includes(".") || priceString.includes(",")) {
|
|
114
|
-
return formatPrice(price);
|
|
115
|
-
}
|
|
116
|
-
const cents = priceString.slice(-2);
|
|
117
|
-
const reais = priceString.slice(0, -2) || "0";
|
|
118
|
-
return Number(`${reais}.${cents}`);
|
|
119
|
-
};
|
|
120
|
-
var transformPorcent = (porcent) => {
|
|
121
|
-
const post = porcent.slice(-2);
|
|
122
|
-
const pre = porcent.slice(0, -2) || "0";
|
|
123
|
-
return Number(`${pre}.${post}`);
|
|
124
|
-
};
|
|
125
|
-
function priceToInteger(value) {
|
|
126
|
-
return String(value).replace(/[.,]/g, "");
|
|
127
|
-
}
|
|
128
|
-
var formaters = {
|
|
129
|
-
phone: (value) => formatPhone(value),
|
|
130
|
-
cep: (value) => formatCEP(value),
|
|
131
|
-
cpf: (value) => maskCPF(value),
|
|
132
|
-
priceToInteger: (value) => priceToInteger(value),
|
|
133
|
-
price: (price) => formatPrice(price),
|
|
134
|
-
transformPrice: (price) => transformPrice(price),
|
|
135
|
-
transformPorcent: (porcent) => transformPorcent(porcent)
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
// src/services/lookup-consumer.ts
|
|
139
|
-
import Cookies from "js-cookie";
|
|
140
|
-
|
|
141
|
-
// src/services/helper.ts
|
|
142
|
-
var getEnv = (key) => {
|
|
143
|
-
if (typeof import.meta !== "undefined") {
|
|
144
|
-
return import.meta.env?.[key];
|
|
145
|
-
}
|
|
146
|
-
if (typeof process !== "undefined") {
|
|
147
|
-
return process.env?.[key];
|
|
148
|
-
}
|
|
149
|
-
return void 0;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
// src/services/lookup-consumer.ts
|
|
153
|
-
var LookupConsumer = async ({ product, consumer }) => {
|
|
154
|
-
const tenant_id = Cookies.get("tenant_id");
|
|
155
|
-
if (!tenant_id) {
|
|
156
|
-
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
157
|
-
}
|
|
158
|
-
if (!consumer || !consumer.holderId) {
|
|
159
|
-
throw new Error(`Consumer holderId information is required`);
|
|
160
|
-
}
|
|
161
|
-
if (!product) {
|
|
162
|
-
throw new Error(`Product information is required`);
|
|
163
|
-
}
|
|
164
|
-
const product_payload = {
|
|
165
|
-
id: product.id,
|
|
166
|
-
ean: product.ean,
|
|
167
|
-
requestedQuantity: product.requestedQuantity,
|
|
168
|
-
listPrice: product.listPrice,
|
|
169
|
-
netPrice: product.netPrice
|
|
170
|
-
};
|
|
171
|
-
try {
|
|
172
|
-
const response = await fetch(
|
|
173
|
-
`${getEnv("VITE_API_URL")}/api/lookup-consumer.ts`,
|
|
174
|
-
{
|
|
175
|
-
method: "POST",
|
|
176
|
-
headers: {
|
|
177
|
-
"Content-Type": "application/json",
|
|
178
|
-
"Accept": "application/json",
|
|
179
|
-
"Authorization": `Bearer ${Cookies.get("pbm-token")}`
|
|
180
|
-
},
|
|
181
|
-
body: JSON.stringify({
|
|
182
|
-
tenant_id,
|
|
183
|
-
product: product_payload,
|
|
184
|
-
table_id: Cookies.get("current-table-id"),
|
|
185
|
-
local_hour: Cookies.get("current-local-hour"),
|
|
186
|
-
consumer
|
|
187
|
-
})
|
|
188
|
-
}
|
|
189
|
-
);
|
|
190
|
-
const data = await response.json();
|
|
191
|
-
if (!data.success) {
|
|
192
|
-
throw new Error("PBMLOG: Enable Discount Failed!");
|
|
193
|
-
}
|
|
194
|
-
return data;
|
|
195
|
-
} catch (error) {
|
|
196
|
-
console.error("Error during enable discount:", error);
|
|
197
|
-
return { success: false, error: "Authorization failed" };
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
// src/components/Form/index.tsx
|
|
202
|
-
import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
|
|
203
|
-
function Form({ startTransition }) {
|
|
204
|
-
const store = usePBMStore();
|
|
205
|
-
const [showCardIDField, setShowCardIDField] = useState(false);
|
|
206
|
-
const { setModal } = useModal();
|
|
207
|
-
const {
|
|
208
|
-
handleSubmit,
|
|
209
|
-
register,
|
|
210
|
-
setValue,
|
|
211
|
-
clearErrors,
|
|
212
|
-
unregister,
|
|
213
|
-
formState: { errors }
|
|
214
|
-
} = useForm({
|
|
215
|
-
resolver: zodResolver(validationSchema),
|
|
216
|
-
mode: "onSubmit",
|
|
217
|
-
defaultValues: {
|
|
218
|
-
securityNumber: store.securityNumber || "",
|
|
219
|
-
coupon: ""
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
const checkSecurityNumber = async (values) => {
|
|
223
|
-
if (store.targetProduct === null) {
|
|
224
|
-
console.error("PBMLOG: Product is not defined!");
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
if (!store.targetProduct.id) {
|
|
228
|
-
console.error("PBMLOG: Product ID is not defined!");
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
if (!store.targetProduct.listPrice) {
|
|
232
|
-
console.error("PBMLOG: List Price is not defined!");
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
store.setSecurityNumber(values.securityNumber.replace(/\D/g, ""));
|
|
236
|
-
const consumerHasDiscountEnabled = await LookupConsumer({
|
|
237
|
-
product: store.targetProduct,
|
|
238
|
-
consumer: { holderId: values.securityNumber.replace(/\D/g, "") }
|
|
239
|
-
});
|
|
240
|
-
if (!consumerHasDiscountEnabled.success) {
|
|
241
|
-
setModal({
|
|
242
|
-
id: "CustomerNotRegistered",
|
|
243
|
-
open: true
|
|
244
|
-
});
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
store.setBenefitsList(consumerHasDiscountEnabled.product);
|
|
248
|
-
store.setState("isActivated");
|
|
249
|
-
};
|
|
250
|
-
const onSubmitDefault = async (values) => {
|
|
251
|
-
if (!store.isAuthenticatedShopper) {
|
|
252
|
-
setModal({ id: "ShopperIsNotAuthenticated", open: true });
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
if (!showCardIDField) {
|
|
256
|
-
setValue("coupon", void 0, { shouldValidate: false });
|
|
257
|
-
}
|
|
258
|
-
if (showCardIDField && values.coupon != void 0) {
|
|
259
|
-
store.setCardID(values.coupon);
|
|
260
|
-
}
|
|
261
|
-
startTransition(async () => {
|
|
262
|
-
await checkSecurityNumber(values);
|
|
263
|
-
});
|
|
264
|
-
};
|
|
265
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
266
|
-
/* @__PURE__ */ jsxs(
|
|
267
|
-
"form",
|
|
268
|
-
{
|
|
269
|
-
onSubmit: handleSubmit(onSubmitDefault),
|
|
270
|
-
className: classNames2(
|
|
271
|
-
"w-full h-auto flex items-start justify-center flex-col mb-2 transition-all duration-150"
|
|
272
|
-
),
|
|
273
|
-
id: "form_security_number_pbm",
|
|
274
|
-
children: [
|
|
275
|
-
/* @__PURE__ */ jsxs(
|
|
276
|
-
"label",
|
|
277
|
-
{
|
|
278
|
-
htmlFor: "input_security_number_pbm",
|
|
279
|
-
className: classNames2(
|
|
280
|
-
"w-full h-auto flex items-start flex-col justify-center relative py-2 transition-all duration-100",
|
|
281
|
-
{
|
|
282
|
-
"mb-4": errors.securityNumber && !showCardIDField
|
|
283
|
-
}
|
|
284
|
-
),
|
|
285
|
-
id: "label_security_number_pbm",
|
|
286
|
-
children: [
|
|
287
|
-
/* @__PURE__ */ jsx2(
|
|
288
|
-
"input",
|
|
289
|
-
{
|
|
290
|
-
type: "text",
|
|
291
|
-
className: classNames2(
|
|
292
|
-
"w-full h-10 bg-(--pbm-input-background) rounded-lg text-sm font-semibold outline-(--pbm-outline-color) focus:outline focus:bg-(--pbm-input-focus) focus:outline-(--pbm-outline-focus-color) text-zinc-600 placeholder:text-zinc-600 px-4 placeholder:text-sm placeholder:font-semibold",
|
|
293
|
-
{
|
|
294
|
-
"outline outline-red-600": errors.securityNumber,
|
|
295
|
-
"rounded-lg": showCardIDField
|
|
296
|
-
}
|
|
297
|
-
),
|
|
298
|
-
style: {
|
|
299
|
-
"--tw-outline-color": !errors.securityNumber ? "var(--pbm-secondary)" : void 0
|
|
300
|
-
},
|
|
301
|
-
placeholder: "Digite seu CPF aqui...",
|
|
302
|
-
required: true,
|
|
303
|
-
maxLength: 14,
|
|
304
|
-
...register("securityNumber", {
|
|
305
|
-
onChange: (e) => {
|
|
306
|
-
const formatted = formaters.cpf(e.target.value);
|
|
307
|
-
setValue("securityNumber", formatted, {
|
|
308
|
-
shouldValidate: true
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
}),
|
|
312
|
-
defaultValue: store.securityNumber || "",
|
|
313
|
-
id: "input_security_number_pbm"
|
|
314
|
-
}
|
|
315
|
-
),
|
|
316
|
-
errors.securityNumber && /* @__PURE__ */ jsx2(
|
|
317
|
-
"span",
|
|
318
|
-
{
|
|
319
|
-
className: "text-red-400 text-xs font-semibold absolute -bottom-3 left-2 text-nowrap",
|
|
320
|
-
id: "security_number_form_error",
|
|
321
|
-
children: errors.securityNumber.message
|
|
322
|
-
}
|
|
323
|
-
)
|
|
324
|
-
]
|
|
325
|
-
}
|
|
326
|
-
),
|
|
327
|
-
/* @__PURE__ */ jsx2(Activity, { mode: showCardIDField ? "visible" : "hidden", children: /* @__PURE__ */ jsxs(
|
|
328
|
-
"label",
|
|
329
|
-
{
|
|
330
|
-
htmlFor: "input_coupon_pbm",
|
|
331
|
-
className: classNames2(
|
|
332
|
-
"w-full h-auto flex items-start flex-col justify-center relative py-2",
|
|
333
|
-
{
|
|
334
|
-
"mt-2": errors.securityNumber
|
|
335
|
-
}
|
|
336
|
-
),
|
|
337
|
-
id: "label_coupon_pbm",
|
|
338
|
-
children: [
|
|
339
|
-
/* @__PURE__ */ jsx2(
|
|
340
|
-
"input",
|
|
341
|
-
{
|
|
342
|
-
type: "text",
|
|
343
|
-
className: classNames2(
|
|
344
|
-
"w-full h-10 bg-gray-100 rounded-s-lg text-sm font-semibold focus:outline focus:bg-white text-zinc-600 placeholder:text-zinc-600 px-4 placeholder:text-sm placeholder:font-semibold",
|
|
345
|
-
{
|
|
346
|
-
"outline outline-red-600": errors.coupon,
|
|
347
|
-
"rounded-lg": showCardIDField
|
|
348
|
-
}
|
|
349
|
-
),
|
|
350
|
-
style: {
|
|
351
|
-
"--tw-outline-color": !errors.coupon ? "var(--pbm-secondary)" : void 0
|
|
352
|
-
},
|
|
353
|
-
placeholder: "Cupom / ID do Cart\xE3o",
|
|
354
|
-
...register("coupon", {
|
|
355
|
-
required: showCardIDField ? "Cupom / ID do Cart\xE3o obrigat\xF3rio." : false,
|
|
356
|
-
shouldUnregister: !showCardIDField,
|
|
357
|
-
onChange: (e) => {
|
|
358
|
-
setValue("coupon", e.target.value, {
|
|
359
|
-
shouldValidate: showCardIDField
|
|
360
|
-
});
|
|
361
|
-
}
|
|
362
|
-
}),
|
|
363
|
-
id: "input_coupon_pbm"
|
|
364
|
-
}
|
|
365
|
-
),
|
|
366
|
-
errors.coupon && /* @__PURE__ */ jsx2(
|
|
367
|
-
"span",
|
|
368
|
-
{
|
|
369
|
-
className: "text-red-400 text-xs font-semibold absolute -bottom-3 left-2 text-nowrap",
|
|
370
|
-
id: "coupon_form_error",
|
|
371
|
-
children: errors.coupon.message
|
|
372
|
-
}
|
|
373
|
-
)
|
|
374
|
-
]
|
|
375
|
-
}
|
|
376
|
-
) }),
|
|
377
|
-
/* @__PURE__ */ jsx2(
|
|
378
|
-
"button",
|
|
379
|
-
{
|
|
380
|
-
type: "submit",
|
|
381
|
-
className: classNames2(
|
|
382
|
-
"w-full h-10 rounded-lg flex items-center justify-center cursor-pointer text-sm text-white font-semibold transition-all duration-150",
|
|
383
|
-
{
|
|
384
|
-
"rounded-lg": showCardIDField
|
|
385
|
-
}
|
|
386
|
-
),
|
|
387
|
-
style: { backgroundColor: "var(--pbm-primary)" },
|
|
388
|
-
id: "button_submit_security_number_pbm",
|
|
389
|
-
children: "Comprar com desconto"
|
|
390
|
-
}
|
|
391
|
-
)
|
|
392
|
-
]
|
|
393
|
-
}
|
|
394
|
-
),
|
|
395
|
-
/* @__PURE__ */ jsxs("section", { className: "flex items-start flex-col gap-2", children: [
|
|
396
|
-
/* @__PURE__ */ jsxs(
|
|
397
|
-
Button_default,
|
|
398
|
-
{
|
|
399
|
-
className: "bg-transparent p-0 pl-2 w-auto h-auto underline cursor-pointer hover:bg-transparent flex items-center justify-start gap-1",
|
|
400
|
-
style: { color: "var(--pbm-text)" },
|
|
401
|
-
onMouseOver: (e) => e.currentTarget.style.filter = "brightness(0.8)",
|
|
402
|
-
onMouseOut: (e) => e.currentTarget.style.filter = "none",
|
|
403
|
-
onClick: () => {
|
|
404
|
-
const newValue = !showCardIDField;
|
|
405
|
-
setShowCardIDField(newValue);
|
|
406
|
-
if (!newValue) {
|
|
407
|
-
unregister("coupon");
|
|
408
|
-
clearErrors("coupon");
|
|
409
|
-
}
|
|
410
|
-
},
|
|
411
|
-
id: "check_benefits_button",
|
|
412
|
-
children: [
|
|
413
|
-
/* @__PURE__ */ jsx2("span", { className: "text-start", children: !showCardIDField ? "Possui Cupom / ID do Cart\xE3o?" : "N\xE3o possui Cupom / ID do Cart\xE3o?" }),
|
|
414
|
-
/* @__PURE__ */ jsx2(
|
|
415
|
-
ArrowRight,
|
|
416
|
-
{
|
|
417
|
-
size: 16,
|
|
418
|
-
className: classNames2({
|
|
419
|
-
"rotate-0": !showCardIDField,
|
|
420
|
-
"rotate-180": showCardIDField
|
|
421
|
-
})
|
|
422
|
-
}
|
|
423
|
-
)
|
|
424
|
-
]
|
|
425
|
-
}
|
|
426
|
-
),
|
|
427
|
-
/* @__PURE__ */ jsxs(
|
|
428
|
-
Button_default,
|
|
429
|
-
{
|
|
430
|
-
className: "bg-transparent p-0 pl-2 w-auto h-auto underline cursor-pointer hover:bg-transparent flex items-center justify-start gap-1",
|
|
431
|
-
style: { color: "var(--pbm-text)" },
|
|
432
|
-
onMouseOver: (e) => e.currentTarget.style.filter = "brightness(0.8)",
|
|
433
|
-
onMouseOut: (e) => e.currentTarget.style.filter = "none",
|
|
434
|
-
onClick: () => store.setState("isPreview"),
|
|
435
|
-
id: "check_benefits_button",
|
|
436
|
-
children: [
|
|
437
|
-
/* @__PURE__ */ jsx2("span", { children: "Consultar Benef\xEDcios" }),
|
|
438
|
-
/* @__PURE__ */ jsx2(ArrowRight, { size: 16 })
|
|
439
|
-
]
|
|
440
|
-
}
|
|
441
|
-
)
|
|
442
|
-
] })
|
|
443
|
-
] });
|
|
444
|
-
}
|
|
445
|
-
var Form_default = Form;
|
|
446
|
-
|
|
447
|
-
// src/components/UI/Icons/index.tsx
|
|
448
|
-
import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
449
|
-
function CheckON({ size }) {
|
|
450
|
-
return /* @__PURE__ */ jsx3(
|
|
451
|
-
"svg",
|
|
452
|
-
{
|
|
453
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
454
|
-
"data-name": "Camada 1",
|
|
455
|
-
viewBox: "0 0 500 500",
|
|
456
|
-
width: size,
|
|
457
|
-
height: size,
|
|
458
|
-
children: /* @__PURE__ */ jsx3(
|
|
459
|
-
"path",
|
|
460
|
-
{
|
|
461
|
-
d: "M421.44 78.56C375.64 32.77 314.76 7.55 250 7.55S124.36 32.77 78.56 78.56C32.77 124.36 7.55 185.24 7.55 250s25.22 125.64 71.01 171.44c45.8 45.79 106.68 71.01 171.44 71.01s125.64-25.22 171.44-71.01c45.79-45.8 71.01-106.68 71.01-171.44s-25.22-125.64-71.01-171.44zm-49.17 121.7L242.88 334.63c-8.98 9.29-23.57 10.17-33.59 2.02l-79.63-64.7c-10.69-8.67-12.33-24.38-3.66-35.07 8.67-10.69 24.38-12.33 35.07-3.65l61.9 50.39L336.5 165.74c4.4-4.75 10.48-7.59 16.95-7.93a24.88 24.88 0 0118.83 7.26c9.72 9.72 9.71 25.48 0 35.19z",
|
|
462
|
-
fill: "#229b00"
|
|
463
|
-
}
|
|
464
|
-
)
|
|
465
|
-
}
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
function CheckOFF({ size }) {
|
|
469
|
-
return /* @__PURE__ */ jsxs2(
|
|
470
|
-
"svg",
|
|
471
|
-
{
|
|
472
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
473
|
-
"data-name": "Camada 1",
|
|
474
|
-
viewBox: "0 0 500 500",
|
|
475
|
-
width: size,
|
|
476
|
-
height: size,
|
|
477
|
-
children: [
|
|
478
|
-
/* @__PURE__ */ jsx3("circle", { cx: 250, cy: 250, r: 237.45, fill: "#fff" }),
|
|
479
|
-
/* @__PURE__ */ jsx3(
|
|
480
|
-
"path",
|
|
481
|
-
{
|
|
482
|
-
d: "M250 492.45c-64.76 0-125.64-25.22-171.44-71.01C32.77 375.64 7.55 314.76 7.55 250S32.77 124.36 78.56 78.56C124.36 32.77 185.24 7.55 250 7.55s125.64 25.22 171.44 71.01c45.79 45.79 71.01 106.68 71.01 171.44s-25.22 125.64-71.01 171.44c-45.79 45.79-106.68 71.01-171.44 71.01zm0-474.9C121.83 17.55 17.55 121.83 17.55 250S121.83 482.45 250 482.45 482.45 378.17 482.45 250 378.17 17.55 250 17.55z",
|
|
483
|
-
fill: "#d8d8d8"
|
|
484
|
-
}
|
|
485
|
-
)
|
|
486
|
-
]
|
|
487
|
-
}
|
|
488
|
-
);
|
|
489
|
-
}
|
|
490
|
-
function Pills({ size, color }) {
|
|
491
|
-
return /* @__PURE__ */ jsxs2(
|
|
492
|
-
"svg",
|
|
493
|
-
{
|
|
494
|
-
viewBox: "-0.003 0 99.979 99.979",
|
|
495
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
496
|
-
fill: "#000000",
|
|
497
|
-
width: size,
|
|
498
|
-
height: size,
|
|
499
|
-
children: [
|
|
500
|
-
/* @__PURE__ */ jsx3("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0" }),
|
|
501
|
-
/* @__PURE__ */ jsx3(
|
|
502
|
-
"g",
|
|
503
|
-
{
|
|
504
|
-
id: "SVGRepo_tracerCarrier",
|
|
505
|
-
strokeLinecap: "round",
|
|
506
|
-
strokeLinejoin: "round"
|
|
507
|
-
}
|
|
508
|
-
),
|
|
509
|
-
/* @__PURE__ */ jsxs2("g", { id: "SVGRepo_iconCarrier", children: [
|
|
510
|
-
/* @__PURE__ */ jsx3(
|
|
511
|
-
"path",
|
|
512
|
-
{
|
|
513
|
-
fill: "#ffe700",
|
|
514
|
-
d: "M92.869 7.105c9.478 9.476 9.478 24.832 0 34.308L41.411 92.869c-9.475 9.474-24.833 9.474-34.307 0-9.476-9.475-9.476-24.832 0-34.308L58.562 7.105c9.475-9.473 24.834-9.473 34.307 0z"
|
|
515
|
-
}
|
|
516
|
-
),
|
|
517
|
-
/* @__PURE__ */ jsx3(
|
|
518
|
-
"path",
|
|
519
|
-
{
|
|
520
|
-
fill: color,
|
|
521
|
-
d: "M32.548 33.122L7.105 58.563c-9.476 9.476-9.476 24.833 0 34.308 9.474 9.475 24.832 9.475 34.307 0L66.85 67.43 32.548 33.122z"
|
|
522
|
-
}
|
|
523
|
-
),
|
|
524
|
-
/* @__PURE__ */ jsx3(
|
|
525
|
-
"path",
|
|
526
|
-
{
|
|
527
|
-
fill: color,
|
|
528
|
-
d: "M65.43 68.862L31.134 34.568l1.414-1.414 34.294 34.294z"
|
|
529
|
-
}
|
|
530
|
-
),
|
|
531
|
-
/* @__PURE__ */ jsx3(
|
|
532
|
-
"path",
|
|
533
|
-
{
|
|
534
|
-
fill: color,
|
|
535
|
-
d: "M38.096 41.51L12.7 66.906a5.894 5.894 0 0 0 0 8.339 5.896 5.896 0 0 0 8.339 0l25.396-25.396-8.339-8.339z"
|
|
536
|
-
}
|
|
537
|
-
),
|
|
538
|
-
/* @__PURE__ */ jsx3(
|
|
539
|
-
"path",
|
|
540
|
-
{
|
|
541
|
-
fill: "#ffe700",
|
|
542
|
-
d: "M75.244 12.7a5.897 5.897 0 0 0-8.343 0L39.51 40.096l8.339 8.339 27.396-27.396a5.899 5.899 0 0 0-.001-8.339z"
|
|
543
|
-
}
|
|
544
|
-
),
|
|
545
|
-
/* @__PURE__ */ jsx3(
|
|
546
|
-
"path",
|
|
547
|
-
{
|
|
548
|
-
fill: color,
|
|
549
|
-
d: "M47.862 48.444l-1.414 1.414-8.335-8.336 1.414-1.414z"
|
|
550
|
-
}
|
|
551
|
-
)
|
|
552
|
-
] })
|
|
553
|
-
]
|
|
554
|
-
}
|
|
555
|
-
);
|
|
556
|
-
}
|
|
557
|
-
function ArrowDown({ size, color }) {
|
|
558
|
-
return /* @__PURE__ */ jsxs2(
|
|
559
|
-
"svg",
|
|
560
|
-
{
|
|
561
|
-
viewBox: "0 0 24 24",
|
|
562
|
-
fill: "none",
|
|
563
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
564
|
-
width: size,
|
|
565
|
-
height: size,
|
|
566
|
-
children: [
|
|
567
|
-
/* @__PURE__ */ jsx3("g", { id: "SVGRepo_bgCarrier", strokeWidth: "0" }),
|
|
568
|
-
/* @__PURE__ */ jsx3(
|
|
569
|
-
"g",
|
|
570
|
-
{
|
|
571
|
-
id: "SVGRepo_tracerCarrier",
|
|
572
|
-
strokeLinecap: "round",
|
|
573
|
-
strokeLinejoin: "round"
|
|
574
|
-
}
|
|
575
|
-
),
|
|
576
|
-
/* @__PURE__ */ jsx3("g", { id: "SVGRepo_iconCarrier", children: /* @__PURE__ */ jsx3(
|
|
577
|
-
"path",
|
|
578
|
-
{
|
|
579
|
-
d: "M7.33199 16.3154C6.94146 15.9248 6.3083 15.9248 5.91777 16.3154C5.52725 16.7059 5.52725 17.339 5.91777 17.7296L10.5834 22.3952C11.3644 23.1762 12.6308 23.1762 13.4118 22.3952L18.0802 17.7267C18.4707 17.3362 18.4707 16.703 18.0802 16.3125C17.6897 15.922 17.0565 15.922 16.666 16.3125L13 19.9786V2.0001C13 1.44781 12.5523 1.0001 12 1.0001C11.4477 1.0001 11 1.44781 11 2.0001V19.9833L7.33199 16.3154Z",
|
|
580
|
-
fill: color
|
|
581
|
-
}
|
|
582
|
-
) })
|
|
583
|
-
]
|
|
584
|
-
}
|
|
585
|
-
);
|
|
586
|
-
}
|
|
587
|
-
var Icons = {
|
|
588
|
-
CheckON,
|
|
589
|
-
CheckOFF,
|
|
590
|
-
Pills,
|
|
591
|
-
ArrowDown
|
|
592
|
-
};
|
|
593
|
-
|
|
594
|
-
// src/components/Header/index.tsx
|
|
595
|
-
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
596
|
-
function Header() {
|
|
597
|
-
const { targetProduct, benefitsEnabled, setBenefitsEnabled } = usePBMStore();
|
|
598
|
-
const Price = formaters.transformPrice(Number(targetProduct?.listPrice));
|
|
599
|
-
const DiscountValue = formaters.transformPrice(
|
|
600
|
-
Number(targetProduct?.discountValue) || 0
|
|
601
|
-
);
|
|
602
|
-
const DiscountPercentual = formaters.transformPorcent(
|
|
603
|
-
targetProduct?.discountPercentual || "0"
|
|
604
|
-
);
|
|
605
|
-
const DiscountPercentualValue = Price * DiscountPercentual / 100;
|
|
606
|
-
const DiscountApplied = Price - DiscountValue || Price - DiscountPercentualValue;
|
|
607
|
-
return /* @__PURE__ */ jsxs3(
|
|
608
|
-
"header",
|
|
609
|
-
{
|
|
610
|
-
className: "flex items-start justify-start flex-col gap-4 w-full p-0.5 rounded-xl mt-5",
|
|
611
|
-
id: "header_pbm",
|
|
612
|
-
children: [
|
|
613
|
-
/* @__PURE__ */ jsxs3(
|
|
614
|
-
"label",
|
|
615
|
-
{
|
|
616
|
-
className: "flex items-center gap-2 cursor-pointer",
|
|
617
|
-
htmlFor: "enable_benefits_checkbox",
|
|
618
|
-
children: [
|
|
619
|
-
/* @__PURE__ */ jsx4(
|
|
620
|
-
"input",
|
|
621
|
-
{
|
|
622
|
-
id: "enable_benefits_checkbox",
|
|
623
|
-
type: "checkbox",
|
|
624
|
-
name: "option",
|
|
625
|
-
className: "peer hidden",
|
|
626
|
-
checked: benefitsEnabled,
|
|
627
|
-
onChange: (e) => setBenefitsEnabled(e.target.checked)
|
|
628
|
-
}
|
|
629
|
-
),
|
|
630
|
-
/* @__PURE__ */ jsx4("div", { className: "w-5 h-5 border border-(--pbm-primary) rounded-full flex items-center justify-center transition-all duration-300 after:content-[''] after:w-2 after:h-2 after:rounded-full after:bg-(--pbm-primary) after:scale-0 after:transition-transform after:duration-200 peer-checked:after:scale-100" }),
|
|
631
|
-
/* @__PURE__ */ jsx4("p", { className: "font-medium text-(--pbm-primary) select-none text-sm", children: "Desconto de Laborat\xF3rio" }),
|
|
632
|
-
/* @__PURE__ */ jsx4(Icons.Pills, { size: 16, color: "var(--pbm-primary)" })
|
|
633
|
-
]
|
|
634
|
-
}
|
|
635
|
-
),
|
|
636
|
-
/* @__PURE__ */ jsx4(
|
|
637
|
-
"span",
|
|
638
|
-
{
|
|
639
|
-
className: "py-1 rounded-xl shrink-0 text-white text-xl font-bold flex items-center justify-start gap-2 relative",
|
|
640
|
-
"data-testid": "test_id_header_price",
|
|
641
|
-
id: "header_price",
|
|
642
|
-
children: /* @__PURE__ */ jsxs3("section", { className: "flex items-start gap-2 justify-center-safe flex-col", children: [
|
|
643
|
-
/* @__PURE__ */ jsxs3("div", { className: "flex items-center-safe justify-start gap-1", children: [
|
|
644
|
-
/* @__PURE__ */ jsx4("span", { className: "line-through text-sm font-light text-zinc-600", children: Number(Price)?.toLocaleString("pt-BR", {
|
|
645
|
-
currency: "BRL",
|
|
646
|
-
currencyDisplay: "symbol",
|
|
647
|
-
currencySign: "standard",
|
|
648
|
-
style: "currency"
|
|
649
|
-
}) }),
|
|
650
|
-
/* @__PURE__ */ jsx4(Icons.ArrowDown, { size: 14, color: "var(--pbm-primary)" }),
|
|
651
|
-
/* @__PURE__ */ jsxs3("span", { className: "font-semibold text-sm text-(--pbm-primary)", children: [
|
|
652
|
-
DiscountPercentual.toFixed(2),
|
|
653
|
-
"%"
|
|
654
|
-
] })
|
|
655
|
-
] }),
|
|
656
|
-
/* @__PURE__ */ jsx4("span", { className: "text-lg text-zinc-700 font-bold", children: DiscountApplied?.toLocaleString("pt-BR", {
|
|
657
|
-
currency: "BRL",
|
|
658
|
-
currencyDisplay: "symbol",
|
|
659
|
-
currencySign: "standard",
|
|
660
|
-
style: "currency"
|
|
661
|
-
}) }),
|
|
662
|
-
targetProduct?.informativeMessage && /* @__PURE__ */ jsx4("span", { className: "text-xs text-zinc-600 font-medium", children: targetProduct?.informativeMessage })
|
|
663
|
-
] })
|
|
664
|
-
}
|
|
665
|
-
)
|
|
666
|
-
]
|
|
667
|
-
}
|
|
668
|
-
);
|
|
669
|
-
}
|
|
670
|
-
var Header_default = Header;
|
|
671
|
-
|
|
672
|
-
// src/components/UI/Loading/index.tsx
|
|
673
|
-
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
674
|
-
function Loading({ textColor }) {
|
|
675
|
-
return /* @__PURE__ */ jsxs4("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
|
|
676
|
-
/* @__PURE__ */ jsx5(
|
|
677
|
-
"div",
|
|
678
|
-
{
|
|
679
|
-
"data-testid": "test_id_spin",
|
|
680
|
-
className: "w-8 h-8 border-4 shrink-0 border-gray-300 rounded-full animate-spin",
|
|
681
|
-
style: { borderTopColor: "var(--pbm-secondary)" },
|
|
682
|
-
id: "loading_spin"
|
|
683
|
-
}
|
|
684
|
-
),
|
|
685
|
-
/* @__PURE__ */ jsx5(
|
|
686
|
-
"p",
|
|
687
|
-
{
|
|
688
|
-
className: "text-sm font-semibold text-start",
|
|
689
|
-
style: { color: textColor || "var(--pbm-text)" },
|
|
690
|
-
id: "loading_label",
|
|
691
|
-
children: "Um momento... estamos verificando seus dados."
|
|
692
|
-
}
|
|
693
|
-
)
|
|
694
|
-
] });
|
|
695
|
-
}
|
|
696
|
-
var Loading_default = Loading;
|
|
697
|
-
|
|
698
|
-
// src/components/UI/Container/index.tsx
|
|
699
|
-
import classNames3 from "classnames";
|
|
700
|
-
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
701
|
-
function Container({
|
|
702
|
-
children,
|
|
703
|
-
variant
|
|
704
|
-
}) {
|
|
705
|
-
const { benefitsEnabled } = usePBMStore();
|
|
706
|
-
return /* @__PURE__ */ jsx6(
|
|
707
|
-
"main",
|
|
708
|
-
{
|
|
709
|
-
className: classNames3({
|
|
710
|
-
"border-3 border-(--pbm-border) overflow-hidden flex flex-col items-center justify-center min-w-(--min-container) max-w-(--max-container) w-full h-auto rounded-xl p-4 bg-white gap-4 relative": variant === "main",
|
|
711
|
-
"w-full relative": variant === "simple",
|
|
712
|
-
"h-0 overflow-hidden": !benefitsEnabled && variant === "simple"
|
|
713
|
-
}),
|
|
714
|
-
"data-testid": "test_id_container",
|
|
715
|
-
"data-variant": variant,
|
|
716
|
-
id: "container_pbm",
|
|
717
|
-
children
|
|
718
|
-
}
|
|
719
|
-
);
|
|
720
|
-
}
|
|
721
|
-
var Container_default = Container;
|
|
722
|
-
|
|
723
|
-
// src/components/UI/Title/index.tsx
|
|
724
|
-
import classNames4 from "classnames";
|
|
725
|
-
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
726
|
-
function Title(props) {
|
|
727
|
-
return /* @__PURE__ */ jsx7(
|
|
728
|
-
"h2",
|
|
729
|
-
{
|
|
730
|
-
className: classNames4(
|
|
731
|
-
"text-start font-semibold text-sm",
|
|
732
|
-
props.className
|
|
733
|
-
),
|
|
734
|
-
style: { color: props.textColor || "var(--pbm-text)", fontSize: props.textSize, textAlign: props.textAlign },
|
|
735
|
-
"data-testid": "test_id_title",
|
|
736
|
-
id: "title_pbm",
|
|
737
|
-
children: props.children
|
|
738
|
-
}
|
|
739
|
-
);
|
|
740
|
-
}
|
|
741
|
-
var Title_default = Title;
|
|
742
|
-
|
|
743
|
-
// src/components/BenefitsTable/index.tsx
|
|
744
|
-
import { useState as useState2 } from "react";
|
|
745
|
-
|
|
746
|
-
// src/components/BenefitsTable/Item.tsx
|
|
747
|
-
import { useCallback, useEffect } from "react";
|
|
748
|
-
import classNames5 from "classnames";
|
|
749
|
-
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
750
|
-
function Item({ data, onChange, checked }) {
|
|
751
|
-
const { setAvailableDiscountSelected, state, isAuthenticatedShopper } = usePBMStore();
|
|
752
|
-
const { setModal } = useModal();
|
|
753
|
-
const ID_INPUT = data.id + "_" + data.requestedQuantity;
|
|
754
|
-
const PricePerUnity = formaters.transformPrice(
|
|
755
|
-
Number(data?.grossPrice) || Number(data?.listPrice) || 0
|
|
756
|
-
);
|
|
757
|
-
const DiscountValuePerUnity = formaters.transformPrice(
|
|
758
|
-
Number(data?.discountValue) || 0
|
|
759
|
-
);
|
|
760
|
-
const DiscountPercentual = formaters.transformPorcent(
|
|
761
|
-
data?.discountPercentual || "0"
|
|
762
|
-
);
|
|
763
|
-
const TotalDiscountValue = DiscountValuePerUnity * Number(data.requestedQuantity);
|
|
764
|
-
const TotalPricePerQuantity = PricePerUnity * Number(data.requestedQuantity);
|
|
765
|
-
const DiscountPercentualValue = TotalPricePerQuantity * DiscountPercentual / 100;
|
|
766
|
-
const AppliedDiscount = TotalPricePerQuantity - TotalDiscountValue || TotalPricePerQuantity - DiscountPercentualValue;
|
|
767
|
-
const updateStorageData = useCallback(() => {
|
|
768
|
-
if (checked) {
|
|
769
|
-
const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
|
|
770
|
-
setAvailableDiscountSelected({
|
|
771
|
-
discount: {
|
|
772
|
-
total: roundToTwoDecimals(TotalDiscountValue),
|
|
773
|
-
unit: roundToTwoDecimals(DiscountValuePerUnity)
|
|
774
|
-
},
|
|
775
|
-
quantity: Number(data.requestedQuantity),
|
|
776
|
-
totalPrice: roundToTwoDecimals(AppliedDiscount),
|
|
777
|
-
grossPrice: data.grossPrice
|
|
778
|
-
});
|
|
779
|
-
}
|
|
780
|
-
}, [
|
|
781
|
-
checked,
|
|
782
|
-
data.requestedQuantity,
|
|
783
|
-
data.grossPrice,
|
|
784
|
-
setAvailableDiscountSelected,
|
|
785
|
-
TotalDiscountValue,
|
|
786
|
-
DiscountValuePerUnity,
|
|
787
|
-
AppliedDiscount
|
|
788
|
-
]);
|
|
789
|
-
useEffect(() => {
|
|
790
|
-
updateStorageData();
|
|
791
|
-
}, [updateStorageData]);
|
|
792
|
-
const handleChange = () => {
|
|
793
|
-
if (!isAuthenticatedShopper && state === "isActivated") {
|
|
794
|
-
setModal({
|
|
795
|
-
id: "ShopperIsNotAuthenticated",
|
|
796
|
-
open: true
|
|
797
|
-
});
|
|
798
|
-
return;
|
|
799
|
-
}
|
|
800
|
-
onChange();
|
|
801
|
-
};
|
|
802
|
-
return /* @__PURE__ */ jsxs5(
|
|
803
|
-
"label",
|
|
804
|
-
{
|
|
805
|
-
htmlFor: ID_INPUT,
|
|
806
|
-
className: classNames5(
|
|
807
|
-
"label_benefits w-full flex items-center justify-start bg-zinc-300/60 border border-zinc-400/50 px-4 py-2 transition-colors rounded-lg gap-1",
|
|
808
|
-
{
|
|
809
|
-
"cursor-not-allowed": state === "isPreview",
|
|
810
|
-
"cursor-pointer": state === "isActivated"
|
|
811
|
-
}
|
|
812
|
-
),
|
|
813
|
-
style: {
|
|
814
|
-
borderColor: checked ? "var(--pbm-primary)" : void 0,
|
|
815
|
-
backgroundColor: checked ? "color-mix(in srgb, var(--pbm-primary), transparent 90%)" : void 0
|
|
816
|
-
},
|
|
817
|
-
id: "label_benefits_" + ID_INPUT,
|
|
818
|
-
children: [
|
|
819
|
-
/* @__PURE__ */ jsx8(
|
|
820
|
-
"input",
|
|
821
|
-
{
|
|
822
|
-
type: "radio",
|
|
823
|
-
name: "benefits_discount",
|
|
824
|
-
id: ID_INPUT,
|
|
825
|
-
className: "hidden",
|
|
826
|
-
checked,
|
|
827
|
-
onChange: handleChange,
|
|
828
|
-
disabled: state === "isPreview"
|
|
829
|
-
}
|
|
830
|
-
),
|
|
831
|
-
/* @__PURE__ */ jsx8("span", { style: { color: "var(--pbm-primary)" }, children: !checked ? /* @__PURE__ */ jsx8(Icons.CheckOFF, { size: 20 }) : /* @__PURE__ */ jsx8(Icons.CheckON, { size: 20 }) }),
|
|
832
|
-
/* @__PURE__ */ jsxs5(
|
|
833
|
-
"span",
|
|
834
|
-
{
|
|
835
|
-
className: "font-semibold text-sm",
|
|
836
|
-
style: { color: "var(--pbm-text)" },
|
|
837
|
-
children: [
|
|
838
|
-
data.requestedQuantity,
|
|
839
|
-
"un"
|
|
840
|
-
]
|
|
841
|
-
}
|
|
842
|
-
),
|
|
843
|
-
/* @__PURE__ */ jsxs5("section", { className: "ml-auto relative gap-2 flex items-center-safe justify-end-safe", children: [
|
|
844
|
-
/* @__PURE__ */ jsxs5(
|
|
845
|
-
"span",
|
|
846
|
-
{
|
|
847
|
-
className: "text-white -top-4 py-0.5 font-semibold text-xs px-2 w-auto text-nowrap rounded-2xl -right-3",
|
|
848
|
-
style: { backgroundColor: "var(--pbm-primary)" },
|
|
849
|
-
children: [
|
|
850
|
-
TotalDiscountValue.toLocaleString("pt-BR", {
|
|
851
|
-
currency: "BRL",
|
|
852
|
-
currencyDisplay: "symbol",
|
|
853
|
-
currencySign: "standard",
|
|
854
|
-
style: "currency"
|
|
855
|
-
}),
|
|
856
|
-
" ",
|
|
857
|
-
"OFF"
|
|
858
|
-
]
|
|
859
|
-
}
|
|
860
|
-
),
|
|
861
|
-
/* @__PURE__ */ jsx8(
|
|
862
|
-
"strong",
|
|
863
|
-
{
|
|
864
|
-
className: "font-semibold text-sm text-center",
|
|
865
|
-
style: { color: "var(--pbm-text)" },
|
|
866
|
-
children: AppliedDiscount.toLocaleString("pt-BR", {
|
|
867
|
-
currency: "BRL",
|
|
868
|
-
currencyDisplay: "symbol",
|
|
869
|
-
currencySign: "standard",
|
|
870
|
-
style: "currency"
|
|
871
|
-
})
|
|
872
|
-
}
|
|
873
|
-
)
|
|
874
|
-
] })
|
|
875
|
-
]
|
|
876
|
-
}
|
|
877
|
-
);
|
|
878
|
-
}
|
|
879
|
-
var Item_default = Item;
|
|
880
|
-
|
|
881
|
-
// src/utils/approved-code.ts
|
|
882
|
-
var APPROVED_BENEFIT_CODE = "N000";
|
|
883
|
-
|
|
884
|
-
// src/components/BenefitsTable/index.tsx
|
|
885
|
-
import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
886
|
-
function BenefitsTable() {
|
|
887
|
-
const {
|
|
888
|
-
setState,
|
|
889
|
-
state,
|
|
890
|
-
customLoginUrl,
|
|
891
|
-
isAuthenticatedShopper,
|
|
892
|
-
benefitsList
|
|
893
|
-
} = usePBMStore();
|
|
894
|
-
const [selectedDiscout, setSelectedDiscount] = useState2(null);
|
|
895
|
-
const [benefitsItems] = useState2(benefitsList);
|
|
896
|
-
if (benefitsItems?.length && benefitsItems[0]?.returnCode !== APPROVED_BENEFIT_CODE && state === "isActivated") {
|
|
897
|
-
return /* @__PURE__ */ jsx9("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: /* @__PURE__ */ jsx9(
|
|
898
|
-
"p",
|
|
899
|
-
{
|
|
900
|
-
className: "text-sm font-semibold text-start",
|
|
901
|
-
style: { color: "var(--pbm-text)" },
|
|
902
|
-
id: "benefits_error_handle",
|
|
903
|
-
children: benefitsItems[0].informativeText
|
|
904
|
-
}
|
|
905
|
-
) });
|
|
906
|
-
}
|
|
907
|
-
return /* @__PURE__ */ jsxs6(
|
|
908
|
-
"section",
|
|
909
|
-
{
|
|
910
|
-
className: "flex items-start justify-center gap-4 w-full h-auto flex-col",
|
|
911
|
-
id: "benefits_table_pbm",
|
|
912
|
-
children: [
|
|
913
|
-
/* @__PURE__ */ jsx9(Title_default, { children: "Descontos dispon\xEDveis:" }),
|
|
914
|
-
/* @__PURE__ */ jsxs6(
|
|
915
|
-
"form",
|
|
916
|
-
{
|
|
917
|
-
className: "flex flex-col items-center justify-start w-full gap-4.5",
|
|
918
|
-
id: "form_benefits_table_pbm",
|
|
919
|
-
onSubmit: (e) => e.preventDefault(),
|
|
920
|
-
children: [
|
|
921
|
-
!benefitsItems && /* @__PURE__ */ jsx9(
|
|
922
|
-
"p",
|
|
923
|
-
{
|
|
924
|
-
className: "text-sm font-semibold text-start text-zinc-900",
|
|
925
|
-
id: "benefits_empty_pbm",
|
|
926
|
-
children: "N\xE3o foi poss\xEDvel encontrar benef\xEDcios para esse produto."
|
|
927
|
-
}
|
|
928
|
-
),
|
|
929
|
-
benefitsItems && benefitsItems.map((item) => {
|
|
930
|
-
const ID_INPUT = item.id + "_" + item.requestedQuantity;
|
|
931
|
-
return /* @__PURE__ */ jsx9(
|
|
932
|
-
Item_default,
|
|
933
|
-
{
|
|
934
|
-
data: item,
|
|
935
|
-
checked: selectedDiscout === ID_INPUT,
|
|
936
|
-
onChange: () => setSelectedDiscount(ID_INPUT)
|
|
937
|
-
},
|
|
938
|
-
ID_INPUT
|
|
939
|
-
);
|
|
940
|
-
})
|
|
941
|
-
]
|
|
942
|
-
}
|
|
943
|
-
),
|
|
944
|
-
state === "isPreview" && /* @__PURE__ */ jsxs6(
|
|
945
|
-
Button_default,
|
|
946
|
-
{
|
|
947
|
-
onClick: () => setState("isEmpty"),
|
|
948
|
-
className: "bg-transparent p-0 w-auto h-auto text-zinc-600 cursor-pointer hover:text-zinc-900 hover:bg-transparent text-start",
|
|
949
|
-
id: "unauthorized_benefits_button",
|
|
950
|
-
children: [
|
|
951
|
-
"Aten\xE7\xE3o: N\xE3o \xE9 poss\xEDvel utilizar os benef\xEDcos sem realizar a consulta do CPF e o Login, por favor",
|
|
952
|
-
" ",
|
|
953
|
-
/* @__PURE__ */ jsx9("span", { className: "underline", children: "insira seu cpf para utilizar os benef\xEDcios" })
|
|
954
|
-
]
|
|
955
|
-
}
|
|
956
|
-
),
|
|
957
|
-
state === "isActivated" && /* @__PURE__ */ jsxs6(Fragment2, { children: [
|
|
958
|
-
!isAuthenticatedShopper && /* @__PURE__ */ jsx9(
|
|
959
|
-
Button_default,
|
|
960
|
-
{
|
|
961
|
-
type: "button",
|
|
962
|
-
onClick: () => window.location.assign(customLoginUrl || "/login"),
|
|
963
|
-
className: "bg-transparent p-0 pl-2 w-auto h-auto text-zinc-600 cursor-pointer hover:text-zinc-900 hover:bg-transparent text-start",
|
|
964
|
-
id: "login",
|
|
965
|
-
children: /* @__PURE__ */ jsx9("span", { className: "underline", children: "Por favor, fa\xE7a o Login para aproveitar os benef\xEDcios!" })
|
|
966
|
-
}
|
|
967
|
-
),
|
|
968
|
-
/* @__PURE__ */ jsx9(
|
|
969
|
-
Button_default,
|
|
970
|
-
{
|
|
971
|
-
onClick: () => setState("isEmpty"),
|
|
972
|
-
className: "bg-transparent p-0 pl-2 w-auto h-auto text-zinc-600 cursor-pointer hover:text-zinc-900 hover:bg-transparent text-start",
|
|
973
|
-
id: "change_security_number",
|
|
974
|
-
children: /* @__PURE__ */ jsx9("span", { className: "underline", children: "Deseja editar o cpf digitado?" })
|
|
975
|
-
}
|
|
976
|
-
)
|
|
977
|
-
] })
|
|
978
|
-
]
|
|
979
|
-
}
|
|
980
|
-
);
|
|
981
|
-
}
|
|
982
|
-
var BenefitsTable_default = BenefitsTable;
|
|
983
|
-
|
|
984
|
-
// src/components/UI/Text/index.tsx
|
|
985
|
-
import classNames6 from "classnames";
|
|
986
|
-
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
987
|
-
function Text(props) {
|
|
988
|
-
return /* @__PURE__ */ jsx10(
|
|
989
|
-
"p",
|
|
990
|
-
{
|
|
991
|
-
className: classNames6(
|
|
992
|
-
"font-normal text-sm",
|
|
993
|
-
props.textAlign && `text-${props.textAlign}`,
|
|
994
|
-
props.className
|
|
995
|
-
),
|
|
996
|
-
style: { color: props.textColor || "var(--pbm-text)", fontSize: props.textSize, textAlign: props.textAlign },
|
|
997
|
-
"data-testid": "test_id_text",
|
|
998
|
-
id: "text_pbm",
|
|
999
|
-
children: props.children
|
|
1000
|
-
}
|
|
1001
|
-
);
|
|
1002
|
-
}
|
|
1003
|
-
var Text_default = Text;
|
|
1004
|
-
|
|
1005
|
-
// src/components/SecurityNumberInvalid/index.tsx
|
|
1006
|
-
import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1007
|
-
function SecurityNumberInvalid({ textColor }) {
|
|
1008
|
-
const { urlAcceptTerms } = usePBMStore();
|
|
1009
|
-
const { setModal } = useModal();
|
|
1010
|
-
const handleOpenModal = () => {
|
|
1011
|
-
if (!urlAcceptTerms) return;
|
|
1012
|
-
setModal({ open: true, id: "iframe_pbm", label: "Aceitar os termos", url: urlAcceptTerms });
|
|
1013
|
-
};
|
|
1014
|
-
return /* @__PURE__ */ jsxs7(
|
|
1015
|
-
"section",
|
|
1016
|
-
{
|
|
1017
|
-
"data-testid": "test_id_invalid",
|
|
1018
|
-
className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y py-6",
|
|
1019
|
-
style: { borderColor: "color-mix(in srgb, var(--pbm-text), transparent 80%)" },
|
|
1020
|
-
id: "security_number_invalid_container_pbm",
|
|
1021
|
-
children: [
|
|
1022
|
-
/* @__PURE__ */ jsx11(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado." }),
|
|
1023
|
-
/* @__PURE__ */ jsxs7(Text_default, { className: "w-full", textColor, children: [
|
|
1024
|
-
"Conclua seu cadastro para habilitar o benef\xEDcio. ",
|
|
1025
|
-
/* @__PURE__ */ jsx11("br", {}),
|
|
1026
|
-
"Ao clicar em \u201CAceitar os termos\u201D, voc\xEA ir\xE1 para uma p\xE1gina externa. Aceite os termos e volte para continuar."
|
|
1027
|
-
] }),
|
|
1028
|
-
/* @__PURE__ */ jsx11(Button_default, { onClick: () => handleOpenModal(), style: { backgroundColor: "var(--pbm-primary)" }, children: "Aceitar os termos" })
|
|
1029
|
-
]
|
|
1030
|
-
}
|
|
1031
|
-
);
|
|
1032
|
-
}
|
|
1033
|
-
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
1034
|
-
|
|
1035
|
-
// src/components/SecurityNumberRegitered/index.tsx
|
|
1036
|
-
import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1037
|
-
function SecurityNumberRegitered({ textColor }) {
|
|
1038
|
-
const { urlRegisterIndustry } = usePBMStore();
|
|
1039
|
-
const { setModal } = useModal();
|
|
1040
|
-
const handleOpenModal = () => {
|
|
1041
|
-
if (!urlRegisterIndustry) return;
|
|
1042
|
-
setModal({ open: true, id: "iframe_pbm", label: "Ativar CPF", url: urlRegisterIndustry });
|
|
1043
|
-
};
|
|
1044
|
-
return /* @__PURE__ */ jsxs8(
|
|
1045
|
-
"section",
|
|
1046
|
-
{
|
|
1047
|
-
"data-testid": "test_id_registered",
|
|
1048
|
-
className: "flex items-end justify-center gap-2 w-full h-auto flex-col border-y py-6",
|
|
1049
|
-
style: { borderColor: "color-mix(in srgb, var(--pbm-text), transparent 80%)" },
|
|
1050
|
-
id: "security_number_registered_container_pbm",
|
|
1051
|
-
children: [
|
|
1052
|
-
/* @__PURE__ */ jsx12(Title_default, { className: "w-full", textColor, children: "Ops, seu CPF ainda n\xE3o est\xE1 habilitado para este produto." }),
|
|
1053
|
-
/* @__PURE__ */ jsx12(Text_default, { className: "w-full", textColor, children: "Para ativar o benef\xEDcio, clique em \u201CAtivar CPF\u201D e conclua a etapa na p\xE1gina externa. Depois, \xE9 s\xF3 voltar para continuar \u2014 vamos aguardar voc\xEA aqui." }),
|
|
1054
|
-
/* @__PURE__ */ jsx12(Button_default, { onClick: () => handleOpenModal(), style: { backgroundColor: "var(--pbm-primary)" }, children: "Ativar CPF" })
|
|
1055
|
-
]
|
|
1056
|
-
}
|
|
1057
|
-
);
|
|
1058
|
-
}
|
|
1059
|
-
var SecurityNumberRegitered_default = SecurityNumberRegitered;
|
|
1060
|
-
|
|
1061
|
-
// src/components/Errors/ErrorToApplyBenefits.tsx
|
|
1062
|
-
import { RefreshCw } from "lucide-react";
|
|
1063
|
-
|
|
1064
|
-
// src/libs/zustand/useError.tsx
|
|
1065
|
-
import { create as create2 } from "zustand";
|
|
1066
|
-
var initialErrorState = {
|
|
1067
|
-
ErrorMessage: "Erro ao aplicar o benef\xEDcio"
|
|
1068
|
-
};
|
|
1069
|
-
var createErrorStore = (set) => ({
|
|
1070
|
-
...initialErrorState,
|
|
1071
|
-
setErrorMessage: (ErrorMessage) => set({ ErrorMessage }),
|
|
1072
|
-
resetErrorMessage: () => set({ ErrorMessage: initialErrorState.ErrorMessage })
|
|
1073
|
-
});
|
|
1074
|
-
var useError = create2(createErrorStore);
|
|
1075
|
-
|
|
1076
|
-
// src/components/Errors/ErrorToApplyBenefits.tsx
|
|
1077
|
-
import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1078
|
-
var ErrorToApplyBenefits = () => {
|
|
1079
|
-
const { ErrorMessage } = useError();
|
|
1080
|
-
const { setState } = usePBMStore();
|
|
1081
|
-
return /* @__PURE__ */ jsxs9(Container_default, { variant: "main", children: [
|
|
1082
|
-
/* @__PURE__ */ jsx13(Title_default, { children: "Erro ao Aplicar o Benef\xEDcio" }),
|
|
1083
|
-
/* @__PURE__ */ jsx13(Text_default, { textAlign: "center", children: ErrorMessage }),
|
|
1084
|
-
/* @__PURE__ */ jsxs9(
|
|
1085
|
-
Button_default,
|
|
1086
|
-
{
|
|
1087
|
-
className: "bg-transparent p-0 pl-2 w-auto h-auto underline cursor-pointer hover:bg-transparent flex items-center justify-start gap-1",
|
|
1088
|
-
style: { color: "var(--pbm-text)" },
|
|
1089
|
-
onMouseOver: (e) => e.currentTarget.style.filter = "brightness(0.8)",
|
|
1090
|
-
onMouseOut: (e) => e.currentTarget.style.filter = "none",
|
|
1091
|
-
onClick: () => setState("isEmpty"),
|
|
1092
|
-
id: "check_benefits_button",
|
|
1093
|
-
children: [
|
|
1094
|
-
/* @__PURE__ */ jsx13("span", { children: "Tentar novamente" }),
|
|
1095
|
-
/* @__PURE__ */ jsx13(RefreshCw, { size: 16 })
|
|
1096
|
-
]
|
|
1097
|
-
}
|
|
1098
|
-
)
|
|
1099
|
-
] });
|
|
1100
|
-
};
|
|
1101
|
-
var ErrorToApplyBenefits_default = ErrorToApplyBenefits;
|
|
1102
|
-
|
|
1103
|
-
// src/components/Modals/CustomerNotRegistered/index.tsx
|
|
1104
|
-
import { useState as useState8 } from "react";
|
|
1105
|
-
|
|
1106
|
-
// src/libs/zustand/usePBMForm.tsx
|
|
1107
|
-
import { create as create3 } from "zustand";
|
|
1108
|
-
var initialPBMFormState = {
|
|
1109
|
-
personalData: { name: "", phone: "", birthday: "", email: "" },
|
|
1110
|
-
address: {
|
|
1111
|
-
postalcode: "",
|
|
1112
|
-
number: "",
|
|
1113
|
-
complement: "",
|
|
1114
|
-
street: "",
|
|
1115
|
-
neighborhood: "",
|
|
1116
|
-
city: "",
|
|
1117
|
-
uf: "",
|
|
1118
|
-
stateAddress: ""
|
|
1119
|
-
},
|
|
1120
|
-
genderResponsibility: { gender: "", patient: null },
|
|
1121
|
-
doctor: { typeCredential: "CRM", register: "", state: "", doctorName: "" },
|
|
1122
|
-
acceptances: {
|
|
1123
|
-
acceptPhone: false,
|
|
1124
|
-
acceptsSms: false,
|
|
1125
|
-
acceptsEmail: false,
|
|
1126
|
-
acceptsMail: false,
|
|
1127
|
-
acceptsPrivacyTermsLGPD: false
|
|
1128
|
-
},
|
|
1129
|
-
step: 0
|
|
1130
|
-
};
|
|
1131
|
-
var usePBMFormStore = create3((set) => ({
|
|
1132
|
-
...initialPBMFormState,
|
|
1133
|
-
setPersonalData: (data) => set((s) => ({ personalData: { ...s.personalData, ...data } })),
|
|
1134
|
-
setAddress: (data) => set((s) => ({ address: { ...s.address, ...data } })),
|
|
1135
|
-
setGenderResponsibility: (data) => set((s) => ({
|
|
1136
|
-
genderResponsibility: { ...s.genderResponsibility, ...data }
|
|
1137
|
-
})),
|
|
1138
|
-
setDoctor: (data) => set((s) => ({ doctor: { ...s.doctor, ...data } })),
|
|
1139
|
-
setAcceptances: (data) => set((s) => ({ acceptances: { ...s.acceptances, ...data } })),
|
|
1140
|
-
setStep: (step) => set({ step }),
|
|
1141
|
-
resetForm: () => set(initialPBMFormState)
|
|
1142
|
-
}));
|
|
1143
|
-
var usePBMForm = usePBMFormStore;
|
|
1144
|
-
|
|
1145
|
-
// src/components/Modals/CustomerNotRegistered/index.tsx
|
|
1146
|
-
import classNames12 from "classnames";
|
|
1147
|
-
|
|
1148
|
-
// src/components/Modals/CustomerNotRegistered/StepPersonalDataForm.tsx
|
|
1149
|
-
import { useState as useState3 } from "react";
|
|
1150
|
-
|
|
1151
|
-
// src/components/Modals/CustomerNotRegistered/Shared/FieldWrapper.tsx
|
|
1152
|
-
import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1153
|
-
var FieldWrapper = ({
|
|
1154
|
-
label,
|
|
1155
|
-
error,
|
|
1156
|
-
children
|
|
1157
|
-
}) => /* @__PURE__ */ jsxs10("div", { className: "flex flex-col gap-1", children: [
|
|
1158
|
-
/* @__PURE__ */ jsx14("label", { className: "text-xs font-medium text-zinc-500 uppercase tracking-wide", children: label }),
|
|
1159
|
-
children,
|
|
1160
|
-
error && /* @__PURE__ */ jsx14("span", { className: "text-xs text-red-500 mt-0.5", children: error })
|
|
1161
|
-
] });
|
|
1162
|
-
var FieldWrapper_default = FieldWrapper;
|
|
1163
|
-
|
|
1164
|
-
// src/components/Modals/CustomerNotRegistered/Shared/DisabledInputClass.ts
|
|
1165
|
-
var disabledInputClass = "w-full rounded-lg border border-gray-200 bg-gray-100 px-3 py-2.5 text-sm text-gray-400 cursor-not-allowed";
|
|
1166
|
-
var DisabledInputClass_default = disabledInputClass;
|
|
1167
|
-
|
|
1168
|
-
// src/components/Modals/CustomerNotRegistered/Shared/InputClass.ts
|
|
1169
|
-
import classNames7 from "classnames";
|
|
1170
|
-
var inputClass = (error) => classNames7(
|
|
1171
|
-
"w-full rounded-lg border px-3 py-2.5 text-sm text-gray-800 outline-none transition-all",
|
|
1172
|
-
"focus:ring-2 focus:ring-blue-500/30 focus:border-blue-500",
|
|
1173
|
-
error ? "border-red-400 bg-red-50" : "border-gray-200 bg-gray-50 hover:border-gray-300"
|
|
1174
|
-
);
|
|
1175
|
-
var InputClass_default = inputClass;
|
|
1176
|
-
|
|
1177
|
-
// src/components/Modals/CustomerNotRegistered/Shared/StepActions.tsx
|
|
1178
|
-
import classNames8 from "classnames";
|
|
1179
|
-
import { jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1180
|
-
var StepActions = ({
|
|
1181
|
-
onNext,
|
|
1182
|
-
onBack,
|
|
1183
|
-
loading,
|
|
1184
|
-
nextLabel = "Continuar",
|
|
1185
|
-
isLast = false
|
|
1186
|
-
}) => /* @__PURE__ */ jsxs11("div", { className: "flex gap-2 mt-2 pt-4 border-t border-gray-100", children: [
|
|
1187
|
-
onBack && /* @__PURE__ */ jsx15(
|
|
1188
|
-
"button",
|
|
1189
|
-
{
|
|
1190
|
-
type: "button",
|
|
1191
|
-
onClick: onBack,
|
|
1192
|
-
className: "flex-1 rounded-lg border border-gray-200 py-2.5 text-sm font-medium text-zinc-600 hover:bg-zinc-600/10 transition-all cursor-pointer",
|
|
1193
|
-
children: "Voltar"
|
|
1194
|
-
}
|
|
1195
|
-
),
|
|
1196
|
-
/* @__PURE__ */ jsx15(
|
|
1197
|
-
"button",
|
|
1198
|
-
{
|
|
1199
|
-
type: "button",
|
|
1200
|
-
onClick: onNext,
|
|
1201
|
-
disabled: loading,
|
|
1202
|
-
className: classNames8(
|
|
1203
|
-
"flex-2 rounded-lg py-2.5 text-sm font-semibold text-white transition-all cursor-pointer",
|
|
1204
|
-
isLast ? "bg-emerald-600 hover:bg-emerald-500" : "bg-(--pbm-primary) hover:bg-(--pbm-primary)/60",
|
|
1205
|
-
loading && "opacity-60 cursor-not-allowed"
|
|
1206
|
-
),
|
|
1207
|
-
children: loading ? /* @__PURE__ */ jsxs11("span", { className: "flex items-center justify-center gap-2", children: [
|
|
1208
|
-
/* @__PURE__ */ jsxs11("svg", { className: "h-4 w-4 animate-spin", viewBox: "0 0 24 24", fill: "none", children: [
|
|
1209
|
-
/* @__PURE__ */ jsx15(
|
|
1210
|
-
"circle",
|
|
1211
|
-
{
|
|
1212
|
-
className: "opacity-25",
|
|
1213
|
-
cx: "12",
|
|
1214
|
-
cy: "12",
|
|
1215
|
-
r: "10",
|
|
1216
|
-
stroke: "currentColor",
|
|
1217
|
-
strokeWidth: "4"
|
|
1218
|
-
}
|
|
1219
|
-
),
|
|
1220
|
-
/* @__PURE__ */ jsx15(
|
|
1221
|
-
"path",
|
|
1222
|
-
{
|
|
1223
|
-
className: "opacity-75",
|
|
1224
|
-
fill: "currentColor",
|
|
1225
|
-
d: "M4 12a8 8 0 018-8v8z"
|
|
1226
|
-
}
|
|
1227
|
-
)
|
|
1228
|
-
] }),
|
|
1229
|
-
"Enviando..."
|
|
1230
|
-
] }) : nextLabel
|
|
1231
|
-
}
|
|
1232
|
-
)
|
|
1233
|
-
] });
|
|
1234
|
-
var StepActions_default = StepActions;
|
|
1235
|
-
|
|
1236
|
-
// src/utils/mappingFormStep.ts
|
|
1237
|
-
var mappingFormStep = {
|
|
1238
|
-
"PersonalData": 0,
|
|
1239
|
-
"Address": 1,
|
|
1240
|
-
"GenderResponsibility": 2,
|
|
1241
|
-
"Doctor": 3,
|
|
1242
|
-
"Acceptances": 4
|
|
1243
|
-
};
|
|
1244
|
-
|
|
1245
|
-
// src/components/Modals/CustomerNotRegistered/StepPersonalDataForm.tsx
|
|
1246
|
-
import { jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
1247
|
-
var StepPersonalDataForm = ({
|
|
1248
|
-
securityNumber,
|
|
1249
|
-
onNext
|
|
1250
|
-
}) => {
|
|
1251
|
-
const { personalData, setPersonalData, setStep } = usePBMForm();
|
|
1252
|
-
const { setModal } = useModal();
|
|
1253
|
-
const [errors, setErrors] = useState3({});
|
|
1254
|
-
const [loading, setLoading] = useState3(false);
|
|
1255
|
-
const validate = () => {
|
|
1256
|
-
const e = {};
|
|
1257
|
-
if (!personalData.name.trim() || personalData.name.trim().split(" ").length < 2)
|
|
1258
|
-
e.name = "Informe o nome completo.";
|
|
1259
|
-
if (!/^\(\d{2}\) \d{5}-\d{4}$/.test(personalData.phone))
|
|
1260
|
-
e.phone = "Telefone inv\xE1lido.";
|
|
1261
|
-
if (!personalData.birthday) e.birthday = "Data de nascimento obrigat\xF3ria.";
|
|
1262
|
-
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(personalData.email))
|
|
1263
|
-
e.email = "E-mail inv\xE1lido.";
|
|
1264
|
-
setErrors(e);
|
|
1265
|
-
return Object.keys(e).length === 0;
|
|
1266
|
-
};
|
|
1267
|
-
const handleSubmit = async () => {
|
|
1268
|
-
if (!validate()) return;
|
|
1269
|
-
setLoading(true);
|
|
1270
|
-
try {
|
|
1271
|
-
setStep(mappingFormStep["Address"]);
|
|
1272
|
-
onNext();
|
|
1273
|
-
} catch {
|
|
1274
|
-
console.error("An error occurred while setting personal data form.");
|
|
1275
|
-
} finally {
|
|
1276
|
-
setLoading(false);
|
|
1277
|
-
}
|
|
1278
|
-
};
|
|
1279
|
-
return /* @__PURE__ */ jsxs12("div", { className: "flex flex-col gap-4", children: [
|
|
1280
|
-
/* @__PURE__ */ jsxs12(FieldWrapper_default, { label: "CPF", children: [
|
|
1281
|
-
/* @__PURE__ */ jsx16(
|
|
1282
|
-
"input",
|
|
1283
|
-
{
|
|
1284
|
-
className: DisabledInputClass_default,
|
|
1285
|
-
value: formaters.cpf(securityNumber),
|
|
1286
|
-
disabled: true,
|
|
1287
|
-
readOnly: true
|
|
1288
|
-
}
|
|
1289
|
-
),
|
|
1290
|
-
/* @__PURE__ */ jsx16("p", { className: "text-xs text-gray-400 mt-1", children: /* @__PURE__ */ jsx16(
|
|
1291
|
-
"button",
|
|
1292
|
-
{
|
|
1293
|
-
type: "button",
|
|
1294
|
-
className: "text-(--pbm-primary) hover:text-(--pbm-primary)/60 cursor-pointer underline underline-offset-2 transition-colors",
|
|
1295
|
-
onClick: () => setModal({ id: "", open: false }),
|
|
1296
|
-
children: "Deseja alterar o CPF? Clique aqui."
|
|
1297
|
-
}
|
|
1298
|
-
) })
|
|
1299
|
-
] }),
|
|
1300
|
-
/* @__PURE__ */ jsx16(FieldWrapper_default, { label: "Nome completo", error: errors.name, children: /* @__PURE__ */ jsx16(
|
|
1301
|
-
"input",
|
|
1302
|
-
{
|
|
1303
|
-
className: InputClass_default(errors.name),
|
|
1304
|
-
placeholder: "Ex: Jo\xE3o da Silva",
|
|
1305
|
-
value: personalData.name,
|
|
1306
|
-
onChange: (e) => {
|
|
1307
|
-
setPersonalData({ name: e.target.value });
|
|
1308
|
-
setErrors((p) => ({ ...p, name: void 0 }));
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
) }),
|
|
1312
|
-
/* @__PURE__ */ jsxs12("div", { className: "grid grid-cols-2 gap-3", children: [
|
|
1313
|
-
/* @__PURE__ */ jsx16(FieldWrapper_default, { label: "Telefone", error: errors.phone, children: /* @__PURE__ */ jsx16(
|
|
1314
|
-
"input",
|
|
1315
|
-
{
|
|
1316
|
-
className: InputClass_default(errors.phone),
|
|
1317
|
-
placeholder: "(11) 99999-8888",
|
|
1318
|
-
value: personalData.phone,
|
|
1319
|
-
onChange: (e) => {
|
|
1320
|
-
setPersonalData({ phone: formaters.phone(e.target.value) });
|
|
1321
|
-
setErrors((p) => ({ ...p, phone: void 0 }));
|
|
1322
|
-
}
|
|
1323
|
-
}
|
|
1324
|
-
) }),
|
|
1325
|
-
/* @__PURE__ */ jsx16(FieldWrapper_default, { label: "Data de nascimento", error: errors.birthday, children: /* @__PURE__ */ jsx16(
|
|
1326
|
-
"input",
|
|
1327
|
-
{
|
|
1328
|
-
type: "date",
|
|
1329
|
-
className: InputClass_default(errors.birthday),
|
|
1330
|
-
value: personalData.birthday,
|
|
1331
|
-
onChange: (e) => {
|
|
1332
|
-
setPersonalData({ birthday: e.target.value });
|
|
1333
|
-
setErrors((p) => ({ ...p, birthday: void 0 }));
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
) })
|
|
1337
|
-
] }),
|
|
1338
|
-
/* @__PURE__ */ jsx16(FieldWrapper_default, { label: "E-mail", error: errors.email, children: /* @__PURE__ */ jsx16(
|
|
1339
|
-
"input",
|
|
1340
|
-
{
|
|
1341
|
-
type: "email",
|
|
1342
|
-
className: InputClass_default(errors.email),
|
|
1343
|
-
placeholder: "joao@email.com",
|
|
1344
|
-
value: personalData.email,
|
|
1345
|
-
onChange: (e) => {
|
|
1346
|
-
setPersonalData({ email: e.target.value });
|
|
1347
|
-
setErrors((p) => ({ ...p, email: void 0 }));
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
) }),
|
|
1351
|
-
/* @__PURE__ */ jsx16(StepActions_default, { onNext: handleSubmit, loading })
|
|
1352
|
-
] });
|
|
1353
|
-
};
|
|
1354
|
-
var StepPersonalDataForm_default = StepPersonalDataForm;
|
|
1355
|
-
|
|
1356
|
-
// src/components/Modals/CustomerNotRegistered/StepAddressForm.tsx
|
|
1357
|
-
import { useCallback as useCallback2, useState as useState4 } from "react";
|
|
1358
|
-
|
|
1359
|
-
// src/services/lookup-postal-code.ts
|
|
1360
|
-
async function LookupPostalCode({ postal_code }) {
|
|
1361
|
-
const response = await fetch(`${getEnv("VITE_CORREIOS_API_URL")}/${postal_code}/json/`);
|
|
1362
|
-
if (!response.ok) {
|
|
1363
|
-
throw new Error("Erro ao consultar CEP");
|
|
1364
|
-
}
|
|
1365
|
-
const data = await response.json();
|
|
1366
|
-
return { ...data, success: true };
|
|
1367
|
-
}
|
|
1368
|
-
|
|
1369
|
-
// src/components/Modals/CustomerNotRegistered/StepAddressForm.tsx
|
|
1370
|
-
import { jsx as jsx17, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1371
|
-
var StepAddressForm = ({
|
|
1372
|
-
onNext,
|
|
1373
|
-
onBack
|
|
1374
|
-
}) => {
|
|
1375
|
-
const { address, setAddress, setStep } = usePBMForm();
|
|
1376
|
-
const [errors, setErrors] = useState4({});
|
|
1377
|
-
const [loadingCep, setLoadingCep] = useState4(false);
|
|
1378
|
-
const [loading, setLoading] = useState4(false);
|
|
1379
|
-
const fetchCEP = useCallback2(
|
|
1380
|
-
async (cep) => {
|
|
1381
|
-
const raw = cep.replace(/\D/g, "");
|
|
1382
|
-
if (raw.length !== 8) return;
|
|
1383
|
-
setLoadingCep(true);
|
|
1384
|
-
try {
|
|
1385
|
-
const response = await LookupPostalCode({ postal_code: raw });
|
|
1386
|
-
if (!response.success) {
|
|
1387
|
-
console.error("Failed to lookup postal code");
|
|
1388
|
-
return;
|
|
1389
|
-
}
|
|
1390
|
-
setAddress({
|
|
1391
|
-
street: response.logradouro,
|
|
1392
|
-
neighborhood: response.bairro,
|
|
1393
|
-
uf: response.uf,
|
|
1394
|
-
city: response.localidade,
|
|
1395
|
-
stateAddress: response.estado,
|
|
1396
|
-
postalcode: response.cep,
|
|
1397
|
-
complement: response.complemento || ""
|
|
1398
|
-
});
|
|
1399
|
-
} catch {
|
|
1400
|
-
console.error("Failed to fetch address for CEP:", cep);
|
|
1401
|
-
} finally {
|
|
1402
|
-
setLoadingCep(false);
|
|
1403
|
-
}
|
|
1404
|
-
},
|
|
1405
|
-
[setAddress]
|
|
1406
|
-
);
|
|
1407
|
-
const validate = () => {
|
|
1408
|
-
const e = {};
|
|
1409
|
-
if (!/^\d{5}-\d{3}$/.test(address.postalcode))
|
|
1410
|
-
e.postalcode = "CEP inv\xE1lido.";
|
|
1411
|
-
if (!address.number.trim()) e.number = "N\xFAmero obrigat\xF3rio.";
|
|
1412
|
-
setErrors(e);
|
|
1413
|
-
return Object.keys(e).length === 0;
|
|
1414
|
-
};
|
|
1415
|
-
const handleSubmit = async () => {
|
|
1416
|
-
if (!validate()) return;
|
|
1417
|
-
setLoading(true);
|
|
1418
|
-
try {
|
|
1419
|
-
setStep(mappingFormStep["GenderResponsibility"]);
|
|
1420
|
-
onNext();
|
|
1421
|
-
} catch {
|
|
1422
|
-
console.log("An error occurred while submitting address form.");
|
|
1423
|
-
} finally {
|
|
1424
|
-
setLoading(false);
|
|
1425
|
-
}
|
|
1426
|
-
};
|
|
1427
|
-
return /* @__PURE__ */ jsxs13("div", { className: "flex flex-col gap-4", children: [
|
|
1428
|
-
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "CEP", error: errors.postalcode, children: /* @__PURE__ */ jsxs13("div", { className: "relative", children: [
|
|
1429
|
-
/* @__PURE__ */ jsx17(
|
|
1430
|
-
"input",
|
|
1431
|
-
{
|
|
1432
|
-
className: InputClass_default(errors.postalcode),
|
|
1433
|
-
placeholder: "00000-000",
|
|
1434
|
-
value: address.postalcode,
|
|
1435
|
-
onChange: (e) => {
|
|
1436
|
-
const formatted = formaters.cep(e.target.value);
|
|
1437
|
-
setAddress({ postalcode: formatted });
|
|
1438
|
-
setErrors((p) => ({
|
|
1439
|
-
...p,
|
|
1440
|
-
postalcode: void 0
|
|
1441
|
-
}));
|
|
1442
|
-
if (formatted.replace(/\D/g, "").length === 8)
|
|
1443
|
-
fetchCEP(formatted);
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
),
|
|
1447
|
-
loadingCep && /* @__PURE__ */ jsx17("div", { className: "absolute right-3 top-1/2 -translate-y-1/2", children: /* @__PURE__ */ jsxs13(
|
|
1448
|
-
"svg",
|
|
1449
|
-
{
|
|
1450
|
-
className: "h-4 w-4 animate-spin text-blue-500",
|
|
1451
|
-
viewBox: "0 0 24 24",
|
|
1452
|
-
fill: "none",
|
|
1453
|
-
children: [
|
|
1454
|
-
/* @__PURE__ */ jsx17(
|
|
1455
|
-
"circle",
|
|
1456
|
-
{
|
|
1457
|
-
className: "opacity-25",
|
|
1458
|
-
cx: "12",
|
|
1459
|
-
cy: "12",
|
|
1460
|
-
r: "10",
|
|
1461
|
-
stroke: "currentColor",
|
|
1462
|
-
strokeWidth: "4"
|
|
1463
|
-
}
|
|
1464
|
-
),
|
|
1465
|
-
/* @__PURE__ */ jsx17(
|
|
1466
|
-
"path",
|
|
1467
|
-
{
|
|
1468
|
-
className: "opacity-75",
|
|
1469
|
-
fill: "currentColor",
|
|
1470
|
-
d: "M4 12a8 8 0 018-8v8z"
|
|
1471
|
-
}
|
|
1472
|
-
)
|
|
1473
|
-
]
|
|
1474
|
-
}
|
|
1475
|
-
) })
|
|
1476
|
-
] }) }),
|
|
1477
|
-
/* @__PURE__ */ jsxs13("div", { className: "grid grid-cols-2 gap-3", children: [
|
|
1478
|
-
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Rua", children: /* @__PURE__ */ jsx17(
|
|
1479
|
-
"input",
|
|
1480
|
-
{
|
|
1481
|
-
className: DisabledInputClass_default,
|
|
1482
|
-
value: address.street || "",
|
|
1483
|
-
disabled: true,
|
|
1484
|
-
readOnly: true,
|
|
1485
|
-
placeholder: "Preenchido pelo CEP"
|
|
1486
|
-
}
|
|
1487
|
-
) }),
|
|
1488
|
-
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Bairro", children: /* @__PURE__ */ jsx17(
|
|
1489
|
-
"input",
|
|
1490
|
-
{
|
|
1491
|
-
className: DisabledInputClass_default,
|
|
1492
|
-
value: address.neighborhood || "",
|
|
1493
|
-
disabled: true,
|
|
1494
|
-
readOnly: true,
|
|
1495
|
-
placeholder: "Preenchido pelo CEP"
|
|
1496
|
-
}
|
|
1497
|
-
) })
|
|
1498
|
-
] }),
|
|
1499
|
-
/* @__PURE__ */ jsxs13("div", { className: "grid grid-cols-2 gap-3", children: [
|
|
1500
|
-
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Cidade", children: /* @__PURE__ */ jsx17(
|
|
1501
|
-
"input",
|
|
1502
|
-
{
|
|
1503
|
-
className: DisabledInputClass_default,
|
|
1504
|
-
value: address.city || "",
|
|
1505
|
-
disabled: true,
|
|
1506
|
-
readOnly: true,
|
|
1507
|
-
placeholder: "Preenchido pelo CEP"
|
|
1508
|
-
}
|
|
1509
|
-
) }),
|
|
1510
|
-
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Estado", children: /* @__PURE__ */ jsx17(
|
|
1511
|
-
"input",
|
|
1512
|
-
{
|
|
1513
|
-
className: DisabledInputClass_default,
|
|
1514
|
-
value: address.stateAddress || "",
|
|
1515
|
-
disabled: true,
|
|
1516
|
-
readOnly: true,
|
|
1517
|
-
placeholder: "UF"
|
|
1518
|
-
}
|
|
1519
|
-
) })
|
|
1520
|
-
] }),
|
|
1521
|
-
/* @__PURE__ */ jsxs13("div", { className: "grid grid-cols-2 gap-3", children: [
|
|
1522
|
-
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "N\xFAmero", error: errors.number, children: /* @__PURE__ */ jsx17(
|
|
1523
|
-
"input",
|
|
1524
|
-
{
|
|
1525
|
-
className: InputClass_default(errors.number),
|
|
1526
|
-
placeholder: "Ex: 100",
|
|
1527
|
-
value: address.number,
|
|
1528
|
-
onChange: (e) => {
|
|
1529
|
-
setAddress({ number: e.target.value });
|
|
1530
|
-
setErrors((p) => ({ ...p, number: void 0 }));
|
|
1531
|
-
}
|
|
1532
|
-
}
|
|
1533
|
-
) }),
|
|
1534
|
-
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Complemento", children: /* @__PURE__ */ jsx17(
|
|
1535
|
-
"input",
|
|
1536
|
-
{
|
|
1537
|
-
className: InputClass_default(),
|
|
1538
|
-
placeholder: "Apto, bloco...",
|
|
1539
|
-
value: address.complement,
|
|
1540
|
-
onChange: (e) => setAddress({ complement: e.target.value })
|
|
1541
|
-
}
|
|
1542
|
-
) })
|
|
1543
|
-
] }),
|
|
1544
|
-
/* @__PURE__ */ jsx17(StepActions_default, { onNext: handleSubmit, onBack, loading })
|
|
1545
|
-
] });
|
|
1546
|
-
};
|
|
1547
|
-
var StepAddressForm_default = StepAddressForm;
|
|
1548
|
-
|
|
1549
|
-
// src/components/Modals/CustomerNotRegistered/StepGenderForm.tsx
|
|
1550
|
-
import classNames9 from "classnames";
|
|
1551
|
-
import { useState as useState5 } from "react";
|
|
1552
|
-
import { jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
1553
|
-
var StepGenderForm = ({
|
|
1554
|
-
onNext,
|
|
1555
|
-
onBack
|
|
1556
|
-
}) => {
|
|
1557
|
-
const { genderResponsibility, setGenderResponsibility, setStep } = usePBMForm();
|
|
1558
|
-
const [errors, setErrors] = useState5(
|
|
1559
|
-
{}
|
|
1560
|
-
);
|
|
1561
|
-
const [loading, setLoading] = useState5(false);
|
|
1562
|
-
const validate = () => {
|
|
1563
|
-
const e = {};
|
|
1564
|
-
if (!genderResponsibility.gender) e.gender = "Selecione o g\xEAnero.";
|
|
1565
|
-
if (genderResponsibility.patient === null)
|
|
1566
|
-
e.patient = "Informe se \xE9 o paciente.";
|
|
1567
|
-
setErrors(e);
|
|
1568
|
-
return Object.keys(e).length === 0;
|
|
1569
|
-
};
|
|
1570
|
-
const handleSubmit = async () => {
|
|
1571
|
-
if (!validate()) return;
|
|
1572
|
-
setLoading(true);
|
|
1573
|
-
try {
|
|
1574
|
-
setStep(mappingFormStep["Doctor"]);
|
|
1575
|
-
onNext();
|
|
1576
|
-
} catch {
|
|
1577
|
-
console.error(
|
|
1578
|
-
"An error occurred while submitting gender responsibility data."
|
|
1579
|
-
);
|
|
1580
|
-
} finally {
|
|
1581
|
-
setLoading(false);
|
|
1582
|
-
}
|
|
1583
|
-
};
|
|
1584
|
-
const genderOptions = [
|
|
1585
|
-
{ value: "M", label: "Masculino" },
|
|
1586
|
-
{ value: "F", label: "Feminino" },
|
|
1587
|
-
{ value: "O", label: "Outro" }
|
|
1588
|
-
];
|
|
1589
|
-
return /* @__PURE__ */ jsxs14("div", { className: "flex flex-col gap-5", children: [
|
|
1590
|
-
/* @__PURE__ */ jsxs14("div", { children: [
|
|
1591
|
-
/* @__PURE__ */ jsx18("label", { className: "text-xs font-medium text-gray-500 uppercase tracking-wide block mb-2", children: "G\xEAnero" }),
|
|
1592
|
-
/* @__PURE__ */ jsx18("div", { className: "flex gap-2", children: genderOptions.map((opt) => /* @__PURE__ */ jsx18(
|
|
1593
|
-
"button",
|
|
1594
|
-
{
|
|
1595
|
-
type: "button",
|
|
1596
|
-
onClick: () => {
|
|
1597
|
-
setGenderResponsibility({ gender: opt.value });
|
|
1598
|
-
setErrors((p) => ({ ...p, gender: void 0 }));
|
|
1599
|
-
},
|
|
1600
|
-
className: classNames9(
|
|
1601
|
-
"flex-1 py-2.5 cursor-pointer px-2.5 rounded-lg border text-sm font-medium transition-all",
|
|
1602
|
-
genderResponsibility.gender === opt.value ? "border-(--pbm-primary) bg-(--pbm-primary) text-white" : "border-gray-200 bg-gray-50 text-gray-600 hover:border-(--pbm-primary)"
|
|
1603
|
-
),
|
|
1604
|
-
children: opt.label
|
|
1605
|
-
},
|
|
1606
|
-
opt.value
|
|
1607
|
-
)) }),
|
|
1608
|
-
errors.gender && /* @__PURE__ */ jsx18("span", { className: "text-xs text-red-500 mt-1 block", children: errors.gender })
|
|
1609
|
-
] }),
|
|
1610
|
-
/* @__PURE__ */ jsxs14("div", { children: [
|
|
1611
|
-
/* @__PURE__ */ jsx18("label", { className: "text-xs font-medium text-gray-500 uppercase tracking-wide block mb-2", children: "Voc\xEA \xE9 o paciente?" }),
|
|
1612
|
-
/* @__PURE__ */ jsx18("div", { className: "flex gap-2", children: [
|
|
1613
|
-
{ label: "Sim, sou o paciente", value: true },
|
|
1614
|
-
{ label: "N\xE3o, sou respons\xE1vel", value: false }
|
|
1615
|
-
].map((opt) => /* @__PURE__ */ jsx18(
|
|
1616
|
-
"button",
|
|
1617
|
-
{
|
|
1618
|
-
type: "button",
|
|
1619
|
-
onClick: () => {
|
|
1620
|
-
setGenderResponsibility({ patient: opt.value });
|
|
1621
|
-
setErrors((p) => ({ ...p, patient: void 0 }));
|
|
1622
|
-
},
|
|
1623
|
-
className: classNames9(
|
|
1624
|
-
"flex-1 py-2.5 px-2.5 text-nowrap cursor-pointer rounded-lg border text-sm font-medium transition-all",
|
|
1625
|
-
genderResponsibility.patient === opt.value ? "border-(--pbm-primary) bg-(--pbm-primary) text-white" : "border-gray-200 bg-gray-50 text-gray-600 hover:border-(--pbm-primary)"
|
|
1626
|
-
),
|
|
1627
|
-
children: opt.label
|
|
1628
|
-
},
|
|
1629
|
-
String(opt.value)
|
|
1630
|
-
)) }),
|
|
1631
|
-
errors.patient && /* @__PURE__ */ jsx18("span", { className: "text-xs text-red-500 mt-1 block", children: errors.patient })
|
|
1632
|
-
] }),
|
|
1633
|
-
/* @__PURE__ */ jsx18(StepActions_default, { onNext: handleSubmit, onBack, loading })
|
|
1634
|
-
] });
|
|
1635
|
-
};
|
|
1636
|
-
var StepGenderForm_default = StepGenderForm;
|
|
1637
|
-
|
|
1638
|
-
// src/components/Modals/CustomerNotRegistered/StepDoctorForm.tsx
|
|
1639
|
-
import { useState as useState6 } from "react";
|
|
1640
|
-
|
|
1641
|
-
// src/utils/ufMapping.ts
|
|
1642
|
-
var BRAZILIAN_STATES = [
|
|
1643
|
-
"AC",
|
|
1644
|
-
"AL",
|
|
1645
|
-
"AP",
|
|
1646
|
-
"AM",
|
|
1647
|
-
"BA",
|
|
1648
|
-
"CE",
|
|
1649
|
-
"DF",
|
|
1650
|
-
"ES",
|
|
1651
|
-
"GO",
|
|
1652
|
-
"MA",
|
|
1653
|
-
"MT",
|
|
1654
|
-
"MS",
|
|
1655
|
-
"MG",
|
|
1656
|
-
"PA",
|
|
1657
|
-
"PB",
|
|
1658
|
-
"PR",
|
|
1659
|
-
"PE",
|
|
1660
|
-
"PI",
|
|
1661
|
-
"RJ",
|
|
1662
|
-
"RN",
|
|
1663
|
-
"RS",
|
|
1664
|
-
"RO",
|
|
1665
|
-
"RR",
|
|
1666
|
-
"SC",
|
|
1667
|
-
"SP",
|
|
1668
|
-
"SE",
|
|
1669
|
-
"TO"
|
|
1670
|
-
];
|
|
1671
|
-
|
|
1672
|
-
// src/components/Modals/CustomerNotRegistered/StepDoctorForm.tsx
|
|
1673
|
-
import { jsx as jsx19, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
1674
|
-
var StepDoctorForm = ({
|
|
1675
|
-
onNext,
|
|
1676
|
-
onBack
|
|
1677
|
-
}) => {
|
|
1678
|
-
const { doctor, setDoctor, setStep } = usePBMForm();
|
|
1679
|
-
const [errors, setErrors] = useState6({});
|
|
1680
|
-
const [loading, setLoading] = useState6(false);
|
|
1681
|
-
const validate = () => {
|
|
1682
|
-
const e = {};
|
|
1683
|
-
if (!doctor.typeCredential)
|
|
1684
|
-
e.typeCredential = "Tipo de credencial obrigat\xF3rio.";
|
|
1685
|
-
if (!doctor.register.trim()) e.register = "N\xFAmero do registro obrigat\xF3rio.";
|
|
1686
|
-
if (!doctor.state) e.state = "Estado obrigat\xF3rio.";
|
|
1687
|
-
if (!doctor.doctorName.trim()) e.doctorName = "Nome do m\xE9dico obrigat\xF3rio.";
|
|
1688
|
-
setErrors(e);
|
|
1689
|
-
return Object.keys(e).length === 0;
|
|
1690
|
-
};
|
|
1691
|
-
const handleSubmit = async () => {
|
|
1692
|
-
if (!validate()) return;
|
|
1693
|
-
setLoading(true);
|
|
1694
|
-
try {
|
|
1695
|
-
setStep(mappingFormStep["Acceptances"]);
|
|
1696
|
-
onNext();
|
|
1697
|
-
} catch {
|
|
1698
|
-
console.error("An error occurred while submitting doctor data.");
|
|
1699
|
-
} finally {
|
|
1700
|
-
setLoading(false);
|
|
1701
|
-
}
|
|
1702
|
-
};
|
|
1703
|
-
return /* @__PURE__ */ jsxs15("div", { className: "flex flex-col gap-4", children: [
|
|
1704
|
-
/* @__PURE__ */ jsxs15("div", { className: "grid grid-cols-3 gap-3", children: [
|
|
1705
|
-
/* @__PURE__ */ jsx19(FieldWrapper_default, { label: "Tipo credencial", error: errors.typeCredential, children: /* @__PURE__ */ jsxs15(
|
|
1706
|
-
"select",
|
|
1707
|
-
{
|
|
1708
|
-
className: InputClass_default(errors.typeCredential),
|
|
1709
|
-
value: doctor.typeCredential,
|
|
1710
|
-
onChange: (e) => {
|
|
1711
|
-
setDoctor({ typeCredential: e.target.value });
|
|
1712
|
-
setErrors((p) => ({
|
|
1713
|
-
...p,
|
|
1714
|
-
typeCredential: void 0
|
|
1715
|
-
}));
|
|
1716
|
-
},
|
|
1717
|
-
children: [
|
|
1718
|
-
/* @__PURE__ */ jsx19("option", { value: "CRM", children: "CRM" }),
|
|
1719
|
-
/* @__PURE__ */ jsx19("option", { value: "CRO", children: "CRO" }),
|
|
1720
|
-
/* @__PURE__ */ jsx19("option", { value: "CRF", children: "CRF" })
|
|
1721
|
-
]
|
|
1722
|
-
}
|
|
1723
|
-
) }),
|
|
1724
|
-
/* @__PURE__ */ jsx19(FieldWrapper_default, { label: "Estado (UF)", error: errors.state, children: /* @__PURE__ */ jsxs15(
|
|
1725
|
-
"select",
|
|
1726
|
-
{
|
|
1727
|
-
className: InputClass_default(errors.state),
|
|
1728
|
-
value: doctor.state,
|
|
1729
|
-
onChange: (e) => {
|
|
1730
|
-
setDoctor({ state: e.target.value });
|
|
1731
|
-
setErrors((p) => ({ ...p, state: void 0 }));
|
|
1732
|
-
},
|
|
1733
|
-
children: [
|
|
1734
|
-
/* @__PURE__ */ jsx19("option", { value: "", children: "UF" }),
|
|
1735
|
-
BRAZILIAN_STATES.map((state) => /* @__PURE__ */ jsx19("option", { value: state, children: state }, state))
|
|
1736
|
-
]
|
|
1737
|
-
}
|
|
1738
|
-
) }),
|
|
1739
|
-
/* @__PURE__ */ jsx19(FieldWrapper_default, { label: "N\xBA registro", error: errors.register, children: /* @__PURE__ */ jsx19("div", { className: "relative", children: /* @__PURE__ */ jsx19(
|
|
1740
|
-
"input",
|
|
1741
|
-
{
|
|
1742
|
-
className: InputClass_default(errors.register),
|
|
1743
|
-
placeholder: "Ex: 123456",
|
|
1744
|
-
value: doctor.register,
|
|
1745
|
-
onChange: (e) => {
|
|
1746
|
-
setDoctor({ register: e.target.value.replace(/\D/g, "") });
|
|
1747
|
-
setErrors((p) => ({
|
|
1748
|
-
...p,
|
|
1749
|
-
register: void 0
|
|
1750
|
-
}));
|
|
1751
|
-
}
|
|
1752
|
-
}
|
|
1753
|
-
) }) })
|
|
1754
|
-
] }),
|
|
1755
|
-
/* @__PURE__ */ jsxs15(FieldWrapper_default, { label: "Nome do m\xE9dico", error: errors.doctorName, children: [
|
|
1756
|
-
/* @__PURE__ */ jsx19("div", { className: "relative", children: /* @__PURE__ */ jsx19(
|
|
1757
|
-
"input",
|
|
1758
|
-
{
|
|
1759
|
-
className: InputClass_default(errors.doctorName),
|
|
1760
|
-
placeholder: "Nome Completo do Profissional",
|
|
1761
|
-
value: doctor.doctorName,
|
|
1762
|
-
onChange: (e) => {
|
|
1763
|
-
setDoctor({ doctorName: e.target.value });
|
|
1764
|
-
setErrors((p) => ({
|
|
1765
|
-
...p,
|
|
1766
|
-
doctorName: void 0
|
|
1767
|
-
}));
|
|
1768
|
-
}
|
|
1769
|
-
}
|
|
1770
|
-
) }),
|
|
1771
|
-
/* @__PURE__ */ jsx19("p", { className: "text-xs text-gray-400 mt-0.5", children: "Preenchido automaticamente ao informar registro + UF." })
|
|
1772
|
-
] }),
|
|
1773
|
-
/* @__PURE__ */ jsx19(StepActions_default, { onNext: handleSubmit, onBack, loading })
|
|
1774
|
-
] });
|
|
1775
|
-
};
|
|
1776
|
-
var StepDoctorForm_default = StepDoctorForm;
|
|
1777
|
-
|
|
1778
|
-
// src/components/Modals/CustomerNotRegistered/StepAcceptancesForm.tsx
|
|
1779
|
-
import { useState as useState7 } from "react";
|
|
1780
|
-
|
|
1781
|
-
// src/components/Modals/CustomerNotRegistered/Shared/CheckRow.tsx
|
|
1782
|
-
import classNames10 from "classnames";
|
|
1783
|
-
import { jsx as jsx20, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
1784
|
-
var CheckRow = ({
|
|
1785
|
-
label,
|
|
1786
|
-
checked,
|
|
1787
|
-
onChange,
|
|
1788
|
-
required,
|
|
1789
|
-
error
|
|
1790
|
-
}) => /* @__PURE__ */ jsxs16(
|
|
1791
|
-
"label",
|
|
1792
|
-
{
|
|
1793
|
-
className: classNames10(
|
|
1794
|
-
"flex items-start gap-3 cursor-pointer group p-3 rounded-lg border transition-all",
|
|
1795
|
-
checked ? "border-emerald-200 bg-emerald-50/60" : "border-zinc-100 hover:border-zinc-200 bg-zinc-50/40",
|
|
1796
|
-
error ? "border-red-300 bg-red-50/40" : ""
|
|
1797
|
-
),
|
|
1798
|
-
children: [
|
|
1799
|
-
/* @__PURE__ */ jsx20(
|
|
1800
|
-
"div",
|
|
1801
|
-
{
|
|
1802
|
-
className: classNames10(
|
|
1803
|
-
"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border transition-all",
|
|
1804
|
-
checked ? "border-(--pbm-primary) bg-(--pbm-primary)" : "border-zinc-300 bg-white"
|
|
1805
|
-
),
|
|
1806
|
-
children: checked && /* @__PURE__ */ jsx20("svg", { className: "h-2.5 w-2.5 text-white", viewBox: "0 0 10 8", fill: "none", children: /* @__PURE__ */ jsx20(
|
|
1807
|
-
"path",
|
|
1808
|
-
{
|
|
1809
|
-
d: "M1 4l3 3 5-6",
|
|
1810
|
-
stroke: "currentColor",
|
|
1811
|
-
strokeWidth: "1.8",
|
|
1812
|
-
strokeLinecap: "round",
|
|
1813
|
-
strokeLinejoin: "round"
|
|
1814
|
-
}
|
|
1815
|
-
) })
|
|
1816
|
-
}
|
|
1817
|
-
),
|
|
1818
|
-
/* @__PURE__ */ jsxs16("span", { className: "text-sm text-zinc-700 leading-snug", children: [
|
|
1819
|
-
label,
|
|
1820
|
-
required && /* @__PURE__ */ jsx20("span", { className: "text-red-400 ml-1", children: "*" })
|
|
1821
|
-
] }),
|
|
1822
|
-
/* @__PURE__ */ jsx20(
|
|
1823
|
-
"input",
|
|
1824
|
-
{
|
|
1825
|
-
type: "checkbox",
|
|
1826
|
-
className: "sr-only",
|
|
1827
|
-
checked,
|
|
1828
|
-
onChange: (e) => onChange(e.target.checked)
|
|
1829
|
-
}
|
|
1830
|
-
)
|
|
1831
|
-
]
|
|
1832
|
-
}
|
|
1833
|
-
);
|
|
1834
|
-
var CheckRow_default = CheckRow;
|
|
1835
|
-
|
|
1836
|
-
// src/services/enable-discount.ts
|
|
1837
|
-
import Cookies2 from "js-cookie";
|
|
1838
|
-
var EnableDiscount = async ({ product, consumer, healthProfessional }) => {
|
|
1839
|
-
const tenant_id = Cookies2.get("tenant_id");
|
|
1840
|
-
if (!tenant_id) {
|
|
1841
|
-
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
1842
|
-
}
|
|
1843
|
-
if (!consumer) {
|
|
1844
|
-
throw new Error(`Consumer information is required`);
|
|
1845
|
-
}
|
|
1846
|
-
if (!healthProfessional) {
|
|
1847
|
-
throw new Error(`Health professional information is required`);
|
|
1848
|
-
}
|
|
1849
|
-
if (!product) {
|
|
1850
|
-
throw new Error(`Product information is required`);
|
|
1851
|
-
}
|
|
1852
|
-
try {
|
|
1853
|
-
const response = await fetch(
|
|
1854
|
-
`${getEnv("VITE_API_URL")}/api/discount.ts`,
|
|
1855
|
-
{
|
|
1856
|
-
method: "POST",
|
|
1857
|
-
headers: {
|
|
1858
|
-
"Content-Type": "application/json",
|
|
1859
|
-
"Accept": "application/json",
|
|
1860
|
-
"Authorization": `Bearer ${Cookies2.get("pbm-token")}`
|
|
1861
|
-
},
|
|
1862
|
-
body: JSON.stringify({
|
|
1863
|
-
tenant_id,
|
|
1864
|
-
product,
|
|
1865
|
-
table_id: Cookies2.get("current-table-id"),
|
|
1866
|
-
local_hour: Cookies2.get("current-local-hour"),
|
|
1867
|
-
consumer,
|
|
1868
|
-
healthProfessional
|
|
1869
|
-
})
|
|
1870
|
-
}
|
|
1871
|
-
);
|
|
1872
|
-
const data = await response.json();
|
|
1873
|
-
if (!data.success) {
|
|
1874
|
-
throw new Error("PBMLOG: Enable Discount Failed!");
|
|
1875
|
-
}
|
|
1876
|
-
Cookies2.set("current-central-number", data.product[0].centralNumber.toString(), {
|
|
1877
|
-
secure: true,
|
|
1878
|
-
sameSite: "Strict",
|
|
1879
|
-
expires: 1
|
|
1880
|
-
});
|
|
1881
|
-
Cookies2.set("current-term-code", data.product[0].activationFields.acceptLgpd.termCode.value.toString(), {
|
|
1882
|
-
secure: true,
|
|
1883
|
-
sameSite: "Strict",
|
|
1884
|
-
expires: 1
|
|
1885
|
-
});
|
|
1886
|
-
return data;
|
|
1887
|
-
} catch (error) {
|
|
1888
|
-
console.error("Error during enable discount:", error);
|
|
1889
|
-
return { success: false, error: "Authorization failed" };
|
|
1890
|
-
}
|
|
1891
|
-
};
|
|
1892
|
-
|
|
1893
|
-
// src/services/activate.ts
|
|
1894
|
-
import Cookies3 from "js-cookie";
|
|
1895
|
-
var Activate = async ({ product, consumer, healthProfessional }) => {
|
|
1896
|
-
const tenant_id = Cookies3.get("tenant_id");
|
|
1897
|
-
if (!tenant_id) {
|
|
1898
|
-
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
1899
|
-
}
|
|
1900
|
-
if (!consumer) {
|
|
1901
|
-
throw new Error(`Consumer information is required`);
|
|
1902
|
-
}
|
|
1903
|
-
if (!healthProfessional) {
|
|
1904
|
-
throw new Error(`Health professional information is required`);
|
|
1905
|
-
}
|
|
1906
|
-
if (!product) {
|
|
1907
|
-
throw new Error(`Product information is required`);
|
|
1908
|
-
}
|
|
1909
|
-
try {
|
|
1910
|
-
const response = await fetch(
|
|
1911
|
-
`${getEnv("VITE_API_URL")}/api/activate.ts`,
|
|
1912
|
-
{
|
|
1913
|
-
method: "POST",
|
|
1914
|
-
headers: {
|
|
1915
|
-
"Content-Type": "application/json",
|
|
1916
|
-
"Accept": "application/json",
|
|
1917
|
-
"Authorization": `Bearer ${Cookies3.get("pbm-token")}`
|
|
1918
|
-
},
|
|
1919
|
-
body: JSON.stringify({
|
|
1920
|
-
tenant_id,
|
|
1921
|
-
product,
|
|
1922
|
-
table_id: Cookies3.get("current-table-id"),
|
|
1923
|
-
local_hour: Cookies3.get("current-local-hour"),
|
|
1924
|
-
central_number: Cookies3.get("current-central-number"),
|
|
1925
|
-
consumer,
|
|
1926
|
-
healthProfessional,
|
|
1927
|
-
acceptLgpd: {
|
|
1928
|
-
evidenceType: "SITE",
|
|
1929
|
-
evidence: "VSTOSITE",
|
|
1930
|
-
termCode: Cookies3.get("current-term-code")
|
|
1931
|
-
}
|
|
1932
|
-
})
|
|
1933
|
-
}
|
|
1934
|
-
);
|
|
1935
|
-
const data = await response.json();
|
|
1936
|
-
if (!data.success) {
|
|
1937
|
-
throw new Error("PBMLOG: Activate Failed!");
|
|
1938
|
-
}
|
|
1939
|
-
return data;
|
|
1940
|
-
} catch (error) {
|
|
1941
|
-
console.error("Error during activate:", error);
|
|
1942
|
-
return { success: false, error: "Authorization failed" };
|
|
1943
|
-
}
|
|
1944
|
-
};
|
|
1945
|
-
|
|
1946
|
-
// src/components/Modals/CustomerNotRegistered/StepAcceptancesForm.tsx
|
|
1947
|
-
import { jsx as jsx21, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
1948
|
-
var StepAcceptancesForm = ({
|
|
1949
|
-
onBack,
|
|
1950
|
-
onDone,
|
|
1951
|
-
securityNumber
|
|
1952
|
-
}) => {
|
|
1953
|
-
const { acceptances, setAcceptances } = usePBMForm();
|
|
1954
|
-
const { targetProduct, cardID } = usePBMStore();
|
|
1955
|
-
const [errors, setErrors] = useState7({});
|
|
1956
|
-
const [loading, setLoading] = useState7(false);
|
|
1957
|
-
const data = usePBMForm.getState();
|
|
1958
|
-
const validate = () => {
|
|
1959
|
-
const e = {};
|
|
1960
|
-
if (!acceptances.acceptsPrivacyTermsLGPD)
|
|
1961
|
-
e.lgpd = "\xC9 obrigat\xF3rio aceitar os termos de privacidade (LGPD).";
|
|
1962
|
-
setErrors(e);
|
|
1963
|
-
return Object.keys(e).length === 0;
|
|
1964
|
-
};
|
|
1965
|
-
const activateConsumer = async (PAYLOAD) => {
|
|
1966
|
-
try {
|
|
1967
|
-
const response = await Activate(PAYLOAD);
|
|
1968
|
-
console.log("Activate response:", response);
|
|
1969
|
-
} catch (error) {
|
|
1970
|
-
console.error("Error during consumer activation:", error);
|
|
1971
|
-
}
|
|
1972
|
-
};
|
|
1973
|
-
const handleSubmit = async () => {
|
|
1974
|
-
if (!validate()) return;
|
|
1975
|
-
setLoading(true);
|
|
1976
|
-
if (!targetProduct) {
|
|
1977
|
-
console.error("No target product found in PBM store.");
|
|
1978
|
-
setLoading(false);
|
|
1979
|
-
return;
|
|
1980
|
-
}
|
|
1981
|
-
const phone = data.personalData.phone.replace(/\D/g, "");
|
|
1982
|
-
const ddd = phone.slice(0, 2);
|
|
1983
|
-
const cellphone = phone.slice(2);
|
|
1984
|
-
const PAYLOAD = {
|
|
1985
|
-
consumer: {
|
|
1986
|
-
holderId: securityNumber,
|
|
1987
|
-
cardId: cardID || "",
|
|
1988
|
-
name: data.personalData.name,
|
|
1989
|
-
email: data.personalData.email,
|
|
1990
|
-
birthdate: data.personalData.birthday,
|
|
1991
|
-
genre: data.genderResponsibility.gender,
|
|
1992
|
-
postalCode: data.address.postalcode.replace(/\D/g, ""),
|
|
1993
|
-
stateCode: data.address.uf || "",
|
|
1994
|
-
cityName: data.address.city || "",
|
|
1995
|
-
cityRegion: data.address.neighborhood || "",
|
|
1996
|
-
addressType: "casa",
|
|
1997
|
-
streetAddress: data.address.street || "",
|
|
1998
|
-
addressNumber: data.address.number || "",
|
|
1999
|
-
addressAdditionalInformation: data.address.complement || "",
|
|
2000
|
-
DDDcellPhone: ddd,
|
|
2001
|
-
cellphone,
|
|
2002
|
-
acceptInformativeMaterial: acceptances.acceptsMail ? "S" : "N",
|
|
2003
|
-
acceptMail: acceptances.acceptsMail ? "S" : "N",
|
|
2004
|
-
acceptEmail: acceptances.acceptsEmail ? "S" : "N",
|
|
2005
|
-
acceptCalls: acceptances.acceptPhone ? "S" : "N",
|
|
2006
|
-
acceptSMS: acceptances.acceptsSms ? "S" : "N",
|
|
2007
|
-
acceptTerm: acceptances.acceptsPrivacyTermsLGPD ? "S" : "N",
|
|
2008
|
-
acceptWhatsApp: "N"
|
|
2009
|
-
},
|
|
2010
|
-
healthProfessional: {
|
|
2011
|
-
id: data.doctor.register,
|
|
2012
|
-
stateCode: data.doctor.state,
|
|
2013
|
-
type: data.doctor.typeCredential,
|
|
2014
|
-
name: data.doctor.doctorName
|
|
2015
|
-
},
|
|
2016
|
-
product: {
|
|
2017
|
-
id: targetProduct.id,
|
|
2018
|
-
ean: targetProduct.ean,
|
|
2019
|
-
requestedQuantity: targetProduct.requestedQuantity,
|
|
2020
|
-
listPrice: targetProduct.listPrice,
|
|
2021
|
-
netPrice: targetProduct.netPrice
|
|
2022
|
-
}
|
|
2023
|
-
};
|
|
2024
|
-
try {
|
|
2025
|
-
const response = await EnableDiscount(PAYLOAD);
|
|
2026
|
-
if (response.success) {
|
|
2027
|
-
await activateConsumer(PAYLOAD);
|
|
2028
|
-
} else {
|
|
2029
|
-
console.error("Failed to enable discount:", response);
|
|
2030
|
-
}
|
|
2031
|
-
onDone();
|
|
2032
|
-
} catch {
|
|
2033
|
-
console.error("An error occurred while submitting acceptances data.");
|
|
2034
|
-
} finally {
|
|
2035
|
-
setLoading(false);
|
|
2036
|
-
}
|
|
2037
|
-
};
|
|
2038
|
-
return /* @__PURE__ */ jsxs17("div", { className: "flex flex-col gap-3", children: [
|
|
2039
|
-
/* @__PURE__ */ jsx21("p", { className: "text-xs text-gray-500 mb-1", children: "Selecione como deseja receber comunica\xE7\xF5es:" }),
|
|
2040
|
-
/* @__PURE__ */ jsx21(
|
|
2041
|
-
CheckRow_default,
|
|
2042
|
-
{
|
|
2043
|
-
label: "Aceito receber contato por telefone",
|
|
2044
|
-
checked: acceptances.acceptPhone,
|
|
2045
|
-
onChange: (v) => setAcceptances({ acceptPhone: v })
|
|
2046
|
-
}
|
|
2047
|
-
),
|
|
2048
|
-
/* @__PURE__ */ jsx21(
|
|
2049
|
-
CheckRow_default,
|
|
2050
|
-
{
|
|
2051
|
-
label: "Aceito receber SMS",
|
|
2052
|
-
checked: acceptances.acceptsSms,
|
|
2053
|
-
onChange: (v) => setAcceptances({ acceptsSms: v })
|
|
2054
|
-
}
|
|
2055
|
-
),
|
|
2056
|
-
/* @__PURE__ */ jsx21(
|
|
2057
|
-
CheckRow_default,
|
|
2058
|
-
{
|
|
2059
|
-
label: "Aceito receber e-mails",
|
|
2060
|
-
checked: acceptances.acceptsEmail,
|
|
2061
|
-
onChange: (v) => setAcceptances({ acceptsEmail: v })
|
|
2062
|
-
}
|
|
2063
|
-
),
|
|
2064
|
-
/* @__PURE__ */ jsx21(
|
|
2065
|
-
CheckRow_default,
|
|
2066
|
-
{
|
|
2067
|
-
label: "Aceito receber correspond\xEAncias por correio",
|
|
2068
|
-
checked: acceptances.acceptsMail,
|
|
2069
|
-
onChange: (v) => setAcceptances({ acceptsMail: v })
|
|
2070
|
-
}
|
|
2071
|
-
),
|
|
2072
|
-
/* @__PURE__ */ jsxs17("div", { className: "mt-1", children: [
|
|
2073
|
-
/* @__PURE__ */ jsx21(
|
|
2074
|
-
CheckRow_default,
|
|
2075
|
-
{
|
|
2076
|
-
label: "Li e aceito os Termos de Privacidade (LGPD)",
|
|
2077
|
-
checked: acceptances.acceptsPrivacyTermsLGPD,
|
|
2078
|
-
onChange: (v) => {
|
|
2079
|
-
setAcceptances({ acceptsPrivacyTermsLGPD: v });
|
|
2080
|
-
setErrors({});
|
|
2081
|
-
},
|
|
2082
|
-
required: true,
|
|
2083
|
-
error: errors.lgpd
|
|
2084
|
-
}
|
|
2085
|
-
),
|
|
2086
|
-
errors.lgpd && /* @__PURE__ */ jsx21("span", { className: "text-xs text-red-500 mt-1 block pl-1", children: errors.lgpd })
|
|
2087
|
-
] }),
|
|
2088
|
-
/* @__PURE__ */ jsx21(
|
|
2089
|
-
StepActions_default,
|
|
2090
|
-
{
|
|
2091
|
-
onNext: handleSubmit,
|
|
2092
|
-
onBack,
|
|
2093
|
-
loading,
|
|
2094
|
-
nextLabel: "Concluir cadastro",
|
|
2095
|
-
isLast: true
|
|
2096
|
-
}
|
|
2097
|
-
)
|
|
2098
|
-
] });
|
|
2099
|
-
};
|
|
2100
|
-
var StepAcceptancesForm_default = StepAcceptancesForm;
|
|
2101
|
-
|
|
2102
|
-
// src/components/Modals/CustomerNotRegistered/Shared/StepProgress.tsx
|
|
2103
|
-
import classNames11 from "classnames";
|
|
2104
|
-
import { jsx as jsx22, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
2105
|
-
var STEP_LABELS = [
|
|
2106
|
-
"Dados Pessoais",
|
|
2107
|
-
"Endere\xE7o",
|
|
2108
|
-
"Perfil",
|
|
2109
|
-
"M\xE9dico",
|
|
2110
|
-
"Aceites"
|
|
2111
|
-
];
|
|
2112
|
-
var StepProgress = ({ current }) => /* @__PURE__ */ jsx22("div", { className: "flex items-center w-full justify-center mb-6", children: STEP_LABELS.map((label, i) => {
|
|
2113
|
-
const done = i < current;
|
|
2114
|
-
const active = i === current;
|
|
2115
|
-
return /* @__PURE__ */ jsxs18(
|
|
2116
|
-
"div",
|
|
2117
|
-
{
|
|
2118
|
-
className: "flex items-center w-full min-w-0 justify-center relative",
|
|
2119
|
-
children: [
|
|
2120
|
-
/* @__PURE__ */ jsxs18("div", { className: "flex flex-col items-center justify-center gap-1 shrink-0 z-10", children: [
|
|
2121
|
-
/* @__PURE__ */ jsx22(
|
|
2122
|
-
"div",
|
|
2123
|
-
{
|
|
2124
|
-
className: classNames11(
|
|
2125
|
-
"flex h-7 w-7 items-center justify-center rounded-full text-xs font-semibold transition-all",
|
|
2126
|
-
done ? "bg-emerald-600 text-white" : active ? "bg-(--pbm-primary) text-white ring-4 ring-(--pbm-primary)/15" : "bg-zinc-100 text-zinc-400"
|
|
2127
|
-
),
|
|
2128
|
-
children: done ? /* @__PURE__ */ jsx22("svg", { className: "h-3.5 w-3.5", viewBox: "0 0 12 10", fill: "none", children: /* @__PURE__ */ jsx22(
|
|
2129
|
-
"path",
|
|
2130
|
-
{
|
|
2131
|
-
d: "M1 5l4 4 6-8",
|
|
2132
|
-
stroke: "currentColor",
|
|
2133
|
-
strokeWidth: "2",
|
|
2134
|
-
strokeLinecap: "round",
|
|
2135
|
-
strokeLinejoin: "round"
|
|
2136
|
-
}
|
|
2137
|
-
) }) : i + 1
|
|
2138
|
-
}
|
|
2139
|
-
),
|
|
2140
|
-
/* @__PURE__ */ jsx22(
|
|
2141
|
-
"span",
|
|
2142
|
-
{
|
|
2143
|
-
className: classNames11(
|
|
2144
|
-
"text-[10px] font-medium whitespace-nowrap hidden sm:block",
|
|
2145
|
-
active ? "text-(--pbm-primary)" : done ? "text-emerald-600" : "text-zinc-400"
|
|
2146
|
-
),
|
|
2147
|
-
children: label
|
|
2148
|
-
}
|
|
2149
|
-
)
|
|
2150
|
-
] }),
|
|
2151
|
-
i < STEP_LABELS.length - 1 && /* @__PURE__ */ jsx22(
|
|
2152
|
-
"div",
|
|
2153
|
-
{
|
|
2154
|
-
className: classNames11(
|
|
2155
|
-
"h-0.5 w-full rounded transition-all absolute top-3.5 left-10",
|
|
2156
|
-
"bg-zinc-200"
|
|
2157
|
-
)
|
|
2158
|
-
}
|
|
2159
|
-
)
|
|
2160
|
-
]
|
|
2161
|
-
},
|
|
2162
|
-
i
|
|
2163
|
-
);
|
|
2164
|
-
}) });
|
|
2165
|
-
var StepProgress_default = StepProgress;
|
|
2166
|
-
|
|
2167
|
-
// src/components/Modals/CustomerNotRegistered/Shared/SuccessScreen.tsx
|
|
2168
|
-
import { jsx as jsx23, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
2169
|
-
var SuccessScreen = ({ onClose }) => /* @__PURE__ */ jsxs19("div", { className: "flex flex-col items-center gap-4 py-4 text-center", children: [
|
|
2170
|
-
/* @__PURE__ */ jsx23("div", { className: "flex h-16 w-16 items-center justify-center rounded-full bg-green-100", children: /* @__PURE__ */ jsx23("svg", { className: "h-8 w-8 text-green-500", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx23(
|
|
2171
|
-
"path",
|
|
2172
|
-
{
|
|
2173
|
-
d: "M5 13l4 4L19 7",
|
|
2174
|
-
stroke: "currentColor",
|
|
2175
|
-
strokeWidth: "2.5",
|
|
2176
|
-
strokeLinecap: "round",
|
|
2177
|
-
strokeLinejoin: "round"
|
|
2178
|
-
}
|
|
2179
|
-
) }) }),
|
|
2180
|
-
/* @__PURE__ */ jsxs19("div", { children: [
|
|
2181
|
-
/* @__PURE__ */ jsx23("h3", { className: "text-base font-semibold text-gray-800", children: "Cadastro conclu\xEDdo!" }),
|
|
2182
|
-
/* @__PURE__ */ jsx23("p", { className: "text-sm text-zinc-500 mt-1", children: "Voc\xEA j\xE1 pode aproveitar os benef\xEDcios de farm\xE1cia." })
|
|
2183
|
-
] }),
|
|
2184
|
-
/* @__PURE__ */ jsx23(
|
|
2185
|
-
"button",
|
|
2186
|
-
{
|
|
2187
|
-
onClick: onClose,
|
|
2188
|
-
className: "cursor-pointer mt-2 rounded-lg bg-(--primary-color) px-6 py-2.5 text-sm font-semibold text-white hover:bg-(--primary-color)/80 transition-all",
|
|
2189
|
-
children: "Fechar"
|
|
2190
|
-
}
|
|
2191
|
-
)
|
|
2192
|
-
] });
|
|
2193
|
-
var SuccessScreen_default = SuccessScreen;
|
|
2194
|
-
|
|
2195
|
-
// src/components/Modals/CustomerNotRegistered/index.tsx
|
|
2196
|
-
import { jsx as jsx24, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
2197
|
-
var CustomerNotRegistered = ({ ID }) => {
|
|
2198
|
-
const { modal, setModal } = useModal();
|
|
2199
|
-
const { securityNumber } = usePBMStore();
|
|
2200
|
-
const { resetForm, step, setStep } = usePBMForm();
|
|
2201
|
-
const [done, setDone] = useState8(false);
|
|
2202
|
-
const closeModal = () => {
|
|
2203
|
-
setModal({ id: "", open: false });
|
|
2204
|
-
setTimeout(() => {
|
|
2205
|
-
setStep(0);
|
|
2206
|
-
setDone(false);
|
|
2207
|
-
resetForm();
|
|
2208
|
-
}, 300);
|
|
2209
|
-
};
|
|
2210
|
-
const next = () => setStep(step + 1);
|
|
2211
|
-
const back = () => setStep(step - 1);
|
|
2212
|
-
const rawSecurityNumber = securityNumber.replace(/\D/g, "");
|
|
2213
|
-
const stepComponents = [
|
|
2214
|
-
/* @__PURE__ */ jsx24(StepPersonalDataForm_default, { securityNumber: rawSecurityNumber, onNext: next }),
|
|
2215
|
-
/* @__PURE__ */ jsx24(
|
|
2216
|
-
StepAddressForm_default,
|
|
2217
|
-
{
|
|
2218
|
-
securityNumber: rawSecurityNumber,
|
|
2219
|
-
onNext: next,
|
|
2220
|
-
onBack: back
|
|
2221
|
-
}
|
|
2222
|
-
),
|
|
2223
|
-
/* @__PURE__ */ jsx24(
|
|
2224
|
-
StepGenderForm_default,
|
|
2225
|
-
{
|
|
2226
|
-
securityNumber: rawSecurityNumber,
|
|
2227
|
-
onNext: next,
|
|
2228
|
-
onBack: back
|
|
2229
|
-
}
|
|
2230
|
-
),
|
|
2231
|
-
/* @__PURE__ */ jsx24(
|
|
2232
|
-
StepDoctorForm_default,
|
|
2233
|
-
{
|
|
2234
|
-
securityNumber: rawSecurityNumber,
|
|
2235
|
-
onNext: next,
|
|
2236
|
-
onBack: back
|
|
2237
|
-
}
|
|
2238
|
-
),
|
|
2239
|
-
/* @__PURE__ */ jsx24(
|
|
2240
|
-
StepAcceptancesForm_default,
|
|
2241
|
-
{
|
|
2242
|
-
securityNumber: rawSecurityNumber,
|
|
2243
|
-
onBack: back,
|
|
2244
|
-
onDone: () => setDone(true)
|
|
2245
|
-
}
|
|
2246
|
-
)
|
|
2247
|
-
];
|
|
2248
|
-
return /* @__PURE__ */ jsxs20(
|
|
2249
|
-
"main",
|
|
2250
|
-
{
|
|
2251
|
-
className: classNames12(
|
|
2252
|
-
"fixed inset-0 flex items-center justify-end z-50 flex-col transition-all shadow bg-black/40",
|
|
2253
|
-
{
|
|
2254
|
-
"opacity-100 pointer-events-auto": modal.id === ID && modal.open,
|
|
2255
|
-
"opacity-0 pointer-events-none": modal.id !== ID || !modal.open
|
|
2256
|
-
}
|
|
2257
|
-
),
|
|
2258
|
-
children: [
|
|
2259
|
-
/* @__PURE__ */ jsx24("div", { className: "absolute inset-0", onClick: closeModal }),
|
|
2260
|
-
/* @__PURE__ */ jsxs20("section", { className: "z-10 bg-white flex flex-col p-6 rounded-2xl w-full max-w-125 min-w-125 mx-4 shadow-xl max-h-[90vh] overflow-y-auto", children: [
|
|
2261
|
-
/* @__PURE__ */ jsxs20("div", { className: "flex items-center justify-between mb-4", children: [
|
|
2262
|
-
/* @__PURE__ */ jsx24(Title_default, { textSize: "18px", textAlign: "start", children: done ? "Tudo pronto!" : "Benef\xEDcio de Farm\xE1cia" }),
|
|
2263
|
-
/* @__PURE__ */ jsx24(
|
|
2264
|
-
"button",
|
|
2265
|
-
{
|
|
2266
|
-
onClick: closeModal,
|
|
2267
|
-
className: "flex h-7 w-7 cursor-pointer items-center justify-center rounded-full text-gray-400 hover:bg-gray-100 hover:text-gray-600 transition-all",
|
|
2268
|
-
children: /* @__PURE__ */ jsx24("svg", { className: "h-4 w-4", viewBox: "0 0 14 14", fill: "none", children: /* @__PURE__ */ jsx24(
|
|
2269
|
-
"path",
|
|
2270
|
-
{
|
|
2271
|
-
d: "M1 1l12 12M13 1L1 13",
|
|
2272
|
-
stroke: "currentColor",
|
|
2273
|
-
strokeWidth: "2",
|
|
2274
|
-
strokeLinecap: "round"
|
|
2275
|
-
}
|
|
2276
|
-
) })
|
|
2277
|
-
}
|
|
2278
|
-
)
|
|
2279
|
-
] }),
|
|
2280
|
-
!done && /* @__PURE__ */ jsx24(StepProgress_default, { current: step }),
|
|
2281
|
-
done ? /* @__PURE__ */ jsx24(SuccessScreen_default, { onClose: closeModal }) : stepComponents[step]
|
|
2282
|
-
] })
|
|
2283
|
-
]
|
|
2284
|
-
}
|
|
2285
|
-
);
|
|
2286
|
-
};
|
|
2287
|
-
var CustomerNotRegistered_default = CustomerNotRegistered;
|
|
2288
|
-
|
|
2289
|
-
// src/components/UI/Link/index.tsx
|
|
2290
|
-
import classNames13 from "classnames";
|
|
2291
|
-
|
|
2292
|
-
// src/utils/getParams.ts
|
|
2293
|
-
var getParams = (params) => {
|
|
2294
|
-
if (params === void 0) return "";
|
|
2295
|
-
return "?" + Object.keys(params).map((paramter) => paramter + "=" + params[paramter]).join("&");
|
|
2296
|
-
};
|
|
2297
|
-
|
|
2298
|
-
// src/components/UI/Link/index.tsx
|
|
2299
|
-
import { jsx as jsx25 } from "react/jsx-runtime";
|
|
2300
|
-
function Link(props) {
|
|
2301
|
-
const { setState } = usePBMStore();
|
|
2302
|
-
return /* @__PURE__ */ jsx25(
|
|
2303
|
-
"a",
|
|
2304
|
-
{
|
|
2305
|
-
...props,
|
|
2306
|
-
target: props.target || "_self",
|
|
2307
|
-
href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
|
|
2308
|
-
className: classNames13(
|
|
2309
|
-
"w-3xs cursor-pointer h-10 rounded-lg text-white text-sm font-semibold transition-colors flex items-center justify-center",
|
|
2310
|
-
props.className
|
|
2311
|
-
),
|
|
2312
|
-
style: { backgroundColor: "var(--pbm-primary)" },
|
|
2313
|
-
onMouseOver: (e) => e.currentTarget.style.backgroundColor = "var(--pbm-secondary)",
|
|
2314
|
-
onMouseOut: (e) => e.currentTarget.style.backgroundColor = "var(--pbm-primary)",
|
|
2315
|
-
"data-testid": "test_id_link",
|
|
2316
|
-
id: "link_pbm",
|
|
2317
|
-
onClick: () => setState("isEmpty"),
|
|
2318
|
-
children: props.children
|
|
2319
|
-
}
|
|
2320
|
-
);
|
|
2321
|
-
}
|
|
2322
|
-
var Link_default = Link;
|
|
2323
|
-
|
|
2324
|
-
// src/components/Modals/ShopperIsNotAuthenticated.tsx
|
|
2325
|
-
import classNames14 from "classnames";
|
|
2326
|
-
import { jsx as jsx26, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
2327
|
-
var ShopperIsNotAuthenticated = ({ ID }) => {
|
|
2328
|
-
const { customLoginUrl } = usePBMStore();
|
|
2329
|
-
const { modal, setModal } = useModal();
|
|
2330
|
-
return /* @__PURE__ */ jsxs21(
|
|
2331
|
-
"main",
|
|
2332
|
-
{
|
|
2333
|
-
className: classNames14(
|
|
2334
|
-
"fixed inset-0 flex items-center justify-center z-50 flex-col transition-all shadow bg-black/40",
|
|
2335
|
-
{
|
|
2336
|
-
"opacity-100 pointer-events-auto": modal.id === ID && modal.open,
|
|
2337
|
-
"opacity-0 pointer-events-none": modal.id != ID || !modal.open
|
|
2338
|
-
}
|
|
2339
|
-
),
|
|
2340
|
-
children: [
|
|
2341
|
-
/* @__PURE__ */ jsx26(
|
|
2342
|
-
"div",
|
|
2343
|
-
{
|
|
2344
|
-
className: "absolute inset-0",
|
|
2345
|
-
onClick: () => setModal({ id: "", open: false })
|
|
2346
|
-
}
|
|
2347
|
-
),
|
|
2348
|
-
/* @__PURE__ */ jsxs21("section", { className: "z-10 bg-white gap-2 flex-col items-center-safe justify-center-safe p-8 rounded-xl", children: [
|
|
2349
|
-
/* @__PURE__ */ jsx26(
|
|
2350
|
-
Title_default,
|
|
2351
|
-
{
|
|
2352
|
-
textColor: "tomato",
|
|
2353
|
-
textSize: "18px",
|
|
2354
|
-
textAlign: "center",
|
|
2355
|
-
className: "mb-2",
|
|
2356
|
-
children: "Opa! Parece que voc\xEA n\xE3o est\xE1 Logado"
|
|
2357
|
-
}
|
|
2358
|
-
),
|
|
2359
|
-
/* @__PURE__ */ jsxs21(Text_default, { className: "mb-2", textAlign: "center", children: [
|
|
2360
|
-
"Para aproveitar os benef\xEDcios \xE9 necess\xE1rio realizar o",
|
|
2361
|
-
" ",
|
|
2362
|
-
/* @__PURE__ */ jsx26("strong", { children: "Login" }),
|
|
2363
|
-
" ou ",
|
|
2364
|
-
/* @__PURE__ */ jsx26("strong", { children: "Cadastro" }),
|
|
2365
|
-
" no site!"
|
|
2366
|
-
] }),
|
|
2367
|
-
/* @__PURE__ */ jsxs21("section", { className: "flex items-center-safe justify-center-safe gap-4", children: [
|
|
2368
|
-
/* @__PURE__ */ jsx26(
|
|
2369
|
-
Button_default,
|
|
2370
|
-
{
|
|
2371
|
-
className: "bg-gray-600 hover:bg-gray-500",
|
|
2372
|
-
onClick: () => setModal({ id: "", open: false }),
|
|
2373
|
-
children: "Seguir sem Benef\xEDcios"
|
|
2374
|
-
}
|
|
2375
|
-
),
|
|
2376
|
-
/* @__PURE__ */ jsx26(Link_default, { href: customLoginUrl || "/login", children: "Aproveitar Benef\xEDcios" })
|
|
2377
|
-
] })
|
|
2378
|
-
] })
|
|
2379
|
-
]
|
|
2380
|
-
}
|
|
2381
|
-
);
|
|
2382
|
-
};
|
|
2383
|
-
var ShopperIsNotAuthenticated_default = ShopperIsNotAuthenticated;
|
|
2384
|
-
|
|
2385
|
-
// src/PBM.tsx
|
|
2386
|
-
import Skeleton from "@mui/material/Skeleton";
|
|
2387
|
-
|
|
2388
|
-
// src/hooks/useAppStartup.tsx
|
|
2389
|
-
import { useEffect as useEffect2, useState as useState9 } from "react";
|
|
2390
|
-
|
|
2391
|
-
// src/services/authorization.ts
|
|
2392
|
-
import Cookies4 from "js-cookie";
|
|
2393
|
-
var GetAuthorization = async ({ tenant_id }) => {
|
|
2394
|
-
if (!tenant_id) {
|
|
2395
|
-
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
2396
|
-
}
|
|
2397
|
-
try {
|
|
2398
|
-
const response = await fetch(
|
|
2399
|
-
`${getEnv("VITE_API_URL")}/api/token.ts`,
|
|
2400
|
-
{
|
|
2401
|
-
method: "POST",
|
|
2402
|
-
headers: {
|
|
2403
|
-
"Content-Type": "application/json",
|
|
2404
|
-
"Accept": "application/json"
|
|
2405
|
-
},
|
|
2406
|
-
body: JSON.stringify({ tenant_id })
|
|
2407
|
-
}
|
|
2408
|
-
);
|
|
2409
|
-
const data = await response.json();
|
|
2410
|
-
if (!data.success) {
|
|
2411
|
-
throw new Error("PBMLOG: Authorization failed!");
|
|
2412
|
-
}
|
|
2413
|
-
const SECONDS_IN_A_DAY = 86400;
|
|
2414
|
-
Cookies4.set("pbm-token", data.access_token, {
|
|
2415
|
-
secure: true,
|
|
2416
|
-
sameSite: "Strict",
|
|
2417
|
-
expires: data.expires_in / SECONDS_IN_A_DAY
|
|
2418
|
-
});
|
|
2419
|
-
Cookies4.set("tenant_id", tenant_id, {
|
|
2420
|
-
secure: true,
|
|
2421
|
-
sameSite: "Strict",
|
|
2422
|
-
expires: 7
|
|
2423
|
-
});
|
|
2424
|
-
return data;
|
|
2425
|
-
} catch (error) {
|
|
2426
|
-
console.error("Error during authorization:", error);
|
|
2427
|
-
return { success: false, error: "Authorization failed" };
|
|
2428
|
-
}
|
|
2429
|
-
};
|
|
2430
|
-
|
|
2431
|
-
// src/libs/zustand/useTheme.tsx
|
|
2432
|
-
import { createStore as createStore2 } from "zustand";
|
|
2433
|
-
import { useStore as useStore2 } from "zustand/react";
|
|
2434
|
-
var initialThemeState = {
|
|
2435
|
-
primaryColor: "#44c2c0",
|
|
2436
|
-
secondaryColor: "#339c9b",
|
|
2437
|
-
backgroundColor: "#ffffff",
|
|
2438
|
-
textColor: "#52525b",
|
|
2439
|
-
borderColor: "#44c2c0",
|
|
2440
|
-
inputOutlineColor: "transparent",
|
|
2441
|
-
inputOutlineFocusColor: "#323232",
|
|
2442
|
-
inputBackgroundColor: "#EDEDED",
|
|
2443
|
-
inputFocusBackgroundColor: "#EDEDED"
|
|
2444
|
-
};
|
|
2445
|
-
var themeStore = createStore2(
|
|
2446
|
-
(set) => ({
|
|
2447
|
-
...initialThemeState,
|
|
2448
|
-
setTheme: (theme) => set((state) => ({ ...state, ...theme }))
|
|
2449
|
-
})
|
|
2450
|
-
);
|
|
2451
|
-
function useTheme(selector) {
|
|
2452
|
-
return useStore2(
|
|
2453
|
-
themeStore,
|
|
2454
|
-
selector ?? ((state) => state)
|
|
2455
|
-
);
|
|
2456
|
-
}
|
|
2457
|
-
|
|
2458
|
-
// src/services/load-products-table.ts
|
|
2459
|
-
import Cookies5 from "js-cookie";
|
|
2460
|
-
|
|
2461
|
-
// src/utils/cleanupCacheTimestamp.ts
|
|
2462
|
-
var CLEANUP_HOUR = 2;
|
|
2463
|
-
var CLEANUP_MINUTE = 30;
|
|
2464
|
-
var cleanupCacheTimestamp = () => {
|
|
2465
|
-
const now = /* @__PURE__ */ new Date();
|
|
2466
|
-
const next = new Date(now);
|
|
2467
|
-
next.setHours(CLEANUP_HOUR, CLEANUP_MINUTE, 0, 0);
|
|
2468
|
-
if (next.getTime() <= now.getTime()) {
|
|
2469
|
-
next.setDate(next.getDate() + 1);
|
|
2470
|
-
}
|
|
2471
|
-
return next.getTime();
|
|
2472
|
-
};
|
|
2473
|
-
|
|
2474
|
-
// src/services/load-products-table.ts
|
|
2475
|
-
var memoryCache = /* @__PURE__ */ new Map();
|
|
2476
|
-
function getCacheKey(tenant_id) {
|
|
2477
|
-
return `load-products-table:${tenant_id}`;
|
|
2478
|
-
}
|
|
2479
|
-
function readCache(key) {
|
|
2480
|
-
const memEntry = memoryCache.get(key);
|
|
2481
|
-
if (memEntry && Date.now() < memEntry.expiresAt) {
|
|
2482
|
-
return memEntry.data;
|
|
2483
|
-
}
|
|
2484
|
-
try {
|
|
2485
|
-
const raw = localStorage.getItem(key);
|
|
2486
|
-
if (!raw) return null;
|
|
2487
|
-
const entry = JSON.parse(raw);
|
|
2488
|
-
if (Date.now() >= entry.expiresAt) {
|
|
2489
|
-
localStorage.removeItem(key);
|
|
2490
|
-
return null;
|
|
2491
|
-
}
|
|
2492
|
-
memoryCache.set(key, entry);
|
|
2493
|
-
return entry.data;
|
|
2494
|
-
} catch {
|
|
2495
|
-
return null;
|
|
2496
|
-
}
|
|
2497
|
-
}
|
|
2498
|
-
function writeCache(key, data) {
|
|
2499
|
-
const entry = { data, expiresAt: cleanupCacheTimestamp(), success: true };
|
|
2500
|
-
memoryCache.set(key, entry);
|
|
2501
|
-
localStorage.setItem(key, JSON.stringify(entry));
|
|
2502
|
-
}
|
|
2503
|
-
var LoadProductsTable = async ({ tenant_id }) => {
|
|
2504
|
-
if (!tenant_id) {
|
|
2505
|
-
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
2506
|
-
}
|
|
2507
|
-
const cacheKey = getCacheKey(tenant_id);
|
|
2508
|
-
const cached = readCache(cacheKey);
|
|
2509
|
-
if (cached) {
|
|
2510
|
-
const result2 = {
|
|
2511
|
-
data: cached,
|
|
2512
|
-
expiresAt: memoryCache.get(cacheKey).expiresAt,
|
|
2513
|
-
success: true
|
|
2514
|
-
};
|
|
2515
|
-
return result2;
|
|
2516
|
-
}
|
|
2517
|
-
const response = await fetch(
|
|
2518
|
-
`${getEnv("VITE_API_URL")}/api/load-tables.ts`,
|
|
2519
|
-
{
|
|
2520
|
-
method: "POST",
|
|
2521
|
-
headers: {
|
|
2522
|
-
"Content-Type": "application/json",
|
|
2523
|
-
"Accept": "application/json",
|
|
2524
|
-
"Authorization": `Bearer ${Cookies5.get("pbm-token")}`
|
|
2525
|
-
},
|
|
2526
|
-
body: JSON.stringify({ tenant_id })
|
|
2527
|
-
}
|
|
2528
|
-
);
|
|
2529
|
-
const data = await response.json();
|
|
2530
|
-
if (data.informativeText !== "Processamento aprovado") {
|
|
2531
|
-
throw new Error("PBMLOG: Load Products Table Failed!");
|
|
2532
|
-
}
|
|
2533
|
-
Cookies5.set("current-table-id", data.control.tableId, {
|
|
2534
|
-
secure: true,
|
|
2535
|
-
sameSite: "Strict",
|
|
2536
|
-
expires: 1
|
|
2537
|
-
});
|
|
2538
|
-
Cookies5.set("current-central-number", data.control.centralNumber.toString(), {
|
|
2539
|
-
secure: true,
|
|
2540
|
-
sameSite: "Strict",
|
|
2541
|
-
expires: 1
|
|
2542
|
-
});
|
|
2543
|
-
Cookies5.set("current-local-hour", data.local_hour, {
|
|
2544
|
-
secure: true,
|
|
2545
|
-
sameSite: "Strict",
|
|
2546
|
-
expires: 1
|
|
2547
|
-
});
|
|
2548
|
-
const formattedData = extractTableData(data.control.tableImage);
|
|
2549
|
-
writeCache(cacheKey, formattedData);
|
|
2550
|
-
const result = {
|
|
2551
|
-
data: formattedData,
|
|
2552
|
-
expiresAt: memoryCache.get(cacheKey).expiresAt,
|
|
2553
|
-
success: true
|
|
2554
|
-
};
|
|
2555
|
-
return result;
|
|
2556
|
-
};
|
|
2557
|
-
function extractTableData(tableImage) {
|
|
2558
|
-
const states = tableImage.map((s) => s.state);
|
|
2559
|
-
const cities = tableImage.flatMap((s) => s.cities.map((c) => c.city));
|
|
2560
|
-
const federalCodes = tableImage.flatMap((s) => s.cities.flatMap((c) => c.federalCodes.map((f) => f.federalCode)));
|
|
2561
|
-
const programNames = tableImage.flatMap((s) => s.cities.flatMap((c) => c.federalCodes.flatMap((f) => f.programNames.map((p) => p.programName))));
|
|
2562
|
-
const products = tableImage.flatMap((s) => s.cities.flatMap((c) => c.federalCodes.flatMap((f) => f.programNames.flatMap((p) => p.products.map((pr) => pr.ean)))));
|
|
2563
|
-
return { states, cities, federalCodes, programNames, products };
|
|
2564
|
-
}
|
|
2565
|
-
|
|
2566
|
-
// src/services/product.ts
|
|
2567
|
-
import Cookies6 from "js-cookie";
|
|
2568
|
-
var GetProduct = async ({ tenant_id, product }) => {
|
|
2569
|
-
if (!tenant_id) {
|
|
2570
|
-
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
2571
|
-
}
|
|
2572
|
-
if (!product) {
|
|
2573
|
-
throw new Error(`Product information is required`);
|
|
2574
|
-
}
|
|
2575
|
-
try {
|
|
2576
|
-
const response = await fetch(
|
|
2577
|
-
`${getEnv("VITE_API_URL")}/api/product.ts`,
|
|
2578
|
-
{
|
|
2579
|
-
method: "POST",
|
|
2580
|
-
headers: {
|
|
2581
|
-
"Content-Type": "application/json",
|
|
2582
|
-
"Accept": "application/json",
|
|
2583
|
-
"Authorization": `Bearer ${Cookies6.get("pbm-token")}`
|
|
2584
|
-
},
|
|
2585
|
-
body: JSON.stringify({
|
|
2586
|
-
tenant_id,
|
|
2587
|
-
product,
|
|
2588
|
-
table_id: Cookies6.get("current-table-id"),
|
|
2589
|
-
local_hour: Cookies6.get("current-local-hour")
|
|
2590
|
-
})
|
|
2591
|
-
}
|
|
2592
|
-
);
|
|
2593
|
-
const data = await response.json();
|
|
2594
|
-
if (!data.success) {
|
|
2595
|
-
throw new Error("PBMLOG: Get Product Failed!");
|
|
2596
|
-
}
|
|
2597
|
-
return data;
|
|
2598
|
-
} catch (error) {
|
|
2599
|
-
console.error("Error during get product:", error);
|
|
2600
|
-
return { success: false, error: "Get Product Failed" };
|
|
2601
|
-
}
|
|
2602
|
-
};
|
|
2603
|
-
|
|
2604
|
-
// src/hooks/useAppStartup.tsx
|
|
2605
|
-
var useAppStartup = (props) => {
|
|
2606
|
-
const {
|
|
2607
|
-
setTargetProduct,
|
|
2608
|
-
setBenefitsList,
|
|
2609
|
-
setIsAuthenticatedShopper,
|
|
2610
|
-
setCustomLoginUrl
|
|
2611
|
-
} = usePBMStore();
|
|
2612
|
-
const { setTheme } = useTheme();
|
|
2613
|
-
const [IsReady, setIsReady] = useState9(false);
|
|
2614
|
-
const [IsValid, setIsValid] = useState9(false);
|
|
2615
|
-
const [EanProductExist, setEanProductExist] = useState9(true);
|
|
2616
|
-
const fetchAuthorizationRequest = async () => {
|
|
2617
|
-
try {
|
|
2618
|
-
const response = await GetAuthorization({
|
|
2619
|
-
tenant_id: props.tenant_id
|
|
2620
|
-
});
|
|
2621
|
-
if (!response.success) {
|
|
2622
|
-
console.error("PBMLOG: Authorization failed!");
|
|
2623
|
-
}
|
|
2624
|
-
return response.success;
|
|
2625
|
-
} catch (error) {
|
|
2626
|
-
console.error("Error fetching authorization:", error);
|
|
2627
|
-
return false;
|
|
2628
|
-
}
|
|
2629
|
-
};
|
|
2630
|
-
const fetchValidateProduct = async () => {
|
|
2631
|
-
if (!props.target_product) {
|
|
2632
|
-
console.error("PBMLOG: Target product is not defined.");
|
|
2633
|
-
setEanProductExist(false);
|
|
2634
|
-
return false;
|
|
2635
|
-
}
|
|
2636
|
-
try {
|
|
2637
|
-
const response = await LoadProductsTable({ tenant_id: props.tenant_id });
|
|
2638
|
-
if (!response.success) {
|
|
2639
|
-
console.error("PBMLOG: Product validation failed!");
|
|
2640
|
-
return false;
|
|
2641
|
-
}
|
|
2642
|
-
if (response.data.products.includes(props.target_product.ean.toString())) {
|
|
2643
|
-
setEanProductExist(true);
|
|
2644
|
-
return true;
|
|
2645
|
-
}
|
|
2646
|
-
return false;
|
|
2647
|
-
} catch (error) {
|
|
2648
|
-
console.error("Error fetching product validation:", error);
|
|
2649
|
-
setEanProductExist(false);
|
|
2650
|
-
}
|
|
2651
|
-
return false;
|
|
2652
|
-
};
|
|
2653
|
-
const fetchProductHasEnableDiscount = async () => {
|
|
2654
|
-
try {
|
|
2655
|
-
if (!props.target_product) {
|
|
2656
|
-
console.error("PBMLOG: Target product is not defined.");
|
|
2657
|
-
setEanProductExist(false);
|
|
2658
|
-
return false;
|
|
2659
|
-
}
|
|
2660
|
-
const response = await GetProduct({
|
|
2661
|
-
tenant_id: props.tenant_id,
|
|
2662
|
-
product: props.target_product
|
|
2663
|
-
});
|
|
2664
|
-
if (!response.success) {
|
|
2665
|
-
console.error("PBMLOG: Product discount check failed!");
|
|
2666
|
-
setEanProductExist(false);
|
|
2667
|
-
return false;
|
|
2668
|
-
}
|
|
2669
|
-
if (!response.product || response.product.length === 0) {
|
|
2670
|
-
console.error("PBMLOG: Product not found in discount check!");
|
|
2671
|
-
setEanProductExist(false);
|
|
2672
|
-
return false;
|
|
2673
|
-
}
|
|
2674
|
-
setTargetProduct({
|
|
2675
|
-
...response.product[0],
|
|
2676
|
-
requestedQuantity: "1",
|
|
2677
|
-
listPrice: formaters.priceToInteger(props.target_product.listPrice),
|
|
2678
|
-
netPrice: formaters.priceToInteger(props.target_product.netPrice)
|
|
2679
|
-
});
|
|
2680
|
-
setBenefitsList(
|
|
2681
|
-
response.product.map((prod) => ({
|
|
2682
|
-
...prod,
|
|
2683
|
-
listPrice: props.target_product.listPrice,
|
|
2684
|
-
netPrice: props.target_product.netPrice
|
|
2685
|
-
}))
|
|
2686
|
-
);
|
|
2687
|
-
setIsAuthenticatedShopper(props.is_authenticated_shopper);
|
|
2688
|
-
setCustomLoginUrl(props.custom_login_url);
|
|
2689
|
-
setEanProductExist(true);
|
|
2690
|
-
return true;
|
|
2691
|
-
} catch (error) {
|
|
2692
|
-
console.error(error);
|
|
2693
|
-
setEanProductExist(false);
|
|
2694
|
-
return false;
|
|
2695
|
-
}
|
|
2696
|
-
};
|
|
2697
|
-
useEffect2(() => {
|
|
2698
|
-
let isMounted = true;
|
|
2699
|
-
const startup = async () => {
|
|
2700
|
-
if (props.theme) {
|
|
2701
|
-
setTheme(props.theme);
|
|
2702
|
-
}
|
|
2703
|
-
const isAuthorized = await fetchAuthorizationRequest();
|
|
2704
|
-
if (!isAuthorized || !isMounted) return;
|
|
2705
|
-
const isValidProduct = await Promise.all(
|
|
2706
|
-
[fetchValidateProduct(), fetchProductHasEnableDiscount()].filter(
|
|
2707
|
-
Boolean
|
|
2708
|
-
)
|
|
2709
|
-
).then((results) => results.every(Boolean));
|
|
2710
|
-
setIsValid(isValidProduct);
|
|
2711
|
-
if (!isValidProduct || !isMounted) return;
|
|
2712
|
-
if (isMounted) {
|
|
2713
|
-
setIsReady(true);
|
|
2714
|
-
}
|
|
2715
|
-
};
|
|
2716
|
-
startup();
|
|
2717
|
-
return () => {
|
|
2718
|
-
isMounted = false;
|
|
2719
|
-
};
|
|
2720
|
-
}, [props.tenant_id]);
|
|
2721
|
-
return { IsReady, IsValid, EanProductExist };
|
|
2722
|
-
};
|
|
2723
|
-
var useAppStartup_default = useAppStartup;
|
|
2724
|
-
|
|
2725
|
-
// src/PBM.tsx
|
|
2726
|
-
import { useTransition } from "react";
|
|
2727
|
-
import { Fragment as Fragment3, jsx as jsx27, jsxs as jsxs22 } from "react/jsx-runtime";
|
|
2728
|
-
function PBM(props) {
|
|
2729
|
-
const { state } = usePBMStore();
|
|
2730
|
-
const { IsReady, EanProductExist, IsValid } = useAppStartup_default(props);
|
|
2731
|
-
const { setErrorMessage } = useError();
|
|
2732
|
-
const theme = useTheme();
|
|
2733
|
-
const [isPending, startTransition] = useTransition();
|
|
2734
|
-
if (!IsValid) return;
|
|
2735
|
-
if (!IsReady) {
|
|
2736
|
-
return /* @__PURE__ */ jsx27(
|
|
2737
|
-
Skeleton,
|
|
2738
|
-
{
|
|
2739
|
-
variant: "rectangular",
|
|
2740
|
-
style: { borderRadius: "12px" },
|
|
2741
|
-
width: 460,
|
|
2742
|
-
height: 358
|
|
2743
|
-
}
|
|
2744
|
-
);
|
|
2745
|
-
}
|
|
2746
|
-
if (!EanProductExist) {
|
|
2747
|
-
setErrorMessage(
|
|
2748
|
-
"O produto n\xE3o foi encontrado no sistema. Por favor, tente novamente mais tarde ou contate o suporte."
|
|
2749
|
-
);
|
|
2750
|
-
return /* @__PURE__ */ jsx27("div", { id: "pbm-library-root", children: /* @__PURE__ */ jsx27(ErrorToApplyBenefits_default, {}) });
|
|
2751
|
-
}
|
|
2752
|
-
return /* @__PURE__ */ jsxs22(
|
|
2753
|
-
"div",
|
|
2754
|
-
{
|
|
2755
|
-
id: "pbm-library-root",
|
|
2756
|
-
style: {
|
|
2757
|
-
"--pbm-primary": theme.primaryColor,
|
|
2758
|
-
"--pbm-secondary": theme.secondaryColor,
|
|
2759
|
-
"--pbm-bg": theme.backgroundColor,
|
|
2760
|
-
"--pbm-text": theme.textColor,
|
|
2761
|
-
"--pbm-border": theme.borderColor,
|
|
2762
|
-
"--pbm-outline-color": theme.inputOutlineColor,
|
|
2763
|
-
"--pbm-outline-focus-color": theme.inputOutlineFocusColor,
|
|
2764
|
-
"--pbm-input-focus-background": theme.inputFocusBackgroundColor,
|
|
2765
|
-
"--pbm-input-background": theme.inputBackgroundColor
|
|
2766
|
-
},
|
|
2767
|
-
children: [
|
|
2768
|
-
/* @__PURE__ */ jsxs22(Container_default, { variant: "main", children: [
|
|
2769
|
-
/* @__PURE__ */ jsx27(Header_default, {}),
|
|
2770
|
-
/* @__PURE__ */ jsx27(Container_default, { variant: "simple", children: isPending ? /* @__PURE__ */ jsx27(Loading_default, {}) : /* @__PURE__ */ jsxs22(Fragment3, { children: [
|
|
2771
|
-
state === "isEmpty" && /* @__PURE__ */ jsx27(Form_default, { startTransition }),
|
|
2772
|
-
state === "isInvalid" && /* @__PURE__ */ jsx27(SecurityNumberInvalid_default, {}),
|
|
2773
|
-
state === "isRegistered" && /* @__PURE__ */ jsx27(SecurityNumberRegitered_default, {}),
|
|
2774
|
-
(state === "isActivated" || state === "isPreview") && /* @__PURE__ */ jsx27(BenefitsTable_default, {}),
|
|
2775
|
-
state === "isError" && /* @__PURE__ */ jsx27(ErrorToApplyBenefits_default, {})
|
|
2776
|
-
] }) })
|
|
2777
|
-
] }),
|
|
2778
|
-
/* @__PURE__ */ jsx27(ShopperIsNotAuthenticated_default, { ID: "ShopperIsNotAuthenticated" }),
|
|
2779
|
-
/* @__PURE__ */ jsx27(CustomerNotRegistered_default, { ID: "CustomerNotRegistered" })
|
|
2780
|
-
]
|
|
2781
|
-
}
|
|
2782
|
-
);
|
|
2783
|
-
}
|
|
2784
|
-
var PBM_default = PBM;
|
|
2785
|
-
export {
|
|
2786
|
-
PBM_default as PBM,
|
|
2787
|
-
usePBMStore
|
|
2788
|
-
};
|
|
2789
|
-
//# sourceMappingURL=index.js.map
|