From de73b8ff68582367a20a370fb07566284828804e Mon Sep 17 00:00:00 2001 From: Oussama El Benney Date: Tue, 6 Aug 2024 16:31:27 +0100 Subject: [PATCH] dixed ' problem and change password useSearchParams problem when building --- .../assign-zone-project/AssignProject.jsx | 2 +- .../CompleteAffectation.jsx | 4 +- .../(dashboard)/assign-zone-project/page.jsx | 6 +- .../consultation-reservations/page.jsx | 2 +- src/app/(dashboard)/etage/CreateEtage.jsx | 2 +- src/app/(dashboard)/etage/EtageTableRow.jsx | 6 +- src/app/(dashboard)/etage/EtagesFilter.jsx | 2 +- src/app/(dashboard)/etage/page.jsx | 4 +- src/app/(dashboard)/place/page.jsx | 2 +- .../privilege/PrivilegesFilter.jsx | 2 +- src/app/(dashboard)/privilege/page.jsx | 2 +- src/app/(dashboard)/projects/ProjectForm.jsx | 2 +- src/app/(dashboard)/reservation/page.jsx | 2 +- src/app/(dashboard)/role/page.jsx | 2 +- src/app/(dashboard)/table/page.jsx | 2 +- src/app/(dashboard)/user/page.jsx | 2 +- .../zone-project/AssignProject.jsx | 2 +- .../zone-project/CompleteAffectation.jsx | 4 +- src/app/(dashboard)/zone-project/page.jsx | 2 +- src/app/(dashboard)/zone/page.jsx | 2 +- .../ChangePasswordComponent.jsx | 133 ++++++++++++++++++ src/app/auth/change-password/page.jsx | 127 +---------------- src/app/lib/session.js | 1 - src/app/ui/ReservationConfirmation.jsx | 2 +- 24 files changed, 168 insertions(+), 149 deletions(-) create mode 100644 src/app/auth/change-password/ChangePasswordComponent.jsx diff --git a/src/app/(dashboard)/assign-zone-project/AssignProject.jsx b/src/app/(dashboard)/assign-zone-project/AssignProject.jsx index 5566068..792edec 100644 --- a/src/app/(dashboard)/assign-zone-project/AssignProject.jsx +++ b/src/app/(dashboard)/assign-zone-project/AssignProject.jsx @@ -338,7 +338,7 @@ const AssignProject = ({ setIsOpen, listProjects, affectations, mutateProjectAff {((collabsAttributed - places.length) > 0) &&
-

Veuillez sélectionner une autre zonne pour compléter l'affectation (optionnel)

+

Veuillez sélectionner une autre zonne pour compléter l'affectation (optionnel)

