Skip to content

Commit cf00541

Browse files
committed
Automatically add https protocol in dref form source information url
1 parent ee2d812 commit cf00541

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"namespace": "drefApplicationForm",
33
"strings": {
4-
"sourceInformationNameLabel": "Sources of information (optional) name",
5-
"sourceInformationLinkLabel": "Sources of information (optional) link",
4+
"sourceInformationNameLabel": "Name",
5+
"sourceInformationLinkLabel": "Link",
66
"sourceInformationDeleteButton": "Delete Source Information"
77
}
88
}

src/views/DrefApplicationForm/EventDetail/SourceInformationInput/index.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { useCallback } from 'react';
12
import {
23
type ArrayError,
34
useFormObject,
45
getErrorObject,
56
type SetValueArg,
67
} from '@togglecorp/toggle-form';
78
import { DeleteBinTwoLineIcon } from '@ifrc-go/icons';
8-
import { randomString } from '@togglecorp/fujs';
9+
import { isNotDefined, randomString } from '@togglecorp/fujs';
910

1011
import Button from '#components/Button';
1112
import NonFieldError from '#components/NonFieldError';
@@ -51,6 +52,31 @@ function SourceInformationInput(props: Props) {
5152
? getErrorObject(errorFromProps?.[value.client_id])
5253
: undefined;
5354

55+
const handleSourceFieldChange = useCallback(
56+
(newValue: string | undefined) => {
57+
if (
58+
isNotDefined(newValue)
59+
|| newValue.startsWith('http://')
60+
|| newValue.startsWith('https://')
61+
|| newValue === 'h'
62+
|| newValue === 'ht'
63+
|| newValue === 'htt'
64+
|| newValue === 'http'
65+
|| newValue === 'http:'
66+
|| newValue === 'http:/'
67+
|| newValue === 'https'
68+
|| newValue === 'https:'
69+
|| newValue === 'https:/'
70+
) {
71+
onFieldChange(newValue, 'source_link');
72+
return;
73+
}
74+
75+
onFieldChange(`https://${newValue}`, 'source_link');
76+
},
77+
[onFieldChange],
78+
);
79+
5480
return (
5581
<div className={styles.sourceInformationInput}>
5682
<NonFieldError error={error} />
@@ -69,7 +95,7 @@ function SourceInformationInput(props: Props) {
6995
name="source_link"
7096
value={value.source_link}
7197
error={error?.source_link}
72-
onChange={onFieldChange}
98+
onChange={handleSourceFieldChange}
7399
disabled={disabled}
74100
/>
75101
<Button

0 commit comments

Comments
 (0)