@@ -2,9 +2,9 @@ import { useLazyQuery, useMutation } from "@apollo/client"
2
2
import React , { useEffect , useState } from "react"
3
3
import { useTranslation } from "react-i18next"
4
4
import * as XLSX from "xlsx"
5
- import { ADD_RATINGS_BY_FILE , FETCH_SPRINTS } from "../Mutations/Ratings"
5
+ import { ADD_RATINGS_BY_FILE , GET_RATINGS_BY_USER_COHORT } from "../Mutations/Ratings"
6
6
import { toast } from "react-toastify"
7
- import { GET_TEAMS_BY_ROLE } from "../Mutations/teamMutation"
7
+ import { GET_TEAMS_BY_USER_ROLE } from "../Mutations/teamMutation"
8
8
9
9
type BulkRatingModalProps = {
10
10
bulkRateModal : boolean ,
@@ -20,19 +20,19 @@ const orgToken = localStorage.getItem('orgToken')
20
20
21
21
const BulkRatingModal = ( { bulkRateModal, setBulkRateModal } : BulkRatingModalProps ) => {
22
22
const { t } = useTranslation ( )
23
- const [ fetchSprints , { data : sprints , loading : loadingSprints , error : sprintsError } ] = useLazyQuery ( FETCH_SPRINTS , {
23
+ const [ getRatingsByUserCohort , { data : ratings , loading : loadingRatings , error : ratingsError } ] = useLazyQuery ( GET_RATINGS_BY_USER_COHORT , {
24
24
variables : {
25
25
orgToken
26
26
} ,
27
27
fetchPolicy : 'network-only' ,
28
28
} )
29
- const [ getTeamsByRole , { data : teams , loading : loadingTeams , error : teamsError } ] = useLazyQuery ( GET_TEAMS_BY_ROLE , {
29
+ const [ getTeamsByUserRole , { data : teams , loading : loadingTeams , error : teamsError } ] = useLazyQuery ( GET_TEAMS_BY_USER_ROLE , {
30
30
variables : {
31
31
orgToken
32
32
} ,
33
33
fetchPolicy : 'network-only' ,
34
34
} )
35
- const [ addRatingsByFile , { data : ratings , loading : loadingRatings , error : ratingsError } ] = useMutation ( ADD_RATINGS_BY_FILE )
35
+ const [ addRatingsByFile , { data : bulkRatings , loading : loadingBulkRatings , error : bulkRatingsError } ] = useMutation ( ADD_RATINGS_BY_FILE )
36
36
const [ formData , setFormData ] = useState < AddRatingsByFileFormData > ( {
37
37
sprint : '' ,
38
38
file : null
@@ -51,7 +51,7 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
51
51
orgToken
52
52
} ,
53
53
} )
54
- fetchSprints ( )
54
+ getRatingsByUserCohort ( )
55
55
toast . success ( "Rating completed succefully" )
56
56
} catch ( err : any ) {
57
57
toast . error ( err ?. message )
@@ -61,7 +61,7 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
61
61
const downloadTeamFile = async ( e : any ) => {
62
62
try {
63
63
if ( selectedTeam === '' ) throw new Error ( "No Team was selected" )
64
- const team = teams . getTeamsByRole . find ( ( team :any ) => team . id === selectedTeam )
64
+ const team = teams . getTeamsByUserRole . find ( ( team :any ) => team . id === selectedTeam )
65
65
const rows : any = [ ]
66
66
team . members . forEach ( ( member : any ) => {
67
67
console . log ( member )
@@ -91,8 +91,8 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
91
91
}
92
92
93
93
useEffect ( ( ) => {
94
- fetchSprints ( )
95
- getTeamsByRole ( )
94
+ getRatingsByUserCohort ( )
95
+ getTeamsByUserRole ( )
96
96
} , [ ] )
97
97
98
98
return (
@@ -105,10 +105,10 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
105
105
< hr className = "w-full my-3 border-b bg-primary" />
106
106
</ div >
107
107
< div >
108
- < form className = "flex flex-col gap-5" onSubmit = { saveRatings } >
108
+ < form data-testid = "bulRating-form" className = "flex flex-col gap-5" onSubmit = { saveRatings } >
109
109
< div className = "flex flex-col gap-1" >
110
110
< label > Choose a sprint</ label >
111
- < select className = "p-2 text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary"
111
+ < select data-testid = "select-sprint" className = "p-2 text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary"
112
112
defaultValue = { "" }
113
113
onChange = { ( e ) => {
114
114
e . preventDefault ( )
@@ -117,55 +117,62 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
117
117
>
118
118
< option > Choose a sprint</ option >
119
119
{
120
- sprints && ! sprints . fetchSprints . length ?
121
- < option value = { 1 } > Sprint 1</ option >
120
+ ratings && ! ratings . getRatingsByUserCohort . length ?
121
+ < option data-testid = "sprint-default-option" value = { 1 } > Sprint 1</ option >
122
122
: ''
123
123
}
124
124
{
125
- sprints && sprints . fetchSprints . length ?
126
- [ ...sprints . fetchSprints , sprints . fetchSprints [ sprints . fetchSprints . length - 1 ] + 1 ] . map ( ( sprint : number ) =>
127
- < option key = { sprint } value = { sprint } > Sprint { sprint } </ option >
125
+ ratings && ratings . getRatingsByUserCohort . length ?
126
+ [ ...ratings . getRatingsByUserCohort ] . map ( ( rating : any ) =>
127
+ < option data-testid = { ` sprint-option- ${ rating . id } ` } key = { rating . id } value = { rating . sprint } > Sprint { rating . sprint } </ option >
128
128
)
129
129
: ''
130
130
}
131
131
{
132
- loadingSprints ?
133
- < option > Loading ...</ option >
132
+ ratings && ratings . getRatingsByUserCohort . length ?
133
+ < option data-testid = "sprint-new-option" value = { [ ... ratings . getRatingsByUserCohort ] . pop ( ) . sprint + 1 } > Sprint { [ ...ratings . getRatingsByUserCohort ] . pop ( ) . sprint + 1 } </ option >
134
134
: ''
135
135
}
136
136
{
137
- sprintsError ?
138
- < option > No sprints found...</ option >
137
+ loadingRatings ?
138
+ < option data-testid = "sprint-loading-option" > Loading ...</ option >
139
+ : ''
140
+ }
141
+ {
142
+ ratingsError ?
143
+ < option data-testid = "sprint-error-option" > No sprints found...</ option >
139
144
: ''
140
145
}
141
146
</ select >
142
147
</ div >
143
148
< div className = "flex items-center justify-between" >
144
149
< input
150
+ data-testid = "file-input"
145
151
className = "w-1/2 h-full bg-gray-600 rounded-md"
146
152
type = "file"
147
153
onChange = { ( e ) => {
148
154
const file = e . target . files ?. [ 0 ]
149
155
setFormData ( { ...formData , file : file ? file : null } )
150
156
} }
157
+ accept = ".xlsx, .xls"
151
158
>
152
159
</ input >
153
160
< div className = "flex gap-2" >
154
- < select className = "p-2 text-sm text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary" defaultValue = { "" } onChange = { ( e ) => setSelectedTeam ( e . target . value ) } >
155
- < option > Choose a team</ option >
161
+ < select data-testid = "select-team" className = "p-2 text-sm text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary" defaultValue = { "" } onChange = { ( e ) => setSelectedTeam ( e . target . value ) } >
162
+ < option data-testid = "team-default-option" > Choose a team</ option >
156
163
{
157
- teams && teams . getTeamsByRole . length > 0 ?
158
- teams . getTeamsByRole . map ( ( team : any ) => < option key = { team . id } value = { team . id } > { team . name } </ option > )
164
+ teams && teams . getTeamsByUserRole . length > 0 ?
165
+ teams . getTeamsByUserRole . map ( ( team : any ) => < option data-testid = { `team-option- ${ team . id } ` } key = { team . id } value = { team . id } > { team . name } </ option > )
159
166
: ''
160
167
}
161
168
</ select >
162
- < button type = "button" onClick = { downloadTeamFile } className = "p-3 text-white rounded-lg bg-green-500 text-sm font-serif font-semibold" > Download</ button >
169
+ < button data-testid = "download-button" type = "button" onClick = { downloadTeamFile } className = "p-3 text-white rounded-lg bg-green-500 text-sm font-serif font-semibold" > Download</ button >
163
170
</ div >
164
171
</ div >
165
172
166
173
< div >
167
174
{
168
- ratings && ratings . addRatingsByFile . RejectedRatings . length > 0 ?
175
+ bulkRatings && bulkRatings . addRatingsByFile . RejectedRatings . length > 0 ?
169
176
< div className = "my-1 overflow-x-auto" >
170
177
< table className = "table-fixed min-w-full" >
171
178
< caption className = "caption-top text-left my-2" >
@@ -181,7 +188,7 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
181
188
</ tr >
182
189
</ thead >
183
190
< tbody >
184
- { ratings . addRatingsByFile ?. RejectedRatings . map ( ( rating : any , index : number ) =>
191
+ { bulkRatings . addRatingsByFile ?. RejectedRatings . map ( ( rating : any , index : number ) =>
185
192
< tr key = { index } className = "text-red-400" >
186
193
< td className = "text-left py-1 px-2" > { rating . email ? rating . email : "null" } </ td >
187
194
< td className = "text-left py-1 px-2" > { rating . quantity ? rating . quantity : "null" } </ td >
0 commit comments