1- import { useEffect , useMemo , useState , type FC } from 'react'
1+ import { useContext , useEffect , useMemo , useState , type FC } from 'react'
22import classNames from 'classnames/bind'
33import styles from './ContactSection.module.scss'
44import { Section } from '../Section'
55import { SocialLink } from '../SocialLink'
66import { LocalStorageKeys } from '~/model/localStorage'
7+ import { formatPhoneNumber } from '~/utils/phone.utils'
8+ import { LangContext } from '~/context/Lang.context'
79
810const cx = classNames . bind ( styles )
911
@@ -19,6 +21,8 @@ const cx = classNames.bind(styles)
1921*/
2022export const ContactSection : FC = ( ) => {
2123 const [ isClientSide , setisClientSide ] = useState ( false )
24+ const { langKey } = useContext ( LangContext )
25+
2226 useEffect ( ( ) => {
2327 setisClientSide ( true )
2428 } , [ ] )
@@ -35,14 +39,8 @@ export const ContactSection: FC = () => {
3539 const storedPhone = window . localStorage . getItem ( LocalStorageKeys . phone )
3640 if ( ! storedPhone ) return null
3741
38- const display = [ ...storedPhone ]
39- . map ( ( c , i ) => ( i > 0 && i % 2 === 0 ? ` ${ c } ` : c ) )
40- . join ( '' )
41-
42- const withIndicator = storedPhone . replace ( / ^ 0 / g, '+33' )
43-
44- return { display, withIndicator }
45- } , [ isClientSide ] )
42+ return formatPhoneNumber ( storedPhone , langKey === 'fr' ? 'fr' : 'intl' )
43+ } , [ isClientSide , langKey ] )
4644
4745 return (
4846 < Section title = "Contact" >
@@ -57,8 +55,8 @@ export const ContactSection: FC = () => {
5755 { phone && (
5856 < SocialLink
5957 icon = "phone"
60- label = { phone . display }
61- link = { `tel:${ phone . withIndicator } ` }
58+ label = { phone . formated }
59+ link = { `tel:${ phone . normalized } ` }
6260 />
6361 ) }
6462 < SocialLink
0 commit comments