mitre-form-component 0.1.4 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -28
- package/dist/index.cjs +439 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -3
- package/dist/index.d.ts +53 -3
- package/dist/index.js +427 -58
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -894,16 +894,183 @@ var Alert = ({
|
|
|
894
894
|
);
|
|
895
895
|
};
|
|
896
896
|
|
|
897
|
+
// src/components/Modal/index.tsx
|
|
898
|
+
import { useEffect as useEffect3, useRef } from "react";
|
|
899
|
+
import { HiX as HiX2 } from "react-icons/hi";
|
|
900
|
+
|
|
901
|
+
// src/components/Modal/styles.ts
|
|
902
|
+
import styled6, { css as css5, keyframes as keyframes2 } from "styled-components";
|
|
903
|
+
var fadeIn2 = keyframes2`
|
|
904
|
+
from { opacity: 0; }
|
|
905
|
+
to { opacity: 1; }
|
|
906
|
+
`;
|
|
907
|
+
var slideIn = keyframes2`
|
|
908
|
+
from { opacity: 0; transform: translateY(-20px) scale(0.96); }
|
|
909
|
+
to { opacity: 1; transform: translateY(0) scale(1); }
|
|
910
|
+
`;
|
|
911
|
+
var Overlay = styled6.div`
|
|
912
|
+
position: fixed;
|
|
913
|
+
inset: 0;
|
|
914
|
+
background: rgba(0, 0, 0, 0.55);
|
|
915
|
+
display: flex;
|
|
916
|
+
align-items: center;
|
|
917
|
+
justify-content: center;
|
|
918
|
+
z-index: 9999;
|
|
919
|
+
padding: 1rem;
|
|
920
|
+
animation: ${fadeIn2} 0.18s ease-out;
|
|
921
|
+
`;
|
|
922
|
+
var accentStyles = {
|
|
923
|
+
success: css5`
|
|
924
|
+
color: ${theme.colors.green2};
|
|
925
|
+
`,
|
|
926
|
+
error: css5`
|
|
927
|
+
color: ${theme.colors.red};
|
|
928
|
+
`
|
|
929
|
+
};
|
|
930
|
+
var Container = styled6.div`
|
|
931
|
+
position: relative;
|
|
932
|
+
background: ${theme.colors.white};
|
|
933
|
+
border-radius: 0.75rem;
|
|
934
|
+
box-shadow: ${theme.shadows.shadow500};
|
|
935
|
+
max-width: 420px;
|
|
936
|
+
width: 100%;
|
|
937
|
+
padding: 1.75rem 1.5rem 1.25rem;
|
|
938
|
+
font-family: ${theme.fonts.primary};
|
|
939
|
+
animation: ${slideIn} 0.22s ease-out;
|
|
940
|
+
|
|
941
|
+
&::before {
|
|
942
|
+
content: "";
|
|
943
|
+
display: block;
|
|
944
|
+
width: 56px;
|
|
945
|
+
height: 4px;
|
|
946
|
+
border-radius: 999px;
|
|
947
|
+
margin: 0 auto 1rem;
|
|
948
|
+
background: ${({ $type }) => $type === "success" ? theme.colors.green2 : theme.colors.red};
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
h2 {
|
|
952
|
+
margin: 0 0 0.5rem;
|
|
953
|
+
font-size: 1.25rem;
|
|
954
|
+
font-weight: 700;
|
|
955
|
+
text-align: center;
|
|
956
|
+
${({ $type }) => accentStyles[$type]}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
p {
|
|
960
|
+
margin: 0 0 1.5rem;
|
|
961
|
+
font-size: 0.95rem;
|
|
962
|
+
line-height: 1.45;
|
|
963
|
+
text-align: center;
|
|
964
|
+
color: ${theme.colors.black};
|
|
965
|
+
}
|
|
966
|
+
`;
|
|
967
|
+
var CloseButton = styled6.button`
|
|
968
|
+
position: absolute;
|
|
969
|
+
top: 0.5rem;
|
|
970
|
+
right: 0.5rem;
|
|
971
|
+
background: transparent;
|
|
972
|
+
border: none;
|
|
973
|
+
cursor: pointer;
|
|
974
|
+
color: ${theme.colors.gray550};
|
|
975
|
+
padding: 0.25rem;
|
|
976
|
+
display: inline-flex;
|
|
977
|
+
align-items: center;
|
|
978
|
+
justify-content: center;
|
|
979
|
+
border-radius: 999px;
|
|
980
|
+
transition: background 0.15s, color 0.15s;
|
|
981
|
+
|
|
982
|
+
&:hover {
|
|
983
|
+
background: ${theme.colors.gray300};
|
|
984
|
+
color: ${theme.colors.black};
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
svg {
|
|
988
|
+
width: 1.1rem;
|
|
989
|
+
height: 1.1rem;
|
|
990
|
+
}
|
|
991
|
+
`;
|
|
992
|
+
var PrimaryButton = styled6.button`
|
|
993
|
+
display: block;
|
|
994
|
+
width: 100%;
|
|
995
|
+
padding: 0.75rem 1rem;
|
|
996
|
+
border: none;
|
|
997
|
+
border-radius: 0.5rem;
|
|
998
|
+
background: ${({ $bgColor }) => $bgColor || theme.colors.yellow500};
|
|
999
|
+
color: ${({ $textColor }) => $textColor || theme.colors.black};
|
|
1000
|
+
font-family: ${theme.fonts.primary};
|
|
1001
|
+
font-size: 1rem;
|
|
1002
|
+
font-weight: 700;
|
|
1003
|
+
cursor: pointer;
|
|
1004
|
+
transition: filter 0.15s;
|
|
1005
|
+
|
|
1006
|
+
&:hover {
|
|
1007
|
+
filter: brightness(0.95);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
&:focus-visible {
|
|
1011
|
+
outline: 2px solid ${theme.colors.yellow400};
|
|
1012
|
+
outline-offset: 2px;
|
|
1013
|
+
}
|
|
1014
|
+
`;
|
|
1015
|
+
|
|
1016
|
+
// src/components/Modal/index.tsx
|
|
1017
|
+
import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1018
|
+
var Modal = ({
|
|
1019
|
+
type,
|
|
1020
|
+
title,
|
|
1021
|
+
message,
|
|
1022
|
+
primaryButtonText,
|
|
1023
|
+
onPrimaryAction,
|
|
1024
|
+
onClose,
|
|
1025
|
+
primaryButtonBgColor,
|
|
1026
|
+
primaryButtonTextColor
|
|
1027
|
+
}) => {
|
|
1028
|
+
const primaryButtonRef = useRef(null);
|
|
1029
|
+
useEffect3(() => {
|
|
1030
|
+
primaryButtonRef.current?.focus();
|
|
1031
|
+
}, []);
|
|
1032
|
+
useEffect3(() => {
|
|
1033
|
+
const handleKey = (event) => {
|
|
1034
|
+
if (event.key === "Escape") {
|
|
1035
|
+
onClose();
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
document.addEventListener("keydown", handleKey);
|
|
1039
|
+
return () => document.removeEventListener("keydown", handleKey);
|
|
1040
|
+
}, [onClose]);
|
|
1041
|
+
const handleOverlayClick = (event) => {
|
|
1042
|
+
if (event.target === event.currentTarget) {
|
|
1043
|
+
onClose();
|
|
1044
|
+
}
|
|
1045
|
+
};
|
|
1046
|
+
return /* @__PURE__ */ jsx4(Overlay, { onClick: handleOverlayClick, role: "dialog", "aria-modal": "true", "aria-label": title, children: /* @__PURE__ */ jsxs4(Container, { $type: type, children: [
|
|
1047
|
+
/* @__PURE__ */ jsx4(CloseButton, { onClick: onClose, "aria-label": "Fechar", children: /* @__PURE__ */ jsx4(HiX2, {}) }),
|
|
1048
|
+
/* @__PURE__ */ jsx4("h2", { children: title }),
|
|
1049
|
+
/* @__PURE__ */ jsx4("p", { children: message }),
|
|
1050
|
+
/* @__PURE__ */ jsx4(
|
|
1051
|
+
PrimaryButton,
|
|
1052
|
+
{
|
|
1053
|
+
ref: primaryButtonRef,
|
|
1054
|
+
onClick: onPrimaryAction,
|
|
1055
|
+
$bgColor: primaryButtonBgColor,
|
|
1056
|
+
$textColor: primaryButtonTextColor,
|
|
1057
|
+
type: "button",
|
|
1058
|
+
children: primaryButtonText
|
|
1059
|
+
}
|
|
1060
|
+
)
|
|
1061
|
+
] }) });
|
|
1062
|
+
};
|
|
1063
|
+
|
|
897
1064
|
// src/components/PhoneInput/index.tsx
|
|
898
1065
|
import {
|
|
899
1066
|
forwardRef as forwardRef2
|
|
900
1067
|
} from "react";
|
|
901
1068
|
|
|
902
1069
|
// src/components/PhoneInput/styles.ts
|
|
903
|
-
import
|
|
1070
|
+
import styled7, { css as css6 } from "styled-components";
|
|
904
1071
|
import { PhoneInput } from "react-international-phone";
|
|
905
1072
|
import "react-international-phone/style.css";
|
|
906
|
-
var FormLabel3 =
|
|
1073
|
+
var FormLabel3 = styled7.label`
|
|
907
1074
|
font-family: ${theme.fonts.primary};
|
|
908
1075
|
font-style: normal;
|
|
909
1076
|
font-weight: 500;
|
|
@@ -913,7 +1080,7 @@ var FormLabel3 = styled6.label`
|
|
|
913
1080
|
margin-bottom: 0.5rem;
|
|
914
1081
|
text-align: left;
|
|
915
1082
|
`;
|
|
916
|
-
var StyledPhoneInput =
|
|
1083
|
+
var StyledPhoneInput = styled7(PhoneInput)`
|
|
917
1084
|
width: 100%;
|
|
918
1085
|
height: 3.125rem;
|
|
919
1086
|
background: ${(props) => props.$backgroundColor || theme.colors.white};
|
|
@@ -1027,24 +1194,24 @@ var StyledPhoneInput = styled6(PhoneInput)`
|
|
|
1027
1194
|
}
|
|
1028
1195
|
}
|
|
1029
1196
|
`;
|
|
1030
|
-
var FormErrorMessage3 =
|
|
1197
|
+
var FormErrorMessage3 = styled7.small`
|
|
1031
1198
|
font-size: 0.75rem;
|
|
1032
1199
|
line-height: 1.125rem;
|
|
1033
1200
|
color: ${theme.colors.red};
|
|
1034
1201
|
margin-top: 0.25rem;
|
|
1035
1202
|
display: block;
|
|
1036
1203
|
`;
|
|
1037
|
-
var FormControl3 =
|
|
1204
|
+
var FormControl3 = styled7.div.withConfig({
|
|
1038
1205
|
shouldForwardProp: (prop) => !["isInvalid"].includes(prop)
|
|
1039
1206
|
})`
|
|
1040
1207
|
${FormLabel3} {
|
|
1041
|
-
${(props) => props.isInvalid &&
|
|
1208
|
+
${(props) => props.isInvalid && css6`
|
|
1042
1209
|
color: ${theme.colors.red};
|
|
1043
1210
|
`};
|
|
1044
1211
|
}
|
|
1045
1212
|
|
|
1046
1213
|
${StyledPhoneInput} {
|
|
1047
|
-
${(props) => props.isInvalid &&
|
|
1214
|
+
${(props) => props.isInvalid && css6`
|
|
1048
1215
|
border: 1px solid ${theme.colors.red};
|
|
1049
1216
|
|
|
1050
1217
|
&:not(:focus)::placeholder {
|
|
@@ -1054,7 +1221,7 @@ var FormControl3 = styled6.div.withConfig({
|
|
|
1054
1221
|
`};
|
|
1055
1222
|
|
|
1056
1223
|
.react-international-phone-input-container {
|
|
1057
|
-
${(props) => props.isInvalid &&
|
|
1224
|
+
${(props) => props.isInvalid && css6`
|
|
1058
1225
|
border: 1px solid ${theme.colors.red};
|
|
1059
1226
|
|
|
1060
1227
|
&:not(:focus)::placeholder {
|
|
@@ -1065,7 +1232,7 @@ var FormControl3 = styled6.div.withConfig({
|
|
|
1065
1232
|
}
|
|
1066
1233
|
|
|
1067
1234
|
.react-international-phone-country-selector-button {
|
|
1068
|
-
${(props) => props.isInvalid &&
|
|
1235
|
+
${(props) => props.isInvalid && css6`
|
|
1069
1236
|
border-right: 1px solid ${theme.colors.red};
|
|
1070
1237
|
`};
|
|
1071
1238
|
}
|
|
@@ -1073,7 +1240,7 @@ var FormControl3 = styled6.div.withConfig({
|
|
|
1073
1240
|
`;
|
|
1074
1241
|
|
|
1075
1242
|
// src/components/PhoneInput/index.tsx
|
|
1076
|
-
import { jsx as
|
|
1243
|
+
import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1077
1244
|
var PhoneInputBase = ({
|
|
1078
1245
|
id,
|
|
1079
1246
|
label,
|
|
@@ -1088,9 +1255,9 @@ var PhoneInputBase = ({
|
|
|
1088
1255
|
value,
|
|
1089
1256
|
...rest
|
|
1090
1257
|
}, ref) => {
|
|
1091
|
-
return /* @__PURE__ */
|
|
1092
|
-
!!label && /* @__PURE__ */
|
|
1093
|
-
/* @__PURE__ */
|
|
1258
|
+
return /* @__PURE__ */ jsxs5(FormControl3, { isInvalid: !!error, children: [
|
|
1259
|
+
!!label && /* @__PURE__ */ jsx5(FormLabel3, { htmlFor: id, $textColor: labelTextColor, children: label }),
|
|
1260
|
+
/* @__PURE__ */ jsx5(
|
|
1094
1261
|
StyledPhoneInput,
|
|
1095
1262
|
{
|
|
1096
1263
|
ref,
|
|
@@ -1124,7 +1291,7 @@ var PhoneInputBase = ({
|
|
|
1124
1291
|
$textColor: inputTextColor
|
|
1125
1292
|
}
|
|
1126
1293
|
),
|
|
1127
|
-
!!error && showErrorMessage && /* @__PURE__ */
|
|
1294
|
+
!!error && showErrorMessage && /* @__PURE__ */ jsx5(FormErrorMessage3, { "data-testid": "error-message", children: typeof error === "string" ? error : error?.message })
|
|
1128
1295
|
] });
|
|
1129
1296
|
};
|
|
1130
1297
|
var PhoneInput2 = forwardRef2(PhoneInputBase);
|
|
@@ -1133,7 +1300,7 @@ var PhoneInput2 = forwardRef2(PhoneInputBase);
|
|
|
1133
1300
|
import {
|
|
1134
1301
|
forwardRef as forwardRef3
|
|
1135
1302
|
} from "react";
|
|
1136
|
-
import { jsx as
|
|
1303
|
+
import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1137
1304
|
var ProductSelectBase = ({
|
|
1138
1305
|
id,
|
|
1139
1306
|
label,
|
|
@@ -1148,9 +1315,9 @@ var ProductSelectBase = ({
|
|
|
1148
1315
|
placeholder = "Selecione um produto",
|
|
1149
1316
|
...rest
|
|
1150
1317
|
}, ref) => {
|
|
1151
|
-
return /* @__PURE__ */
|
|
1152
|
-
!!label && /* @__PURE__ */
|
|
1153
|
-
/* @__PURE__ */
|
|
1318
|
+
return /* @__PURE__ */ jsxs6(FormControl, { isInvalid: !!error, children: [
|
|
1319
|
+
!!label && /* @__PURE__ */ jsx6(FormLabel, { htmlFor: id, $textColor: labelTextColor, children: label }),
|
|
1320
|
+
/* @__PURE__ */ jsxs6(
|
|
1154
1321
|
Select,
|
|
1155
1322
|
{
|
|
1156
1323
|
id,
|
|
@@ -1162,18 +1329,37 @@ var ProductSelectBase = ({
|
|
|
1162
1329
|
$textColor: textColor,
|
|
1163
1330
|
...rest,
|
|
1164
1331
|
children: [
|
|
1165
|
-
/* @__PURE__ */
|
|
1166
|
-
products.map((product) => /* @__PURE__ */
|
|
1332
|
+
/* @__PURE__ */ jsx6("option", { value: "", disabled: true, children: placeholder }),
|
|
1333
|
+
products.map((product) => /* @__PURE__ */ jsx6("option", { value: product.id, children: product.name }, product.id))
|
|
1167
1334
|
]
|
|
1168
1335
|
}
|
|
1169
1336
|
),
|
|
1170
|
-
!!error && showErrorMessage && /* @__PURE__ */
|
|
1337
|
+
!!error && showErrorMessage && /* @__PURE__ */ jsx6(FormErrorMessage, { "data-testid": "error-message", children: typeof error === "string" ? error : error.message })
|
|
1171
1338
|
] });
|
|
1172
1339
|
};
|
|
1173
1340
|
var ProductSelect = forwardRef3(ProductSelectBase);
|
|
1174
1341
|
|
|
1342
|
+
// src/config/environments.ts
|
|
1343
|
+
var ENVIRONMENTS = {
|
|
1344
|
+
homol: {
|
|
1345
|
+
apiUrl: "https://leads-hml.mitrerealty.com.br/api-leads",
|
|
1346
|
+
apiToken: "TEFORElOR19NSVRSRTptZlFXZnhvUHdNbWVZY0FidkF0QWJ3Q2RFYWtKckJBOXg5cGNsOTBvS1V0N2ZsU0d4TEtNdEZZd3k0NFlEc0c3",
|
|
1347
|
+
whatsappPhone: "551148100601",
|
|
1348
|
+
chatUrl: "https://crm-hml.mitrerealty.com.br/wcc/UserLoginSubmit.do"
|
|
1349
|
+
},
|
|
1350
|
+
prod: {
|
|
1351
|
+
apiUrl: "https://leads.mitrerealty.com.br/api-leads",
|
|
1352
|
+
apiToken: "TEFORElOR19NSVRSRTptZlFXZnhvUHdNbWVZY0FidkF0QWJ3Q2RFYWtKckJBOXg5cGNsOTBvS1V0N2ZsU0d4TEtNdEZZd3k0NFlEc0c3",
|
|
1353
|
+
whatsappPhone: "551148100601",
|
|
1354
|
+
chatUrl: "https://crm.mitrerealty.com.br/wcc/UserLoginSubmit.do"
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
var resolveEnvironment = (ambiente = "homol") => {
|
|
1358
|
+
return ENVIRONMENTS[ambiente] ?? null;
|
|
1359
|
+
};
|
|
1360
|
+
|
|
1175
1361
|
// src/components/Form/index.tsx
|
|
1176
|
-
import { Fragment, jsx as
|
|
1362
|
+
import { Fragment, jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1177
1363
|
var phoneUtil = PhoneNumberUtil.getInstance();
|
|
1178
1364
|
var PreferenciaContato = /* @__PURE__ */ ((PreferenciaContato2) => {
|
|
1179
1365
|
PreferenciaContato2["Whatsapp"] = "Whatsapp";
|
|
@@ -1181,6 +1367,40 @@ var PreferenciaContato = /* @__PURE__ */ ((PreferenciaContato2) => {
|
|
|
1181
1367
|
PreferenciaContato2["Ligacao"] = "Liga\xE7\xE3o";
|
|
1182
1368
|
return PreferenciaContato2;
|
|
1183
1369
|
})(PreferenciaContato || {});
|
|
1370
|
+
var WHATSAPP_MESSAGE = "Ol\xE1! Tenho interesse e gostaria de mais informa\xE7\xF5es.";
|
|
1371
|
+
var WHATSAPP_TITLE = "Fale com um corretor por WhatsApp";
|
|
1372
|
+
var WHATSAPP_SUBTITLE = "Informe seus dados para contato.";
|
|
1373
|
+
var WHATSAPP_BUTTON_TEXT = "Entrar";
|
|
1374
|
+
var CHAT_TITLE = "Fale com um corretor por chat";
|
|
1375
|
+
var CHAT_SUBTITLE = "Informe seus dados para contato.";
|
|
1376
|
+
var CHAT_BUTTON_TEXT = "Entrar";
|
|
1377
|
+
var MODAL_ERROR_TITLE = "N\xE3o foi poss\xEDvel completar seu contato";
|
|
1378
|
+
var MODAL_ERROR_MESSAGE = "Por favor, tente novamente em alguns instantes.";
|
|
1379
|
+
var MODAL_ERROR_BUTTON_TEXT = "OK";
|
|
1380
|
+
var MODAL_SUCCESS_TITLE = "Cadastro realizado!";
|
|
1381
|
+
var MODAL_SUCCESS_MESSAGE_WHATSAPP = "Clique abaixo para continuar pelo WhatsApp.";
|
|
1382
|
+
var MODAL_SUCCESS_BUTTON_WHATSAPP = "Abrir WhatsApp";
|
|
1383
|
+
var MODAL_SUCCESS_MESSAGE_CHAT = "Clique abaixo para iniciar o atendimento.";
|
|
1384
|
+
var MODAL_SUCCESS_BUTTON_CHAT = "Iniciar atendimento";
|
|
1385
|
+
function buildWhatsappUrl(phone) {
|
|
1386
|
+
const digits = phone.replace(/\D/g, "");
|
|
1387
|
+
const text = encodeURIComponent(WHATSAPP_MESSAGE);
|
|
1388
|
+
return `https://api.whatsapp.com/send?phone=${digits}&text=${text}`;
|
|
1389
|
+
}
|
|
1390
|
+
function submitChatInNewTab(chatUrl, virtualObj) {
|
|
1391
|
+
const form = document.createElement("form");
|
|
1392
|
+
form.method = "POST";
|
|
1393
|
+
form.action = chatUrl;
|
|
1394
|
+
form.target = "_blank";
|
|
1395
|
+
const input = document.createElement("input");
|
|
1396
|
+
input.type = "hidden";
|
|
1397
|
+
input.name = "virtual_obj";
|
|
1398
|
+
input.value = JSON.stringify(virtualObj);
|
|
1399
|
+
form.appendChild(input);
|
|
1400
|
+
document.body.appendChild(form);
|
|
1401
|
+
form.submit();
|
|
1402
|
+
document.body.removeChild(form);
|
|
1403
|
+
}
|
|
1184
1404
|
var isPhoneValid = (phone) => {
|
|
1185
1405
|
try {
|
|
1186
1406
|
return phoneUtil.isValidNumber(phoneUtil.parseAndKeepRawInput(phone));
|
|
@@ -1212,8 +1432,8 @@ var schemaWithProduct = yup.object().shape({
|
|
|
1212
1432
|
var schema = yup.object().shape(baseSchema);
|
|
1213
1433
|
var MitreFormComponent = React2.forwardRef(({
|
|
1214
1434
|
products,
|
|
1215
|
-
|
|
1216
|
-
|
|
1435
|
+
ambiente = "homol",
|
|
1436
|
+
canal = "form",
|
|
1217
1437
|
showHeader = true,
|
|
1218
1438
|
title = "Atendimento por mensagem",
|
|
1219
1439
|
subtitle = "Informe seus dados e retornaremos a mensagem.",
|
|
@@ -1228,6 +1448,9 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1228
1448
|
inputPlaceholderColor = theme.colors.gray100,
|
|
1229
1449
|
inputTextColor = theme.colors.black,
|
|
1230
1450
|
showPreferenciaContato = false,
|
|
1451
|
+
idProdutoTerceiro,
|
|
1452
|
+
idEmpreendimento,
|
|
1453
|
+
naoCriarEvento,
|
|
1231
1454
|
onSuccess,
|
|
1232
1455
|
onError
|
|
1233
1456
|
}, ref) => {
|
|
@@ -1237,6 +1460,7 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1237
1460
|
const [successMessage, setSuccessMessage] = useState3("");
|
|
1238
1461
|
const [formKey, setFormKey] = useState3(0);
|
|
1239
1462
|
const [selectedProductId, setSelectedProductId] = useState3(null);
|
|
1463
|
+
const [actionModal, setActionModal] = useState3(null);
|
|
1240
1464
|
const validateProducts = () => {
|
|
1241
1465
|
if (!products) {
|
|
1242
1466
|
return "Lista de produtos n\xE3o foi fornecida";
|
|
@@ -1261,7 +1485,53 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1261
1485
|
}
|
|
1262
1486
|
return null;
|
|
1263
1487
|
};
|
|
1488
|
+
const env = resolveEnvironment(ambiente);
|
|
1489
|
+
const validateAmbienteConfig = () => {
|
|
1490
|
+
if (!env) {
|
|
1491
|
+
return `ambiente='${ambiente}' n\xE3o \xE9 reconhecido. Use 'homol' ou 'prod'.`;
|
|
1492
|
+
}
|
|
1493
|
+
if (!env.apiUrl || !env.apiToken) {
|
|
1494
|
+
return `Configura\xE7\xE3o interna do ambiente '${ambiente}' est\xE1 incompleta (apiUrl/apiToken).`;
|
|
1495
|
+
}
|
|
1496
|
+
return null;
|
|
1497
|
+
};
|
|
1498
|
+
const validateWhatsappConfig = () => {
|
|
1499
|
+
if (canal !== "whatsapp") return null;
|
|
1500
|
+
if (!env) return null;
|
|
1501
|
+
const raw = env.whatsappPhone?.trim() ?? "";
|
|
1502
|
+
if (!raw) {
|
|
1503
|
+
return `canal='whatsapp' exige whatsappPhone no ambiente '${ambiente}'.`;
|
|
1504
|
+
}
|
|
1505
|
+
const normalized = raw.startsWith("+") ? raw : `+${raw}`;
|
|
1506
|
+
if (!isPhoneValid(normalized)) {
|
|
1507
|
+
return `whatsappPhone do ambiente '${ambiente}' \xE9 inv\xE1lido (${JSON.stringify(env.whatsappPhone)}).`;
|
|
1508
|
+
}
|
|
1509
|
+
return null;
|
|
1510
|
+
};
|
|
1511
|
+
const validateChatConfig = () => {
|
|
1512
|
+
if (canal !== "chat") return null;
|
|
1513
|
+
if (!env) return null;
|
|
1514
|
+
const raw = env.chatUrl?.trim() ?? "";
|
|
1515
|
+
if (!raw) {
|
|
1516
|
+
return `canal='chat' exige chatUrl no ambiente '${ambiente}'.`;
|
|
1517
|
+
}
|
|
1518
|
+
try {
|
|
1519
|
+
const parsed = new URL(raw);
|
|
1520
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
1521
|
+
return `chatUrl do ambiente '${ambiente}' precisa ter protocolo http(s) (recebido: ${JSON.stringify(env.chatUrl)}).`;
|
|
1522
|
+
}
|
|
1523
|
+
} catch {
|
|
1524
|
+
return `chatUrl do ambiente '${ambiente}' n\xE3o \xE9 URL absoluta v\xE1lida (recebido: ${JSON.stringify(env.chatUrl)}).`;
|
|
1525
|
+
}
|
|
1526
|
+
return null;
|
|
1527
|
+
};
|
|
1264
1528
|
const productsValidationError = validateProducts();
|
|
1529
|
+
const ambienteConfigError = validateAmbienteConfig();
|
|
1530
|
+
const whatsappConfigError = validateWhatsappConfig();
|
|
1531
|
+
const chatConfigError = validateChatConfig();
|
|
1532
|
+
const effectiveShowPreferenciaContato = canal === "whatsapp" || canal === "chat" ? false : showPreferenciaContato;
|
|
1533
|
+
const effectiveTitle = canal === "whatsapp" ? WHATSAPP_TITLE : canal === "chat" ? CHAT_TITLE : title;
|
|
1534
|
+
const effectiveSubtitle = canal === "whatsapp" ? WHATSAPP_SUBTITLE : canal === "chat" ? CHAT_SUBTITLE : subtitle;
|
|
1265
1535
|
const [utm, setUtm] = useState3({ utm_source: "direto", createdAt: (/* @__PURE__ */ new Date()).toISOString() });
|
|
1266
1536
|
const formSchema = products && products.length > 1 ? schemaWithProduct : schema;
|
|
1267
1537
|
const { control, register, handleSubmit, formState: { errors }, reset, clearErrors } = useForm({
|
|
@@ -1300,9 +1570,13 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1300
1570
|
const phoneValue = phone.inputValue;
|
|
1301
1571
|
const phoneDigitsOnly = phoneValue?.replace(/\D/g, "") || "";
|
|
1302
1572
|
const message = "Gostaria de mais informa\xE7\xF5es sobre o produto";
|
|
1573
|
+
setActionModal(null);
|
|
1303
1574
|
try {
|
|
1304
1575
|
setIsLoading(true);
|
|
1305
|
-
if (!
|
|
1576
|
+
if (!env) {
|
|
1577
|
+
throw new Error("Ambiente n\xE3o resolvido");
|
|
1578
|
+
}
|
|
1579
|
+
if (!products || products.length === 0) {
|
|
1306
1580
|
throw new Error("Par\xE2metros obrigat\xF3rios n\xE3o informados");
|
|
1307
1581
|
}
|
|
1308
1582
|
let selectedProduct;
|
|
@@ -1318,6 +1592,8 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1318
1592
|
}
|
|
1319
1593
|
selectedProduct = foundProduct;
|
|
1320
1594
|
}
|
|
1595
|
+
const paginaAtual = typeof window !== "undefined" ? window.location.href : void 0;
|
|
1596
|
+
const naoCriarEventoEfetivo = canal !== "form" && (naoCriarEvento ?? true);
|
|
1321
1597
|
const requestBody = {
|
|
1322
1598
|
name,
|
|
1323
1599
|
email,
|
|
@@ -1328,13 +1604,23 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1328
1604
|
utm_campaign: utm.utm_campaign,
|
|
1329
1605
|
utm_medium: utm.utm_medium,
|
|
1330
1606
|
utm_term: utm.utm_term,
|
|
1331
|
-
...
|
|
1607
|
+
...canal === "whatsapp" ? { preferencia_contato: "Whatsapp" /* Whatsapp */ } : effectiveShowPreferenciaContato && preferencia_contato ? { preferencia_contato } : {},
|
|
1608
|
+
...canal !== "form" ? {
|
|
1609
|
+
canal,
|
|
1610
|
+
...paginaAtual ? { pagina: paginaAtual } : {},
|
|
1611
|
+
// Paridade com atendimento.html legado: o mesmo <form id="chat-form">
|
|
1612
|
+
// era usado para chat e whatsapp, portanto is_chat=true ia em ambos.
|
|
1613
|
+
is_chat: true,
|
|
1614
|
+
...idProdutoTerceiro !== void 0 ? { idProdutoTerceiro } : {},
|
|
1615
|
+
...idEmpreendimento !== void 0 ? { idEmpreendimento } : {},
|
|
1616
|
+
...naoCriarEventoEfetivo ? { naoCriarEvento: true } : {}
|
|
1617
|
+
} : {}
|
|
1332
1618
|
};
|
|
1333
|
-
const response = await fetch(`${apiUrl}/leads`, {
|
|
1619
|
+
const response = await fetch(`${env.apiUrl}/leads`, {
|
|
1334
1620
|
method: "POST",
|
|
1335
1621
|
headers: {
|
|
1336
1622
|
"Content-Type": "application/json",
|
|
1337
|
-
Authorization: `Basic ${apiToken}`
|
|
1623
|
+
Authorization: `Basic ${env.apiToken}`
|
|
1338
1624
|
},
|
|
1339
1625
|
body: JSON.stringify(requestBody)
|
|
1340
1626
|
});
|
|
@@ -1343,26 +1629,64 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1343
1629
|
}
|
|
1344
1630
|
const responseData = await response.json();
|
|
1345
1631
|
const leadId = responseData.leadId || responseData.id || "";
|
|
1346
|
-
setSuccessMessage("Mensagem enviada com sucesso!");
|
|
1347
1632
|
resetForm();
|
|
1348
1633
|
onSuccess?.(requestBody, leadId);
|
|
1634
|
+
if (canal === "whatsapp") {
|
|
1635
|
+
setActionModal({
|
|
1636
|
+
kind: "success",
|
|
1637
|
+
canal: "whatsapp",
|
|
1638
|
+
targetUrl: buildWhatsappUrl(env.whatsappPhone)
|
|
1639
|
+
});
|
|
1640
|
+
} else if (canal === "chat") {
|
|
1641
|
+
const virtualObj = {
|
|
1642
|
+
...requestBody,
|
|
1643
|
+
externalOriginId: leadId,
|
|
1644
|
+
...paginaAtual ? { pagina: paginaAtual } : {},
|
|
1645
|
+
...idProdutoTerceiro !== void 0 ? { idProdutoTerceiro } : {},
|
|
1646
|
+
...idEmpreendimento !== void 0 ? { idEmpreendimento } : {},
|
|
1647
|
+
...naoCriarEventoEfetivo ? { naoCriarEvento: true } : {}
|
|
1648
|
+
};
|
|
1649
|
+
setActionModal({
|
|
1650
|
+
kind: "success",
|
|
1651
|
+
canal: "chat",
|
|
1652
|
+
chatUrl: env.chatUrl,
|
|
1653
|
+
virtualObj
|
|
1654
|
+
});
|
|
1655
|
+
} else {
|
|
1656
|
+
setSuccessMessage("Mensagem enviada com sucesso!");
|
|
1657
|
+
}
|
|
1349
1658
|
} catch (err) {
|
|
1350
1659
|
const error2 = err instanceof Error ? err : new Error("Erro desconhecido");
|
|
1351
|
-
|
|
1660
|
+
if (canal === "whatsapp" || canal === "chat") {
|
|
1661
|
+
setActionModal({ kind: "error" });
|
|
1662
|
+
} else {
|
|
1663
|
+
handleError(err);
|
|
1664
|
+
}
|
|
1352
1665
|
onError?.(error2);
|
|
1353
1666
|
} finally {
|
|
1354
1667
|
setIsLoading(false);
|
|
1355
1668
|
}
|
|
1356
1669
|
};
|
|
1357
|
-
if (productsValidationError) {
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1670
|
+
if (productsValidationError || ambienteConfigError || whatsappConfigError || chatConfigError) {
|
|
1671
|
+
if (productsValidationError) {
|
|
1672
|
+
console.error("Erro na valida\xE7\xE3o dos produtos:", productsValidationError);
|
|
1673
|
+
}
|
|
1674
|
+
if (ambienteConfigError) {
|
|
1675
|
+
console.error("Erro na valida\xE7\xE3o do ambiente:", ambienteConfigError);
|
|
1676
|
+
}
|
|
1677
|
+
if (whatsappConfigError) {
|
|
1678
|
+
console.error("Erro na valida\xE7\xE3o do canal whatsapp:", whatsappConfigError);
|
|
1679
|
+
}
|
|
1680
|
+
if (chatConfigError) {
|
|
1681
|
+
console.error("Erro na valida\xE7\xE3o do canal chat:", chatConfigError);
|
|
1682
|
+
}
|
|
1683
|
+
return /* @__PURE__ */ jsx7(FormContainer, { $backgroundColor: backgroundColor, $innerPadding: innerPadding, ref, children: /* @__PURE__ */ jsxs7(HeaderContainer, { children: [
|
|
1684
|
+
/* @__PURE__ */ jsx7(Title, { $textColor: textColor, children: "Erro no carregamento do formul\xE1rio!" }),
|
|
1685
|
+
/* @__PURE__ */ jsx7(Subtitle, { $textColor: textColor, children: "N\xE3o foi poss\xEDvel carregar o formul\xE1rio. Tente novamente mais tarde." })
|
|
1362
1686
|
] }) });
|
|
1363
1687
|
}
|
|
1364
|
-
return /* @__PURE__ */
|
|
1365
|
-
error && /* @__PURE__ */
|
|
1688
|
+
return /* @__PURE__ */ jsxs7(Fragment, { children: [
|
|
1689
|
+
error && /* @__PURE__ */ jsx7(
|
|
1366
1690
|
Alert,
|
|
1367
1691
|
{
|
|
1368
1692
|
type: "error",
|
|
@@ -1372,7 +1696,7 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1372
1696
|
children: error.message
|
|
1373
1697
|
}
|
|
1374
1698
|
),
|
|
1375
|
-
successMessage && /* @__PURE__ */
|
|
1699
|
+
successMessage && /* @__PURE__ */ jsx7(
|
|
1376
1700
|
Alert,
|
|
1377
1701
|
{
|
|
1378
1702
|
type: "success",
|
|
@@ -1382,13 +1706,58 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1382
1706
|
children: successMessage
|
|
1383
1707
|
}
|
|
1384
1708
|
),
|
|
1385
|
-
/* @__PURE__ */
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1709
|
+
actionModal?.kind === "error" && /* @__PURE__ */ jsx7(
|
|
1710
|
+
Modal,
|
|
1711
|
+
{
|
|
1712
|
+
type: "error",
|
|
1713
|
+
title: MODAL_ERROR_TITLE,
|
|
1714
|
+
message: MODAL_ERROR_MESSAGE,
|
|
1715
|
+
primaryButtonText: MODAL_ERROR_BUTTON_TEXT,
|
|
1716
|
+
onPrimaryAction: () => setActionModal(null),
|
|
1717
|
+
onClose: () => setActionModal(null),
|
|
1718
|
+
primaryButtonBgColor: buttonBackgroundColor,
|
|
1719
|
+
primaryButtonTextColor: buttonTextColor
|
|
1720
|
+
}
|
|
1721
|
+
),
|
|
1722
|
+
actionModal?.kind === "success" && actionModal.canal === "whatsapp" && /* @__PURE__ */ jsx7(
|
|
1723
|
+
Modal,
|
|
1724
|
+
{
|
|
1725
|
+
type: "success",
|
|
1726
|
+
title: MODAL_SUCCESS_TITLE,
|
|
1727
|
+
message: MODAL_SUCCESS_MESSAGE_WHATSAPP,
|
|
1728
|
+
primaryButtonText: MODAL_SUCCESS_BUTTON_WHATSAPP,
|
|
1729
|
+
onPrimaryAction: () => {
|
|
1730
|
+
window.open(actionModal.targetUrl, "_blank", "noopener,noreferrer");
|
|
1731
|
+
setActionModal(null);
|
|
1732
|
+
},
|
|
1733
|
+
onClose: () => setActionModal(null),
|
|
1734
|
+
primaryButtonBgColor: buttonBackgroundColor,
|
|
1735
|
+
primaryButtonTextColor: buttonTextColor
|
|
1736
|
+
}
|
|
1737
|
+
),
|
|
1738
|
+
actionModal?.kind === "success" && actionModal.canal === "chat" && /* @__PURE__ */ jsx7(
|
|
1739
|
+
Modal,
|
|
1740
|
+
{
|
|
1741
|
+
type: "success",
|
|
1742
|
+
title: MODAL_SUCCESS_TITLE,
|
|
1743
|
+
message: MODAL_SUCCESS_MESSAGE_CHAT,
|
|
1744
|
+
primaryButtonText: MODAL_SUCCESS_BUTTON_CHAT,
|
|
1745
|
+
onPrimaryAction: () => {
|
|
1746
|
+
submitChatInNewTab(actionModal.chatUrl, actionModal.virtualObj);
|
|
1747
|
+
setActionModal(null);
|
|
1748
|
+
},
|
|
1749
|
+
onClose: () => setActionModal(null),
|
|
1750
|
+
primaryButtonBgColor: buttonBackgroundColor,
|
|
1751
|
+
primaryButtonTextColor: buttonTextColor
|
|
1752
|
+
}
|
|
1753
|
+
),
|
|
1754
|
+
/* @__PURE__ */ jsxs7(FormContainer, { $backgroundColor: backgroundColor, $innerPadding: innerPadding, ref, children: [
|
|
1755
|
+
showHeader && /* @__PURE__ */ jsxs7(HeaderContainer, { children: [
|
|
1756
|
+
/* @__PURE__ */ jsx7(Title, { $textColor: textColor, children: effectiveTitle }),
|
|
1757
|
+
/* @__PURE__ */ jsx7(Subtitle, { $textColor: textColor, children: effectiveSubtitle })
|
|
1389
1758
|
] }),
|
|
1390
|
-
/* @__PURE__ */
|
|
1391
|
-
products.length > 1 && /* @__PURE__ */
|
|
1759
|
+
/* @__PURE__ */ jsxs7(Form, { $textColor: textColor, onSubmit: handleSubmit(sendMessage), noValidate: true, children: [
|
|
1760
|
+
products.length > 1 && /* @__PURE__ */ jsx7(
|
|
1392
1761
|
ProductSelect,
|
|
1393
1762
|
{
|
|
1394
1763
|
id: "productId",
|
|
@@ -1405,7 +1774,7 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1405
1774
|
textColor: inputTextColor
|
|
1406
1775
|
}
|
|
1407
1776
|
),
|
|
1408
|
-
/* @__PURE__ */
|
|
1777
|
+
/* @__PURE__ */ jsx7(
|
|
1409
1778
|
Input2,
|
|
1410
1779
|
{
|
|
1411
1780
|
id: "name",
|
|
@@ -1423,7 +1792,7 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1423
1792
|
inputTextColor
|
|
1424
1793
|
}
|
|
1425
1794
|
),
|
|
1426
|
-
/* @__PURE__ */
|
|
1795
|
+
/* @__PURE__ */ jsx7(
|
|
1427
1796
|
Input2,
|
|
1428
1797
|
{
|
|
1429
1798
|
id: "email",
|
|
@@ -1442,7 +1811,7 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1442
1811
|
inputTextColor
|
|
1443
1812
|
}
|
|
1444
1813
|
),
|
|
1445
|
-
/* @__PURE__ */
|
|
1814
|
+
/* @__PURE__ */ jsx7(
|
|
1446
1815
|
Controller,
|
|
1447
1816
|
{
|
|
1448
1817
|
name: "phone",
|
|
@@ -1451,7 +1820,7 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1451
1820
|
shouldUnregister: true,
|
|
1452
1821
|
render: ({ field }) => {
|
|
1453
1822
|
const errorMsg = errors.phone?.inputValue?.message || errors.phone?.phone?.message || errors.phone?.message;
|
|
1454
|
-
return /* @__PURE__ */
|
|
1823
|
+
return /* @__PURE__ */ jsx7(
|
|
1455
1824
|
PhoneInput2,
|
|
1456
1825
|
{
|
|
1457
1826
|
id: "phone",
|
|
@@ -1474,9 +1843,9 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1474
1843
|
},
|
|
1475
1844
|
formKey
|
|
1476
1845
|
),
|
|
1477
|
-
|
|
1478
|
-
/* @__PURE__ */
|
|
1479
|
-
/* @__PURE__ */
|
|
1846
|
+
effectiveShowPreferenciaContato && /* @__PURE__ */ jsxs7(FormControl, { isInvalid: !!errors.preferencia_contato, children: [
|
|
1847
|
+
/* @__PURE__ */ jsx7(FormLabel, { htmlFor: "preferencia_contato", $textColor: textColor, children: "Prefer\xEAncia de Contato" }),
|
|
1848
|
+
/* @__PURE__ */ jsxs7(
|
|
1480
1849
|
Select,
|
|
1481
1850
|
{
|
|
1482
1851
|
id: "preferencia_contato",
|
|
@@ -1487,19 +1856,19 @@ var MitreFormComponent = React2.forwardRef(({
|
|
|
1487
1856
|
$focusBorderColor: inputFocusBorderColor,
|
|
1488
1857
|
$textColor: inputTextColor,
|
|
1489
1858
|
children: [
|
|
1490
|
-
/* @__PURE__ */
|
|
1491
|
-
Object.values(PreferenciaContato).map((op) => /* @__PURE__ */
|
|
1859
|
+
/* @__PURE__ */ jsx7("option", { value: "", disabled: true, children: "Selecione uma op\xE7\xE3o" }),
|
|
1860
|
+
Object.values(PreferenciaContato).map((op) => /* @__PURE__ */ jsx7("option", { value: op, children: op }, op))
|
|
1492
1861
|
]
|
|
1493
1862
|
}
|
|
1494
1863
|
),
|
|
1495
|
-
errors.preferencia_contato && /* @__PURE__ */
|
|
1864
|
+
errors.preferencia_contato && /* @__PURE__ */ jsx7(FormErrorMessage, { children: errors.preferencia_contato.message })
|
|
1496
1865
|
] }),
|
|
1497
|
-
/* @__PURE__ */
|
|
1498
|
-
/* @__PURE__ */
|
|
1499
|
-
/* @__PURE__ */
|
|
1866
|
+
/* @__PURE__ */ jsx7("h6", { children: "* Campos de preenchimento obrigat\xF3rio." }),
|
|
1867
|
+
/* @__PURE__ */ jsx7(ButtonContainer, { children: /* @__PURE__ */ jsx7(Button2, { bgColor: buttonBackgroundColor, color: buttonTextColor, type: "submit", isSubmitting: loading, children: canal === "whatsapp" ? WHATSAPP_BUTTON_TEXT : canal === "chat" ? CHAT_BUTTON_TEXT : "Enviar mensagem" }) }),
|
|
1868
|
+
/* @__PURE__ */ jsxs7("p", { children: [
|
|
1500
1869
|
"A Mitre Realty respeita a sua privacidade e utiliza os seus dados pessoais para contat\xE1-lo por e-mail ou telefone aqui registrados. Para saber mais, acesse a nossa",
|
|
1501
1870
|
" ",
|
|
1502
|
-
/* @__PURE__ */
|
|
1871
|
+
/* @__PURE__ */ jsx7(
|
|
1503
1872
|
"a",
|
|
1504
1873
|
{
|
|
1505
1874
|
href: "https://www.mitrerealty.com.br/politica-de-privacidade",
|