@@ -2,9 +2,9 @@ import { useLazyQuery, useMutation } from "@apollo/client"
22import React , { useEffect , useState } from "react"
33import { useTranslation } from "react-i18next"
44import * 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"
66import { toast } from "react-toastify"
7- import { GET_TEAMS_BY_ROLE } from "../Mutations/teamMutation"
7+ import { GET_TEAMS_BY_USER_ROLE } from "../Mutations/teamMutation"
88
99type BulkRatingModalProps = {
1010 bulkRateModal : boolean ,
@@ -20,19 +20,19 @@ const orgToken = localStorage.getItem('orgToken')
2020
2121const BulkRatingModal = ( { bulkRateModal, setBulkRateModal } : BulkRatingModalProps ) => {
2222 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 , {
2424 variables : {
2525 orgToken
2626 } ,
2727 fetchPolicy : 'network-only' ,
2828 } )
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 , {
3030 variables : {
3131 orgToken
3232 } ,
3333 fetchPolicy : 'network-only' ,
3434 } )
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 )
3636 const [ formData , setFormData ] = useState < AddRatingsByFileFormData > ( {
3737 sprint : '' ,
3838 file : null
@@ -51,7 +51,7 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
5151 orgToken
5252 } ,
5353 } )
54- fetchSprints ( )
54+ getRatingsByUserCohort ( )
5555 toast . success ( "Rating completed succefully" )
5656 } catch ( err : any ) {
5757 toast . error ( err ?. message )
@@ -61,7 +61,7 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
6161 const downloadTeamFile = async ( e : any ) => {
6262 try {
6363 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 )
6565 const rows : any = [ ]
6666 team . members . forEach ( ( member : any ) => {
6767 console . log ( member )
@@ -91,8 +91,8 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
9191 }
9292
9393 useEffect ( ( ) => {
94- fetchSprints ( )
95- getTeamsByRole ( )
94+ getRatingsByUserCohort ( )
95+ getTeamsByUserRole ( )
9696 } , [ ] )
9797
9898 return (
@@ -105,10 +105,10 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
105105 < hr className = "w-full my-3 border-b bg-primary" />
106106 </ div >
107107 < 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 } >
109109 < div className = "flex flex-col gap-1" >
110110 < 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"
112112 defaultValue = { "" }
113113 onChange = { ( e ) => {
114114 e . preventDefault ( )
@@ -117,55 +117,62 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
117117 >
118118 < option > Choose a sprint</ option >
119119 {
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 >
122122 : ''
123123 }
124124 {
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 >
128128 )
129129 : ''
130130 }
131131 {
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 >
134134 : ''
135135 }
136136 {
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 >
139144 : ''
140145 }
141146 </ select >
142147 </ div >
143148 < div className = "flex items-center justify-between" >
144149 < input
150+ data-testid = "file-input"
145151 className = "w-1/2 h-full bg-gray-600 rounded-md"
146152 type = "file"
147153 onChange = { ( e ) => {
148154 const file = e . target . files ?. [ 0 ]
149155 setFormData ( { ...formData , file : file ? file : null } )
150156 } }
157+ accept = ".xlsx, .xls"
151158 >
152159 </ input >
153160 < 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 >
156163 {
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 > )
159166 : ''
160167 }
161168 </ 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 >
163170 </ div >
164171 </ div >
165172
166173 < div >
167174 {
168- ratings && ratings . addRatingsByFile . RejectedRatings . length > 0 ?
175+ bulkRatings && bulkRatings . addRatingsByFile . RejectedRatings . length > 0 ?
169176 < div className = "my-1 overflow-x-auto" >
170177 < table className = "table-fixed min-w-full" >
171178 < caption className = "caption-top text-left my-2" >
@@ -181,7 +188,7 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
181188 </ tr >
182189 </ thead >
183190 < tbody >
184- { ratings . addRatingsByFile ?. RejectedRatings . map ( ( rating : any , index : number ) =>
191+ { bulkRatings . addRatingsByFile ?. RejectedRatings . map ( ( rating : any , index : number ) =>
185192 < tr key = { index } className = "text-red-400" >
186193 < td className = "text-left py-1 px-2" > { rating . email ? rating . email : "null" } </ td >
187194 < td className = "text-left py-1 px-2" > { rating . quantity ? rating . quantity : "null" } </ td >
0 commit comments