From 52eabe3cd0b7cd0138f996df124cfdc6a7728e08 Mon Sep 17 00:00:00 2001 From: c00b3r Date: Fri, 25 Apr 2025 16:17:02 +0500 Subject: [PATCH] feat: update footer and input tel mask --- src/components/Layout/Feedback.tsx | 37 ++++++++++++++++-------------- src/components/Layout/Footer.tsx | 8 +++---- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/components/Layout/Feedback.tsx b/src/components/Layout/Feedback.tsx index 5cecafe..469200f 100644 --- a/src/components/Layout/Feedback.tsx +++ b/src/components/Layout/Feedback.tsx @@ -46,15 +46,10 @@ interface IInput { export function FeedbackForm() { const [[phoneCode, country], setPhoneCodeAndCountry] = useState< [string, Country] - >(['+7', 'RU']); + >(['+971', 'AE']); const placeholder = useMemo( - () => - getExampleNumber(country, examples) - ?.formatInternational() - .split(' ') - .slice(1) - .join(' '), + () => getExampleNumber(country, examples), [country] ); @@ -64,6 +59,18 @@ export function FeedbackForm() { const { register, handleSubmit, formState } = form; + const handlePhoneChange = (e: React.ChangeEvent) => { + const value = e.target.value; + // Remove all spaces and ensure we have the correct country code + const cleanValue = value.replaceAll(/ /g, ''); + if (!cleanValue.startsWith('+971')) { + // If the value doesn't start with +971, force it + form.setValue('phone', '+971' + cleanValue.replace('+', '')); + } else { + form.setValue('phone', cleanValue); + } + }; + async function onSubmit(data: IInput) { await api.post('mail', { json: data }).json(); } @@ -105,16 +112,12 @@ export function FeedbackForm() { { - form.setValue( - 'phone', - phoneCode + e.target.value.replaceAll(/ /g, '') - ); - }} + onChange={handlePhoneChange} id={'tel'} maskChar={null} - mask={'+7 ' + (placeholder?.replace(/\d/g, '9') ?? '')} - placeholder={'+7 ' + placeholder} + mask={'+971 59 999 9999'} + placeholder={'+971 5X XXX XXXX'} + value={form.watch('phone')} className="placeholder:btnl placeholder:font-medium placeholder:select-none peer btnl w-full h-full transition-all bg-transparent rounded-none outline-none" />
@@ -147,8 +150,8 @@ export function FeedbackForm() {

- Мы получили заявку -
и скоро свяжемся с вами! + We received your request +
and will contact you soon!

diff --git a/src/components/Layout/Footer.tsx b/src/components/Layout/Footer.tsx index e7e1f92..5832219 100644 --- a/src/components/Layout/Footer.tsx +++ b/src/components/Layout/Footer.tsx @@ -17,22 +17,22 @@ export function Footer() {