Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/apps/review/src/lib/hooks/useFetchSubmissionReviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import {
} from 'react'
import { find, forEach, map } from 'lodash'
import { toast } from 'react-toastify'
import useSWR, { SWRResponse } from 'swr'
import useSWR, { mutate, SWRResponse } from 'swr'

import { handleError } from '~/apps/admin/src/lib/utils'
import { EnvironmentConfig } from '~/config'

import {
AppealInfo,
Expand Down Expand Up @@ -458,7 +459,7 @@ export function useFetchSubmissionReviews(reviewId: string = ''): useFetchSubmis
data: appeals,
error: fetchAppealsError,
}: SWRResponse<AppealInfo[], Error> = useSWR<AppealInfo[], Error>(
`EnvironmentConfig.API.V6/appeals/resourceId/${resourceId}`,
`${EnvironmentConfig.API.V6}/appeals/resourceId/${resourceId}`,
{
fetcher: () => fetchAppeals(1, 100, resourceId),
isPaused: () => !resourceId,
Expand Down Expand Up @@ -857,8 +858,18 @@ export function useFetchSubmissionReviews(reviewId: string = ''): useFetchSubmis

setIsSavingAppealResponse(true)
Promise.all(listRequest)
.then(() => {
.then(async () => {
setIsSavingAppealResponse(false)
// Revalidate SWR caches so other components using the raw SWR data update immediately
try {
if (reviewId) {
// re-fetch review data
mutate(`EnvironmentConfig.API.V6/reviews/${reviewId}`)
}
} catch (e) {
// ignore mutate errors
}

toast.success('Appeal response saved successfully!')
success()
})
Expand All @@ -867,7 +878,7 @@ export function useFetchSubmissionReviews(reviewId: string = ''): useFetchSubmis
handleError(e)
})
},
[resourceId, reviewInfo, setUpdatedReviewInfo, updatedReviewInfo],
[resourceId, reviewInfo, setUpdatedReviewInfo, updatedReviewInfo, reviewId],
)

/**
Expand Down
2 changes: 1 addition & 1 deletion src/apps/review/src/lib/utils/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function getReviewRoute(
? `${prefix}/${match[1]}/${match[2]}`
: `/${match[1]}/${match[2]}`

return `${basePath}/reviews/${submissionId}?reviewId=${encodedReviewId}`
return `${basePath}/reviews/${submissionId}?reviewId=${encodedReviewId}&respondToAppeals=true`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
Adding &respondToAppeals=true to the query string changes the behavior of the route. Ensure that this change is intentional and that all parts of the application relying on this route are updated accordingly. If this parameter is optional, consider making it conditional to avoid potential issues with existing functionality.

}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { mutate } from 'swr'
import { FC, useCallback, useEffect, useMemo, useState } from 'react'
import { useSearchParams } from 'react-router-dom'

import { ChallengeLinksForAdmin } from '~/apps/review/src/lib/components/ChallengeLinksForAdmin'
import { ScorecardViewer } from '~/apps/review/src/lib/components/Scorecard'
Expand All @@ -25,6 +26,8 @@ import styles from './ReviewViewer.module.scss'

const ReviewViewer: FC = () => {
const navigate = useAppNavigate()
const [searchParams] = useSearchParams()
const [respondToAppeals, setRespondToAppeals] = useState(searchParams.get('respondToAppeals') === 'true')
const {
reviewId,
setReviewStatus,
Expand Down Expand Up @@ -205,8 +208,11 @@ const ReviewViewer: FC = () => {
useEffect(() => {
if (!canEditScorecard && isManagerEdit) {
setIsManagerEdit(false)
} else if (!isManagerEdit && respondToAppeals) {
setIsManagerEdit(true)
setRespondToAppeals(false)
}
}, [canEditScorecard, isManagerEdit])
}, [canEditScorecard, isManagerEdit, respondToAppeals])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The dependency array for this useEffect includes respondToAppeals, which is being set within the effect itself. This can lead to an infinite loop if not handled carefully. Ensure that the logic inside the effect does not inadvertently cause repeated state updates.


const toggleManagerEdit = useCallback(() => {
setIsManagerEdit(prev => !prev)
Expand Down
Loading