From ef4d1e40ba258b9ea1321a70210068eb74dc7fa7 Mon Sep 17 00:00:00 2001 From: pikiou Date: Mon, 22 May 2023 09:41:18 +0200 Subject: [PATCH] Add login form on pages where login is needed --- src/components/Asks/AskMeals.tsx | 6 +- .../Asks/AskParticipationDetails.tsx | 6 +- src/components/Asks/index.tsx | 2 +- src/components/LoginForm/index.tsx | 55 ++++++++++++++++--- src/components/LoginForm/styles.module.scss | 8 +++ src/components/RegisterForm/index.tsx | 29 ++++++---- src/pages/Admin/DbEdit/DbEdit.tsx | 4 +- .../GameDetailsUpdate/GameDetailsUpdate.tsx | 4 +- src/pages/Board/Board.tsx | 4 +- src/pages/Knowledge/KnowledgesPage.tsx | 4 +- .../KnowledgeCards/KnowledgeCardsPage.tsx | 4 +- src/pages/Loaning/LoaningPage.tsx | 4 +- src/pages/Loans/LoansPage.tsx | 4 +- .../TeamAssignment/TeamAssignmentPage.tsx | 4 +- src/pages/Volunteers/Volunteers.tsx | 3 +- src/store/volunteerLogin.ts | 12 ++++ 16 files changed, 115 insertions(+), 38 deletions(-) diff --git a/src/components/Asks/AskMeals.tsx b/src/components/Asks/AskMeals.tsx index f40b90d..b88a561 100644 --- a/src/components/Asks/AskMeals.tsx +++ b/src/components/Asks/AskMeals.tsx @@ -4,6 +4,7 @@ import { fetchVolunteerAsksSet } from "../../store/volunteerAsksSet" import { useAskTools, addAsk, answerLaterOnProfileBefore } from "./utils" import MealsForm, { fetchFor as fetchForMealsForm } from "../VolunteerBoard/MealsForm/MealsForm" import { useUserMeals } from "../VolunteerBoard/meals.utils" +import { useUserDayWishes } from "../VolunteerBoard/daysWishes.utils" export function AskMeals(asks: JSX.Element[], id: number): void { const { dispatch, jwtToken, volunteerAsks } = useAskTools() @@ -17,8 +18,11 @@ export function AskMeals(asks: JSX.Element[], id: number): void { }, [dispatch, id, jwtToken, volunteerAsks?.hiddenAsks]) const [userMeals] = useUserMeals() + const [userWishes] = useUserDayWishes() + const participation = get(userWishes, "active", "inconnu") as string const meals = get(userMeals, "meals", []) - const needToShow = meals.length === 0 + const needToShow = + (participation === "oui" || participation === "peut-etre") && meals.length === 0 addAsk( asks, diff --git a/src/components/Asks/AskParticipationDetails.tsx b/src/components/Asks/AskParticipationDetails.tsx index 8c21f81..7d5752c 100644 --- a/src/components/Asks/AskParticipationDetails.tsx +++ b/src/components/Asks/AskParticipationDetails.tsx @@ -6,6 +6,7 @@ import ParticipationDetailsForm, { fetchFor as fetchForParticipationDetailsForm, } from "../VolunteerBoard/ParticipationDetailsForm/ParticipationDetailsForm" import { useUserParticipationDetails } from "../VolunteerBoard/participationDetails.utils" +import { useUserDayWishes } from "../VolunteerBoard/daysWishes.utils" export function AskParticipationDetails(asks: JSX.Element[], id: number): void { const { dispatch, jwtToken, volunteerAsks } = useAskTools() @@ -19,9 +20,12 @@ export function AskParticipationDetails(asks: JSX.Element[], id: number): void { }, [dispatch, id, jwtToken, volunteerAsks?.hiddenAsks]) const [participationDetails] = useUserParticipationDetails() + const [userWishes] = useUserDayWishes() + const participation = get(userWishes, "active", "inconnu") as string const tshirtSize = get(participationDetails, "tshirtSize", "") const food = get(participationDetails, "food", "") - const needToShow = !tshirtSize || !food + const needToShow = + (participation === "oui" || participation === "peut-etre") && (!tshirtSize || !food) addAsk( asks, diff --git a/src/components/Asks/index.tsx b/src/components/Asks/index.tsx index d08ce1d..1e5a11c 100644 --- a/src/components/Asks/index.tsx +++ b/src/components/Asks/index.tsx @@ -46,7 +46,7 @@ const Asks = (): JSX.Element | null => { dans Mon profil :)
Tu as fait le tour des dernières infos ou questions importantes, - merci ! :) + merci !
Nous te préviendrons quand il y en aura de nouvelles.
diff --git a/src/components/LoginForm/index.tsx b/src/components/LoginForm/index.tsx index 36f8597..8c0e751 100644 --- a/src/components/LoginForm/index.tsx +++ b/src/components/LoginForm/index.tsx @@ -2,11 +2,16 @@ import { memo, useCallback, useRef } from "react" import { get } from "lodash" import { shallowEqual, useDispatch, useSelector } from "react-redux" import { AppState } from "../../store" -import { fetchVolunteerLogin } from "../../store/volunteerLogin" +import { fetchVolunteerLogin, fetchVolunteerLoginToRoot } from "../../store/volunteerLogin" import styles from "./styles.module.scss" import FormSubmit from "../Form/FormSubmit/FormSubmit" -const LoginForm = (): JSX.Element => { +interface Props { + redirectToRoot?: boolean + loginNeeded?: boolean +} + +const LoginForm = ({ redirectToRoot, loginNeeded }: Props): JSX.Element => { const dispatch = useDispatch() const loginError = useSelector((state: AppState) => state.volunteerLogin.error, shallowEqual) @@ -20,17 +25,19 @@ const LoginForm = (): JSX.Element => { const email = get(emailRef, "current.value", "") const password = get(passwordRef, "current.value", "") - dispatch(fetchVolunteerLogin({ email, password })) + dispatch( + (redirectToRoot ? fetchVolunteerLoginToRoot : fetchVolunteerLogin)({ + email, + password, + }) + ) return false }, - [dispatch] + [dispatch, redirectToRoot] ) - return ( + const loginForm = (
-
- Si tu es bénévole ou que tu l'as déjà été, connecte-toi pour accéder à ton espace. -
@@ -48,6 +55,38 @@ const LoginForm = (): JSX.Element => {
) + + return ( + <> + {loginNeeded && ( +
+
+
+ Tu dois t'identifier pour accéder à cette page ! +
+ {loginForm} +
+
+ )} + + {redirectToRoot && loginForm} + + {!loginNeeded && !redirectToRoot && ( + <> +
+ Si tu es bénévole ou que tu l'as déjà été, connecte-toi pour accéder à ton + espace. +
+ {loginForm} + + )} + + ) +} +// Set default props +LoginForm.defaultProps = { + redirectToRoot: undefined, + loginNeeded: undefined, } export default memo(LoginForm) diff --git a/src/components/LoginForm/styles.module.scss b/src/components/LoginForm/styles.module.scss index 6b8cd30..ea04de7 100755 --- a/src/components/LoginForm/styles.module.scss +++ b/src/components/LoginForm/styles.module.scss @@ -1,6 +1,14 @@ @import "../../theme/variables"; @import "../../theme/mixins"; +.loginPage { + @include page-wrapper-center; +} + +.loginContent { + @include page-content-wrapper; +} + .loginIntro { margin-bottom: 10px; } diff --git a/src/components/RegisterForm/index.tsx b/src/components/RegisterForm/index.tsx index 750dc5e..e5c005c 100644 --- a/src/components/RegisterForm/index.tsx +++ b/src/components/RegisterForm/index.tsx @@ -256,7 +256,7 @@ const RegisterForm = ({ dispatch }: Props): JSX.Element => { ) - const cameAsVisitor = ( + const alreadySignupForm = ( <>
@@ -294,11 +294,15 @@ const RegisterForm = ({ dispatch }: Props): JSX.Element => { Viens simplement t'identifier sur fo.parisestludique.fr{" "} ou en dessous ^^

- + )} + + ) + const cameAsVisitor = ( + <>
@@ -668,16 +672,21 @@ const RegisterForm = ({ dispatch }: Props): JSX.Element => { ) return ( -
+ <> {intro} {enableRegistering && commentQuestion} - {cameAsVisitor} - {meeting} - {pelMember} - {nameMobileEmail} - {!enableRegistering && commentQuestion} - {howToContact !== "Aucun" && submitButton} -
+ {alreadySignupForm} + {!alreadySignup && ( +
+ {cameAsVisitor} + {meeting} + {pelMember} + {nameMobileEmail} + {!enableRegistering && commentQuestion} + {howToContact !== "Aucun" && submitButton} +
+ )} + ) } diff --git a/src/pages/Admin/DbEdit/DbEdit.tsx b/src/pages/Admin/DbEdit/DbEdit.tsx index 62f47bd..9bf6c34 100644 --- a/src/pages/Admin/DbEdit/DbEdit.tsx +++ b/src/pages/Admin/DbEdit/DbEdit.tsx @@ -4,7 +4,7 @@ import { useSelector } from "react-redux" import { AppThunk } from "../../../store" import { selectUserJwtToken } from "../../../store/auth" -import { DbEdit, fetchForDbEdit } from "../../../components" +import { DbEdit, fetchForDbEdit, LoginForm } from "../../../components" export type Props = RouteComponentProps @@ -19,7 +19,7 @@ const DbEditPage: FC = (): JSX.Element => { ) } - return
Besoin d'être identifié
+ return } // Fetch server-side data here diff --git a/src/pages/Admin/GameDetailsUpdate/GameDetailsUpdate.tsx b/src/pages/Admin/GameDetailsUpdate/GameDetailsUpdate.tsx index df2f952..04ba12b 100644 --- a/src/pages/Admin/GameDetailsUpdate/GameDetailsUpdate.tsx +++ b/src/pages/Admin/GameDetailsUpdate/GameDetailsUpdate.tsx @@ -4,7 +4,7 @@ import { useSelector } from "react-redux" import { AppThunk } from "../../../store" import { selectUserJwtToken } from "../../../store/auth" -import { GameDetailsUpdate } from "../../../components" +import { GameDetailsUpdate, LoginForm } from "../../../components" import { fetchGameDetailsUpdateIfNeed } from "../../../store/gameDetailsUpdate" export type Props = RouteComponentProps @@ -20,7 +20,7 @@ const GameDetailsUpdatePage: FC = (): JSX.Element => { ) } - return
Besoin d'être identifié
+ return } // Fetch server-side data here diff --git a/src/pages/Board/Board.tsx b/src/pages/Board/Board.tsx index 1da11a2..4e638dd 100644 --- a/src/pages/Board/Board.tsx +++ b/src/pages/Board/Board.tsx @@ -5,7 +5,7 @@ import { useSelector } from "react-redux" import { AppThunk } from "../../store" import { selectUserJwtToken } from "../../store/auth" import Page from "../../components/ui/Page/Page" -import { Board, fetchForBoard } from "../../components" +import { Board, fetchForBoard, LoginForm } from "../../components" export type Props = RouteComponentProps @@ -20,7 +20,7 @@ const BoardPage: FC = (): JSX.Element => { ) } - return
Besoin d'être identifié
+ return } // Fetch server-side data here diff --git a/src/pages/Knowledge/KnowledgesPage.tsx b/src/pages/Knowledge/KnowledgesPage.tsx index 0c55f2b..0504526 100644 --- a/src/pages/Knowledge/KnowledgesPage.tsx +++ b/src/pages/Knowledge/KnowledgesPage.tsx @@ -5,7 +5,7 @@ import { Helmet } from "react-helmet" import { AppThunk } from "../../store" import styles from "./styles.module.scss" -import { KnowledgeBoxList, KnowledgeIntro, fetchForKnowledge } from "../../components" +import { KnowledgeBoxList, KnowledgeIntro, LoginForm, fetchForKnowledge } from "../../components" import { selectUserJwtToken } from "../../store/auth" export type Props = RouteComponentProps @@ -14,7 +14,7 @@ const KnowledgesPage: FC = (): JSX.Element => { const jwtToken = useSelector(selectUserJwtToken) if (jwtToken === undefined) return

