From a45e44678f2ca2103df7c798c68a4c258f23730b Mon Sep 17 00:00:00 2001 From: Hazem Krimi Date: Sun, 30 May 2021 02:33:47 +0100 Subject: [PATCH] Update template page --- src/pages/Template/index.tsx | 146 +++++++++++++++++++++++++++++++---- 1 file changed, 130 insertions(+), 16 deletions(-) diff --git a/src/pages/Template/index.tsx b/src/pages/Template/index.tsx index 5641f71..960a749 100644 --- a/src/pages/Template/index.tsx +++ b/src/pages/Template/index.tsx @@ -1,27 +1,141 @@ -import { useReactiveVar } from '@apollo/client'; +import { useEffect, useState } from 'react'; +import { useLazyQuery, useReactiveVar } from '@apollo/client'; import { Redirect } from 'react-router'; +import { useHistory, useParams } from 'react-router-dom'; import { roleVar } from '../../graphql/state'; -import { Empty } from '../../assets'; -import { Box } from '../../components'; +import { Empty, Settings } from '../../assets'; +import { Box, Button, FeatureCard, Text, Spinner } from '../../components'; import { Wrapper } from './styles'; +import { + GetAllTemplatesQuery, + GetAllTemplatesQueryVariables, + GetTemplateByIdQuery, + GetTemplateByIdQueryVariables, + TemplateOutput, +} from '../../graphql/types'; +import { + GET_ALL_TEMPLATES, + GET_TEMPLATE_BY_ID, +} from '../../graphql/template.api'; const Template = () => { const role = useReactiveVar(roleVar); + const history = useHistory(); + const { id } = useParams<{ id: string }>(); + const [template, setTemplate] = useState(); + + const [getTemplates, { loading: templatesLoading }] = useLazyQuery< + GetAllTemplatesQuery, + GetAllTemplatesQueryVariables + >(GET_ALL_TEMPLATES, { + onCompleted({ getAllTemplates }) { + setTemplate(getAllTemplates[0]); + }, + fetchPolicy: 'network-only', + }); + + const [getTemplate, { loading: templateLoading }] = useLazyQuery< + GetTemplateByIdQuery, + GetTemplateByIdQueryVariables + >(GET_TEMPLATE_BY_ID, { + onCompleted({ getTemplateById }) { + setTemplate(getTemplateById); + }, + fetchPolicy: 'network-only', + }); + + useEffect(() => { + if (id) { + getTemplate({ variables: { id } }); + } else { + getTemplates(); + } + + // eslint-disable-next-line + }, [id]); return role === 'productOwner' || role === 'developer' ? ( - - - - - - - + <> + {!templatesLoading && !templateLoading ? ( + <> + {template ? ( + + + + + + {template.name} + + +