-
Notifications
You must be signed in to change notification settings - Fork 21
feat(PM-3398): added description and associated skills field in Add/Update Work experience modal, work card in Profile Page #1398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| import { Dispatch, FC, SetStateAction, useEffect, useMemo, useState } from 'react' | ||
| import { Dispatch, FC, SetStateAction, useCallback, useEffect, useMemo, useState } from 'react' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| import { useSearchParams } from 'react-router-dom' | ||
| import { SWRResponse } from 'swr' | ||
|
|
||
| import { MemberTraitsAPI, useMemberTraits, UserProfile, UserTrait, UserTraitIds } from '~/libs/core' | ||
| import { MemberTraitsAPI, useMemberTraits, UserProfile, UserSkill, UserTrait, UserTraitIds } from '~/libs/core' | ||
| import { useSkillsByIds } from '~/libs/shared/lib/services/standard-skills' | ||
|
|
||
| import { EDIT_MODE_QUERY_PARAM, profileEditModes } from '../../config' | ||
| import { AddButton, EditMemberPropertyBtn, EmptySection } from '../../components' | ||
|
|
@@ -31,6 +33,66 @@ const WorkExpirence: FC<WorkExpirenceProps> = (props: WorkExpirenceProps) => { | |
| const workExpirence: UserTrait[] | undefined | ||
| = useMemo(() => memberWorkExpirenceTraits?.[0]?.traits?.data, [memberWorkExpirenceTraits]) | ||
|
|
||
| // Collect all unique skill IDs from work experience entries | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| const allSkillIds = useMemo(() => { | ||
| if (!workExpirence) { | ||
| return [] | ||
| } | ||
|
|
||
| const skillIdsSet = new Set<string>() | ||
| workExpirence.forEach((work: UserTrait) => { | ||
| if (work.associatedSkills && Array.isArray(work.associatedSkills)) { | ||
| work.associatedSkills.forEach((skillId: string) => { | ||
| if (skillId && typeof skillId === 'string') { | ||
| skillIdsSet.add(skillId) | ||
| } | ||
| }) | ||
| } | ||
| }) | ||
|
|
||
| return Array.from(skillIdsSet) | ||
| }, [workExpirence]) | ||
|
|
||
| const { data: fetchedSkills, error: skillsError }: SWRResponse<UserSkill[], Error> = useSkillsByIds( | ||
hentrymartin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| allSkillIds.length > 0 ? allSkillIds : undefined, | ||
| ) | ||
|
|
||
| // Determine loading state: data is undefined and no error yet | ||
| const loadingSkills = fetchedSkills === undefined && !skillsError | ||
|
|
||
| // Build skill names map from fetched skills | ||
| const skillNamesMap = useMemo(() => { | ||
| const map: Record<string, string> = {} | ||
|
|
||
| if (fetchedSkills) { | ||
| fetchedSkills.forEach(skill => { | ||
| if (skill.id && skill.name) { | ||
| map[skill.id] = skill.name | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| // For skills that weren't found, use ID as fallback | ||
| allSkillIds.forEach(skillId => { | ||
| if (!map[skillId]) { | ||
| map[skillId] = skillId | ||
| } | ||
| }) | ||
|
|
||
| return map | ||
| }, [fetchedSkills, allSkillIds]) | ||
|
|
||
| const areSkillsLoaded = useCallback((work: UserTrait): boolean => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| if (!work.associatedSkills || !Array.isArray(work.associatedSkills) || work.associatedSkills.length === 0) { | ||
| return true | ||
| } | ||
|
|
||
| return work.associatedSkills.every((skillId: string) => { | ||
| const skillName = skillNamesMap[skillId] | ||
| return skillName && skillName !== skillId | ||
| }) | ||
| }, [skillNamesMap]) | ||
|
|
||
| useEffect(() => { | ||
| if (props.authProfile && editMode === profileEditModes.workExperience) { | ||
| setIsEditMode(true) | ||
|
|
@@ -83,6 +145,8 @@ const WorkExpirence: FC<WorkExpirenceProps> = (props: WorkExpirenceProps) => { | |
| <WorkExpirenceCard | ||
| key={uniqueKey || `${work.position || 'experience'}-${index}`} | ||
| work={work} | ||
| skillNamesMap={skillNamesMap} | ||
| showSkills={!loadingSkills && areSkillsLoaded(work)} | ||
| /> | ||
| ) | ||
| }) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.