Added toast and add logout
This commit is contained in:
@@ -11,6 +11,8 @@ import VotingPage from "./pages/VotingPage";
|
||||
import CreatePollForm from "./pages/CreatePollForm";
|
||||
import { QueryClient, QueryClientProvider } from "react-query";
|
||||
import PrivateRoute from "./components/PrivateRoute/PrivateRoute";
|
||||
import { ToastContainer } from "react-toastify";
|
||||
import "react-toastify/dist/ReactToastify.css";
|
||||
|
||||
function App() {
|
||||
const queryClient = new QueryClient();
|
||||
@@ -30,6 +32,19 @@ function App() {
|
||||
<Route path="/create" element={<CreatePollForm />} />
|
||||
</Route>
|
||||
</Routes>
|
||||
<ToastContainer
|
||||
position="bottom-right"
|
||||
autoClose={5000}
|
||||
hideProgressBar={false}
|
||||
newestOnTop={false}
|
||||
closeOnClick
|
||||
rtl={false}
|
||||
pauseOnFocusLoss
|
||||
draggable
|
||||
pauseOnHover
|
||||
theme="dark"
|
||||
transition:Bounce
|
||||
/>
|
||||
</BrowserRouter>
|
||||
</QueryClientProvider>
|
||||
);
|
||||
|
||||
@@ -1,13 +1,27 @@
|
||||
import React from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import useUserStore from '../../store/useStore';
|
||||
import { useMutation } from 'react-query';
|
||||
import logoutService from '../../services/logoutService';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
function ProfileImage({userData}) {
|
||||
|
||||
const {setUser} = useUserStore();
|
||||
|
||||
const mutation = useMutation(logoutService, {
|
||||
onSuccess: (data) => {
|
||||
setUser({});
|
||||
toast.success(data?.message);
|
||||
},
|
||||
onError: (error) => {
|
||||
toast.error("Something went wrong");
|
||||
console.log(error);
|
||||
},
|
||||
});
|
||||
|
||||
const handleLogout = () => {
|
||||
setUser({});
|
||||
mutation.mutate();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import { loginService } from '../services/loginService';
|
||||
import SpinnerLoader from '../components/Loaders/SpinnerLoader';
|
||||
import InlineTextError from '../components/Errors/InlineTextError';
|
||||
import useUserStore from '../store/useStore';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
const LoginPage = () => {
|
||||
|
||||
@@ -18,6 +19,7 @@ const LoginPage = () => {
|
||||
const mutation = useMutation(loginService, {
|
||||
onSuccess: (data) => {
|
||||
setUser(data?.user);
|
||||
toast.success(data?.message);
|
||||
setEmail('');
|
||||
setPassword('');
|
||||
navigator('/');
|
||||
|
||||
8
frontend/src/services/logoutService.js
Normal file
8
frontend/src/services/logoutService.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import axiosInstance from "../helper/axiosInstance";
|
||||
|
||||
async function logoutService() {
|
||||
const response = await axiosInstance.get("/user/logout");
|
||||
return response.data;
|
||||
}
|
||||
|
||||
export default logoutService
|
||||
Reference in New Issue
Block a user