@agrada_digital/pbm 0.0.115 → 0.0.116
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.css +13 -213
- package/dist/index.d.ts +36 -18
- package/dist/index.js +914 -1152
- package/dist/vanilla.js +29 -39
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -50,6 +50,7 @@ var initialPBMState = {
|
|
|
50
50
|
grossPrice: 0
|
|
51
51
|
},
|
|
52
52
|
benefitsEnabled: true,
|
|
53
|
+
benefitsList: null,
|
|
53
54
|
targetProduct: null,
|
|
54
55
|
campaign: "pbm_campaign",
|
|
55
56
|
isAuthenticatedShopper: false,
|
|
@@ -67,7 +68,8 @@ var createPBMStore = (set) => ({
|
|
|
67
68
|
setIsAuthenticatedShopper: (isAuthenticatedShopper) => set({ isAuthenticatedShopper }),
|
|
68
69
|
setCustomLoginUrl: (customLoginUrl) => set({ customLoginUrl }),
|
|
69
70
|
setCardID: (cardID) => set({ cardID }),
|
|
70
|
-
setBenefitsEnabled: (benefitsEnabled) => set({ benefitsEnabled })
|
|
71
|
+
setBenefitsEnabled: (benefitsEnabled) => set({ benefitsEnabled }),
|
|
72
|
+
setBenefitsList: (benefitsList) => set({ benefitsList })
|
|
71
73
|
});
|
|
72
74
|
var pbmStore = createStore(createPBMStore);
|
|
73
75
|
function usePBMStore(selector) {
|
|
@@ -84,44 +86,6 @@ import { ArrowRight } from "lucide-react";
|
|
|
84
86
|
import classNames2 from "classnames";
|
|
85
87
|
import { Activity, useState } from "react";
|
|
86
88
|
|
|
87
|
-
// src/services/lookup-customer.ts
|
|
88
|
-
import Cookies from "js-cookie";
|
|
89
|
-
|
|
90
|
-
// src/services/helper.ts
|
|
91
|
-
var getEnv = (key) => {
|
|
92
|
-
if (typeof import.meta !== "undefined") {
|
|
93
|
-
return import.meta.env?.[key];
|
|
94
|
-
}
|
|
95
|
-
if (typeof process !== "undefined") {
|
|
96
|
-
return process.env?.[key];
|
|
97
|
-
}
|
|
98
|
-
return void 0;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// src/services/lookup-customer.ts
|
|
102
|
-
var LookupCustomer = async ({ DOCUMENT }) => {
|
|
103
|
-
const API_URL = getEnv("VITE_API_URL");
|
|
104
|
-
const AUTH_TOKEN = Cookies.get("pbm-token");
|
|
105
|
-
if (!AUTH_TOKEN) {
|
|
106
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
107
|
-
}
|
|
108
|
-
const response = await fetch(`${API_URL}/programregistration/${DOCUMENT}`, {
|
|
109
|
-
method: "GET",
|
|
110
|
-
headers: {
|
|
111
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
112
|
-
"Content-Type": "application/json"
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
if (response.status === 404) {
|
|
116
|
-
return {
|
|
117
|
-
...await response.json(),
|
|
118
|
-
success: false
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
const dataResponse = await response.json();
|
|
122
|
-
return dataResponse;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
89
|
// src/libs/zustand/useModal.tsx
|
|
126
90
|
import { create } from "zustand";
|
|
127
91
|
var initialModalState = {
|
|
@@ -144,58 +108,80 @@ var formatPhone = (value) => value.replace(/\D/g, "").slice(0, 11).replace(/^(\d
|
|
|
144
108
|
var formatCEP = (value) => value.replace(/\D/g, "").slice(0, 8).replace(/^(\d{5})(\d{0,3})/, "$1-$2");
|
|
145
109
|
var maskCPF = (value) => value.replace(/\D/g, "").replace(/(\d{3})(\d{3})(\d{3})(\d{2})/, "$1.$2.$3-$4");
|
|
146
110
|
var formatPrice = (price) => Number(String(price).replace(",", "."));
|
|
111
|
+
var transformPrice = (price) => {
|
|
112
|
+
const priceString = String(price);
|
|
113
|
+
const cents = priceString.slice(-2);
|
|
114
|
+
const reais = priceString.slice(0, -2) || "0";
|
|
115
|
+
return Number(`${reais}.${cents}`);
|
|
116
|
+
};
|
|
117
|
+
var transformPorcent = (porcent) => {
|
|
118
|
+
const post = porcent.slice(-2);
|
|
119
|
+
const pre = porcent.slice(0, -2) || "0";
|
|
120
|
+
return Number(`${pre}.${post}`);
|
|
121
|
+
};
|
|
147
122
|
var formaters = {
|
|
148
123
|
phone: (value) => formatPhone(value),
|
|
149
124
|
cep: (value) => formatCEP(value),
|
|
150
125
|
cpf: (value) => maskCPF(value),
|
|
151
|
-
price: (price) => formatPrice(price)
|
|
126
|
+
price: (price) => formatPrice(price),
|
|
127
|
+
transformPrice: (price) => transformPrice(price),
|
|
128
|
+
transformPorcent: (porcent) => transformPorcent(porcent)
|
|
152
129
|
};
|
|
153
130
|
|
|
154
|
-
// src/
|
|
155
|
-
import
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
},
|
|
167
|
-
genderResponsibility: { gender: "", patient: null },
|
|
168
|
-
doctor: { typeCredential: "CRM", register: "", state: "", doctorName: "" },
|
|
169
|
-
acceptances: {
|
|
170
|
-
acceptPhone: false,
|
|
171
|
-
acceptsSms: false,
|
|
172
|
-
acceptsEmail: false,
|
|
173
|
-
acceptsMail: false,
|
|
174
|
-
acceptsPrivacyTermsLGPD: false
|
|
175
|
-
},
|
|
176
|
-
step: 0
|
|
131
|
+
// src/services/lookup-consumer.ts
|
|
132
|
+
import Cookies from "js-cookie";
|
|
133
|
+
|
|
134
|
+
// src/services/helper.ts
|
|
135
|
+
var getEnv = (key) => {
|
|
136
|
+
if (typeof import.meta !== "undefined") {
|
|
137
|
+
return import.meta.env?.[key];
|
|
138
|
+
}
|
|
139
|
+
if (typeof process !== "undefined") {
|
|
140
|
+
return process.env?.[key];
|
|
141
|
+
}
|
|
142
|
+
return void 0;
|
|
177
143
|
};
|
|
178
|
-
var usePBMFormStore = create2((set) => ({
|
|
179
|
-
...initialPBMFormState,
|
|
180
|
-
setPersonalData: (data) => set((s) => ({ personalData: { ...s.personalData, ...data } })),
|
|
181
|
-
setAddress: (data) => set((s) => ({ address: { ...s.address, ...data } })),
|
|
182
|
-
setGenderResponsibility: (data) => set((s) => ({
|
|
183
|
-
genderResponsibility: { ...s.genderResponsibility, ...data }
|
|
184
|
-
})),
|
|
185
|
-
setDoctor: (data) => set((s) => ({ doctor: { ...s.doctor, ...data } })),
|
|
186
|
-
setAcceptances: (data) => set((s) => ({ acceptances: { ...s.acceptances, ...data } })),
|
|
187
|
-
setStep: (step) => set({ step }),
|
|
188
|
-
resetForm: () => set(initialPBMFormState)
|
|
189
|
-
}));
|
|
190
|
-
var usePBMForm = usePBMFormStore;
|
|
191
144
|
|
|
192
|
-
// src/
|
|
193
|
-
var
|
|
194
|
-
"
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
145
|
+
// src/services/lookup-consumer.ts
|
|
146
|
+
var LookupConsumer = async ({ product, consumer }) => {
|
|
147
|
+
const tenant_id = Cookies.get("tenant_id");
|
|
148
|
+
if (!tenant_id) {
|
|
149
|
+
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
150
|
+
}
|
|
151
|
+
if (!consumer || !consumer.holderId) {
|
|
152
|
+
throw new Error(`Consumer holderId information is required`);
|
|
153
|
+
}
|
|
154
|
+
if (!product) {
|
|
155
|
+
throw new Error(`Product information is required`);
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const response = await fetch(
|
|
159
|
+
`${getEnv("VITE_API_URL")}/api/lookup-consumer.ts`,
|
|
160
|
+
{
|
|
161
|
+
method: "POST",
|
|
162
|
+
headers: {
|
|
163
|
+
"Content-Type": "application/json",
|
|
164
|
+
"Accept": "application/json",
|
|
165
|
+
"Authorization": `Bearer ${Cookies.get("pbm-token")}`
|
|
166
|
+
},
|
|
167
|
+
body: JSON.stringify({
|
|
168
|
+
tenant_id,
|
|
169
|
+
product,
|
|
170
|
+
table_id: Cookies.get("current-table-id"),
|
|
171
|
+
local_hour: Cookies.get("current-local-hour"),
|
|
172
|
+
consumer
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
);
|
|
176
|
+
const data = await response.json();
|
|
177
|
+
if (!data.success) {
|
|
178
|
+
throw new Error("PBMLOG: Enable Discount Failed!");
|
|
179
|
+
}
|
|
180
|
+
return data;
|
|
181
|
+
} catch (error) {
|
|
182
|
+
console.error("Error during enable discount:", error);
|
|
183
|
+
return { success: false, error: "Authorization failed" };
|
|
184
|
+
}
|
|
199
185
|
};
|
|
200
186
|
|
|
201
187
|
// src/components/Form/index.tsx
|
|
@@ -204,7 +190,6 @@ function Form({ startTransition }) {
|
|
|
204
190
|
const store = usePBMStore();
|
|
205
191
|
const [showCardIDField, setShowCardIDField] = useState(false);
|
|
206
192
|
const { setModal } = useModal();
|
|
207
|
-
const { setStep } = usePBMForm();
|
|
208
193
|
const {
|
|
209
194
|
handleSubmit,
|
|
210
195
|
register,
|
|
@@ -220,58 +205,12 @@ function Form({ startTransition }) {
|
|
|
220
205
|
coupon: ""
|
|
221
206
|
}
|
|
222
207
|
});
|
|
223
|
-
const
|
|
224
|
-
customer
|
|
225
|
-
}) => {
|
|
226
|
-
const data = customer.data;
|
|
227
|
-
if (data.registration?.personal_data === null) {
|
|
228
|
-
setStep(mappingFormStep["PersonalData"]);
|
|
229
|
-
setModal({
|
|
230
|
-
id: "CustomerNotRegistered",
|
|
231
|
-
open: true
|
|
232
|
-
});
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
if (data.registration?.address === null) {
|
|
236
|
-
setStep(mappingFormStep["Address"]);
|
|
237
|
-
setModal({
|
|
238
|
-
id: "CustomerNotRegistered",
|
|
239
|
-
open: true
|
|
240
|
-
});
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
if (data.registration?.identity_responsibility === null) {
|
|
244
|
-
setStep(mappingFormStep["GenderResponsibility"]);
|
|
245
|
-
setModal({
|
|
246
|
-
id: "CustomerNotRegistered",
|
|
247
|
-
open: true
|
|
248
|
-
});
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
if (data.registration?.medical_data === null) {
|
|
252
|
-
setStep(mappingFormStep["Doctor"]);
|
|
253
|
-
setModal({
|
|
254
|
-
id: "CustomerNotRegistered",
|
|
255
|
-
open: true
|
|
256
|
-
});
|
|
257
|
-
return;
|
|
258
|
-
}
|
|
259
|
-
if (data.registration?.lgpd === null) {
|
|
260
|
-
setStep(mappingFormStep["Acceptances"]);
|
|
261
|
-
setModal({
|
|
262
|
-
id: "CustomerNotRegistered",
|
|
263
|
-
open: true
|
|
264
|
-
});
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
store.setState("isActivated");
|
|
268
|
-
};
|
|
269
|
-
const checkSecurityNumberBenefits = async (values) => {
|
|
208
|
+
const checkSecurityNumber = async (values) => {
|
|
270
209
|
if (store.targetProduct === null) {
|
|
271
210
|
console.error("PBMLOG: Product is not defined!");
|
|
272
211
|
return;
|
|
273
212
|
}
|
|
274
|
-
if (!store.targetProduct.
|
|
213
|
+
if (!store.targetProduct.id) {
|
|
275
214
|
console.error("PBMLOG: Product ID is not defined!");
|
|
276
215
|
return;
|
|
277
216
|
}
|
|
@@ -280,28 +219,11 @@ function Form({ startTransition }) {
|
|
|
280
219
|
return;
|
|
281
220
|
}
|
|
282
221
|
store.setSecurityNumber(values.securityNumber.replace(/\D/g, ""));
|
|
283
|
-
const
|
|
284
|
-
|
|
222
|
+
const consumerHasDiscountEnabled = await LookupConsumer({
|
|
223
|
+
product: store.targetProduct,
|
|
224
|
+
consumer: { holderId: values.securityNumber.replace(/\D/g, "") }
|
|
285
225
|
});
|
|
286
|
-
if (
|
|
287
|
-
if (!customerIsRegistered.data.requestId) {
|
|
288
|
-
console.error(
|
|
289
|
-
"PBMLOG: Request ID is not defined in lookup customer response"
|
|
290
|
-
);
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
store.setRequestId(customerIsRegistered.data.requestId || "");
|
|
294
|
-
CheckCustomerRegisterSteps({ customer: customerIsRegistered });
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
if (!customerIsRegistered.success) {
|
|
298
|
-
if (!customerIsRegistered.requestId) {
|
|
299
|
-
console.error(
|
|
300
|
-
"PBMLOG: Request ID is not defined in lookup customer response for non registered customer"
|
|
301
|
-
);
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
store.setRequestId(customerIsRegistered.requestId || "");
|
|
226
|
+
if (!consumerHasDiscountEnabled.success) {
|
|
305
227
|
setModal({
|
|
306
228
|
id: "CustomerNotRegistered",
|
|
307
229
|
open: true
|
|
@@ -321,7 +243,7 @@ function Form({ startTransition }) {
|
|
|
321
243
|
store.setCardID(values.coupon);
|
|
322
244
|
}
|
|
323
245
|
startTransition(async () => {
|
|
324
|
-
await
|
|
246
|
+
await checkSecurityNumber(values);
|
|
325
247
|
});
|
|
326
248
|
};
|
|
327
249
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
@@ -337,7 +259,7 @@ function Form({ startTransition }) {
|
|
|
337
259
|
/* @__PURE__ */ jsxs(
|
|
338
260
|
"label",
|
|
339
261
|
{
|
|
340
|
-
htmlFor: "
|
|
262
|
+
htmlFor: "input_security_number_pbm",
|
|
341
263
|
className: classNames2(
|
|
342
264
|
"w-full h-auto flex items-start flex-col justify-center relative py-2 transition-all duration-100",
|
|
343
265
|
{
|
|
@@ -389,7 +311,7 @@ function Form({ startTransition }) {
|
|
|
389
311
|
/* @__PURE__ */ jsx2(Activity, { mode: showCardIDField ? "visible" : "hidden", children: /* @__PURE__ */ jsxs(
|
|
390
312
|
"label",
|
|
391
313
|
{
|
|
392
|
-
htmlFor: "
|
|
314
|
+
htmlFor: "input_coupon_pbm",
|
|
393
315
|
className: classNames2(
|
|
394
316
|
"w-full h-auto flex items-start flex-col justify-center relative py-2",
|
|
395
317
|
{
|
|
@@ -657,29 +579,46 @@ var Icons = {
|
|
|
657
579
|
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
658
580
|
function Header({ originalProductPrice }) {
|
|
659
581
|
const { targetProduct, benefitsEnabled, setBenefitsEnabled } = usePBMStore();
|
|
660
|
-
const Price =
|
|
661
|
-
|
|
582
|
+
const Price = formaters.transformPrice(
|
|
583
|
+
Number(targetProduct?.listPrice) || originalProductPrice
|
|
584
|
+
);
|
|
585
|
+
const DiscountValue = formaters.transformPrice(
|
|
586
|
+
Number(targetProduct?.discountValue) || 0
|
|
587
|
+
);
|
|
588
|
+
const DiscountPercentual = formaters.transformPorcent(
|
|
589
|
+
targetProduct?.discountMaxNewPatient || "0"
|
|
590
|
+
);
|
|
591
|
+
const DiscountPercentualValue = Price * DiscountPercentual / 100;
|
|
592
|
+
const DiscountApplied = Price - DiscountPercentualValue || Price - DiscountValue;
|
|
662
593
|
return /* @__PURE__ */ jsxs3(
|
|
663
594
|
"header",
|
|
664
595
|
{
|
|
665
596
|
className: "flex items-start justify-start flex-col gap-4 w-full p-0.5 rounded-xl mt-5",
|
|
666
597
|
id: "header_pbm",
|
|
667
598
|
children: [
|
|
668
|
-
/* @__PURE__ */ jsxs3(
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
599
|
+
/* @__PURE__ */ jsxs3(
|
|
600
|
+
"label",
|
|
601
|
+
{
|
|
602
|
+
className: "flex items-center gap-2 cursor-pointer",
|
|
603
|
+
htmlFor: "enable_benefits_checkbox",
|
|
604
|
+
children: [
|
|
605
|
+
/* @__PURE__ */ jsx4(
|
|
606
|
+
"input",
|
|
607
|
+
{
|
|
608
|
+
id: "enable_benefits_checkbox",
|
|
609
|
+
type: "checkbox",
|
|
610
|
+
name: "option",
|
|
611
|
+
className: "peer hidden",
|
|
612
|
+
checked: benefitsEnabled,
|
|
613
|
+
onChange: (e) => setBenefitsEnabled(e.target.checked)
|
|
614
|
+
}
|
|
615
|
+
),
|
|
616
|
+
/* @__PURE__ */ jsx4("div", { className: "w-5 h-5 border border-(--pbm-primary) rounded-full flex items-center justify-center transition-all duration-300 after:content-[''] after:w-2 after:h-2 after:rounded-full after:bg-(--pbm-primary) after:scale-0 after:transition-transform after:duration-200 peer-checked:after:scale-100" }),
|
|
617
|
+
/* @__PURE__ */ jsx4("p", { className: "font-medium text-(--pbm-primary) select-none text-sm", children: "Desconto de Laborat\xF3rio" }),
|
|
618
|
+
/* @__PURE__ */ jsx4(Icons.Pills, { size: 16, color: "var(--pbm-primary)" })
|
|
619
|
+
]
|
|
620
|
+
}
|
|
621
|
+
),
|
|
683
622
|
/* @__PURE__ */ jsx4(
|
|
684
623
|
"span",
|
|
685
624
|
{
|
|
@@ -696,11 +635,11 @@ function Header({ originalProductPrice }) {
|
|
|
696
635
|
}) }),
|
|
697
636
|
/* @__PURE__ */ jsx4(Icons.ArrowDown, { size: 14, color: "var(--pbm-primary)" }),
|
|
698
637
|
/* @__PURE__ */ jsxs3("span", { className: "font-semibold text-sm text-(--pbm-primary)", children: [
|
|
699
|
-
|
|
638
|
+
DiscountPercentual.toFixed(2),
|
|
700
639
|
"%"
|
|
701
640
|
] })
|
|
702
641
|
] }),
|
|
703
|
-
/* @__PURE__ */ jsx4("span", { className: "text-lg text-zinc-700 font-bold", children:
|
|
642
|
+
/* @__PURE__ */ jsx4("span", { className: "text-lg text-zinc-700 font-bold", children: DiscountApplied?.toLocaleString("pt-BR", {
|
|
704
643
|
currency: "BRL",
|
|
705
644
|
currencyDisplay: "symbol",
|
|
706
645
|
currencySign: "standard",
|
|
@@ -716,173 +655,20 @@ function Header({ originalProductPrice }) {
|
|
|
716
655
|
}
|
|
717
656
|
var Header_default = Header;
|
|
718
657
|
|
|
719
|
-
// src/components/Iframe/index.tsx
|
|
720
|
-
import classNames5 from "classnames";
|
|
721
|
-
import { TriangleAlert, ExternalLink } from "lucide-react";
|
|
722
|
-
import { useState as useState2, useEffect } from "react";
|
|
723
|
-
|
|
724
|
-
// src/components/UI/Title/index.tsx
|
|
725
|
-
import classNames3 from "classnames";
|
|
726
|
-
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
727
|
-
function Title(props) {
|
|
728
|
-
return /* @__PURE__ */ jsx5(
|
|
729
|
-
"h2",
|
|
730
|
-
{
|
|
731
|
-
className: classNames3(
|
|
732
|
-
"text-start font-semibold text-sm",
|
|
733
|
-
props.className
|
|
734
|
-
),
|
|
735
|
-
style: { color: props.textColor || "var(--pbm-text)", fontSize: props.textSize, textAlign: props.textAlign },
|
|
736
|
-
"data-testid": "test_id_title",
|
|
737
|
-
id: "title_pbm",
|
|
738
|
-
children: props.children
|
|
739
|
-
}
|
|
740
|
-
);
|
|
741
|
-
}
|
|
742
|
-
var Title_default = Title;
|
|
743
|
-
|
|
744
|
-
// src/components/UI/Text/index.tsx
|
|
745
|
-
import classNames4 from "classnames";
|
|
746
|
-
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
747
|
-
function Text(props) {
|
|
748
|
-
return /* @__PURE__ */ jsx6(
|
|
749
|
-
"p",
|
|
750
|
-
{
|
|
751
|
-
className: classNames4(
|
|
752
|
-
"font-normal text-sm",
|
|
753
|
-
props.textAlign && `text-${props.textAlign}`,
|
|
754
|
-
props.className
|
|
755
|
-
),
|
|
756
|
-
style: { color: props.textColor || "var(--pbm-text)", fontSize: props.textSize, textAlign: props.textAlign },
|
|
757
|
-
"data-testid": "test_id_text",
|
|
758
|
-
id: "text_pbm",
|
|
759
|
-
children: props.children
|
|
760
|
-
}
|
|
761
|
-
);
|
|
762
|
-
}
|
|
763
|
-
var Text_default = Text;
|
|
764
|
-
|
|
765
|
-
// src/components/Iframe/index.tsx
|
|
766
|
-
import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
767
|
-
function Iframe() {
|
|
768
|
-
const [showFallback, setShowFallback] = useState2(false);
|
|
769
|
-
const { setState } = usePBMStore();
|
|
770
|
-
const { resetModal, modal } = useModal();
|
|
771
|
-
const isOpen = modal.open && modal.id === "iframe_pbm";
|
|
772
|
-
useEffect(() => {
|
|
773
|
-
if (isOpen) {
|
|
774
|
-
setShowFallback(false);
|
|
775
|
-
}
|
|
776
|
-
}, [isOpen, modal.url]);
|
|
777
|
-
const handleOpenInNewWindow = () => {
|
|
778
|
-
if (modal.url) {
|
|
779
|
-
window.open(modal.url, "_blank", "noopener,noreferrer");
|
|
780
|
-
}
|
|
781
|
-
};
|
|
782
|
-
const handleClose = () => {
|
|
783
|
-
setState("isEmpty");
|
|
784
|
-
resetModal();
|
|
785
|
-
};
|
|
786
|
-
if (!modal.url) return;
|
|
787
|
-
return /* @__PURE__ */ jsxs4(
|
|
788
|
-
"main",
|
|
789
|
-
{
|
|
790
|
-
className: classNames5(
|
|
791
|
-
"fixed inset-0 flex items-center justify-center z-50 flex-col transition-all duration-300 pt-[10%]",
|
|
792
|
-
isOpen ? "opacity-100 pointer-events-auto" : "opacity-0 pointer-events-none"
|
|
793
|
-
),
|
|
794
|
-
id: "iframe_pbm",
|
|
795
|
-
children: [
|
|
796
|
-
/* @__PURE__ */ jsx7(
|
|
797
|
-
"div",
|
|
798
|
-
{
|
|
799
|
-
className: "bg-black/40 inset-0 absolute backdrop-blur-sm",
|
|
800
|
-
onClick: handleClose
|
|
801
|
-
}
|
|
802
|
-
),
|
|
803
|
-
/* @__PURE__ */ jsxs4("section", { className: "w-[90%] md:w-4/5 gap-4 h-auto bg-zinc-900 py-3 px-6 flex items-center justify-end rounded-t-2xl border-b border-white/10 z-10 shadow-2xl", children: [
|
|
804
|
-
/* @__PURE__ */ jsx7(
|
|
805
|
-
Button_default,
|
|
806
|
-
{
|
|
807
|
-
onClick: handleClose,
|
|
808
|
-
className: "bg-red-500 hover:bg-red-400 w-auto px-6 h-9 transition-all active:scale-95 shadow-lg text-xs md:text-sm",
|
|
809
|
-
children: "Cancelar"
|
|
810
|
-
}
|
|
811
|
-
),
|
|
812
|
-
/* @__PURE__ */ jsx7(
|
|
813
|
-
Button_default,
|
|
814
|
-
{
|
|
815
|
-
onClick: handleClose,
|
|
816
|
-
className: "bg-blue-600 hover:bg-blue-500 w-auto px-6 h-9 transition-all active:scale-95 shadow-lg text-xs md:text-sm",
|
|
817
|
-
children: "Finalizei o formul\xE1rio"
|
|
818
|
-
}
|
|
819
|
-
)
|
|
820
|
-
] }),
|
|
821
|
-
/* @__PURE__ */ jsx7("div", { className: "w-[90%] md:w-4/5 h-[60vh] bg-zinc-900 z-10 overflow-hidden relative shadow-2xl", children: showFallback ? /* @__PURE__ */ jsxs4("div", { className: "absolute inset-0 flex flex-col items-center justify-center p-8 text-center bg-zinc-900", children: [
|
|
822
|
-
/* @__PURE__ */ jsx7("div", { className: "bg-yellow-500/10 p-4 rounded-full mb-4 animate-pulse", children: /* @__PURE__ */ jsx7(TriangleAlert, { size: 48, className: "text-yellow-500" }) }),
|
|
823
|
-
/* @__PURE__ */ jsx7(Title_default, { textColor: "white", textSize: "20px", textAlign: "center", className: "mb-2", children: "N\xE3o foi poss\xEDvel carregar o conte\xFAdo" }),
|
|
824
|
-
/* @__PURE__ */ jsx7(Text_default, { textColor: "#a1a1aa", textAlign: "center", className: "mb-8 max-w-md", children: "Este conte\xFAdo n\xE3o permite exibi\xE7\xE3o integrada por seguran\xE7a. Clique no bot\xE3o abaixo para concluir em uma nova aba." }),
|
|
825
|
-
/* @__PURE__ */ jsxs4(
|
|
826
|
-
Button_default,
|
|
827
|
-
{
|
|
828
|
-
onClick: handleOpenInNewWindow,
|
|
829
|
-
className: "flex items-center gap-2 w-auto px-8 h-12 shadow-xl shadow-emerald-500/20",
|
|
830
|
-
children: [
|
|
831
|
-
/* @__PURE__ */ jsx7(ExternalLink, { size: 18 }),
|
|
832
|
-
"Abrir em nova janela"
|
|
833
|
-
]
|
|
834
|
-
}
|
|
835
|
-
)
|
|
836
|
-
] }) : /* @__PURE__ */ jsx7(
|
|
837
|
-
"iframe",
|
|
838
|
-
{
|
|
839
|
-
src: modal.url,
|
|
840
|
-
title: modal.label ?? "Conte\xFAdo PBM",
|
|
841
|
-
className: "w-full h-full border-none bg-white animate-fade-in",
|
|
842
|
-
allowFullScreen: true,
|
|
843
|
-
onError: () => setShowFallback(true)
|
|
844
|
-
}
|
|
845
|
-
) }),
|
|
846
|
-
/* @__PURE__ */ jsxs4("section", { className: "w-[90%] md:w-4/5 flex flex-col md:flex-row items-center justify-between gap-3 bg-zinc-900 py-4 px-6 rounded-b-2xl border-t border-white/5 z-10 shadow-2xl", children: [
|
|
847
|
-
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2", children: [
|
|
848
|
-
/* @__PURE__ */ jsx7(TriangleAlert, { size: 18, className: "text-yellow-500 shrink-0" }),
|
|
849
|
-
/* @__PURE__ */ jsxs4(Text_default, { textColor: "white", className: "text-[10px] md:text-xs", children: [
|
|
850
|
-
/* @__PURE__ */ jsx7("span", { className: "text-yellow-500 font-bold mr-1", children: "Importante:" }),
|
|
851
|
-
"Se a p\xE1gina n\xE3o carregar, tente abrir em tela cheia usando o bot\xE3o ao lado."
|
|
852
|
-
] })
|
|
853
|
-
] }),
|
|
854
|
-
/* @__PURE__ */ jsxs4(
|
|
855
|
-
"button",
|
|
856
|
-
{
|
|
857
|
-
onClick: handleOpenInNewWindow,
|
|
858
|
-
className: "text-white/60 hover:text-white text-[11px] underline flex items-center gap-1 transition-colors cursor-pointer",
|
|
859
|
-
children: [
|
|
860
|
-
/* @__PURE__ */ jsx7(ExternalLink, { size: 14 }),
|
|
861
|
-
" Abrir em nova aba"
|
|
862
|
-
]
|
|
863
|
-
}
|
|
864
|
-
)
|
|
865
|
-
] })
|
|
866
|
-
]
|
|
867
|
-
}
|
|
868
|
-
);
|
|
869
|
-
}
|
|
870
|
-
var Iframe_default = Iframe;
|
|
871
|
-
|
|
872
658
|
// src/components/UI/Loading/index.tsx
|
|
873
|
-
import { jsx as
|
|
659
|
+
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
874
660
|
function Loading({ textColor }) {
|
|
875
|
-
return /* @__PURE__ */
|
|
876
|
-
/* @__PURE__ */
|
|
661
|
+
return /* @__PURE__ */ jsxs4("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: [
|
|
662
|
+
/* @__PURE__ */ jsx5(
|
|
877
663
|
"div",
|
|
878
664
|
{
|
|
879
665
|
"data-testid": "test_id_spin",
|
|
880
|
-
className: "w-8 h-8 border-4 border-gray-300 rounded-full animate-spin",
|
|
666
|
+
className: "w-8 h-8 border-4 shrink-0 border-gray-300 rounded-full animate-spin",
|
|
881
667
|
style: { borderTopColor: "var(--pbm-secondary)" },
|
|
882
668
|
id: "loading_spin"
|
|
883
669
|
}
|
|
884
670
|
),
|
|
885
|
-
/* @__PURE__ */
|
|
671
|
+
/* @__PURE__ */ jsx5(
|
|
886
672
|
"p",
|
|
887
673
|
{
|
|
888
674
|
className: "text-sm font-semibold text-start",
|
|
@@ -896,17 +682,17 @@ function Loading({ textColor }) {
|
|
|
896
682
|
var Loading_default = Loading;
|
|
897
683
|
|
|
898
684
|
// src/components/UI/Container/index.tsx
|
|
899
|
-
import
|
|
900
|
-
import { jsx as
|
|
685
|
+
import classNames3 from "classnames";
|
|
686
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
901
687
|
function Container({
|
|
902
688
|
children,
|
|
903
689
|
variant
|
|
904
690
|
}) {
|
|
905
691
|
const { benefitsEnabled } = usePBMStore();
|
|
906
|
-
return /* @__PURE__ */
|
|
692
|
+
return /* @__PURE__ */ jsx6(
|
|
907
693
|
"main",
|
|
908
694
|
{
|
|
909
|
-
className:
|
|
695
|
+
className: classNames3({
|
|
910
696
|
"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",
|
|
911
697
|
"w-full relative": variant === "simple",
|
|
912
698
|
"h-0 overflow-hidden": !benefitsEnabled && variant === "simple"
|
|
@@ -920,83 +706,60 @@ function Container({
|
|
|
920
706
|
}
|
|
921
707
|
var Container_default = Container;
|
|
922
708
|
|
|
923
|
-
// src/
|
|
924
|
-
import
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
const dataResponse = await response.json();
|
|
943
|
-
if (!dataResponse.success) {
|
|
944
|
-
throw new Error(dataResponse.message || "Failed to fetch document validation");
|
|
945
|
-
}
|
|
946
|
-
return dataResponse;
|
|
947
|
-
};
|
|
948
|
-
|
|
949
|
-
// src/services/benefits-without-document.ts
|
|
950
|
-
import Cookies3 from "js-cookie";
|
|
951
|
-
var CheckBenefistWithoutDocument = async ({ products }) => {
|
|
952
|
-
const API_URL = getEnv("VITE_API_URL");
|
|
953
|
-
if (!API_URL) {
|
|
954
|
-
throw new Error("API URL is not defined in environment variables");
|
|
955
|
-
}
|
|
956
|
-
const AUTH_TOKEN = Cookies3.get("pbm-token");
|
|
957
|
-
if (!AUTH_TOKEN) {
|
|
958
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
959
|
-
}
|
|
960
|
-
const response = await fetch(`${API_URL}/products/genericBenefit`, {
|
|
961
|
-
method: "POST",
|
|
962
|
-
headers: {
|
|
963
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
964
|
-
"Content-Type": "application/json"
|
|
965
|
-
},
|
|
966
|
-
body: JSON.stringify({ products })
|
|
967
|
-
});
|
|
968
|
-
const dataResponse = await response.json();
|
|
969
|
-
if (!dataResponse.success) {
|
|
970
|
-
throw new Error(dataResponse.message || "Failed to fetch benefits without document");
|
|
971
|
-
}
|
|
972
|
-
return dataResponse;
|
|
973
|
-
};
|
|
709
|
+
// src/components/UI/Title/index.tsx
|
|
710
|
+
import classNames4 from "classnames";
|
|
711
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
712
|
+
function Title(props) {
|
|
713
|
+
return /* @__PURE__ */ jsx7(
|
|
714
|
+
"h2",
|
|
715
|
+
{
|
|
716
|
+
className: classNames4(
|
|
717
|
+
"text-start font-semibold text-sm",
|
|
718
|
+
props.className
|
|
719
|
+
),
|
|
720
|
+
style: { color: props.textColor || "var(--pbm-text)", fontSize: props.textSize, textAlign: props.textAlign },
|
|
721
|
+
"data-testid": "test_id_title",
|
|
722
|
+
id: "title_pbm",
|
|
723
|
+
children: props.children
|
|
724
|
+
}
|
|
725
|
+
);
|
|
726
|
+
}
|
|
727
|
+
var Title_default = Title;
|
|
974
728
|
|
|
975
729
|
// src/components/BenefitsTable/index.tsx
|
|
976
|
-
import {
|
|
730
|
+
import { useState as useState2, useTransition } from "react";
|
|
977
731
|
|
|
978
732
|
// src/components/BenefitsTable/Item.tsx
|
|
979
|
-
import { useCallback, useEffect
|
|
980
|
-
import
|
|
981
|
-
import { jsx as
|
|
733
|
+
import { useCallback, useEffect } from "react";
|
|
734
|
+
import classNames5 from "classnames";
|
|
735
|
+
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
982
736
|
function Item({ data, onChange, checked }) {
|
|
983
737
|
const { setAvailableDiscountSelected, state, isAuthenticatedShopper } = usePBMStore();
|
|
984
738
|
const { setModal } = useModal();
|
|
985
|
-
const ID_INPUT = "
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
const
|
|
739
|
+
const ID_INPUT = data.id + "_" + data.authorizedQuantity;
|
|
740
|
+
const PricePerUnity = formaters.transformPrice(
|
|
741
|
+
Number(data?.grossPrice) || Number(data?.listPrice) || 0
|
|
742
|
+
);
|
|
743
|
+
const DiscountValuePerUnity = formaters.transformPrice(
|
|
744
|
+
Number(data?.discountValue) || 0
|
|
745
|
+
);
|
|
746
|
+
const DiscountPercentual = formaters.transformPorcent(
|
|
747
|
+
data?.discountPercentual || "0"
|
|
748
|
+
);
|
|
749
|
+
const TotalDiscountValue = DiscountValuePerUnity * data.authorizedQuantity;
|
|
750
|
+
const TotalPricePerQuantity = PricePerUnity * data.authorizedQuantity;
|
|
751
|
+
const DiscountPercentualValue = TotalPricePerQuantity * DiscountPercentual / 100;
|
|
752
|
+
const AppliedDiscount = TotalPricePerQuantity - DiscountPercentualValue || TotalPricePerQuantity - TotalDiscountValue;
|
|
990
753
|
const updateStorageData = useCallback(() => {
|
|
991
754
|
if (checked) {
|
|
992
755
|
const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
|
|
993
756
|
setAvailableDiscountSelected({
|
|
994
757
|
discount: {
|
|
995
|
-
total: roundToTwoDecimals(
|
|
996
|
-
unit: roundToTwoDecimals(
|
|
758
|
+
total: roundToTwoDecimals(TotalDiscountValue),
|
|
759
|
+
unit: roundToTwoDecimals(DiscountValuePerUnity)
|
|
997
760
|
},
|
|
998
761
|
quantity: data.authorizedQuantity,
|
|
999
|
-
totalPrice: roundToTwoDecimals(
|
|
762
|
+
totalPrice: roundToTwoDecimals(AppliedDiscount),
|
|
1000
763
|
grossPrice: data.grossPrice
|
|
1001
764
|
});
|
|
1002
765
|
}
|
|
@@ -1005,11 +768,11 @@ function Item({ data, onChange, checked }) {
|
|
|
1005
768
|
data.authorizedQuantity,
|
|
1006
769
|
data.grossPrice,
|
|
1007
770
|
setAvailableDiscountSelected,
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
771
|
+
TotalDiscountValue,
|
|
772
|
+
DiscountValuePerUnity,
|
|
773
|
+
AppliedDiscount
|
|
1011
774
|
]);
|
|
1012
|
-
|
|
775
|
+
useEffect(() => {
|
|
1013
776
|
updateStorageData();
|
|
1014
777
|
}, [updateStorageData]);
|
|
1015
778
|
const handleChange = () => {
|
|
@@ -1022,11 +785,11 @@ function Item({ data, onChange, checked }) {
|
|
|
1022
785
|
}
|
|
1023
786
|
onChange();
|
|
1024
787
|
};
|
|
1025
|
-
return /* @__PURE__ */
|
|
788
|
+
return /* @__PURE__ */ jsxs5(
|
|
1026
789
|
"label",
|
|
1027
790
|
{
|
|
1028
791
|
htmlFor: ID_INPUT,
|
|
1029
|
-
className:
|
|
792
|
+
className: classNames5(
|
|
1030
793
|
"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",
|
|
1031
794
|
{
|
|
1032
795
|
"cursor-not-allowed": state === "isPreview",
|
|
@@ -1040,7 +803,7 @@ function Item({ data, onChange, checked }) {
|
|
|
1040
803
|
},
|
|
1041
804
|
id: "label_benefits_" + ID_INPUT,
|
|
1042
805
|
children: [
|
|
1043
|
-
/* @__PURE__ */
|
|
806
|
+
/* @__PURE__ */ jsx8(
|
|
1044
807
|
"input",
|
|
1045
808
|
{
|
|
1046
809
|
type: "radio",
|
|
@@ -1052,8 +815,8 @@ function Item({ data, onChange, checked }) {
|
|
|
1052
815
|
disabled: state === "isPreview"
|
|
1053
816
|
}
|
|
1054
817
|
),
|
|
1055
|
-
/* @__PURE__ */
|
|
1056
|
-
/* @__PURE__ */
|
|
818
|
+
/* @__PURE__ */ jsx8("span", { style: { color: "var(--pbm-primary)" }, children: !checked ? /* @__PURE__ */ jsx8(Icons.CheckOFF, { size: 20 }) : /* @__PURE__ */ jsx8(Icons.CheckON, { size: 20 }) }),
|
|
819
|
+
/* @__PURE__ */ jsxs5(
|
|
1057
820
|
"span",
|
|
1058
821
|
{
|
|
1059
822
|
className: "font-semibold text-sm",
|
|
@@ -1064,14 +827,14 @@ function Item({ data, onChange, checked }) {
|
|
|
1064
827
|
]
|
|
1065
828
|
}
|
|
1066
829
|
),
|
|
1067
|
-
/* @__PURE__ */
|
|
1068
|
-
/* @__PURE__ */
|
|
830
|
+
/* @__PURE__ */ jsxs5("section", { className: "ml-auto relative gap-2 flex items-center-safe justify-end-safe", children: [
|
|
831
|
+
/* @__PURE__ */ jsxs5(
|
|
1069
832
|
"span",
|
|
1070
833
|
{
|
|
1071
834
|
className: "text-white -top-4 py-0.5 font-semibold text-xs px-2 w-auto text-nowrap rounded-2xl -right-3",
|
|
1072
835
|
style: { backgroundColor: "var(--pbm-primary)" },
|
|
1073
836
|
children: [
|
|
1074
|
-
|
|
837
|
+
TotalDiscountValue.toLocaleString("pt-BR", {
|
|
1075
838
|
currency: "BRL",
|
|
1076
839
|
currencyDisplay: "symbol",
|
|
1077
840
|
currencySign: "standard",
|
|
@@ -1082,12 +845,12 @@ function Item({ data, onChange, checked }) {
|
|
|
1082
845
|
]
|
|
1083
846
|
}
|
|
1084
847
|
),
|
|
1085
|
-
/* @__PURE__ */
|
|
848
|
+
/* @__PURE__ */ jsx8(
|
|
1086
849
|
"strong",
|
|
1087
850
|
{
|
|
1088
851
|
className: "font-semibold text-sm text-center",
|
|
1089
852
|
style: { color: "var(--pbm-text)" },
|
|
1090
|
-
children:
|
|
853
|
+
children: AppliedDiscount.toLocaleString("pt-BR", {
|
|
1091
854
|
currency: "BRL",
|
|
1092
855
|
currencyDisplay: "symbol",
|
|
1093
856
|
currencySign: "standard",
|
|
@@ -1102,104 +865,30 @@ function Item({ data, onChange, checked }) {
|
|
|
1102
865
|
}
|
|
1103
866
|
var Item_default = Item;
|
|
1104
867
|
|
|
868
|
+
// src/utils/approved-code.ts
|
|
869
|
+
var APPROVED_BENEFIT_CODE = "N000";
|
|
870
|
+
|
|
1105
871
|
// src/components/BenefitsTable/index.tsx
|
|
1106
|
-
import { Fragment as Fragment2, jsx as
|
|
872
|
+
import { Fragment as Fragment2, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1107
873
|
function BenefitsTable() {
|
|
1108
|
-
const [isPending
|
|
874
|
+
const [isPending] = useTransition();
|
|
1109
875
|
const {
|
|
1110
|
-
securityNumber,
|
|
876
|
+
// securityNumber,
|
|
1111
877
|
setState,
|
|
1112
878
|
state,
|
|
1113
|
-
targetProduct,
|
|
879
|
+
// targetProduct,
|
|
1114
880
|
customLoginUrl,
|
|
1115
881
|
isAuthenticatedShopper,
|
|
1116
|
-
requestId
|
|
882
|
+
// requestId,
|
|
883
|
+
benefitsList
|
|
1117
884
|
} = usePBMStore();
|
|
1118
|
-
const [selectedDiscout, setSelectedDiscount] =
|
|
1119
|
-
const [benefitsItems
|
|
1120
|
-
useEffect3(() => {
|
|
1121
|
-
if (!targetProduct?.productId) {
|
|
1122
|
-
console.error("PBMLOG: Product ID is not defined on targetProduct");
|
|
1123
|
-
return;
|
|
1124
|
-
}
|
|
1125
|
-
if (!targetProduct.ean) {
|
|
1126
|
-
console.error("PBMLOG: EAN is not defined on targetProduct");
|
|
1127
|
-
return;
|
|
1128
|
-
}
|
|
1129
|
-
if (!targetProduct.listPrice) {
|
|
1130
|
-
console.error("PBMLOG: List Price is not defined on targetProduct");
|
|
1131
|
-
return;
|
|
1132
|
-
}
|
|
1133
|
-
if (!targetProduct.price) {
|
|
1134
|
-
console.error("PBMLOG: Price is not defined on targetProduct");
|
|
1135
|
-
return;
|
|
1136
|
-
}
|
|
1137
|
-
const fetchDicountsWithoutDocument = async () => {
|
|
1138
|
-
try {
|
|
1139
|
-
const data = {
|
|
1140
|
-
productId: Number(targetProduct.productId),
|
|
1141
|
-
ean: targetProduct.ean,
|
|
1142
|
-
requestedQuantity: 1,
|
|
1143
|
-
listPrice: targetProduct.listPrice,
|
|
1144
|
-
netPrice: targetProduct.price
|
|
1145
|
-
};
|
|
1146
|
-
const response = await CheckBenefistWithoutDocument({
|
|
1147
|
-
products: [data]
|
|
1148
|
-
});
|
|
1149
|
-
if (response.success && response.data) {
|
|
1150
|
-
setBenefitsItems(response.data);
|
|
1151
|
-
} else {
|
|
1152
|
-
setBenefitsItems(void 0);
|
|
1153
|
-
}
|
|
1154
|
-
} catch (error) {
|
|
1155
|
-
setBenefitsItems(void 0);
|
|
1156
|
-
console.error(error);
|
|
1157
|
-
}
|
|
1158
|
-
};
|
|
1159
|
-
const fetchDiscountWithDocument = async () => {
|
|
1160
|
-
if (!securityNumber) {
|
|
1161
|
-
console.error("PBMLOG: Document is not defined");
|
|
1162
|
-
return;
|
|
1163
|
-
}
|
|
1164
|
-
if (!requestId) {
|
|
1165
|
-
console.error("PBMLOG: Request ID is not defined");
|
|
1166
|
-
return;
|
|
1167
|
-
}
|
|
1168
|
-
try {
|
|
1169
|
-
const data = {
|
|
1170
|
-
productId: Number(targetProduct.productId),
|
|
1171
|
-
ean: targetProduct.ean,
|
|
1172
|
-
quantity: 1,
|
|
1173
|
-
listPrice: targetProduct.listPrice
|
|
1174
|
-
};
|
|
1175
|
-
const response = await ActivateCustomer({
|
|
1176
|
-
document: securityNumber,
|
|
1177
|
-
requestId,
|
|
1178
|
-
products: [data]
|
|
1179
|
-
});
|
|
1180
|
-
if (response.success && response.data) {
|
|
1181
|
-
setBenefitsItems(response.data.product);
|
|
1182
|
-
} else {
|
|
1183
|
-
setBenefitsItems(void 0);
|
|
1184
|
-
}
|
|
1185
|
-
} catch (error) {
|
|
1186
|
-
setBenefitsItems(void 0);
|
|
1187
|
-
console.error(error);
|
|
1188
|
-
}
|
|
1189
|
-
};
|
|
1190
|
-
startTransition(async () => {
|
|
1191
|
-
if (state === "isActivated") {
|
|
1192
|
-
await fetchDiscountWithDocument();
|
|
1193
|
-
} else {
|
|
1194
|
-
await fetchDicountsWithoutDocument();
|
|
1195
|
-
}
|
|
1196
|
-
});
|
|
1197
|
-
}, []);
|
|
885
|
+
const [selectedDiscout, setSelectedDiscount] = useState2(null);
|
|
886
|
+
const [benefitsItems] = useState2(benefitsList);
|
|
1198
887
|
if (isPending) {
|
|
1199
|
-
return /* @__PURE__ */
|
|
888
|
+
return /* @__PURE__ */ jsx9(Loading_default, { textColor: "var(--pbm-text)" });
|
|
1200
889
|
}
|
|
1201
|
-
if (benefitsItems?.length && benefitsItems[0]?.
|
|
1202
|
-
return /* @__PURE__ */
|
|
890
|
+
if (benefitsItems?.length && benefitsItems[0]?.returnCode !== APPROVED_BENEFIT_CODE && state === "isActivated") {
|
|
891
|
+
return /* @__PURE__ */ jsx9("main", { className: "flex items-center justify-center gap-4", id: "loading_pbm", children: /* @__PURE__ */ jsx9(
|
|
1203
892
|
"p",
|
|
1204
893
|
{
|
|
1205
894
|
className: "text-sm font-semibold text-start",
|
|
@@ -1209,21 +898,21 @@ function BenefitsTable() {
|
|
|
1209
898
|
}
|
|
1210
899
|
) });
|
|
1211
900
|
}
|
|
1212
|
-
return /* @__PURE__ */
|
|
901
|
+
return /* @__PURE__ */ jsxs6(
|
|
1213
902
|
"section",
|
|
1214
903
|
{
|
|
1215
904
|
className: "flex items-start justify-center gap-4 w-full h-auto flex-col",
|
|
1216
905
|
id: "benefits_table_pbm",
|
|
1217
906
|
children: [
|
|
1218
|
-
/* @__PURE__ */
|
|
1219
|
-
/* @__PURE__ */
|
|
907
|
+
/* @__PURE__ */ jsx9(Title_default, { children: "Descontos dispon\xEDveis:" }),
|
|
908
|
+
/* @__PURE__ */ jsxs6(
|
|
1220
909
|
"form",
|
|
1221
910
|
{
|
|
1222
911
|
className: "flex flex-col items-center justify-start w-full gap-4.5",
|
|
1223
912
|
id: "form_benefits_table_pbm",
|
|
1224
913
|
onSubmit: (e) => e.preventDefault(),
|
|
1225
914
|
children: [
|
|
1226
|
-
!benefitsItems && /* @__PURE__ */
|
|
915
|
+
!benefitsItems && /* @__PURE__ */ jsx9(
|
|
1227
916
|
"p",
|
|
1228
917
|
{
|
|
1229
918
|
className: "text-sm font-semibold text-start text-zinc-900",
|
|
@@ -1231,22 +920,22 @@ function BenefitsTable() {
|
|
|
1231
920
|
children: "N\xE3o foi poss\xEDvel encontrar benef\xEDcios para esse produto."
|
|
1232
921
|
}
|
|
1233
922
|
),
|
|
1234
|
-
benefitsItems && benefitsItems.map((item
|
|
1235
|
-
const ID_INPUT = "
|
|
1236
|
-
return /* @__PURE__ */
|
|
923
|
+
benefitsItems && benefitsItems.map((item) => {
|
|
924
|
+
const ID_INPUT = item.id + "_" + item.authorizedQuantity;
|
|
925
|
+
return /* @__PURE__ */ jsx9(
|
|
1237
926
|
Item_default,
|
|
1238
927
|
{
|
|
1239
928
|
data: item,
|
|
1240
929
|
checked: selectedDiscout === ID_INPUT,
|
|
1241
930
|
onChange: () => setSelectedDiscount(ID_INPUT)
|
|
1242
931
|
},
|
|
1243
|
-
|
|
932
|
+
ID_INPUT
|
|
1244
933
|
);
|
|
1245
934
|
})
|
|
1246
935
|
]
|
|
1247
936
|
}
|
|
1248
937
|
),
|
|
1249
|
-
state === "isPreview" && /* @__PURE__ */
|
|
938
|
+
state === "isPreview" && /* @__PURE__ */ jsxs6(
|
|
1250
939
|
Button_default,
|
|
1251
940
|
{
|
|
1252
941
|
onClick: () => setState("isEmpty"),
|
|
@@ -1255,28 +944,28 @@ function BenefitsTable() {
|
|
|
1255
944
|
children: [
|
|
1256
945
|
"Aten\xE7\xE3o: N\xE3o \xE9 poss\xEDvel utilizar os benef\xEDcos sem realizar a consulta do CPF e o Login, por favor",
|
|
1257
946
|
" ",
|
|
1258
|
-
/* @__PURE__ */
|
|
947
|
+
/* @__PURE__ */ jsx9("span", { className: "underline", children: "insira seu cpf para utilizar os benef\xEDcios" })
|
|
1259
948
|
]
|
|
1260
949
|
}
|
|
1261
950
|
),
|
|
1262
|
-
state === "isActivated" && /* @__PURE__ */
|
|
1263
|
-
!isAuthenticatedShopper && /* @__PURE__ */
|
|
951
|
+
state === "isActivated" && /* @__PURE__ */ jsxs6(Fragment2, { children: [
|
|
952
|
+
!isAuthenticatedShopper && /* @__PURE__ */ jsx9(
|
|
1264
953
|
Button_default,
|
|
1265
954
|
{
|
|
1266
955
|
type: "button",
|
|
1267
956
|
onClick: () => window.location.assign(customLoginUrl || "/login"),
|
|
1268
957
|
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",
|
|
1269
958
|
id: "login",
|
|
1270
|
-
children: /* @__PURE__ */
|
|
959
|
+
children: /* @__PURE__ */ jsx9("span", { className: "underline", children: "Por favor, fa\xE7a o Login para aproveitar os benef\xEDcios!" })
|
|
1271
960
|
}
|
|
1272
961
|
),
|
|
1273
|
-
/* @__PURE__ */
|
|
962
|
+
/* @__PURE__ */ jsx9(
|
|
1274
963
|
Button_default,
|
|
1275
964
|
{
|
|
1276
965
|
onClick: () => setState("isEmpty"),
|
|
1277
966
|
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",
|
|
1278
967
|
id: "change_security_number",
|
|
1279
|
-
children: /* @__PURE__ */
|
|
968
|
+
children: /* @__PURE__ */ jsx9("span", { className: "underline", children: "Deseja editar o cpf digitado?" })
|
|
1280
969
|
}
|
|
1281
970
|
)
|
|
1282
971
|
] })
|
|
@@ -1286,8 +975,29 @@ function BenefitsTable() {
|
|
|
1286
975
|
}
|
|
1287
976
|
var BenefitsTable_default = BenefitsTable;
|
|
1288
977
|
|
|
978
|
+
// src/components/UI/Text/index.tsx
|
|
979
|
+
import classNames6 from "classnames";
|
|
980
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
981
|
+
function Text(props) {
|
|
982
|
+
return /* @__PURE__ */ jsx10(
|
|
983
|
+
"p",
|
|
984
|
+
{
|
|
985
|
+
className: classNames6(
|
|
986
|
+
"font-normal text-sm",
|
|
987
|
+
props.textAlign && `text-${props.textAlign}`,
|
|
988
|
+
props.className
|
|
989
|
+
),
|
|
990
|
+
style: { color: props.textColor || "var(--pbm-text)", fontSize: props.textSize, textAlign: props.textAlign },
|
|
991
|
+
"data-testid": "test_id_text",
|
|
992
|
+
id: "text_pbm",
|
|
993
|
+
children: props.children
|
|
994
|
+
}
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
var Text_default = Text;
|
|
998
|
+
|
|
1289
999
|
// src/components/SecurityNumberInvalid/index.tsx
|
|
1290
|
-
import { jsx as
|
|
1000
|
+
import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1291
1001
|
function SecurityNumberInvalid({ textColor }) {
|
|
1292
1002
|
const { urlAcceptTerms } = usePBMStore();
|
|
1293
1003
|
const { setModal } = useModal();
|
|
@@ -1295,7 +1005,7 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
1295
1005
|
if (!urlAcceptTerms) return;
|
|
1296
1006
|
setModal({ open: true, id: "iframe_pbm", label: "Aceitar os termos", url: urlAcceptTerms });
|
|
1297
1007
|
};
|
|
1298
|
-
return /* @__PURE__ */
|
|
1008
|
+
return /* @__PURE__ */ jsxs7(
|
|
1299
1009
|
"section",
|
|
1300
1010
|
{
|
|
1301
1011
|
"data-testid": "test_id_invalid",
|
|
@@ -1303,13 +1013,13 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
1303
1013
|
style: { borderColor: "color-mix(in srgb, var(--pbm-text), transparent 80%)" },
|
|
1304
1014
|
id: "security_number_invalid_container_pbm",
|
|
1305
1015
|
children: [
|
|
1306
|
-
/* @__PURE__ */
|
|
1307
|
-
/* @__PURE__ */
|
|
1016
|
+
/* @__PURE__ */ jsx11(Title_default, { className: "w-full", textColor, children: "CPF n\xE3o cadastrado." }),
|
|
1017
|
+
/* @__PURE__ */ jsxs7(Text_default, { className: "w-full", textColor, children: [
|
|
1308
1018
|
"Conclua seu cadastro para habilitar o benef\xEDcio. ",
|
|
1309
|
-
/* @__PURE__ */
|
|
1019
|
+
/* @__PURE__ */ jsx11("br", {}),
|
|
1310
1020
|
"Ao clicar em \u201CAceitar os termos\u201D, voc\xEA ir\xE1 para uma p\xE1gina externa. Aceite os termos e volte para continuar."
|
|
1311
1021
|
] }),
|
|
1312
|
-
/* @__PURE__ */
|
|
1022
|
+
/* @__PURE__ */ jsx11(Button_default, { onClick: () => handleOpenModal(), style: { backgroundColor: "var(--pbm-primary)" }, children: "Aceitar os termos" })
|
|
1313
1023
|
]
|
|
1314
1024
|
}
|
|
1315
1025
|
);
|
|
@@ -1317,7 +1027,7 @@ function SecurityNumberInvalid({ textColor }) {
|
|
|
1317
1027
|
var SecurityNumberInvalid_default = SecurityNumberInvalid;
|
|
1318
1028
|
|
|
1319
1029
|
// src/components/SecurityNumberRegitered/index.tsx
|
|
1320
|
-
import { jsx as
|
|
1030
|
+
import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1321
1031
|
function SecurityNumberRegitered({ textColor }) {
|
|
1322
1032
|
const { urlRegisterIndustry } = usePBMStore();
|
|
1323
1033
|
const { setModal } = useModal();
|
|
@@ -1325,7 +1035,7 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
1325
1035
|
if (!urlRegisterIndustry) return;
|
|
1326
1036
|
setModal({ open: true, id: "iframe_pbm", label: "Ativar CPF", url: urlRegisterIndustry });
|
|
1327
1037
|
};
|
|
1328
|
-
return /* @__PURE__ */
|
|
1038
|
+
return /* @__PURE__ */ jsxs8(
|
|
1329
1039
|
"section",
|
|
1330
1040
|
{
|
|
1331
1041
|
"data-testid": "test_id_registered",
|
|
@@ -1333,9 +1043,9 @@ function SecurityNumberRegitered({ textColor }) {
|
|
|
1333
1043
|
style: { borderColor: "color-mix(in srgb, var(--pbm-text), transparent 80%)" },
|
|
1334
1044
|
id: "security_number_registered_container_pbm",
|
|
1335
1045
|
children: [
|
|
1336
|
-
/* @__PURE__ */
|
|
1337
|
-
/* @__PURE__ */
|
|
1338
|
-
/* @__PURE__ */
|
|
1046
|
+
/* @__PURE__ */ jsx12(Title_default, { className: "w-full", textColor, children: "Ops, seu CPF ainda n\xE3o est\xE1 habilitado para este produto." }),
|
|
1047
|
+
/* @__PURE__ */ jsx12(Text_default, { className: "w-full", textColor, children: "Para ativar o benef\xEDcio, clique em \u201CAtivar CPF\u201D e conclua a etapa na p\xE1gina externa. Depois, \xE9 s\xF3 voltar para continuar \u2014 vamos aguardar voc\xEA aqui." }),
|
|
1048
|
+
/* @__PURE__ */ jsx12(Button_default, { onClick: () => handleOpenModal(), style: { backgroundColor: "var(--pbm-primary)" }, children: "Ativar CPF" })
|
|
1339
1049
|
]
|
|
1340
1050
|
}
|
|
1341
1051
|
);
|
|
@@ -1346,7 +1056,7 @@ var SecurityNumberRegitered_default = SecurityNumberRegitered;
|
|
|
1346
1056
|
import { RefreshCw } from "lucide-react";
|
|
1347
1057
|
|
|
1348
1058
|
// src/libs/zustand/useError.tsx
|
|
1349
|
-
import { create as
|
|
1059
|
+
import { create as create2 } from "zustand";
|
|
1350
1060
|
var initialErrorState = {
|
|
1351
1061
|
ErrorMessage: "Erro ao aplicar o benef\xEDcio"
|
|
1352
1062
|
};
|
|
@@ -1355,17 +1065,17 @@ var createErrorStore = (set) => ({
|
|
|
1355
1065
|
setErrorMessage: (ErrorMessage) => set({ ErrorMessage }),
|
|
1356
1066
|
resetErrorMessage: () => set({ ErrorMessage: initialErrorState.ErrorMessage })
|
|
1357
1067
|
});
|
|
1358
|
-
var useError =
|
|
1068
|
+
var useError = create2(createErrorStore);
|
|
1359
1069
|
|
|
1360
1070
|
// src/components/Errors/ErrorToApplyBenefits.tsx
|
|
1361
|
-
import { jsx as
|
|
1071
|
+
import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1362
1072
|
var ErrorToApplyBenefits = () => {
|
|
1363
1073
|
const { ErrorMessage } = useError();
|
|
1364
1074
|
const { setState } = usePBMStore();
|
|
1365
|
-
return /* @__PURE__ */
|
|
1366
|
-
/* @__PURE__ */
|
|
1367
|
-
/* @__PURE__ */
|
|
1368
|
-
/* @__PURE__ */
|
|
1075
|
+
return /* @__PURE__ */ jsxs9(Container_default, { variant: "main", children: [
|
|
1076
|
+
/* @__PURE__ */ jsx13(Title_default, { children: "Erro ao Aplicar o Benef\xEDcio" }),
|
|
1077
|
+
/* @__PURE__ */ jsx13(Text_default, { textAlign: "center", children: ErrorMessage }),
|
|
1078
|
+
/* @__PURE__ */ jsxs9(
|
|
1369
1079
|
Button_default,
|
|
1370
1080
|
{
|
|
1371
1081
|
className: "bg-transparent p-0 pl-2 w-auto h-auto underline cursor-pointer hover:bg-transparent flex items-center justify-start gap-1",
|
|
@@ -1375,8 +1085,8 @@ var ErrorToApplyBenefits = () => {
|
|
|
1375
1085
|
onClick: () => setState("isEmpty"),
|
|
1376
1086
|
id: "check_benefits_button",
|
|
1377
1087
|
children: [
|
|
1378
|
-
/* @__PURE__ */
|
|
1379
|
-
/* @__PURE__ */
|
|
1088
|
+
/* @__PURE__ */ jsx13("span", { children: "Tentar novamente" }),
|
|
1089
|
+
/* @__PURE__ */ jsx13(RefreshCw, { size: 16 })
|
|
1380
1090
|
]
|
|
1381
1091
|
}
|
|
1382
1092
|
)
|
|
@@ -1385,22 +1095,63 @@ var ErrorToApplyBenefits = () => {
|
|
|
1385
1095
|
var ErrorToApplyBenefits_default = ErrorToApplyBenefits;
|
|
1386
1096
|
|
|
1387
1097
|
// src/components/Modals/CustomerNotRegistered/index.tsx
|
|
1388
|
-
import { useState as
|
|
1389
|
-
|
|
1098
|
+
import { useState as useState8 } from "react";
|
|
1099
|
+
|
|
1100
|
+
// src/libs/zustand/usePBMForm.tsx
|
|
1101
|
+
import { create as create3 } from "zustand";
|
|
1102
|
+
var initialPBMFormState = {
|
|
1103
|
+
personalData: { name: "", phone: "", birthday: "", email: "" },
|
|
1104
|
+
address: {
|
|
1105
|
+
postalcode: "",
|
|
1106
|
+
number: "",
|
|
1107
|
+
complement: "",
|
|
1108
|
+
street: "",
|
|
1109
|
+
neighborhood: "",
|
|
1110
|
+
city: "",
|
|
1111
|
+
uf: "",
|
|
1112
|
+
stateAddress: ""
|
|
1113
|
+
},
|
|
1114
|
+
genderResponsibility: { gender: "", patient: null },
|
|
1115
|
+
doctor: { typeCredential: "CRM", register: "", state: "", doctorName: "" },
|
|
1116
|
+
acceptances: {
|
|
1117
|
+
acceptPhone: false,
|
|
1118
|
+
acceptsSms: false,
|
|
1119
|
+
acceptsEmail: false,
|
|
1120
|
+
acceptsMail: false,
|
|
1121
|
+
acceptsPrivacyTermsLGPD: false
|
|
1122
|
+
},
|
|
1123
|
+
step: 0
|
|
1124
|
+
};
|
|
1125
|
+
var usePBMFormStore = create3((set) => ({
|
|
1126
|
+
...initialPBMFormState,
|
|
1127
|
+
setPersonalData: (data) => set((s) => ({ personalData: { ...s.personalData, ...data } })),
|
|
1128
|
+
setAddress: (data) => set((s) => ({ address: { ...s.address, ...data } })),
|
|
1129
|
+
setGenderResponsibility: (data) => set((s) => ({
|
|
1130
|
+
genderResponsibility: { ...s.genderResponsibility, ...data }
|
|
1131
|
+
})),
|
|
1132
|
+
setDoctor: (data) => set((s) => ({ doctor: { ...s.doctor, ...data } })),
|
|
1133
|
+
setAcceptances: (data) => set((s) => ({ acceptances: { ...s.acceptances, ...data } })),
|
|
1134
|
+
setStep: (step) => set({ step }),
|
|
1135
|
+
resetForm: () => set(initialPBMFormState)
|
|
1136
|
+
}));
|
|
1137
|
+
var usePBMForm = usePBMFormStore;
|
|
1138
|
+
|
|
1139
|
+
// src/components/Modals/CustomerNotRegistered/index.tsx
|
|
1140
|
+
import classNames12 from "classnames";
|
|
1390
1141
|
|
|
1391
1142
|
// src/components/Modals/CustomerNotRegistered/StepPersonalDataForm.tsx
|
|
1392
|
-
import { useState as
|
|
1143
|
+
import { useState as useState3 } from "react";
|
|
1393
1144
|
|
|
1394
1145
|
// src/components/Modals/CustomerNotRegistered/Shared/FieldWrapper.tsx
|
|
1395
|
-
import { jsx as
|
|
1146
|
+
import { jsx as jsx14, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
1396
1147
|
var FieldWrapper = ({
|
|
1397
1148
|
label,
|
|
1398
1149
|
error,
|
|
1399
1150
|
children
|
|
1400
|
-
}) => /* @__PURE__ */
|
|
1401
|
-
/* @__PURE__ */
|
|
1151
|
+
}) => /* @__PURE__ */ jsxs10("div", { className: "flex flex-col gap-1", children: [
|
|
1152
|
+
/* @__PURE__ */ jsx14("label", { className: "text-xs font-medium text-zinc-500 uppercase tracking-wide", children: label }),
|
|
1402
1153
|
children,
|
|
1403
|
-
error && /* @__PURE__ */
|
|
1154
|
+
error && /* @__PURE__ */ jsx14("span", { className: "text-xs text-red-500 mt-0.5", children: error })
|
|
1404
1155
|
] });
|
|
1405
1156
|
var FieldWrapper_default = FieldWrapper;
|
|
1406
1157
|
|
|
@@ -1409,8 +1160,8 @@ var disabledInputClass = "w-full rounded-lg border border-gray-200 bg-gray-100 p
|
|
|
1409
1160
|
var DisabledInputClass_default = disabledInputClass;
|
|
1410
1161
|
|
|
1411
1162
|
// src/components/Modals/CustomerNotRegistered/Shared/InputClass.ts
|
|
1412
|
-
import
|
|
1413
|
-
var inputClass = (error) =>
|
|
1163
|
+
import classNames7 from "classnames";
|
|
1164
|
+
var inputClass = (error) => classNames7(
|
|
1414
1165
|
"w-full rounded-lg border px-3 py-2.5 text-sm text-gray-800 outline-none transition-all",
|
|
1415
1166
|
"focus:ring-2 focus:ring-blue-500/30 focus:border-blue-500",
|
|
1416
1167
|
error ? "border-red-400 bg-red-50" : "border-gray-200 bg-gray-50 hover:border-gray-300"
|
|
@@ -1418,16 +1169,16 @@ var inputClass = (error) => classNames8(
|
|
|
1418
1169
|
var InputClass_default = inputClass;
|
|
1419
1170
|
|
|
1420
1171
|
// src/components/Modals/CustomerNotRegistered/Shared/StepActions.tsx
|
|
1421
|
-
import
|
|
1422
|
-
import { jsx as
|
|
1172
|
+
import classNames8 from "classnames";
|
|
1173
|
+
import { jsx as jsx15, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
1423
1174
|
var StepActions = ({
|
|
1424
1175
|
onNext,
|
|
1425
1176
|
onBack,
|
|
1426
1177
|
loading,
|
|
1427
1178
|
nextLabel = "Continuar",
|
|
1428
1179
|
isLast = false
|
|
1429
|
-
}) => /* @__PURE__ */
|
|
1430
|
-
onBack && /* @__PURE__ */
|
|
1180
|
+
}) => /* @__PURE__ */ jsxs11("div", { className: "flex gap-2 mt-2 pt-4 border-t border-gray-100", children: [
|
|
1181
|
+
onBack && /* @__PURE__ */ jsx15(
|
|
1431
1182
|
"button",
|
|
1432
1183
|
{
|
|
1433
1184
|
type: "button",
|
|
@@ -1436,20 +1187,20 @@ var StepActions = ({
|
|
|
1436
1187
|
children: "Voltar"
|
|
1437
1188
|
}
|
|
1438
1189
|
),
|
|
1439
|
-
/* @__PURE__ */
|
|
1190
|
+
/* @__PURE__ */ jsx15(
|
|
1440
1191
|
"button",
|
|
1441
1192
|
{
|
|
1442
1193
|
type: "button",
|
|
1443
1194
|
onClick: onNext,
|
|
1444
1195
|
disabled: loading,
|
|
1445
|
-
className:
|
|
1196
|
+
className: classNames8(
|
|
1446
1197
|
"flex-2 rounded-lg py-2.5 text-sm font-semibold text-white transition-all cursor-pointer",
|
|
1447
1198
|
isLast ? "bg-emerald-600 hover:bg-emerald-500" : "bg-(--pbm-primary) hover:bg-(--pbm-primary)/60",
|
|
1448
1199
|
loading && "opacity-60 cursor-not-allowed"
|
|
1449
1200
|
),
|
|
1450
|
-
children: loading ? /* @__PURE__ */
|
|
1451
|
-
/* @__PURE__ */
|
|
1452
|
-
/* @__PURE__ */
|
|
1201
|
+
children: loading ? /* @__PURE__ */ jsxs11("span", { className: "flex items-center justify-center gap-2", children: [
|
|
1202
|
+
/* @__PURE__ */ jsxs11("svg", { className: "h-4 w-4 animate-spin", viewBox: "0 0 24 24", fill: "none", children: [
|
|
1203
|
+
/* @__PURE__ */ jsx15(
|
|
1453
1204
|
"circle",
|
|
1454
1205
|
{
|
|
1455
1206
|
className: "opacity-25",
|
|
@@ -1460,7 +1211,7 @@ var StepActions = ({
|
|
|
1460
1211
|
strokeWidth: "4"
|
|
1461
1212
|
}
|
|
1462
1213
|
),
|
|
1463
|
-
/* @__PURE__ */
|
|
1214
|
+
/* @__PURE__ */ jsx15(
|
|
1464
1215
|
"path",
|
|
1465
1216
|
{
|
|
1466
1217
|
className: "opacity-75",
|
|
@@ -1476,40 +1227,25 @@ var StepActions = ({
|
|
|
1476
1227
|
] });
|
|
1477
1228
|
var StepActions_default = StepActions;
|
|
1478
1229
|
|
|
1479
|
-
// src/
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
}
|
|
1487
|
-
const response = await fetch(`${API_URL}/programregistration/personalData`, {
|
|
1488
|
-
method: "PUT",
|
|
1489
|
-
headers: {
|
|
1490
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
1491
|
-
"Content-Type": "application/json"
|
|
1492
|
-
},
|
|
1493
|
-
body: JSON.stringify({ document, requestId, ...personalData })
|
|
1494
|
-
});
|
|
1495
|
-
const dataResponse = await response.json();
|
|
1496
|
-
if (!dataResponse.success) {
|
|
1497
|
-
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
1498
|
-
}
|
|
1499
|
-
return dataResponse;
|
|
1230
|
+
// src/utils/mappingFormStep.ts
|
|
1231
|
+
var mappingFormStep = {
|
|
1232
|
+
"PersonalData": 0,
|
|
1233
|
+
"Address": 1,
|
|
1234
|
+
"GenderResponsibility": 2,
|
|
1235
|
+
"Doctor": 3,
|
|
1236
|
+
"Acceptances": 4
|
|
1500
1237
|
};
|
|
1501
1238
|
|
|
1502
1239
|
// src/components/Modals/CustomerNotRegistered/StepPersonalDataForm.tsx
|
|
1503
|
-
import { jsx as
|
|
1240
|
+
import { jsx as jsx16, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
1504
1241
|
var StepPersonalDataForm = ({
|
|
1505
1242
|
securityNumber,
|
|
1506
1243
|
onNext
|
|
1507
1244
|
}) => {
|
|
1508
1245
|
const { personalData, setPersonalData, setStep } = usePBMForm();
|
|
1509
1246
|
const { setModal } = useModal();
|
|
1510
|
-
const
|
|
1511
|
-
const [
|
|
1512
|
-
const [loading, setLoading] = useState4(false);
|
|
1247
|
+
const [errors, setErrors] = useState3({});
|
|
1248
|
+
const [loading, setLoading] = useState3(false);
|
|
1513
1249
|
const validate = () => {
|
|
1514
1250
|
const e = {};
|
|
1515
1251
|
if (!personalData.name.trim() || personalData.name.trim().split(" ").length < 2)
|
|
@@ -1526,15 +1262,6 @@ var StepPersonalDataForm = ({
|
|
|
1526
1262
|
if (!validate()) return;
|
|
1527
1263
|
setLoading(true);
|
|
1528
1264
|
try {
|
|
1529
|
-
const response = await SetPersonalDataForm({
|
|
1530
|
-
document: securityNumber,
|
|
1531
|
-
requestId: store.requestId,
|
|
1532
|
-
personalData
|
|
1533
|
-
});
|
|
1534
|
-
if (!response.success) {
|
|
1535
|
-
console.error("Failed to set personal data form:", response.message);
|
|
1536
|
-
return;
|
|
1537
|
-
}
|
|
1538
1265
|
setStep(mappingFormStep["Address"]);
|
|
1539
1266
|
onNext();
|
|
1540
1267
|
} catch {
|
|
@@ -1543,9 +1270,9 @@ var StepPersonalDataForm = ({
|
|
|
1543
1270
|
setLoading(false);
|
|
1544
1271
|
}
|
|
1545
1272
|
};
|
|
1546
|
-
return /* @__PURE__ */
|
|
1547
|
-
/* @__PURE__ */
|
|
1548
|
-
/* @__PURE__ */
|
|
1273
|
+
return /* @__PURE__ */ jsxs12("div", { className: "flex flex-col gap-4", children: [
|
|
1274
|
+
/* @__PURE__ */ jsxs12(FieldWrapper_default, { label: "CPF", children: [
|
|
1275
|
+
/* @__PURE__ */ jsx16(
|
|
1549
1276
|
"input",
|
|
1550
1277
|
{
|
|
1551
1278
|
className: DisabledInputClass_default,
|
|
@@ -1554,7 +1281,7 @@ var StepPersonalDataForm = ({
|
|
|
1554
1281
|
readOnly: true
|
|
1555
1282
|
}
|
|
1556
1283
|
),
|
|
1557
|
-
/* @__PURE__ */
|
|
1284
|
+
/* @__PURE__ */ jsx16("p", { className: "text-xs text-gray-400 mt-1", children: /* @__PURE__ */ jsx16(
|
|
1558
1285
|
"button",
|
|
1559
1286
|
{
|
|
1560
1287
|
type: "button",
|
|
@@ -1564,7 +1291,7 @@ var StepPersonalDataForm = ({
|
|
|
1564
1291
|
}
|
|
1565
1292
|
) })
|
|
1566
1293
|
] }),
|
|
1567
|
-
/* @__PURE__ */
|
|
1294
|
+
/* @__PURE__ */ jsx16(FieldWrapper_default, { label: "Nome completo", error: errors.name, children: /* @__PURE__ */ jsx16(
|
|
1568
1295
|
"input",
|
|
1569
1296
|
{
|
|
1570
1297
|
className: InputClass_default(errors.name),
|
|
@@ -1576,8 +1303,8 @@ var StepPersonalDataForm = ({
|
|
|
1576
1303
|
}
|
|
1577
1304
|
}
|
|
1578
1305
|
) }),
|
|
1579
|
-
/* @__PURE__ */
|
|
1580
|
-
/* @__PURE__ */
|
|
1306
|
+
/* @__PURE__ */ jsxs12("div", { className: "grid grid-cols-2 gap-3", children: [
|
|
1307
|
+
/* @__PURE__ */ jsx16(FieldWrapper_default, { label: "Telefone", error: errors.phone, children: /* @__PURE__ */ jsx16(
|
|
1581
1308
|
"input",
|
|
1582
1309
|
{
|
|
1583
1310
|
className: InputClass_default(errors.phone),
|
|
@@ -1589,7 +1316,7 @@ var StepPersonalDataForm = ({
|
|
|
1589
1316
|
}
|
|
1590
1317
|
}
|
|
1591
1318
|
) }),
|
|
1592
|
-
/* @__PURE__ */
|
|
1319
|
+
/* @__PURE__ */ jsx16(FieldWrapper_default, { label: "Data de nascimento", error: errors.birthday, children: /* @__PURE__ */ jsx16(
|
|
1593
1320
|
"input",
|
|
1594
1321
|
{
|
|
1595
1322
|
type: "date",
|
|
@@ -1602,7 +1329,7 @@ var StepPersonalDataForm = ({
|
|
|
1602
1329
|
}
|
|
1603
1330
|
) })
|
|
1604
1331
|
] }),
|
|
1605
|
-
/* @__PURE__ */
|
|
1332
|
+
/* @__PURE__ */ jsx16(FieldWrapper_default, { label: "E-mail", error: errors.email, children: /* @__PURE__ */ jsx16(
|
|
1606
1333
|
"input",
|
|
1607
1334
|
{
|
|
1608
1335
|
type: "email",
|
|
@@ -1615,89 +1342,53 @@ var StepPersonalDataForm = ({
|
|
|
1615
1342
|
}
|
|
1616
1343
|
}
|
|
1617
1344
|
) }),
|
|
1618
|
-
/* @__PURE__ */
|
|
1345
|
+
/* @__PURE__ */ jsx16(StepActions_default, { onNext: handleSubmit, loading })
|
|
1619
1346
|
] });
|
|
1620
1347
|
};
|
|
1621
1348
|
var StepPersonalDataForm_default = StepPersonalDataForm;
|
|
1622
1349
|
|
|
1623
1350
|
// src/components/Modals/CustomerNotRegistered/StepAddressForm.tsx
|
|
1624
|
-
import { useCallback as useCallback2, useState as
|
|
1351
|
+
import { useCallback as useCallback2, useState as useState4 } from "react";
|
|
1625
1352
|
|
|
1626
1353
|
// src/services/lookup-postal-code.ts
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
if (!AUTH_TOKEN) {
|
|
1632
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
1633
|
-
}
|
|
1634
|
-
const response = await fetch(`${API_URL}/programregistration/consulta-cep/${POSTAL_CODE}`, {
|
|
1635
|
-
method: "GET",
|
|
1636
|
-
headers: {
|
|
1637
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
1638
|
-
"Content-Type": "application/json"
|
|
1639
|
-
}
|
|
1640
|
-
});
|
|
1641
|
-
const dataResponse = await response.json();
|
|
1642
|
-
if (!dataResponse.success) {
|
|
1643
|
-
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
1644
|
-
}
|
|
1645
|
-
return dataResponse;
|
|
1646
|
-
};
|
|
1647
|
-
|
|
1648
|
-
// src/services/set-address-data-form.ts
|
|
1649
|
-
import Cookies6 from "js-cookie";
|
|
1650
|
-
var SetAddressDataForm = async ({ document, requestId, address }) => {
|
|
1651
|
-
const API_URL = getEnv("VITE_API_URL");
|
|
1652
|
-
const AUTH_TOKEN = Cookies6.get("pbm-token");
|
|
1653
|
-
if (!AUTH_TOKEN) {
|
|
1654
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
1655
|
-
}
|
|
1656
|
-
const response = await fetch(`${API_URL}/programregistration/address`, {
|
|
1657
|
-
method: "PUT",
|
|
1658
|
-
headers: {
|
|
1659
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
1660
|
-
"Content-Type": "application/json"
|
|
1661
|
-
},
|
|
1662
|
-
body: JSON.stringify({ document, requestId, ...address })
|
|
1663
|
-
});
|
|
1664
|
-
const dataResponse = await response.json();
|
|
1665
|
-
if (!dataResponse.success) {
|
|
1666
|
-
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
1354
|
+
async function LookupPostalCode({ postal_code }) {
|
|
1355
|
+
const response = await fetch(`${getEnv("VITE_CORREIOS_API_URL")}/${postal_code}/json/`);
|
|
1356
|
+
if (!response.ok) {
|
|
1357
|
+
throw new Error("Erro ao consultar CEP");
|
|
1667
1358
|
}
|
|
1668
|
-
|
|
1669
|
-
};
|
|
1359
|
+
const data = await response.json();
|
|
1360
|
+
return { ...data, success: true };
|
|
1361
|
+
}
|
|
1670
1362
|
|
|
1671
1363
|
// src/components/Modals/CustomerNotRegistered/StepAddressForm.tsx
|
|
1672
|
-
import { jsx as
|
|
1364
|
+
import { jsx as jsx17, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1673
1365
|
var StepAddressForm = ({
|
|
1674
|
-
securityNumber,
|
|
1675
1366
|
onNext,
|
|
1676
1367
|
onBack
|
|
1677
1368
|
}) => {
|
|
1678
1369
|
const { address, setAddress, setStep } = usePBMForm();
|
|
1679
|
-
const
|
|
1680
|
-
const [
|
|
1681
|
-
const [
|
|
1682
|
-
const [loading, setLoading] = useState5(false);
|
|
1370
|
+
const [errors, setErrors] = useState4({});
|
|
1371
|
+
const [loadingCep, setLoadingCep] = useState4(false);
|
|
1372
|
+
const [loading, setLoading] = useState4(false);
|
|
1683
1373
|
const fetchCEP = useCallback2(
|
|
1684
1374
|
async (cep) => {
|
|
1685
1375
|
const raw = cep.replace(/\D/g, "");
|
|
1686
1376
|
if (raw.length !== 8) return;
|
|
1687
1377
|
setLoadingCep(true);
|
|
1688
1378
|
try {
|
|
1689
|
-
const response = await LookupPostalCode({
|
|
1379
|
+
const response = await LookupPostalCode({ postal_code: raw });
|
|
1690
1380
|
if (!response.success) {
|
|
1691
1381
|
console.error("Failed to lookup postal code");
|
|
1692
1382
|
return;
|
|
1693
1383
|
}
|
|
1694
1384
|
setAddress({
|
|
1695
|
-
street: response.
|
|
1696
|
-
neighborhood: response.
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1385
|
+
street: response.logradouro,
|
|
1386
|
+
neighborhood: response.bairro,
|
|
1387
|
+
uf: response.uf,
|
|
1388
|
+
city: response.localidade,
|
|
1389
|
+
stateAddress: response.estado,
|
|
1390
|
+
postalcode: response.cep,
|
|
1391
|
+
complement: response.complemento || ""
|
|
1701
1392
|
});
|
|
1702
1393
|
} catch {
|
|
1703
1394
|
console.error("Failed to fetch address for CEP:", cep);
|
|
@@ -1719,19 +1410,6 @@ var StepAddressForm = ({
|
|
|
1719
1410
|
if (!validate()) return;
|
|
1720
1411
|
setLoading(true);
|
|
1721
1412
|
try {
|
|
1722
|
-
const response = await SetAddressDataForm({
|
|
1723
|
-
document: securityNumber,
|
|
1724
|
-
requestId: store.requestId,
|
|
1725
|
-
address: {
|
|
1726
|
-
postalcode: address.postalcode.replace(/\D/g, ""),
|
|
1727
|
-
number: address.number,
|
|
1728
|
-
complement: address.complement
|
|
1729
|
-
}
|
|
1730
|
-
});
|
|
1731
|
-
if (!response.success) {
|
|
1732
|
-
console.log("Failed to set address data form:", response.message);
|
|
1733
|
-
return;
|
|
1734
|
-
}
|
|
1735
1413
|
setStep(mappingFormStep["GenderResponsibility"]);
|
|
1736
1414
|
onNext();
|
|
1737
1415
|
} catch {
|
|
@@ -1740,9 +1418,9 @@ var StepAddressForm = ({
|
|
|
1740
1418
|
setLoading(false);
|
|
1741
1419
|
}
|
|
1742
1420
|
};
|
|
1743
|
-
return /* @__PURE__ */
|
|
1744
|
-
/* @__PURE__ */
|
|
1745
|
-
/* @__PURE__ */
|
|
1421
|
+
return /* @__PURE__ */ jsxs13("div", { className: "flex flex-col gap-4", children: [
|
|
1422
|
+
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "CEP", error: errors.postalcode, children: /* @__PURE__ */ jsxs13("div", { className: "relative", children: [
|
|
1423
|
+
/* @__PURE__ */ jsx17(
|
|
1746
1424
|
"input",
|
|
1747
1425
|
{
|
|
1748
1426
|
className: InputClass_default(errors.postalcode),
|
|
@@ -1760,14 +1438,14 @@ var StepAddressForm = ({
|
|
|
1760
1438
|
}
|
|
1761
1439
|
}
|
|
1762
1440
|
),
|
|
1763
|
-
loadingCep && /* @__PURE__ */
|
|
1441
|
+
loadingCep && /* @__PURE__ */ jsx17("div", { className: "absolute right-3 top-1/2 -translate-y-1/2", children: /* @__PURE__ */ jsxs13(
|
|
1764
1442
|
"svg",
|
|
1765
1443
|
{
|
|
1766
1444
|
className: "h-4 w-4 animate-spin text-blue-500",
|
|
1767
1445
|
viewBox: "0 0 24 24",
|
|
1768
1446
|
fill: "none",
|
|
1769
1447
|
children: [
|
|
1770
|
-
/* @__PURE__ */
|
|
1448
|
+
/* @__PURE__ */ jsx17(
|
|
1771
1449
|
"circle",
|
|
1772
1450
|
{
|
|
1773
1451
|
className: "opacity-25",
|
|
@@ -1778,7 +1456,7 @@ var StepAddressForm = ({
|
|
|
1778
1456
|
strokeWidth: "4"
|
|
1779
1457
|
}
|
|
1780
1458
|
),
|
|
1781
|
-
/* @__PURE__ */
|
|
1459
|
+
/* @__PURE__ */ jsx17(
|
|
1782
1460
|
"path",
|
|
1783
1461
|
{
|
|
1784
1462
|
className: "opacity-75",
|
|
@@ -1790,8 +1468,8 @@ var StepAddressForm = ({
|
|
|
1790
1468
|
}
|
|
1791
1469
|
) })
|
|
1792
1470
|
] }) }),
|
|
1793
|
-
/* @__PURE__ */
|
|
1794
|
-
/* @__PURE__ */
|
|
1471
|
+
/* @__PURE__ */ jsxs13("div", { className: "grid grid-cols-2 gap-3", children: [
|
|
1472
|
+
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Rua", children: /* @__PURE__ */ jsx17(
|
|
1795
1473
|
"input",
|
|
1796
1474
|
{
|
|
1797
1475
|
className: DisabledInputClass_default,
|
|
@@ -1801,7 +1479,7 @@ var StepAddressForm = ({
|
|
|
1801
1479
|
placeholder: "Preenchido pelo CEP"
|
|
1802
1480
|
}
|
|
1803
1481
|
) }),
|
|
1804
|
-
/* @__PURE__ */
|
|
1482
|
+
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Bairro", children: /* @__PURE__ */ jsx17(
|
|
1805
1483
|
"input",
|
|
1806
1484
|
{
|
|
1807
1485
|
className: DisabledInputClass_default,
|
|
@@ -1812,8 +1490,8 @@ var StepAddressForm = ({
|
|
|
1812
1490
|
}
|
|
1813
1491
|
) })
|
|
1814
1492
|
] }),
|
|
1815
|
-
/* @__PURE__ */
|
|
1816
|
-
/* @__PURE__ */
|
|
1493
|
+
/* @__PURE__ */ jsxs13("div", { className: "grid grid-cols-2 gap-3", children: [
|
|
1494
|
+
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Cidade", children: /* @__PURE__ */ jsx17(
|
|
1817
1495
|
"input",
|
|
1818
1496
|
{
|
|
1819
1497
|
className: DisabledInputClass_default,
|
|
@@ -1823,7 +1501,7 @@ var StepAddressForm = ({
|
|
|
1823
1501
|
placeholder: "Preenchido pelo CEP"
|
|
1824
1502
|
}
|
|
1825
1503
|
) }),
|
|
1826
|
-
/* @__PURE__ */
|
|
1504
|
+
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Estado", children: /* @__PURE__ */ jsx17(
|
|
1827
1505
|
"input",
|
|
1828
1506
|
{
|
|
1829
1507
|
className: DisabledInputClass_default,
|
|
@@ -1834,8 +1512,8 @@ var StepAddressForm = ({
|
|
|
1834
1512
|
}
|
|
1835
1513
|
) })
|
|
1836
1514
|
] }),
|
|
1837
|
-
/* @__PURE__ */
|
|
1838
|
-
/* @__PURE__ */
|
|
1515
|
+
/* @__PURE__ */ jsxs13("div", { className: "grid grid-cols-2 gap-3", children: [
|
|
1516
|
+
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "N\xFAmero", error: errors.number, children: /* @__PURE__ */ jsx17(
|
|
1839
1517
|
"input",
|
|
1840
1518
|
{
|
|
1841
1519
|
className: InputClass_default(errors.number),
|
|
@@ -1847,7 +1525,7 @@ var StepAddressForm = ({
|
|
|
1847
1525
|
}
|
|
1848
1526
|
}
|
|
1849
1527
|
) }),
|
|
1850
|
-
/* @__PURE__ */
|
|
1528
|
+
/* @__PURE__ */ jsx17(FieldWrapper_default, { label: "Complemento", children: /* @__PURE__ */ jsx17(
|
|
1851
1529
|
"input",
|
|
1852
1530
|
{
|
|
1853
1531
|
className: InputClass_default(),
|
|
@@ -1857,51 +1535,24 @@ var StepAddressForm = ({
|
|
|
1857
1535
|
}
|
|
1858
1536
|
) })
|
|
1859
1537
|
] }),
|
|
1860
|
-
/* @__PURE__ */
|
|
1538
|
+
/* @__PURE__ */ jsx17(StepActions_default, { onNext: handleSubmit, onBack, loading })
|
|
1861
1539
|
] });
|
|
1862
1540
|
};
|
|
1863
1541
|
var StepAddressForm_default = StepAddressForm;
|
|
1864
1542
|
|
|
1865
1543
|
// src/components/Modals/CustomerNotRegistered/StepGenderForm.tsx
|
|
1866
|
-
import
|
|
1867
|
-
import { useState as
|
|
1868
|
-
|
|
1869
|
-
// src/services/set-gender-responsability-data-form.ts
|
|
1870
|
-
import Cookies7 from "js-cookie";
|
|
1871
|
-
var SetGenderResponsabilityDataForm = async ({ document, requestId, identity_responsibility }) => {
|
|
1872
|
-
const API_URL = getEnv("VITE_API_URL");
|
|
1873
|
-
const AUTH_TOKEN = Cookies7.get("pbm-token");
|
|
1874
|
-
if (!AUTH_TOKEN) {
|
|
1875
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
1876
|
-
}
|
|
1877
|
-
const response = await fetch(`${API_URL}/programregistration/genderResponsibility`, {
|
|
1878
|
-
method: "PUT",
|
|
1879
|
-
headers: {
|
|
1880
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
1881
|
-
"Content-Type": "application/json"
|
|
1882
|
-
},
|
|
1883
|
-
body: JSON.stringify({ document, requestId, ...identity_responsibility })
|
|
1884
|
-
});
|
|
1885
|
-
const dataResponse = await response.json();
|
|
1886
|
-
if (!dataResponse.success) {
|
|
1887
|
-
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
1888
|
-
}
|
|
1889
|
-
return dataResponse;
|
|
1890
|
-
};
|
|
1891
|
-
|
|
1892
|
-
// src/components/Modals/CustomerNotRegistered/StepGenderForm.tsx
|
|
1893
|
-
import { jsx as jsx19, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
1544
|
+
import classNames9 from "classnames";
|
|
1545
|
+
import { useState as useState5 } from "react";
|
|
1546
|
+
import { jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
1894
1547
|
var StepGenderForm = ({
|
|
1895
|
-
securityNumber,
|
|
1896
1548
|
onNext,
|
|
1897
1549
|
onBack
|
|
1898
1550
|
}) => {
|
|
1899
1551
|
const { genderResponsibility, setGenderResponsibility, setStep } = usePBMForm();
|
|
1900
|
-
const
|
|
1901
|
-
const [errors, setErrors] = useState6(
|
|
1552
|
+
const [errors, setErrors] = useState5(
|
|
1902
1553
|
{}
|
|
1903
1554
|
);
|
|
1904
|
-
const [loading, setLoading] =
|
|
1555
|
+
const [loading, setLoading] = useState5(false);
|
|
1905
1556
|
const validate = () => {
|
|
1906
1557
|
const e = {};
|
|
1907
1558
|
if (!genderResponsibility.gender) e.gender = "Selecione o g\xEAnero.";
|
|
@@ -1914,21 +1565,6 @@ var StepGenderForm = ({
|
|
|
1914
1565
|
if (!validate()) return;
|
|
1915
1566
|
setLoading(true);
|
|
1916
1567
|
try {
|
|
1917
|
-
const response = await SetGenderResponsabilityDataForm({
|
|
1918
|
-
document: securityNumber,
|
|
1919
|
-
requestId: store.requestId,
|
|
1920
|
-
identity_responsibility: {
|
|
1921
|
-
gender: genderResponsibility.gender,
|
|
1922
|
-
patient: genderResponsibility.patient
|
|
1923
|
-
}
|
|
1924
|
-
});
|
|
1925
|
-
if (!response.success) {
|
|
1926
|
-
console.error(
|
|
1927
|
-
"Failed to submit gender responsibility data:",
|
|
1928
|
-
response.message
|
|
1929
|
-
);
|
|
1930
|
-
return;
|
|
1931
|
-
}
|
|
1932
1568
|
setStep(mappingFormStep["Doctor"]);
|
|
1933
1569
|
onNext();
|
|
1934
1570
|
} catch {
|
|
@@ -1944,10 +1580,10 @@ var StepGenderForm = ({
|
|
|
1944
1580
|
{ value: "F", label: "Feminino" },
|
|
1945
1581
|
{ value: "O", label: "Outro" }
|
|
1946
1582
|
];
|
|
1947
|
-
return /* @__PURE__ */
|
|
1948
|
-
/* @__PURE__ */
|
|
1949
|
-
/* @__PURE__ */
|
|
1950
|
-
/* @__PURE__ */
|
|
1583
|
+
return /* @__PURE__ */ jsxs14("div", { className: "flex flex-col gap-5", children: [
|
|
1584
|
+
/* @__PURE__ */ jsxs14("div", { children: [
|
|
1585
|
+
/* @__PURE__ */ jsx18("label", { className: "text-xs font-medium text-gray-500 uppercase tracking-wide block mb-2", children: "G\xEAnero" }),
|
|
1586
|
+
/* @__PURE__ */ jsx18("div", { className: "flex gap-2", children: genderOptions.map((opt) => /* @__PURE__ */ jsx18(
|
|
1951
1587
|
"button",
|
|
1952
1588
|
{
|
|
1953
1589
|
type: "button",
|
|
@@ -1955,22 +1591,22 @@ var StepGenderForm = ({
|
|
|
1955
1591
|
setGenderResponsibility({ gender: opt.value });
|
|
1956
1592
|
setErrors((p) => ({ ...p, gender: void 0 }));
|
|
1957
1593
|
},
|
|
1958
|
-
className:
|
|
1959
|
-
"flex-1 py-2.5 rounded-lg border text-sm font-medium transition-all",
|
|
1960
|
-
genderResponsibility.gender === opt.value ? "border-
|
|
1594
|
+
className: classNames9(
|
|
1595
|
+
"flex-1 py-2.5 cursor-pointer px-2.5 rounded-lg border text-sm font-medium transition-all",
|
|
1596
|
+
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)"
|
|
1961
1597
|
),
|
|
1962
1598
|
children: opt.label
|
|
1963
1599
|
},
|
|
1964
1600
|
opt.value
|
|
1965
1601
|
)) }),
|
|
1966
|
-
errors.gender && /* @__PURE__ */
|
|
1602
|
+
errors.gender && /* @__PURE__ */ jsx18("span", { className: "text-xs text-red-500 mt-1 block", children: errors.gender })
|
|
1967
1603
|
] }),
|
|
1968
|
-
/* @__PURE__ */
|
|
1969
|
-
/* @__PURE__ */
|
|
1970
|
-
/* @__PURE__ */
|
|
1604
|
+
/* @__PURE__ */ jsxs14("div", { children: [
|
|
1605
|
+
/* @__PURE__ */ jsx18("label", { className: "text-xs font-medium text-gray-500 uppercase tracking-wide block mb-2", children: "Voc\xEA \xE9 o paciente?" }),
|
|
1606
|
+
/* @__PURE__ */ jsx18("div", { className: "flex gap-2", children: [
|
|
1971
1607
|
{ label: "Sim, sou o paciente", value: true },
|
|
1972
1608
|
{ label: "N\xE3o, sou respons\xE1vel", value: false }
|
|
1973
|
-
].map((opt) => /* @__PURE__ */
|
|
1609
|
+
].map((opt) => /* @__PURE__ */ jsx18(
|
|
1974
1610
|
"button",
|
|
1975
1611
|
{
|
|
1976
1612
|
type: "button",
|
|
@@ -1978,23 +1614,23 @@ var StepGenderForm = ({
|
|
|
1978
1614
|
setGenderResponsibility({ patient: opt.value });
|
|
1979
1615
|
setErrors((p) => ({ ...p, patient: void 0 }));
|
|
1980
1616
|
},
|
|
1981
|
-
className:
|
|
1982
|
-
"flex-1 py-2.5 rounded-lg border text-sm font-medium transition-all",
|
|
1983
|
-
genderResponsibility.patient === opt.value ? "border-
|
|
1617
|
+
className: classNames9(
|
|
1618
|
+
"flex-1 py-2.5 px-2.5 text-nowrap cursor-pointer rounded-lg border text-sm font-medium transition-all",
|
|
1619
|
+
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)"
|
|
1984
1620
|
),
|
|
1985
1621
|
children: opt.label
|
|
1986
1622
|
},
|
|
1987
1623
|
String(opt.value)
|
|
1988
1624
|
)) }),
|
|
1989
|
-
errors.patient && /* @__PURE__ */
|
|
1625
|
+
errors.patient && /* @__PURE__ */ jsx18("span", { className: "text-xs text-red-500 mt-1 block", children: errors.patient })
|
|
1990
1626
|
] }),
|
|
1991
|
-
/* @__PURE__ */
|
|
1627
|
+
/* @__PURE__ */ jsx18(StepActions_default, { onNext: handleSubmit, onBack, loading })
|
|
1992
1628
|
] });
|
|
1993
1629
|
};
|
|
1994
1630
|
var StepGenderForm_default = StepGenderForm;
|
|
1995
1631
|
|
|
1996
1632
|
// src/components/Modals/CustomerNotRegistered/StepDoctorForm.tsx
|
|
1997
|
-
import {
|
|
1633
|
+
import { useState as useState6 } from "react";
|
|
1998
1634
|
|
|
1999
1635
|
// src/utils/ufMapping.ts
|
|
2000
1636
|
var BRAZILIAN_STATES = [
|
|
@@ -2027,91 +1663,15 @@ var BRAZILIAN_STATES = [
|
|
|
2027
1663
|
"TO"
|
|
2028
1664
|
];
|
|
2029
1665
|
|
|
2030
|
-
// src/services/set-doctor-data-form.ts
|
|
2031
|
-
import Cookies8 from "js-cookie";
|
|
2032
|
-
var SetDoctorDataForm = async ({ document, requestId, doctor }) => {
|
|
2033
|
-
const API_URL = getEnv("VITE_API_URL");
|
|
2034
|
-
const AUTH_TOKEN = Cookies8.get("pbm-token");
|
|
2035
|
-
if (!AUTH_TOKEN) {
|
|
2036
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
2037
|
-
}
|
|
2038
|
-
const response = await fetch(`${API_URL}/programregistration/doctorName`, {
|
|
2039
|
-
method: "PUT",
|
|
2040
|
-
headers: {
|
|
2041
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
2042
|
-
"Content-Type": "application/json"
|
|
2043
|
-
},
|
|
2044
|
-
body: JSON.stringify({ document, requestId, ...doctor })
|
|
2045
|
-
});
|
|
2046
|
-
const dataResponse = await response.json();
|
|
2047
|
-
if (!dataResponse.success) {
|
|
2048
|
-
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
2049
|
-
}
|
|
2050
|
-
return dataResponse;
|
|
2051
|
-
};
|
|
2052
|
-
|
|
2053
|
-
// src/services/lookup-doctor.ts
|
|
2054
|
-
import Cookies9 from "js-cookie";
|
|
2055
|
-
var LookupDoctor = async ({ typeCredential, register, uf }) => {
|
|
2056
|
-
const API_URL = getEnv("VITE_API_URL");
|
|
2057
|
-
const AUTH_TOKEN = Cookies9.get("pbm-token");
|
|
2058
|
-
if (!AUTH_TOKEN) {
|
|
2059
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
2060
|
-
}
|
|
2061
|
-
const queryParams = new URLSearchParams({
|
|
2062
|
-
tipoCredencial: typeCredential,
|
|
2063
|
-
registro: register,
|
|
2064
|
-
uf
|
|
2065
|
-
});
|
|
2066
|
-
const response = await fetch(`${API_URL}/doctors/consulta-profissional?${queryParams.toString()}`, {
|
|
2067
|
-
method: "GET",
|
|
2068
|
-
headers: {
|
|
2069
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
2070
|
-
"Content-Type": "application/json"
|
|
2071
|
-
}
|
|
2072
|
-
});
|
|
2073
|
-
const dataResponse = await response.json();
|
|
2074
|
-
if (!dataResponse.success) {
|
|
2075
|
-
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
2076
|
-
}
|
|
2077
|
-
return dataResponse;
|
|
2078
|
-
};
|
|
2079
|
-
|
|
2080
1666
|
// src/components/Modals/CustomerNotRegistered/StepDoctorForm.tsx
|
|
2081
|
-
import { jsx as
|
|
1667
|
+
import { jsx as jsx19, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
2082
1668
|
var StepDoctorForm = ({
|
|
2083
|
-
securityNumber,
|
|
2084
1669
|
onNext,
|
|
2085
1670
|
onBack
|
|
2086
1671
|
}) => {
|
|
2087
1672
|
const { doctor, setDoctor, setStep } = usePBMForm();
|
|
2088
|
-
const
|
|
2089
|
-
const [
|
|
2090
|
-
const [loadingDoctor, setLoadingDoctor] = useState7(false);
|
|
2091
|
-
const [loading, setLoading] = useState7(false);
|
|
2092
|
-
const fetchDoctor = useCallback3(async () => {
|
|
2093
|
-
if (!doctor.register || !doctor.state || !doctor.typeCredential) return;
|
|
2094
|
-
setLoadingDoctor(true);
|
|
2095
|
-
try {
|
|
2096
|
-
const response = await LookupDoctor({
|
|
2097
|
-
typeCredential: doctor.typeCredential,
|
|
2098
|
-
register: doctor.register,
|
|
2099
|
-
uf: doctor.state
|
|
2100
|
-
});
|
|
2101
|
-
if (!response.success) {
|
|
2102
|
-
console.error("Failed to fetch doctor data:", response.message);
|
|
2103
|
-
return;
|
|
2104
|
-
}
|
|
2105
|
-
const data = response.data;
|
|
2106
|
-
if (data?.nomeProfissional) {
|
|
2107
|
-
setDoctor({ doctorName: data.nomeProfissional });
|
|
2108
|
-
}
|
|
2109
|
-
} catch {
|
|
2110
|
-
console.error("An error occurred while fetching doctor data.");
|
|
2111
|
-
} finally {
|
|
2112
|
-
setLoadingDoctor(false);
|
|
2113
|
-
}
|
|
2114
|
-
}, [doctor.register, doctor.state, doctor.typeCredential, setDoctor]);
|
|
1673
|
+
const [errors, setErrors] = useState6({});
|
|
1674
|
+
const [loading, setLoading] = useState6(false);
|
|
2115
1675
|
const validate = () => {
|
|
2116
1676
|
const e = {};
|
|
2117
1677
|
if (!doctor.typeCredential)
|
|
@@ -2126,20 +1686,6 @@ var StepDoctorForm = ({
|
|
|
2126
1686
|
if (!validate()) return;
|
|
2127
1687
|
setLoading(true);
|
|
2128
1688
|
try {
|
|
2129
|
-
const response = await SetDoctorDataForm({
|
|
2130
|
-
document: securityNumber,
|
|
2131
|
-
requestId: store.requestId,
|
|
2132
|
-
doctor: {
|
|
2133
|
-
typeCredential: doctor.typeCredential,
|
|
2134
|
-
register: doctor.register,
|
|
2135
|
-
state: doctor.state,
|
|
2136
|
-
doctorName: doctor.doctorName
|
|
2137
|
-
}
|
|
2138
|
-
});
|
|
2139
|
-
if (!response.success) {
|
|
2140
|
-
console.error("Failed to submit doctor data:", response.message);
|
|
2141
|
-
return;
|
|
2142
|
-
}
|
|
2143
1689
|
setStep(mappingFormStep["Acceptances"]);
|
|
2144
1690
|
onNext();
|
|
2145
1691
|
} catch {
|
|
@@ -2148,9 +1694,9 @@ var StepDoctorForm = ({
|
|
|
2148
1694
|
setLoading(false);
|
|
2149
1695
|
}
|
|
2150
1696
|
};
|
|
2151
|
-
return /* @__PURE__ */
|
|
2152
|
-
/* @__PURE__ */
|
|
2153
|
-
/* @__PURE__ */
|
|
1697
|
+
return /* @__PURE__ */ jsxs15("div", { className: "flex flex-col gap-4", children: [
|
|
1698
|
+
/* @__PURE__ */ jsxs15("div", { className: "grid grid-cols-3 gap-3", children: [
|
|
1699
|
+
/* @__PURE__ */ jsx19(FieldWrapper_default, { label: "Tipo credencial", error: errors.typeCredential, children: /* @__PURE__ */ jsxs15(
|
|
2154
1700
|
"select",
|
|
2155
1701
|
{
|
|
2156
1702
|
className: InputClass_default(errors.typeCredential),
|
|
@@ -2163,13 +1709,13 @@ var StepDoctorForm = ({
|
|
|
2163
1709
|
}));
|
|
2164
1710
|
},
|
|
2165
1711
|
children: [
|
|
2166
|
-
/* @__PURE__ */
|
|
2167
|
-
/* @__PURE__ */
|
|
2168
|
-
/* @__PURE__ */
|
|
1712
|
+
/* @__PURE__ */ jsx19("option", { value: "CRM", children: "CRM" }),
|
|
1713
|
+
/* @__PURE__ */ jsx19("option", { value: "CRO", children: "CRO" }),
|
|
1714
|
+
/* @__PURE__ */ jsx19("option", { value: "CRF", children: "CRF" })
|
|
2169
1715
|
]
|
|
2170
1716
|
}
|
|
2171
1717
|
) }),
|
|
2172
|
-
/* @__PURE__ */
|
|
1718
|
+
/* @__PURE__ */ jsx19(FieldWrapper_default, { label: "Estado (UF)", error: errors.state, children: /* @__PURE__ */ jsxs15(
|
|
2173
1719
|
"select",
|
|
2174
1720
|
{
|
|
2175
1721
|
className: InputClass_default(errors.state),
|
|
@@ -2179,12 +1725,12 @@ var StepDoctorForm = ({
|
|
|
2179
1725
|
setErrors((p) => ({ ...p, state: void 0 }));
|
|
2180
1726
|
},
|
|
2181
1727
|
children: [
|
|
2182
|
-
/* @__PURE__ */
|
|
2183
|
-
BRAZILIAN_STATES.map((state) => /* @__PURE__ */
|
|
1728
|
+
/* @__PURE__ */ jsx19("option", { value: "", children: "UF" }),
|
|
1729
|
+
BRAZILIAN_STATES.map((state) => /* @__PURE__ */ jsx19("option", { value: state, children: state }, state))
|
|
2184
1730
|
]
|
|
2185
1731
|
}
|
|
2186
1732
|
) }),
|
|
2187
|
-
/* @__PURE__ */
|
|
1733
|
+
/* @__PURE__ */ jsx19(FieldWrapper_default, { label: "N\xBA registro", error: errors.register, children: /* @__PURE__ */ jsx19("div", { className: "relative", children: /* @__PURE__ */ jsx19(
|
|
2188
1734
|
"input",
|
|
2189
1735
|
{
|
|
2190
1736
|
className: InputClass_default(errors.register),
|
|
@@ -2196,94 +1742,62 @@ var StepDoctorForm = ({
|
|
|
2196
1742
|
...p,
|
|
2197
1743
|
register: void 0
|
|
2198
1744
|
}));
|
|
2199
|
-
}
|
|
2200
|
-
onBlur: fetchDoctor
|
|
1745
|
+
}
|
|
2201
1746
|
}
|
|
2202
1747
|
) }) })
|
|
2203
1748
|
] }),
|
|
2204
|
-
/* @__PURE__ */
|
|
2205
|
-
/* @__PURE__ */
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
}));
|
|
2218
|
-
}
|
|
2219
|
-
}
|
|
2220
|
-
),
|
|
2221
|
-
loadingDoctor && /* @__PURE__ */ jsx20("div", { className: "absolute right-3 top-1/2 -translate-y-1/2", children: /* @__PURE__ */ jsxs16(
|
|
2222
|
-
"svg",
|
|
2223
|
-
{
|
|
2224
|
-
className: "h-4 w-4 animate-spin text-blue-500",
|
|
2225
|
-
viewBox: "0 0 24 24",
|
|
2226
|
-
fill: "none",
|
|
2227
|
-
children: [
|
|
2228
|
-
/* @__PURE__ */ jsx20(
|
|
2229
|
-
"circle",
|
|
2230
|
-
{
|
|
2231
|
-
className: "opacity-25",
|
|
2232
|
-
cx: "12",
|
|
2233
|
-
cy: "12",
|
|
2234
|
-
r: "10",
|
|
2235
|
-
stroke: "currentColor",
|
|
2236
|
-
strokeWidth: "4"
|
|
2237
|
-
}
|
|
2238
|
-
),
|
|
2239
|
-
/* @__PURE__ */ jsx20(
|
|
2240
|
-
"path",
|
|
2241
|
-
{
|
|
2242
|
-
className: "opacity-75",
|
|
2243
|
-
fill: "currentColor",
|
|
2244
|
-
d: "M4 12a8 8 0 018-8v8z"
|
|
2245
|
-
}
|
|
2246
|
-
)
|
|
2247
|
-
]
|
|
1749
|
+
/* @__PURE__ */ jsxs15(FieldWrapper_default, { label: "Nome do m\xE9dico", error: errors.doctorName, children: [
|
|
1750
|
+
/* @__PURE__ */ jsx19("div", { className: "relative", children: /* @__PURE__ */ jsx19(
|
|
1751
|
+
"input",
|
|
1752
|
+
{
|
|
1753
|
+
className: InputClass_default(errors.doctorName),
|
|
1754
|
+
placeholder: "Nome Completo do Profissional",
|
|
1755
|
+
value: doctor.doctorName,
|
|
1756
|
+
onChange: (e) => {
|
|
1757
|
+
setDoctor({ doctorName: e.target.value });
|
|
1758
|
+
setErrors((p) => ({
|
|
1759
|
+
...p,
|
|
1760
|
+
doctorName: void 0
|
|
1761
|
+
}));
|
|
2248
1762
|
}
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
/* @__PURE__ */
|
|
1763
|
+
}
|
|
1764
|
+
) }),
|
|
1765
|
+
/* @__PURE__ */ jsx19("p", { className: "text-xs text-gray-400 mt-0.5", children: "Preenchido automaticamente ao informar registro + UF." })
|
|
2252
1766
|
] }),
|
|
2253
|
-
/* @__PURE__ */
|
|
1767
|
+
/* @__PURE__ */ jsx19(StepActions_default, { onNext: handleSubmit, onBack, loading })
|
|
2254
1768
|
] });
|
|
2255
1769
|
};
|
|
2256
1770
|
var StepDoctorForm_default = StepDoctorForm;
|
|
2257
1771
|
|
|
2258
1772
|
// src/components/Modals/CustomerNotRegistered/StepAcceptancesForm.tsx
|
|
2259
|
-
import { useState as
|
|
1773
|
+
import { useState as useState7 } from "react";
|
|
2260
1774
|
|
|
2261
1775
|
// src/components/Modals/CustomerNotRegistered/Shared/CheckRow.tsx
|
|
2262
|
-
import
|
|
2263
|
-
import { jsx as
|
|
1776
|
+
import classNames10 from "classnames";
|
|
1777
|
+
import { jsx as jsx20, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
2264
1778
|
var CheckRow = ({
|
|
2265
1779
|
label,
|
|
2266
1780
|
checked,
|
|
2267
1781
|
onChange,
|
|
2268
1782
|
required,
|
|
2269
1783
|
error
|
|
2270
|
-
}) => /* @__PURE__ */
|
|
1784
|
+
}) => /* @__PURE__ */ jsxs16(
|
|
2271
1785
|
"label",
|
|
2272
1786
|
{
|
|
2273
|
-
className:
|
|
1787
|
+
className: classNames10(
|
|
2274
1788
|
"flex items-start gap-3 cursor-pointer group p-3 rounded-lg border transition-all",
|
|
2275
1789
|
checked ? "border-emerald-200 bg-emerald-50/60" : "border-zinc-100 hover:border-zinc-200 bg-zinc-50/40",
|
|
2276
1790
|
error ? "border-red-300 bg-red-50/40" : ""
|
|
2277
1791
|
),
|
|
2278
1792
|
children: [
|
|
2279
|
-
/* @__PURE__ */
|
|
1793
|
+
/* @__PURE__ */ jsx20(
|
|
2280
1794
|
"div",
|
|
2281
1795
|
{
|
|
2282
|
-
className:
|
|
1796
|
+
className: classNames10(
|
|
2283
1797
|
"mt-0.5 flex h-4 w-4 shrink-0 items-center justify-center rounded border transition-all",
|
|
2284
1798
|
checked ? "border-(--pbm-primary) bg-(--pbm-primary)" : "border-zinc-300 bg-white"
|
|
2285
1799
|
),
|
|
2286
|
-
children: checked && /* @__PURE__ */
|
|
1800
|
+
children: checked && /* @__PURE__ */ jsx20("svg", { className: "h-2.5 w-2.5 text-white", viewBox: "0 0 10 8", fill: "none", children: /* @__PURE__ */ jsx20(
|
|
2287
1801
|
"path",
|
|
2288
1802
|
{
|
|
2289
1803
|
d: "M1 4l3 3 5-6",
|
|
@@ -2295,11 +1809,11 @@ var CheckRow = ({
|
|
|
2295
1809
|
) })
|
|
2296
1810
|
}
|
|
2297
1811
|
),
|
|
2298
|
-
/* @__PURE__ */
|
|
1812
|
+
/* @__PURE__ */ jsxs16("span", { className: "text-sm text-zinc-700 leading-snug", children: [
|
|
2299
1813
|
label,
|
|
2300
|
-
required && /* @__PURE__ */
|
|
1814
|
+
required && /* @__PURE__ */ jsx20("span", { className: "text-red-400 ml-1", children: "*" })
|
|
2301
1815
|
] }),
|
|
2302
|
-
/* @__PURE__ */
|
|
1816
|
+
/* @__PURE__ */ jsx20(
|
|
2303
1817
|
"input",
|
|
2304
1818
|
{
|
|
2305
1819
|
type: "checkbox",
|
|
@@ -2313,40 +1827,128 @@ var CheckRow = ({
|
|
|
2313
1827
|
);
|
|
2314
1828
|
var CheckRow_default = CheckRow;
|
|
2315
1829
|
|
|
2316
|
-
// src/services/
|
|
2317
|
-
import
|
|
2318
|
-
var
|
|
2319
|
-
const
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
1830
|
+
// src/services/enable-discount.ts
|
|
1831
|
+
import Cookies2 from "js-cookie";
|
|
1832
|
+
var EnableDiscount = async ({ product, consumer, healthProfessional }) => {
|
|
1833
|
+
const tenant_id = Cookies2.get("tenant_id");
|
|
1834
|
+
if (!tenant_id) {
|
|
1835
|
+
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
2323
1836
|
}
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
1837
|
+
if (!consumer) {
|
|
1838
|
+
throw new Error(`Consumer information is required`);
|
|
1839
|
+
}
|
|
1840
|
+
if (!healthProfessional) {
|
|
1841
|
+
throw new Error(`Health professional information is required`);
|
|
1842
|
+
}
|
|
1843
|
+
if (!product) {
|
|
1844
|
+
throw new Error(`Product information is required`);
|
|
1845
|
+
}
|
|
1846
|
+
try {
|
|
1847
|
+
const response = await fetch(
|
|
1848
|
+
`${getEnv("VITE_API_URL")}/api/discount.ts`,
|
|
1849
|
+
{
|
|
1850
|
+
method: "POST",
|
|
1851
|
+
headers: {
|
|
1852
|
+
"Content-Type": "application/json",
|
|
1853
|
+
"Accept": "application/json",
|
|
1854
|
+
"Authorization": `Bearer ${Cookies2.get("pbm-token")}`
|
|
1855
|
+
},
|
|
1856
|
+
body: JSON.stringify({
|
|
1857
|
+
tenant_id,
|
|
1858
|
+
product,
|
|
1859
|
+
table_id: Cookies2.get("current-table-id"),
|
|
1860
|
+
local_hour: Cookies2.get("current-local-hour"),
|
|
1861
|
+
consumer,
|
|
1862
|
+
healthProfessional
|
|
1863
|
+
})
|
|
1864
|
+
}
|
|
1865
|
+
);
|
|
1866
|
+
const data = await response.json();
|
|
1867
|
+
if (!data.success) {
|
|
1868
|
+
throw new Error("PBMLOG: Enable Discount Failed!");
|
|
1869
|
+
}
|
|
1870
|
+
Cookies2.set("current-central-number", data.product[0].centralNumber.toString(), {
|
|
1871
|
+
secure: true,
|
|
1872
|
+
sameSite: "Strict",
|
|
1873
|
+
expires: 1
|
|
1874
|
+
});
|
|
1875
|
+
Cookies2.set("current-term-code", data.product[0].activationFields.acceptLgpd.termCode.value.toString(), {
|
|
1876
|
+
secure: true,
|
|
1877
|
+
sameSite: "Strict",
|
|
1878
|
+
expires: 1
|
|
1879
|
+
});
|
|
1880
|
+
return data;
|
|
1881
|
+
} catch (error) {
|
|
1882
|
+
console.error("Error during enable discount:", error);
|
|
1883
|
+
return { success: false, error: "Authorization failed" };
|
|
1884
|
+
}
|
|
1885
|
+
};
|
|
1886
|
+
|
|
1887
|
+
// src/services/activate.ts
|
|
1888
|
+
import Cookies3 from "js-cookie";
|
|
1889
|
+
var Activate = async ({ product, consumer, healthProfessional }) => {
|
|
1890
|
+
const tenant_id = Cookies3.get("tenant_id");
|
|
1891
|
+
if (!tenant_id) {
|
|
1892
|
+
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
1893
|
+
}
|
|
1894
|
+
if (!consumer) {
|
|
1895
|
+
throw new Error(`Consumer information is required`);
|
|
1896
|
+
}
|
|
1897
|
+
if (!healthProfessional) {
|
|
1898
|
+
throw new Error(`Health professional information is required`);
|
|
1899
|
+
}
|
|
1900
|
+
if (!product) {
|
|
1901
|
+
throw new Error(`Product information is required`);
|
|
1902
|
+
}
|
|
1903
|
+
try {
|
|
1904
|
+
const response = await fetch(
|
|
1905
|
+
`${getEnv("VITE_API_URL")}/api/activate.ts`,
|
|
1906
|
+
{
|
|
1907
|
+
method: "POST",
|
|
1908
|
+
headers: {
|
|
1909
|
+
"Content-Type": "application/json",
|
|
1910
|
+
"Accept": "application/json",
|
|
1911
|
+
"Authorization": `Bearer ${Cookies3.get("pbm-token")}`
|
|
1912
|
+
},
|
|
1913
|
+
body: JSON.stringify({
|
|
1914
|
+
tenant_id,
|
|
1915
|
+
product,
|
|
1916
|
+
table_id: Cookies3.get("current-table-id"),
|
|
1917
|
+
local_hour: Cookies3.get("current-local-hour"),
|
|
1918
|
+
central_number: Cookies3.get("current-central-number"),
|
|
1919
|
+
consumer,
|
|
1920
|
+
healthProfessional,
|
|
1921
|
+
acceptLgpd: {
|
|
1922
|
+
evidenceType: "SITE",
|
|
1923
|
+
evidence: "VSTOSITE",
|
|
1924
|
+
termCode: Cookies3.get("current-term-code")
|
|
1925
|
+
}
|
|
1926
|
+
})
|
|
1927
|
+
}
|
|
1928
|
+
);
|
|
1929
|
+
const data = await response.json();
|
|
1930
|
+
if (!data.success) {
|
|
1931
|
+
throw new Error("PBMLOG: Activate Failed!");
|
|
1932
|
+
}
|
|
1933
|
+
return data;
|
|
1934
|
+
} catch (error) {
|
|
1935
|
+
console.error("Error during activate:", error);
|
|
1936
|
+
return { success: false, error: "Authorization failed" };
|
|
2335
1937
|
}
|
|
2336
|
-
return dataResponse;
|
|
2337
1938
|
};
|
|
2338
1939
|
|
|
2339
1940
|
// src/components/Modals/CustomerNotRegistered/StepAcceptancesForm.tsx
|
|
2340
|
-
import { jsx as
|
|
1941
|
+
import { jsx as jsx21, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
2341
1942
|
var StepAcceptancesForm = ({
|
|
2342
|
-
securityNumber,
|
|
2343
1943
|
onBack,
|
|
2344
|
-
onDone
|
|
1944
|
+
onDone,
|
|
1945
|
+
securityNumber
|
|
2345
1946
|
}) => {
|
|
2346
1947
|
const { acceptances, setAcceptances } = usePBMForm();
|
|
2347
|
-
const
|
|
2348
|
-
const [errors, setErrors] =
|
|
2349
|
-
const [loading, setLoading] =
|
|
1948
|
+
const { targetProduct, cardID } = usePBMStore();
|
|
1949
|
+
const [errors, setErrors] = useState7({});
|
|
1950
|
+
const [loading, setLoading] = useState7(false);
|
|
1951
|
+
const data = usePBMForm.getState();
|
|
2350
1952
|
const validate = () => {
|
|
2351
1953
|
const e = {};
|
|
2352
1954
|
if (!acceptances.acceptsPrivacyTermsLGPD)
|
|
@@ -2354,24 +1956,65 @@ var StepAcceptancesForm = ({
|
|
|
2354
1956
|
setErrors(e);
|
|
2355
1957
|
return Object.keys(e).length === 0;
|
|
2356
1958
|
};
|
|
1959
|
+
const activateConsumer = async (PAYLOAD) => {
|
|
1960
|
+
try {
|
|
1961
|
+
const response = await Activate(PAYLOAD);
|
|
1962
|
+
console.log("Activate response:", response);
|
|
1963
|
+
} catch (error) {
|
|
1964
|
+
console.error("Error during consumer activation:", error);
|
|
1965
|
+
}
|
|
1966
|
+
};
|
|
2357
1967
|
const handleSubmit = async () => {
|
|
2358
1968
|
if (!validate()) return;
|
|
2359
1969
|
setLoading(true);
|
|
1970
|
+
if (!targetProduct) {
|
|
1971
|
+
console.error("No target product found in PBM store.");
|
|
1972
|
+
setLoading(false);
|
|
1973
|
+
return;
|
|
1974
|
+
}
|
|
1975
|
+
const phone = data.personalData.phone.replace(/\D/g, "");
|
|
1976
|
+
const ddd = phone.slice(0, 2);
|
|
1977
|
+
const cellphone = phone.slice(2);
|
|
1978
|
+
const PAYLOAD = {
|
|
1979
|
+
consumer: {
|
|
1980
|
+
holderId: securityNumber,
|
|
1981
|
+
cardId: cardID || "",
|
|
1982
|
+
name: data.personalData.name,
|
|
1983
|
+
email: data.personalData.email,
|
|
1984
|
+
birthdate: data.personalData.birthday,
|
|
1985
|
+
genre: data.genderResponsibility.gender,
|
|
1986
|
+
postalCode: data.address.postalcode.replace(/\D/g, ""),
|
|
1987
|
+
stateCode: data.address.uf || "",
|
|
1988
|
+
cityName: data.address.city || "",
|
|
1989
|
+
cityRegion: data.address.neighborhood || "",
|
|
1990
|
+
addressType: "casa",
|
|
1991
|
+
streetAddress: data.address.street || "",
|
|
1992
|
+
addressNumber: data.address.number || "",
|
|
1993
|
+
addressAdditionalInformation: data.address.complement || "",
|
|
1994
|
+
DDDcellPhone: ddd,
|
|
1995
|
+
cellphone,
|
|
1996
|
+
acceptInformativeMaterial: acceptances.acceptsMail ? "S" : "N",
|
|
1997
|
+
acceptMail: acceptances.acceptsMail ? "S" : "N",
|
|
1998
|
+
acceptEmail: acceptances.acceptsEmail ? "S" : "N",
|
|
1999
|
+
acceptCalls: acceptances.acceptPhone ? "S" : "N",
|
|
2000
|
+
acceptSMS: acceptances.acceptsSms ? "S" : "N",
|
|
2001
|
+
acceptTerm: acceptances.acceptsPrivacyTermsLGPD ? "S" : "N",
|
|
2002
|
+
acceptWhatsApp: "N"
|
|
2003
|
+
},
|
|
2004
|
+
healthProfessional: {
|
|
2005
|
+
id: data.doctor.register,
|
|
2006
|
+
stateCode: data.doctor.state,
|
|
2007
|
+
type: data.doctor.typeCredential,
|
|
2008
|
+
name: data.doctor.doctorName
|
|
2009
|
+
},
|
|
2010
|
+
product: targetProduct
|
|
2011
|
+
};
|
|
2360
2012
|
try {
|
|
2361
|
-
const response = await
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
acceptsSms: acceptances.acceptsSms,
|
|
2367
|
-
acceptsEmail: acceptances.acceptsEmail,
|
|
2368
|
-
acceptsMail: acceptances.acceptsMail,
|
|
2369
|
-
acceptsPrivacyTermsLGPD: acceptances.acceptsPrivacyTermsLGPD
|
|
2370
|
-
}
|
|
2371
|
-
});
|
|
2372
|
-
if (!response.success) {
|
|
2373
|
-
console.error("Failed to submit acceptances data:", response.message);
|
|
2374
|
-
return;
|
|
2013
|
+
const response = await EnableDiscount(PAYLOAD);
|
|
2014
|
+
if (response.success) {
|
|
2015
|
+
await activateConsumer(PAYLOAD);
|
|
2016
|
+
} else {
|
|
2017
|
+
console.error("Failed to enable discount:", response);
|
|
2375
2018
|
}
|
|
2376
2019
|
onDone();
|
|
2377
2020
|
} catch {
|
|
@@ -2380,9 +2023,9 @@ var StepAcceptancesForm = ({
|
|
|
2380
2023
|
setLoading(false);
|
|
2381
2024
|
}
|
|
2382
2025
|
};
|
|
2383
|
-
return /* @__PURE__ */
|
|
2384
|
-
/* @__PURE__ */
|
|
2385
|
-
/* @__PURE__ */
|
|
2026
|
+
return /* @__PURE__ */ jsxs17("div", { className: "flex flex-col gap-3", children: [
|
|
2027
|
+
/* @__PURE__ */ jsx21("p", { className: "text-xs text-gray-500 mb-1", children: "Selecione como deseja receber comunica\xE7\xF5es:" }),
|
|
2028
|
+
/* @__PURE__ */ jsx21(
|
|
2386
2029
|
CheckRow_default,
|
|
2387
2030
|
{
|
|
2388
2031
|
label: "Aceito receber contato por telefone",
|
|
@@ -2390,7 +2033,7 @@ var StepAcceptancesForm = ({
|
|
|
2390
2033
|
onChange: (v) => setAcceptances({ acceptPhone: v })
|
|
2391
2034
|
}
|
|
2392
2035
|
),
|
|
2393
|
-
/* @__PURE__ */
|
|
2036
|
+
/* @__PURE__ */ jsx21(
|
|
2394
2037
|
CheckRow_default,
|
|
2395
2038
|
{
|
|
2396
2039
|
label: "Aceito receber SMS",
|
|
@@ -2398,7 +2041,7 @@ var StepAcceptancesForm = ({
|
|
|
2398
2041
|
onChange: (v) => setAcceptances({ acceptsSms: v })
|
|
2399
2042
|
}
|
|
2400
2043
|
),
|
|
2401
|
-
/* @__PURE__ */
|
|
2044
|
+
/* @__PURE__ */ jsx21(
|
|
2402
2045
|
CheckRow_default,
|
|
2403
2046
|
{
|
|
2404
2047
|
label: "Aceito receber e-mails",
|
|
@@ -2406,7 +2049,7 @@ var StepAcceptancesForm = ({
|
|
|
2406
2049
|
onChange: (v) => setAcceptances({ acceptsEmail: v })
|
|
2407
2050
|
}
|
|
2408
2051
|
),
|
|
2409
|
-
/* @__PURE__ */
|
|
2052
|
+
/* @__PURE__ */ jsx21(
|
|
2410
2053
|
CheckRow_default,
|
|
2411
2054
|
{
|
|
2412
2055
|
label: "Aceito receber correspond\xEAncias por correio",
|
|
@@ -2414,8 +2057,8 @@ var StepAcceptancesForm = ({
|
|
|
2414
2057
|
onChange: (v) => setAcceptances({ acceptsMail: v })
|
|
2415
2058
|
}
|
|
2416
2059
|
),
|
|
2417
|
-
/* @__PURE__ */
|
|
2418
|
-
/* @__PURE__ */
|
|
2060
|
+
/* @__PURE__ */ jsxs17("div", { className: "mt-1", children: [
|
|
2061
|
+
/* @__PURE__ */ jsx21(
|
|
2419
2062
|
CheckRow_default,
|
|
2420
2063
|
{
|
|
2421
2064
|
label: "Li e aceito os Termos de Privacidade (LGPD)",
|
|
@@ -2428,9 +2071,9 @@ var StepAcceptancesForm = ({
|
|
|
2428
2071
|
error: errors.lgpd
|
|
2429
2072
|
}
|
|
2430
2073
|
),
|
|
2431
|
-
errors.lgpd && /* @__PURE__ */
|
|
2074
|
+
errors.lgpd && /* @__PURE__ */ jsx21("span", { className: "text-xs text-red-500 mt-1 block pl-1", children: errors.lgpd })
|
|
2432
2075
|
] }),
|
|
2433
|
-
/* @__PURE__ */
|
|
2076
|
+
/* @__PURE__ */ jsx21(
|
|
2434
2077
|
StepActions_default,
|
|
2435
2078
|
{
|
|
2436
2079
|
onNext: handleSubmit,
|
|
@@ -2445,8 +2088,8 @@ var StepAcceptancesForm = ({
|
|
|
2445
2088
|
var StepAcceptancesForm_default = StepAcceptancesForm;
|
|
2446
2089
|
|
|
2447
2090
|
// src/components/Modals/CustomerNotRegistered/Shared/StepProgress.tsx
|
|
2448
|
-
import
|
|
2449
|
-
import { jsx as
|
|
2091
|
+
import classNames11 from "classnames";
|
|
2092
|
+
import { jsx as jsx22, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
2450
2093
|
var STEP_LABELS = [
|
|
2451
2094
|
"Dados Pessoais",
|
|
2452
2095
|
"Endere\xE7o",
|
|
@@ -2454,23 +2097,23 @@ var STEP_LABELS = [
|
|
|
2454
2097
|
"M\xE9dico",
|
|
2455
2098
|
"Aceites"
|
|
2456
2099
|
];
|
|
2457
|
-
var StepProgress = ({ current }) => /* @__PURE__ */
|
|
2100
|
+
var StepProgress = ({ current }) => /* @__PURE__ */ jsx22("div", { className: "flex items-center w-full justify-center mb-6", children: STEP_LABELS.map((label, i) => {
|
|
2458
2101
|
const done = i < current;
|
|
2459
2102
|
const active = i === current;
|
|
2460
|
-
return /* @__PURE__ */
|
|
2103
|
+
return /* @__PURE__ */ jsxs18(
|
|
2461
2104
|
"div",
|
|
2462
2105
|
{
|
|
2463
2106
|
className: "flex items-center w-full min-w-0 justify-center relative",
|
|
2464
2107
|
children: [
|
|
2465
|
-
/* @__PURE__ */
|
|
2466
|
-
/* @__PURE__ */
|
|
2108
|
+
/* @__PURE__ */ jsxs18("div", { className: "flex flex-col items-center justify-center gap-1 shrink-0 z-10", children: [
|
|
2109
|
+
/* @__PURE__ */ jsx22(
|
|
2467
2110
|
"div",
|
|
2468
2111
|
{
|
|
2469
|
-
className:
|
|
2112
|
+
className: classNames11(
|
|
2470
2113
|
"flex h-7 w-7 items-center justify-center rounded-full text-xs font-semibold transition-all",
|
|
2471
2114
|
done ? "bg-emerald-600 text-white" : active ? "bg-(--pbm-primary) text-white ring-4 ring-(--pbm-primary)/15" : "bg-zinc-100 text-zinc-400"
|
|
2472
2115
|
),
|
|
2473
|
-
children: done ? /* @__PURE__ */
|
|
2116
|
+
children: done ? /* @__PURE__ */ jsx22("svg", { className: "h-3.5 w-3.5", viewBox: "0 0 12 10", fill: "none", children: /* @__PURE__ */ jsx22(
|
|
2474
2117
|
"path",
|
|
2475
2118
|
{
|
|
2476
2119
|
d: "M1 5l4 4 6-8",
|
|
@@ -2482,10 +2125,10 @@ var StepProgress = ({ current }) => /* @__PURE__ */ jsx23("div", { className: "f
|
|
|
2482
2125
|
) }) : i + 1
|
|
2483
2126
|
}
|
|
2484
2127
|
),
|
|
2485
|
-
/* @__PURE__ */
|
|
2128
|
+
/* @__PURE__ */ jsx22(
|
|
2486
2129
|
"span",
|
|
2487
2130
|
{
|
|
2488
|
-
className:
|
|
2131
|
+
className: classNames11(
|
|
2489
2132
|
"text-[10px] font-medium whitespace-nowrap hidden sm:block",
|
|
2490
2133
|
active ? "text-(--pbm-primary)" : done ? "text-emerald-600" : "text-zinc-400"
|
|
2491
2134
|
),
|
|
@@ -2493,11 +2136,11 @@ var StepProgress = ({ current }) => /* @__PURE__ */ jsx23("div", { className: "f
|
|
|
2493
2136
|
}
|
|
2494
2137
|
)
|
|
2495
2138
|
] }),
|
|
2496
|
-
i < STEP_LABELS.length - 1 && /* @__PURE__ */
|
|
2139
|
+
i < STEP_LABELS.length - 1 && /* @__PURE__ */ jsx22(
|
|
2497
2140
|
"div",
|
|
2498
2141
|
{
|
|
2499
|
-
className:
|
|
2500
|
-
"h-0.5 w-
|
|
2142
|
+
className: classNames11(
|
|
2143
|
+
"h-0.5 w-full rounded transition-all absolute top-3.5 left-10",
|
|
2501
2144
|
"bg-zinc-200"
|
|
2502
2145
|
)
|
|
2503
2146
|
}
|
|
@@ -2510,9 +2153,9 @@ var StepProgress = ({ current }) => /* @__PURE__ */ jsx23("div", { className: "f
|
|
|
2510
2153
|
var StepProgress_default = StepProgress;
|
|
2511
2154
|
|
|
2512
2155
|
// src/components/Modals/CustomerNotRegistered/Shared/SuccessScreen.tsx
|
|
2513
|
-
import { jsx as
|
|
2514
|
-
var SuccessScreen = ({ onClose }) => /* @__PURE__ */
|
|
2515
|
-
/* @__PURE__ */
|
|
2156
|
+
import { jsx as jsx23, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
2157
|
+
var SuccessScreen = ({ onClose }) => /* @__PURE__ */ jsxs19("div", { className: "flex flex-col items-center gap-4 py-4 text-center", children: [
|
|
2158
|
+
/* @__PURE__ */ jsx23("div", { className: "flex h-16 w-16 items-center justify-center rounded-full bg-green-100", children: /* @__PURE__ */ jsx23("svg", { className: "h-8 w-8 text-green-500", viewBox: "0 0 24 24", fill: "none", children: /* @__PURE__ */ jsx23(
|
|
2516
2159
|
"path",
|
|
2517
2160
|
{
|
|
2518
2161
|
d: "M5 13l4 4L19 7",
|
|
@@ -2522,11 +2165,11 @@ var SuccessScreen = ({ onClose }) => /* @__PURE__ */ jsxs20("div", { className:
|
|
|
2522
2165
|
strokeLinejoin: "round"
|
|
2523
2166
|
}
|
|
2524
2167
|
) }) }),
|
|
2525
|
-
/* @__PURE__ */
|
|
2526
|
-
/* @__PURE__ */
|
|
2527
|
-
/* @__PURE__ */
|
|
2168
|
+
/* @__PURE__ */ jsxs19("div", { children: [
|
|
2169
|
+
/* @__PURE__ */ jsx23("h3", { className: "text-base font-semibold text-gray-800", children: "Cadastro conclu\xEDdo!" }),
|
|
2170
|
+
/* @__PURE__ */ jsx23("p", { className: "text-sm text-zinc-500 mt-1", children: "Voc\xEA j\xE1 pode aproveitar os benef\xEDcios de farm\xE1cia." })
|
|
2528
2171
|
] }),
|
|
2529
|
-
/* @__PURE__ */
|
|
2172
|
+
/* @__PURE__ */ jsx23(
|
|
2530
2173
|
"button",
|
|
2531
2174
|
{
|
|
2532
2175
|
onClick: onClose,
|
|
@@ -2538,12 +2181,12 @@ var SuccessScreen = ({ onClose }) => /* @__PURE__ */ jsxs20("div", { className:
|
|
|
2538
2181
|
var SuccessScreen_default = SuccessScreen;
|
|
2539
2182
|
|
|
2540
2183
|
// src/components/Modals/CustomerNotRegistered/index.tsx
|
|
2541
|
-
import { jsx as
|
|
2184
|
+
import { jsx as jsx24, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
2542
2185
|
var CustomerNotRegistered = ({ ID }) => {
|
|
2543
2186
|
const { modal, setModal } = useModal();
|
|
2544
2187
|
const { securityNumber } = usePBMStore();
|
|
2545
2188
|
const { resetForm, step, setStep } = usePBMForm();
|
|
2546
|
-
const [done, setDone] =
|
|
2189
|
+
const [done, setDone] = useState8(false);
|
|
2547
2190
|
const closeModal = () => {
|
|
2548
2191
|
setModal({ id: "", open: false });
|
|
2549
2192
|
setTimeout(() => {
|
|
@@ -2556,8 +2199,8 @@ var CustomerNotRegistered = ({ ID }) => {
|
|
|
2556
2199
|
const back = () => setStep(step - 1);
|
|
2557
2200
|
const rawSecurityNumber = securityNumber.replace(/\D/g, "");
|
|
2558
2201
|
const stepComponents = [
|
|
2559
|
-
/* @__PURE__ */
|
|
2560
|
-
/* @__PURE__ */
|
|
2202
|
+
/* @__PURE__ */ jsx24(StepPersonalDataForm_default, { securityNumber: rawSecurityNumber, onNext: next }),
|
|
2203
|
+
/* @__PURE__ */ jsx24(
|
|
2561
2204
|
StepAddressForm_default,
|
|
2562
2205
|
{
|
|
2563
2206
|
securityNumber: rawSecurityNumber,
|
|
@@ -2565,7 +2208,7 @@ var CustomerNotRegistered = ({ ID }) => {
|
|
|
2565
2208
|
onBack: back
|
|
2566
2209
|
}
|
|
2567
2210
|
),
|
|
2568
|
-
/* @__PURE__ */
|
|
2211
|
+
/* @__PURE__ */ jsx24(
|
|
2569
2212
|
StepGenderForm_default,
|
|
2570
2213
|
{
|
|
2571
2214
|
securityNumber: rawSecurityNumber,
|
|
@@ -2573,7 +2216,7 @@ var CustomerNotRegistered = ({ ID }) => {
|
|
|
2573
2216
|
onBack: back
|
|
2574
2217
|
}
|
|
2575
2218
|
),
|
|
2576
|
-
/* @__PURE__ */
|
|
2219
|
+
/* @__PURE__ */ jsx24(
|
|
2577
2220
|
StepDoctorForm_default,
|
|
2578
2221
|
{
|
|
2579
2222
|
securityNumber: rawSecurityNumber,
|
|
@@ -2581,7 +2224,7 @@ var CustomerNotRegistered = ({ ID }) => {
|
|
|
2581
2224
|
onBack: back
|
|
2582
2225
|
}
|
|
2583
2226
|
),
|
|
2584
|
-
/* @__PURE__ */
|
|
2227
|
+
/* @__PURE__ */ jsx24(
|
|
2585
2228
|
StepAcceptancesForm_default,
|
|
2586
2229
|
{
|
|
2587
2230
|
securityNumber: rawSecurityNumber,
|
|
@@ -2590,10 +2233,10 @@ var CustomerNotRegistered = ({ ID }) => {
|
|
|
2590
2233
|
}
|
|
2591
2234
|
)
|
|
2592
2235
|
];
|
|
2593
|
-
return /* @__PURE__ */
|
|
2236
|
+
return /* @__PURE__ */ jsxs20(
|
|
2594
2237
|
"main",
|
|
2595
2238
|
{
|
|
2596
|
-
className:
|
|
2239
|
+
className: classNames12(
|
|
2597
2240
|
"fixed inset-0 flex items-center justify-end z-50 flex-col transition-all shadow bg-black/40",
|
|
2598
2241
|
{
|
|
2599
2242
|
"opacity-100 pointer-events-auto": modal.id === ID && modal.open,
|
|
@@ -2601,16 +2244,16 @@ var CustomerNotRegistered = ({ ID }) => {
|
|
|
2601
2244
|
}
|
|
2602
2245
|
),
|
|
2603
2246
|
children: [
|
|
2604
|
-
/* @__PURE__ */
|
|
2605
|
-
/* @__PURE__ */
|
|
2606
|
-
/* @__PURE__ */
|
|
2607
|
-
/* @__PURE__ */
|
|
2608
|
-
/* @__PURE__ */
|
|
2247
|
+
/* @__PURE__ */ jsx24("div", { className: "absolute inset-0", onClick: closeModal }),
|
|
2248
|
+
/* @__PURE__ */ jsxs20("section", { className: "z-10 bg-white flex flex-col p-6 rounded-2xl w-full max-w-125 min-w-125 mx-4 shadow-xl max-h-[90vh] overflow-y-auto", children: [
|
|
2249
|
+
/* @__PURE__ */ jsxs20("div", { className: "flex items-center justify-between mb-4", children: [
|
|
2250
|
+
/* @__PURE__ */ jsx24(Title_default, { textSize: "18px", textAlign: "start", children: done ? "Tudo pronto!" : "Benef\xEDcio de Farm\xE1cia" }),
|
|
2251
|
+
/* @__PURE__ */ jsx24(
|
|
2609
2252
|
"button",
|
|
2610
2253
|
{
|
|
2611
2254
|
onClick: closeModal,
|
|
2612
2255
|
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",
|
|
2613
|
-
children: /* @__PURE__ */
|
|
2256
|
+
children: /* @__PURE__ */ jsx24("svg", { className: "h-4 w-4", viewBox: "0 0 14 14", fill: "none", children: /* @__PURE__ */ jsx24(
|
|
2614
2257
|
"path",
|
|
2615
2258
|
{
|
|
2616
2259
|
d: "M1 1l12 12M13 1L1 13",
|
|
@@ -2622,8 +2265,8 @@ var CustomerNotRegistered = ({ ID }) => {
|
|
|
2622
2265
|
}
|
|
2623
2266
|
)
|
|
2624
2267
|
] }),
|
|
2625
|
-
!done && /* @__PURE__ */
|
|
2626
|
-
done ? /* @__PURE__ */
|
|
2268
|
+
!done && /* @__PURE__ */ jsx24(StepProgress_default, { current: step }),
|
|
2269
|
+
done ? /* @__PURE__ */ jsx24(SuccessScreen_default, { onClose: closeModal }) : stepComponents[step]
|
|
2627
2270
|
] })
|
|
2628
2271
|
]
|
|
2629
2272
|
}
|
|
@@ -2632,7 +2275,7 @@ var CustomerNotRegistered = ({ ID }) => {
|
|
|
2632
2275
|
var CustomerNotRegistered_default = CustomerNotRegistered;
|
|
2633
2276
|
|
|
2634
2277
|
// src/components/UI/Link/index.tsx
|
|
2635
|
-
import
|
|
2278
|
+
import classNames13 from "classnames";
|
|
2636
2279
|
|
|
2637
2280
|
// src/utils/getParams.ts
|
|
2638
2281
|
var getParams = (params) => {
|
|
@@ -2641,16 +2284,16 @@ var getParams = (params) => {
|
|
|
2641
2284
|
};
|
|
2642
2285
|
|
|
2643
2286
|
// src/components/UI/Link/index.tsx
|
|
2644
|
-
import { jsx as
|
|
2287
|
+
import { jsx as jsx25 } from "react/jsx-runtime";
|
|
2645
2288
|
function Link(props) {
|
|
2646
2289
|
const { setState } = usePBMStore();
|
|
2647
|
-
return /* @__PURE__ */
|
|
2290
|
+
return /* @__PURE__ */ jsx25(
|
|
2648
2291
|
"a",
|
|
2649
2292
|
{
|
|
2650
2293
|
...props,
|
|
2651
2294
|
target: props.target || "_self",
|
|
2652
2295
|
href: typeof props.href === "string" ? props.href : props.href.pathname + getParams(props.href.param),
|
|
2653
|
-
className:
|
|
2296
|
+
className: classNames13(
|
|
2654
2297
|
"w-3xs cursor-pointer h-10 rounded-lg text-white text-sm font-semibold transition-colors flex items-center justify-center",
|
|
2655
2298
|
props.className
|
|
2656
2299
|
),
|
|
@@ -2667,15 +2310,15 @@ function Link(props) {
|
|
|
2667
2310
|
var Link_default = Link;
|
|
2668
2311
|
|
|
2669
2312
|
// src/components/Modals/ShopperIsNotAuthenticated.tsx
|
|
2670
|
-
import
|
|
2671
|
-
import { jsx as
|
|
2313
|
+
import classNames14 from "classnames";
|
|
2314
|
+
import { jsx as jsx26, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
2672
2315
|
var ShopperIsNotAuthenticated = ({ ID }) => {
|
|
2673
2316
|
const { customLoginUrl } = usePBMStore();
|
|
2674
2317
|
const { modal, setModal } = useModal();
|
|
2675
|
-
return /* @__PURE__ */
|
|
2318
|
+
return /* @__PURE__ */ jsxs21(
|
|
2676
2319
|
"main",
|
|
2677
2320
|
{
|
|
2678
|
-
className:
|
|
2321
|
+
className: classNames14(
|
|
2679
2322
|
"fixed inset-0 flex items-center justify-center z-50 flex-col transition-all shadow bg-black/40",
|
|
2680
2323
|
{
|
|
2681
2324
|
"opacity-100 pointer-events-auto": modal.id === ID && modal.open,
|
|
@@ -2683,15 +2326,15 @@ var ShopperIsNotAuthenticated = ({ ID }) => {
|
|
|
2683
2326
|
}
|
|
2684
2327
|
),
|
|
2685
2328
|
children: [
|
|
2686
|
-
/* @__PURE__ */
|
|
2329
|
+
/* @__PURE__ */ jsx26(
|
|
2687
2330
|
"div",
|
|
2688
2331
|
{
|
|
2689
2332
|
className: "absolute inset-0",
|
|
2690
2333
|
onClick: () => setModal({ id: "", open: false })
|
|
2691
2334
|
}
|
|
2692
2335
|
),
|
|
2693
|
-
/* @__PURE__ */
|
|
2694
|
-
/* @__PURE__ */
|
|
2336
|
+
/* @__PURE__ */ jsxs21("section", { className: "z-10 bg-white gap-2 flex-col items-center-safe justify-center-safe p-8 rounded-xl", children: [
|
|
2337
|
+
/* @__PURE__ */ jsx26(
|
|
2695
2338
|
Title_default,
|
|
2696
2339
|
{
|
|
2697
2340
|
textColor: "tomato",
|
|
@@ -2701,16 +2344,16 @@ var ShopperIsNotAuthenticated = ({ ID }) => {
|
|
|
2701
2344
|
children: "Opa! Parece que voc\xEA n\xE3o est\xE1 Logado"
|
|
2702
2345
|
}
|
|
2703
2346
|
),
|
|
2704
|
-
/* @__PURE__ */
|
|
2347
|
+
/* @__PURE__ */ jsxs21(Text_default, { className: "mb-2", textAlign: "center", children: [
|
|
2705
2348
|
"Para aproveitar os benef\xEDcios \xE9 necess\xE1rio realizar o",
|
|
2706
2349
|
" ",
|
|
2707
|
-
/* @__PURE__ */
|
|
2350
|
+
/* @__PURE__ */ jsx26("strong", { children: "Login" }),
|
|
2708
2351
|
" ou ",
|
|
2709
|
-
/* @__PURE__ */
|
|
2352
|
+
/* @__PURE__ */ jsx26("strong", { children: "Cadastro" }),
|
|
2710
2353
|
" no site!"
|
|
2711
2354
|
] }),
|
|
2712
|
-
/* @__PURE__ */
|
|
2713
|
-
/* @__PURE__ */
|
|
2355
|
+
/* @__PURE__ */ jsxs21("section", { className: "flex items-center-safe justify-center-safe gap-4", children: [
|
|
2356
|
+
/* @__PURE__ */ jsx26(
|
|
2714
2357
|
Button_default,
|
|
2715
2358
|
{
|
|
2716
2359
|
className: "bg-gray-600 hover:bg-gray-500",
|
|
@@ -2718,7 +2361,7 @@ var ShopperIsNotAuthenticated = ({ ID }) => {
|
|
|
2718
2361
|
children: "Seguir sem Benef\xEDcios"
|
|
2719
2362
|
}
|
|
2720
2363
|
),
|
|
2721
|
-
/* @__PURE__ */
|
|
2364
|
+
/* @__PURE__ */ jsx26(Link_default, { href: customLoginUrl || "/login", children: "Aproveitar Benef\xEDcios" })
|
|
2722
2365
|
] })
|
|
2723
2366
|
] })
|
|
2724
2367
|
]
|
|
@@ -2731,94 +2374,46 @@ var ShopperIsNotAuthenticated_default = ShopperIsNotAuthenticated;
|
|
|
2731
2374
|
import Skeleton from "@mui/material/Skeleton";
|
|
2732
2375
|
|
|
2733
2376
|
// src/hooks/useAppStartup.tsx
|
|
2734
|
-
import { useEffect as
|
|
2735
|
-
|
|
2736
|
-
// src/services/authorization.ts
|
|
2737
|
-
import Cookies11 from "js-cookie";
|
|
2738
|
-
|
|
2739
|
-
// src/services/clients-config.ts
|
|
2740
|
-
var CLIENTS_CONFIG = {
|
|
2741
|
-
santo_remedio: {
|
|
2742
|
-
access_token: getEnv("VITE_KEYCLOAK_ACCESSTOKEN_SANTOREMEDIO") || ""
|
|
2743
|
-
}
|
|
2744
|
-
};
|
|
2377
|
+
import { useEffect as useEffect2, useState as useState9 } from "react";
|
|
2745
2378
|
|
|
2746
2379
|
// src/services/authorization.ts
|
|
2380
|
+
import Cookies4 from "js-cookie";
|
|
2747
2381
|
var GetAuthorization = async ({ tenant_id }) => {
|
|
2748
|
-
|
|
2749
|
-
if (!client || !client.access_token) {
|
|
2382
|
+
if (!tenant_id) {
|
|
2750
2383
|
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
2751
2384
|
}
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
const data = await response.json();
|
|
2768
|
-
if (!data.success) {
|
|
2769
|
-
throw new Error("Authorization failed");
|
|
2770
|
-
}
|
|
2771
|
-
const SECONDS_IN_A_DAY = 86400;
|
|
2772
|
-
Cookies11.set("pbm-token", data.data.access_token, {
|
|
2773
|
-
secure: true,
|
|
2774
|
-
sameSite: "Strict",
|
|
2775
|
-
expires: data.data.expires_in / SECONDS_IN_A_DAY
|
|
2776
|
-
});
|
|
2777
|
-
return data;
|
|
2778
|
-
};
|
|
2779
|
-
|
|
2780
|
-
// src/services/get-product-by-ean.ts
|
|
2781
|
-
import Cookies12 from "js-cookie";
|
|
2782
|
-
var GetProductByEAN = async ({ PRODUCT_EAN }) => {
|
|
2783
|
-
const API_URL = getEnv("VITE_API_URL");
|
|
2784
|
-
const AUTH_TOKEN = Cookies12.get("pbm-token");
|
|
2785
|
-
if (!AUTH_TOKEN) {
|
|
2786
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
2787
|
-
}
|
|
2788
|
-
const response = await fetch(`${API_URL}/products/ean/${PRODUCT_EAN}`, {
|
|
2789
|
-
method: "GET",
|
|
2790
|
-
headers: {
|
|
2791
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
2792
|
-
"Content-Type": "application/json"
|
|
2793
|
-
}
|
|
2794
|
-
});
|
|
2795
|
-
const dataResponse = await response.json();
|
|
2796
|
-
if (!dataResponse.success) {
|
|
2797
|
-
throw new Error(dataResponse.message || "Failed to fetch authorization");
|
|
2798
|
-
}
|
|
2799
|
-
return dataResponse;
|
|
2800
|
-
};
|
|
2801
|
-
|
|
2802
|
-
// src/services/get-list-products.ts
|
|
2803
|
-
import Cookies13 from "js-cookie";
|
|
2804
|
-
var GetProductsWithBenefits = async (eanProduct) => {
|
|
2805
|
-
const API_URL = getEnv("VITE_API_URL");
|
|
2806
|
-
const AUTH_TOKEN = Cookies13.get("pbm-token");
|
|
2807
|
-
if (!AUTH_TOKEN) {
|
|
2808
|
-
throw new Error("Token is not defined in cookies or is expired");
|
|
2809
|
-
}
|
|
2810
|
-
const response = await fetch(`${API_URL}/products/program-verification/${eanProduct}`, {
|
|
2811
|
-
method: "GET",
|
|
2812
|
-
headers: {
|
|
2813
|
-
Authorization: `Bearer ${AUTH_TOKEN}`,
|
|
2814
|
-
"Content-Type": "application/json"
|
|
2385
|
+
try {
|
|
2386
|
+
const response = await fetch(
|
|
2387
|
+
`${getEnv("VITE_API_URL")}/api/token.ts`,
|
|
2388
|
+
{
|
|
2389
|
+
method: "POST",
|
|
2390
|
+
headers: {
|
|
2391
|
+
"Content-Type": "application/json",
|
|
2392
|
+
"Accept": "application/json"
|
|
2393
|
+
},
|
|
2394
|
+
body: JSON.stringify({ tenant_id })
|
|
2395
|
+
}
|
|
2396
|
+
);
|
|
2397
|
+
const data = await response.json();
|
|
2398
|
+
if (!data.success) {
|
|
2399
|
+
throw new Error("PBMLOG: Authorization failed!");
|
|
2815
2400
|
}
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2401
|
+
const SECONDS_IN_A_DAY = 86400;
|
|
2402
|
+
Cookies4.set("pbm-token", data.access_token, {
|
|
2403
|
+
secure: true,
|
|
2404
|
+
sameSite: "Strict",
|
|
2405
|
+
expires: data.expires_in / SECONDS_IN_A_DAY
|
|
2406
|
+
});
|
|
2407
|
+
Cookies4.set("tenant_id", tenant_id, {
|
|
2408
|
+
secure: true,
|
|
2409
|
+
sameSite: "Strict",
|
|
2410
|
+
expires: 7
|
|
2411
|
+
});
|
|
2412
|
+
return data;
|
|
2413
|
+
} catch (error) {
|
|
2414
|
+
console.error("Error during authorization:", error);
|
|
2415
|
+
return { success: false, error: "Authorization failed" };
|
|
2820
2416
|
}
|
|
2821
|
-
return dataResponse;
|
|
2822
2417
|
};
|
|
2823
2418
|
|
|
2824
2419
|
// src/libs/zustand/useTheme.tsx
|
|
@@ -2848,21 +2443,169 @@ function useTheme(selector) {
|
|
|
2848
2443
|
);
|
|
2849
2444
|
}
|
|
2850
2445
|
|
|
2446
|
+
// src/services/load-products-table.ts
|
|
2447
|
+
import Cookies5 from "js-cookie";
|
|
2448
|
+
|
|
2449
|
+
// src/utils/cleanupCacheTimestamp.ts
|
|
2450
|
+
var CLEANUP_HOUR = 2;
|
|
2451
|
+
var CLEANUP_MINUTE = 30;
|
|
2452
|
+
var cleanupCacheTimestamp = () => {
|
|
2453
|
+
const now = /* @__PURE__ */ new Date();
|
|
2454
|
+
const next = new Date(now);
|
|
2455
|
+
next.setHours(CLEANUP_HOUR, CLEANUP_MINUTE, 0, 0);
|
|
2456
|
+
if (next.getTime() <= now.getTime()) {
|
|
2457
|
+
next.setDate(next.getDate() + 1);
|
|
2458
|
+
}
|
|
2459
|
+
return next.getTime();
|
|
2460
|
+
};
|
|
2461
|
+
|
|
2462
|
+
// src/services/load-products-table.ts
|
|
2463
|
+
var memoryCache = /* @__PURE__ */ new Map();
|
|
2464
|
+
function getCacheKey(tenant_id) {
|
|
2465
|
+
return `load-products-table:${tenant_id}`;
|
|
2466
|
+
}
|
|
2467
|
+
function readCache(key) {
|
|
2468
|
+
const memEntry = memoryCache.get(key);
|
|
2469
|
+
if (memEntry && Date.now() < memEntry.expiresAt) {
|
|
2470
|
+
return memEntry.data;
|
|
2471
|
+
}
|
|
2472
|
+
try {
|
|
2473
|
+
const raw = localStorage.getItem(key);
|
|
2474
|
+
if (!raw) return null;
|
|
2475
|
+
const entry = JSON.parse(raw);
|
|
2476
|
+
if (Date.now() >= entry.expiresAt) {
|
|
2477
|
+
localStorage.removeItem(key);
|
|
2478
|
+
return null;
|
|
2479
|
+
}
|
|
2480
|
+
memoryCache.set(key, entry);
|
|
2481
|
+
return entry.data;
|
|
2482
|
+
} catch {
|
|
2483
|
+
return null;
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
function writeCache(key, data) {
|
|
2487
|
+
const entry = { data, expiresAt: cleanupCacheTimestamp(), success: true };
|
|
2488
|
+
memoryCache.set(key, entry);
|
|
2489
|
+
localStorage.setItem(key, JSON.stringify(entry));
|
|
2490
|
+
}
|
|
2491
|
+
var LoadProductsTable = async ({ tenant_id }) => {
|
|
2492
|
+
if (!tenant_id) {
|
|
2493
|
+
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
2494
|
+
}
|
|
2495
|
+
const cacheKey = getCacheKey(tenant_id);
|
|
2496
|
+
const cached = readCache(cacheKey);
|
|
2497
|
+
if (cached) {
|
|
2498
|
+
const result2 = {
|
|
2499
|
+
data: cached,
|
|
2500
|
+
expiresAt: memoryCache.get(cacheKey).expiresAt,
|
|
2501
|
+
success: true
|
|
2502
|
+
};
|
|
2503
|
+
return result2;
|
|
2504
|
+
}
|
|
2505
|
+
const response = await fetch(
|
|
2506
|
+
`${getEnv("VITE_API_URL")}/api/load-tables.ts`,
|
|
2507
|
+
{
|
|
2508
|
+
method: "POST",
|
|
2509
|
+
headers: {
|
|
2510
|
+
"Content-Type": "application/json",
|
|
2511
|
+
"Accept": "application/json",
|
|
2512
|
+
"Authorization": `Bearer ${Cookies5.get("pbm-token")}`
|
|
2513
|
+
},
|
|
2514
|
+
body: JSON.stringify({ tenant_id })
|
|
2515
|
+
}
|
|
2516
|
+
);
|
|
2517
|
+
const data = await response.json();
|
|
2518
|
+
if (data.informativeText !== "Processamento aprovado") {
|
|
2519
|
+
throw new Error("PBMLOG: Load Products Table Failed!");
|
|
2520
|
+
}
|
|
2521
|
+
Cookies5.set("current-table-id", data.control.tableId, {
|
|
2522
|
+
secure: true,
|
|
2523
|
+
sameSite: "Strict",
|
|
2524
|
+
expires: 1
|
|
2525
|
+
});
|
|
2526
|
+
Cookies5.set("current-central-number", data.control.centralNumber.toString(), {
|
|
2527
|
+
secure: true,
|
|
2528
|
+
sameSite: "Strict",
|
|
2529
|
+
expires: 1
|
|
2530
|
+
});
|
|
2531
|
+
Cookies5.set("current-local-hour", data.local_hour, {
|
|
2532
|
+
secure: true,
|
|
2533
|
+
sameSite: "Strict",
|
|
2534
|
+
expires: 1
|
|
2535
|
+
});
|
|
2536
|
+
const formattedData = extractTableData(data.control.tableImage);
|
|
2537
|
+
writeCache(cacheKey, formattedData);
|
|
2538
|
+
const result = {
|
|
2539
|
+
data: formattedData,
|
|
2540
|
+
expiresAt: memoryCache.get(cacheKey).expiresAt,
|
|
2541
|
+
success: true
|
|
2542
|
+
};
|
|
2543
|
+
return result;
|
|
2544
|
+
};
|
|
2545
|
+
function extractTableData(tableImage) {
|
|
2546
|
+
const states = tableImage.map((s) => s.state);
|
|
2547
|
+
const cities = tableImage.flatMap((s) => s.cities.map((c) => c.city));
|
|
2548
|
+
const federalCodes = tableImage.flatMap((s) => s.cities.flatMap((c) => c.federalCodes.map((f) => f.federalCode)));
|
|
2549
|
+
const programNames = tableImage.flatMap((s) => s.cities.flatMap((c) => c.federalCodes.flatMap((f) => f.programNames.map((p) => p.programName))));
|
|
2550
|
+
const products = tableImage.flatMap((s) => s.cities.flatMap((c) => c.federalCodes.flatMap((f) => f.programNames.flatMap((p) => p.products.map((pr) => pr.ean)))));
|
|
2551
|
+
return { states, cities, federalCodes, programNames, products };
|
|
2552
|
+
}
|
|
2553
|
+
|
|
2554
|
+
// src/services/product.ts
|
|
2555
|
+
import Cookies6 from "js-cookie";
|
|
2556
|
+
var GetProduct = async ({ tenant_id, product }) => {
|
|
2557
|
+
if (!tenant_id) {
|
|
2558
|
+
throw new Error(`No configuration found for tenant: ${tenant_id}`);
|
|
2559
|
+
}
|
|
2560
|
+
if (!product) {
|
|
2561
|
+
throw new Error(`Product information is required`);
|
|
2562
|
+
}
|
|
2563
|
+
try {
|
|
2564
|
+
const response = await fetch(
|
|
2565
|
+
`${getEnv("VITE_API_URL")}/api/product.ts`,
|
|
2566
|
+
{
|
|
2567
|
+
method: "POST",
|
|
2568
|
+
headers: {
|
|
2569
|
+
"Content-Type": "application/json",
|
|
2570
|
+
"Accept": "application/json",
|
|
2571
|
+
"Authorization": `Bearer ${Cookies6.get("pbm-token")}`
|
|
2572
|
+
},
|
|
2573
|
+
body: JSON.stringify({
|
|
2574
|
+
tenant_id,
|
|
2575
|
+
product,
|
|
2576
|
+
table_id: Cookies6.get("current-table-id"),
|
|
2577
|
+
local_hour: Cookies6.get("current-local-hour")
|
|
2578
|
+
})
|
|
2579
|
+
}
|
|
2580
|
+
);
|
|
2581
|
+
const data = await response.json();
|
|
2582
|
+
if (!data.success) {
|
|
2583
|
+
throw new Error("PBMLOG: Get Product Failed!");
|
|
2584
|
+
}
|
|
2585
|
+
return data;
|
|
2586
|
+
} catch (error) {
|
|
2587
|
+
console.error("Error during get product:", error);
|
|
2588
|
+
return { success: false, error: "Get Product Failed" };
|
|
2589
|
+
}
|
|
2590
|
+
};
|
|
2591
|
+
|
|
2851
2592
|
// src/hooks/useAppStartup.tsx
|
|
2852
2593
|
var useAppStartup = (props) => {
|
|
2853
2594
|
const {
|
|
2854
2595
|
setTargetProduct,
|
|
2855
|
-
|
|
2596
|
+
setBenefitsList,
|
|
2856
2597
|
setIsAuthenticatedShopper,
|
|
2857
2598
|
setCustomLoginUrl
|
|
2858
2599
|
} = usePBMStore();
|
|
2859
2600
|
const { setTheme } = useTheme();
|
|
2860
|
-
const [IsReady, setIsReady] =
|
|
2861
|
-
const [IsValid, setIsValid] =
|
|
2862
|
-
const [EanProductExist, setEanProductExist] =
|
|
2601
|
+
const [IsReady, setIsReady] = useState9(false);
|
|
2602
|
+
const [IsValid, setIsValid] = useState9(false);
|
|
2603
|
+
const [EanProductExist, setEanProductExist] = useState9(true);
|
|
2863
2604
|
const fetchAuthorizationRequest = async () => {
|
|
2864
2605
|
try {
|
|
2865
|
-
const response = await GetAuthorization({
|
|
2606
|
+
const response = await GetAuthorization({
|
|
2607
|
+
tenant_id: props.tenant_id
|
|
2608
|
+
});
|
|
2866
2609
|
if (!response.success) {
|
|
2867
2610
|
console.error("PBMLOG: Authorization failed!");
|
|
2868
2611
|
}
|
|
@@ -2873,57 +2616,73 @@ var useAppStartup = (props) => {
|
|
|
2873
2616
|
}
|
|
2874
2617
|
};
|
|
2875
2618
|
const fetchValidateProduct = async () => {
|
|
2876
|
-
if (!props.
|
|
2877
|
-
console.error("PBMLOG:
|
|
2619
|
+
if (!props.target_product) {
|
|
2620
|
+
console.error("PBMLOG: Target product is not defined.");
|
|
2878
2621
|
setEanProductExist(false);
|
|
2879
2622
|
return false;
|
|
2880
2623
|
}
|
|
2881
2624
|
try {
|
|
2882
|
-
const response = await
|
|
2883
|
-
if (response.success) {
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2625
|
+
const response = await LoadProductsTable({ tenant_id: props.tenant_id });
|
|
2626
|
+
if (!response.success) {
|
|
2627
|
+
console.error("PBMLOG: Product validation failed!");
|
|
2628
|
+
return false;
|
|
2629
|
+
}
|
|
2630
|
+
if (response.data.products.includes(props.target_product.ean.toString())) {
|
|
2631
|
+
setEanProductExist(true);
|
|
2632
|
+
return true;
|
|
2888
2633
|
}
|
|
2634
|
+
return false;
|
|
2889
2635
|
} catch (error) {
|
|
2890
|
-
console.error(error);
|
|
2636
|
+
console.error("Error fetching product validation:", error);
|
|
2637
|
+
setEanProductExist(false);
|
|
2891
2638
|
}
|
|
2892
2639
|
return false;
|
|
2893
2640
|
};
|
|
2894
|
-
const
|
|
2641
|
+
const fetchProductHasEnableDiscount = async () => {
|
|
2895
2642
|
try {
|
|
2896
|
-
if (!props.
|
|
2897
|
-
console.error("PBMLOG:
|
|
2643
|
+
if (!props.target_product) {
|
|
2644
|
+
console.error("PBMLOG: Target product is not defined.");
|
|
2898
2645
|
setEanProductExist(false);
|
|
2899
|
-
return;
|
|
2646
|
+
return false;
|
|
2900
2647
|
}
|
|
2901
|
-
const response = await
|
|
2902
|
-
|
|
2648
|
+
const response = await GetProduct({
|
|
2649
|
+
tenant_id: props.tenant_id,
|
|
2650
|
+
product: props.target_product
|
|
2903
2651
|
});
|
|
2904
|
-
if (response.success
|
|
2905
|
-
|
|
2906
|
-
const { pbm, sku: _sku, ...targetProductNewData } = response.data;
|
|
2907
|
-
setTargetProduct({
|
|
2908
|
-
...targetProduct,
|
|
2909
|
-
...targetProductNewData,
|
|
2910
|
-
productId: Number(targetProductNewData.productId),
|
|
2911
|
-
informativeMessage: pbm.informativeMessage ?? "",
|
|
2912
|
-
discountMax: pbm.discountMax ?? 0,
|
|
2913
|
-
industryLogo: pbm.imageLink ?? void 0,
|
|
2914
|
-
ean: props.ean_product
|
|
2915
|
-
});
|
|
2916
|
-
setIsAuthenticatedShopper(props.is_authenticated_shopper);
|
|
2917
|
-
setCustomLoginUrl(props.custom_login_url);
|
|
2918
|
-
} else {
|
|
2652
|
+
if (!response.success) {
|
|
2653
|
+
console.error("PBMLOG: Product discount check failed!");
|
|
2919
2654
|
setEanProductExist(false);
|
|
2655
|
+
return false;
|
|
2920
2656
|
}
|
|
2657
|
+
if (!response.product || response.product.length === 0) {
|
|
2658
|
+
console.error("PBMLOG: Product not found in discount check!");
|
|
2659
|
+
setEanProductExist(false);
|
|
2660
|
+
return false;
|
|
2661
|
+
}
|
|
2662
|
+
setTargetProduct({
|
|
2663
|
+
...response.product[0],
|
|
2664
|
+
requestedQuantity: 1,
|
|
2665
|
+
listPrice: props.target_product.listPrice,
|
|
2666
|
+
netPrice: props.target_product.netPrice
|
|
2667
|
+
});
|
|
2668
|
+
setBenefitsList(
|
|
2669
|
+
response.product.map((prod) => ({
|
|
2670
|
+
...prod,
|
|
2671
|
+
listPrice: props.target_product.listPrice,
|
|
2672
|
+
netPrice: props.target_product.netPrice
|
|
2673
|
+
}))
|
|
2674
|
+
);
|
|
2675
|
+
setIsAuthenticatedShopper(props.is_authenticated_shopper);
|
|
2676
|
+
setCustomLoginUrl(props.custom_login_url);
|
|
2677
|
+
setEanProductExist(true);
|
|
2678
|
+
return true;
|
|
2921
2679
|
} catch (error) {
|
|
2922
2680
|
console.error(error);
|
|
2923
2681
|
setEanProductExist(false);
|
|
2682
|
+
return false;
|
|
2924
2683
|
}
|
|
2925
2684
|
};
|
|
2926
|
-
|
|
2685
|
+
useEffect2(() => {
|
|
2927
2686
|
let isMounted = true;
|
|
2928
2687
|
const startup = async () => {
|
|
2929
2688
|
if (props.theme) {
|
|
@@ -2931,9 +2690,13 @@ var useAppStartup = (props) => {
|
|
|
2931
2690
|
}
|
|
2932
2691
|
const isAuthorized = await fetchAuthorizationRequest();
|
|
2933
2692
|
if (!isAuthorized || !isMounted) return;
|
|
2934
|
-
const isValidProduct = await
|
|
2693
|
+
const isValidProduct = await Promise.all(
|
|
2694
|
+
[fetchValidateProduct(), fetchProductHasEnableDiscount()].filter(
|
|
2695
|
+
Boolean
|
|
2696
|
+
)
|
|
2697
|
+
).then((results) => results.every(Boolean));
|
|
2698
|
+
setIsValid(isValidProduct);
|
|
2935
2699
|
if (!isValidProduct || !isMounted) return;
|
|
2936
|
-
await fetchProductByEan();
|
|
2937
2700
|
if (isMounted) {
|
|
2938
2701
|
setIsReady(true);
|
|
2939
2702
|
}
|
|
@@ -2942,14 +2705,14 @@ var useAppStartup = (props) => {
|
|
|
2942
2705
|
return () => {
|
|
2943
2706
|
isMounted = false;
|
|
2944
2707
|
};
|
|
2945
|
-
}, [props.
|
|
2708
|
+
}, [props.tenant_id]);
|
|
2946
2709
|
return { IsReady, IsValid, EanProductExist };
|
|
2947
2710
|
};
|
|
2948
2711
|
var useAppStartup_default = useAppStartup;
|
|
2949
2712
|
|
|
2950
2713
|
// src/PBM.tsx
|
|
2951
2714
|
import { useTransition as useTransition2 } from "react";
|
|
2952
|
-
import { Fragment as Fragment3, jsx as
|
|
2715
|
+
import { Fragment as Fragment3, jsx as jsx27, jsxs as jsxs22 } from "react/jsx-runtime";
|
|
2953
2716
|
function PBM(props) {
|
|
2954
2717
|
const { state } = usePBMStore();
|
|
2955
2718
|
const { IsReady, EanProductExist, IsValid } = useAppStartup_default(props);
|
|
@@ -2959,7 +2722,7 @@ function PBM(props) {
|
|
|
2959
2722
|
const formatedProductPrice = formaters.price(props.original_product_price);
|
|
2960
2723
|
if (!IsValid) return;
|
|
2961
2724
|
if (!IsReady) {
|
|
2962
|
-
return /* @__PURE__ */
|
|
2725
|
+
return /* @__PURE__ */ jsx27(
|
|
2963
2726
|
Skeleton,
|
|
2964
2727
|
{
|
|
2965
2728
|
variant: "rectangular",
|
|
@@ -2973,9 +2736,9 @@ function PBM(props) {
|
|
|
2973
2736
|
setErrorMessage(
|
|
2974
2737
|
"O produto n\xE3o foi encontrado no sistema. Por favor, tente novamente mais tarde ou contate o suporte."
|
|
2975
2738
|
);
|
|
2976
|
-
return /* @__PURE__ */
|
|
2739
|
+
return /* @__PURE__ */ jsx27("div", { id: "pbm-library-root", children: /* @__PURE__ */ jsx27(ErrorToApplyBenefits_default, {}) });
|
|
2977
2740
|
}
|
|
2978
|
-
return /* @__PURE__ */
|
|
2741
|
+
return /* @__PURE__ */ jsxs22(
|
|
2979
2742
|
"div",
|
|
2980
2743
|
{
|
|
2981
2744
|
id: "pbm-library-root",
|
|
@@ -2991,19 +2754,18 @@ function PBM(props) {
|
|
|
2991
2754
|
"--pbm-input-background": theme.inputBackgroundColor
|
|
2992
2755
|
},
|
|
2993
2756
|
children: [
|
|
2994
|
-
/* @__PURE__ */
|
|
2995
|
-
/* @__PURE__ */
|
|
2996
|
-
/* @__PURE__ */
|
|
2997
|
-
state === "isEmpty" && /* @__PURE__ */
|
|
2998
|
-
state === "isInvalid" && /* @__PURE__ */
|
|
2999
|
-
state === "isRegistered" && /* @__PURE__ */
|
|
3000
|
-
(state === "isActivated" || state === "isPreview") && /* @__PURE__ */
|
|
3001
|
-
state === "isError" && /* @__PURE__ */
|
|
2757
|
+
/* @__PURE__ */ jsxs22(Container_default, { variant: "main", children: [
|
|
2758
|
+
/* @__PURE__ */ jsx27(Header_default, { originalProductPrice: formatedProductPrice || 0 }),
|
|
2759
|
+
/* @__PURE__ */ jsx27(Container_default, { variant: "simple", children: isPending ? /* @__PURE__ */ jsx27(Loading_default, {}) : /* @__PURE__ */ jsxs22(Fragment3, { children: [
|
|
2760
|
+
state === "isEmpty" && /* @__PURE__ */ jsx27(Form_default, { startTransition }),
|
|
2761
|
+
state === "isInvalid" && /* @__PURE__ */ jsx27(SecurityNumberInvalid_default, {}),
|
|
2762
|
+
state === "isRegistered" && /* @__PURE__ */ jsx27(SecurityNumberRegitered_default, {}),
|
|
2763
|
+
(state === "isActivated" || state === "isPreview") && /* @__PURE__ */ jsx27(BenefitsTable_default, {}),
|
|
2764
|
+
state === "isError" && /* @__PURE__ */ jsx27(ErrorToApplyBenefits_default, {})
|
|
3002
2765
|
] }) })
|
|
3003
2766
|
] }),
|
|
3004
|
-
/* @__PURE__ */
|
|
3005
|
-
/* @__PURE__ */
|
|
3006
|
-
/* @__PURE__ */ jsx28(Iframe_default, {})
|
|
2767
|
+
/* @__PURE__ */ jsx27(ShopperIsNotAuthenticated_default, { ID: "ShopperIsNotAuthenticated" }),
|
|
2768
|
+
/* @__PURE__ */ jsx27(CustomerNotRegistered_default, { ID: "CustomerNotRegistered" })
|
|
3007
2769
|
]
|
|
3008
2770
|
}
|
|
3009
2771
|
);
|