Passed
Push — task/common-translation-packag... ( dbb970...52324d )
by Tristan
06:50 queued 11s
created

resources/assets/js/components/JobBuilder/Review/JobReviewActivityFeed.tsx   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 169
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 137
mnd 2
bc 2
fnc 0
dl 0
loc 169
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import * as React from "react";
2
import { connect } from "react-redux";
3
import { defineMessages, useIntl, FormattedMessage } from "react-intl";
4
import CommentForm from "../../CommentForm";
5
import ActivityFeed from "../../ActivityFeed";
6
import { LocationId } from "../../../models/lookupConstants";
7
import { RootState } from "../../../store/store";
8
import { getComments } from "../../../store/Job/jobSelector";
9
import Icon from "../../Icon";
10
import { hasKey } from "../../../helpers/queries";
11
12
export const reviewLocations = defineMessages({
13
  [LocationId.generic]: {
14
    id: "reviewLocations.jpb.generic",
15
    defaultMessage: "Generic",
16
    description: "Location where the activity is located.",
17
  },
18
  [LocationId.heading]: {
19
    id: "reviewLocations.jpb.heading",
20
    defaultMessage: "Job Page Heading",
21
    description: "Location where the activity is located.",
22
  },
23
  [LocationId.basicInfo]: {
24
    id: "reviewLocations.jpb.basicInfo",
25
    defaultMessage: "Basic Information",
26
    description: "Location where the activity is located.",
27
  },
28
  [LocationId.impact]: {
29
    id: "reviewLocations.jpb.impact",
30
    defaultMessage: "Impact",
31
    description: "Location where the activity is located.",
32
  },
33
  [LocationId.tasks]: {
34
    id: "reviewLocations.jpb.tasks",
35
    defaultMessage: "Tasks",
36
    description: "Location where the activity is located.",
37
  },
38
  [LocationId.skills]: {
39
    id: "reviewLocations.jpb.skills",
40
    defaultMessage: "Criteria",
41
    description: "Location where the activity is located.",
42
  },
43
  [LocationId.langRequirements]: {
44
    id: "reviewLocations.jpb.langRequirements",
45
    defaultMessage: "Language Requirements",
46
    description: "Location where the activity is located.",
47
  },
48
  [LocationId.environment]: {
49
    id: "reviewLocations.jpb.environment",
50
    defaultMessage: "Work Environment",
51
    description: "Location where the activity is located.",
52
  },
53
});
54
55
const messages = defineMessages({
56
  loadingIcon: {
57
    id: "activityfeed.review.loadingIconText",
58
    defaultMessage: "Data is loading...",
59
    description: "Accessible text for the loading icon",
60
  },
61
});
62
63
interface JobReviewActivityFeedProps {
64
  jobId: number;
65
  isHrAdvisor: boolean;
66
  totalActivities: number | null;
67
}
68
69
const JobReviewActivityFeed: React.FunctionComponent<JobReviewActivityFeedProps> = ({
70
  jobId,
71
  isHrAdvisor,
72
  totalActivities,
73
}) => {
74
  const intl = useIntl();
75
  const locationOptions = Object.values(LocationId)
76
    .filter(location => hasKey(reviewLocations, location))
77
    .map(location => ({
78
      value: location,
79
      label: intl.formatMessage(reviewLocations[location]),
80
    }));
81
82
  return (
83
    <section data-c-padding="top(double)">
84
      <div data-c-accordion-group>
85
        <div data-c-accordion="" className="">
86
          <button
87
            aria-expanded="false"
88
            data-c-accordion-trigger
89
            tabIndex={0}
90
            type="button"
91
            data-c-background="c1(100)"
92
            data-c-padding="all(1)"
93
          >
94
            <div>
95
              <h3 data-c-font-size="h3" data-c-color="white">
96
                <FormattedMessage
97
                  id="activityfeed.review.header"
98
                  defaultMessage="Click to View Comments {totalActivities}"
99
                  description="The activity feed header."
100
                  values={{
101
                    totalActivities:
102
                      totalActivities === null ? (
103
                        <Icon
104
                          icon="fa fa-spinner fa-spin"
105
                          accessibleText={intl.formatMessage(
106
                            messages.loadingIcon,
107
                          )}
108
                          sematicIcon
109
                        />
110
                      ) : (
111
                        `(${totalActivities})`
112
                      ),
113
                  }}
114
                />
115
              </h3>
116
            </div>
117
            <span data-c-visibility="invisible">
118
              <FormattedMessage
119
                id="activityfeed.review.accordionAccessibleLabel"
120
                defaultMessage="Click to view..."
121
                description="The accessibility text displayed on the activity feed accordion button."
122
              />
123
            </span>
124
            <p
125
              data-c-accordion-add=""
126
              data-c-font-style="underline"
127
              data-c-color="white"
128
            >
129
              <i className="fas fa-caret-down" />
130
            </p>
131
            <p
132
              data-c-accordion-remove=""
133
              data-c-font-style="underline"
134
              data-c-color="white"
135
            >
136
              <i className="fas fa-caret-up" />
137
            </p>
138
          </button>
139
          <div
140
            aria-hidden="false"
141
            data-c-accordion-content
142
            data-c-background="grey(20)"
143
            data-c-padding="all(1)"
144
          >
145
            <CommentForm
146
              jobId={jobId}
147
              isHrAdvisor={isHrAdvisor}
148
              location={LocationId.generic}
149
              locationOptions={locationOptions}
150
            />
151
            <hr data-c-hr="thin(black)" data-c-margin="top(1)" />
152
            <ActivityFeed jobId={jobId} isHrAdvisor={isHrAdvisor} />
153
          </div>
154
        </div>
155
      </div>
156
    </section>
157
  );
158
};
159
160
const mapStateToProps = (
161
  state: RootState,
162
): {
163
  totalActivities: number | null;
164
} => ({
165
  totalActivities: getComments(state) ? getComments(state).length : null,
166
});
167
168
export default connect(mapStateToProps, () => ({}))(JobReviewActivityFeed);
169