Skip to content

Commit 24600e2

Browse files
committed
Add client-side URL validation for social media fields
1 parent aad245a commit 24600e2

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

app/[locale]/dashboard/[entityType]/[entitySlug]/profile/userProfile.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ const updateUserMutation: any = graphql(`
3535
}
3636
`);
3737

38+
const urlRegex = /^(https?:\/\/)([\w-]+\.)+[\w-]{2,}(\/\S*)?$/;
39+
3840
const UserProfile = () => {
3941
const params = useParams<{ entityType: string; entitySlug: string }>();
4042

@@ -112,7 +114,22 @@ const UserProfile = () => {
112114
if (!formValidation) {
113115
toast('Please fill all the required fields');
114116
return;
115-
} else {
117+
}
118+
if (formData.githubProfile && !urlRegex.test(formData.githubProfile)) {
119+
toast.error('Enter a valid GitHub URL');
120+
return;
121+
}
122+
123+
if (formData.linkedinProfile && !urlRegex.test(formData.linkedinProfile)) {
124+
toast.error('Enter a valid LinkedIn URL');
125+
return;
126+
}
127+
128+
if (formData.twitterProfile && !urlRegex.test(formData.twitterProfile)) {
129+
toast.error('Enter a valid Twitter URL');
130+
return;
131+
}
132+
else {
116133
const inputData: UpdateUserInput = {
117134
firstName: formData.firstName,
118135
lastName: formData.lastName,

0 commit comments

Comments
 (0)