Fix company search filters and build regressions
This commit is contained in:
parent
a8abb68e36
commit
11efad0312
3 changed files with 71 additions and 32 deletions
|
|
@ -21,11 +21,13 @@ import { Sheet, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetT
|
|||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||
import { ROLE_OPTIONS, type RoleOption } from "@/lib/authz"
|
||||
|
||||
type AdminRole = RoleOption | "machine"
|
||||
|
||||
type AdminUser = {
|
||||
id: string
|
||||
email: string
|
||||
name: string
|
||||
role: RoleOption
|
||||
role: AdminRole
|
||||
tenantId: string
|
||||
createdAt: string
|
||||
updatedAt: string | null
|
||||
|
|
@ -61,7 +63,7 @@ type CompanyOption = {
|
|||
type Props = {
|
||||
initialUsers: AdminUser[]
|
||||
initialInvites: AdminInvite[]
|
||||
roleOptions: readonly RoleOption[]
|
||||
roleOptions: readonly AdminRole[]
|
||||
defaultTenantId: string
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +115,11 @@ function sanitizeInvite(invite: AdminInvite & { events?: unknown }): AdminInvite
|
|||
return rest
|
||||
}
|
||||
|
||||
function coerceRole(role: AdminRole | string | null | undefined): RoleOption {
|
||||
const candidate = (role ?? "agent").toLowerCase()
|
||||
return (ROLE_OPTIONS as readonly string[]).includes(candidate) ? (candidate as RoleOption) : "agent"
|
||||
}
|
||||
|
||||
export function AdminUsersManager({ initialUsers, initialInvites, roleOptions, defaultTenantId }: Props) {
|
||||
const [users, setUsers] = useState<AdminUser[]>(initialUsers)
|
||||
const [invites, setInvites] = useState<AdminInvite[]>(initialInvites)
|
||||
|
|
@ -144,7 +151,17 @@ export function AdminUsersManager({ initialUsers, initialInvites, roleOptions, d
|
|||
const [isResettingPassword, setIsResettingPassword] = useState(false)
|
||||
const [passwordPreview, setPasswordPreview] = useState<string | null>(null)
|
||||
|
||||
const normalizedRoles = useMemo(() => roleOptions ?? ROLE_OPTIONS, [roleOptions])
|
||||
const normalizedRoles = useMemo<readonly AdminRole[]>(() => {
|
||||
return (roleOptions && roleOptions.length > 0 ? roleOptions : ROLE_OPTIONS) as readonly AdminRole[]
|
||||
}, [roleOptions])
|
||||
const selectableRoles = useMemo(() => {
|
||||
const unique = new Set<RoleOption>()
|
||||
normalizedRoles.forEach((roleOption) => {
|
||||
const coerced = coerceRole(roleOption)
|
||||
unique.add(coerced)
|
||||
})
|
||||
return Array.from(unique)
|
||||
}, [normalizedRoles])
|
||||
const teamUsers = useMemo(() => users.filter((user) => user.role !== "machine"), [users])
|
||||
const machineUsers = useMemo(() => users.filter((user) => user.role === "machine"), [users])
|
||||
|
||||
|
|
@ -175,7 +192,7 @@ export function AdminUsersManager({ initialUsers, initialInvites, roleOptions, d
|
|||
setEditForm({
|
||||
name: editUser.name || "",
|
||||
email: editUser.email,
|
||||
role: editUser.role,
|
||||
role: coerceRole(editUser.role),
|
||||
tenantId: editUser.tenantId || defaultTenantId,
|
||||
companyId: editUser.companyId ?? "",
|
||||
})
|
||||
|
|
@ -567,13 +584,11 @@ export function AdminUsersManager({ initialUsers, initialInvites, roleOptions, d
|
|||
<SelectValue placeholder="Selecione" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{normalizedRoles
|
||||
.filter((option) => option !== "machine")
|
||||
.map((option) => (
|
||||
<SelectItem key={option} value={option}>
|
||||
{formatRole(option)}
|
||||
</SelectItem>
|
||||
))}
|
||||
{selectableRoles.map((option) => (
|
||||
<SelectItem key={option} value={option}>
|
||||
{formatRole(option)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
|
@ -693,7 +708,7 @@ export function AdminUsersManager({ initialUsers, initialInvites, roleOptions, d
|
|||
</Tabs>
|
||||
|
||||
<Sheet open={Boolean(editUser)} onOpenChange={(open) => (!open ? setEditUserId(null) : null)}>
|
||||
<SheetContent position="right" size="lg" className="space-y-6 overflow-y-auto">
|
||||
<SheetContent side="right" className="space-y-6 overflow-y-auto sm:max-w-2xl">
|
||||
<SheetHeader>
|
||||
<SheetTitle>Editar usuário</SheetTitle>
|
||||
<SheetDescription>Atualize os dados cadastrais, papel e vínculo do colaborador.</SheetDescription>
|
||||
|
|
@ -733,13 +748,11 @@ export function AdminUsersManager({ initialUsers, initialInvites, roleOptions, d
|
|||
<SelectValue placeholder="Selecione" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{normalizedRoles
|
||||
.filter((option) => option !== "machine")
|
||||
.map((option) => (
|
||||
<SelectItem key={option} value={option}>
|
||||
{formatRole(option)}
|
||||
</SelectItem>
|
||||
))}
|
||||
{selectableRoles.map((option) => (
|
||||
<SelectItem key={option} value={option}>
|
||||
{formatRole(option)}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue