move toast in App and fix error in login

This commit is contained in:
Guillaume Dorce 2022-09-30 19:10:37 +02:00
parent 51fc7dff85
commit 2896fbdc56
3 changed files with 8 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import Login from './routes/login';
import Home from './routes/home';
import { CookiesProvider, useCookies } from 'react-cookie';
import Signup from './routes/signup';
import { ToastContainer } from 'react-toastify';
// Create a client
const queryClient = new QueryClient();
@ -38,6 +39,7 @@ export default () => {
<Route path="/signup" element={<Auth route="signup"/>} />
<Route path="/home" element={<Auth route="home"/>} />
</Routes>
<ToastContainer />
<Outlet />
</CookiesProvider>
</QueryClientProvider>

View File

@ -1,7 +1,6 @@
import AppHeader from '@components/AppHeader';
import MessageWrapper from '@components/MessageWrapper';
import NewMessage from '@components/NewMessage';
import { ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
const Home = () => {
@ -10,7 +9,6 @@ const Home = () => {
<AppHeader />
<MessageWrapper />
<NewMessage />
<ToastContainer />
</div>
);
};

View File

@ -4,6 +4,7 @@ import { useQuery } from '@tanstack/react-query';
import { useState } from 'react';
import { useCookies } from 'react-cookie';
import type { Token } from '../types';
import { toastError } from '@controllers/Toasts';
const Login = () => {
const [email, setEmail] = useState('');
@ -21,6 +22,10 @@ const Login = () => {
'Content-Type': 'application/json',
},
});
const data = await response.json();
if (data.error) {
throw data.error;
}
return response.json();
},
{
@ -28,7 +33,7 @@ const Login = () => {
setCookie('token', data.token, { path: '/', expires: new Date(data.expiresAt) });
},
onError: (error) => {
console.error(error);
toastError(error as string);
},
enabled: false,
refetchOnWindowFocus: false,