Skip to content

Commit c4704cf

Browse files
committed
#716 - limit the max no of skills selected in onboarding
1 parent 6e1bae7 commit c4704cf

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/apps/onboarding/src/pages/skills/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export const PageSkillsContent: FC<{
1616
}> = props => {
1717
const navigate: any = useNavigate()
1818
const [loading, setLoading] = useState(false)
19-
const { formInput: emsiFormInput, saveSkills: saveEmsiSkills }: MemberSkillEditor = useMemberSkillEditor()
19+
const { formInput: emsiFormInput, saveSkills: saveEmsiSkills }: MemberSkillEditor = useMemberSkillEditor({
20+
limit: 15,
21+
})
2022

2123
async function saveSkills(): Promise<void> {
2224
setLoading(true)

src/libs/shared/lib/components/input-skill-selector/InputSkillSelector.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const fetchSkills = (queryTerm: string): Promise<Option[]> => (
2828
)
2929

3030
interface InputSkillSelectorProps {
31+
readonly limit?: number
3132
readonly loading?: boolean
3233
readonly value?: EmsiSkill[]
3334
readonly onChange?: (event: ChangeEvent<HTMLInputElement>) => void
@@ -36,6 +37,7 @@ interface InputSkillSelectorProps {
3637
const InputSkillSelector: FC<InputSkillSelectorProps> = props => (
3738
<InputMultiselect
3839
label='Select Skills'
40+
limit={props.limit}
3941
placeholder='Type to add a skill...'
4042
onFetchOptions={fetchSkills}
4143
name='skills'

src/libs/shared/lib/components/member-skill-editor/use-member-skill-editor.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ export interface MemberSkillEditor {
3131
* @returns
3232
*/
3333

34-
export const useMemberSkillEditor = (): MemberSkillEditor => {
34+
export const useMemberSkillEditor = ({
35+
limit,
36+
}: {limit?: number} = {}): MemberSkillEditor => {
3537
const { profile }: ProfileContextData = useContext(profileContext)
3638
const [isEmsiInitialized, setIsEmsiInitialized] = useState<boolean>(false)
3739
const [skills, setSkills] = useState<EmsiSkill[]>([])
@@ -120,8 +122,13 @@ export const useMemberSkillEditor = (): MemberSkillEditor => {
120122

121123
// build the form input
122124
const formInput = useMemo(() => (
123-
<InputSkillSelector value={skills} onChange={handleOnChange} loading={loading} />
124-
), [skills, handleOnChange, loading])
125+
<InputSkillSelector
126+
value={skills}
127+
onChange={handleOnChange}
128+
loading={loading}
129+
limit={limit}
130+
/>
131+
), [skills, handleOnChange, loading, limit])
125132

126133
return {
127134
formInput,

src/libs/ui/lib/components/form/form-groups/form-input/input-multiselect/InputMultiselect.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface InputMultiselectProps {
2626
readonly hideInlineErrors?: boolean
2727
readonly hint?: string
2828
readonly label?: string
29+
readonly limit?: number
2930
readonly name: string
3031
readonly onChange: (event: ChangeEvent<HTMLInputElement>) => void
3132
readonly options?: ReadonlyArray<InputMultiselectOption>
@@ -55,6 +56,10 @@ const InputMultiselect: FC<InputMultiselectProps> = (props: InputMultiselectProp
5556
} as unknown as ChangeEvent<HTMLInputElement>)
5657
}
5758

59+
function isOptionDisabled(): boolean {
60+
return !!props.limit && (props.value?.length as number) >= props.limit
61+
}
62+
5863
return (
5964
<InputWrapper
6065
{...props}
@@ -63,6 +68,7 @@ const InputMultiselect: FC<InputMultiselectProps> = (props: InputMultiselectProp
6368
label={(props.label || props.name) ?? 'Select Option'}
6469
hideInlineErrors={props.hideInlineErrors}
6570
type='text'
71+
hint={props.limit ? ` (max ${props.limit})` : undefined}
6672
>
6773
<AsyncSelect
6874
className={styles.multiselect}
@@ -79,6 +85,8 @@ const InputMultiselect: FC<InputMultiselectProps> = (props: InputMultiselectProp
7985
onBlur={noop}
8086
blurInputOnSelect={false}
8187
isLoading={props.loading}
88+
isOptionDisabled={isOptionDisabled}
89+
isSearchable={!isOptionDisabled()}
8290
components={{ MultiValueRemove }}
8391
value={props.value}
8492
/>

0 commit comments

Comments
 (0)