Skip to content

Commit 0f290cb

Browse files
committed
requested changes for Update logic to get twitter username
1 parent d9e8630 commit 0f290cb

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

components/sessions/SpeakersDetails.tsx

+6-11
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@ export const SpeakersDetails = ({ session }: { session: Session }) => {
1515
return null
1616
}
1717

18-
const getTwitterUsername = (url: string) => {
19-
if (url.includes('twitter.com/')) {
20-
return url.split('twitter.com/')[1]
21-
}
22-
if (url.includes('x.com/')) {
23-
return url.split('x.com/')[1]
24-
}
25-
return null
18+
const getTwitterUsername = (url: string): string | null => {
19+
if (!url) return null
20+
const match = url.match(/(?:twitter\.com|x\.com)\/([^/?#]+)/i)
21+
return match?.[1] ?? null
2622
}
2723

2824
return (
@@ -73,9 +69,8 @@ export const SpeakersDetails = ({ session }: { session: Session }) => {
7369
className="text-primary dark:text-accent text-sm lowercase font-medium"
7470
>
7571
@
76-
{speaker.twitter
77-
? getTwitterUsername(speaker.twitter)
78-
: speaker.name}
72+
{getTwitterUsername(speaker.twitter ?? '') ||
73+
speaker.name}
7974
</a>
8075
</a>
8176
</p>

0 commit comments

Comments
 (0)