From 9c3a947ad38a52deef945902857f34f79f0617f6 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Thu, 21 Nov 2024 10:38:44 +0100 Subject: [PATCH 1/3] fix: contactlink --- .../ItaliaTheme/View/Commons/ContactLink.jsx | 127 ++++++++++-------- 1 file changed, 73 insertions(+), 54 deletions(-) diff --git a/src/components/ItaliaTheme/View/Commons/ContactLink.jsx b/src/components/ItaliaTheme/View/Commons/ContactLink.jsx index 180a6f76a..8a8ed7403 100644 --- a/src/components/ItaliaTheme/View/Commons/ContactLink.jsx +++ b/src/components/ItaliaTheme/View/Commons/ContactLink.jsx @@ -15,7 +15,6 @@ const messages = defineMessages({ id: 'email_label', defaultMessage: 'E-mail', }, - call: { id: 'chiama_il_numero', defaultMessage: 'Chiama il numero', @@ -32,70 +31,90 @@ const messages = defineMessages({ const ContactLink = ({ tel, fax, email, label = true, strong = false }) => { const intl = useIntl(); - let ret_label = null; - let ret = null; - - function ReplacePhoneNumbers(str, type) { - // eslint-disable-next-line no-useless-escape - let newhtml = str.replace(/\+?[0-9]( ?[0-9\/-]+)+.?[0-9]*/gm, function (v) { - let r = - "" + - v + - ''; - return r; - }); - return newhtml; - } - function ReplaceEmails(str) { - let newhtml = str.replace( - /([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi, - function (v) { - let r = - "" + - v + - ''; - return r; - }, + const formatTel = (str, type) => + str.split(/\+?[0-9]( ?[0-9/-]+)+.?[0-9]*/gm).map((v, i) => + i % 2 === 0 ? ( + {` ${v} `} + ) : ( + + {v} + + ), ); - return newhtml; - } + + const formatEmail = (str) => + str + .split(/([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)/gi) + .map((v, i) => + i % 2 === 0 ? ( + {` ${v} `} + ) : ( + + {v} + + ), + ); if (tel) { - ret_label = intl.formatMessage(messages.telefono); - ret = ReplacePhoneNumbers(tel, 'tel'); + return ( + <> + {label && + (strong ? ( + {intl.formatMessage(messages.telefono)} + ) : ( + intl.formatMessage(messages.telefono) + ))} + {formatTel(tel, 'tel')} + + ); } else if (fax) { - ret_label = intl.formatMessage(messages.fax); - ret = ReplacePhoneNumbers(fax, 'fax'); + return ( + <> + {label && + (strong ? ( + {intl.formatMessage(messages.fax)} + ) : ( + intl.formatMessage(messages.fax) + ))} + {formatTel(fax, 'fax')} + + ); } else if (email) { - ret_label = intl.formatMessage(messages.email_label); - ret = ReplaceEmails(email); + return ( + <> + {label && + (strong ? ( + {intl.formatMessage(messages.email_label)} + ) : ( + intl.formatMessage(messages.email_label) + ))} + {formatEmail(email)} + + ); + } else { + return null; } - ret_label = label ? <>{ret_label}: : null; - ret_label = label ? strong ? {ret_label} : ret_label : null; - - return ret ? ( - <> - {ret_label} - - - ) : null; }; ContactLink.propTypes = { tel: PropTypes.string, + fax: PropTypes.string, + email: PropTypes.string, + label: PropTypes.bool, + strong: PropTypes.bool, }; export default ContactLink; From 86ffb97c1c520cbb0eb74474485d263801523a33 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Sat, 23 Nov 2024 01:09:11 +0100 Subject: [PATCH 2/3] fix: phone regex --- .../ItaliaTheme/View/Commons/ContactLink.jsx | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/components/ItaliaTheme/View/Commons/ContactLink.jsx b/src/components/ItaliaTheme/View/Commons/ContactLink.jsx index 8a8ed7403..6b7544aab 100644 --- a/src/components/ItaliaTheme/View/Commons/ContactLink.jsx +++ b/src/components/ItaliaTheme/View/Commons/ContactLink.jsx @@ -33,23 +33,27 @@ const ContactLink = ({ tel, fax, email, label = true, strong = false }) => { const intl = useIntl(); const formatTel = (str, type) => - str.split(/\+?[0-9]( ?[0-9/-]+)+.?[0-9]*/gm).map((v, i) => - i % 2 === 0 ? ( - {` ${v} `} - ) : ( - - {v} - - ), - ); + str + .split( + /((?:\+?\d{1,3}[-.\s]?)?(?:\(?\d{3}\)?[-.\s]?)?\d{3}[-.\s]?\d{4})/gm, + ) + .map((v, i) => + i % 2 === 0 ? ( + {` ${v} `} + ) : ( + + {v} + + ), + ); const formatEmail = (str) => str From 5063713473dd93872a65ff75280389ad06f600c3 Mon Sep 17 00:00:00 2001 From: Mauro Amico Date: Sat, 23 Nov 2024 01:22:50 +0100 Subject: [PATCH 3/3] fix: phone regex --- src/components/ItaliaTheme/View/Commons/ContactLink.jsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/ItaliaTheme/View/Commons/ContactLink.jsx b/src/components/ItaliaTheme/View/Commons/ContactLink.jsx index 6b7544aab..cfbfc3d94 100644 --- a/src/components/ItaliaTheme/View/Commons/ContactLink.jsx +++ b/src/components/ItaliaTheme/View/Commons/ContactLink.jsx @@ -34,9 +34,7 @@ const ContactLink = ({ tel, fax, email, label = true, strong = false }) => { const formatTel = (str, type) => str - .split( - /((?:\+?\d{1,3}[-.\s]?)?(?:\(?\d{3}\)?[-.\s]?)?\d{3}[-.\s]?\d{4})/gm, - ) + .split(/((?:\+?\d{1,3}[-.\s]?)?(?:\(?\d{3}\)?[-.\s]?)?\d{3}[-.\s]?\d+)/gm) .map((v, i) => i % 2 === 0 ? ( {` ${v} `}