Skip to content

Commit 84a2d1b

Browse files
authored
Merge pull request #928 from topcoder-platform/TSJR-14_standardized-skills-inputs
TSJR-14 update skill input to use standardized skills api
2 parents 82e4c11 + 1a8cb24 commit 84a2d1b

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ReactNode, useCallback, useContext, useEffect, useMemo, useState } from 'react'
2-
import { differenceWith } from 'lodash'
2+
import { differenceWith, pick } from 'lodash'
33

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

@@ -45,13 +45,15 @@ export const useMemberSkillEditor = ({
4545
return
4646
}
4747

48+
const skillIds = skills.map(skill => pick(skill, 'id'))
49+
4850
if (!isInitialized) {
49-
await createMemberSkills(profile.userId, skills)
51+
await createMemberSkills(profile.userId, skillIds)
5052
setIsInitialized(true)
5153
return
5254
}
5355

54-
await updateMemberSkills(profile.userId, skills)
56+
await updateMemberSkills(profile.userId, skillIds)
5557
}, [isInitialized, profile?.userId, skills])
5658

5759
// Handle user changes
Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { EnvironmentConfig } from '~/config'
22
import { UserSkill, xhrGetAsync, xhrPostAsync, xhrPutAsync } from '~/libs/core'
33

4-
const baseUrl = `${EnvironmentConfig.API.V5}/emsi-skills/member-emsi-skills`
4+
const baseUrl = `${EnvironmentConfig.API.V5}/standardized-skills`
5+
6+
export interface UpdateUserSkillDTO {
7+
id: string
8+
levelId?: string
9+
}
510

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

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

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

26-
export async function createMemberSkills(userId: number, skills: UserSkill[]): Promise<void> {
27-
return xhrPostAsync(baseUrl, {
31+
export async function createMemberSkills(userId: number, skills: UpdateUserSkillDTO[]): Promise<void> {
32+
return xhrPostAsync(`${baseUrl}/user-skills/${userId}`, {
2833
skills,
29-
userId,
3034
})
3135
}
3236

33-
export async function updateMemberSkills(userId: string | number, skills: UserSkill[]): Promise<void> {
34-
return xhrPutAsync(`${baseUrl}/${userId}`, {
37+
export async function updateMemberSkills(
38+
userId: string | number,
39+
skills: UpdateUserSkillDTO[],
40+
): Promise<void> {
41+
return xhrPutAsync(`${baseUrl}/user-skills/${userId}`, {
3542
skills,
3643
})
3744
}

0 commit comments

Comments
 (0)