handleOtherZoneSelection(e)} className='flex-1 rounded-md px-3 duration-150 delay-75 focus:ring ring-offset-1 ring-sushi-200 border h-10 border-neutral-300 outline-none'> diff --git a/src/app/(dashboard)/assign-zone-project/page.jsx b/src/app/(dashboard)/assign-zone-project/page.jsx index f3e0a85..599a69a 100644 --- a/src/app/(dashboard)/assign-zone-project/page.jsx +++ b/src/app/(dashboard)/assign-zone-project/page.jsx @@ -265,7 +265,7 @@ const AffectingZoneProject = () => { {isLoadingListProjects &&
} {!isLoadingListProjects && <> {(!isArray(listProjectsAffected) || listProjectsAffected?.length === 0) ?
-

Aucune Affectation n'a été trouvé.

+

Aucune Affectation n'a été trouvé.

:
@@ -310,7 +310,7 @@ const AffectingZoneProject = () => { { (listProjectsSemiAffected && listProjectsSemiAffected.length) ?
: @@ -320,7 +320,7 @@ const AffectingZoneProject = () => { isOpen={isModalOpen} onClose={() => setModalOpen(false)} onConfirm={handleConfirmDelete} - message={`Êtes-vous sûr de vouloir supprimer l'affectation "${selectedAffectaionToDelete?.id_project.nom}"?`} + message={`Êtes-vous sûr de vouloir supprimer l'affectation "${selectedAffectaionToDelete?.id_project.nom}"?`} /> diff --git a/src/app/(dashboard)/consultation-reservations/page.jsx b/src/app/(dashboard)/consultation-reservations/page.jsx index a1ce7ba..2dea09c 100644 --- a/src/app/(dashboard)/consultation-reservations/page.jsx +++ b/src/app/(dashboard)/consultation-reservations/page.jsx @@ -435,7 +435,7 @@ const Reservation = () => { {(!isLoadingData && !selectedZoneData) &&

Vous êtes en télétravail - aujourd'hui.

+ aujourd'hui.

} diff --git a/src/app/(dashboard)/etage/CreateEtage.jsx b/src/app/(dashboard)/etage/CreateEtage.jsx index 4e27ebc..91ac78d 100644 --- a/src/app/(dashboard)/etage/CreateEtage.jsx +++ b/src/app/(dashboard)/etage/CreateEtage.jsx @@ -170,7 +170,7 @@ const CreateEtage = ({ appendEtage, cancelCreate }) => {

{Math.round((image.size / (1024 * 1024)) * 100) / 100}Mo

-

Voir l'image

+

Voir l'image

{(isDisplayingImage) &&
diff --git a/src/app/(dashboard)/etage/EtageTableRow.jsx b/src/app/(dashboard)/etage/EtageTableRow.jsx index eb44b09..5d9de27 100644 --- a/src/app/(dashboard)/etage/EtageTableRow.jsx +++ b/src/app/(dashboard)/etage/EtageTableRow.jsx @@ -215,7 +215,7 @@ const EtageTableRow = ({ id, numero, setEtages, image: etageImage }) => { {(imageAttributs.size) &&

{Math.round((imageAttributs.size / (1024 * 1024)) * 100) / 100}Mo

}
-

Voir l'image

+

Voir l'image

@@ -227,10 +227,10 @@ const EtageTableRow = ({ id, numero, setEtages, image: etageImage }) => { } } {(!image && !isUpdating) &&

- Aucune image n'est associée à cet étage. + Aucune image n'est associée à cet étage.

} {(image && !isUpdating) &&
-

Voir l'image

+

Voir l'image

}
diff --git a/src/app/(dashboard)/etage/EtagesFilter.jsx b/src/app/(dashboard)/etage/EtagesFilter.jsx index 406e6e3..f91f7d5 100644 --- a/src/app/(dashboard)/etage/EtagesFilter.jsx +++ b/src/app/(dashboard)/etage/EtagesFilter.jsx @@ -14,7 +14,7 @@ const EtagesFilter = memo(function page({ setFilter, filter }) {

Recherche

- +
diff --git a/src/app/(dashboard)/etage/page.jsx b/src/app/(dashboard)/etage/page.jsx index 59ac933..972dd15 100644 --- a/src/app/(dashboard)/etage/page.jsx +++ b/src/app/(dashboard)/etage/page.jsx @@ -41,13 +41,13 @@ const Etage = () => { {isLoading &&
} {!isLoading && <> {(!isArray(etages) || etages?.length === 0) ?
-

Aucun étage n'a été trouvée.

+

Aucun étage n'a été trouvée.

:
- + {(isCreating) && setIsCreating(false)} appendEtage={appendEtage} />} diff --git a/src/app/(dashboard)/place/page.jsx b/src/app/(dashboard)/place/page.jsx index 08c1014..3533112 100644 --- a/src/app/(dashboard)/place/page.jsx +++ b/src/app/(dashboard)/place/page.jsx @@ -120,7 +120,7 @@ const Place = () => { {isLoading &&
} {!isLoading && <> {(!isArray(places) || places?.length === 0) ?
-

Aucune Place n'a été trouvé.

+

Aucune Place n'a été trouvé.

:
Numéro ÉtageL'image de l'étageL'image de l'étage Actions
diff --git a/src/app/(dashboard)/privilege/PrivilegesFilter.jsx b/src/app/(dashboard)/privilege/PrivilegesFilter.jsx index d251f0e..bf8df54 100644 --- a/src/app/(dashboard)/privilege/PrivilegesFilter.jsx +++ b/src/app/(dashboard)/privilege/PrivilegesFilter.jsx @@ -14,7 +14,7 @@ const PrivilegesFilter = memo(function page({ setFilter, filter }) {

Recherche

- +
diff --git a/src/app/(dashboard)/privilege/page.jsx b/src/app/(dashboard)/privilege/page.jsx index c052366..49acf4e 100644 --- a/src/app/(dashboard)/privilege/page.jsx +++ b/src/app/(dashboard)/privilege/page.jsx @@ -41,7 +41,7 @@ const Privilege = () => { {isLoading &&
} {!isLoading && <> {(!isArray(privileges) || privileges?.length === 0) ?
-

Aucune habilitation n'a été trouvée.

+

Aucune habilitation n'a été trouvée.

:
diff --git a/src/app/(dashboard)/projects/ProjectForm.jsx b/src/app/(dashboard)/projects/ProjectForm.jsx index 40e29d1..e732f37 100644 --- a/src/app/(dashboard)/projects/ProjectForm.jsx +++ b/src/app/(dashboard)/projects/ProjectForm.jsx @@ -189,7 +189,7 @@ const ProjectForm = ({setIsOpen, onAddProject, onEditProject, editingProject, se
{userIds.map((user, index) => ( -
+

{`${user.first_name} ${user.last_name}`} ({user.role.name})

diff --git a/src/app/(dashboard)/reservation/page.jsx b/src/app/(dashboard)/reservation/page.jsx index 422d12c..c3a1a0f 100644 --- a/src/app/(dashboard)/reservation/page.jsx +++ b/src/app/(dashboard)/reservation/page.jsx @@ -268,7 +268,7 @@ const Reservation = () => {
} {(!isLoadingData && !selectedZoneData) &&
-

Vous êtes en télétravail aujourd'hui.

+

Vous êtes en télétravail aujourd'hui.

}
diff --git a/src/app/(dashboard)/role/page.jsx b/src/app/(dashboard)/role/page.jsx index 214767a..ccb732d 100644 --- a/src/app/(dashboard)/role/page.jsx +++ b/src/app/(dashboard)/role/page.jsx @@ -55,7 +55,7 @@ const Role = () => { {isLoading &&
} {!isLoading && <> {(!isArray(roles) || roles?.length === 0) ?
-

Aucun rôle n'a été trouvé.

+

Aucun rôle n'a été trouvé.

:
diff --git a/src/app/(dashboard)/table/page.jsx b/src/app/(dashboard)/table/page.jsx index 7de51af..8fe6058 100644 --- a/src/app/(dashboard)/table/page.jsx +++ b/src/app/(dashboard)/table/page.jsx @@ -87,7 +87,7 @@ const Table = () => { {isLoading &&
} {!isLoading && <> {(!isArray(tables) || tables?.length === 0) ?
-

Aucune Table n'a été trouvé.

+

Aucune Table n'a été trouvé.

:
diff --git a/src/app/(dashboard)/user/page.jsx b/src/app/(dashboard)/user/page.jsx index d032b24..ffbef5c 100644 --- a/src/app/(dashboard)/user/page.jsx +++ b/src/app/(dashboard)/user/page.jsx @@ -67,7 +67,7 @@ const UserPage = () => { {(isLoading) &&
} {(!isLoading) && <> {(!isArray(users) || users?.length === 0) ?
-

Aucun utilisateurs n'a été trouvé

+

Aucun utilisateurs n'a été trouvé

:
diff --git a/src/app/(dashboard)/zone-project/AssignProject.jsx b/src/app/(dashboard)/zone-project/AssignProject.jsx index 3c923a8..4742f75 100644 --- a/src/app/(dashboard)/zone-project/AssignProject.jsx +++ b/src/app/(dashboard)/zone-project/AssignProject.jsx @@ -338,7 +338,7 @@ const AssignProject = ({ setIsOpen, listProjects, affectations, mutateProjectAff
{((collabsAttributed - places.length) > 0) &&
-

Veuillez sélectionner une autre zonne pour compléter l'affectation (optionnel)

+

Veuillez sélectionner une autre zonne pour compléter l'affectation (optionnel)

handleOtherZoneSelection(e)} className='flex-1 rounded-md px-3 duration-150 delay-75 focus:ring ring-offset-1 ring-sushi-200 border h-10 border-neutral-300 outline-none'> diff --git a/src/app/(dashboard)/zone-project/page.jsx b/src/app/(dashboard)/zone-project/page.jsx index c6de000..7bf4bde 100644 --- a/src/app/(dashboard)/zone-project/page.jsx +++ b/src/app/(dashboard)/zone-project/page.jsx @@ -320,7 +320,7 @@ const AffectingZoneProject = () => { { (listProjectsSemiAffected && listProjectsSemiAffected.length) ?
: diff --git a/src/app/(dashboard)/zone/page.jsx b/src/app/(dashboard)/zone/page.jsx index 4585298..c8a5426 100644 --- a/src/app/(dashboard)/zone/page.jsx +++ b/src/app/(dashboard)/zone/page.jsx @@ -68,7 +68,7 @@ const Zone = () => { {isLoading &&
} {!isLoading && <> {(!isArray(zones) || zones?.length === 0) ?
-

Aucune zone n'a été trouvé.

+

Aucune zone n'a été trouvé.

:
diff --git a/src/app/auth/change-password/ChangePasswordComponent.jsx b/src/app/auth/change-password/ChangePasswordComponent.jsx new file mode 100644 index 0000000..ef073d0 --- /dev/null +++ b/src/app/auth/change-password/ChangePasswordComponent.jsx @@ -0,0 +1,133 @@ +"use client" +import fetchRequest from '@/app/lib/fetchRequest' +import Image from 'next/image' +import Link from 'next/link' +import React, {useEffect, useState} from 'react' +import {useSearchParams} from 'next/navigation' +import Loader from '@/components/Loader/Loader' +import {PASSWORD_REGEX} from '@/app/lib/constants' +import {useNotification} from '@/context/NotificationContext' +import TeambookVertical from "@/static/image/teambook-vertical.png"; + +const ChangePassword = () => { + const [isSuccess, setIsSuccess] = useState(false) + const [formErrors, setFormErrors] = useState([]) + const [password, setPassword] = useState("") + const [confirmPassword, setConfirmPassword] = useState("") + const [isLoading, setIsLoading] = useState(false) + const {toggleNotification} = useNotification() + const searchParams = useSearchParams() + + const handleChangePassword = async (event) => { + event.preventDefault() + setIsLoading(true) + let token = ""; + if (searchParams.has("token")) { + token = searchParams.get("token") + } + const {isSuccess, data, errors} = await fetchRequest(`/password_reset/confirm/?token=${token}`, { + method: "POST", + body: JSON.stringify({ + password, + token + }) + }) + if (isSuccess) { + setIsSuccess(true) + } else { + console.log(errors) + setIsLoading(false) + if (errors.type === "ValidationError") { + if (errors.detail.token) { + setFormErrors(["Le lien que vous avez utilisé pour réinitialiser votre mot de passe est invalide"]) + } else { + setFormErrors(["Le Mot de passe est invalide"]) + } + } else if (errors?.detail?.detail?.startsWith("The OTP password entered is not valid")) { + setFormErrors(["Le lien que vous avez utilisé pour réinitialiser votre mot de passe est déja utilisé"]) + } else { + toggleNotification({ + type: "error", + message: "Internal Server Error", + visible: true + }) + } + } + } + + const isEmptyFields = !password && !confirmPassword + + useEffect(() => { + let currentErrors = [] + if (password !== confirmPassword) { + currentErrors.push("Les mots de passe ne sont pas identiques.") + } + if (password.length < 8) { + currentErrors.push("Le mot de passe doit comporter au moins 8 caractères.") + } + if (!PASSWORD_REGEX.test(password)) { + currentErrors.push("Le mot de passe doit contenir au moins une lettre, un chiffre et un caractère spécial.") + } + setFormErrors(currentErrors) + }, [password, confirmPassword]) + + return ( +
+
+ +
+ {(!isSuccess) && +
+

Changer votre Mot de passe +

+
+
+ + setPassword(event.target.value)} type="password" + name="new_password1" id="new_password1" + className="w-full py-6 rounded-md px-3 duration-150 delay-75 focus:ring ring-offset-1 ring-sushi-200 border h-10 border-neutral-300 outline-none"/> +
+
+ + setConfirmPassword(event.target.value)} type="password" + name="new_password2" id="new_password2" + className="w-full py-6 rounded-md px-3 duration-150 delay-75 focus:ring ring-offset-1 ring-sushi-200 border h-10 border-neutral-300 outline-none"/> +
+
+
    +
  • Le mot de passe doit contenir au moins 8 caractères
  • +
  • Le mot de passe doit contenir au moins un chiffre
  • +
  • Le mot de passe doit contenir au moins un caractère spécial
  • +
+
+ +
    0 && !isEmptyFields ? "bg-red-100 border border-red-300 min-h-10" : ""} w-full px-3 text-xs py-3 rounded relative mt-9 list-inside list-disc`} + role="alert"> + {!isEmptyFields && formErrors.map((error, index) => { + return
  • {error}
  • + })} +
+ +
} + {(isSuccess) && ( +
+

The password has been changed!

+ log in + again? +
+ )} +
+ ) +} + +export default ChangePassword \ No newline at end of file diff --git a/src/app/auth/change-password/page.jsx b/src/app/auth/change-password/page.jsx index 235d187..12798ca 100644 --- a/src/app/auth/change-password/page.jsx +++ b/src/app/auth/change-password/page.jsx @@ -1,125 +1,12 @@ -"use client" -import fetchRequest from '@/app/lib/fetchRequest' -import Image from 'next/image' -import Link from 'next/link' -import React, {useEffect, useState} from 'react' -import {useSearchParams} from 'next/navigation' -import Loader from '@/components/Loader/Loader' -import {PASSWORD_REGEX} from '@/app/lib/constants' -import {useNotification} from '@/context/NotificationContext' -import TeambookVertical from "@/static/image/teambook-vertical.png"; +import React, { Suspense } from 'react' +import ChangePassword from "@/app/auth/change-password/ChangePasswordComponent"; -const ChangePassword = () => { - const [isSuccess, setIsSuccess] = useState(false) - const [formErrors, setFormErrors] = useState([]) - const [password, setPassword] = useState("") - const [confirmPassword, setConfirmPassword] = useState("") - const [isLoading, setIsLoading] = useState(false) - const params = useSearchParams(); - const {toggleNotification} = useNotification() - const handleChangePassword = async (event) => { - event.preventDefault() - setIsLoading(true) - const {isSuccess, data, errors} = await fetchRequest(`/password_reset/confirm/?token=${params.get("token")}`, { - method: "POST", - body: JSON.stringify({ - password, - token: params.get("token") - }) - }) - if (isSuccess) { - setIsSuccess(true) - } else { - console.log(errors) - setIsLoading(false) - if (errors.type === "ValidationError") { - if (errors.detail.token) { - setFormErrors(["Le lien que vous avez utilisé pour réinitialiser votre mot de passe est invalide"]) - } else { - setFormErrors(["Le Mot de passe est invalide"]) - } - } else if (errors?.detail?.detail?.startsWith("The OTP password entered is not valid")) { - setFormErrors(["Le lien que vous avez utilisé pour réinitialiser votre mot de passe est déja utilisé"]) - } else { - toggleNotification({ - type: "error", - message: "Internal Server Error", - visible: true - }) - } - } - } - const isEmptyFields = !password && !confirmPassword - useEffect(() => { - var currentErrors = [] - if (password !== confirmPassword) { - currentErrors.push("Les mots de passe ne sont pas identiques.") - } - if (password.length < 8) { - currentErrors.push("Le mot de passe doit comporter au moins 8 caractères.") - } - if (!PASSWORD_REGEX.test(password)) { - currentErrors.push("Le mot de passe doit contenir au moins une lettre, un chiffre et un caractère spécial.") - } - setFormErrors(currentErrors) - }, [password, confirmPassword]) +const ChangePasswordPage = () => { return ( -
-
- -
- {(!isSuccess) && -
-

Changer votre Mot de passe -

-
-
- - setPassword(event.target.value)} type="password" - name="new_password1" id="new_password1" - className="w-full py-6 rounded-md px-3 duration-150 delay-75 focus:ring ring-offset-1 ring-sushi-200 border h-10 border-neutral-300 outline-none"/> -
-
- - setConfirmPassword(event.target.value)} type="password" - name="new_password2" id="new_password2" - className="w-full py-6 rounded-md px-3 duration-150 delay-75 focus:ring ring-offset-1 ring-sushi-200 border h-10 border-neutral-300 outline-none"/> -
-
-
    -
  • Le mot de passe doit contenir au moins 8 caractères
  • -
  • Le mot de passe doit contenir au moins un chiffre
  • -
  • Le mot de passe doit contenir au moins un caractère spécial
  • -
-
- -
    0 && !isEmptyFields ? "bg-red-100 border border-red-300 min-h-10" : ""} w-full px-3 text-xs py-3 rounded relative mt-9 list-inside list-disc`} - role="alert"> - {!isEmptyFields && formErrors.map((error, index) => { - return
  • {error}
  • - })} -
- -
} - {(isSuccess) && ( -
-

The password has been changed!

- log in - again? -
- )} -
+ Loading...}> + + ) } -export default ChangePassword \ No newline at end of file +export default ChangePasswordPage diff --git a/src/app/lib/session.js b/src/app/lib/session.js index 1eb509a..c5883f5 100644 --- a/src/app/lib/session.js +++ b/src/app/lib/session.js @@ -3,7 +3,6 @@ import Cookies from 'js-cookie'; import { SignJWT, jwtVerify } from 'jose' const secretKey = process.env.NEXT_PUBLIC_SESSION_SECRET; -console.log(secretKey); const encodedKey = new TextEncoder().encode(secretKey) export async function encrypt(payload) { diff --git a/src/app/ui/ReservationConfirmation.jsx b/src/app/ui/ReservationConfirmation.jsx index 7ec4532..9f768bf 100644 --- a/src/app/ui/ReservationConfirmation.jsx +++ b/src/app/ui/ReservationConfirmation.jsx @@ -27,7 +27,7 @@ const ReservationConfirmation = ({ isOpen, onClose, onConfirm, isLoading, reserv
-

Confirmation d'annulation de Réservation

+

Confirmation d'annulation de Réservation

Êtes-vous sûr de vouloir annuler la réservation de la place {reservationData.placeName || ""} à la table {reservationData.tableName || ""} dans la zone {reservationData.zoneName || ""}