From 9d3216f0b7c8eff5823d7b83126ce3a8ca517021 Mon Sep 17 00:00:00 2001 From: ibolton336 Date: Tue, 19 Sep 2023 21:43:26 -0400 Subject: [PATCH 1/2] Review archetypes code implementation Signed-off-by: ibolton336 --- client/src/app/Paths.ts | 1 + client/src/app/Routes.tsx | 5 ++ client/src/app/api/models.ts | 2 + .../application-detail-drawer-assessment.tsx | 4 +- .../app/pages/archetypes/archetypes-page.tsx | 25 +++++---- .../adoption-candidate-graph.tsx | 4 +- .../adoption-candidate-table.tsx | 4 +- .../components/review-form/review-form.tsx | 51 +++++++------------ client/src/app/pages/review/review-page.tsx | 39 +++++++++----- client/src/app/queries/reviews.ts | 37 ++++++++++---- 10 files changed, 101 insertions(+), 71 deletions(-) diff --git a/client/src/app/Paths.ts b/client/src/app/Paths.ts index 27d3dbc904..b2e55c63fa 100644 --- a/client/src/app/Paths.ts +++ b/client/src/app/Paths.ts @@ -16,6 +16,7 @@ export enum Paths { applicationAssessmentSummary = "/applications/assessment-summary/:assessmentId", archetypeAssessmentSummary = "/archetypes/assessment-summary/:assessmentId", applicationsReview = "/applications/:applicationId/review", + archetypeReview = "/archetypes/:archetypeId/review", applicationsAnalysis = "/applications/analysis", archetypes = "/archetypes", controls = "/controls", diff --git a/client/src/app/Routes.tsx b/client/src/app/Routes.tsx index fb4bac0ab9..1575586ea6 100644 --- a/client/src/app/Routes.tsx +++ b/client/src/app/Routes.tsx @@ -90,6 +90,11 @@ export const devRoutes: IRoute[] = [ comp: Assessment, exact: false, }, + { + path: Paths.archetypeReview, + comp: Review, + exact: false, + }, { path: Paths.applicationsReview, comp: Review, diff --git a/client/src/app/api/models.ts b/client/src/app/api/models.ts index 804c807ee7..d4ad356db9 100644 --- a/client/src/app/api/models.ts +++ b/client/src/app/api/models.ts @@ -139,6 +139,7 @@ export interface Review { workPriority: number; comments?: string; application?: Ref; + archetype?: Ref; } export interface ApplicationDependency { @@ -753,4 +754,5 @@ export interface Archetype { stakeholderGroups?: Ref[]; applications?: Ref[]; assessments?: Ref[]; + review?: Ref; } 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 9889a331fa..4ef6480e3d 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 { useGetReviewByAppId } from "@app/queries/reviews"; +import { useGetReviewByItemId } 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 } = useGetReviewByAppId(application?.id || ""); + const { review: appReview } = useGetReviewByItemId(application?.id); const notYetReviewed = ( ); diff --git a/client/src/app/pages/archetypes/archetypes-page.tsx b/client/src/app/pages/archetypes/archetypes-page.tsx index 586003ede1..f92ce72854 100644 --- a/client/src/app/pages/archetypes/archetypes-page.tsx +++ b/client/src/app/pages/archetypes/archetypes-page.tsx @@ -69,6 +69,7 @@ const Archetypes: React.FC = () => { const [archetypeToEdit, setArchetypeToEdit] = useState( null ); + const [reviewToEdit, setReviewToEdit] = React.useState(null); const [archetypeToDuplicate, setArchetypeToDuplicate] = useState(null); @@ -186,16 +187,15 @@ const Archetypes: React.FC = () => { } }; const reviewSelectedArchetype = (archetype: Archetype) => { - //TODO: Review archetype - // if (application.review) { - // setReviewToEdit(application.id); - // } else { - // history.push( - // formatPath(Paths.applicationsReview, { - // applicationId: application.id, - // }) - // ); - // } + if (archetype.review) { + setReviewToEdit(archetype.id); + } else { + history.push( + formatPath(Paths.archetypeReview, { + archetypeId: archetype.id, + }) + ); + } }; return ( @@ -309,6 +309,11 @@ const Archetypes: React.FC = () => { onClick: () => assessSelectedArchetype(archetype), }, + { + title: t("actions.review"), + onClick: () => + reviewSelectedArchetype(archetype), + }, { title: t("actions.edit"), onClick: () => setArchetypeToEdit(archetype), 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 a2af7bf25c..64b61904fa 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 @@ -36,8 +36,8 @@ import { import { ApplicationSelectionContext } from "../../application-selection-context"; import { CartesianSquare } from "./cartesian-square"; import { Arrow } from "./arrow"; -import { useGetReviewByAppId } from "@app/queries/reviews"; import useFetchApplicationDependencies from "@app/hooks/useFetchApplicationDependencies/useFetchApplicationDependencies"; +import { useGetReviewByItemId } 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 } = useGetReviewByAppId(current?.id || ""); + const { review: appReview } = useGetReviewByItemId(current?.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 b5169ef6cf..bad41d2078 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 { useGetReviewByAppId } from "@app/queries/reviews"; +import { useGetReviewByItemId } 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 } = useGetReviewByAppId(app?.id || ""); + const { review: reviewData } = useGetReviewByItemId(app?.id); const riskData = assessmentRisks?.find((e) => e.applicationId === app.id); 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 abb25131bb..b9e048f957 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 @@ -15,6 +15,7 @@ import { PROPOSED_ACTION_LIST, EFFORT_ESTIMATE_LIST } from "@app/Constants"; import { number } from "yup"; import { Application, + Archetype, EffortEstimate, New, ProposedAction, @@ -35,6 +36,7 @@ import { useQueryClient } from "@tanstack/react-query"; import { useHistory } from "react-router-dom"; import { Paths } from "@app/Paths"; import { NotificationsContext } from "@app/components/NotificationsContext"; +import useIsArchetype from "@app/hooks/useIsArchetype"; export interface FormValues { action: ProposedAction; @@ -45,17 +47,20 @@ export interface FormValues { } export interface IReviewFormProps { - application: Application; + application?: Application; + archetype?: Archetype; review?: Review | null; } export const ReviewForm: React.FC = ({ + archetype, application, review, }) => { const { t } = useTranslation(); const history = useHistory(); const { pushNotification } = React.useContext(NotificationsContext); + const isArchetype = useIsArchetype(); const actionOptions: OptionWithValue[] = useMemo(() => { return Object.entries(PROPOSED_ACTION_LIST).map(([key, value]) => ({ @@ -107,39 +112,11 @@ export const ReviewForm: React.FC = ({ console.log("Invalid form", errors); }; - // const onSubmit = (formValues: FormValues) => { - // const payload: Review = { - // ...review, - // proposedAction: formValues.action, - // effortEstimate: formValues.effort, - // businessCriticality: formValues.criticality || 0, - // workPriority: formValues.priority || 0, - // comments: formValues.comments.trim(), - // // application: { ...application, review: undefined }, - // application: { id: application.id, name: application.name }, - // }; - - // let promise: Promise; - // if (review) { - // promise = updateReview({ - // ...review, - // ...payload, - // }); - // } else { - // promise = createReview(payload); - // } - - // promise - // .then((response) => { - // onSaved(response); - // }) - // .catch((error) => {}); - // }; const queryClient = useQueryClient(); const onHandleUpdateReviewSuccess = () => { queryClient.invalidateQueries([ reviewsByItemIdQueryKey, - application.review?.id, + application?.review?.id, ]); }; const createReviewMutation = useCreateReviewMutation(); @@ -155,7 +132,15 @@ export const ReviewForm: React.FC = ({ businessCriticality: formValues.criticality || 0, workPriority: formValues.priority || 0, comments: formValues.comments.trim(), - application: { id: application.id, name: application.name }, + ...(isArchetype && archetype + ? { + archetype: { id: archetype.id, name: archetype.name }, + } + : application + ? { + application: { id: application.id, name: application.name }, + } + : undefined), }; try { @@ -178,7 +163,7 @@ export const ReviewForm: React.FC = ({ }); } - history.push(Paths.applications); + history.push(isArchetype ? Paths.archetypes : Paths.applications); } catch (error) { console.error("Error:", error); pushNotification({ @@ -309,7 +294,7 @@ export const ReviewForm: React.FC = ({ aria-label="cancel" variant={ButtonVariant.link} onClick={() => { - history.push(Paths.applications); + history.push(isArchetype ? Paths.archetypes : Paths.applications); }} > {t("actions.cancel")} diff --git a/client/src/app/pages/review/review-page.tsx b/client/src/app/pages/review/review-page.tsx index 6e1053b9a7..3a33e005fa 100644 --- a/client/src/app/pages/review/review-page.tsx +++ b/client/src/app/pages/review/review-page.tsx @@ -22,15 +22,18 @@ import QuestionnaireSummary, { SummaryType, } from "@app/components/questionnaire-summary/questionnaire-summary"; import { PageHeader } from "@app/components/PageHeader"; -import { useGetReviewByAppId } from "@app/queries/reviews"; +import { useGetReviewByItemId } from "@app/queries/reviews"; +import useIsArchetype from "@app/hooks/useIsArchetype"; const ReviewPage: React.FC = () => { const { t } = useTranslation(); const { applicationId, archetypeId } = useParams(); + const isArchetype = useIsArchetype(); - const { application, review, fetchError, isFetching } = useGetReviewByAppId( - applicationId || "" + const { application, review, fetchError, isFetching } = useGetReviewByItemId( + applicationId || archetypeId, + isArchetype ); //TODO: Review archetypes? @@ -38,6 +41,25 @@ const ReviewPage: React.FC = () => { //TODO: Add a dropdown with multiple assessments to choose from const assessment = undefined; + const breadcrumbs = [ + ...(isArchetype + ? [ + { + title: t("terms.archetypes"), + path: Paths.archetypes, + }, + ] + : [ + { + title: t("terms.applications"), + path: Paths.applications, + }, + ]), + { + title: t("terms.review"), + path: Paths.applicationsReview, + }, + ]; if (fetchError) { return ( @@ -48,16 +70,7 @@ 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={[]} /> diff --git a/client/src/app/queries/reviews.ts b/client/src/app/queries/reviews.ts index b49541ddf8..66730f1fb2 100644 --- a/client/src/app/queries/reviews.ts +++ b/client/src/app/queries/reviews.ts @@ -10,6 +10,7 @@ import { 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"; @@ -40,6 +41,7 @@ export const useCreateReviewMutation = ( queryClient.invalidateQueries([ reviewsByItemIdQueryKey, res?.application?.id, + res?.archetype?.id, ]); onSuccess && onSuccess(res?.application?.name || ""); }, @@ -61,6 +63,7 @@ export const useUpdateReviewMutation = ( queryClient.invalidateQueries([ reviewsByItemIdQueryKey, _?.application?.id, + _.archetype?.id, ]); onSuccess && onSuccess(args?.application?.name || ""); }, @@ -89,28 +92,42 @@ export const useDeleteReviewMutation = ( }); }; -export function useGetReviewByAppId(applicationId: string | number) { +export function useGetReviewByItemId( + id?: string | number, + isArchetype?: boolean +) { const { application, isFetching: isApplicationFetching, fetchError: applicationError, - } = useFetchApplicationById(applicationId); + } = useFetchApplicationById(id); + + const { + archetype, + isFetching: isArchetypeFetching, + fetchError: archetypeError, + } = useFetchArchetypeById(id); let review = null; let isLoading = false; let isError = false; - const appReviewId = application?.review?.id; + const reviewId = application?.review?.id || archetype?.review?.id; const reviewQuery = useQuery( - ["review", application?.review?.id], - () => (appReviewId ? getReviewById(appReviewId) : null), + [ + reviewsByItemIdQueryKey, + reviewId, + application?.review?.id, + archetype?.review?.id, + ], + () => (reviewId ? getReviewById(reviewId) : null), { - enabled: !!appReviewId, + enabled: !!reviewId, } ); - if (appReviewId) { + if (reviewId) { review = reviewQuery.data; isLoading = reviewQuery.isLoading; isError = reviewQuery.isError; @@ -118,10 +135,12 @@ export function useGetReviewByAppId(applicationId: string | number) { return { application, + archetype, review, isLoading, isError, - isFetching: isApplicationFetching || isLoading, - fetchError: applicationError || (review ? reviewQuery.error : null), + isFetching: isApplicationFetching || isLoading || isArchetypeFetching, + fetchError: + applicationError || (review ? reviewQuery.error : null) || archetypeError, }; } From 0dd192ebab7d9f469943b14bcda7a27026d0c26b Mon Sep 17 00:00:00 2001 From: ibolton336 Date: Wed, 20 Sep 2023 16:01:36 -0400 Subject: [PATCH 2/2] PR comments addressed Signed-off-by: ibolton336 --- .../application-detail-drawer-assessment.tsx | 4 +- .../app/pages/archetypes/archetypes-page.tsx | 19 ++--- .../adoption-candidate-graph.tsx | 4 +- .../adoption-candidate-table.tsx | 4 +- .../application-details.tsx | 4 +- .../components/review-form/review-form.tsx | 16 +---- client/src/app/pages/review/review-page.tsx | 71 +++++++++---------- client/src/app/queries/reviews.ts | 63 ++++------------ 8 files changed, 61 insertions(+), 124 deletions(-) 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/archetypes/archetypes-page.tsx b/client/src/app/pages/archetypes/archetypes-page.tsx index f92ce72854..60fad8847d 100644 --- a/client/src/app/pages/archetypes/archetypes-page.tsx +++ b/client/src/app/pages/archetypes/archetypes-page.tsx @@ -69,7 +69,6 @@ const Archetypes: React.FC = () => { const [archetypeToEdit, setArchetypeToEdit] = useState( null ); - const [reviewToEdit, setReviewToEdit] = React.useState(null); const [archetypeToDuplicate, setArchetypeToDuplicate] = useState(null); @@ -186,18 +185,6 @@ const Archetypes: React.FC = () => { setArchetypeToAssess(null); } }; - const reviewSelectedArchetype = (archetype: Archetype) => { - if (archetype.review) { - setReviewToEdit(archetype.id); - } else { - history.push( - formatPath(Paths.archetypeReview, { - archetypeId: archetype.id, - }) - ); - } - }; - return ( <> @@ -312,7 +299,11 @@ const Archetypes: React.FC = () => { { title: t("actions.review"), onClick: () => - reviewSelectedArchetype(archetype), + history.push( + formatPath(Paths.archetypeReview, { + archetypeId: archetype.id, + }) + ), }, { title: t("actions.edit"), 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 b9e048f957..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 @@ -28,11 +28,9 @@ import { } from "@app/components/HookFormPFFields"; import { OptionWithValue, SimpleSelect } from "@app/components/SimpleSelect"; import { - reviewsByItemIdQueryKey, useCreateReviewMutation, useUpdateReviewMutation, } from "@app/queries/reviews"; -import { useQueryClient } from "@tanstack/react-query"; import { useHistory } from "react-router-dom"; import { Paths } from "@app/Paths"; import { NotificationsContext } from "@app/components/NotificationsContext"; @@ -57,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); @@ -112,17 +111,8 @@ export const ReviewForm: React.FC = ({ console.log("Invalid form", errors); }; - const queryClient = useQueryClient(); - const onHandleUpdateReviewSuccess = () => { - queryClient.invalidateQueries([ - reviewsByItemIdQueryKey, - application?.review?.id, - ]); - }; const createReviewMutation = useCreateReviewMutation(); - const updateReviewMutation = useUpdateReviewMutation( - onHandleUpdateReviewSuccess - ); + const updateReviewMutation = useUpdateReviewMutation(); const onSubmit = async (formValues: FormValues) => { const payload: New = { @@ -251,7 +241,7 @@ export const ReviewForm: React.FC = ({ label={t("composed.workPriority")} fieldId="priority" isRequired - renderInput={({ field: { value, name, onChange } }) => ( + renderInput={({ field: { value, onChange } }) => ( { const { t } = useTranslation(); @@ -31,15 +33,15 @@ const ReviewPage: React.FC = () => { const { applicationId, archetypeId } = useParams(); const isArchetype = useIsArchetype(); - const { application, review, fetchError, isFetching } = useGetReviewByItemId( - applicationId || archetypeId, - isArchetype - ); - - //TODO: Review archetypes? - // const { archetype } = useFetchArchetypeById(archetypeId || ""); + const { archetype } = useFetchArchetypeById(archetypeId); + const { application } = useFetchApplicationById(applicationId); - //TODO: Add a dropdown with multiple assessments to choose from + 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 @@ -55,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) { @@ -94,37 +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 66730f1fb2..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,55 +90,18 @@ export const useDeleteReviewMutation = ( }); }; -export function useGetReviewByItemId( - id?: string | number, - isArchetype?: boolean -) { - 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, }; -} +};