diff --git a/CHANGELOG.md b/CHANGELOG.md index 6853205ed..4acdcebcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ changes. ### Added +- Add redirection to outcomes when proposal is not found [Issue 3230](https://github.com/IntersectMBO/govtool/issues/3230) + ### Fixed - Fix post-vote navigation to governance action list [Issue 3242](https://github.com/IntersectMBO/govtool/issues/3242) diff --git a/govtool/frontend/src/components/organisms/DashboardGovernanceActionDetails.tsx b/govtool/frontend/src/components/organisms/DashboardGovernanceActionDetails.tsx index d7dd7be60..d5ffa61c2 100644 --- a/govtool/frontend/src/components/organisms/DashboardGovernanceActionDetails.tsx +++ b/govtool/frontend/src/components/organisms/DashboardGovernanceActionDetails.tsx @@ -1,3 +1,4 @@ +import { useEffect } from "react"; import { useNavigate, useLocation, @@ -5,8 +6,9 @@ import { generatePath, } from "react-router-dom"; import { Box, CircularProgress, Link, Typography } from "@mui/material"; +import { AxiosError } from "axios"; -import { ICONS, PATHS } from "@consts"; +import { ICONS, OUTCOMES_PATHS, PATHS } from "@consts"; import { useCardano } from "@context"; import { useGetProposalQuery, @@ -42,13 +44,24 @@ export const DashboardGovernanceActionDetails = () => { const shortenedGovActionId = txHash && getShortenedGovActionId(txHash, +index); - const { data, isLoading } = useGetProposalQuery( + const { data, isLoading, error } = useGetProposalQuery( fullProposalId ?? "", !state?.proposal || !state?.vote, ); const proposal = (data ?? state)?.proposal; const vote = (data ?? state)?.vote; + useEffect(() => { + const isProposalNotFound = + (error as AxiosError)?.response?.data === + `Proposal with id: ${fullProposalId} not found`; + if (isProposalNotFound && fullProposalId) { + navigate( + OUTCOMES_PATHS.governanceActionOutcomes.replace(":id", fullProposalId), + ); + } + }, [error]); + return ( { const { dRepID } = useCardano(); - const { data, isLoading, refetch, isRefetching } = useQuery( + const { data, isLoading, refetch, isRefetching, error } = useQuery( [QUERY_KEYS.useGetProposalKey, dRepID, proposalId], () => getProposal(proposalId, dRepID), { @@ -21,5 +21,6 @@ export const useGetProposalQuery = (proposalId: string, enabled?: boolean) => { isLoading, refetch, isFetching: isRefetching, + error, }; };