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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactNode, useCallback, useContext, useEffect, useMemo, useState } from 'react'
import { differenceWith } from 'lodash'
import { differenceWith, pick } from 'lodash'

import { profileContext, ProfileContextData, UserSkill } from '~/libs/core'

Expand Down Expand Up @@ -45,13 +45,15 @@ export const useMemberSkillEditor = ({
return
}

const skillIds = skills.map(skill => pick(skill, 'id'))

if (!isInitialized) {
await createMemberSkills(profile.userId, skills)
await createMemberSkills(profile.userId, skillIds)
setIsInitialized(true)
return
}

await updateMemberSkills(profile.userId, skills)
await updateMemberSkills(profile.userId, skillIds)
}, [isInitialized, profile?.userId, skills])

// Handle user changes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { EnvironmentConfig } from '~/config'
import { UserSkill, xhrGetAsync, xhrPostAsync, xhrPutAsync } from '~/libs/core'

const baseUrl = `${EnvironmentConfig.API.V5}/emsi-skills/member-emsi-skills`
const baseUrl = `${EnvironmentConfig.API.V5}/standardized-skills`

export interface UpdateUserSkillDTO {
id: string
levelId?: string
}

export async function autoCompleteSkills(queryTerm: string): Promise<UserSkill[]> {
if (!queryTerm) {
return Promise.resolve([])
}

const encodedQuery = encodeURIComponent(queryTerm)
return xhrGetAsync(`${EnvironmentConfig.API.V5}/emsi-skills/skills/auto-complete?term=${encodedQuery}`)
return xhrGetAsync(`${baseUrl}/skills/autocomplete?term=${encodedQuery}`)
}

export type FetchMemberSkillsConfig = {
Expand All @@ -19,19 +24,21 @@ export async function fetchMemberSkills(
userId: string | number | undefined,
config: FetchMemberSkillsConfig,
): Promise<UserSkill[]> {
const url = `${baseUrl}/${userId}?pageFlag=${!config.skipPagination}`
const url = `${baseUrl}/user-skills/${userId}?disablePagination=${config.skipPagination}`
return xhrGetAsync(url)
}

export async function createMemberSkills(userId: number, skills: UserSkill[]): Promise<void> {
return xhrPostAsync(baseUrl, {
export async function createMemberSkills(userId: number, skills: UpdateUserSkillDTO[]): Promise<void> {
return xhrPostAsync(`${baseUrl}/user-skills/${userId}`, {
skills,
userId,
})
}

export async function updateMemberSkills(userId: string | number, skills: UserSkill[]): Promise<void> {
return xhrPutAsync(`${baseUrl}/${userId}`, {
export async function updateMemberSkills(
userId: string | number,
skills: UpdateUserSkillDTO[],
): Promise<void> {
return xhrPutAsync(`${baseUrl}/user-skills/${userId}`, {
skills,
})
}