From c9d52b67fed0daab5dde5ec17033596e66337d0c Mon Sep 17 00:00:00 2001 From: Vane <72040969+vanedq@users.noreply.github.com> Date: Tue, 16 Sep 2025 09:19:53 -0300 Subject: [PATCH] Updated personalInfoForm.tsx to automatically put the phone DDD into parenthesis. --- .../src/components/forms/personalInfoForm.tsx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/cv-generator/src/components/forms/personalInfoForm.tsx b/cv-generator/src/components/forms/personalInfoForm.tsx index ac5a8e6..e800de3 100644 --- a/cv-generator/src/components/forms/personalInfoForm.tsx +++ b/cv-generator/src/components/forms/personalInfoForm.tsx @@ -1,6 +1,16 @@ export default function PersonalInfoForm({ currentCV, updateCV, isVisible }: any) { if (!isVisible) return null; + {/* Formata número de telefone */} + const formatPhone = (value: string) => { + //Permite apenas números (\D=não dígito; g=global) + const validType = value.replace(/\D/g, ''); + //Separa DDD + if (validType.length > 2) + return `(${validType.slice(0,2)})${validType.slice(2)}`; + return validType; + } + return (

Informações Pessoais

@@ -45,10 +55,13 @@ export default function PersonalInfoForm({ currentCV, updateCV, isVisible }: any type="tel" placeholder="Telefone (opcional)" value={currentCV.personalInfo.phone || ''} - onChange={(e) => updateCV({ + onChange={(e) => { + const phoneNumber = formatPhone(e.target.value); + updateCV({ ...currentCV, - personalInfo: { ...currentCV.personalInfo, phone: e.target.value } - })} + personalInfo: { ...currentCV.personalInfo, phone: phoneNumber } + }) + }} className="w-full p-2 border rounded" />