Skip to content

Commit

Permalink
add fetchSprints query and addRatingsByFile mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
shema-surge committed Oct 23, 2024
1 parent bd05d16 commit fbf9229
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 12 deletions.
43 changes: 43 additions & 0 deletions src/Mutations/Ratings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,46 @@ export const REJECT_RATING = gql`
rejectRating(user: $user, sprint: $sprint)
}
`;

export const FETCH_SPRINTS = gql`
query fetchSprints($orgToken: String!){
fetchSprints(orgToken: $orgToken)
}
`

export const ADD_RATINGS_BY_FILE = gql`
mutation addRatingsByFile($file: Upload!, $sprint: Int!, $orgToken: String!){
addRatingsByFile(file: $file, sprint: $sprint orgToken: $orgToken){
NewRatings {
user {
email
}
sprint
phase
quality
quantity
professional_Skills
feedbacks {
sender {
email
}
content
createdAt
}
cohort {
name
}
}
RejectedRatings,
UpdatedRatings {
quantity
quality
professional_Skills
feedbacks {
content
}
oldFeedback
}
}
}
`
78 changes: 66 additions & 12 deletions src/components/BulkRatingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
import React from "react"
import { useLazyQuery, useMutation } from "@apollo/client"
import React, { useEffect, useState } from "react"
import { useTranslation } from "react-i18next"
import { ADD_RATINGS_BY_FILE, FETCH_SPRINTS } from "../Mutations/Ratings"
import { toast } from "react-toastify"

type BulkRatingModalProps = {
bulkRateModal: boolean,
setBulkRateModal: React.Dispatch<React.SetStateAction<boolean>>
}

type AddRatingsByFileFormData = {
sprint: string,
file: File | null,
}

const orgToken = localStorage.getItem('orgToken')

const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalProps) => {
const { t } = useTranslation()
const [fetchSprints, {data: sprints, loading: loadingSprints, error: sprintsError}] = useLazyQuery(FETCH_SPRINTS,{
variables:{
orgToken
},
fetchPolicy: 'network-only'
})
const [addRatingsByFile,{data: ratings, loading: loadingRatings, error: ratingsError}] = useMutation(ADD_RATINGS_BY_FILE)
const [formData, setFormData] = useState<AddRatingsByFileFormData>({
sprint: '',
file: null
})

const saveRatings=async(e: React.FormEvent)=>{
try{
e.preventDefault()
await addRatingsByFile({
variables: {
file:formData.file,
sprint:parseInt(formData.sprint),

Check failure on line 39 in src/components/BulkRatingModal.tsx

View workflow job for this annotation

GitHub Actions / build

Missing radix parameter
orgToken
},
})
console.log(ratings)

Check failure on line 43 in src/components/BulkRatingModal.tsx

View workflow job for this annotation

GitHub Actions / build

Unexpected console statement
toast.success("Rating completed susccefully")
}catch(err: any){
toast.error(err?.message)
}
}

useEffect(()=>{
fetchSprints()
},[])

return (
<div className={`${bulkRateModal? "block" : "hidden"} h-screen w-screen z-20 bg-black bg-opacity-30 backdrop-blur-sm fixed top-0 left-0 flex items-center justify-center px-4`}>
<div className="w-full p-4 pb-8 bg-indigo-100 rounded-lg dark:bg-dark-bg sm:w-3/4 xl:w-4/12">
Expand All @@ -18,21 +61,32 @@ const BulkRatingModal = ({ bulkRateModal, setBulkRateModal }: BulkRatingModalPro
<hr className="w-full my-3 border-b bg-primary" />
</div>
<div>
<form className="flex flex-col gap-5">
<div className="flex flex-col gap-1">
<label>Choose a cohort</label>
<select className="p-2 text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary">
<option value={"Cohort 1"}>Cohort 1</option>
</select>
</div>
<form className="flex flex-col gap-5" onSubmit={saveRatings}>
<div className="flex flex-col gap-1">
<label>Choose a sprint</label>
<select className="p-2 text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary">
<option value={"Cohort 1"}>Cohort 1</option>
</select>
<select className="p-2 text-black dark:text-white rounded-lg bg-white dark:bg-dark border-2 border-primary"
onChange={(e)=>{
e.preventDefault()
setFormData({...formData, sprint: e.target.value})
}}
>
{
sprints?
[...sprints.fetchSprints, sprints.fetchSprints[sprints.fetchSprints.length-1]+1].map((sprint: number)=>(<option key={sprint} value={sprint}>Sprint {sprint}</option>))
:<option>loading...</option>
}
</select>
</div>

<input className="" type="file"></input>
<input
className=""
type="file"
onChange={(e)=>{
const file = e.target.files?.[0]
setFormData({...formData, file: file ? file : null})
}}
>
</input>
<div className="flex justify-between w-full">
<button className="w-[40%] md:w-1/4 p-3 text-white rounded-lg bg-primary text-sm font-serif font-semibold" type="button" onClick={() => setBulkRateModal(false)}>
Cancel
Expand Down

0 comments on commit fbf9229

Please sign in to comment.