diff --git a/src/pages/Feature/index.tsx b/src/pages/Feature/index.tsx index 41a3cc6..0c51b46 100644 --- a/src/pages/Feature/index.tsx +++ b/src/pages/Feature/index.tsx @@ -1,27 +1,108 @@ -import { useReactiveVar } from '@apollo/client'; +import { useEffect, useState } from 'react'; +import { useHistory, useParams } from 'react-router-dom'; +import { useLazyQuery, useReactiveVar } from '@apollo/client'; import { Redirect } from 'react-router'; import { roleVar } from '../../graphql/state'; -import { Empty } from '../../assets'; -import { Box } from '../../components'; +import { Empty, Settings } from '../../assets'; +import { Box, Text, Button, Spinner } from '../../components'; import { Wrapper } from './styles'; +import { + FeatureOutput, + GetAllFeaturesQuery, + GetAllFeaturesQueryVariables, + GetFeatureByIdQuery, + GetFeatureByIdQueryVariables, +} from '../../graphql/types'; +import { GET_ALL_FEATURES, GET_FEATURE_BY_ID } from '../../graphql/feature.api'; const Feature = () => { const role = useReactiveVar(roleVar); + const history = useHistory(); + const { id } = useParams<{ id: string }>(); + const [feature, setFeature] = useState(); + + const [getFeatures, { loading: featuresLoading }] = useLazyQuery< + GetAllFeaturesQuery, + GetAllFeaturesQueryVariables + >(GET_ALL_FEATURES, { + onCompleted({ getAllFeatures }) { + setFeature(getAllFeatures[0]); + }, + fetchPolicy: 'network-only', + }); + + const [getFeature, { loading: featureLoading }] = useLazyQuery< + GetFeatureByIdQuery, + GetFeatureByIdQueryVariables + >(GET_FEATURE_BY_ID, { + onCompleted({ getFeatureById }) { + setFeature(getFeatureById); + }, + fetchPolicy: 'network-only', + }); + + useEffect(() => { + if (id) { + getFeature({ variables: { id } }); + } else { + getFeatures(); + } + + // eslint-disable-next-line + }, [id]); return role === 'developer' ? ( - - - - - - - + <> + {!featuresLoading && !featureLoading ? ( + <> + {feature ? ( + + + + + + {feature.name} + + +