diff --git a/package-lock.json b/package-lock.json index ba289ee9a..ebf44d55b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,7 +1,7 @@ { "name": "atlp-pulse-fn", "version": "2.0.0", - "lockfileVersion": 2, + "lockfileVersion": 3, "requires": true, "packages": { "": { @@ -22048,8 +22048,9 @@ }, "node_modules/webpack-cli": { "version": "4.10.0", + "resolved": "https://registry.npmjs.org/webpack-cli/-/webpack-cli-4.10.0.tgz", + "integrity": "sha512-NLhDfH/h4O6UOy+0LSso42xvYypClINuMNBVVzX4vX98TmTaTUxwRbXdhucbFMd2qLaCTcLq/PdYrvi8onw90w==", "dev": true, - "license": "MIT", "dependencies": { "@discoveryjs/json-ext": "^0.5.0", "@webpack-cli/configtest": "^1.2.0", @@ -22679,6 +22680,7 @@ "zen-observable": "0.8.15" } } +<<<<<<< HEAD }, "dependencies": { "@aashutoshrathi/word-wrap": { @@ -37175,5 +37177,7 @@ "zen-observable": "0.8.15" } } +======= +>>>>>>> 70c0cf0 (Coordinate should update ratings) } } diff --git a/src/components/ratings/ViewWeeklyRatings.tsx b/src/components/ratings/ViewWeeklyRatings.tsx index 782a0217f..7e25f79cb 100644 --- a/src/components/ratings/ViewWeeklyRatings.tsx +++ b/src/components/ratings/ViewWeeklyRatings.tsx @@ -1,13 +1,17 @@ /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ /* istanbul ignore file */ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { Dialog } from '@mui/material'; import { useNavigate } from 'react-router'; +import { toast } from 'react-toastify'; +import { useLazyQuery, useMutation } from '@apollo/client'; import AddNewRatings from './AddNewRatings'; import Dropout from './Dropout'; import useViewTraineeRatings from './hooks/useViewTraineeRatings'; -import Spinner from '../Spinner'; +import Button from '../Buttons'; +import { UPDATE_RATING } from '../../Mutations/Ratings'; +import { DEFAULT_GRADE } from '../../Mutations/MakeDefault'; function ViewSprintRatings({ traineeName, @@ -18,6 +22,12 @@ function ViewSprintRatings({ }: any) { const [selectSprint, setSelectSprint] = useState(null); const [openModel, setOpenModel] = useState(true); + const [editRatingFormVisible, setEditRatingFormVisible] = useState(false); + const [updateMessage, setUpdateMessage] = useState(''); + const [defaultGrading, setDefaultGrading] = useState([]); + const [loggedUserRole, setloggedUser] = useState(null); + + const [showActions, setShowActions] = useState(false); const navigate = useNavigate(); const { onClose, @@ -37,13 +47,97 @@ function ViewSprintRatings({ setSuccessMessage, loading, } = useViewTraineeRatings({ traineeEmail, selectSprint, setOpenModel }); - if (loading) { - return ( -
- -
- ); - } + + useEffect(() => { + // eslint-disable-next-line no-use-before-define + DefaultGrade({ + fetchPolicy: 'network-only', + onCompleted: (data) => { + setDefaultGrading(data?.getDefaultGrading[0]?.grade); + }, + + onError: (error) => { + toast.error(error?.message || 'Failed to load the data'); + }, + }); + + const storedAuth = localStorage.getItem('auth'); + + if (storedAuth) { + const auth = JSON.parse(storedAuth); + const { role } = auth; + if (role) { + setloggedUser(role); + } + } + }, []); + + const [DefaultGrade] = useLazyQuery(DEFAULT_GRADE, {}); + const [updateRatings, { loading: updateRatingLoading, data, error }] = + useMutation(UPDATE_RATING); + + const openEditRatingForm = () => { + setEditRatingFormVisible(true); + }; + + const [rows, setRows] = useState({}); + + useEffect(() => { + if (maxSprint > 0 && selectedSprintRatings) { + const ratingChosen: any = selectedSprintRatings[0]; + setRows({ + quality: ratingChosen.quality, + qualityremark: '', + quantity: ratingChosen.quantity, + quantityremark: '', + feedback: '', + professional: ratingChosen.professional_Skills, + professionalRemark: '', + bodyQuantity: '', + bodyQuality: '', + bodyProfessional: ratingChosen.professionalRemark, + sprint: ratingChosen.sprint, + username: '', + user: {}, + id: '', + }); + } + }, [editRatingFormVisible]); + + useEffect(() => { + if (updateMessage) { + const time = setTimeout(() => { + setUpdateMessage(''); + }, 1500); + } + }, [updateMessage]); + + const handleUpdate = async (e: any) => { + e.preventDefault(); + + try { + const ratingsData = { + user: traineeId, + sprint: rows.sprint, + quantity: rows?.quantity, + quantityRemark: rows?.quantityremark, + quality: rows?.quality, + qualityRemark: rows?.qualityremark, + professionalSkills: rows?.professional, + professionalRemark: rows?.professionalRemark, + orgToken: organizationToken, + }; + await updateRatings({ variables: { ...ratingsData } }); + + setUpdateMessage('Rating updated successfully'); + } catch (error: any) { + toast.error(error.message || 'something went wrong'); + setShowActions(true); + } + setEditRatingFormVisible(false); + setUpdateMessage('Waiting for the Admin to Approve'); + setOpenModel(true); + }; return (
@@ -202,6 +296,7 @@ function ViewSprintRatings({
))} +
) : (
@@ -214,27 +309,179 @@ function ViewSprintRatings({ )} {traineeStatus.status === 'active' ? ( -
- {successMessage ? ( -

{successMessage}

- ) : ( - '' - )} - + {updateMessage || successMessage ? ( +

+ {updateMessage || successMessage} +

+ ) : ( + '' + )} +
+
+ {!viewAddNewRating && + !editRatingFormVisible && + loggedUserRole === 'coordinator' && ( + + )} +
+
+ {!viewAddNewRating && + !editRatingFormVisible && + loggedUserRole === 'coordinator' && ( + + )} +
) : ( )} + + {editRatingFormVisible && maxSprint !== 0 && ( +
+
+

+ {t('Update Rating')} +

+
+
+
{t('Quality')}:
+ +
+
+
{t('Quantity')}:
+ +
+
+
+ {t('Professionalism')}: +
+ +
+
+
+

{t('Feedback')}

+