refactor: add reusable select controls and enhance data table columns
This commit is contained in:
@@ -58,6 +58,7 @@ export function PackageTable({
|
||||
onPageChange,
|
||||
onLimitChange,
|
||||
}}
|
||||
actionsSticky
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ export function PlanTable({
|
||||
}}
|
||||
sorting={sorting}
|
||||
onSortingChange={onSortingChange}
|
||||
actionsSticky
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ export function ProjectTable({
|
||||
onPageChange,
|
||||
onLimitChange,
|
||||
}}
|
||||
actionsSticky
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@ export function RoleTable({
|
||||
}}
|
||||
sorting={sorting}
|
||||
onSortingChange={onSortingChange}
|
||||
actionsSticky
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import { useCallback, useState } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { Plus, ShieldCheck } from 'lucide-react';
|
||||
|
||||
import { PageHeader } from '@/components/page-header';
|
||||
@@ -27,6 +27,7 @@ export default function RolesPage() {
|
||||
(state) => state.user?.organization_id ?? null,
|
||||
);
|
||||
const [isSheetOpen, setIsSheetOpen] = useState(false);
|
||||
const [activeRole, setActiveRole] = useState<Role | null>(null);
|
||||
const {
|
||||
skip,
|
||||
setSkip,
|
||||
@@ -49,6 +50,7 @@ export default function RolesPage() {
|
||||
sorting,
|
||||
});
|
||||
const permissionsQuery = usePermissionsTreeQuery(isSheetOpen);
|
||||
|
||||
const roleForm = useRoleForm({
|
||||
organizationId,
|
||||
permissionTree: permissionsQuery.permissionTree,
|
||||
@@ -72,18 +74,32 @@ export default function RolesPage() {
|
||||
statusMutation;
|
||||
|
||||
const openCreate = useCallback(() => {
|
||||
prepareCreateRole();
|
||||
setActiveRole(null);
|
||||
setIsSheetOpen(true);
|
||||
}, [prepareCreateRole]);
|
||||
}, []);
|
||||
|
||||
const openEdit = useCallback(
|
||||
(role: Role) => {
|
||||
prepareEditRole(role);
|
||||
setActiveRole(role);
|
||||
setIsSheetOpen(true);
|
||||
},
|
||||
[prepareEditRole],
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isSheetOpen || permissionsQuery.permissionTree.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
activeRole ? prepareEditRole(activeRole) : prepareCreateRole();
|
||||
}, [
|
||||
activeRole,
|
||||
isSheetOpen,
|
||||
permissionsQuery.permissionTree,
|
||||
prepareCreateRole,
|
||||
prepareEditRole,
|
||||
]);
|
||||
|
||||
const toggleStatus = useCallback(
|
||||
(role: Role) => {
|
||||
updateRoleStatus(role);
|
||||
|
||||
@@ -58,6 +58,7 @@ export function SegmentTable({
|
||||
onPageChange,
|
||||
onLimitChange,
|
||||
}}
|
||||
actionsSticky
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -74,6 +74,7 @@ export function TenantTable({
|
||||
}}
|
||||
sorting={sorting}
|
||||
onSortingChange={onSortingChange}
|
||||
actionsSticky
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ export function useUserColumns(): ColumnDef<AdministrationUser>[] {
|
||||
{
|
||||
accessorKey: 'email',
|
||||
header: 'Email',
|
||||
size: 200,
|
||||
minSize: 160,
|
||||
},
|
||||
{
|
||||
accessorKey: 'phone_number',
|
||||
@@ -42,6 +44,7 @@ export function useUserColumns(): ColumnDef<AdministrationUser>[] {
|
||||
accessorKey: 'roles',
|
||||
header: 'Roles',
|
||||
enableSorting: false,
|
||||
meta: { disableTruncate: true },
|
||||
cell: ({ row }) => (
|
||||
<div className="flex flex-wrap gap-1">
|
||||
{row.original.roles?.length ? (
|
||||
|
||||
@@ -75,6 +75,7 @@ export function UserTable({
|
||||
}}
|
||||
sorting={sorting}
|
||||
onSortingChange={onSortingChange}
|
||||
actionsSticky
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user