Routes privées avec page d'accueil publique

This commit is contained in:
2020-08-13 10:16:00 +02:00
parent 680614148c
commit 5790c91d82
11 changed files with 147 additions and 34 deletions

View File

@ -1,33 +1,20 @@
import React from 'react';
import React, { useEffect } from 'react';
import { Page } from '../Page';
import { Dashboard } from './Dashboard';
import { useUserProfileQuery } from '../../gql/queries/profile';
import { WithLoader } from '../WithLoader';
import { WelcomeContent } from './WelcomeContent';
import { useUserProfile } from '../../gql/queries/profile';
import { useHistory } from 'react-router';
export function HomePage() {
const { data, loading } = useUserProfileQuery();
const { user } = useUserProfile();
const history = useHistory();
const { userProfile } = (data || {});
useEffect(() => {
if (user.id !== '') history.push('/dashboard');
}, [user.id])
return (
<Page title={userProfile ? 'Tableau de bord' : 'Accueil'}>
<div className="container is-fluid">
<section className="mt-5">
<WithLoader loading={loading}>
{
userProfile ?
<Dashboard /> :
<div className="columns">
<div className="column is-4 is-offset-4">
<div className="box">
<p>Veuillez vous authentifier.</p>
</div>
</div>
</div>
}
</WithLoader>
</section>
</div>
<Page title="Accueil">
<WelcomeContent />
</Page>
);
}