"use client" import type { User } from "better-auth" import type { Member } from "better-auth/plugins/organization" import { type ComponentProps, useContext, useMemo } from "react" import { AuthUIContext } from "../../lib/auth-ui-provider" import { cn } from "../../lib/utils" import type { AuthLocalization } from "../../localization/auth-localization" import type { SettingsCardClassNames } from "../settings/shared/settings-card" import { SettingsCellSkeleton } from "../settings/skeletons/settings-cell-skeleton" import { Button } from "../ui/button" import { Card, CardContent, CardHeader, CardTitle } from "../ui/card" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "../ui/dialog" import { MemberCell } from "./member-cell" import { UpdateMemberTeamCell } from "./update-member-team-cell" export interface UpdateMemberTeamsDialogProps extends ComponentProps { classNames?: SettingsCardClassNames localization?: AuthLocalization member: Member & { user?: Partial | null } } export function UpdateMemberTeamsDialog({ member, classNames, localization: localizationProp, onOpenChange, ...props }: UpdateMemberTeamsDialogProps) { const { hooks: { useListTeams, useListUserTeams }, localization: contextLocalization } = useContext(AuthUIContext) const localization = useMemo( () => ({ ...contextLocalization, ...localizationProp }), [contextLocalization, localizationProp] ) const { data: memberTeams, isPending: memberTeamsPending, refetch } = useListUserTeams() function isAdded(teamId: string) { return memberTeams?.some((mt) => mt.id === teamId) ?? false } const { data: orgTeams, isPending: orgTeamsPending } = useListTeams({ organizationId: member.organizationId }) const isPending = memberTeamsPending || orgTeamsPending return ( e.preventDefault()} > {localization.UPDATE_TEAMS} {localization.UPDATE_TEAMS_DESCRIPTION}
{localization.TEAMS} {isPending ? ( ) : orgTeams && orgTeams.length > 0 ? ( orgTeams .sort( (a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime() ) .map((team) => ( )) ) : (

{localization.NO_TEAMS_FOUND}

)}
) }