From b5dcf4ad626a41be7e3ffa566a3c0c843c2bc2a4 Mon Sep 17 00:00:00 2001 From: NSUWAL123 Date: Thu, 21 Mar 2024 17:53:33 +0545 Subject: [PATCH 1/6] feat updateReviewState: post update review-state api integration --- src/frontend/src/api/SubmissionService.ts | 33 +++++++++ .../ProjectSubmissions/SubmissionsTable.tsx | 4 +- .../UpdateReviewStatusModal.tsx | 73 +++++++++++++------ .../src/store/slices/SubmissionSlice.ts | 6 +- src/frontend/src/store/types/ISubmissions.ts | 5 +- 5 files changed, 97 insertions(+), 24 deletions(-) diff --git a/src/frontend/src/api/SubmissionService.ts b/src/frontend/src/api/SubmissionService.ts index 2ba55763b7..ecd9b1be05 100644 --- a/src/frontend/src/api/SubmissionService.ts +++ b/src/frontend/src/api/SubmissionService.ts @@ -1,4 +1,5 @@ import CoreModules from '@/shared/CoreModules'; +import { CommonActions } from '@/store/slices/CommonSlice'; import { ProjectActions } from '@/store/slices/ProjectSlice'; // import { HomeProjectCardModel } from '@/models/home/homeModel'; import { SubmissionActions } from '@/store/slices/SubmissionSlice'; @@ -114,3 +115,35 @@ export const SubmissionTableService: Function = (url: string, payload) => { await fetchSubmissionTable(url, payload); }; }; + +export const UpdateReviewStateService: Function = (url: string) => { + return async (dispatch) => { + const UpdateReviewState = async (url: string) => { + try { + dispatch(SubmissionActions.UpdateReviewStateLoading(true)); + const response = await CoreModules.axios.post(url); + dispatch( + SubmissionActions.SetUpdateReviewStatusModal({ + toggleModalStatus: false, + submissionId: null, + instanceId: null, + taskId: null, + }), + ); + dispatch(SubmissionActions.UpdateReviewStateLoading(false)); + } catch (error) { + dispatch( + CommonActions.SetSnackBar({ + open: true, + message: 'Failed to update review state.', + variant: 'error', + duration: 2000, + }), + ); + dispatch(SubmissionActions.UpdateReviewStateLoading(false)); + } + }; + + await UpdateReviewState(url); + }; +}; diff --git a/src/frontend/src/components/ProjectSubmissions/SubmissionsTable.tsx b/src/frontend/src/components/ProjectSubmissions/SubmissionsTable.tsx index a8bf4b61a5..77bbb6e567 100644 --- a/src/frontend/src/components/ProjectSubmissions/SubmissionsTable.tsx +++ b/src/frontend/src/components/ProjectSubmissions/SubmissionsTable.tsx @@ -446,7 +446,9 @@ const SubmissionsTable = ({ toggleView }) => { dispatch( SubmissionActions.SetUpdateReviewStatusModal({ toggleModalStatus: true, - submissionId: row?.meta?.instanceID, + instanceId: row?.meta?.instanceID, + taskId: row?.phonenumber, + projectId: decodedId, }), ); }} diff --git a/src/frontend/src/components/ProjectSubmissions/UpdateReviewStatusModal.tsx b/src/frontend/src/components/ProjectSubmissions/UpdateReviewStatusModal.tsx index 49b0b0ef31..f18ccd95f4 100644 --- a/src/frontend/src/components/ProjectSubmissions/UpdateReviewStatusModal.tsx +++ b/src/frontend/src/components/ProjectSubmissions/UpdateReviewStatusModal.tsx @@ -1,11 +1,12 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { Modal } from '@/components/common/Modal'; -import CoreModules from '@/shared/CoreModules'; import { useDispatch } from 'react-redux'; import { SubmissionActions } from '@/store/slices/SubmissionSlice'; import { reviewListType } from '@/models/submission/submissionModel'; +import { UpdateReviewStateService } from '@/api/SubmissionService'; import TextArea from '../common/TextArea'; import Button from '../common/Button'; +import { useAppSelector } from '@/types/reduxTypes'; const reviewList: reviewListType[] = [ { @@ -15,7 +16,7 @@ const reviewList: reviewListType[] = [ hoverClass: 'hover:fmtm-text-[#40B449] hover:fmtm-border-[#40B449]', }, { - id: 'hasIssue', + id: 'hasIssues', title: 'Has Issue', className: 'fmtm-bg-[#E9DFCF] fmtm-text-[#D99F00] fmtm-border-[#D99F00]', hoverClass: 'hover:fmtm-text-[#D99F00] hover:fmtm-border-[#D99F00]', @@ -30,9 +31,31 @@ const reviewList: reviewListType[] = [ const UpdateReviewStatusModal = () => { const dispatch = useDispatch(); - const [reviewStatus, setReviewStatus] = useState(''); - const [noteComments, setNoteComments] = useState(''); - const updateReviewStatusModal = CoreModules.useAppSelector((state) => state.submission.updateReviewStatusModal); + const [reviewStatus, setReviewStatus] = useState(''); + const [noteComments, setNoteComments] = useState(''); + const [error, setError] = useState(''); + const updateReviewStatusModal = useAppSelector((state) => state.submission.updateReviewStatusModal); + const updateReviewStateLoading = useAppSelector((state) => state.submission.updateReviewStateLoading); + + const handleStatusUpdate = () => { + if (!updateReviewStatusModal.instanceId || !updateReviewStatusModal.projectId || !updateReviewStatusModal.taskId) { + return; + } + + if (!reviewStatus) { + setError('Review state needs to be selected.'); + return; + } + dispatch( + UpdateReviewStateService( + `${import.meta.env.VITE_API_URL}/submission/update_review_state/${ + updateReviewStatusModal.projectId + }?project_id=${updateReviewStatusModal.projectId}&task_id=${parseInt( + updateReviewStatusModal.taskId, + )}&instance_id=${updateReviewStatusModal.instanceId}&review_state=${reviewStatus}`, + ), + ); + }; return ( { className="!fmtm-w-fit !fmtm-outline-none fmtm-rounded-xl" description={
-
- {reviewList.map((reviewBtn) => ( - - ))} +
+
+ {reviewList.map((reviewBtn) => ( + + ))} +
+ {error &&

{error}

}