diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx index dc7659f..d7e2105 100644 --- a/src/app/(auth)/login/page.tsx +++ b/src/app/(auth)/login/page.tsx @@ -4,10 +4,11 @@ import Form from "#/components/form/form" import { loginSchema } from "#/schema" import { useMutation } from "@tanstack/react-query" import { signIn } from "next-auth/react" -import { useRouter } from "next/navigation"; +import { useRouter, useSearchParams } from "next/navigation"; export default function LoginPage() { const router = useRouter() + const params = useSearchParams().get("redirect_to"); const mutation = useMutation({ mutationKey: ['login'], @@ -26,7 +27,11 @@ export default function LoginPage() { console.error(errorMessage) throw new Error(result.error) } else { - router.push('/admin/home') + if (params) { + router.push(params); + } else { + router.push('/admin/home') + } } return result } catch (error: any) { @@ -47,7 +52,7 @@ export default function LoginPage() {
Connexion} + child={} />
) diff --git a/src/app/admin/admins/page.tsx b/src/app/admin/admins/page.tsx index 05df663..88219a5 100644 --- a/src/app/admin/admins/page.tsx +++ b/src/app/admin/admins/page.tsx @@ -298,6 +298,7 @@ export default function Admins() { columns={columns} data={users || []} pageSize={5} + isDataLoading={isLoading} header={(table) => { const selectedIds = table .getRowModel() diff --git a/src/app/admin/home/page.tsx b/src/app/admin/home/page.tsx index bc69bc2..879891a 100644 --- a/src/app/admin/home/page.tsx +++ b/src/app/admin/home/page.tsx @@ -187,6 +187,7 @@ export default function HomePage () { diff --git a/src/app/admin/layout.tsx b/src/app/admin/layout.tsx index 15e2217..e4e34ec 100644 --- a/src/app/admin/layout.tsx +++ b/src/app/admin/layout.tsx @@ -1,9 +1,24 @@ -import { ReactNode } from "react"; +"use client" + +import { ReactNode, useEffect } from "react"; import "../../assets/css/admin.css" import Sidebar from "../../components/admin/sidebar"; import Header from "../../components/admin/adminHeader"; +import { signOutFunc } from "#/lib/function"; +import { usePathname } from "next/navigation"; +import { useSession } from "next-auth/react"; export default function Dashboard({ children }: { children: ReactNode }) { + const { status, data } = useSession(); + const path = usePathname(); + + useEffect(() => { + if (status !== "loading") { + if (status === "unauthenticated" || (data && !data.user.access_token)) { + signOutFunc(); + } + } + }, [data, status, path]); return ( diff --git a/src/app/admin/organizations/page.tsx b/src/app/admin/organizations/page.tsx index 8341444..1a400c1 100644 --- a/src/app/admin/organizations/page.tsx +++ b/src/app/admin/organizations/page.tsx @@ -1,3 +1,4 @@ +"use client"; import { useState } from "react"; import Image from "next/image"; @@ -11,16 +12,14 @@ import { Modal } from "#/components/modal"; import Table from "#/components/table/table"; import Form from "#/components/form/form"; import { icons } from "#/assets/icons"; -import { adminSchema, companySchema } from "#/schema"; +import { companySchema } from "#/schema"; import { Admin, Company } from "#/types"; import Link from "next/link"; export default function Organizations() { const { data: session, status } = useSession(); - const [open, setOpen] = useState(false); const [openModal, setOpenModal] = useState(false); const [openDeleteModal, setOpenDeleteModal] = useState(false); - const [openEditModal, setOpenEditModal] = useState(false); const [selectedAdminId, setSelectedAdminId] = useState(null); const queryClient = useQueryClient(); @@ -105,34 +104,6 @@ export default function Organizations() { }, }); - const updateMutation = useMutation({ - mutationFn: async (data: { - id: string; - last_name: string; - first_name: string; - email: string; - }) => { - try { - const response = await axios.put( - `https://private-docs-api.intside.co/companies/${data.id}/`, - data, - { headers: { Authorization: `Bearer ${session?.user.access_token}` } } - ); - - if (response.status === 200 || response.status === 201) { - console.log("modification réussie !"); - setOpenEditModal(false); - } - } catch (error) { - console.error("Erreur lors de la mise à jour", error); - } - }, - onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ["organizations"] }); - refetch(); - }, - }); - const deleteMutation = useMutation({ mutationFn: async (id: string) => { try { @@ -268,14 +239,14 @@ export default function Organizations() { } title="Supprimer une organisation" content={
-

Voulez-vous vraiment supprimer cette organisation ?

+

Voulez-vous vraiment supprimer cette organisation ?

{ + const selectedIds = table + .getRowModel() + .rows.filter((row) => row.getIsSelected()) + .map((row) => row.original.id); + + return ( +
+
+ + table.toggleAllPageRowsSelected(e.target.checked) + } + /> + + + +

+ Sélectionner une action +

+
+ + + + bulkDeleteMutation.mutate(selectedIds)} + className="p-2 text-[14px] cursor-pointer hover:bg-blue-100 hover:text-blue-500 rounded-md" + > + Supprimer + + + +
+
+ +
+ {/* Modal d'ajout */} + { + if (!isOpen) { + setOpenModal(false); + } + }} + trigger={ +
setOpenModal(true)} + className="cursor-pointer p-3 bg-blue-600 text-white rounded-full" + > + Ajouter une organisation +
+ } + content={ + ({ + label: user.name, + value: user.id, + })) || [], + }, + ]} + submit={createMutation.mutate} // Le type est maintenant compatible + schema={companySchema} + child={ + + } + /> + } + /> + + table.setGlobalFilter(value)} + button={ + + } + /> +
+
+ ); + }} + /> + ); +} diff --git a/src/components/admin/adminHeader.tsx b/src/components/admin/adminHeader.tsx index 993ed9f..2e31708 100644 --- a/src/components/admin/adminHeader.tsx +++ b/src/components/admin/adminHeader.tsx @@ -15,7 +15,7 @@ export default function AdminHeader() { return ( <> {table.getHeaderGroups().map((headerGroup) => ( + {header + ? + + : + } {headerGroup.headers.map((header) => { return( )) ) + : isDataLoading ? + ( + + + + ) : ( - diff --git a/src/lib/function.ts b/src/lib/function.ts new file mode 100644 index 0000000..44c6d61 --- /dev/null +++ b/src/lib/function.ts @@ -0,0 +1,11 @@ +import { signOut } from "next-auth/react"; + +export const signOutFunc = () => { + signOut({ + callbackUrl: `/login?redirect_to=${ + window.location.pathname === "/logout" + ? "/home" + : window.location.pathname + }`, + }); + }; \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index bc1ac0b..ec29d34 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -23,7 +23,8 @@ export interface FormProps { submit: (param: any) => unknown, className?: string, child: ReactNode, - schema: ZodSchema + schema: ZodSchema, + formClassName?: string } export interface StatsType {
+ + ({ type="checkbox" name="" id="" /> @@ -141,9 +150,17 @@ export default function Table({
+ Chargement... +
+ Aucun résultats