|
1
|
|
|
import * as React from "react"; |
|
2
|
|
|
import { |
|
3
|
|
|
useIntl, |
|
4
|
|
|
FormattedMessage, |
|
5
|
|
|
MessageDescriptor, |
|
6
|
|
|
defineMessages, |
|
7
|
|
|
} from "react-intl"; |
|
8
|
|
|
import { connect } from "react-redux"; |
|
9
|
|
|
import { hasKey } from "../helpers/queries"; |
|
10
|
|
|
import { LocationId } from "../models/lookupConstants"; |
|
11
|
|
|
import CommentForm from "./CommentForm"; |
|
12
|
|
|
import ActivityList from "./ActivityList"; |
|
13
|
|
|
import Icon from "./Icon"; |
|
14
|
|
|
import { Comment } from "../models/types"; |
|
15
|
|
|
import { fetchingComments, getComments } from "../store/Job/jobSelector"; |
|
16
|
|
|
import { RootState } from "../store/store"; |
|
17
|
|
|
|
|
18
|
|
|
const messages = defineMessages({ |
|
19
|
|
|
loadingIcon: { |
|
20
|
|
|
id: "activityfeed.loadingIconText", |
|
21
|
|
|
defaultMessage: "Number of activities is loading...", |
|
22
|
|
|
description: "Accessible text for the loading icon", |
|
23
|
|
|
}, |
|
24
|
|
|
}); |
|
25
|
|
|
|
|
26
|
|
|
interface ActivityFeedProps { |
|
27
|
|
|
commentsLoading: boolean; |
|
28
|
|
|
generalLocation: string; |
|
29
|
|
|
isHrAdvisor: boolean; |
|
30
|
|
|
jobId: number; |
|
31
|
|
|
locationMessages: { [LocationId: string]: MessageDescriptor }; |
|
32
|
|
|
totalActivities: number; |
|
33
|
|
|
filterComments?: (comment: Comment) => boolean; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
const ActivityFeed: React.FunctionComponent<ActivityFeedProps> = ({ |
|
37
|
|
|
commentsLoading, |
|
38
|
|
|
generalLocation, |
|
39
|
|
|
isHrAdvisor, |
|
40
|
|
|
jobId, |
|
41
|
|
|
locationMessages, |
|
42
|
|
|
totalActivities, |
|
43
|
|
|
filterComments, |
|
44
|
|
|
}) => { |
|
45
|
|
|
const intl = useIntl(); |
|
46
|
|
|
const locationOptions = Object.values(LocationId) |
|
47
|
|
|
.filter(location => hasKey(locationMessages, location)) |
|
48
|
|
|
.map(location => ({ |
|
49
|
|
|
value: location, |
|
50
|
|
|
label: intl.formatMessage(locationMessages[location]), |
|
51
|
|
|
})); |
|
52
|
|
|
return ( |
|
53
|
|
|
<section> |
|
54
|
|
|
<div data-c-accordion-group> |
|
55
|
|
|
<div data-c-accordion="" className=""> |
|
56
|
|
|
<button |
|
57
|
|
|
aria-expanded="false" |
|
58
|
|
|
data-c-accordion-trigger |
|
59
|
|
|
tabIndex={0} |
|
60
|
|
|
type="button" |
|
61
|
|
|
data-c-background="c1(100)" |
|
62
|
|
|
data-c-padding="all(1)" |
|
63
|
|
|
> |
|
64
|
|
|
<div> |
|
65
|
|
|
<h3 data-c-font-size="h3" data-c-color="white"> |
|
66
|
|
|
<FormattedMessage |
|
67
|
|
|
id="activityfeed.header" |
|
68
|
|
|
defaultMessage="Click to View Comments {totalActivities}" |
|
69
|
|
|
description="The activity feed header." |
|
70
|
|
|
values={{ |
|
71
|
|
|
totalActivities: commentsLoading ? ( |
|
72
|
|
|
<Icon |
|
73
|
|
|
icon="fa fa-spinner fa-spin" |
|
74
|
|
|
accessibleText={intl.formatMessage( |
|
75
|
|
|
messages.loadingIcon, |
|
76
|
|
|
)} |
|
77
|
|
|
sematicIcon |
|
78
|
|
|
/> |
|
79
|
|
|
) : ( |
|
80
|
|
|
`(${totalActivities})` |
|
81
|
|
|
), |
|
82
|
|
|
}} |
|
83
|
|
|
/> |
|
84
|
|
|
</h3> |
|
85
|
|
|
</div> |
|
86
|
|
|
<span data-c-visibility="invisible"> |
|
87
|
|
|
<FormattedMessage |
|
88
|
|
|
id="activityfeed.accordionAccessibleLabel" |
|
89
|
|
|
defaultMessage="Click to view..." |
|
90
|
|
|
description="The accessibility text displayed on the activity feed accordion button." |
|
91
|
|
|
/> |
|
92
|
|
|
</span> |
|
93
|
|
|
<p |
|
94
|
|
|
data-c-accordion-add="" |
|
95
|
|
|
data-c-font-style="underline" |
|
96
|
|
|
data-c-color="white" |
|
97
|
|
|
> |
|
98
|
|
|
<i className="fas fa-caret-up" /> |
|
99
|
|
|
</p> |
|
100
|
|
|
<p |
|
101
|
|
|
data-c-accordion-remove="" |
|
102
|
|
|
data-c-font-style="underline" |
|
103
|
|
|
data-c-color="white" |
|
104
|
|
|
> |
|
105
|
|
|
<i className="fas fa-caret-down" /> |
|
106
|
|
|
</p> |
|
107
|
|
|
</button> |
|
108
|
|
|
<div |
|
109
|
|
|
aria-hidden="false" |
|
110
|
|
|
data-c-accordion-content |
|
111
|
|
|
data-c-background="grey(20)" |
|
112
|
|
|
data-c-padding="all(1)" |
|
113
|
|
|
> |
|
114
|
|
|
<CommentForm |
|
115
|
|
|
jobId={jobId} |
|
116
|
|
|
isHrAdvisor={isHrAdvisor} |
|
117
|
|
|
location={generalLocation} |
|
118
|
|
|
locationOptions={locationOptions} |
|
119
|
|
|
/> |
|
120
|
|
|
<hr data-c-hr="thin(black)" data-c-margin="top(1)" /> |
|
121
|
|
|
<ActivityList |
|
122
|
|
|
generalLocation={generalLocation} |
|
123
|
|
|
jobId={jobId} |
|
124
|
|
|
isHrAdvisor={isHrAdvisor} |
|
125
|
|
|
filterComments={filterComments} |
|
126
|
|
|
/> |
|
127
|
|
|
</div> |
|
128
|
|
|
</div> |
|
129
|
|
|
</div> |
|
130
|
|
|
</section> |
|
131
|
|
|
); |
|
132
|
|
|
}; |
|
133
|
|
|
|
|
134
|
|
|
const mapStateToProps = ( |
|
135
|
|
|
state: RootState, |
|
136
|
|
|
{ |
|
137
|
|
|
filterComments = (): boolean => true, |
|
138
|
|
|
}: { filterComments?: (comment: Comment) => boolean }, |
|
139
|
|
|
): { |
|
140
|
|
|
commentsLoading: boolean; |
|
141
|
|
|
totalActivities: number; |
|
142
|
|
|
} => ({ |
|
143
|
|
|
commentsLoading: fetchingComments(state), |
|
144
|
|
|
totalActivities: getComments(state).filter(filterComments).length, |
|
145
|
|
|
}); |
|
146
|
|
|
|
|
147
|
|
|
export default connect(mapStateToProps, () => ({}))(ActivityFeed); |
|
148
|
|
|
|