"use client"; import { Dispatch, SetStateAction, useTransition } from "react"; import { removeUserFromTenant } from "@/actions/users/users"; import { DeleteIcon } from "@/components/icons"; import { Button, useToast } from "@/components/shadcn"; interface ExpelUserFormProps { userId: string; userName?: string; tenantId: string; setIsOpen: Dispatch>; } export const ExpelUserForm = ({ userId, userName, tenantId, setIsOpen, }: ExpelUserFormProps) => { const { toast } = useToast(); const [isPending, startTransition] = useTransition(); const handleExpel = () => { startTransition(async () => { const formData = new FormData(); formData.append("userId", userId); formData.append("tenantId", tenantId); const data = await removeUserFromTenant(formData); if (!data || !("success" in data) || data.success !== true) { const detail = data && "errors" in data && data.errors?.[0]?.detail ? data.errors[0].detail : "Failed to expel the user"; toast({ variant: "destructive", title: "Oops! Something went wrong", description: detail, }); return; } toast({ title: "User expelled", description: `${userName ?? "The user"} was removed from this organization.`, }); setIsOpen(false); }); }; const displayName = userName ?? "this user"; return (

{displayName} will lose access to this organization. If they don't belong to any other organization, their account will be permanently deleted.

); };