"use client" import { Loader2, UsersIcon } from "lucide-react" import { type ComponentProps, useContext, useMemo, useState } from "react" import { AuthUIContext } from "../../lib/auth-ui-provider" import { cn, getLocalizedError } from "../../lib/utils" import type { AuthLocalization } from "../../localization/auth-localization" import type { Team } from "../../types/auth-hooks" import type { Refetch } from "../../types/refetch" import type { SettingsCardClassNames } from "../settings/shared/settings-card" import { Button } from "../ui/button" import { Card } from "../ui/card" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "../ui/dialog" interface DeleteTeamDialogProps extends ComponentProps { classNames?: SettingsCardClassNames team: Team localization?: AuthLocalization refetch?: Refetch } export function DeleteTeamDialog({ classNames, team, localization: localizationProp, refetch, onOpenChange, ...props }: DeleteTeamDialogProps) { const { authClient, localization: contextLocalization, toast, localizeErrors } = useContext(AuthUIContext) const localization = useMemo( () => ({ ...contextLocalization, ...localizationProp }), [contextLocalization, localizationProp] ) const [isDeleting, setIsDeleting] = useState(false) const handleDelete = async () => { try { setIsDeleting(true) await authClient.organization.removeTeam({ teamId: team.id, organizationId: team.organizationId, fetchOptions: { throw: true } }) toast({ variant: "success", message: localization.DELETE_TEAM_SUCCESS }) await refetch?.() onOpenChange?.(false) } catch (error) { toast({ variant: "error", message: getLocalizedError({ error, localization, localizeErrors }) }) } finally { setIsDeleting(false) } } return ( e.preventDefault()} > {localization.DELETE_TEAM} {localization.REMOVE_TEAM_CONFIRM}
{team.name}
{localization?.TEAM}
) }