Skip to content

Commit 9b4af5e

Browse files
committed
Update PartnerProfileForm to use optional chaining for URL checks and enhance URL regex for better flexibility
1 parent d9560ec commit 9b4af5e

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

frontend/src/components/PartnerProfileForm.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function PartnerProfileForm({
141141
<Input />
142142
</Form.Item>
143143
)}
144-
{(!hub_user || !hub_user.url.includes("AUAF")) && (
144+
{(!hub_user || !hub_user.url?.includes("AUAF")) && (
145145
<Form.Item
146146
label={t("partnerProfile.organizationName")}
147147
name="organization"
@@ -195,7 +195,7 @@ function PartnerProfileForm({
195195
</Form.Item>
196196
</div>
197197
) : null}
198-
{hub_user && hub_user.url.includes("AUAF") && (
198+
{hub_user && hub_user.url?.includes("AUAF") && (
199199
<Form.Item
200200
label={t("partnerProfile.title")}
201201
name="title"
@@ -210,7 +210,7 @@ function PartnerProfileForm({
210210
<Input />
211211
</Form.Item>
212212
)}
213-
{(!hub_user || !hub_user.url.includes("AUAF")) && (
213+
{(!hub_user || !hub_user.url?.includes("AUAF")) && (
214214
<Form.Item
215215
label={t("partnerProfile.location")}
216216
name="location"
@@ -227,7 +227,7 @@ function PartnerProfileForm({
227227
)}
228228
<Form.Item
229229
label={
230-
hub_user && hub_user.url.includes("AUAF")
230+
hub_user && hub_user.url?.includes("AUAF")
231231
? t("partnerProfile.AUAFcontactFullName")
232232
: t("partnerProfile.contactFullName")
233233
}
@@ -241,7 +241,7 @@ function PartnerProfileForm({
241241
>
242242
<Input />
243243
</Form.Item>
244-
{(!hub_user || !hub_user.url.includes("AUAF")) && (
244+
{(!hub_user || !hub_user.url?.includes("AUAF")) && (
245245
<Form.Item
246246
label={t("partnerProfile.regionsWork")}
247247
name="regions"
@@ -257,7 +257,7 @@ function PartnerProfileForm({
257257
)}
258258
<Form.Item
259259
label={
260-
hub_user && hub_user.url.includes("AUAF")
260+
hub_user && hub_user.url?.includes("AUAF")
261261
? t("partnerProfile.AUAFbriefIntro")
262262
: t("partnerProfile.briefIntro")
263263
}
@@ -271,7 +271,7 @@ function PartnerProfileForm({
271271
>
272272
<Input.TextArea rows={3} />
273273
</Form.Item>
274-
{!hub_user || !hub_user.url.includes("AUAF") ? (
274+
{!hub_user || !hub_user.url?.includes("AUAF") ? (
275275
<div className={styles.formGroup}>
276276
<Form.Item
277277
className={styles.formGroupItem}
@@ -340,10 +340,10 @@ function PartnerProfileForm({
340340
>
341341
<Select mode="multiple" options={getSDGs(t)} />
342342
</Form.Item>
343-
{(!hub_user || !hub_user.url.includes("AUAF")) && (
343+
{(!hub_user || !hub_user.url?.includes("AUAF")) && (
344344
<Form.Item
345345
label={
346-
hub_user && hub_user.url === "GSRFoundation"
346+
hub_user && hub_user.url?.includes("GSRFoundation")
347347
? t("partnerProfile.projectNames_GSR")
348348
: t("partnerProfile.projectNames")
349349
}
@@ -353,12 +353,12 @@ function PartnerProfileForm({
353353
</Form.Item>
354354
)}
355355

356-
{hub_user && hub_user.url === "GSRFoundation" && (
356+
{hub_user && hub_user.url?.includes("GSRFoundation") && (
357357
<Form.Item label={t("partnerProfile.success_GSR")} name="success">
358358
<Input.TextArea rows={3} />
359359
</Form.Item>
360360
)}
361-
{(!hub_user || !hub_user.url.includes("AUAF")) && (
361+
{(!hub_user || !hub_user.url?.includes("AUAF")) && (
362362
<div className={styles.formGroup}>
363363
<Form.Item
364364
label={t("partnerProfile.collaborationGrants")}

frontend/src/utils/misc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,13 @@ export const validateEmail = (email) => {
1616
return re.test(String(email).toLowerCase());
1717
};
1818

19+
// More flexible URL regex that accepts:
20+
// - URLs with or without protocol (http/https)
21+
// - URLs starting with www.
22+
// - Domain names without protocol or www (e.g., example.com)
23+
// - LinkedIn URLs with special characters
1924
export const urlRegex =
20-
/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
25+
/^(?:(?:(?:https?|ftp):)?\/\/)?(?:www\.)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
2126

2227
export const validateUrl = (value) => {
2328
return urlRegex.test(value);

0 commit comments

Comments
 (0)