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