"use client"; import { useActionState, useEffect, useState } from "react"; import * as Dialog from "@radix-ui/react-dialog"; import { LoaderCircle, Trash2, UserRound, Users } from "lucide-react"; import { manageUserAction, type FormState } from "@/app/actions/auth"; import type { ManagedUser } from "@/lib/auth-service"; import { ScrollFade } from "@/components/ScrollFade"; export function UsersTable({ users, currentUserId }: { users: ManagedUser[]; currentUserId: string }) { const [state, action, pending] = useActionState(manageUserAction, {}); const [deleting, setDeleting] = useState(null); const [deleteAttempted, setDeleteAttempted] = useState(false); useEffect(() => { if (state.success) setDeleting(null); }, [state]); const activeCount = users.filter((user) => user.active).length; return

Users

{activeCount} active · {users.length - activeCount} inactive

Scroll sideways to see actions →

{state.error &&

{state.error}

} {state.success &&

{state.success}

}
{users.map((user) => )}
Mega Plant users and their access status
UserEmailAccessStatusActions
{user.id === currentUserId && You}
{user.email} {user.id === currentUserId ? Full :
}
{user.active && !user.passwordChanged &&

First sign-in pending

}
{user.id === currentUserId ? Current account :
}

Making a user inactive keeps their account and blocks access to the app. Reactivate them here whenever they need access again.

{ if (!open && !pending) setDeleting(null); }}> Delete this user? {deleting?.name || "This user"} ({deleting?.email}) will lose access and their account will be permanently removed. You can make them inactive instead if they may return. {deleteAttempted && !pending && state.error &&

{state.error}

}
setDeleteAttempted(true)}>
; }