diff --git a/client/src/app/pages/applications/components/application-detail-drawer/application-detail-drawer-assessment.tsx b/client/src/app/pages/applications/components/application-detail-drawer/application-detail-drawer-assessment.tsx index 4ef6480e3d..6df452469b 100644 --- a/client/src/app/pages/applications/components/application-detail-drawer/application-detail-drawer-assessment.tsx +++ b/client/src/app/pages/applications/components/application-detail-drawer/application-detail-drawer-assessment.tsx @@ -20,7 +20,7 @@ import { ApplicationDetailDrawer, IApplicationDetailDrawerProps, } from "./application-detail-drawer"; -import { useGetReviewByItemId } from "@app/queries/reviews"; +import { useFetchReviewById } from "@app/queries/reviews"; export interface IApplicationDetailDrawerAssessmentProps extends Pick { @@ -32,7 +32,7 @@ export const ApplicationDetailDrawerAssessment: React.FC< > = ({ application, onCloseClick, task }) => { const { t } = useTranslation(); - const { review: appReview } = useGetReviewByItemId(application?.id); + const { review: appReview } = useFetchReviewById(application?.review?.id); const notYetReviewed = ( ); diff --git a/client/src/app/pages/reports/components/adoption-candidate-graph/adoption-candidate-graph.tsx b/client/src/app/pages/reports/components/adoption-candidate-graph/adoption-candidate-graph.tsx index 64b61904fa..05a8d49ec9 100644 --- a/client/src/app/pages/reports/components/adoption-candidate-graph/adoption-candidate-graph.tsx +++ b/client/src/app/pages/reports/components/adoption-candidate-graph/adoption-candidate-graph.tsx @@ -37,7 +37,7 @@ import { ApplicationSelectionContext } from "../../application-selection-context import { CartesianSquare } from "./cartesian-square"; import { Arrow } from "./arrow"; import useFetchApplicationDependencies from "@app/hooks/useFetchApplicationDependencies/useFetchApplicationDependencies"; -import { useGetReviewByItemId } from "@app/queries/reviews"; +import { useFetchReviewById } from "@app/queries/reviews"; interface Line { from: LinePoint; @@ -165,7 +165,7 @@ export const AdoptionCandidateGraph: React.FC = () => { const appConfidence = confidences.find( (elem) => elem.applicationId === current.id ); - const { review: appReview } = useGetReviewByItemId(current?.id); + const { review: appReview } = useFetchReviewById(current?.review?.id); if (appConfidence && appReview) { const key = appReview.proposedAction; diff --git a/client/src/app/pages/reports/components/adoption-candidate-table/adoption-candidate-table.tsx b/client/src/app/pages/reports/components/adoption-candidate-table/adoption-candidate-table.tsx index bad41d2078..3db5cddda8 100644 --- a/client/src/app/pages/reports/components/adoption-candidate-table/adoption-candidate-table.tsx +++ b/client/src/app/pages/reports/components/adoption-candidate-table/adoption-candidate-table.tsx @@ -22,7 +22,7 @@ import { } from "@app/api/models"; import { ApplicationSelectionContext } from "../../application-selection-context"; -import { useGetReviewByItemId } from "@app/queries/reviews"; +import { useFetchReviewById } from "@app/queries/reviews"; import { useQuery } from "@tanstack/react-query"; import { useFetchRisks } from "@app/queries/risks"; import { AppTableWithControls } from "@app/components/AppTableWithControls"; @@ -110,7 +110,7 @@ export const AdoptionCandidateTable: React.FC = () => { const confidenceData = confidence?.find( (e) => e.applicationId === app.id ); - const { review: reviewData } = useGetReviewByItemId(app?.id); + const { review: reviewData } = useFetchReviewById(app?.review?.id); const riskData = assessmentRisks?.find((e) => e.applicationId === app.id); diff --git a/client/src/app/pages/review/components/application-details/application-details.tsx b/client/src/app/pages/review/components/application-details/application-details.tsx index 13973a8871..bab21fcfbf 100644 --- a/client/src/app/pages/review/components/application-details/application-details.tsx +++ b/client/src/app/pages/review/components/application-details/application-details.tsx @@ -13,7 +13,7 @@ import { Application, Assessment } from "@app/api/models"; import { useFetchQuestionnaires } from "@app/queries/questionnaires"; export interface IApplicationDetailsProps { - application: Application; + application?: Application; assessment?: Assessment; } @@ -27,7 +27,7 @@ export const ApplicationDetails: React.FC = ({ (questionnaire) => questionnaire.id === assessment?.questionnaire?.id ); const { t } = useTranslation(); - if (!matchingQuestionnaire) { + if (!matchingQuestionnaire || !application) { return null; } diff --git a/client/src/app/pages/review/components/review-form/review-form.tsx b/client/src/app/pages/review/components/review-form/review-form.tsx index 2812956aae..d7cb37c527 100644 --- a/client/src/app/pages/review/components/review-form/review-form.tsx +++ b/client/src/app/pages/review/components/review-form/review-form.tsx @@ -55,6 +55,7 @@ export const ReviewForm: React.FC = ({ application, review, }) => { + console.log("existing review", review); const { t } = useTranslation(); const history = useHistory(); const { pushNotification } = React.useContext(NotificationsContext); diff --git a/client/src/app/pages/review/review-page.tsx b/client/src/app/pages/review/review-page.tsx index 84887a9493..5928336b07 100644 --- a/client/src/app/pages/review/review-page.tsx +++ b/client/src/app/pages/review/review-page.tsx @@ -22,8 +22,9 @@ import QuestionnaireSummary, { SummaryType, } from "@app/components/questionnaire-summary/questionnaire-summary"; import { PageHeader } from "@app/components/PageHeader"; -import { useGetReviewByItemId } from "@app/queries/reviews"; +import { useFetchReviewById } from "@app/queries/reviews"; import useIsArchetype from "@app/hooks/useIsArchetype"; +import { useFetchApplicationById } from "@app/queries/applications"; import { useFetchArchetypeById } from "@app/queries/archetypes"; const ReviewPage: React.FC = () => { @@ -32,12 +33,15 @@ const ReviewPage: React.FC = () => { const { applicationId, archetypeId } = useParams(); const isArchetype = useIsArchetype(); - const { application, review, fetchError, isFetching } = useGetReviewByItemId( - applicationId || archetypeId - ); - const { archetype } = useFetchArchetypeById(archetypeId); + const { application } = useFetchApplicationById(applicationId); + const { review, fetchError, isFetching } = useFetchReviewById( + isArchetype ? archetype?.review?.id : application?.review?.id + ); + console.log("archetype.review", archetype?.review?.id); + console.log("reviewl", review); + console.log("isFetchign", isFetching); const assessment = undefined; const breadcrumbs = [ ...(isArchetype @@ -53,10 +57,10 @@ const ReviewPage: React.FC = () => { path: Paths.applications, }, ]), - { - title: t("terms.review"), - path: Paths.applicationsReview, - }, + // { + // title: t("terms.review"), + // path: Paths.applicationsReview, + // }, ]; if (fetchError) { @@ -92,41 +96,30 @@ const ReviewPage: React.FC = () => { description={ {t("message.reviewInstructions")} } - breadcrumbs={[ - { - title: t("terms.applications"), - path: Paths.applications, - }, - { - title: t("terms.review"), - path: Paths.applicationsReview, - }, - ]} + breadcrumbs={breadcrumbs} menuActions={[]} /> }> - {application && ( - -
- - - - - - -
-
- )} + +
+ + + + + + +
+
{assessment && ( diff --git a/client/src/app/queries/reviews.ts b/client/src/app/queries/reviews.ts index 2ac407c343..c841da5880 100644 --- a/client/src/app/queries/reviews.ts +++ b/client/src/app/queries/reviews.ts @@ -9,8 +9,6 @@ import { } from "@app/api/rest"; import { New, Review } from "@app/api/models"; import { AxiosError } from "axios"; -import { useFetchApplicationById } from "./applications"; -import { useFetchArchetypeById } from "./archetypes"; export const reviewQueryKey = "review"; export const reviewsByItemIdQueryKey = "reviewsByItemId"; @@ -92,52 +90,18 @@ export const useDeleteReviewMutation = ( }); }; -export function useGetReviewByItemId(id?: string | number) { - const { - application, - isFetching: isApplicationFetching, - fetchError: applicationError, - } = useFetchApplicationById(id); - - const { - archetype, - isFetching: isArchetypeFetching, - fetchError: archetypeError, - } = useFetchArchetypeById(id); - - let review = null; - let isLoading = false; - let isError = false; - - const reviewId = application?.review?.id || archetype?.review?.id; - - const reviewQuery = useQuery( - [ - reviewsByItemIdQueryKey, - reviewId, - application?.review?.id, - archetype?.review?.id, - ], - () => (reviewId ? getReviewById(reviewId) : null), - { - enabled: !!reviewId, - } - ); - - if (reviewId) { - review = reviewQuery.data; - isLoading = reviewQuery.isLoading; - isError = reviewQuery.isError; - } +export const useFetchReviewById = (id?: number | string) => { + const { data, isLoading, error, isFetching } = useQuery({ + queryKey: [reviewQueryKey, id], + queryFn: () => + id === undefined ? Promise.resolve(null) : getReviewById(id), + onError: (error: AxiosError) => console.log("error, ", error), + enabled: id !== undefined, + }); return { - application, - archetype, - review, - isLoading, - isError, - isFetching: isApplicationFetching || isLoading || isArchetypeFetching, - fetchError: - applicationError || (review ? reviewQuery.error : null) || archetypeError, + review: data, + isFetching: isFetching, + fetchError: error, }; -} +};