mirror of
https://github.com/Paris-est-Ludique/intranet.git
synced 2025-06-08 08:34:20 +02:00
Fix login not updating redux store by reloading whole page
This commit is contained in:
parent
4b2a68174b
commit
140891c4c0
@ -1,21 +1,18 @@
|
||||
import React, { FC, memo, useCallback } from "react"
|
||||
import { useDispatch, useSelector } from "react-redux"
|
||||
import { useSelector } from "react-redux"
|
||||
import { unsetJWT } from "../../services/auth"
|
||||
import { isUserConnected, logoutUser } from "../../store/auth"
|
||||
import { isUserConnected } from "../../store/auth"
|
||||
import styles from "./styles.module.scss"
|
||||
|
||||
const LogoutButton: FC = (): JSX.Element | null => {
|
||||
const dispatch = useDispatch()
|
||||
const connected = useSelector(isUserConnected)
|
||||
|
||||
const onClick = useCallback(
|
||||
(event: React.SyntheticEvent): void => {
|
||||
event.preventDefault()
|
||||
unsetJWT()
|
||||
dispatch(logoutUser())
|
||||
},
|
||||
[dispatch]
|
||||
)
|
||||
const onClick = useCallback((event: React.SyntheticEvent): void => {
|
||||
event.preventDefault()
|
||||
unsetJWT()
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
location?.reload()
|
||||
}, [])
|
||||
|
||||
if (!connected) return null
|
||||
|
||||
|
@ -7,7 +7,7 @@ import styles from "./styles.module.scss"
|
||||
import { selectUserJwtToken } from "../../store/auth"
|
||||
import { VolunteerNotifs } from "../../services/volunteers"
|
||||
import LogoutButton from "../LogoutButton/LogoutButton"
|
||||
import { TeamWishesForm } from ".."
|
||||
// import { TeamWishesForm } from ".."
|
||||
import { fetchFor as fetchForTeamWishesForm } from "../VolunteerBoard/TeamWishesForm/TeamWishesForm"
|
||||
|
||||
interface Props {
|
||||
@ -144,25 +144,25 @@ const Notifications = ({ volunteerNotifs }: Props): JSX.Element | null => {
|
||||
)
|
||||
}
|
||||
|
||||
const onSubmit3 = useCallback((): void => {
|
||||
dispatch(
|
||||
fetchVolunteerNotifsSet(jwtToken, 0, {
|
||||
hiddenNotifs: [...(volunteerNotifs?.hiddenNotifs || []), 3],
|
||||
})
|
||||
)
|
||||
}, [dispatch, jwtToken, volunteerNotifs])
|
||||
// const onSubmit3 = useCallback((): void => {
|
||||
// dispatch(
|
||||
// fetchVolunteerNotifsSet(jwtToken, 0, {
|
||||
// hiddenNotifs: [...(volunteerNotifs?.hiddenNotifs || []), 3],
|
||||
// })
|
||||
// )
|
||||
// }, [dispatch, jwtToken, volunteerNotifs])
|
||||
|
||||
if (!_.includes(hidden, 3)) {
|
||||
notifs.push(
|
||||
<div key="1">
|
||||
<div className={styles.notificationsPage}>
|
||||
<div className={styles.notificationsContent}>
|
||||
<TeamWishesForm afterSubmit={onSubmit3} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
// if (!_.includes(hidden, 3)) {
|
||||
// notifs.push(
|
||||
// <div key="1">
|
||||
// <div className={styles.notificationsPage}>
|
||||
// <div className={styles.notificationsContent}>
|
||||
// <TeamWishesForm afterSubmit={onSubmit3} />
|
||||
// </div>
|
||||
// </div>
|
||||
// </div>
|
||||
// )
|
||||
// }
|
||||
|
||||
/* DISCORD
|
||||
Discord nous donne à tous la parole via nos téléphone ou navigateurs, pour organiser le meilleur des festivals !
|
||||
|
@ -48,13 +48,13 @@ const AnnouncementsPage: FC<Props> = (): JSX.Element => {
|
||||
}
|
||||
return (
|
||||
<div>
|
||||
<div className={styles.announcement}>
|
||||
<div className={styles.announcements}>
|
||||
<div className={styles.loginContent}>
|
||||
<Helmet title="LoginPage" />
|
||||
<LoginForm />
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.announcement}>
|
||||
<div className={styles.announcements}>
|
||||
<div className={styles.navigationLink}>
|
||||
<Link to="/sinscrire"> S'informer sur le bénévolat </Link>
|
||||
</div>
|
||||
|
@ -22,6 +22,7 @@ export const auth = createSlice({
|
||||
state.jwt = action.payload.jwt
|
||||
},
|
||||
logoutUser: (state) => {
|
||||
// Unused, just reload page :/
|
||||
state.id = 0
|
||||
state.jwt = ""
|
||||
},
|
||||
|
@ -3,9 +3,6 @@ import { PayloadAction, createSlice } from "@reduxjs/toolkit"
|
||||
import { StateRequest, elementFetch } from "./utils"
|
||||
import { VolunteerLogin } from "../services/volunteers"
|
||||
import { setJWT } from "../services/auth"
|
||||
import { AppDispatch } from "."
|
||||
import { setCurrentUser } from "./auth"
|
||||
import { fetchVolunteerNotifsSet } from "./volunteerNotifsSet"
|
||||
import { volunteerLogin } from "../services/volunteersAccessors"
|
||||
|
||||
type StateVolunteer = { entity?: VolunteerLogin } & StateRequest
|
||||
@ -41,9 +38,9 @@ export const fetchVolunteerLogin = elementFetch<VolunteerLogin, Parameters<typeo
|
||||
getSuccess,
|
||||
getFailure,
|
||||
undefined,
|
||||
(login: VolunteerLogin, dispatch: AppDispatch) => {
|
||||
(login: VolunteerLogin) => {
|
||||
setJWT(login.jwt, login.id)
|
||||
dispatch(setCurrentUser(login))
|
||||
dispatch(fetchVolunteerNotifsSet(login.jwt, login.id, {}))
|
||||
// eslint-disable-next-line no-restricted-globals
|
||||
location?.reload()
|
||||
}
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user