diff --git a/src/components/widgets/InformationWidget.tsx b/src/components/widgets/InformationWidget.tsx index ea59a71..6cb7ba0 100644 --- a/src/components/widgets/InformationWidget.tsx +++ b/src/components/widgets/InformationWidget.tsx @@ -1,7 +1,33 @@ import { Card, CardContent, CardHeader } from '@/components/ui/Card'; +import type { Company } from '@/types/Company'; +import type { User } from '@/types/user'; +import { Loader } from '@/components/ui/Loader'; import { Building } from "lucide-react"; -export function InformationWidget() { +interface InformationWidgetProps { + user: User; + company: Company; + isLoading: boolean; + error: string; +} + +function setVipBadge(vip_level: string | undefined) { + switch (vip_level?.toLowerCase()) { + case "platinum": + return {vip_level?.toUpperCase()}; + case "premium": + return {vip_level?.toUpperCase()}; + default: + return {vip_level?.toUpperCase()}; + } +} + +export const InformationWidget: React.FC = ({ + user, + company, + isLoading, + error, +}) => { return ( @@ -12,23 +38,27 @@ export function InformationWidget() { - - - Entité Légale - Cabinet Juridique Example & Associés - - - Administrateur du compte - Direction Générale (direction@example.com) - - - Niveau d'Infogérance (SLA) - - VIP PLATINUM - Couverture 24/7 (99.99%) - - - + {isLoading && !error && } + {!isLoading && !error && ( + + + Entité Légale + {company?.name} + + + Administrateur du compte + {user?.role} {user?.name} + Email : {user?.emailVisibility && user?.email}{!user?.emailVisibility && "caché"} + + + Niveau d'Infogérance (SLA) + + {setVipBadge(company?.vip_level)} + Couverture 24/7 (99.99%) + + + + )} ); diff --git a/src/hooks/useUserInformations.ts b/src/hooks/useUserInformations.ts new file mode 100644 index 0000000..33d8075 --- /dev/null +++ b/src/hooks/useUserInformations.ts @@ -0,0 +1,30 @@ +import { pb } from "@/services/pocketbase"; +import type { Company } from "@/types/Company"; +import type { User } from "@/types/user"; +import { useEffect, useState } from "react"; + +export const useUserInformations = () => { + const [user, setUser] = useState(null); + const [company, setCompany] = useState(null); + const [isLoading, setIsLoading] = useState(true); + const [error, setError] = useState(null); + + useEffect(() => { + const fetchInformations = async () => { + setIsLoading(true); + try { + const userRecords = await pb.collection('aegis_users').getFullList(); + setUser(userRecords[0]); + const companyRecords = await pb.collection('aegis_companies').getFullList(); + setCompany(companyRecords[0]) + } catch (err) { + setError("Erreur lors de la récupération des infos utilisateur :"+err); + } finally { + setIsLoading(false); + } + }; + fetchInformations(); + }, []); + + return { user, company, isLoading, error }; +}; \ No newline at end of file diff --git a/src/pages/AccountSettings.tsx b/src/pages/AccountSettings.tsx index 3c196f3..02048e3 100644 --- a/src/pages/AccountSettings.tsx +++ b/src/pages/AccountSettings.tsx @@ -1,29 +1,29 @@ import PageHeader from "@/components/ui/PageHeader"; import AccessWidget from "@/components/widgets/AccessWidget"; import InformationWidget from "@/components/widgets/InformationWidget"; +import { useUserInformations } from "@/hooks/useUserInformations"; export default function AccountSettings() { + const { user, company, isLoading, error } = useUserInformations(); return ( - - {/* Contenu Principal */} {/* Header */} - - {/* Colonne 1 : Sécurité */} - - + {/* Colonne 2 : Organisation & Contrat */} - - + - ); diff --git a/src/types/Company.ts b/src/types/Company.ts new file mode 100644 index 0000000..addb1d4 --- /dev/null +++ b/src/types/Company.ts @@ -0,0 +1,8 @@ +export interface Company { + id: string; + name: string; + no: string; + vip_level: string; + created: string; + updated: string +} \ No newline at end of file diff --git a/src/types/User.ts b/src/types/User.ts new file mode 100644 index 0000000..fe0e146 --- /dev/null +++ b/src/types/User.ts @@ -0,0 +1,12 @@ +export interface User { + id: string; + email: string; + emailVisibility: boolean; + verified: boolean; + name: string; + role: string; + company: string; + mfa_enabled: boolean; + created: string; + updated: string +} \ No newline at end of file