Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
fix: if there's an email in the blog link, make it a 'mailto' link.
Browse files Browse the repository at this point in the history
  • Loading branch information
sametcn99 committed Feb 25, 2024
1 parent 4af8891 commit 214d636
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
12 changes: 9 additions & 3 deletions components/ProfileCard/ProfileCardFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import SocialLinks from "./SocialLinks";
import { createUrlObject } from "@/lib/utils";
import { checkEmail, createUrlObject } from "@/lib/utils";
import { MdOutlineWorkOutline } from "react-icons/md";
import { TfiWorld } from "react-icons/tfi";
import { Box, Link, Text } from "@radix-ui/themes";
Expand Down Expand Up @@ -27,12 +27,18 @@ export default function ProfileCardFooter({
<Box className="flex w-full flex-row flex-wrap items-center justify-center gap-2">
{userData.blog && (
<Link
href={createUrlObject(userData.blog).href}
href={
checkEmail(userData.blog)
? `mailto:${userData.blog}`
: createUrlObject(userData.blog).href
}
className="dialog-trigger"
target="_blank"
>
<TfiWorld />
{createUrlObject(userData.blog).host}
{checkEmail(userData.blog)
? `${userData.blog}`
: createUrlObject(userData.blog).href}
</Link>
)}
{userData.company && (
Expand Down
2 changes: 1 addition & 1 deletion components/ProfileCard/ProfileCardHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function ProfileCardHeader({
@{userData.login}
</Link>
{userData.bio && (
<Text className="break-all text-base font-normal md:break-normal">
<Text className="break-words text-base font-normal md:break-normal">
{userData.bio}
</Text>
)}
Expand Down
6 changes: 6 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export const createUrlObject = (link: string) => {
return url;
};

export const checkEmail = (email: string) => {
const regex =
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return regex.test(String(email).toLowerCase());
};

export async function fetchContact(
username: string,
option: string,
Expand Down

1 comment on commit 214d636

@vercel
Copy link

@vercel vercel bot commented on 214d636 Feb 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.