From 613af2e1e975ff673881e36f827819b58abf2018 Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Mon, 21 Jun 2021 23:17:37 +0100 Subject: [PATCH] Fix template and prototype bugs --- src/pages/Project/index.tsx | 9 +++++++++ src/pages/Template/index.tsx | 16 ++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/pages/Project/index.tsx b/src/pages/Project/index.tsx index 07a4f1b..ae319f7 100644 --- a/src/pages/Project/index.tsx +++ b/src/pages/Project/index.tsx @@ -211,6 +211,10 @@ const Project = () => { }); } else getProjects(); + return () => { + setProject(undefined); + }; + // eslint-disable-next-line }, [id, role]); @@ -236,6 +240,11 @@ const Project = () => { } })(); + return () => { + setPrototype(undefined); + setTransactionsData(undefined); + }; + // eslint-disable-next-line }, [project]); diff --git a/src/pages/Template/index.tsx b/src/pages/Template/index.tsx index 5b5a7a4..3a8c5d5 100644 --- a/src/pages/Template/index.tsx +++ b/src/pages/Template/index.tsx @@ -60,8 +60,8 @@ const Template = () => { GetAllTemplatesQueryVariables >(GET_ALL_TEMPLATES, { onCompleted({ getAllTemplates }) { - setTemplate(getAllTemplates[0]); - getCategory({ variables: { id: template?.category! } }); + if (getAllTemplates.length > 0) + history.push(`/template/${getAllTemplates[0].id}`); }, fetchPolicy: 'network-only', }); @@ -82,8 +82,9 @@ const Template = () => { GetPrototypeByIdQueryVariables >(GET_PROTOTYPE_BY_ID, { onCompleted({ getPrototypeById }) { - setPrototype(getPrototypeById.prototype); + if (getPrototypeById) setPrototype(getPrototypeById.prototype); }, + fetchPolicy: 'network-only', }); const handlePrint = useReactToPrint({ @@ -98,6 +99,11 @@ const Template = () => { getTemplates(); } + return () => { + setTemplate(undefined); + setPrototype(undefined); + }; + // eslint-disable-next-line }, [id]); @@ -140,7 +146,9 @@ const Template = () => { variant='primary-action' text='Prototype' iconLeft={} - disabled={!prototype && role === 'productOwner'} + disabled={ + prototype === undefined && role === 'productOwner' + } onClick={() => history.push(`/prototype/${id || template.id}`) }