Skip to content

Commit 077f6e6

Browse files
committed
TSJR-314 - more updates to admin skill
1 parent f6012f6 commit 077f6e6

File tree

22 files changed

+625
-330
lines changed

22 files changed

+625
-330
lines changed

src/apps/admin/src/skills-manager/components/bulk-editor/BulkEditor.tsx

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,45 @@ import { Button } from '~/libs/ui'
66
import { SkillsManagerContextValue, useSkillsManagerContext } from '../../context'
77

88
import { ArchiveSkillsModal } from './archive-skills-modal'
9+
import { MoveSkillsModal } from './move-skills-modal'
910
import styles from './BulkEditor.module.scss'
1011

1112
interface BulkEditorProps {
1213
className?: string
1314
}
1415

1516
const BulkEditor: FC<BulkEditorProps> = props => {
16-
const { bulkEditorCtx: context }: SkillsManagerContextValue = useSkillsManagerContext()
17+
const {
18+
bulkEditorCtx: context,
19+
refetchSkills,
20+
}: SkillsManagerContextValue = useSkillsManagerContext()
21+
1722
const [showArchive, setShowArchive] = useState(false)
23+
const [showMoveSkills, setShowMoveSkills] = useState(false)
24+
25+
function openArchiveModal(): void {
26+
setShowArchive(true)
27+
}
28+
29+
function openMoveSkillsModal(): void {
30+
setShowMoveSkills(true)
31+
}
32+
33+
function closeArchiveModal(archived?: boolean): void {
34+
if (archived) {
35+
refetchSkills()
36+
context.toggleAll()
37+
}
1838

19-
function toggleArchive(): void {
20-
setShowArchive(d => !d)
39+
setShowArchive(false)
40+
}
41+
42+
function closeMoveSkillsModal(moved?: boolean): void {
43+
if (moved) {
44+
refetchSkills()
45+
}
46+
47+
setShowMoveSkills(false)
2148
}
2249

2350
const hasSelection = context.selectedSkills.length > 0
@@ -37,7 +64,7 @@ const BulkEditor: FC<BulkEditorProps> = props => {
3764
label='Archive selected'
3865
size='lg'
3966
disabled={!hasSelection}
40-
onClick={toggleArchive}
67+
onClick={openArchiveModal}
4168
/>
4269
<Button
4370
primary
@@ -52,10 +79,15 @@ const BulkEditor: FC<BulkEditorProps> = props => {
5279
label='Move selected'
5380
size='lg'
5481
disabled={!hasSelection}
82+
onClick={openMoveSkillsModal}
5583
/>
5684

5785
{showArchive && (
58-
<ArchiveSkillsModal skills={context.selectedSkills} onClose={toggleArchive} />
86+
<ArchiveSkillsModal skills={context.selectedSkills} onClose={closeArchiveModal} />
87+
)}
88+
89+
{showMoveSkills && (
90+
<MoveSkillsModal skills={context.selectedSkills} onClose={closeMoveSkillsModal} />
5991
)}
6092
</div>
6193
)

src/apps/admin/src/skills-manager/components/bulk-editor/archive-skills-modal/ArchiveSkillsModal.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
1-
import { FC } from 'react'
1+
import { FC, useState } from 'react'
22

3-
import { BaseModal, Button } from '~/libs/ui'
3+
import { BaseModal, Button, LoadingSpinner } from '~/libs/ui'
44

5-
import { StandardizedSkill } from '../../../services'
65
import { SkillsList } from '../../skills-list'
6+
import { bulkArchiveStandardizedSkills, StandardizedSkill } from '../../../services'
77
import { SkillsManagerContextValue, useSkillsManagerContext } from '../../../context'
88

99
import styles from './ArchiveSkillsModal.module.scss'
1010

1111
interface ArchiveSkillsModalProps {
1212
skills: StandardizedSkill[]
13-
onClose: () => void
13+
onClose: (archived?: boolean) => void
1414
}
1515

1616
const ArchiveSkillsModal: FC<ArchiveSkillsModalProps> = props => {
17+
const [isLoading, setIsLoading] = useState(false)
18+
1719
const { bulkEditorCtx: context }: SkillsManagerContextValue = useSkillsManagerContext()
1820

21+
async function archiveAll(): Promise<void> {
22+
setIsLoading(true)
23+
await bulkArchiveStandardizedSkills(props.skills)
24+
props.onClose(true)
25+
setIsLoading(false)
26+
}
27+
28+
function close(): void {
29+
props.onClose()
30+
}
31+
1932
return (
2033
<BaseModal
2134
onClose={props.onClose}
@@ -25,8 +38,8 @@ const ArchiveSkillsModal: FC<ArchiveSkillsModalProps> = props => {
2538
bodyClassName={styles.modalBody}
2639
buttons={(
2740
<>
28-
<Button primary light label='Cancel' onClick={props.onClose} />
29-
<Button primary variant='danger' label='Archive' onClick={props.onClose} />
41+
<Button primary light label='Cancel' onClick={close} size='lg' />
42+
<Button primary variant='danger' label='Archive' onClick={archiveAll} size='lg' />
3043
</>
3144
)}
3245
>
@@ -37,7 +50,7 @@ const ArchiveSkillsModal: FC<ArchiveSkillsModalProps> = props => {
3750
isSelected={context.isSkillSelected}
3851
editMode={!!context.isEditing}
3952
/>
40-
{/* <LoadingSpinner hide={!loading} overlay /> */}
53+
<LoadingSpinner hide={!isLoading} overlay />
4154
</BaseModal>
4255
)
4356
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@import '@libs/ui/styles/includes';
2+
3+
.modalBody {
4+
.skillsList {
5+
column-count: 2;
6+
margin: -$sp-2;
7+
}
8+
}
9+
10+
.formInput {
11+
&Label {
12+
margin-bottom: $sp-2;
13+
}
14+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { ChangeEvent, FC, useMemo, useState } from 'react'
2+
import { noop } from 'lodash'
3+
4+
import { BaseModal, Button, InputSelectReact, LoadingSpinner } from '~/libs/ui'
5+
6+
import { SkillsManagerContextValue, useSkillsManagerContext } from '../../../context'
7+
import { bulkUpdateStandardizedSkills, StandardizedSkill } from '../../../services'
8+
import { mapCategoryToSelectOption } from '../../../lib'
9+
import { SkillsList } from '../../skills-list'
10+
11+
import styles from './MoveSkillsModal.module.scss'
12+
13+
interface MoveSkillsModalProps {
14+
skills: StandardizedSkill[]
15+
onClose: (archived?: boolean) => void
16+
}
17+
18+
const MoveSkillsModal: FC<MoveSkillsModalProps> = props => {
19+
const [isLoading, setIsLoading] = useState(false)
20+
const [categoryId, setCategoryId] = useState<string>()
21+
22+
const {
23+
bulkEditorCtx: context,
24+
categories,
25+
}: SkillsManagerContextValue = useSkillsManagerContext()
26+
27+
const currentCategoryOptions = useMemo(() => (
28+
mapCategoryToSelectOption([props.skills[0]?.category].filter(Boolean))
29+
), [props.skills])
30+
31+
const categoryOptions = useMemo(() => mapCategoryToSelectOption(categories), [categories])
32+
33+
function handleCategoryChange(ev: ChangeEvent<HTMLInputElement>): void {
34+
setCategoryId(ev.target.value)
35+
}
36+
37+
async function moveAll(): Promise<void> {
38+
setIsLoading(true)
39+
await bulkUpdateStandardizedSkills(props.skills, { categoryId })
40+
props.onClose(true)
41+
setIsLoading(false)
42+
}
43+
44+
function close(): void {
45+
props.onClose()
46+
}
47+
48+
return (
49+
<BaseModal
50+
onClose={props.onClose}
51+
open
52+
size='lg'
53+
title='Move These Skills'
54+
bodyClassName={styles.modalBody}
55+
buttons={(
56+
<>
57+
<Button primary light label='Cancel' onClick={close} size='lg' />
58+
<Button
59+
primary
60+
label='Move'
61+
onClick={moveAll}
62+
size='lg'
63+
disabled={!categoryId || categoryId === currentCategoryOptions[0]?.value}
64+
/>
65+
</>
66+
)}
67+
>
68+
<SkillsList
69+
className={styles.skillsList}
70+
skills={props.skills}
71+
onSelect={context.toggleSkill}
72+
isSelected={context.isSkillSelected}
73+
editMode={!!context.isEditing}
74+
/>
75+
76+
<div className={styles.formInput}>
77+
<div className={styles.formInputLabel}>
78+
<h2>From:</h2>
79+
</div>
80+
<InputSelectReact
81+
label='Skill Category'
82+
options={currentCategoryOptions}
83+
value={currentCategoryOptions[0]?.value}
84+
name='from'
85+
onChange={noop}
86+
disabled
87+
/>
88+
</div>
89+
<div className={styles.formInput}>
90+
<div className={styles.formInputLabel}>
91+
<h2>To:</h2>
92+
</div>
93+
<InputSelectReact
94+
label='Skill Category'
95+
placeholder='Select category'
96+
options={categoryOptions}
97+
value={categoryId}
98+
name='to'
99+
onChange={handleCategoryChange}
100+
/>
101+
</div>
102+
103+
<LoadingSpinner hide={!isLoading} overlay />
104+
</BaseModal>
105+
)
106+
}
107+
108+
export default MoveSkillsModal
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as MoveSkillsModal } from './MoveSkillsModal'

src/apps/admin/src/skills-manager/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ export * from './category-modal'
44
export * from './more-actions-menu'
55
export * from './page-header'
66
export * from './search-input'
7-
export * from './skill-modal'
7+
export * from './skill-modals'

0 commit comments

Comments
 (0)