move toast in App and fix error in login
This commit is contained in:
parent
51fc7dff85
commit
2896fbdc56
|
|
@ -4,6 +4,7 @@ import Login from './routes/login';
|
||||||
import Home from './routes/home';
|
import Home from './routes/home';
|
||||||
import { CookiesProvider, useCookies } from 'react-cookie';
|
import { CookiesProvider, useCookies } from 'react-cookie';
|
||||||
import Signup from './routes/signup';
|
import Signup from './routes/signup';
|
||||||
|
import { ToastContainer } from 'react-toastify';
|
||||||
|
|
||||||
// Create a client
|
// Create a client
|
||||||
const queryClient = new QueryClient();
|
const queryClient = new QueryClient();
|
||||||
|
|
@ -38,6 +39,7 @@ export default () => {
|
||||||
<Route path="/signup" element={<Auth route="signup"/>} />
|
<Route path="/signup" element={<Auth route="signup"/>} />
|
||||||
<Route path="/home" element={<Auth route="home"/>} />
|
<Route path="/home" element={<Auth route="home"/>} />
|
||||||
</Routes>
|
</Routes>
|
||||||
|
<ToastContainer />
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</CookiesProvider>
|
</CookiesProvider>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import AppHeader from '@components/AppHeader';
|
import AppHeader from '@components/AppHeader';
|
||||||
import MessageWrapper from '@components/MessageWrapper';
|
import MessageWrapper from '@components/MessageWrapper';
|
||||||
import NewMessage from '@components/NewMessage';
|
import NewMessage from '@components/NewMessage';
|
||||||
import { ToastContainer } from 'react-toastify';
|
|
||||||
import 'react-toastify/dist/ReactToastify.css';
|
import 'react-toastify/dist/ReactToastify.css';
|
||||||
|
|
||||||
const Home = () => {
|
const Home = () => {
|
||||||
|
|
@ -10,7 +9,6 @@ const Home = () => {
|
||||||
<AppHeader />
|
<AppHeader />
|
||||||
<MessageWrapper />
|
<MessageWrapper />
|
||||||
<NewMessage />
|
<NewMessage />
|
||||||
<ToastContainer />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { useQuery } from '@tanstack/react-query';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useCookies } from 'react-cookie';
|
import { useCookies } from 'react-cookie';
|
||||||
import type { Token } from '../types';
|
import type { Token } from '../types';
|
||||||
|
import { toastError } from '@controllers/Toasts';
|
||||||
|
|
||||||
const Login = () => {
|
const Login = () => {
|
||||||
const [email, setEmail] = useState('');
|
const [email, setEmail] = useState('');
|
||||||
|
|
@ -21,6 +22,10 @@ const Login = () => {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const data = await response.json();
|
||||||
|
if (data.error) {
|
||||||
|
throw data.error;
|
||||||
|
}
|
||||||
return response.json();
|
return response.json();
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -28,7 +33,7 @@ const Login = () => {
|
||||||
setCookie('token', data.token, { path: '/', expires: new Date(data.expiresAt) });
|
setCookie('token', data.token, { path: '/', expires: new Date(data.expiresAt) });
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
console.error(error);
|
toastError(error as string);
|
||||||
},
|
},
|
||||||
enabled: false,
|
enabled: false,
|
||||||
refetchOnWindowFocus: false,
|
refetchOnWindowFocus: false,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue