From e47ea5eecc867b0cc1aa19eff68608236ca6ffdf Mon Sep 17 00:00:00 2001 From: Esdras Renan Date: Fri, 24 Oct 2025 10:15:30 -0300 Subject: [PATCH] Refine admin users filters with searchable combobox --- .../admin/users/admin-users-workspace.tsx | 181 ++++++++++-------- 1 file changed, 98 insertions(+), 83 deletions(-) diff --git a/src/components/admin/users/admin-users-workspace.tsx b/src/components/admin/users/admin-users-workspace.tsx index 4cb6906..505bd5a 100644 --- a/src/components/admin/users/admin-users-workspace.tsx +++ b/src/components/admin/users/admin-users-workspace.tsx @@ -60,6 +60,7 @@ import { import { Textarea } from "@/components/ui/textarea" import { Badge } from "@/components/ui/badge" import { Avatar, AvatarFallback } from "@/components/ui/avatar" +import { SearchableCombobox, type SearchableComboboxOption } from "@/components/ui/searchable-combobox" export type AdminAccount = { id: string @@ -196,6 +197,32 @@ function AccountsTable({ initialAccounts }: { initialAccounts: AdminAccount[] }) return Array.from(map.entries()).map(([id, name]) => ({ id, name })) }, [accounts]) + const roleSelectOptions = useMemo( + () => ROLE_OPTIONS_DISPLAY.map((option) => ({ value: option.value, label: option.label })), + [], + ) + + const roleFilterOptions = useMemo( + () => [{ value: "all", label: "Todos os papéis" }, ...roleSelectOptions], + [roleSelectOptions], + ) + + const companyFilterOptions = useMemo( + () => [ + { value: "all", label: "Todas as empresas" }, + ...companies.map((company) => ({ value: company.id, label: company.name })), + ], + [companies], + ) + + const editCompanyOptions = useMemo( + () => [ + { value: NO_COMPANY_SELECT_VALUE, label: "Sem empresa vinculada" }, + ...companies.map((company) => ({ value: company.id, label: company.name })), + ], + [companies], + ) + const openDeleteDialog = useCallback((ids: string[]) => { setDeleteDialogIds(ids) }, []) @@ -379,34 +406,31 @@ function AccountsTable({ initialAccounts }: { initialAccounts: AdminAccount[] }) />
-
- - -
- +
+ + { + const normalized = + next === "MANAGER" || next === "COLLABORATOR" ? next : "all" + setRoleFilter(normalized) + }} + options={roleFilterOptions} + placeholder="Todos os papéis" + searchPlaceholder="Buscar papel..." + className="md:w-[12rem]" + />
+ setCompanyFilter(next ?? "all")} + options={companyFilterOptions} + placeholder="Todas as empresas" + searchPlaceholder="Buscar empresa..." + className="md:w-[16rem]" + />
+
- + {account.companyName ?? Sem empresa} - + {ROLE_LABEL[account.role]} - {formatDate(account.lastSeenAt)} - + + {formatDate(account.lastSeenAt)} + +
- - - setRowSelection((prev) => ({ ...prev, [account.id]: Boolean(checked) })) - } - /> + +
+ + setRowSelection((prev) => ({ ...prev, [account.id]: Boolean(checked) })) + } + aria-label={`Selecionar ${account.name}`} + /> +
) @@ -571,50 +600,36 @@ function AccountsTable({ initialAccounts }: { initialAccounts: AdminAccount[] }) />
- - -
-
- - + /> +
+
+ + + setEditForm((prev) => ({ + ...prev, + companyId: next === NO_COMPANY_SELECT_VALUE || next === null ? "" : next, + })) + } + options={editCompanyOptions} + placeholder="Sem empresa vinculada" + searchPlaceholder="Buscar empresa..." + disabled={isSavingAccount} + />