From d29b899134534bc4f25222e266bd85e4a3f41439 Mon Sep 17 00:00:00 2001 From: Xitang Date: Mon, 3 Jul 2023 21:44:56 -0700 Subject: [PATCH] Reformat link src logic --- .../Resume/ResumePDF/ResumePDFProfile.tsx | 33 +++++++------------ 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/src/app/components/Resume/ResumePDF/ResumePDFProfile.tsx b/src/app/components/Resume/ResumePDF/ResumePDFProfile.tsx index d697f03..a01f522 100644 --- a/src/app/components/Resume/ResumePDF/ResumePDFProfile.tsx +++ b/src/app/components/Resume/ResumePDF/ResumePDFProfile.tsx @@ -56,34 +56,23 @@ export const ResumePDFProfile = ({ const Wrapper = ({ children }: { children: React.ReactNode }) => { if (!shouldUseLinkWrapper) return <>{children}; - let urlSrc = ""; - + let src = ""; switch (key) { - case "email": - urlSrc = `mailto:${value}`; + case "email": { + src = `mailto:${value}`; break; - - case "phone": - urlSrc = `tel:${value.replace(/[^\d+]/g, "")}`; - break; - - case "url": - let removalCases = ["http://", "https://"]; - let http_protocol = "https://"; - - removalCases.forEach((item) => { - if (value.startsWith(item)) { - value = value.substring(item.length - 1, value.length - 1); - http_protocol = item; - } - }); - - urlSrc = `${http_protocol}${value}`; + } + case "phone": { + src = `tel:${value.replace(/[^\d+]/g, "")}`; // Keep only + and digits break; + } + default: { + src = value.startsWith("http") ? value : `https://${value}`; + } } return ( - + {children} );