import { Button, IconButton } from "@mui/joy"; import { useEffect, useState } from "react"; import toast from "react-hot-toast"; import useUserStore from "../../stores/v1/user"; import { showCommonDialog } from "../Alert"; import CreateUserDialog from "../CreateUserDialog"; import Icon from "../Icon"; const MemberSection = () => { const userStore = useUserStore(); const [showCreateUserDialog, setShowCreateUserDialog] = useState(false); const [currentEditingUser, setCurrentEditingUser] = useState(undefined); const userList = Object.values(userStore.userMapById); useEffect(() => { userStore.fetchUserList(); }, []); const handleCreateUserDialogClose = () => { setShowCreateUserDialog(false); setCurrentEditingUser(undefined); }; const handleDeleteUser = async (user: User) => { showCommonDialog({ title: "Delete User", content: `Are you sure to delete user \`${user.nickname}\`? You cannot undo this action.`, style: "danger", onConfirm: async () => { try { await userStore.deleteUser(user.id); toast.success(`User \`${user.nickname}\` deleted successfully`); } catch (error: any) { toast.error(`Failed to delete user \`${user.nickname}\`: ${error.response.data.message}`); } }, }); }; return ( <>

Users

A list of all the users in your workspace including their nickname, email and role.

{userList.map((user) => ( ))}
Nickname Email Role Edit
{user.nickname} {user.email} {user.role} { setCurrentEditingUser(user); setShowCreateUserDialog(true); }} > handleDeleteUser(user)}>
{showCreateUserDialog && } ); }; export default MemberSection;