1
|
|
|
import React, { useState } from "react"; |
2
|
|
|
import { useIntl, defineMessages } from "react-intl"; |
3
|
|
|
import { |
4
|
|
|
Experience, |
5
|
|
|
ExperienceSkill, |
6
|
|
|
Skill, |
7
|
|
|
SkillSkillCategory, |
8
|
|
|
SkillCategory, |
9
|
|
|
} from "../../../models/types"; |
10
|
|
|
import { |
11
|
|
|
getExperiencesOfSkill, |
12
|
|
|
getExperienceOfExperienceSkill, |
13
|
|
|
} from "../../Application/helpers"; |
14
|
|
|
import { localizeFieldNonNull, getLocale } from "../../../helpers/localize"; |
15
|
|
|
import { sortLocalizedAlphabetical } from "../../../helpers/queries"; |
16
|
|
|
import Accordion from "./Accordion"; |
17
|
|
|
|
18
|
|
|
const messages = defineMessages({ |
19
|
|
|
group: { |
20
|
|
|
id: "applicantProfile.skills.list.group", |
21
|
|
|
defaultMessage: "Group", |
22
|
|
|
description: "Text for the 'Group' option on the sort toggle UI.", |
23
|
|
|
}, |
24
|
|
|
alpha: { |
25
|
|
|
id: "applicantProfile.skills.list.alpha", |
26
|
|
|
defaultMessage: "A-Z", |
27
|
|
|
description: "Text for the 'A-Z' option on the sort toggle UI.", |
28
|
|
|
}, |
29
|
|
|
journey: { |
30
|
|
|
id: "applicantProfile.skills.list.journey", |
31
|
|
|
defaultMessage: "Journey", |
32
|
|
|
description: "Text for the 'Journey' option on the sort toggle UI.", |
33
|
|
|
}, |
34
|
|
|
sortBy: { |
35
|
|
|
id: "applicantProfile.skills.list.sortBy", |
36
|
|
|
defaultMessage: "Sort By:", |
37
|
|
|
description: "Text for the label on the sort toggle UI.", |
38
|
|
|
}, |
39
|
|
|
experiencesLabel: { |
40
|
|
|
id: "applicantProfile,skills.list.experiencesLabel", |
41
|
|
|
defaultMessage: |
42
|
|
|
"{experienceCount, plural, =0 {No Experiences} one {1 Experience} other {{experienceCount Experiences}}}", |
43
|
|
|
description: |
44
|
|
|
"Subheading that displays the count of experiences on each accordion.", |
45
|
|
|
}, |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
enum SortTypes { |
49
|
|
|
Group = "group", |
50
|
|
|
Alpha = "alpha", |
51
|
|
|
// Journey = "journey", Future enhancement according to designs. |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
interface SortButtonProps { |
55
|
|
|
text: string; |
56
|
|
|
active: boolean; |
57
|
|
|
handleClick: () => void; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
const SortButton: React.FC<SortButtonProps> = ({ |
61
|
|
|
text, |
62
|
|
|
active, |
63
|
|
|
handleClick, |
64
|
|
|
}) => ( |
65
|
|
|
<button |
66
|
|
|
data-h2-button={`${active ? "theme-1" : "black"}, square, medium, clear`} |
67
|
|
|
type="button" |
68
|
|
|
onClick={handleClick} |
69
|
|
|
> |
70
|
|
|
<span data-h2-button-label>{text}</span> |
71
|
|
|
</button> |
72
|
|
|
); |
73
|
|
|
|
74
|
|
|
interface ListProps { |
75
|
|
|
experiences: Experience[]; |
76
|
|
|
experienceSkills: ExperienceSkill[]; |
77
|
|
|
skillCategories: SkillCategory[]; |
78
|
|
|
skillSkillCategories: SkillSkillCategory[]; |
79
|
|
|
skills: Skill[]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
const List: React.FC<ListProps> = ({ |
83
|
|
|
experiences, |
84
|
|
|
experienceSkills, |
85
|
|
|
skillCategories, |
86
|
|
|
skillSkillCategories, |
87
|
|
|
skills, |
88
|
|
|
}) => { |
89
|
|
|
const intl = useIntl(); |
90
|
|
|
const locale = getLocale(intl.locale); |
91
|
|
|
const [sortType, setSortType] = useState<SortTypes>(SortTypes.Group); |
92
|
|
|
|
93
|
|
|
return ( |
94
|
|
|
<div> |
95
|
|
|
<p> |
96
|
|
|
{intl.formatMessage(messages.sortBy)}{" "} |
97
|
|
|
<SortButton |
98
|
|
|
text={intl.formatMessage(messages[SortTypes.Group])} |
99
|
|
|
active={sortType === SortTypes.Group} |
100
|
|
|
handleClick={() => setSortType(SortTypes.Group)} |
101
|
|
|
/>{" "} |
102
|
|
|
<SortButton |
103
|
|
|
text={intl.formatMessage(messages[SortTypes.Alpha])} |
104
|
|
|
active={sortType === SortTypes.Alpha} |
105
|
|
|
handleClick={() => setSortType(SortTypes.Alpha)} |
106
|
|
|
/> |
107
|
|
|
</p> |
108
|
|
|
{skillCategories.map((skillCategory: SkillCategory) => ( |
109
|
|
|
<div key={skillCategory.id}> |
110
|
|
|
<h2>{localizeFieldNonNull(locale, skillCategory, "name")}</h2> |
111
|
|
|
{skills |
112
|
|
|
.sort(sortLocalizedAlphabetical(locale)) |
113
|
|
|
.map((skill: Skill) => { |
114
|
|
|
const experienceCount = getExperiencesOfSkill( |
115
|
|
|
skill, |
116
|
|
|
experienceSkills, |
117
|
|
|
).length; |
118
|
|
|
|
119
|
|
|
return ( |
120
|
|
|
<Accordion |
121
|
|
|
key={skill.id} |
122
|
|
|
title={ |
123
|
|
|
<p data-h2-font-size="small"> |
124
|
|
|
{localizeFieldNonNull(locale, skill, "name")} |
125
|
|
|
</p> |
126
|
|
|
} |
127
|
|
|
subtitle={ |
128
|
|
|
<p data-h2-font-size="small"> |
129
|
|
|
{intl.formatMessage(messages.experiencesLabel, { |
130
|
|
|
experienceCount, |
131
|
|
|
})} |
132
|
|
|
</p> |
133
|
|
|
} |
134
|
|
|
> |
135
|
|
|
<div>Content</div> |
136
|
|
|
</Accordion> |
137
|
|
|
); |
138
|
|
|
})} |
139
|
|
|
</div> |
140
|
|
|
))} |
141
|
|
|
</div> |
142
|
|
|
); |
143
|
|
|
}; |
144
|
|
|
|
145
|
|
|
export default List; |
146
|
|
|
|