From f9ebeba157b9b1f0409b4215dc9296ef6ceccabd Mon Sep 17 00:00:00 2001 From: Andy Espagnolo Date: Fri, 16 Feb 2024 12:28:44 -0300 Subject: [PATCH] fix: redirect user to grant submit page on invalid category url (#1658) --- src/pages/submit/grant.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/pages/submit/grant.tsx b/src/pages/submit/grant.tsx index 991d5a2f9..e9d5782f3 100644 --- a/src/pages/submit/grant.tsx +++ b/src/pages/submit/grant.tsx @@ -30,7 +30,12 @@ import Head from '../../components/Layout/Head' import LoadingView from '../../components/Layout/LoadingView' import LogIn from '../../components/Layout/LogIn' import CategorySelector from '../../components/Projects/CategorySelector' -import { GrantRequest, GrantRequestCategoryAssessment, NewGrantCategory } from '../../entities/Grant/types' +import { + GrantRequest, + GrantRequestCategoryAssessment, + NewGrantCategory, + VALID_CATEGORIES, +} from '../../entities/Grant/types' import { SUBMISSION_THRESHOLD_GRANT } from '../../entities/Proposal/constants' import { ProposalType } from '../../entities/Proposal/types' import { asNumber, isGrantProposalSubmitEnabled, userModifiedForm } from '../../entities/Proposal/utils' @@ -118,7 +123,11 @@ export default function SubmitGrant() { } catch (error) { console.error(error) } finally { - patchGrantRequest((prevState) => ({ ...prevState, category })) + if (category && VALID_CATEGORIES.includes(category)) { + patchGrantRequest((prevState) => ({ ...prevState, category })) + } else { + navigate('/submit/grant') + } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [])