Skip to content

Commit 73e1002

Browse files
committed
Profiles: social media panel feedback
1 parent 5fdbf03 commit 73e1002

File tree

3 files changed

+63
-27
lines changed

3 files changed

+63
-27
lines changed

src/apps/profiles/src/member-profile/links/ModifyMemberLinksModal/LinkForm/LinkForm.tsx

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { trim } from 'lodash'
2-
import { FC, forwardRef, ForwardRefExoticComponent, SVGProps, useEffect, useImperativeHandle, useState } from 'react'
2+
import {
3+
FC,
4+
forwardRef,
5+
ForwardRefExoticComponent,
6+
SVGProps,
7+
useEffect,
8+
useImperativeHandle,
9+
useRef,
10+
useState,
11+
} from 'react'
312
import classNames from 'classnames'
413

514
import { Button, IconOutline, InputSelect, InputText } from '~/libs/ui'
615

7-
import { linkTypes } from '../link-types.config'
16+
import { additionalLinkTypes } from '../link-types.config'
817
import { isValidURL } from '../../../../lib'
918
import { renderLinkIcon } from '../../MemberLinks'
1019

@@ -41,6 +50,8 @@ const LinkForm: ForwardRefExoticComponent<
4150
const [selectedLinkType, setSelectedLinkType] = useState<string | undefined>()
4251
const [selectedLinkURL, setSelectedLinkURL] = useState<string | undefined>()
4352
const [shouldValidateForm, setShouldValidateForm] = useState<boolean>(false)
53+
const canShowTypeError = useRef(false)
54+
const canShowUrlError = useRef(false)
4455

4556
useEffect(() => {
4657
if (shouldValidateForm) {
@@ -52,37 +63,58 @@ const LinkForm: ForwardRefExoticComponent<
5263
resetForm() {
5364
setShouldValidateForm(false)
5465
setFormErrors({})
66+
canShowTypeError.current = false
67+
canShowUrlError.current = false
5568
},
5669
validateForm() {
70+
canShowTypeError.current = true
71+
canShowUrlError.current = true
5772
handleFormAction()
5873
},
5974
}))
6075

6176
function handleSelectedLinkTypeChange(event: React.ChangeEvent<HTMLInputElement>): void {
77+
canShowTypeError.current = true
6278
setSelectedLinkType(event.target.value)
6379
setShouldValidateForm(true)
6480
}
6581

6682
function handleURLChange(event: React.ChangeEvent<HTMLInputElement>): void {
83+
canShowUrlError.current = true
6784
setSelectedLinkURL(event.target.value)
6885
setShouldValidateForm(true)
6986
}
7087

71-
function handleFormAction(): void {
88+
function getFormError(): boolean {
7289
setFormErrors({})
7390

91+
let isError = false
7492
if (!selectedLinkType) {
75-
setFormErrors({ selectedLinkType: 'Please select a link type' })
76-
return
93+
isError = true
94+
if (canShowTypeError.current) {
95+
setFormErrors({ selectedLinkType: 'Please select a link type' })
96+
}
7797
}
7898

7999
if (!props.allowEmptyUrl && !trim(selectedLinkURL)) {
80-
setFormErrors({ url: 'Please enter a URL' })
81-
return
100+
isError = true
101+
if (canShowUrlError.current) {
102+
setFormErrors({ url: 'Please enter a URL' })
103+
}
82104
}
83105

84106
if (selectedLinkURL && !isValidURL(selectedLinkURL as string)) {
85-
setFormErrors({ url: 'Invalid URL' })
107+
isError = true
108+
if (canShowUrlError.current) {
109+
setFormErrors({ url: 'Invalid URL' })
110+
}
111+
}
112+
113+
return isError
114+
}
115+
116+
function handleFormAction(): void {
117+
if (getFormError()) {
86118
return
87119
}
88120

@@ -91,14 +123,14 @@ const LinkForm: ForwardRefExoticComponent<
91123
if (absoluteURL.indexOf('://') > 0 || absoluteURL.indexOf('//') === 0) {
92124

93125
props.onSave({
94-
name: selectedLinkType,
126+
name: selectedLinkType ?? '',
95127
url: absoluteURL,
96128
})
97129
} else {
98130
absoluteURL = absoluteURL ? `https://${absoluteURL}` : ''
99131

100132
props.onSave({
101-
name: selectedLinkType,
133+
name: selectedLinkType ?? '',
102134
url: absoluteURL,
103135
})
104136
}
@@ -124,7 +156,7 @@ const LinkForm: ForwardRefExoticComponent<
124156
<div className={styles.form}>
125157
{props.allowEditType ? (
126158
<InputSelect
127-
options={linkTypes}
159+
options={additionalLinkTypes}
128160
value={selectedLinkType}
129161
onChange={handleSelectedLinkTypeChange}
130162
name='linkType'

src/apps/profiles/src/member-profile/links/ModifyMemberLinksModal/ModifyMemberLinksModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ const ModifyMemberLinksModal: FC<ModifyMemberLinksModalProps> = (props: ModifyMe
277277
<Button
278278
onClick={handleAddAdditional}
279279
secondary
280-
label='+ Additional Link'
280+
label='+ Add link'
281281
disabled={isSaving}
282282
/>
283283
</div>
Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
export const linkTypes = [
1+
export const additionalLinkTypes = [
22
{
3-
name: 'Facebook',
4-
value: 'Facebook',
3+
name: 'Twitter',
4+
value: 'X / Twitter',
55
},
66
{
7-
name: 'GitHub',
8-
value: 'GitHub',
7+
name: 'Website',
8+
value: 'Website',
99
},
1010
{
11-
name: 'Instagram',
12-
value: 'Instagram',
11+
name: 'YouTube',
12+
value: 'YouTube',
1313
},
1414
{
15-
name: 'LinkedIn',
16-
value: 'LinkedIn',
15+
name: 'Facebook',
16+
value: 'Facebook',
1717
},
18+
]
19+
20+
export const linkTypes = [
1821
{
19-
name: 'Twitter',
20-
value: 'X / Twitter',
22+
name: 'LinkedIn',
23+
value: 'LinkedIn',
2124
},
2225
{
23-
name: 'Website',
24-
value: 'Website',
26+
name: 'GitHub',
27+
value: 'GitHub',
2528
},
2629
{
27-
name: 'YouTube',
28-
value: 'YouTube',
30+
name: 'Instagram',
31+
value: 'Instagram',
2932
},
33+
...additionalLinkTypes,
3034
]

0 commit comments

Comments
 (0)