Skip to content

Commit 3c1fbb7

Browse files
committed
TSJR-314 - throw error when creating duplicate skill
1 parent e4bb311 commit 3c1fbb7

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/apps/admin/src/skills-manager/components/skill-modals/skill-form/SkillForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const SkillForm: FC<SkillFormProps> = props => {
3535
const {
3636
categories,
3737
refetchCategories,
38-
skillsList,
38+
allSkills: skillsList,
3939
}: SkillsManagerContextValue = useSkillsManagerContext()
4040

4141
const [forceUpdate, setForceUpdate] = useState(false)

src/apps/admin/src/skills-manager/context/skills-manager.context.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { findSkillsMatches, GroupedSkills, groupSkillsByCategory } from '../lib'
77
import { SkillsBulkEditorContext, useSkillsBulkEditorContext } from './use-skills-bulk-editor-context'
88

99
export interface SkillsManagerContextValue {
10+
allSkills: StandardizedSkill[],
1011
categories: StandardizedSkillCategory[]
1112
skillsFilter: string
1213
setSkillsFilter: (filter: string) => void
@@ -37,16 +38,20 @@ export const SkillsManagerContext: FC<SkillsManagerContextProps> = props => {
3738
const [editSkill, setEditSkill] = useState<StandardizedSkill>()
3839

3940
const {
40-
data: allSkills,
41+
data: allSkills = [],
4142
mutate: refetchSkills,
42-
}: SWRResponse<StandardizedSkill[]> = useFetchSkills(showArchivedSkills)
43+
}: SWRResponse<StandardizedSkill[]> = useFetchSkills(true)
4344

4445
const {
4546
data: allCategories = [],
4647
mutate: refetchCategories,
4748
}: SWRResponse<StandardizedSkillCategory[]> = useFetchCategories()
4849

49-
const skills = useMemo(() => findSkillsMatches(allSkills ?? [], skillsFilter), [allSkills, skillsFilter])
50+
const filteredSkills = useMemo(() => (
51+
showArchivedSkills ? allSkills : allSkills.filter(s => !s.deleted_at)
52+
), [allSkills, showArchivedSkills])
53+
54+
const skills = useMemo(() => findSkillsMatches(filteredSkills, skillsFilter), [filteredSkills, skillsFilter])
5055
const groupedSkills = useMemo(() => groupSkillsByCategory(skills), [skills])
5156

5257
const bulkEditorCtx = useSkillsBulkEditorContext(skills)
@@ -56,6 +61,7 @@ export const SkillsManagerContext: FC<SkillsManagerContextProps> = props => {
5661
}, [])
5762

5863
const contextValue = useMemo(() => ({
64+
allSkills,
5965
bulkEditorCtx,
6066
categories: allCategories,
6167
editCategory,
@@ -71,6 +77,7 @@ export const SkillsManagerContext: FC<SkillsManagerContextProps> = props => {
7177
skillsList: skills,
7278
toggleArchivedSkills,
7379
}), [
80+
allSkills,
7481
bulkEditorCtx,
7582
allCategories,
7683
editCategory,

0 commit comments

Comments
 (0)