diff --git a/src/app/admin/organizations/[id]/page.tsx b/src/app/admin/organizations/[id]/page.tsx index 6543c4b..59de245 100644 --- a/src/app/admin/organizations/[id]/page.tsx +++ b/src/app/admin/organizations/[id]/page.tsx @@ -16,134 +16,143 @@ export default function Profile() { const segments = pathname.split("/"); const uid = segments[segments.length - 1]; + const { data: session, status } = useSession(); const { data: companyInfos, isLoading } = useQuery({ enabled: status === 'authenticated', - queryKey: ["stats", session?.user.access_token], + queryKey: ["companyStats", session?.user.access_token], queryFn: async () => { try { const response = await axios.get( `https://private-docs-api.intside.co/companies/${uid}`, { headers: { 'Authorization': `Bearer ${session?.user.access_token}` + }, + params: { + details: true } } - ) + ); if (response.data) { - return response.data as CompanyById + return response.data as CompanyById; } } catch (error: any) { - console.error(error) + console.error(error); } } - }) - const adminId = companyInfos?.owner - + }); + + /* + const adminId = companyInfos?.owner; + console.log('will run the admin request'); const { data: adminInfos } = useQuery({ - enabled: status === 'authenticated', - queryKey: ["stats", session?.user.access_token], + enabled: !!adminId && status === 'authenticated', // Only run when adminId is available + queryKey: ["admin", adminId], // Ensure adminId is used in the query key queryFn: async () => { + console.log('running the admin request'); + //console.log('url :', `https://private-docs-api.intside.co/users/${adminId}`); + try { const response = await axios.get( - `https://private-docs-api.intside.co/users/${companyInfos}`, { + `https://private-docs-api.intside.co/users/${adminId}`, { // Use adminId instead of companyInfos headers: { 'Authorization': `Bearer ${session?.user.access_token}` } } - ) + ); if (response.data) { - return response.data.data as Owner + return response.data as Owner; } - } catch (error: any) { - console.error(error) + } catch (error) { + console.error(error); } } - }) - console.log(`https://private-docs-api.intside.co/users/${companyInfos}`); - + + }); +*/ return ( <> {/* {companyInfos[0]?.id} */}
-
+
-

{companyInfos?.name || "Pentatonic"}

- +
-
+

Détails de l'admin

-
-
+
+
E-mail
-
+

Adresse e-mail

-

{adminInfos?.email || "email"}

+

{companyInfos?.owner?.email || "email"}

-
+
E-mail
-
+

Prénom

-

{adminInfos?.first_name || "nom"}

+

{companyInfos?.owner?.first_name || "nom"}

Nom

-

{adminInfos?.last_name || "nom"}

+

{companyInfos?.owner?.last_name || "nom"}


-
-
-
+
+
+
Documents
-
+

Documents

-

123

+

{companyInfos?.total_documents || "0"}

-
+
Documents
-
+

Utilisateurs

-

24

+

{companyInfos?.total_users || "0"}

-
+
Fichiers
-
+

Taille des fichiers

-

3.41GB

+

{companyInfos?.total_documents_sizes + " "}GB

-
+
Horlorge
-
+

Dernière utilisation

-

26 Jan 2024 - 14h15

+

{companyInfos?.last_use || "-"}

diff --git a/src/app/admin/organizations/[id]/update/page.tsx b/src/app/admin/organizations/[id]/update/page.tsx index bd0caac..d7e2e60 100644 --- a/src/app/admin/organizations/[id]/update/page.tsx +++ b/src/app/admin/organizations/[id]/update/page.tsx @@ -3,57 +3,72 @@ import { icons } from "#/assets/icons" import Image from "next/image" import axios from "axios"; import { useSession } from "next-auth/react"; -import { useQuery } from "@tanstack/react-query"; -import { Company } from "#/types"; +import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; +import { Company, CompanyById } from "#/types"; import FloatingLabelInput from "#/components/floatingLabelInput"; +import { usePathname } from "next/navigation"; +import Link from "next/link"; +import Form from "#/components/form/form"; +import { adminSchema } from "#/schema/loginSchema"; export default function Update() { + const pathname = usePathname(); + + const segments = pathname.split("/"); + const uid = segments[segments.length - 2]; + const queryClient = useQueryClient() + - const { data: session, status } = useSession(); - const { data: company, isLoading } = useQuery({ + const { data: companyInfos, refetch, isLoading } = useQuery({ enabled: status === 'authenticated', - queryKey: ["stats", session?.user.access_token], + queryKey: ["companyStats", session?.user.access_token], queryFn: async () => { try { const response = await axios.get( - 'https://private-docs-api.intside.co/companies', { + `https://private-docs-api.intside.co/users/${uid}`, { headers: { 'Authorization': `Bearer ${session?.user.access_token}` + }, + params: { + details: true } } - ) + ); if (response.data) { - return response.data.data as Company + return response.data as CompanyById; } } catch (error: any) { - console.error(error) + console.error(error); } } - }) + }); - const { data: adminOrganization } = useQuery({ - enabled: status === 'authenticated', - queryKey: ["stats", session?.user.access_token], - queryFn: async () => { + const { mutate, isPending } = useMutation({ + mutationFn: async (id: string) => { try { - const response = await axios.get( - 'https://private-docs-api.intside.co/users/me', { + const response = await axios.delete( + `https://private-docs-api.intside.co/companies/${id}/`, { headers: { 'Authorization': `Bearer ${session?.user.access_token}` } } ) - if (response.data) { - return response.data as Company + if (response.status === 200 || response.status === 201) { + console.log('Suppresion réussie !') } - } catch (error: any) { + } catch (error) { console.error(error) } + }, + onSuccess: () => { + queryClient.invalidateQueries({ queryKey: ["companies"] }) + + refetch() } }) @@ -62,28 +77,61 @@ export default function Update() { <> {/* { company.map() } */} + + {/*
Connexion} + /> */} + +
-

Pentatonic

- +
- +
- +
- +
- +
diff --git a/src/assets/css/admin.css b/src/assets/css/admin.css index f0ed29d..e08f76e 100644 --- a/src/assets/css/admin.css +++ b/src/assets/css/admin.css @@ -1,51 +1,51 @@ /* Sidebar */ -.sidebar{ +.sidebar { border-right: 1px solid var(--cinder); position: fixed; } -.nav-item .nav-home{ +.nav-item .nav-home { margin-bottom: -10px; } -.nav-item{ +.nav-item { width: 100%; height: max-content; } -.nav-item.active{ +.nav-item.active { border-right: 2px solid var(--primary); } -.nav-item svg{ - color: var(--primary)!important; - background-color: var(--primary)!important; - fill: var(--primary)!important; - stroke: var(--primary)!important +.nav-item svg { + color: var(--primary) !important; + background-color: var(--primary) !important; + fill: var(--primary) !important; + stroke: var(--primary) !important } -.nav-home{ +.nav-home { margin-top: -11px; margin-bottom: -11px; } /* Border */ -.icon-border{ +.icon-border { border: 1px solid var(--cinder); padding: 8px; border-radius: 12px; cursor: pointer; } -.dropdown-menu{ +.dropdown-menu { width: max-content; background-color: var(--background); border-radius: 8px; box-shadow: 0 0 24px #0000001A; } -.dropdown-item a{ +.dropdown-item a { width: max-content; padding: 10px 20px; display: flex; @@ -62,7 +62,7 @@ overflow: hidden; } -.icon-rounded{ +.icon-rounded { width: max-content; height: max-content; padding: 8px; @@ -72,15 +72,37 @@ background-color: var(--bluegray); border-radius: 100px; } -.labels-container{ + +.labels-container { min-width: 100%; display: flex; flex-wrap: wrap; gap: 24px; } -.labels-container .label-container{ + +.labels-container .label-container { width: 40%; } -.labels-container .floating-label div.relative{ + +.labels-container .floating-label div.relative { width: 100%; +} + +.admin-infos { + gap: 12px; +} +.admin-card { + width: 284px; +} + + + +@media (max-width: 1024px) { + .admin-infos { + /* justify-content: space-between; */ + /* gap: 30px; */ + } + .admin-card { + /* max-width: 100%; */ + } } \ No newline at end of file diff --git a/src/assets/css/ruben-ui.css b/src/assets/css/ruben-ui.css index 6a04580..2085fbb 100644 --- a/src/assets/css/ruben-ui.css +++ b/src/assets/css/ruben-ui.css @@ -119,6 +119,9 @@ .r-gap-70{ gap: 70px; } +.r-r-gap-12{ + row-gap: 12px; +} /* Small (SM) */ @media (min-width: 640px) { /* Styles for small devices and up */ diff --git a/src/components/form/form.tsx b/src/components/form/form.tsx index 6a44dfe..4dd8e82 100644 --- a/src/components/form/form.tsx +++ b/src/components/form/form.tsx @@ -5,71 +5,71 @@ import { FormProps } from "#/types" import { FormEvent, useState } from "react" export default function Form({ - fields, - submit, - className, - child, - title, - schema -} : FormProps) { - const [errors, setErrors] = useState>({}); + fields, + submit, + className, + child, + title, + schema +}: FormProps) { + const [errors, setErrors] = useState>({}); - const handleSubmit = (e: FormEvent) => { - e.preventDefault() + const handleSubmit = (e: FormEvent) => { + e.preventDefault() - const formData = new FormData(e.currentTarget) - const data = Object.fromEntries(formData) + const formData = new FormData(e.currentTarget) + const data = Object.fromEntries(formData) - console.log("FORM DATA = ", data) - const result = schema.safeParse(data); - console.log("ZOD = ", result.error?.format()) + console.log("FORM DATA = ", data) + const result = schema.safeParse(data); + console.log("ZOD = ", result.error?.format()) - if(!result.success) { - const formatedErrors = result.error.format() as Record; + if (!result.success) { + const formatedErrors = result.error.format() as Record; - const newErrors: Record = {}; - Object.keys(formatedErrors).forEach((field) => { - if (field !== "_errors" && formatedErrors[field]._errors?.length) { - newErrors[field] = formatedErrors[field]._errors[0]; - } - }); - - setErrors(newErrors) - } else { - setErrors({}) - submit(result.data) + const newErrors: Record = {}; + Object.keys(formatedErrors).forEach((field) => { + if (field !== "_errors" && formatedErrors[field]._errors?.length) { + newErrors[field] = formatedErrors[field]._errors[0]; } + }); + + setErrors(newErrors) + } else { + setErrors({}) + submit(result.data) } + } - return ( - -
-

{title}

+ return ( + +
+

{title}

+
+ +
+ + { + fields.map((item, index) => ( +
+ + + {errors[item.name]}
+ )) + } + {child} +
+ -
- - { - fields.map((item, index) => ( -
- - - {errors[item.name]} -
- )) - } - {child} -
- - - ) + ) } \ No newline at end of file diff --git a/src/schema/loginSchema.ts b/src/schema/loginSchema.ts index e32d3aa..4d4c298 100644 --- a/src/schema/loginSchema.ts +++ b/src/schema/loginSchema.ts @@ -3,4 +3,12 @@ import { z } from "zod"; export const loginSchema = z.object({ email: z.string().email("Email invalide"), password: z.string().min(8, "Le mot de passe doit contenir au moins 8 caractères") +}); + +export const adminSchema = z.object({ + id: z.string().optional(), + last_name: z.string(), + first_name: z.string(), + email: z.string().min(1, "L'email est requis").email("Email invalide"), + organization: z.string().optional(), }); \ No newline at end of file diff --git a/src/types/index.ts b/src/types/index.ts index c27c713..1c591fc 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -51,11 +51,14 @@ export interface Owner { last_name: string } -export interface CompanyById { +export interface CompanyById { id: string name: string is_premium: boolean status: string - owner: string - description: string -} + owner: Owner + total_users: number + total_documents: number + total_documents_sizes: number + last_use: any +} \ No newline at end of file