"use client" import axios from "axios"; import * as React from 'react'; import { useEffect, useState } from "react"; import { useSession } from "next-auth/react"; import { cn } from "@/lib/utils"; import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover" import { Button } from "../ui/button"; import { Check, ChevronsUpDown } from "lucide-react"; import { User } from "@prisma/client"; import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem } from "../ui/command"; const AdminProfile = () => { const session = useSession(); const [impersonation, setImpersonation] = useState(null) const [open, setOpen] = useState(false) const [users, setUsers] = useState([]) useEffect(() => { const fetch = async (userId: string | undefined) => { if (!userId) return await axios.get("/api/users?id=" + userId) .then(u => { setImpersonation(u.data?.name) }) } console.log(session) fetch(session?.data?.user?.impersonation?.id) }, []) useEffect(() => { const fetchUsers = async () => { await axios.get("/api/users") .then((u) => { setUsers(u.data.filter(x => x.id != session.data?.user.id)) }) } fetchUsers() }, []) const onImpersonationChange = async (userId: string, name: string) => { if (impersonation) { if (impersonation == session.data?.user.impersonation?.name) { await axios.delete("/api/account/impersonate") .then(() => { setImpersonation(null) window.location.reload() }) } else { await axios.put("/api/account/impersonate", { targetId: userId }) .then(() => { setImpersonation(name) window.location.reload() }) } } else { await axios.post("/api/account/impersonate", { targetId: userId }) .then(() => { setImpersonation(name) window.location.reload() }) } } return (

Role:

{session?.data?.user?.role}

Impersonation:

No voices found. {users.map((user) => ( { onImpersonationChange(user.id, user.name ?? "") setOpen(false) }} > {user.name} ))}
); } export default AdminProfile;