Loading...

if (!jwtToken) { - return
Besoin d'être identifié
+ return } return (
diff --git a/src/pages/KnowledgeCards/KnowledgeCardsPage.tsx b/src/pages/KnowledgeCards/KnowledgeCardsPage.tsx index 1dc4507..bd0c902 100644 --- a/src/pages/KnowledgeCards/KnowledgeCardsPage.tsx +++ b/src/pages/KnowledgeCards/KnowledgeCardsPage.tsx @@ -3,7 +3,7 @@ import { useSelector } from "react-redux" import { RouteComponentProps } from "react-router-dom" import { AppThunk } from "../../store" -import { KnowledgeCard, fetchForKnowledgeCard } from "../../components" +import { KnowledgeCard, fetchForKnowledgeCard, LoginForm } from "../../components" import { selectUserJwtToken } from "../../store/auth" export type Props = RouteComponentProps @@ -12,7 +12,7 @@ const KnowledgeCardsPage: FC = (): JSX.Element => { const jwtToken = useSelector(selectUserJwtToken) if (jwtToken === undefined) return

Loading...

if (!jwtToken) { - return
Besoin d'être identifié
+ return } return } diff --git a/src/pages/Loaning/LoaningPage.tsx b/src/pages/Loaning/LoaningPage.tsx index b911258..c1bce6a 100644 --- a/src/pages/Loaning/LoaningPage.tsx +++ b/src/pages/Loaning/LoaningPage.tsx @@ -5,7 +5,7 @@ import { Helmet } from "react-helmet" import { AppThunk } from "../../store" import styles from "./styles.module.scss" -import { LoaningIntro, Loaning, fetchForLoaning } from "../../components" +import { LoaningIntro, Loaning, fetchForLoaning, LoginForm } from "../../components" import { selectUserJwtToken } from "../../store/auth" export type Props = RouteComponentProps @@ -14,7 +14,7 @@ const LoaningPage: FC = (): JSX.Element => { const jwtToken = useSelector(selectUserJwtToken) if (jwtToken === undefined) return

Loading...

if (!jwtToken) { - return
Besoin d'être identifié
+ return } return (
diff --git a/src/pages/Loans/LoansPage.tsx b/src/pages/Loans/LoansPage.tsx index 68f21f2..6b57952 100644 --- a/src/pages/Loans/LoansPage.tsx +++ b/src/pages/Loans/LoansPage.tsx @@ -5,7 +5,7 @@ import { Helmet } from "react-helmet" import { AppThunk } from "../../store" import styles from "./styles.module.scss" -import { LoansIntro, Loans, fetchForLoans } from "../../components" +import { LoansIntro, Loans, fetchForLoans, LoginForm } from "../../components" import { selectUserJwtToken } from "../../store/auth" export type Props = RouteComponentProps @@ -14,7 +14,7 @@ const LoansPage: FC = (): JSX.Element => { const jwtToken = useSelector(selectUserJwtToken) if (jwtToken === undefined) return

Loading...

if (!jwtToken) { - return
Besoin d'être identifié
+ return } return (
diff --git a/src/pages/TeamAssignment/TeamAssignmentPage.tsx b/src/pages/TeamAssignment/TeamAssignmentPage.tsx index 5750f75..b33194e 100644 --- a/src/pages/TeamAssignment/TeamAssignmentPage.tsx +++ b/src/pages/TeamAssignment/TeamAssignmentPage.tsx @@ -5,7 +5,7 @@ import { useSelector } from "react-redux" import { AppThunk } from "../../store" import { selectUserJwtToken } from "../../store/auth" import Page from "../../components/ui/Page/Page" -import { TeamAssignment, fetchForTeamAssignment } from "../../components" +import { TeamAssignment, fetchForTeamAssignment, LoginForm } from "../../components" import VolunteersWithTeamWishes from "../../components/TeamAssignment/VolunteersWithTeamWishes" export type Props = RouteComponentProps @@ -26,7 +26,7 @@ const TeamAssignmentPage: FC = (): JSX.Element => { ) } - return
Besoin d'être identifié
+ return } // Fetch server-side data here diff --git a/src/pages/Volunteers/Volunteers.tsx b/src/pages/Volunteers/Volunteers.tsx index eec249a..ea728d8 100644 --- a/src/pages/Volunteers/Volunteers.tsx +++ b/src/pages/Volunteers/Volunteers.tsx @@ -5,6 +5,7 @@ import { useSelector } from "react-redux" import { AppThunk } from "../../store" import { selectUserJwtToken } from "../../store/auth" import Page from "../../components/ui/Page/Page" +import { LoginForm } from "../../components" import { fetchVolunteerListIfNeed } from "../../store/volunteerList" export type Props = RouteComponentProps @@ -20,7 +21,7 @@ const BoardPage: FC = (): JSX.Element => { ) } - return
Besoin d'être identifié
+ return } // Fetch server-side data here diff --git a/src/store/volunteerLogin.ts b/src/store/volunteerLogin.ts index 785f52d..2481904 100644 --- a/src/store/volunteerLogin.ts +++ b/src/store/volunteerLogin.ts @@ -32,6 +32,18 @@ const volunteerLoginSlice = createSlice({ export default volunteerLoginSlice.reducer export const { getRequesting, getSuccess, getFailure } = volunteerLoginSlice.actions +export const fetchVolunteerLoginToRoot = elementFetch< + VolunteerLogin, + Parameters +>(volunteerLogin, getRequesting, getSuccess, getFailure, undefined, (login: VolunteerLogin) => { + setJWT(login.jwt, login.id, login.roles) + // eslint-disable-next-line no-restricted-globals + if (location?.pathname) { + // eslint-disable-next-line no-restricted-globals + location.pathname = "/" + } +}) + export const fetchVolunteerLogin = elementFetch>( volunteerLogin, getRequesting,