diff --git a/src/components/LogoutButton/LogoutButton.tsx b/src/components/LogoutButton/LogoutButton.tsx new file mode 100644 index 0000000..4ccb9bd --- /dev/null +++ b/src/components/LogoutButton/LogoutButton.tsx @@ -0,0 +1,31 @@ +import React, { FC, memo, useCallback } from "react" +import { useDispatch, useSelector } from "react-redux" +import { unsetJWT } from "../../services/auth" +import { isUserConnected, logoutUser } 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] + ) + + if (!connected) return null + + return ( +
+ +
+ ) +} + +export default memo(LogoutButton) diff --git a/src/components/LogoutButton/styles.module.scss b/src/components/LogoutButton/styles.module.scss new file mode 100644 index 0000000..c86678a --- /dev/null +++ b/src/components/LogoutButton/styles.module.scss @@ -0,0 +1,8 @@ +.logoutButton { + text-align: center; + + button { + font-weight: normal; + font-size: 0.9em; + } +} diff --git a/src/components/Notifications/index.tsx b/src/components/Notifications/index.tsx index 53f2f00..417b0ee 100644 --- a/src/components/Notifications/index.tsx +++ b/src/components/Notifications/index.tsx @@ -4,9 +4,9 @@ import isNode from "detect-node" import { useDispatch, useSelector } from "react-redux" import { fetchVolunteerNotifsSet } from "../../store/volunteerNotifsSet" import styles from "./styles.module.scss" -import { logoutUser, selectUserJwtToken } from "../../store/auth" -import { unsetJWT } from "../../services/auth" +import { selectUserJwtToken } from "../../store/auth" import { VolunteerNotifs } from "../../services/volunteers" +import LogoutButton from "../LogoutButton/LogoutButton" interface Props { // eslint-disable-next-line react/require-default-props @@ -360,28 +360,16 @@ Tu n'y es absolument pas obligé(e) ! C'est juste plus pratique. ) } - const onClick = useCallback( - (event: React.SyntheticEvent): void => { - event.preventDefault() - unsetJWT() - dispatch(logoutUser()) - }, - [dispatch] - ) - - notifs.push( -
- -
- ) - if (volunteerNotifs === undefined) { return null } - return
{notifs.map((t) => t).reduce((prev, curr) => [prev, curr])}
+ return ( +
+ {notifs.map((t) => t).reduce((prev, curr) => [prev, curr])} + +
+ ) } export default memo(Notifications)