@greatapps/common 1.1.339 → 1.1.342
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/components/account/hooks/useChangePhoneForm.mjs +20 -3
- package/dist/components/account/hooks/useChangePhoneForm.mjs.map +1 -1
- package/dist/components/account/sections/ChangePhoneModal.mjs +16 -8
- package/dist/components/account/sections/ChangePhoneModal.mjs.map +1 -1
- package/dist/components/layouts/ProfilePopover.mjs +9 -23
- package/dist/components/layouts/ProfilePopover.mjs.map +1 -1
- package/dist/components/ui/form/PhoneInput.mjs +2 -0
- package/dist/components/ui/form/PhoneInput.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/account/hooks/useChangePhoneForm.tsx +29 -3
- package/src/components/account/sections/ChangePhoneModal.tsx +22 -8
- package/src/components/layouts/ProfilePopover.tsx +0 -8
- package/src/components/ui/form/PhoneInput.tsx +3 -0
|
@@ -3,14 +3,14 @@ import { jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { useState, useCallback } from "react";
|
|
4
4
|
import { toast } from "sonner";
|
|
5
5
|
import { Toast } from "../../ui/feedback/Toast";
|
|
6
|
-
import { requestPhoneChangeAction } from "../../../modules/accounts/actions/account-management.action";
|
|
6
|
+
import { requestPhoneChangeAction, updateUserAction } from "../../../modules/accounts/actions/account-management.action";
|
|
7
7
|
function splitPhoneValue(fullValue) {
|
|
8
8
|
const trimmed = fullValue.trim();
|
|
9
9
|
const spaceIdx = trimmed.indexOf(" ");
|
|
10
10
|
if (spaceIdx === -1) return { ddi: "+55", local: trimmed };
|
|
11
11
|
return { ddi: trimmed.slice(0, spaceIdx), local: trimmed.slice(spaceIdx + 1) };
|
|
12
12
|
}
|
|
13
|
-
function useChangePhoneForm() {
|
|
13
|
+
function useChangePhoneForm({ hasExistingPhone, onDirectUpdateSuccess }) {
|
|
14
14
|
const [showVerification, setShowVerification] = useState(false);
|
|
15
15
|
const [phoneValue, setPhoneValue] = useState("");
|
|
16
16
|
const [phoneError, setPhoneError] = useState("");
|
|
@@ -29,6 +29,23 @@ function useChangePhoneForm() {
|
|
|
29
29
|
}
|
|
30
30
|
setIsSubmitting(true);
|
|
31
31
|
try {
|
|
32
|
+
if (!hasExistingPhone) {
|
|
33
|
+
const result2 = await updateUserAction({ phone: local, ddi });
|
|
34
|
+
if (!result2.success) {
|
|
35
|
+
toast.custom((t) => /* @__PURE__ */ jsx(
|
|
36
|
+
Toast,
|
|
37
|
+
{
|
|
38
|
+
variant: "error",
|
|
39
|
+
message: result2.error ?? "Ocorreu um erro ao salvar o telefone. Tente novamente mais tarde.",
|
|
40
|
+
toastId: t
|
|
41
|
+
}
|
|
42
|
+
));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
toast.custom((t) => /* @__PURE__ */ jsx(Toast, { variant: "success", message: "Telefone adicionado", toastId: t }));
|
|
46
|
+
onDirectUpdateSuccess?.();
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
32
49
|
const result = await requestPhoneChangeAction(local, ddi);
|
|
33
50
|
if (!result.success) {
|
|
34
51
|
toast.custom((t) => /* @__PURE__ */ jsx(
|
|
@@ -46,7 +63,7 @@ function useChangePhoneForm() {
|
|
|
46
63
|
} finally {
|
|
47
64
|
setIsSubmitting(false);
|
|
48
65
|
}
|
|
49
|
-
}, [phoneValue]);
|
|
66
|
+
}, [phoneValue, hasExistingPhone, onDirectUpdateSuccess]);
|
|
50
67
|
const handleBack = useCallback(() => {
|
|
51
68
|
setShowVerification(false);
|
|
52
69
|
}, []);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/account/hooks/useChangePhoneForm.tsx"],"sourcesContent":["'use client';\n\nimport { useState, useCallback } from 'react';\nimport { toast } from 'sonner';\nimport { Toast } from '../../ui/feedback/Toast';\nimport { requestPhoneChangeAction } from '../../../modules/accounts/actions/account-management.action';\n\nfunction splitPhoneValue(fullValue: string): { ddi: string; local: string } {\n const trimmed = fullValue.trim();\n const spaceIdx = trimmed.indexOf(' ');\n if (spaceIdx === -1) return { ddi: '+55', local: trimmed };\n return { ddi: trimmed.slice(0, spaceIdx), local: trimmed.slice(spaceIdx + 1) };\n}\n\nexport default function useChangePhoneForm() {\n const [showVerification, setShowVerification] = useState(false);\n const [phoneValue, setPhoneValue] = useState('');\n const [phoneError, setPhoneError] = useState('');\n const [isSubmitting, setIsSubmitting] = useState(false);\n const [submittedPhone, setSubmittedPhone] = useState({ ddi: '+55', local: '' });\n\n const handlePhoneChange = useCallback((value: string) => {\n setPhoneValue(value);\n if (phoneError) setPhoneError('');\n }, [phoneError]);\n\n const handleContinue = useCallback(async (e: React.FormEvent) => {\n e.preventDefault();\n\n const { ddi, local } = splitPhoneValue(phoneValue);\n\n if (!local || local.replace(/\\D/g, '').length < 8) {\n setPhoneError('Número de telefone inválido');\n return;\n }\n\n setIsSubmitting(true);\n try {\n const result = await requestPhoneChangeAction(local, ddi);\n\n if (!result.success) {\n toast.custom((t) => (\n <Toast\n variant=\"error\"\n message={result.error ?? 'Número já existente ou ocorreu um erro. Tente novamente mais tarde.'}\n toastId={t}\n />\n ));\n return;\n }\n\n setSubmittedPhone({ ddi, local });\n setShowVerification(true);\n } finally {\n setIsSubmitting(false);\n }\n }, [phoneValue]);\n\n const handleBack = useCallback(() => {\n setShowVerification(false);\n }, []);\n\n const resetForm = useCallback(() => {\n setPhoneValue('');\n setPhoneError('');\n setSubmittedPhone({ ddi: '+55', local: '' });\n setShowVerification(false);\n }, []);\n\n return {\n showVerification,\n phoneValue,\n phoneError,\n isSubmitting,\n submittedPhone,\n handlePhoneChange,\n handleContinue,\n handleBack,\n resetForm,\n };\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/account/hooks/useChangePhoneForm.tsx"],"sourcesContent":["'use client';\n\nimport { useState, useCallback } from 'react';\nimport { toast } from 'sonner';\nimport { Toast } from '../../ui/feedback/Toast';\nimport { requestPhoneChangeAction, updateUserAction } from '../../../modules/accounts/actions/account-management.action';\n\nfunction splitPhoneValue(fullValue: string): { ddi: string; local: string } {\n const trimmed = fullValue.trim();\n const spaceIdx = trimmed.indexOf(' ');\n if (spaceIdx === -1) return { ddi: '+55', local: trimmed };\n return { ddi: trimmed.slice(0, spaceIdx), local: trimmed.slice(spaceIdx + 1) };\n}\n\ninterface UseChangePhoneFormOptions {\n hasExistingPhone: boolean;\n onDirectUpdateSuccess?: () => void;\n}\n\nexport default function useChangePhoneForm({ hasExistingPhone, onDirectUpdateSuccess }: UseChangePhoneFormOptions) {\n const [showVerification, setShowVerification] = useState(false);\n const [phoneValue, setPhoneValue] = useState('');\n const [phoneError, setPhoneError] = useState('');\n const [isSubmitting, setIsSubmitting] = useState(false);\n const [submittedPhone, setSubmittedPhone] = useState({ ddi: '+55', local: '' });\n\n const handlePhoneChange = useCallback((value: string) => {\n setPhoneValue(value);\n if (phoneError) setPhoneError('');\n }, [phoneError]);\n\n const handleContinue = useCallback(async (e: React.FormEvent) => {\n e.preventDefault();\n\n const { ddi, local } = splitPhoneValue(phoneValue);\n\n if (!local || local.replace(/\\D/g, '').length < 8) {\n setPhoneError('Número de telefone inválido');\n return;\n }\n\n setIsSubmitting(true);\n try {\n if (!hasExistingPhone) {\n const result = await updateUserAction({ phone: local, ddi });\n\n if (!result.success) {\n toast.custom((t) => (\n <Toast\n variant=\"error\"\n message={result.error ?? 'Ocorreu um erro ao salvar o telefone. Tente novamente mais tarde.'}\n toastId={t}\n />\n ));\n return;\n }\n\n toast.custom((t) => (\n <Toast variant=\"success\" message=\"Telefone adicionado\" toastId={t} />\n ));\n onDirectUpdateSuccess?.();\n return;\n }\n\n const result = await requestPhoneChangeAction(local, ddi);\n\n if (!result.success) {\n toast.custom((t) => (\n <Toast\n variant=\"error\"\n message={result.error ?? 'Número já existente ou ocorreu um erro. Tente novamente mais tarde.'}\n toastId={t}\n />\n ));\n return;\n }\n\n setSubmittedPhone({ ddi, local });\n setShowVerification(true);\n } finally {\n setIsSubmitting(false);\n }\n }, [phoneValue, hasExistingPhone, onDirectUpdateSuccess]);\n\n const handleBack = useCallback(() => {\n setShowVerification(false);\n }, []);\n\n const resetForm = useCallback(() => {\n setPhoneValue('');\n setPhoneError('');\n setSubmittedPhone({ ddi: '+55', local: '' });\n setShowVerification(false);\n }, []);\n\n return {\n showVerification,\n phoneValue,\n phoneError,\n isSubmitting,\n submittedPhone,\n handlePhoneChange,\n handleContinue,\n handleBack,\n resetForm,\n };\n}\n"],"mappings":";AAgDY;AA9CZ,SAAS,UAAU,mBAAmB;AACtC,SAAS,aAAa;AACtB,SAAS,aAAa;AACtB,SAAS,0BAA0B,wBAAwB;AAE3D,SAAS,gBAAgB,WAAmD;AAC1E,QAAM,UAAU,UAAU,KAAK;AAC/B,QAAM,WAAW,QAAQ,QAAQ,GAAG;AACpC,MAAI,aAAa,GAAI,QAAO,EAAE,KAAK,OAAO,OAAO,QAAQ;AACzD,SAAO,EAAE,KAAK,QAAQ,MAAM,GAAG,QAAQ,GAAG,OAAO,QAAQ,MAAM,WAAW,CAAC,EAAE;AAC/E;AAOe,SAAR,mBAAoC,EAAE,kBAAkB,sBAAsB,GAA8B;AACjH,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAAS,KAAK;AAC9D,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,EAAE;AAC/C,QAAM,CAAC,YAAY,aAAa,IAAI,SAAS,EAAE;AAC/C,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,KAAK;AACtD,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAS,EAAE,KAAK,OAAO,OAAO,GAAG,CAAC;AAE9E,QAAM,oBAAoB,YAAY,CAAC,UAAkB;AACvD,kBAAc,KAAK;AACnB,QAAI,WAAY,eAAc,EAAE;AAAA,EAClC,GAAG,CAAC,UAAU,CAAC;AAEf,QAAM,iBAAiB,YAAY,OAAO,MAAuB;AAC/D,MAAE,eAAe;AAEjB,UAAM,EAAE,KAAK,MAAM,IAAI,gBAAgB,UAAU;AAEjD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;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["result"]}
|
|
@@ -16,9 +16,14 @@ import useOtpVerification from "../hooks/useOtpVerification";
|
|
|
16
16
|
function ChangePhoneModal({ open, onClose }) {
|
|
17
17
|
const { user } = useAuth();
|
|
18
18
|
const invalidateUser = useInvalidateUser();
|
|
19
|
+
const hasExistingPhone = !!user?.phone;
|
|
19
20
|
const currentPhoneDisplay = user?.phone ? formatPhone(
|
|
20
21
|
user.ddi && user.phone.startsWith(user.ddi) ? user.phone.slice(user.ddi.length) : user.phone
|
|
21
22
|
) : "";
|
|
23
|
+
const handleDirectUpdateSuccess = () => {
|
|
24
|
+
invalidateUser();
|
|
25
|
+
onClose();
|
|
26
|
+
};
|
|
22
27
|
const {
|
|
23
28
|
showVerification,
|
|
24
29
|
phoneValue,
|
|
@@ -29,7 +34,10 @@ function ChangePhoneModal({ open, onClose }) {
|
|
|
29
34
|
handleContinue,
|
|
30
35
|
handleBack,
|
|
31
36
|
resetForm
|
|
32
|
-
} = useChangePhoneForm(
|
|
37
|
+
} = useChangePhoneForm({
|
|
38
|
+
hasExistingPhone,
|
|
39
|
+
onDirectUpdateSuccess: handleDirectUpdateSuccess
|
|
40
|
+
});
|
|
33
41
|
const handleSuccess = () => {
|
|
34
42
|
invalidateUser();
|
|
35
43
|
resetForm();
|
|
@@ -82,9 +90,9 @@ function ChangePhoneModal({ open, onClose }) {
|
|
|
82
90
|
/* @__PURE__ */ jsx(DialogTitle, { className: "paragraph-medium-semibold text-gray-950 text-center flex-1", children: "Alterar telefone" }),
|
|
83
91
|
/* @__PURE__ */ jsx(Button, { variant: "ghost", className: "size-8! p-0", onClick: handleClose, children: /* @__PURE__ */ jsx(IconX, { size: 18, className: "text-gray-500" }) })
|
|
84
92
|
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
85
|
-
/* @__PURE__ */ jsx(DialogHeader, { className: "sr-only", children: /* @__PURE__ */ jsx(DialogTitle, { children: "Alterar telefone" }) }),
|
|
93
|
+
/* @__PURE__ */ jsx(DialogHeader, { className: "sr-only", children: /* @__PURE__ */ jsx(DialogTitle, { children: hasExistingPhone ? "Alterar telefone" : "Adicionar telefone" }) }),
|
|
86
94
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-center px-4 py-3 relative border-b border-gray-200 lg:border-b-0", children: [
|
|
87
|
-
/* @__PURE__ */ jsx("span", { className: "paragraph-medium-semibold text-gray-950 text-center", children: "Alterar telefone" }),
|
|
95
|
+
/* @__PURE__ */ jsx("span", { className: "paragraph-medium-semibold text-gray-950 text-center", children: hasExistingPhone ? "Alterar telefone" : "Adicionar telefone" }),
|
|
88
96
|
/* @__PURE__ */ jsx(
|
|
89
97
|
Button,
|
|
90
98
|
{
|
|
@@ -96,7 +104,7 @@ function ChangePhoneModal({ open, onClose }) {
|
|
|
96
104
|
)
|
|
97
105
|
] })
|
|
98
106
|
] }),
|
|
99
|
-
/* @__PURE__ */ jsx("div", { className: `${showVerification ? "w-full" : "w-1/2"} h-0.75 bg-pages-300` }),
|
|
107
|
+
/* @__PURE__ */ jsx("div", { className: `${showVerification || !hasExistingPhone ? "w-full" : "w-1/2"} h-0.75 bg-pages-300` }),
|
|
100
108
|
showVerification ? /* @__PURE__ */ jsxs(
|
|
101
109
|
"form",
|
|
102
110
|
{
|
|
@@ -154,13 +162,13 @@ function ChangePhoneModal({ open, onClose }) {
|
|
|
154
162
|
) : /* @__PURE__ */ jsxs("form", { onSubmit: handleContinue, className: "flex flex-col flex-1 lg:flex-none", children: [
|
|
155
163
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-5 lg:gap-6 px-4 lg:px-5 py-5 lg:py-6 flex-1 lg:flex-none", children: [
|
|
156
164
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
|
|
157
|
-
/* @__PURE__ */ jsx("span", { className: "paragraph-medium-semibold text-gray-950", children: "Atualizar telefone de contato" }),
|
|
158
|
-
/* @__PURE__ */ jsx("span", { className: "paragraph-small-regular text-gray-600", children: "Informe o novo n\xFAmero para manter seu contato atualizado." })
|
|
165
|
+
/* @__PURE__ */ jsx("span", { className: "paragraph-medium-semibold text-gray-950", children: hasExistingPhone ? "Atualizar telefone de contato" : "Adicionar telefone de contato" }),
|
|
166
|
+
/* @__PURE__ */ jsx("span", { className: "paragraph-small-regular text-gray-600", children: hasExistingPhone ? "Informe o novo n\xFAmero para manter seu contato atualizado." : "Informe seu n\xFAmero de telefone para contato." })
|
|
159
167
|
] }),
|
|
160
168
|
/* @__PURE__ */ jsx(
|
|
161
169
|
PhoneInput,
|
|
162
170
|
{
|
|
163
|
-
label: "Novo n\xFAmero",
|
|
171
|
+
label: hasExistingPhone ? "Novo n\xFAmero" : "N\xFAmero de telefone",
|
|
164
172
|
placeholder: "(00) 0 0000-0000",
|
|
165
173
|
value: phoneValue,
|
|
166
174
|
onChange: handlePhoneChange,
|
|
@@ -171,7 +179,7 @@ function ChangePhoneModal({ open, onClose }) {
|
|
|
171
179
|
] }),
|
|
172
180
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between p-4 lg:p-5 border-t border-gray-200 mt-auto lg:mt-0", children: [
|
|
173
181
|
/* @__PURE__ */ jsx(Button, { variant: "secondary", className: "h-10!", type: "button", onClick: handleClose, children: "Cancelar" }),
|
|
174
|
-
/* @__PURE__ */ jsx(Button, { className: "h-10!", type: "submit", disabled: isSubmitting, children: isSubmitting ? "Enviando..." : "Continuar" })
|
|
182
|
+
/* @__PURE__ */ jsx(Button, { className: "h-10!", type: "submit", disabled: isSubmitting, children: isSubmitting ? hasExistingPhone ? "Enviando..." : "Salvando..." : hasExistingPhone ? "Continuar" : "Salvar" })
|
|
175
183
|
] })
|
|
176
184
|
] })
|
|
177
185
|
]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/account/sections/ChangePhoneModal.tsx"],"sourcesContent":["'use client';\n\nimport { IconChevronLeft, IconX, IconMessage } from '@tabler/icons-react';\nimport { Button } from '../../ui/buttons/Button';\nimport { Dialog, DialogContent, DialogHeader, DialogTitle } from '../../ui/overlay/Dialog';\nimport { Separator } from '../../ui/data-display/Separator';\nimport { InputOTP, InputOTPGroup, InputOTPSlot } from '../../ui/form/InputOtp';\nimport PhoneInput from '../../ui/form/PhoneInput';\nimport { formatTimer, formatPhone } from '../../../utils/format/masks';\nimport { OTP_CODE_LENGTH } from '../../../utils/validators/account';\nimport { useAuth } from '../../../providers/auth.provider';\nimport { useInvalidateUser } from '../../../modules/auth/hooks/useUserQuery';\nimport { confirmPhoneChangeAction } from '../../../modules/accounts/actions/account-management.action';\nimport useChangePhoneForm from '../hooks/useChangePhoneForm';\nimport useOtpVerification from '../hooks/useOtpVerification';\n\ninterface ChangePhoneModalProps {\n open: boolean;\n onClose: () => void;\n}\n\nexport function ChangePhoneModal({ open, onClose }: ChangePhoneModalProps) {\n const { user } = useAuth();\n const invalidateUser = useInvalidateUser();\n\n const currentPhoneDisplay = user?.phone\n ? formatPhone(\n user.ddi && user.phone.startsWith(user.ddi) ? user.phone.slice(user.ddi.length) : user.phone\n )\n : '';\n\n const {\n showVerification,\n phoneValue,\n phoneError,\n isSubmitting,\n submittedPhone,\n handlePhoneChange,\n handleContinue,\n handleBack,\n resetForm,\n } = useChangePhoneForm();\n\n const handleSuccess = () => {\n invalidateUser();\n resetForm();\n onClose();\n };\n\n const {\n code,\n isLoading,\n hasError,\n timer,\n canResend,\n isValidLength,\n handleCodeChange,\n handleValidate,\n handleResend,\n reset: resetOtp,\n } = useOtpVerification({\n onSuccess: handleSuccess,\n successMessage: 'Telefone alterado',\n validateFn: async (token) => {\n const result = await confirmPhoneChangeAction(token, submittedPhone.local, submittedPhone.ddi);\n return result.success;\n },\n resendFn: async () => {\n const { requestPhoneChangeAction } = await import('../../../modules/accounts/actions/account-management.action');\n const result = await requestPhoneChangeAction(submittedPhone.local, submittedPhone.ddi);\n if (!result.success) {\n throw new Error(result.error);\n }\n },\n });\n\n const handleClose = () => {\n resetForm();\n resetOtp();\n onClose();\n };\n\n const handleBackFromVerification = () => {\n resetOtp();\n handleBack();\n };\n\n return (\n <Dialog open={open} onOpenChange={handleClose}>\n <DialogContent\n showCloseButton={false}\n overlayClassName=\"z-[1002]\"\n className=\"flex flex-col p-0 gap-0 max-w-full sm:max-w-full border-0 rounded-t-2xl rounded-b-none h-dvh top-0 bottom-0 left-0 right-0 translate-x-0 translate-y-0 lg:max-w-125 lg:h-auto lg:rounded-lg lg:border lg:top-[50%] lg:left-[50%] lg:right-auto lg:bottom-auto lg:translate-x-[-50%] lg:translate-y-[-50%] z-[1003]\"\n >\n {showVerification ? (\n <DialogHeader className=\"flex flex-row items-center justify-between px-4 py-3 border-b border-gray-200 lg:border-b-0\">\n <Button variant=\"ghost\" className=\"size-8! p-0\" onClick={handleBackFromVerification}>\n <IconChevronLeft size={20} className=\"text-gray-950\" />\n </Button>\n <DialogTitle className=\"paragraph-medium-semibold text-gray-950 text-center flex-1\">\n Alterar telefone\n </DialogTitle>\n <Button variant=\"ghost\" className=\"size-8! p-0\" onClick={handleClose}>\n <IconX size={18} className=\"text-gray-500\" />\n </Button>\n </DialogHeader>\n ) : (\n <>\n <DialogHeader className=\"sr-only\">\n <DialogTitle>Alterar telefone</DialogTitle>\n </DialogHeader>\n <div className=\"flex items-center justify-center px-4 py-3 relative border-b border-gray-200 lg:border-b-0\">\n <span className=\"paragraph-medium-semibold text-gray-950 text-center\">\n Alterar telefone\n </span>\n <Button\n variant=\"ghost\"\n className=\"absolute right-2 size-8! p-0\"\n onClick={handleClose}\n >\n <IconX size={18} className=\"text-gray-500\" />\n </Button>\n </div>\n </>\n )}\n\n <div className={`${showVerification ? 'w-full' : 'w-1/2'} h-0.75 bg-pages-300`} />\n\n {showVerification ? (\n <form\n onSubmit={(e) => {\n e.preventDefault();\n handleValidate();\n }}\n className=\"flex flex-col flex-1 lg:flex-none\"\n >\n <div className=\"px-4 lg:px-5 py-5 lg:py-6 flex flex-col gap-4 flex-1 lg:flex-none\">\n <div className=\"flex items-center justify-center size-12 bg-white rounded-lg shadow-xs border border-gray-200\">\n <IconMessage size={20} className=\"text-gray-950\" />\n </div>\n\n <div className=\"flex flex-col gap-1\">\n <h3 className=\"paragraph-medium-semibold text-gray-950\">Código de validação</h3>\n <p className=\"paragraph-small-regular text-gray-600\">\n Enviamos um código de validação para o número atual{' '}\n <span className=\"font-semibold text-gray-950\">{currentPhoneDisplay}.</span>\n </p>\n </div>\n\n <div className=\"flex flex-col gap-2\">\n <InputOTP maxLength={OTP_CODE_LENGTH} value={code} onChange={handleCodeChange}>\n <InputOTPGroup className=\"flex flex-row gap-2\">\n {[...Array(OTP_CODE_LENGTH)].map((_, i) => (\n <InputOTPSlot\n key={i}\n index={i}\n className={`uppercase text-2xl font-medium w-11 lg:w-12 h-13 lg:h-14 rounded-lg border bg-white shadow-none [&_div.animate-caret-blink]:bg-gray-950 ${hasError ? 'border-red-500' : 'border-gray-200'}`}\n />\n ))}\n </InputOTPGroup>\n </InputOTP>\n {hasError && (\n <p className=\"paragraph-small-regular text-red-500\">Código incorreto</p>\n )}\n </div>\n\n {canResend ? (\n <button\n type=\"button\"\n onClick={handleResend}\n className=\"paragraph-small-medium text-gray-950 underline cursor-pointer hover:text-gray-700 w-fit\"\n >\n Reenviar código\n </button>\n ) : (\n <p className=\"paragraph-small-regular text-gray-500\">\n Reenviar em{' '}\n <span className=\"paragraph-small-semibold text-gray-950\">\n {formatTimer(timer)}\n </span>\n </p>\n )}\n </div>\n\n <Separator />\n\n <div className=\"flex items-center justify-between px-4 lg:px-5 py-4 lg:py-5 mt-auto lg:mt-0\">\n <Button variant=\"secondary\" className=\"h-10!\" type=\"button\" onClick={handleClose}>\n Cancelar\n </Button>\n <Button className=\"h-10!\" type=\"submit\" disabled={!isValidLength || isLoading}>\n {isLoading ? 'Validando...' : 'Alterar telefone'}\n </Button>\n </div>\n </form>\n ) : (\n <form onSubmit={handleContinue} className=\"flex flex-col flex-1 lg:flex-none\">\n <div className=\"flex flex-col gap-5 lg:gap-6 px-4 lg:px-5 py-5 lg:py-6 flex-1 lg:flex-none\">\n <div className=\"flex flex-col gap-1\">\n <span className=\"paragraph-medium-semibold text-gray-950\">\n Atualizar telefone de contato\n </span>\n <span className=\"paragraph-small-regular text-gray-600\">\n Informe o novo número para manter seu contato atualizado.\n </span>\n </div>\n\n <PhoneInput\n label=\"Novo número\"\n placeholder=\"(00) 0 0000-0000\"\n value={phoneValue}\n onChange={handlePhoneChange}\n error={!!phoneError}\n errorMessage={phoneError}\n />\n </div>\n\n <div className=\"flex items-center justify-between p-4 lg:p-5 border-t border-gray-200 mt-auto lg:mt-0\">\n <Button variant=\"secondary\" className=\"h-10!\" type=\"button\" onClick={handleClose}>\n Cancelar\n </Button>\n <Button className=\"h-10!\" type=\"submit\" disabled={isSubmitting}>\n {isSubmitting ? 'Enviando...' : 'Continuar'}\n </Button>\n </div>\n </form>\n )}\n </DialogContent>\n </Dialog>\n );\n}\n"],"mappings":";AA+FU,SAYA,UAVI,KAFJ;AA7FV,SAAS,iBAAiB,OAAO,mBAAmB;AACpD,SAAS,cAAc;AACvB,SAAS,QAAQ,eAAe,cAAc,mBAAmB;AACjE,SAAS,iBAAiB;AAC1B,SAAS,UAAU,eAAe,oBAAoB;AACtD,OAAO,gBAAgB;AACvB,SAAS,aAAa,mBAAmB;AACzC,SAAS,uBAAuB;AAChC,SAAS,eAAe;AACxB,SAAS,yBAAyB;AAClC,SAAS,gCAAgC;AACzC,OAAO,wBAAwB;AAC/B,OAAO,wBAAwB;AAOxB,SAAS,iBAAiB,EAAE,MAAM,QAAQ,GAA0B;AACzE,QAAM,EAAE,KAAK,IAAI,QAAQ;AACzB,QAAM,iBAAiB,kBAAkB;AAEzC,QAAM,sBAAsB,MAAM,QAC9B;AAAA,IACE,KAAK,OAAO,KAAK,MAAM,WAAW,KAAK,GAAG,IAAI,KAAK,MAAM,MAAM,KAAK,IAAI,MAAM,IAAI,KAAK;AAAA,EACzF,IAC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S,UAAU,cAC/C,yBAAe,gBAAgB,aAClC;AAAA,aACF;AAAA,WACF;AAAA;AAAA;AAAA,EAEJ,GACF;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/components/account/sections/ChangePhoneModal.tsx"],"sourcesContent":["'use client';\n\nimport { IconChevronLeft, IconX, IconMessage } from '@tabler/icons-react';\nimport { Button } from '../../ui/buttons/Button';\nimport { Dialog, DialogContent, DialogHeader, DialogTitle } from '../../ui/overlay/Dialog';\nimport { Separator } from '../../ui/data-display/Separator';\nimport { InputOTP, InputOTPGroup, InputOTPSlot } from '../../ui/form/InputOtp';\nimport PhoneInput from '../../ui/form/PhoneInput';\nimport { formatTimer, formatPhone } from '../../../utils/format/masks';\nimport { OTP_CODE_LENGTH } from '../../../utils/validators/account';\nimport { useAuth } from '../../../providers/auth.provider';\nimport { useInvalidateUser } from '../../../modules/auth/hooks/useUserQuery';\nimport { confirmPhoneChangeAction } from '../../../modules/accounts/actions/account-management.action';\nimport useChangePhoneForm from '../hooks/useChangePhoneForm';\nimport useOtpVerification from '../hooks/useOtpVerification';\n\ninterface ChangePhoneModalProps {\n open: boolean;\n onClose: () => void;\n}\n\nexport function ChangePhoneModal({ open, onClose }: ChangePhoneModalProps) {\n const { user } = useAuth();\n const invalidateUser = useInvalidateUser();\n\n const hasExistingPhone = !!user?.phone;\n\n const currentPhoneDisplay = user?.phone\n ? formatPhone(\n user.ddi && user.phone.startsWith(user.ddi) ? user.phone.slice(user.ddi.length) : user.phone\n )\n : '';\n\n const handleDirectUpdateSuccess = () => {\n invalidateUser();\n onClose();\n };\n\n const {\n showVerification,\n phoneValue,\n phoneError,\n isSubmitting,\n submittedPhone,\n handlePhoneChange,\n handleContinue,\n handleBack,\n resetForm,\n } = useChangePhoneForm({\n hasExistingPhone,\n onDirectUpdateSuccess: handleDirectUpdateSuccess,\n });\n\n const handleSuccess = () => {\n invalidateUser();\n resetForm();\n onClose();\n };\n\n const {\n code,\n isLoading,\n hasError,\n timer,\n canResend,\n isValidLength,\n handleCodeChange,\n handleValidate,\n handleResend,\n reset: resetOtp,\n } = useOtpVerification({\n onSuccess: handleSuccess,\n successMessage: 'Telefone alterado',\n validateFn: async (token) => {\n const result = await confirmPhoneChangeAction(token, submittedPhone.local, submittedPhone.ddi);\n return result.success;\n },\n resendFn: async () => {\n const { requestPhoneChangeAction } = await import('../../../modules/accounts/actions/account-management.action');\n const result = await requestPhoneChangeAction(submittedPhone.local, submittedPhone.ddi);\n if (!result.success) {\n throw new Error(result.error);\n }\n },\n });\n\n const handleClose = () => {\n resetForm();\n resetOtp();\n onClose();\n };\n\n const handleBackFromVerification = () => {\n resetOtp();\n handleBack();\n };\n\n return (\n <Dialog open={open} onOpenChange={handleClose}>\n <DialogContent\n showCloseButton={false}\n overlayClassName=\"z-[1002]\"\n className=\"flex flex-col p-0 gap-0 max-w-full sm:max-w-full border-0 rounded-t-2xl rounded-b-none h-dvh top-0 bottom-0 left-0 right-0 translate-x-0 translate-y-0 lg:max-w-125 lg:h-auto lg:rounded-lg lg:border lg:top-[50%] lg:left-[50%] lg:right-auto lg:bottom-auto lg:translate-x-[-50%] lg:translate-y-[-50%] z-[1003]\"\n >\n {showVerification ? (\n <DialogHeader className=\"flex flex-row items-center justify-between px-4 py-3 border-b border-gray-200 lg:border-b-0\">\n <Button variant=\"ghost\" className=\"size-8! p-0\" onClick={handleBackFromVerification}>\n <IconChevronLeft size={20} className=\"text-gray-950\" />\n </Button>\n <DialogTitle className=\"paragraph-medium-semibold text-gray-950 text-center flex-1\">\n Alterar telefone\n </DialogTitle>\n <Button variant=\"ghost\" className=\"size-8! p-0\" onClick={handleClose}>\n <IconX size={18} className=\"text-gray-500\" />\n </Button>\n </DialogHeader>\n ) : (\n <>\n <DialogHeader className=\"sr-only\">\n <DialogTitle>{hasExistingPhone ? 'Alterar telefone' : 'Adicionar telefone'}</DialogTitle>\n </DialogHeader>\n <div className=\"flex items-center justify-center px-4 py-3 relative border-b border-gray-200 lg:border-b-0\">\n <span className=\"paragraph-medium-semibold text-gray-950 text-center\">\n {hasExistingPhone ? 'Alterar telefone' : 'Adicionar telefone'}\n </span>\n <Button\n variant=\"ghost\"\n className=\"absolute right-2 size-8! p-0\"\n onClick={handleClose}\n >\n <IconX size={18} className=\"text-gray-500\" />\n </Button>\n </div>\n </>\n )}\n\n <div className={`${showVerification || !hasExistingPhone ? 'w-full' : 'w-1/2'} h-0.75 bg-pages-300`} />\n\n {showVerification ? (\n <form\n onSubmit={(e) => {\n e.preventDefault();\n handleValidate();\n }}\n className=\"flex flex-col flex-1 lg:flex-none\"\n >\n <div className=\"px-4 lg:px-5 py-5 lg:py-6 flex flex-col gap-4 flex-1 lg:flex-none\">\n <div className=\"flex items-center justify-center size-12 bg-white rounded-lg shadow-xs border border-gray-200\">\n <IconMessage size={20} className=\"text-gray-950\" />\n </div>\n\n <div className=\"flex flex-col gap-1\">\n <h3 className=\"paragraph-medium-semibold text-gray-950\">Código de validação</h3>\n <p className=\"paragraph-small-regular text-gray-600\">\n Enviamos um código de validação para o número atual{' '}\n <span className=\"font-semibold text-gray-950\">{currentPhoneDisplay}.</span>\n </p>\n </div>\n\n <div className=\"flex flex-col gap-2\">\n <InputOTP maxLength={OTP_CODE_LENGTH} value={code} onChange={handleCodeChange}>\n <InputOTPGroup className=\"flex flex-row gap-2\">\n {[...Array(OTP_CODE_LENGTH)].map((_, i) => (\n <InputOTPSlot\n key={i}\n index={i}\n className={`uppercase text-2xl font-medium w-11 lg:w-12 h-13 lg:h-14 rounded-lg border bg-white shadow-none [&_div.animate-caret-blink]:bg-gray-950 ${hasError ? 'border-red-500' : 'border-gray-200'}`}\n />\n ))}\n </InputOTPGroup>\n </InputOTP>\n {hasError && (\n <p className=\"paragraph-small-regular text-red-500\">Código incorreto</p>\n )}\n </div>\n\n {canResend ? (\n <button\n type=\"button\"\n onClick={handleResend}\n className=\"paragraph-small-medium text-gray-950 underline cursor-pointer hover:text-gray-700 w-fit\"\n >\n Reenviar código\n </button>\n ) : (\n <p className=\"paragraph-small-regular text-gray-500\">\n Reenviar em{' '}\n <span className=\"paragraph-small-semibold text-gray-950\">\n {formatTimer(timer)}\n </span>\n </p>\n )}\n </div>\n\n <Separator />\n\n <div className=\"flex items-center justify-between px-4 lg:px-5 py-4 lg:py-5 mt-auto lg:mt-0\">\n <Button variant=\"secondary\" className=\"h-10!\" type=\"button\" onClick={handleClose}>\n Cancelar\n </Button>\n <Button className=\"h-10!\" type=\"submit\" disabled={!isValidLength || isLoading}>\n {isLoading ? 'Validando...' : 'Alterar telefone'}\n </Button>\n </div>\n </form>\n ) : (\n <form onSubmit={handleContinue} className=\"flex flex-col flex-1 lg:flex-none\">\n <div className=\"flex flex-col gap-5 lg:gap-6 px-4 lg:px-5 py-5 lg:py-6 flex-1 lg:flex-none\">\n <div className=\"flex flex-col gap-1\">\n <span className=\"paragraph-medium-semibold text-gray-950\">\n {hasExistingPhone ? 'Atualizar telefone de contato' : 'Adicionar telefone de contato'}\n </span>\n <span className=\"paragraph-small-regular text-gray-600\">\n {hasExistingPhone\n ? 'Informe o novo número para manter seu contato atualizado.'\n : 'Informe seu número de telefone para contato.'}\n </span>\n </div>\n\n <PhoneInput\n label={hasExistingPhone ? 'Novo número' : 'Número de telefone'}\n placeholder=\"(00) 0 0000-0000\"\n value={phoneValue}\n onChange={handlePhoneChange}\n error={!!phoneError}\n errorMessage={phoneError}\n />\n </div>\n\n <div className=\"flex items-center justify-between p-4 lg:p-5 border-t border-gray-200 mt-auto lg:mt-0\">\n <Button variant=\"secondary\" className=\"h-10!\" type=\"button\" onClick={handleClose}>\n Cancelar\n </Button>\n <Button className=\"h-10!\" type=\"submit\" disabled={isSubmitting}>\n {isSubmitting\n ? (hasExistingPhone ? 'Enviando...' : 'Salvando...')\n : (hasExistingPhone ? 'Continuar' : 'Salvar')}\n </Button>\n </div>\n </form>\n )}\n </DialogContent>\n </Dialog>\n );\n}\n"],"mappings":";AAyGU,SAYA,UAVI,KAFJ;AAvGV,SAAS,i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+EACb;AAAA,oCAAC,UAAO,SAAQ,aAAY,WAAU,SAAQ,MAAK,UAAS,SAAS,aAAa,sBAElF;AAAA,gBACA,oBAAC,UAAO,WAAU,SAAQ,MAAK,UAAS,UAAU,CAAC,iBAAiB,WACjE,sBAAY,iBAAiB,oBAChC;AAAA,iBACF;AAAA;AAAA;AAAA,QACF,IAEA,qBAAC,UAAK,UAAU,gBAAgB,WAAU,qCACxC;AAAA,+BAAC,SAAI,WAAU,8EACb;AAAA,iCAAC,SAAI,WAAU,uBACb;AAAA,kCAAC,UAAK,WAAU,2CACb,6BAAmB,kCAAkC,iCACxD;AAAA,cACA,oBAAC,UAAK,WAAU,yCACb,6BACG,iEACA,mDACN;AAAA,eACF;AAAA,YAEA;AAAA,cAAC;AAAA;AAAA,gBACC,OAAO,mBAAmB,mBAAgB;AAAA,gBAC1C,aAAY;AAAA,gBACZ,OAAO;AAAA,gBACP,UAAU;AAAA,gBACV,OAAO,CAAC,CAAC;AAAA,gBACT,cAAc;AAAA;AAAA,YAChB;AAAA,aACF;AAAA,UAEA,qBAAC,SAAI,WAAU,yFACb;AAAA,gCAAC,UAAO,SAAQ,aAAY,WAAU,SAAQ,MAAK,UAAS,SAAS,aAAa,sBAElF;AAAA,YACA,oBAAC,UAAO,WAAU,SAAQ,MAAK,UAAS,UAAU,cAC/C,yBACI,mBAAmB,gBAAgB,gBACnC,mBAAmB,cAAc,UACxC;AAAA,aACF;AAAA,WACF;AAAA;AAAA;AAAA,EAEJ,GACF;AAEJ;","names":[]}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
5
|
-
import { IconSettings2 } from "@tabler/icons-react";
|
|
6
5
|
import { Popover } from "../ui/overlay/Popover";
|
|
7
6
|
import { Progress } from "../ui/feedback/Progress";
|
|
8
7
|
import { Separator } from "../ui/data-display/Separator";
|
|
@@ -112,28 +111,15 @@ function ProfilePopover({
|
|
|
112
111
|
}
|
|
113
112
|
),
|
|
114
113
|
/* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-2", children: [
|
|
115
|
-
/* @__PURE__ */
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
),
|
|
127
|
-
menuItems.map((item, index) => /* @__PURE__ */ jsx(
|
|
128
|
-
NavBarItem,
|
|
129
|
-
{
|
|
130
|
-
icon: item.icon,
|
|
131
|
-
label: item.label,
|
|
132
|
-
onClick: item.onClick
|
|
133
|
-
},
|
|
134
|
-
index
|
|
135
|
-
))
|
|
136
|
-
] }),
|
|
114
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-col", children: menuItems.map((item, index) => /* @__PURE__ */ jsx(
|
|
115
|
+
NavBarItem,
|
|
116
|
+
{
|
|
117
|
+
icon: item.icon,
|
|
118
|
+
label: item.label,
|
|
119
|
+
onClick: item.onClick
|
|
120
|
+
},
|
|
121
|
+
index
|
|
122
|
+
)) }),
|
|
137
123
|
/* @__PURE__ */ jsx(Separator, {}),
|
|
138
124
|
/* @__PURE__ */ jsx(NavBarItem, { label: "Sair", onClick: handleLogout })
|
|
139
125
|
] })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/layouts/ProfilePopover.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { IconSettings2 } from \"@tabler/icons-react\";\nimport { Popover } from \"../ui/overlay/Popover\";\nimport { Progress } from \"../ui/feedback/Progress\";\nimport { Separator } from \"../ui/data-display/Separator\";\nimport { NavBarItem } from \"./NavBarItem\";\nimport { UserAvatar } from \"../ui/data-display/UserAvatar\";\nimport { LoadingOverlay } from \"../ui/feedback/LoadingOverlay\";\nimport { useAuth } from \"../../providers/auth.provider\";\nimport { cn } from \"../../infra/utils/clsx\";\nimport { useIaCredits } from \"../../modules/ia-credits/hooks/ia-credits.hook\";\nimport { useBuyCreditsModal } from \"../../store/useBuyCreditsModal\";\nimport { useAccountModals } from \"../../store/useAccountModals\";\n\nexport interface ProfileMenuItem {\n icon?: React.ReactNode;\n label: string;\n onClick: () => void;\n}\n\nexport interface ProfilePopoverProps {\n side?: \"top\" | \"bottom\" | \"left\" | \"right\";\n align?: \"start\" | \"center\" | \"end\";\n contentClassName?: string;\n menuItems?: ProfileMenuItem[];\n}\n\nfunction ProfilePopover({\n side = \"top\",\n align = \"start\",\n contentClassName = \"absolute bottom-2 left-[26px]\",\n menuItems = [],\n}: ProfilePopoverProps) {\n const { user, logout } = useAuth();\n const [isLoggingOut, setIsLoggingOut] = useState(false);\n const [popoverOpen, setPopoverOpen] = useState(false);\n\n const { summary, subscription, isSubscriptionLoading, isCreditsLoading } =\n useIaCredits();\n const { openModal: openBuyCreditsModal } = useBuyCreditsModal();\n const { openConfigurations } = useAccountModals();\n\n const handleLogout = async () => {\n try {\n setPopoverOpen(false);\n setIsLoggingOut(true);\n await logout();\n } finally {\n setIsLoggingOut(false);\n }\n };\n\n const hasSubscription = !isSubscriptionLoading && subscription !== null;\n\n const shouldShowCredits = hasSubscription && subscription.id_wl === 1;\n const creditsPercentage =\n shouldShowCredits && summary.totalCredits > 0\n ? (summary.usedCredits / summary.totalCredits) * 100\n : 0;\n\n return (\n <>\n <LoadingOverlay\n isLoading={isLoggingOut}\n message=\"Saindo da sua conta...\"\n />\n <Popover open={popoverOpen} onOpenChange={setPopoverOpen}>\n <PopoverPrimitive.Trigger className=\"cursor-pointer\">\n {user && (\n <UserAvatar\n key={user.id}\n photo={user.photo}\n name={user.name}\n size={40}\n />\n )}\n </PopoverPrimitive.Trigger>\n\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n className={cn(\n \"w-64.75 p-0 bg-white rounded-2xl shadow-md border border-gray-200 z-99\",\n contentClassName,\n )}\n side={side}\n align={align}\n sideOffset={8}\n >\n <div className=\"grid grid-cols-[32px_1fr] items-center gap-3 p-3 w-full\">\n {user && (\n <UserAvatar\n key={user.id}\n photo={user.photo}\n name={user.name}\n size={32}\n />\n )}\n\n <div className=\"flex flex-col gap-0.5 min-w-0\">\n <span className=\"paragraph-small-semibold text-gray-950 truncate\">\n {user?.name || \"\"}\n </span>\n <span className=\"paragraph-xsmall-medium text-gray-500 truncate\">\n {user?.email || \"\"}\n </span>\n </div>\n </div>\n\n <div className=\"flex flex-col gap-2 border-t border-gray-200 rounded-2xl p-1.5\">\n {shouldShowCredits && (\n <div\n className={cn(\n \"flex flex-col bg-gray-950 rounded-lg gap-4 w-full p-4 transition-colors\",\n \"cursor-pointer hover:bg-gray-900\",\n )}\n onClick={() => openBuyCreditsModal()}\n >\n <div className=\"flex items-center justify-between gap-2\">\n <span className=\"paragraph-xsmall-semibold text-white truncate\">\n Créditos usados\n </span>\n <span className=\"paragraph-xsmall-medium text-white/50\">\n {summary.usedCredits.toLocaleString(\"pt-BR\")}/\n {summary.totalCredits.toLocaleString(\"pt-BR\")}\n </span>\n </div>\n <Progress\n className=\"bg-white/10\"\n indicatorColor=\"bg-white\"\n value={creditsPercentage}\n />\n </div>\n )}\n\n <div className=\"flex flex-col gap-2\">\n <div className=\"flex flex-col\">\n
|
|
1
|
+
{"version":3,"sources":["../../../src/components/layouts/ProfilePopover.tsx"],"sourcesContent":["\"use client\";\n\nimport { useState } from \"react\";\nimport * as PopoverPrimitive from \"@radix-ui/react-popover\";\nimport { IconSettings2 } from \"@tabler/icons-react\";\nimport { Popover } from \"../ui/overlay/Popover\";\nimport { Progress } from \"../ui/feedback/Progress\";\nimport { Separator } from \"../ui/data-display/Separator\";\nimport { NavBarItem } from \"./NavBarItem\";\nimport { UserAvatar } from \"../ui/data-display/UserAvatar\";\nimport { LoadingOverlay } from \"../ui/feedback/LoadingOverlay\";\nimport { useAuth } from \"../../providers/auth.provider\";\nimport { cn } from \"../../infra/utils/clsx\";\nimport { useIaCredits } from \"../../modules/ia-credits/hooks/ia-credits.hook\";\nimport { useBuyCreditsModal } from \"../../store/useBuyCreditsModal\";\nimport { useAccountModals } from \"../../store/useAccountModals\";\n\nexport interface ProfileMenuItem {\n icon?: React.ReactNode;\n label: string;\n onClick: () => void;\n}\n\nexport interface ProfilePopoverProps {\n side?: \"top\" | \"bottom\" | \"left\" | \"right\";\n align?: \"start\" | \"center\" | \"end\";\n contentClassName?: string;\n menuItems?: ProfileMenuItem[];\n}\n\nfunction ProfilePopover({\n side = \"top\",\n align = \"start\",\n contentClassName = \"absolute bottom-2 left-[26px]\",\n menuItems = [],\n}: ProfilePopoverProps) {\n const { user, logout } = useAuth();\n const [isLoggingOut, setIsLoggingOut] = useState(false);\n const [popoverOpen, setPopoverOpen] = useState(false);\n\n const { summary, subscription, isSubscriptionLoading, isCreditsLoading } =\n useIaCredits();\n const { openModal: openBuyCreditsModal } = useBuyCreditsModal();\n const { openConfigurations } = useAccountModals();\n\n const handleLogout = async () => {\n try {\n setPopoverOpen(false);\n setIsLoggingOut(true);\n await logout();\n } finally {\n setIsLoggingOut(false);\n }\n };\n\n const hasSubscription = !isSubscriptionLoading && subscription !== null;\n\n const shouldShowCredits = hasSubscription && subscription.id_wl === 1;\n const creditsPercentage =\n shouldShowCredits && summary.totalCredits > 0\n ? (summary.usedCredits / summary.totalCredits) * 100\n : 0;\n\n return (\n <>\n <LoadingOverlay\n isLoading={isLoggingOut}\n message=\"Saindo da sua conta...\"\n />\n <Popover open={popoverOpen} onOpenChange={setPopoverOpen}>\n <PopoverPrimitive.Trigger className=\"cursor-pointer\">\n {user && (\n <UserAvatar\n key={user.id}\n photo={user.photo}\n name={user.name}\n size={40}\n />\n )}\n </PopoverPrimitive.Trigger>\n\n <PopoverPrimitive.Portal>\n <PopoverPrimitive.Content\n className={cn(\n \"w-64.75 p-0 bg-white rounded-2xl shadow-md border border-gray-200 z-99\",\n contentClassName,\n )}\n side={side}\n align={align}\n sideOffset={8}\n >\n <div className=\"grid grid-cols-[32px_1fr] items-center gap-3 p-3 w-full\">\n {user && (\n <UserAvatar\n key={user.id}\n photo={user.photo}\n name={user.name}\n size={32}\n />\n )}\n\n <div className=\"flex flex-col gap-0.5 min-w-0\">\n <span className=\"paragraph-small-semibold text-gray-950 truncate\">\n {user?.name || \"\"}\n </span>\n <span className=\"paragraph-xsmall-medium text-gray-500 truncate\">\n {user?.email || \"\"}\n </span>\n </div>\n </div>\n\n <div className=\"flex flex-col gap-2 border-t border-gray-200 rounded-2xl p-1.5\">\n {shouldShowCredits && (\n <div\n className={cn(\n \"flex flex-col bg-gray-950 rounded-lg gap-4 w-full p-4 transition-colors\",\n \"cursor-pointer hover:bg-gray-900\",\n )}\n onClick={() => openBuyCreditsModal()}\n >\n <div className=\"flex items-center justify-between gap-2\">\n <span className=\"paragraph-xsmall-semibold text-white truncate\">\n Créditos usados\n </span>\n <span className=\"paragraph-xsmall-medium text-white/50\">\n {summary.usedCredits.toLocaleString(\"pt-BR\")}/\n {summary.totalCredits.toLocaleString(\"pt-BR\")}\n </span>\n </div>\n <Progress\n className=\"bg-white/10\"\n indicatorColor=\"bg-white\"\n value={creditsPercentage}\n />\n </div>\n )}\n\n <div className=\"flex flex-col gap-2\">\n <div className=\"flex flex-col\">\n {menuItems.map((item, index) => (\n <NavBarItem\n key={index}\n icon={item.icon}\n label={item.label}\n onClick={item.onClick}\n />\n ))}\n </div>\n <Separator />\n <NavBarItem label=\"Sair\" onClick={handleLogout} />\n </div>\n </div>\n </PopoverPrimitive.Content>\n </PopoverPrimitive.Portal>\n </Popover>\n </>\n );\n}\n\nexport { ProfilePopover };\n"],"mappings":";AAgEI,mBACE,KAoCQ,YArCV;AA9DJ,SAAS,gBAAgB;AACzB,YAAY,sBAAsB;AAElC,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAC3B,SAAS,kBAAkB;A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AA,gBACX,oBAAC,cAAW,OAAM,QAAO,SAAS,cAAc;AAAA,iBAClD;AAAA,eACF;AAAA;AAAA;AAAA,MACF,GACF;AAAA,OACF;AAAA,KACF;AAEJ;","names":[]}
|
|
@@ -52,6 +52,8 @@ function PhoneInput({
|
|
|
52
52
|
};
|
|
53
53
|
const handleNumberChange = (e) => {
|
|
54
54
|
const rawInput = e.target.value;
|
|
55
|
+
const digits = rawInput.replace(/\D/g, "");
|
|
56
|
+
if (digits.length > 15) return;
|
|
55
57
|
const cursorPos = e.target.selectionStart ?? rawInput.length;
|
|
56
58
|
const digitsBeforeCursor = rawInput.slice(0, cursorPos).replace(/\D/g, "").length;
|
|
57
59
|
const formatted = formatNational(rawInput, selectedCountry.iso);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/ui/form/PhoneInput.tsx"],"sourcesContent":["'use client';\n\nimport { useState, useEffect, useRef } from 'react';\nimport { AsYouType, CountryCode } from 'libphonenumber-js';\nimport { Input, Separator, Popover, PopoverTrigger, PopoverContent, cn } from '@greatapps/common';\nimport { IconChevronDown, IconSearch } from '@tabler/icons-react';\nimport { COUNTRIES, Country, flagUrl, parsePhoneValue } from '../../../utils/countries';\n\nfunction formatNational(digits: string, iso: string): string {\n const raw = digits.replace(/\\D/g, '');\n if (!raw) return '';\n return new AsYouType(iso as CountryCode).input(raw);\n}\n\ninterface PhoneInputProps {\n value?: string;\n onChange?: (value: string) => void;\n label?: string;\n optional?: boolean;\n required?: boolean;\n hintMessage?: string;\n error?: boolean;\n errorMessage?: string;\n placeholder?: string;\n disabled?: boolean;\n classnameContainer?: string;\n className?: string;\n}\n\nexport default function PhoneInput({\n value,\n onChange,\n label,\n optional = false,\n required = false,\n hintMessage,\n error = false,\n errorMessage,\n placeholder,\n disabled = false,\n classnameContainer,\n className,\n}: PhoneInputProps) {\n const parsed = parsePhoneValue(value ?? '');\n const [selectedCountry, setSelectedCountry] = useState<Country>(parsed.country);\n const [phoneNumber, setPhoneNumber] = useState(parsed.number);\n const [search, setSearch] = useState('');\n const [open, setOpen] = useState(false);\n const prevValueRef = useRef(value);\n const inputRef = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (value !== prevValueRef.current) {\n prevValueRef.current = value;\n const p = parsePhoneValue(value ?? '');\n setSelectedCountry(p.country);\n setPhoneNumber(formatNational(p.number, p.country.iso));\n }\n }, [value]);\n\n const emit = (country: Country, number: string) => {\n onChange?.(`${country.dial} ${number}`);\n };\n\n const handleCountrySelect = (country: Country) => {\n const reformatted = formatNational(phoneNumber, country.iso);\n setSelectedCountry(country);\n setPhoneNumber(reformatted);\n setOpen(false);\n setSearch('');\n emit(country, reformatted);\n };\n\n const handleNumberChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const rawInput = e.target.value;\n const cursorPos = e.target.selectionStart ?? rawInput.length;\n const digitsBeforeCursor = rawInput.slice(0, cursorPos).replace(/\\D/g, '').length;\n\n const formatted = formatNational(rawInput, selectedCountry.iso);\n setPhoneNumber(formatted);\n emit(selectedCountry, formatted);\n\n requestAnimationFrame(() => {\n if (!inputRef.current) return;\n let digitCount = 0;\n let newPos = formatted.length;\n for (let i = 0; i < formatted.length; i++) {\n if (/\\d/.test(formatted[i])) {\n digitCount++;\n if (digitCount === digitsBeforeCursor) {\n newPos = i + 1;\n break;\n }\n }\n }\n inputRef.current.setSelectionRange(newPos, newPos);\n });\n };\n\n const filtered = COUNTRIES.filter(\n (c) =>\n c.name.toLowerCase().includes(search.toLowerCase()) ||\n c.dial.includes(search) ||\n c.iso.toLowerCase().includes(search.toLowerCase())\n );\n\n const finalMessage = error && errorMessage ? errorMessage : hintMessage;\n const showMessage = finalMessage && finalMessage.trim() !== '';\n\n return (\n <div className=\"flex flex-col gap-1.5\">\n {label && (\n <div className=\"flex items-center gap-1 paragraph-xsmall-semibold\">\n <span className=\"text-zinc-600\">{label}</span>\n {optional && <span className=\"text-zinc-500\">(Opcional)</span>}\n {required && <span className=\"text-red-600\">*</span>}\n </div>\n )}\n\n <div\n className={cn(\n 'flex gap-2 items-center border rounded-lg h-10 transition-colors',\n error\n ? 'border-red-600 hover:border-red-700'\n : 'border-zinc-200 hover:border-zinc-400 focus-within:border-zinc-950',\n disabled && 'cursor-not-allowed',\n classnameContainer\n )}\n >\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <button\n type=\"button\"\n className=\"flex items-center gap-1.5 px-3 h-full shrink-0 focus:outline-none\"\n disabled={disabled}\n >\n <img src={flagUrl(selectedCountry.iso)} alt={selectedCountry.iso} className=\"w-5 h-5 rounded-full\" />\n <span className=\"paragraph-small-regular text-zinc-950\">{selectedCountry.dial}</span>\n <IconChevronDown size={14} className={cn(\"text-zinc-500 transition-transform duration-200\", open && \"rotate-180\")} />\n </button>\n </PopoverTrigger>\n <PopoverContent className=\"w-72 p-0 z-[1010]\" align=\"start\" side=\"top\">\n <div className=\"flex items-center gap-2 p-2 border-b border-zinc-100\">\n <IconSearch size={14} className=\"text-zinc-400 shrink-0\" />\n <input\n type=\"text\"\n className=\"flex-1 text-sm outline-none placeholder:text-zinc-400\"\n placeholder=\"Buscar país...\"\n value={search}\n onChange={(e) => setSearch(e.target.value)}\n autoFocus\n />\n </div>\n <div className=\"max-h-60 overflow-y-auto overscroll-contain\" onTouchMove={(e) => e.stopPropagation()} onWheel={(e) => e.stopPropagation()}>\n {filtered.map((country) => (\n <button\n key={country.iso}\n type=\"button\"\n className={cn(\n 'flex items-center gap-2.5 w-full px-3 py-2 text-left hover:bg-zinc-50 transition-colors',\n selectedCountry.iso === country.iso && 'bg-zinc-100'\n )}\n onClick={() => handleCountrySelect(country)}\n >\n <img src={flagUrl(country.iso)} alt={country.iso} className=\"w-5 h-5 rounded-full shrink-0\" />\n <span className=\"paragraph-small-regular text-zinc-950 flex-1 truncate\">\n {country.name}\n </span>\n <span className=\"paragraph-small-regular text-zinc-500 shrink-0\">\n {country.dial}\n </span>\n </button>\n ))}\n {filtered.length === 0 && (\n <p className=\"text-sm text-zinc-500 p-3 text-center\">Nenhum país encontrado</p>\n )}\n </div>\n </PopoverContent>\n </Popover>\n\n <Separator orientation=\"vertical\" />\n\n <Input\n ref={inputRef}\n type=\"tel\"\n value={phoneNumber}\n onChange={handleNumberChange}\n placeholder={placeholder}\n disabled={disabled}\n className={cn(\n 'paragraph-small-medium w-full h-full text-zinc-950 border-0 focus-visible:ring-0 focus-visible:ring-offset-0',\n disabled && 'cursor-not-allowed',\n className\n )}\n />\n </div>\n\n {showMessage && (\n <span className={cn('paragraph-xsmall-medium', error ? 'text-red-600' : 'text-zinc-600')}>\n {finalMessage}\n </span>\n )}\n </div>\n );\n}\n"],"mappings":";AAgHQ,SACE,KADF;AA9GR,SAAS,UAAU,WAAW,cAAc;AAC5C,SAAS,iBAA8B;AACvC,SAAS,OAAO,WAAW,SAAS,gBAAgB,gBAAgB,UAAU;AAC9E,SAAS,iBAAiB,kBAAkB;AAC5C,SAAS,WAAoB,SAAS,uBAAuB;AAE7D,SAAS,eAAe,QAAgB,KAAqB;AAC3D,QAAM,MAAM,OAAO,QAAQ,OAAO,EAAE;AACpC,MAAI,CAAC,IAAK,QAAO;AACjB,SAAO,IAAI,UAAU,GAAkB,EAAE,MAAM,GAAG;AACpD;AAiBe,SAAR,WAA4B;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX,WAAW;AAAA,EACX;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AACF,GAAoB;AAClB,QAAM,SAAS,gBAAgB,SAAS,EAAE;AAC1C,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,SAAkB,OAAO,OAAO;AAC9E,QAAM,CAAC,aAAa,cAAc,IAAI,SAAS,OAAO,MAAM;AAC5D,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAS,EAAE;AACvC,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,KAAK;AACtC,QAAM,eAAe,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sourcesContent":["'use client';\n\nimport { useState, useEffect, useRef } from 'react';\nimport { AsYouType, CountryCode } from 'libphonenumber-js';\nimport { Input, Separator, Popover, PopoverTrigger, PopoverContent, cn } from '@greatapps/common';\nimport { IconChevronDown, IconSearch } from '@tabler/icons-react';\nimport { COUNTRIES, Country, flagUrl, parsePhoneValue } from '../../../utils/countries';\n\nfunction formatNational(digits: string, iso: string): string {\n const raw = digits.replace(/\\D/g, '');\n if (!raw) return '';\n return new AsYouType(iso as CountryCode).input(raw);\n}\n\ninterface PhoneInputProps {\n value?: string;\n onChange?: (value: string) => void;\n label?: string;\n optional?: boolean;\n required?: boolean;\n hintMessage?: string;\n error?: boolean;\n errorMessage?: string;\n placeholder?: string;\n disabled?: boolean;\n classnameContainer?: string;\n className?: string;\n}\n\nexport default function PhoneInput({\n value,\n onChange,\n label,\n optional = false,\n required = false,\n hintMessage,\n error = false,\n errorMessage,\n placeholder,\n disabled = false,\n classnameContainer,\n className,\n}: PhoneInputProps) {\n const parsed = parsePhoneValue(value ?? '');\n const [selectedCountry, setSelectedCountry] = useState<Country>(parsed.country);\n const [phoneNumber, setPhoneNumber] = useState(parsed.number);\n const [search, setSearch] = useState('');\n const [open, setOpen] = useState(false);\n const prevValueRef = useRef(value);\n const inputRef = useRef<HTMLInputElement>(null);\n\n useEffect(() => {\n if (value !== prevValueRef.current) {\n prevValueRef.current = value;\n const p = parsePhoneValue(value ?? '');\n setSelectedCountry(p.country);\n setPhoneNumber(formatNational(p.number, p.country.iso));\n }\n }, [value]);\n\n const emit = (country: Country, number: string) => {\n onChange?.(`${country.dial} ${number}`);\n };\n\n const handleCountrySelect = (country: Country) => {\n const reformatted = formatNational(phoneNumber, country.iso);\n setSelectedCountry(country);\n setPhoneNumber(reformatted);\n setOpen(false);\n setSearch('');\n emit(country, reformatted);\n };\n\n const handleNumberChange = (e: React.ChangeEvent<HTMLInputElement>) => {\n const rawInput = e.target.value;\n const digits = rawInput.replace(/\\D/g, '');\n if (digits.length > 15) return;\n\n const cursorPos = e.target.selectionStart ?? rawInput.length;\n const digitsBeforeCursor = rawInput.slice(0, cursorPos).replace(/\\D/g, '').length;\n\n const formatted = formatNational(rawInput, selectedCountry.iso);\n setPhoneNumber(formatted);\n emit(selectedCountry, formatted);\n\n requestAnimationFrame(() => {\n if (!inputRef.current) return;\n let digitCount = 0;\n let newPos = formatted.length;\n for (let i = 0; i < formatted.length; i++) {\n if (/\\d/.test(formatted[i])) {\n digitCount++;\n if (digitCount === digitsBeforeCursor) {\n newPos = i + 1;\n break;\n }\n }\n }\n inputRef.current.setSelectionRange(newPos, newPos);\n });\n };\n\n const filtered = COUNTRIES.filter(\n (c) =>\n c.name.toLowerCase().includes(search.toLowerCase()) ||\n c.dial.includes(search) ||\n c.iso.toLowerCase().includes(search.toLowerCase())\n );\n\n const finalMessage = error && errorMessage ? errorMessage : hintMessage;\n const showMessage = finalMessage && finalMessage.trim() !== '';\n\n return (\n <div className=\"flex flex-col gap-1.5\">\n {label && (\n <div className=\"flex items-center gap-1 paragraph-xsmall-semibold\">\n <span className=\"text-zinc-600\">{label}</span>\n {optional && <span className=\"text-zinc-500\">(Opcional)</span>}\n {required && <span className=\"text-red-600\">*</span>}\n </div>\n )}\n\n <div\n className={cn(\n 'flex gap-2 items-center border rounded-lg h-10 transition-colors',\n error\n ? 'border-red-600 hover:border-red-700'\n : 'border-zinc-200 hover:border-zinc-400 focus-within:border-zinc-950',\n disabled && 'cursor-not-allowed',\n classnameContainer\n )}\n >\n <Popover open={open} onOpenChange={setOpen}>\n <PopoverTrigger asChild>\n <button\n type=\"button\"\n className=\"flex items-center gap-1.5 px-3 h-full shrink-0 focus:outline-none\"\n disabled={disabled}\n >\n <img src={flagUrl(selectedCountry.iso)} alt={selectedCountry.iso} className=\"w-5 h-5 rounded-full\" />\n <span className=\"paragraph-small-regular text-zinc-950\">{selectedCountry.dial}</span>\n <IconChevronDown size={14} className={cn(\"text-zinc-500 transition-transform duration-200\", open && \"rotate-180\")} />\n </button>\n </PopoverTrigger>\n <PopoverContent className=\"w-72 p-0 z-[1010]\" align=\"start\" side=\"top\">\n <div className=\"flex items-center gap-2 p-2 border-b border-zinc-100\">\n <IconSearch size={14} className=\"text-zinc-400 shrink-0\" />\n <input\n type=\"text\"\n className=\"flex-1 text-sm outline-none placeholder:text-zinc-400\"\n placeholder=\"Buscar país...\"\n value={search}\n onChange={(e) => setSearch(e.target.value)}\n autoFocus\n />\n </div>\n <div className=\"max-h-60 overflow-y-auto overscroll-contain\" onTouchMove={(e) => e.stopPropagation()} onWheel={(e) => e.stopPropagation()}>\n {filtered.map((country) => (\n <button\n key={country.iso}\n type=\"button\"\n className={cn(\n 'flex items-center gap-2.5 w-full px-3 py-2 text-left hover:bg-zinc-50 transition-colors',\n selectedCountry.iso === country.iso && 'bg-zinc-100'\n )}\n onClick={() => handleCountrySelect(country)}\n >\n <img src={flagUrl(country.iso)} alt={country.iso} className=\"w-5 h-5 rounded-full shrink-0\" />\n <span className=\"paragraph-small-regular text-zinc-950 flex-1 truncate\">\n {country.name}\n </span>\n <span className=\"paragraph-small-regular text-zinc-500 shrink-0\">\n {country.dial}\n </span>\n </button>\n ))}\n {filtered.length === 0 && (\n <p className=\"text-sm text-zinc-500 p-3 text-center\">Nenhum país encontrado</p>\n )}\n </div>\n </PopoverContent>\n </Popover>\n\n <Separator orientation=\"vertical\" />\n\n <Input\n ref={inputRef}\n type=\"tel\"\n value={phoneNumber}\n onChange={handleNumberChange}\n placeholder={placeholder}\n disabled={disabled}\n className={cn(\n 'paragraph-small-medium w-full h-full text-zinc-950 border-0 focus-visible:ring-0 focus-visible:ring-offset-0',\n disabled && 'cursor-not-allowed',\n className\n )}\n />\n </div>\n\n {showMessage && (\n <span className={cn('paragraph-xsmall-medium', error ? 'text-red-600' : 'text-zinc-600')}>\n {finalMessage}\n </span>\n )}\n </div>\n );\n}\n"],"mappings":";AAmHQ,SACE,KADF;AAjHR,SAAS,UAAU,WAAW,cAAc;AAC5C,SAAS,iBAA8B;AAC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,MAAM,oBAAoB,OAAO;AAAA,oBAE1C;AAAA,0CAAC,SAAI,KAAK,QAAQ,QAAQ,GAAG,GAAG,KAAK,QAAQ,KAAK,WAAU,iCAAgC;AAAA,sBAC5F,oBAAC,UAAK,WAAU,yDACb,kBAAQ,MACX;AAAA,sBACA,oBAAC,UAAK,WAAU,kDACb,kBAAQ,MACX;AAAA;AAAA;AAAA,kBAdK,QAAQ;AAAA,gBAef,CACD;AAAA,gBACA,SAAS,WAAW,KACnB,oBAAC,OAAE,WAAU,yCAAwC,uCAAsB;AAAA,iBAE/E;AAAA,eACF;AAAA,aACF;AAAA,UAEA,oBAAC,aAAU,aAAY,YAAW;AAAA,UAElC;AAAA,YAAC;AAAA;AAAA,cACC,KAAK;AAAA,cACL,MAAK;AAAA,cACL,OAAO;AAAA,cACP,UAAU;AAAA,cACV;AAAA,cACA;AAAA,cACA,WAAW;AAAA,gBACT;AAAA,gBACA,YAAY;AAAA,gBACZ;AAAA,cACF;AAAA;AAAA,UACF;AAAA;AAAA;AAAA,IACF;AAAA,IAEC,eACC,oBAAC,UAAK,WAAW,GAAG,2BAA2B,QAAQ,iBAAiB,eAAe,GACpF,wBACH;AAAA,KAEJ;AAEJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { useState, useCallback } from 'react';
|
|
4
4
|
import { toast } from 'sonner';
|
|
5
5
|
import { Toast } from '../../ui/feedback/Toast';
|
|
6
|
-
import { requestPhoneChangeAction } from '../../../modules/accounts/actions/account-management.action';
|
|
6
|
+
import { requestPhoneChangeAction, updateUserAction } from '../../../modules/accounts/actions/account-management.action';
|
|
7
7
|
|
|
8
8
|
function splitPhoneValue(fullValue: string): { ddi: string; local: string } {
|
|
9
9
|
const trimmed = fullValue.trim();
|
|
@@ -12,7 +12,12 @@ function splitPhoneValue(fullValue: string): { ddi: string; local: string } {
|
|
|
12
12
|
return { ddi: trimmed.slice(0, spaceIdx), local: trimmed.slice(spaceIdx + 1) };
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
interface UseChangePhoneFormOptions {
|
|
16
|
+
hasExistingPhone: boolean;
|
|
17
|
+
onDirectUpdateSuccess?: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function useChangePhoneForm({ hasExistingPhone, onDirectUpdateSuccess }: UseChangePhoneFormOptions) {
|
|
16
21
|
const [showVerification, setShowVerification] = useState(false);
|
|
17
22
|
const [phoneValue, setPhoneValue] = useState('');
|
|
18
23
|
const [phoneError, setPhoneError] = useState('');
|
|
@@ -36,6 +41,27 @@ export default function useChangePhoneForm() {
|
|
|
36
41
|
|
|
37
42
|
setIsSubmitting(true);
|
|
38
43
|
try {
|
|
44
|
+
if (!hasExistingPhone) {
|
|
45
|
+
const result = await updateUserAction({ phone: local, ddi });
|
|
46
|
+
|
|
47
|
+
if (!result.success) {
|
|
48
|
+
toast.custom((t) => (
|
|
49
|
+
<Toast
|
|
50
|
+
variant="error"
|
|
51
|
+
message={result.error ?? 'Ocorreu um erro ao salvar o telefone. Tente novamente mais tarde.'}
|
|
52
|
+
toastId={t}
|
|
53
|
+
/>
|
|
54
|
+
));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
toast.custom((t) => (
|
|
59
|
+
<Toast variant="success" message="Telefone adicionado" toastId={t} />
|
|
60
|
+
));
|
|
61
|
+
onDirectUpdateSuccess?.();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
39
65
|
const result = await requestPhoneChangeAction(local, ddi);
|
|
40
66
|
|
|
41
67
|
if (!result.success) {
|
|
@@ -54,7 +80,7 @@ export default function useChangePhoneForm() {
|
|
|
54
80
|
} finally {
|
|
55
81
|
setIsSubmitting(false);
|
|
56
82
|
}
|
|
57
|
-
}, [phoneValue]);
|
|
83
|
+
}, [phoneValue, hasExistingPhone, onDirectUpdateSuccess]);
|
|
58
84
|
|
|
59
85
|
const handleBack = useCallback(() => {
|
|
60
86
|
setShowVerification(false);
|
|
@@ -23,12 +23,19 @@ export function ChangePhoneModal({ open, onClose }: ChangePhoneModalProps) {
|
|
|
23
23
|
const { user } = useAuth();
|
|
24
24
|
const invalidateUser = useInvalidateUser();
|
|
25
25
|
|
|
26
|
+
const hasExistingPhone = !!user?.phone;
|
|
27
|
+
|
|
26
28
|
const currentPhoneDisplay = user?.phone
|
|
27
29
|
? formatPhone(
|
|
28
30
|
user.ddi && user.phone.startsWith(user.ddi) ? user.phone.slice(user.ddi.length) : user.phone
|
|
29
31
|
)
|
|
30
32
|
: '';
|
|
31
33
|
|
|
34
|
+
const handleDirectUpdateSuccess = () => {
|
|
35
|
+
invalidateUser();
|
|
36
|
+
onClose();
|
|
37
|
+
};
|
|
38
|
+
|
|
32
39
|
const {
|
|
33
40
|
showVerification,
|
|
34
41
|
phoneValue,
|
|
@@ -39,7 +46,10 @@ export function ChangePhoneModal({ open, onClose }: ChangePhoneModalProps) {
|
|
|
39
46
|
handleContinue,
|
|
40
47
|
handleBack,
|
|
41
48
|
resetForm,
|
|
42
|
-
} = useChangePhoneForm(
|
|
49
|
+
} = useChangePhoneForm({
|
|
50
|
+
hasExistingPhone,
|
|
51
|
+
onDirectUpdateSuccess: handleDirectUpdateSuccess,
|
|
52
|
+
});
|
|
43
53
|
|
|
44
54
|
const handleSuccess = () => {
|
|
45
55
|
invalidateUser();
|
|
@@ -107,11 +117,11 @@ export function ChangePhoneModal({ open, onClose }: ChangePhoneModalProps) {
|
|
|
107
117
|
) : (
|
|
108
118
|
<>
|
|
109
119
|
<DialogHeader className="sr-only">
|
|
110
|
-
<DialogTitle>Alterar telefone</DialogTitle>
|
|
120
|
+
<DialogTitle>{hasExistingPhone ? 'Alterar telefone' : 'Adicionar telefone'}</DialogTitle>
|
|
111
121
|
</DialogHeader>
|
|
112
122
|
<div className="flex items-center justify-center px-4 py-3 relative border-b border-gray-200 lg:border-b-0">
|
|
113
123
|
<span className="paragraph-medium-semibold text-gray-950 text-center">
|
|
114
|
-
Alterar telefone
|
|
124
|
+
{hasExistingPhone ? 'Alterar telefone' : 'Adicionar telefone'}
|
|
115
125
|
</span>
|
|
116
126
|
<Button
|
|
117
127
|
variant="ghost"
|
|
@@ -124,7 +134,7 @@ export function ChangePhoneModal({ open, onClose }: ChangePhoneModalProps) {
|
|
|
124
134
|
</>
|
|
125
135
|
)}
|
|
126
136
|
|
|
127
|
-
<div className={`${showVerification ? 'w-full' : 'w-1/2'} h-0.75 bg-pages-300`} />
|
|
137
|
+
<div className={`${showVerification || !hasExistingPhone ? 'w-full' : 'w-1/2'} h-0.75 bg-pages-300`} />
|
|
128
138
|
|
|
129
139
|
{showVerification ? (
|
|
130
140
|
<form
|
|
@@ -198,15 +208,17 @@ export function ChangePhoneModal({ open, onClose }: ChangePhoneModalProps) {
|
|
|
198
208
|
<div className="flex flex-col gap-5 lg:gap-6 px-4 lg:px-5 py-5 lg:py-6 flex-1 lg:flex-none">
|
|
199
209
|
<div className="flex flex-col gap-1">
|
|
200
210
|
<span className="paragraph-medium-semibold text-gray-950">
|
|
201
|
-
Atualizar telefone de contato
|
|
211
|
+
{hasExistingPhone ? 'Atualizar telefone de contato' : 'Adicionar telefone de contato'}
|
|
202
212
|
</span>
|
|
203
213
|
<span className="paragraph-small-regular text-gray-600">
|
|
204
|
-
|
|
214
|
+
{hasExistingPhone
|
|
215
|
+
? 'Informe o novo número para manter seu contato atualizado.'
|
|
216
|
+
: 'Informe seu número de telefone para contato.'}
|
|
205
217
|
</span>
|
|
206
218
|
</div>
|
|
207
219
|
|
|
208
220
|
<PhoneInput
|
|
209
|
-
label=
|
|
221
|
+
label={hasExistingPhone ? 'Novo número' : 'Número de telefone'}
|
|
210
222
|
placeholder="(00) 0 0000-0000"
|
|
211
223
|
value={phoneValue}
|
|
212
224
|
onChange={handlePhoneChange}
|
|
@@ -220,7 +232,9 @@ export function ChangePhoneModal({ open, onClose }: ChangePhoneModalProps) {
|
|
|
220
232
|
Cancelar
|
|
221
233
|
</Button>
|
|
222
234
|
<Button className="h-10!" type="submit" disabled={isSubmitting}>
|
|
223
|
-
{isSubmitting
|
|
235
|
+
{isSubmitting
|
|
236
|
+
? (hasExistingPhone ? 'Enviando...' : 'Salvando...')
|
|
237
|
+
: (hasExistingPhone ? 'Continuar' : 'Salvar')}
|
|
224
238
|
</Button>
|
|
225
239
|
</div>
|
|
226
240
|
</form>
|
|
@@ -137,14 +137,6 @@ function ProfilePopover({
|
|
|
137
137
|
|
|
138
138
|
<div className="flex flex-col gap-2">
|
|
139
139
|
<div className="flex flex-col">
|
|
140
|
-
<NavBarItem
|
|
141
|
-
icon={<IconSettings2 size={20} />}
|
|
142
|
-
label="Preferências"
|
|
143
|
-
onClick={() => {
|
|
144
|
-
setPopoverOpen(false);
|
|
145
|
-
openConfigurations();
|
|
146
|
-
}}
|
|
147
|
-
/>
|
|
148
140
|
{menuItems.map((item, index) => (
|
|
149
141
|
<NavBarItem
|
|
150
142
|
key={index}
|
|
@@ -73,6 +73,9 @@ export default function PhoneInput({
|
|
|
73
73
|
|
|
74
74
|
const handleNumberChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
75
75
|
const rawInput = e.target.value;
|
|
76
|
+
const digits = rawInput.replace(/\D/g, '');
|
|
77
|
+
if (digits.length > 15) return;
|
|
78
|
+
|
|
76
79
|
const cursorPos = e.target.selectionStart ?? rawInput.length;
|
|
77
80
|
const digitsBeforeCursor = rawInput.slice(0, cursorPos).replace(/\D/g, '').length;
|
|
78
81
|
|