-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTraineePerformance.tsx
351 lines (335 loc) · 12.9 KB
/
TraineePerformance.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
import React, { useContext, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useLazyQuery, gql, useQuery } from '@apollo/client';
import { toast } from 'react-toastify';
import Pagination from './Pagination';
import PerformanceData from '../dummyData/performance.json';
import { TRAINEE_RATING } from '../Mutations/Ratings';
import RemarksModal from '../pages/ratings/CoordinatorRemarks';
import { UserContext } from '../hook/useAuth';
import { rowsType } from '../pages/ratings/frame';
import oop from '../assets/oops.svg';
import Spinner from './Spinner';
export const GET_RATINGS_DATA = gql`
query FetchRatingsTrainee {
fetchRatingsTrainee {
quality
qualityRemark
bodyQuality
professional_Skills
bodyQuantity
quantityRemark
quantity
average
sprint
professionalRemark
bodyProfessional
approved
coordinator
cohort {
name
phase {
name
}
coordinator {
email
profile {
firstName
name
lastName
}
}
program {
name
manager {
email
}
}
}
user {
id
profile {
name
firstName
lastName
}
email
organizations
}
}
}
`;
function TraineePerfomance() {
const [usedata, setUserdata] = useState([]);
const { data, loading, error } = useQuery(GET_RATINGS_DATA, {});
const { user } = useContext(UserContext);
const [row, setRow] = useState<rowsType>({
id: user?.userId,
feedbacks: [],
sprint: 0,
username: 'string',
user: 'string',
qualityremark: '',
quantityremark: '',
professionalRemark: '',
});
useEffect(() => {
if (data && data.fetchRatingsTrainee) {
const ratingsData = data.fetchRatingsTrainee;
const customHeadings = ratingsData.map((item: any) => ({
Name: item?.user?.profile?.name,
Email: item?.user?.email,
Quality: item.quality,
QualityRemark: item.qualityRemark,
Quantity: item.quantity,
QuantityRemark: item.quantityRemark,
Professional_Skills: item.professional_Skills,
Professional_SkillsRemark: item.professionalRemark,
Average: item.average,
Sprint: item.sprint,
Cohort: item?.cohort?.name,
Phase: item?.cohort?.phase?.name,
Coodinator: item?.cohort?.coordinator?.profile?.name,
}));
setUserdata(customHeadings);
}
}, [data]);
const [ratings, setRatings] = useState<any>([]);
const [toggle, setToggle] = useState(false);
const { t } = useTranslation();
const {
firstContentIndex,
lastContentIndex,
nextPage,
prevPage,
page,
gaps,
setPage,
totalPages,
} = Pagination({
contentPerPage: 3,
count: PerformanceData.length,
});
const [getRatings] = useLazyQuery(TRAINEE_RATING, {});
useEffect(() => {
getRatings({
fetchPolicy: 'network-only',
onCompleted: (data) => {
setRatings(data?.fetchRatingsTrainee);
sessionStorage.removeItem('data');
},
onError: (error) => {
toast.error(error?.message || 'Something went wrong');
},
});
}, []);
const openFeed = (rate: any) => {
setToggle(true);
setRow((prev) => ({
...prev,
sprint: rate?.sprint,
quantityremark: rate?.quantityRemark,
qualityremark: rate?.qualityRemark,
professionalRemark: rate?.professionalRemark,
id: user?.userId,
username: rate?.cohort?.coordinator?.profile?.name,
user: rate?.cohort?.coordinator?.email,
feedbacks: rate?.feedbacks,
}));
};
const closeFeeds = () => {
setToggle(false);
};
if (loading) {
return (
<>
<div className="bg-light-bg dark:bg-dark-frame-bg pb-10">
<div className="">
<div className="bg-white dark:bg-dark-bg shadow-lg py-8 px-5 rounded-md w-full mdl:w-[70%] mdl:m-auto flex">
<div className=" flex-1">
<div className="flex w-full h-full items-center justify-between">
<p className="text-gray-800 dark:text-white font-semibold text-[24px] w-[90%] m-auto">
<Spinner />
</p>
</div>
</div>
</div>
</div>
</div>
</>
);
}
if (ratings?.length === 0) {
return (
<>
<div className="bg-light-bg dark:bg-dark-frame-bg pb-10">
<div className="">
<div className="bg-white dark:bg-dark-bg shadow-lg py-8 px-5 rounded-md w-full mdl:w-[70%] mdl:m-auto flex">
<div className="flex ml-2 items-center justify-between">
<div className="">
<img src={oop} className="w-[8rem] h-[8rem]" alt="images" />
</div>
</div>
<div className=" flex-1">
<div className="flex w-full h-full items-center justify-between">
<p className="text-gray-800 dark:text-white font-semibold text-[24px] w-[90%] m-auto">
Performance updates are on the way! Stay tuned for the
latest insights!
</p>
</div>
</div>
</div>
</div>
</div>
</>
);
}
return (
<>
<RemarksModal showRemarks={toggle} closeModal={closeFeeds} rows={row} />
<div className="bg-light-bg dark:bg-dark-frame-bg pb-10 font-serif">
<div className="">
<div className="bg-white dark:bg-dark-bg shadow-lg px-5 py-8 rounded-md w-full">
<div className="">
<div className="flex ml-2 items-center justify-between">
<h2 className="text-gray-800 dark:text-white font-semibold">
{t('Performance score')}
</h2>
</div>
<div className="flex ml-[-25px] px-7 py-2 mt-4"> </div>
</div>
<div>
<div className="-mx-4 sm:-mx-8 px-4 sm:px-8 py-2 overflow-x-auto">
<div className="inline-block w-full lg:min-w-full shadow rounded-lg overflow-hidden">
<table className="min-w-full leading-normal">
<thead className="dark:text-white "> </thead>
<tbody>
<tr>
<th className="p-6 border-b-2 border-gray-200 bg-gray-100 dark:bg-neutral-600 text-center text-xs font-semibold text-gray-600 dark:text-white uppercase tracking-wider">
{t('Sprint')}
</th>
<th className="p-6 border-b-2 border-gray-200 bg-gray-100 dark:bg-neutral-600 text-center text-xs font-semibold text-gray-600 dark:text-white uppercase tracking-wider">
{t('Phase')}
</th>
<th className="px-5 border-b-2 border-gray-200 bg-gray-100 dark:bg-neutral-600 text-center text-xs font-semibold text-gray-600 dark:text-white uppercase md:table-cell sm:hidden tracking-wider">
{t('Quantity')}
</th>
<th className="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 dark:bg-neutral-600 text-center text-xs font-semibold text-gray-600 dark:text-white uppercase md:table-cell sm:hidden tracking-wider">
{t('Quality')}
</th>
<th className="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 dark:bg-neutral-600 text-center text-xs font-semibold text-gray-600 dark:text-white uppercase md:table-cell sm:hidden tracking-wider">
{t('Professional skills')}
</th>
<th className="px-5 py-3 border-b-2 border-gray-200 bg-gray-100 dark:bg-neutral-600 text-center text-xs font-semibold text-gray-600 dark:text-white uppercase tracking-wider">
{t('Average')}
</th>
</tr>
{ratings
?.slice(firstContentIndex, lastContentIndex)
.map((item: any) => (
<tr key={item.sprint}>
<td className="px-5 py-5 border-b border-gray-200 bg-white dark:bg-dark-bg text-sm">
<div className="flex justify-center items-center">
<div className="">
<p className="text-gray-900 text-center dark:text-white whitespace-no-wrap">
{item.sprint}
</p>
</div>
</div>
</td>
<td className="px-5 py-5 border-b border-gray-200 bg-white dark:bg-dark-bg text-sm md:table-cell sm:hidden">
<p className="text-gray-900 dark:text-white whitespace-no-wrap text-center">
{item.cohort.phase?.name}
</p>
</td>
<td className="px-5 py-5 border-b border-gray-200 bg-white dark:bg-dark-bg text-sm md:table-cell sm:hidden">
<p className="text-gray-900 dark:text-white whitespace-no-wrap text-center">
{item.quantity}
</p>
</td>
<td className="px-5 py-5 border-b border-gray-200 bg-white dark:bg-dark-bg text-sm md:table-cell sm:hidden">
<p className="text-gray-900 dark:text-white whitespace-no-wrap text-center ">
{item.quality}
</p>
</td>
<td className="px-5 py-5 border-b border-gray-200 bg-white dark:bg-dark-bg text-sm md:table-cell sm:hidden">
<p className="text-gray-900 dark:text-white whitespace-no-wrap text-center ">
{item.professional_Skills}
</p>
</td>
<td className="px-5 py-5 border-b border-gray-200 bg-white dark:bg-dark-bg text-sm">
<p className="text-gray-900 dark:text-white whitespace-no-wrap text-center">
{item.average % 1 === 0
? item.average
: Number(item.average).toFixed(2)}
</p>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>
<div className="flex items-center justify-center gap-1 mt-12 mb-0">
<button
onClick={prevPage}
data-testid="prev"
type="button"
className={`page flex text-white h-12 w-12 items-center justify-center border-solid cursor-pointer bg-transparent ${
page === 1 && 'disabled'
}`}
>
←
</button>
<button
onClick={() => setPage(1)}
data-testid="page1"
type="button"
className={`page flex text-white h-12 w-12 items-center justify-center border-solid cursor-pointer bg-transparent ${
page === 1 && 'disabled'
}`}
>
1
</button>
{gaps.paginationGroup.map((el) => (
<button
onClick={() => setPage(el)}
data-testid="page"
key={el}
type="button"
className={`page flex text-white h-12 w-12 items-center justify-center border-solid cursor-pointer bg-transparent ${
page === el ? 'active' : ''
}`}
>
{el}
</button>
))}
<button
onClick={() => setPage(totalPages)}
data-testid="page3"
type="button"
className={`page flex text-white h-12 w-12 items-center justify-center border-solid cursor-pointer bg-transparent ${
page === totalPages && 'disabled'
}`}
>
{totalPages}
</button>
<button
onClick={nextPage}
data-testid="next"
type="button"
className={`page flex text-white h-12 w-12 items-center justify-center border-solid cursor-pointer bg-transparent ${
page === totalPages && 'disabled'
}`}
>
→
</button>
</div>
</div>
</div>
</>
);
}
export default TraineePerfomance;