Skip to content

Commit

Permalink
fix(updateReviewStatusModal): on submission approve or previously rej…
Browse files Browse the repository at this point in the history
…ected entity, delete bad geometry record
  • Loading branch information
NSUWAL123 committed Jan 17, 2025
1 parent baf3093 commit 58b52d6
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import React, { useEffect, useState } from 'react';
import { Modal } from '@/components/common/Modal';
import { SubmissionActions } from '@/store/slices/SubmissionSlice';
import { reviewListType } from '@/models/submission/submissionModel';
import { PostGeometry, UpdateReviewStateService } from '@/api/SubmissionService';
import { DeleteGeometry, PostGeometry, UpdateReviewStateService } from '@/api/SubmissionService';
import TextArea from '../common/TextArea';
import Button from '../common/Button';
import { PostProjectComments, UpdateEntityState } from '@/api/Project';
import { GetGeometryLog, PostProjectComments, UpdateEntityState } from '@/api/Project';
import { entity_state } from '@/types/enums';
import { useAppDispatch, useAppSelector } from '@/types/reduxTypes';
import { task_event } from '@/types/enums';
Expand Down Expand Up @@ -33,11 +33,19 @@ const UpdateReviewStatusModal = () => {
const [reviewStatus, setReviewStatus] = useState('');
const updateReviewStatusModal = useAppSelector((state) => state.submission.updateReviewStatusModal);
const updateReviewStateLoading = useAppSelector((state) => state.submission.updateReviewStateLoading);
const badGeomLogList = useAppSelector((state) => state?.project?.badGeomLogList);

useEffect(() => {
setReviewStatus(updateReviewStatusModal.reviewState);
}, [updateReviewStatusModal.reviewState]);

useEffect(() => {
if (!updateReviewStatusModal.projectId) return;
dispatch(
GetGeometryLog(`${import.meta.env.VITE_API_URL}/projects/${updateReviewStatusModal.projectId}/geometry/records`),
);
}, [updateReviewStatusModal.projectId]);

const handleStatusUpdate = async () => {
if (
!updateReviewStatusModal.instanceId ||
Expand All @@ -61,7 +69,6 @@ const UpdateReviewStatusModal = () => {
);

// post bad geometry if submission is marked as hasIssues
// delete bad geometry if submission is marked as approved
if (reviewStatus === 'hasIssues') {
const badFeature = {
...(updateReviewStatusModal.feature as featureType),
Expand All @@ -85,6 +92,18 @@ const UpdateReviewStatusModal = () => {
);
}

// delete bad geometry if the entity previously has rejected submission and current submission is marked as approved
if (reviewStatus === 'approved') {
const badGeomId = badGeomLogList.find(
(geom) => geom.geojson.properties.entity_id === updateReviewStatusModal.entity_id,
)?.id;
dispatch(
DeleteGeometry(
`${import.meta.env.VITE_API_URL}/projects/${updateReviewStatusModal.projectId}/geometry/records/${badGeomId}`,
),
);
}

dispatch(
UpdateEntityState(
`${import.meta.env.VITE_API_URL}/projects/${updateReviewStatusModal.projectId}/entity/status`,
Expand All @@ -96,6 +115,7 @@ const UpdateReviewStatusModal = () => {
),
);
}

if (noteComments.trim().length > 0) {
dispatch(
PostProjectComments(
Expand Down

0 comments on commit 58b52d6

Please sign in to comment.