Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/apps/onboarding/src/pages/skills/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const PageSkillsContent: FC<{
}> = props => {
const navigate: any = useNavigate()
const [loading, setLoading] = useState(false)
const { formInput: emsiFormInput, saveSkills: saveEmsiSkills }: MemberSkillEditor = useMemberSkillEditor()
const { formInput: emsiFormInput, saveSkills: saveEmsiSkills }: MemberSkillEditor = useMemberSkillEditor({
limit: 15,
})

async function saveSkills(): Promise<void> {
setLoading(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const fetchSkills = (queryTerm: string): Promise<Option[]> => (
)

interface InputSkillSelectorProps {
readonly limit?: number
readonly loading?: boolean
readonly value?: EmsiSkill[]
readonly onChange?: (event: ChangeEvent<HTMLInputElement>) => void
Expand All @@ -36,6 +37,7 @@ interface InputSkillSelectorProps {
const InputSkillSelector: FC<InputSkillSelectorProps> = props => (
<InputMultiselect
label='Select Skills'
limit={props.limit}
placeholder='Type to add a skill...'
onFetchOptions={fetchSkills}
name='skills'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export interface MemberSkillEditor {
* @returns
*/

export const useMemberSkillEditor = (): MemberSkillEditor => {
export const useMemberSkillEditor = ({
limit,
}: {limit?: number} = {}): MemberSkillEditor => {
const { profile }: ProfileContextData = useContext(profileContext)
const [isEmsiInitialized, setIsEmsiInitialized] = useState<boolean>(false)
const [skills, setSkills] = useState<EmsiSkill[]>([])
Expand Down Expand Up @@ -120,8 +122,13 @@ export const useMemberSkillEditor = (): MemberSkillEditor => {

// build the form input
const formInput = useMemo(() => (
<InputSkillSelector value={skills} onChange={handleOnChange} loading={loading} />
), [skills, handleOnChange, loading])
<InputSkillSelector
value={skills}
onChange={handleOnChange}
loading={loading}
limit={limit}
/>
), [skills, handleOnChange, loading, limit])

return {
formInput,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface InputMultiselectProps {
readonly hideInlineErrors?: boolean
readonly hint?: string
readonly label?: string
readonly limit?: number
readonly name: string
readonly onChange: (event: ChangeEvent<HTMLInputElement>) => void
readonly options?: ReadonlyArray<InputMultiselectOption>
Expand Down Expand Up @@ -55,6 +56,10 @@ const InputMultiselect: FC<InputMultiselectProps> = (props: InputMultiselectProp
} as unknown as ChangeEvent<HTMLInputElement>)
}

function isOptionDisabled(): boolean {
return !!props.limit && (props.value?.length as number) >= props.limit
}

return (
<InputWrapper
{...props}
Expand All @@ -63,6 +68,7 @@ const InputMultiselect: FC<InputMultiselectProps> = (props: InputMultiselectProp
label={(props.label || props.name) ?? 'Select Option'}
hideInlineErrors={props.hideInlineErrors}
type='text'
hint={props.limit ? ` (max ${props.limit})` : undefined}
>
<AsyncSelect
className={styles.multiselect}
Expand All @@ -79,6 +85,8 @@ const InputMultiselect: FC<InputMultiselectProps> = (props: InputMultiselectProp
onBlur={noop}
blurInputOnSelect={false}
isLoading={props.loading}
isOptionDisabled={isOptionDisabled}
isSearchable={!isOptionDisabled()}
components={{ MultiValueRemove }}
value={props.value}
/>
Expand Down