Compare commits
3 Commits
6f4399a048
...
bd0782a55f
| Author | SHA1 | Date | |
|---|---|---|---|
| bd0782a55f | |||
| db11a512bf | |||
| 1325afdab2 |
1619
package-lock.json
generated
1619
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -20,6 +20,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@base-ui/react": "^1.5.0",
|
||||||
"@radix-ui/react-avatar": "^1.1.10",
|
"@radix-ui/react-avatar": "^1.1.10",
|
||||||
"@radix-ui/react-collapsible": "^1.1.12",
|
"@radix-ui/react-collapsible": "^1.1.12",
|
||||||
"@radix-ui/react-dialog": "^1.1.15",
|
"@radix-ui/react-dialog": "^1.1.15",
|
||||||
@@ -32,6 +33,7 @@
|
|||||||
"@tanstack/react-query": "^5.101.0",
|
"@tanstack/react-query": "^5.101.0",
|
||||||
"@tanstack/react-query-devtools": "^5.101.0",
|
"@tanstack/react-query-devtools": "^5.101.0",
|
||||||
"@tanstack/react-table": "^8.21.3",
|
"@tanstack/react-table": "^8.21.3",
|
||||||
|
"@tanstack/react-virtual": "^3.14.3",
|
||||||
"axios": "^1.13.6",
|
"axios": "^1.13.6",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
@@ -40,7 +42,7 @@
|
|||||||
"motion": "^12.38.0",
|
"motion": "^12.38.0",
|
||||||
"next": "16.0.10",
|
"next": "16.0.10",
|
||||||
"next-themes": "^0.4.6",
|
"next-themes": "^0.4.6",
|
||||||
"radix-ui": "^1.4.3",
|
"radix-ui": "^1.6.0",
|
||||||
"react": "19.2.0",
|
"react": "19.2.0",
|
||||||
"react-dom": "19.2.0",
|
"react-dom": "19.2.0",
|
||||||
"react-hook-form": "^7.79.0",
|
"react-hook-form": "^7.79.0",
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ export function useClientColumns({
|
|||||||
columns.push({
|
columns.push({
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
header: () => <div className="text-right">Actions</div>,
|
header: () => <div className="text-right">Actions</div>,
|
||||||
|
enableSorting: false,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const client = row.original;
|
const client = row.original;
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Input } from '@/components/ui/input';
|
import { TableSearchInput } from '@/components/data-table/TableSearchInput';
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -25,11 +25,10 @@ export function ClientFilters({
|
|||||||
}: ClientFiltersProps) {
|
}: ClientFiltersProps) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
||||||
<Input
|
<TableSearchInput
|
||||||
value={searchTerm}
|
value={searchTerm}
|
||||||
onChange={(event) => onSearchChange(event.target.value)}
|
onChange={onSearchChange}
|
||||||
placeholder="Search clients"
|
placeholder="Search clients"
|
||||||
className="md:max-w-sm"
|
|
||||||
/>
|
/>
|
||||||
<Select
|
<Select
|
||||||
value={statusFilter}
|
value={statusFilter}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import type { ColumnDef } from '@tanstack/react-table';
|
import type { ColumnDef, SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
import { DataTable } from '@/components/data-table';
|
import { DataTable } from '@/components/data-table';
|
||||||
import type { Client } from '@/types';
|
import type { Client } from '@/types';
|
||||||
@@ -14,7 +14,10 @@ interface ClientTableProps {
|
|||||||
skip: number;
|
skip: number;
|
||||||
limit: number;
|
limit: number;
|
||||||
total: number;
|
total: number;
|
||||||
|
sorting: SortingState;
|
||||||
onPageChange: (skip: number) => void;
|
onPageChange: (skip: number) => void;
|
||||||
|
onLimitChange: (limit: number) => void;
|
||||||
|
onSortingChange: (sorting: SortingState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ClientTable({
|
export function ClientTable({
|
||||||
@@ -25,7 +28,10 @@ export function ClientTable({
|
|||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
total,
|
total,
|
||||||
|
sorting,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
|
onLimitChange,
|
||||||
|
onSortingChange,
|
||||||
}: ClientTableProps) {
|
}: ClientTableProps) {
|
||||||
return (
|
return (
|
||||||
<DataTable
|
<DataTable
|
||||||
@@ -40,8 +46,10 @@ export function ClientTable({
|
|||||||
limit,
|
limit,
|
||||||
totalItems: total,
|
totalItems: total,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onLimitChange: () => undefined,
|
onLimitChange,
|
||||||
}}
|
}}
|
||||||
|
sorting={sorting}
|
||||||
|
onSortingChange={onSortingChange}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
import type { SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
import { useDebounce } from '@/hooks/useDebounce';
|
import { useDebounce } from '@/hooks/useDebounce';
|
||||||
|
|
||||||
@@ -8,7 +9,8 @@ export type ClientStatusFilter = 'all' | 'active' | 'inactive';
|
|||||||
|
|
||||||
export function useClientFilters() {
|
export function useClientFilters() {
|
||||||
const [skip, setSkip] = useState(0);
|
const [skip, setSkip] = useState(0);
|
||||||
const [limit] = useState(10);
|
const [limit, setLimitValue] = useState(10);
|
||||||
|
const [sorting, setSortingValue] = useState<SortingState>([]);
|
||||||
const [searchTerm, setSearchTermValue] = useState('');
|
const [searchTerm, setSearchTermValue] = useState('');
|
||||||
const [statusFilter, setStatusFilterValue] = useState<ClientStatusFilter>('all');
|
const [statusFilter, setStatusFilterValue] = useState<ClientStatusFilter>('all');
|
||||||
const debouncedSearchTerm = useDebounce(searchTerm.trim(), 400);
|
const debouncedSearchTerm = useDebounce(searchTerm.trim(), 400);
|
||||||
@@ -23,10 +25,23 @@ export function useClientFilters() {
|
|||||||
setSkip(0);
|
setSkip(0);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const setLimit = useCallback((value: number) => {
|
||||||
|
setLimitValue(value);
|
||||||
|
setSkip(0);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const setSorting = useCallback((value: SortingState) => {
|
||||||
|
setSortingValue(value);
|
||||||
|
setSkip(0);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
setSkip,
|
setSkip,
|
||||||
limit,
|
limit,
|
||||||
|
setLimit,
|
||||||
|
sorting,
|
||||||
|
setSorting,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
debouncedSearchTerm,
|
debouncedSearchTerm,
|
||||||
setSearchTerm,
|
setSearchTerm,
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import type { SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
|
import { getServerSortParams } from '@/components/data-table/sorting';
|
||||||
import { clientService } from '@/services/api';
|
import { clientService } from '@/services/api';
|
||||||
import type { ClientListParams } from '@/types';
|
import type { ClientListParams } from '@/types';
|
||||||
import { clientKeys } from '../queries/clientKeys';
|
import { clientKeys } from '../queries/clientKeys';
|
||||||
@@ -13,6 +15,7 @@ interface UseClientsQueryParams {
|
|||||||
limit: number;
|
limit: number;
|
||||||
searchTerm: string;
|
searchTerm: string;
|
||||||
statusFilter: ClientStatusFilter;
|
statusFilter: ClientStatusFilter;
|
||||||
|
sorting: SortingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildClientListParams({
|
function buildClientListParams({
|
||||||
@@ -20,22 +23,22 @@ function buildClientListParams({
|
|||||||
limit,
|
limit,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
sorting,
|
||||||
}: UseClientsQueryParams): ClientListParams {
|
}: UseClientsQueryParams): ClientListParams {
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
search_term: searchTerm || undefined,
|
search_term: searchTerm || undefined,
|
||||||
is_active: statusFilter === 'all' ? undefined : statusFilter === 'active',
|
is_active: statusFilter === 'all' ? undefined : statusFilter === 'active',
|
||||||
sort_by: 'created_at',
|
...getServerSortParams(sorting),
|
||||||
sort_order: 'desc',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useClientsQuery(params: UseClientsQueryParams) {
|
export function useClientsQuery(params: UseClientsQueryParams) {
|
||||||
const { skip, limit, searchTerm, statusFilter } = params;
|
const { skip, limit, searchTerm, statusFilter, sorting } = params;
|
||||||
const listParams = useMemo(
|
const listParams = useMemo(
|
||||||
() => buildClientListParams({ skip, limit, searchTerm, statusFilter }),
|
() => buildClientListParams({ skip, limit, searchTerm, statusFilter, sorting }),
|
||||||
[limit, searchTerm, skip, statusFilter],
|
[limit, searchTerm, skip, sorting, statusFilter],
|
||||||
);
|
);
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ export default function ClientsPage() {
|
|||||||
skip,
|
skip,
|
||||||
setSkip,
|
setSkip,
|
||||||
limit,
|
limit,
|
||||||
|
setLimit,
|
||||||
|
sorting,
|
||||||
|
setSorting,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
debouncedSearchTerm,
|
debouncedSearchTerm,
|
||||||
setSearchTerm,
|
setSearchTerm,
|
||||||
@@ -37,6 +40,7 @@ export default function ClientsPage() {
|
|||||||
limit,
|
limit,
|
||||||
searchTerm: debouncedSearchTerm,
|
searchTerm: debouncedSearchTerm,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
sorting,
|
||||||
});
|
});
|
||||||
const clientForm = useClientForm({
|
const clientForm = useClientForm({
|
||||||
onSaved: () => setIsSheetOpen(false),
|
onSaved: () => setIsSheetOpen(false),
|
||||||
@@ -111,7 +115,10 @@ export default function ClientsPage() {
|
|||||||
skip={skip}
|
skip={skip}
|
||||||
limit={limit}
|
limit={limit}
|
||||||
total={total}
|
total={total}
|
||||||
|
sorting={sorting}
|
||||||
onPageChange={setSkip}
|
onPageChange={setSkip}
|
||||||
|
onLimitChange={setLimit}
|
||||||
|
onSortingChange={setSorting}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<PoweredBy />
|
<PoweredBy />
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ export function usePlanColumns({
|
|||||||
{
|
{
|
||||||
id: 'limits',
|
id: 'limits',
|
||||||
header: 'Limits',
|
header: 'Limits',
|
||||||
|
enableSorting: false,
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="text-xs text-muted-foreground">
|
<div className="text-xs text-muted-foreground">
|
||||||
<p>{row.original.max_projects} projects</p>
|
<p>{row.original.max_projects} projects</p>
|
||||||
@@ -96,6 +97,7 @@ export function usePlanColumns({
|
|||||||
columns.push({
|
columns.push({
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
header: () => <div className="text-right">Actions</div>,
|
header: () => <div className="text-right">Actions</div>,
|
||||||
|
enableSorting: false,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const plan = row.original;
|
const plan = row.original;
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Search } from 'lucide-react';
|
import { TableSearchInput } from '@/components/data-table/TableSearchInput';
|
||||||
|
|
||||||
import { Input } from '@/components/ui/input';
|
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -27,15 +25,12 @@ export function PlanFilters({
|
|||||||
}: PlanFiltersProps) {
|
}: PlanFiltersProps) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-center">
|
||||||
<div className="relative w-full sm:w-72">
|
<TableSearchInput
|
||||||
<Search className="pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-muted-foreground" />
|
value={searchTerm}
|
||||||
<Input
|
onChange={onSearchChange}
|
||||||
value={searchTerm}
|
placeholder="Search plans"
|
||||||
onChange={(event) => onSearchChange(event.target.value)}
|
className="w-full sm:w-72"
|
||||||
placeholder="Search plans"
|
/>
|
||||||
className="pl-9"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<Select value={statusFilter} onValueChange={(value) => onStatusChange(value as PlanStatusFilter)}>
|
<Select value={statusFilter} onValueChange={(value) => onStatusChange(value as PlanStatusFilter)}>
|
||||||
<SelectTrigger className="w-full sm:w-40">
|
<SelectTrigger className="w-full sm:w-40">
|
||||||
<SelectValue placeholder="Status" />
|
<SelectValue placeholder="Status" />
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import type { ColumnDef } from '@tanstack/react-table';
|
import type { ColumnDef, SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
import { DataTable } from '@/components/data-table';
|
import { DataTable } from '@/components/data-table';
|
||||||
import type { Plan } from '@/types';
|
import type { Plan } from '@/types';
|
||||||
@@ -14,7 +14,10 @@ interface PlanTableProps {
|
|||||||
skip: number;
|
skip: number;
|
||||||
limit: number;
|
limit: number;
|
||||||
total: number;
|
total: number;
|
||||||
|
sorting: SortingState;
|
||||||
onPageChange: (skip: number) => void;
|
onPageChange: (skip: number) => void;
|
||||||
|
onLimitChange: (limit: number) => void;
|
||||||
|
onSortingChange: (sorting: SortingState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function PlanTable({
|
export function PlanTable({
|
||||||
@@ -25,7 +28,10 @@ export function PlanTable({
|
|||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
total,
|
total,
|
||||||
|
sorting,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
|
onLimitChange,
|
||||||
|
onSortingChange,
|
||||||
}: PlanTableProps) {
|
}: PlanTableProps) {
|
||||||
return (
|
return (
|
||||||
<DataTable
|
<DataTable
|
||||||
@@ -40,8 +46,10 @@ export function PlanTable({
|
|||||||
limit,
|
limit,
|
||||||
totalItems: total,
|
totalItems: total,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onLimitChange: () => undefined,
|
onLimitChange,
|
||||||
}}
|
}}
|
||||||
|
sorting={sorting}
|
||||||
|
onSortingChange={onSortingChange}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
import type { SortingState } from '@tanstack/react-table';
|
||||||
import { useDebounce } from '@/hooks/useDebounce';
|
import { useDebounce } from '@/hooks/useDebounce';
|
||||||
|
|
||||||
export type PlanStatusFilter = 'all' | 'active' | 'inactive';
|
export type PlanStatusFilter = 'all' | 'active' | 'inactive';
|
||||||
|
|
||||||
export function usePlanFilters() {
|
export function usePlanFilters() {
|
||||||
const [skip, setSkip] = useState(0);
|
const [skip, setSkip] = useState(0);
|
||||||
const [limit] = useState(10);
|
const [limit, setLimitValue] = useState(10);
|
||||||
|
const [sorting, setSortingValue] = useState<SortingState>([]);
|
||||||
const [searchTerm, setSearchTerm] = useState('');
|
const [searchTerm, setSearchTerm] = useState('');
|
||||||
const [statusFilter, setStatusFilter] = useState<PlanStatusFilter>('all');
|
const [statusFilter, setStatusFilter] = useState<PlanStatusFilter>('all');
|
||||||
const debouncedSearchTerm = useDebounce(searchTerm, 400);
|
const debouncedSearchTerm = useDebounce(searchTerm, 400);
|
||||||
@@ -22,10 +24,23 @@ export function usePlanFilters() {
|
|||||||
setSkip(0);
|
setSkip(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setLimit = (value: number) => {
|
||||||
|
setLimitValue(value);
|
||||||
|
setSkip(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const setSorting = (value: SortingState) => {
|
||||||
|
setSortingValue(value);
|
||||||
|
setSkip(0);
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
setSkip,
|
setSkip,
|
||||||
limit,
|
limit,
|
||||||
|
setLimit,
|
||||||
|
sorting,
|
||||||
|
setSorting,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
debouncedSearchTerm,
|
debouncedSearchTerm,
|
||||||
setSearchTerm: updateSearchTerm,
|
setSearchTerm: updateSearchTerm,
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import type { SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
|
import { getServerSortParams } from '@/components/data-table/sorting';
|
||||||
import { mapPermissionTree } from '@/components/permission-tree';
|
import { mapPermissionTree } from '@/components/permission-tree';
|
||||||
import { permissionService, planService } from '@/services/api';
|
import { permissionService, planService } from '@/services/api';
|
||||||
import type { PlanListParams } from '@/types';
|
import type { PlanListParams } from '@/types';
|
||||||
@@ -15,6 +17,7 @@ interface UsePlansQueryParams {
|
|||||||
limit: number;
|
limit: number;
|
||||||
searchTerm: string;
|
searchTerm: string;
|
||||||
statusFilter: PlanStatusFilter;
|
statusFilter: PlanStatusFilter;
|
||||||
|
sorting: SortingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildPlanListParams({
|
function buildPlanListParams({
|
||||||
@@ -22,14 +25,14 @@ function buildPlanListParams({
|
|||||||
limit,
|
limit,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
sorting,
|
||||||
}: UsePlansQueryParams): PlanListParams {
|
}: UsePlansQueryParams): PlanListParams {
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
search_term: searchTerm || undefined,
|
search_term: searchTerm || undefined,
|
||||||
is_active: statusFilter === 'all' ? undefined : statusFilter === 'active',
|
is_active: statusFilter === 'all' ? undefined : statusFilter === 'active',
|
||||||
sort_by: 'created_at',
|
...getServerSortParams(sorting),
|
||||||
sort_order: 'desc',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ export default function PlansPage() {
|
|||||||
skip,
|
skip,
|
||||||
setSkip,
|
setSkip,
|
||||||
limit,
|
limit,
|
||||||
|
setLimit,
|
||||||
|
sorting,
|
||||||
|
setSorting,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
debouncedSearchTerm,
|
debouncedSearchTerm,
|
||||||
setSearchTerm,
|
setSearchTerm,
|
||||||
@@ -39,6 +42,7 @@ export default function PlansPage() {
|
|||||||
limit,
|
limit,
|
||||||
searchTerm: debouncedSearchTerm,
|
searchTerm: debouncedSearchTerm,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
sorting,
|
||||||
});
|
});
|
||||||
const permissionsQuery = useOrganizationPermissionTreeQuery(isSheetOpen);
|
const permissionsQuery = useOrganizationPermissionTreeQuery(isSheetOpen);
|
||||||
|
|
||||||
@@ -165,7 +169,10 @@ export default function PlansPage() {
|
|||||||
skip={skip}
|
skip={skip}
|
||||||
limit={limit}
|
limit={limit}
|
||||||
total={total}
|
total={total}
|
||||||
|
sorting={sorting}
|
||||||
onPageChange={setSkip}
|
onPageChange={setSkip}
|
||||||
|
onLimitChange={setLimit}
|
||||||
|
onSortingChange={setSorting}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<PoweredBy />
|
<PoweredBy />
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ export function useRoleColumns({
|
|||||||
columns.push({
|
columns.push({
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
header: () => <div className="text-right">Actions</div>,
|
header: () => <div className="text-right">Actions</div>,
|
||||||
|
enableSorting: false,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const role = row.original;
|
const role = row.original;
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Input } from '@/components/ui/input';
|
import { TableSearchInput } from '@/components/data-table/TableSearchInput';
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -26,11 +26,10 @@ export function RoleFilters({
|
|||||||
}: RoleFiltersProps) {
|
}: RoleFiltersProps) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
||||||
<Input
|
<TableSearchInput
|
||||||
value={searchTerm}
|
value={searchTerm}
|
||||||
onChange={(event) => onSearchChange(event.target.value)}
|
onChange={onSearchChange}
|
||||||
placeholder="Search roles"
|
placeholder="Search roles"
|
||||||
className="md:max-w-sm"
|
|
||||||
/>
|
/>
|
||||||
<Select value={statusFilter} onValueChange={(value) => onStatusChange(value as StatusFilter)}>
|
<Select value={statusFilter} onValueChange={(value) => onStatusChange(value as StatusFilter)}>
|
||||||
<SelectTrigger className="md:w-44">
|
<SelectTrigger className="md:w-44">
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { Input } from '@/components/ui/input';
|
|||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import {
|
import {
|
||||||
Sheet,
|
Sheet,
|
||||||
|
SheetClose,
|
||||||
SheetContent,
|
SheetContent,
|
||||||
SheetDescription,
|
SheetDescription,
|
||||||
SheetFooter,
|
SheetFooter,
|
||||||
@@ -47,76 +48,79 @@ export function RoleSheet({
|
|||||||
}: RoleSheetProps) {
|
}: RoleSheetProps) {
|
||||||
return (
|
return (
|
||||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||||
<SheetContent className="w-full overflow-y-auto sm:max-w-2xl">
|
<SheetContent
|
||||||
<SheetHeader>
|
side="right"
|
||||||
|
className="flex h-full flex-col gap-0 p-0 sm:max-w-3xl lg:max-w-2xl"
|
||||||
|
>
|
||||||
|
<SheetHeader className="shrink-0 border-b px-6 py-4">
|
||||||
<SheetTitle>{roleId ? 'Edit Role' : 'Create Role'}</SheetTitle>
|
<SheetTitle>{roleId ? 'Edit Role' : 'Create Role'}</SheetTitle>
|
||||||
<SheetDescription>
|
<SheetDescription>
|
||||||
Assign the role details and permission access for this organization.
|
Assign the role details and permission access for this organization.
|
||||||
</SheetDescription>
|
</SheetDescription>
|
||||||
</SheetHeader>
|
</SheetHeader>
|
||||||
<form onSubmit={onSubmit} className="flex flex-1 flex-col gap-5 px-4">
|
|
||||||
<div className="grid gap-4 md:grid-cols-2">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label htmlFor="role-name">Role Name</Label>
|
|
||||||
<Input
|
|
||||||
id="role-name"
|
|
||||||
placeholder="Enter role name"
|
|
||||||
{...register('name', { required: true })}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label htmlFor="role-display-name">Display Name</Label>
|
|
||||||
<Input
|
|
||||||
id="role-display-name"
|
|
||||||
placeholder="Enter display name"
|
|
||||||
{...register('display_name', { required: true })}
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
<form onSubmit={onSubmit} className="flex min-h-0 flex-1 flex-col">
|
||||||
<Label htmlFor="role-description">Description</Label>
|
<div className="flex-1 space-y-5 overflow-y-auto px-6 py-4">
|
||||||
<textarea
|
<div className="grid gap-4 md:grid-cols-2">
|
||||||
id="role-description"
|
<div className="space-y-2">
|
||||||
placeholder="Describe this role"
|
<Label htmlFor="role-name">Role Name</Label>
|
||||||
{...register('description')}
|
<Input
|
||||||
className="min-h-24 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
id="role-name"
|
||||||
/>
|
placeholder="Enter role name"
|
||||||
</div>
|
{...register('name', { required: true })}
|
||||||
|
required
|
||||||
<div className="space-y-3">
|
/>
|
||||||
<div className="flex items-center justify-between gap-3">
|
|
||||||
<Label>Permissions</Label>
|
|
||||||
<span className="text-xs text-muted-foreground">{permissionIds.length} selected</span>
|
|
||||||
</div>
|
|
||||||
{isPermissionsLoading ? (
|
|
||||||
<div className="rounded-md border p-6 text-sm text-muted-foreground">
|
|
||||||
Loading permissions...
|
|
||||||
</div>
|
</div>
|
||||||
) : (
|
<div className="space-y-2">
|
||||||
<PermissionTree
|
<Label htmlFor="role-display-name">Display Name</Label>
|
||||||
items={permissionTree}
|
<Input
|
||||||
selectedIds={permissionIds}
|
id="role-display-name"
|
||||||
onChange={onPermissionIdsChange}
|
placeholder="Enter display name"
|
||||||
|
{...register('display_name', { required: true })}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="role-description">Description</Label>
|
||||||
|
<textarea
|
||||||
|
id="role-description"
|
||||||
|
placeholder="Describe this role"
|
||||||
|
{...register('description')}
|
||||||
|
className="min-h-24 w-full rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
|
||||||
/>
|
/>
|
||||||
)}
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-3">
|
||||||
|
<div className="flex items-center justify-between gap-3">
|
||||||
|
<Label>Permissions</Label>
|
||||||
|
<span className="text-xs text-muted-foreground">{permissionIds.length} selected</span>
|
||||||
|
</div>
|
||||||
|
{isPermissionsLoading ? (
|
||||||
|
<div className="rounded-md border p-6 text-sm text-muted-foreground">
|
||||||
|
Loading permissions...
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<PermissionTree
|
||||||
|
items={permissionTree}
|
||||||
|
selectedIds={permissionIds}
|
||||||
|
onChange={onPermissionIdsChange}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<SheetFooter className="px-0">
|
<SheetFooter className="shrink-0 border-t px-6 py-4 sm:flex-row sm:justify-end">
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="outline"
|
|
||||||
onClick={() => onOpenChange(false)}
|
|
||||||
disabled={isSaving}
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</Button>
|
|
||||||
<Button type="submit" disabled={isSaving}>
|
<Button type="submit" disabled={isSaving}>
|
||||||
{isSaving ? <Loader2 className="mr-2 size-4 animate-spin" /> : null}
|
{isSaving ? <Loader2 className="mr-2 size-4 animate-spin" /> : null}
|
||||||
{roleId ? 'Update Role' : 'Create Role'}
|
{roleId ? 'Update Role' : 'Create Role'}
|
||||||
</Button>
|
</Button>
|
||||||
|
<SheetClose asChild>
|
||||||
|
<Button type="button" variant="outline" disabled={isSaving}>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</SheetClose>
|
||||||
</SheetFooter>
|
</SheetFooter>
|
||||||
</form>
|
</form>
|
||||||
</SheetContent>
|
</SheetContent>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import type { ColumnDef } from '@tanstack/react-table';
|
import type { ColumnDef, SortingState } from '@tanstack/react-table';
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
|
|
||||||
import { DataTable } from '@/components/data-table';
|
import { DataTable } from '@/components/data-table';
|
||||||
@@ -14,7 +14,10 @@ interface RoleTableProps {
|
|||||||
skip: number;
|
skip: number;
|
||||||
limit: number;
|
limit: number;
|
||||||
total: number;
|
total: number;
|
||||||
|
sorting: SortingState;
|
||||||
onPageChange: (skip: number) => void;
|
onPageChange: (skip: number) => void;
|
||||||
|
onLimitChange: (limit: number) => void;
|
||||||
|
onSortingChange: (sorting: SortingState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RoleTable({
|
export function RoleTable({
|
||||||
@@ -25,7 +28,10 @@ export function RoleTable({
|
|||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
total,
|
total,
|
||||||
|
sorting,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
|
onLimitChange,
|
||||||
|
onSortingChange,
|
||||||
}: RoleTableProps) {
|
}: RoleTableProps) {
|
||||||
return (
|
return (
|
||||||
<DataTable
|
<DataTable
|
||||||
@@ -40,8 +46,10 @@ export function RoleTable({
|
|||||||
limit,
|
limit,
|
||||||
totalItems: total,
|
totalItems: total,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onLimitChange: () => undefined,
|
onLimitChange,
|
||||||
}}
|
}}
|
||||||
|
sorting={sorting}
|
||||||
|
onSortingChange={onSortingChange}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
|
import type { SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
export type StatusFilter = 'all' | 'active' | 'inactive';
|
export type StatusFilter = 'all' | 'active' | 'inactive';
|
||||||
|
|
||||||
@@ -8,7 +9,8 @@ const SEARCH_DEBOUNCE_MS = 400;
|
|||||||
|
|
||||||
export function useRoleFilters() {
|
export function useRoleFilters() {
|
||||||
const [skip, setSkip] = useState(0);
|
const [skip, setSkip] = useState(0);
|
||||||
const [limit] = useState(10);
|
const [limit, setLimitValue] = useState(10);
|
||||||
|
const [sorting, setSortingValue] = useState<SortingState>([]);
|
||||||
const [searchTerm, setSearchTermValue] = useState('');
|
const [searchTerm, setSearchTermValue] = useState('');
|
||||||
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState('');
|
const [debouncedSearchTerm, setDebouncedSearchTerm] = useState('');
|
||||||
const [statusFilter, setStatusFilterValue] = useState<StatusFilter>('all');
|
const [statusFilter, setStatusFilterValue] = useState<StatusFilter>('all');
|
||||||
@@ -31,10 +33,23 @@ export function useRoleFilters() {
|
|||||||
setSkip(0);
|
setSkip(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const setLimit = (value: number) => {
|
||||||
|
setLimitValue(value);
|
||||||
|
setSkip(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
const setSorting = (value: SortingState) => {
|
||||||
|
setSortingValue(value);
|
||||||
|
setSkip(0);
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
setSkip,
|
setSkip,
|
||||||
limit,
|
limit,
|
||||||
|
setLimit,
|
||||||
|
sorting,
|
||||||
|
setSorting,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
debouncedSearchTerm,
|
debouncedSearchTerm,
|
||||||
setSearchTerm,
|
setSearchTerm,
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
|
import type { SortingState } from '@tanstack/react-table';
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
|
import { getServerSortParams } from '@/components/data-table/sorting';
|
||||||
import { mapPermissionTree } from '@/components/permission-tree';
|
import { mapPermissionTree } from '@/components/permission-tree';
|
||||||
import { permissionService, roleService } from '@/services/api';
|
import { permissionService, roleService } from '@/services/api';
|
||||||
import type { Role, RoleListParams } from '@/types';
|
import type { Role, RoleListParams } from '@/types';
|
||||||
@@ -16,6 +18,7 @@ interface UseRolesQueryParams {
|
|||||||
limit: number;
|
limit: number;
|
||||||
searchTerm: string;
|
searchTerm: string;
|
||||||
statusFilter: StatusFilter;
|
statusFilter: StatusFilter;
|
||||||
|
sorting: SortingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildRoleListParams({
|
function buildRoleListParams({
|
||||||
@@ -23,22 +26,22 @@ function buildRoleListParams({
|
|||||||
limit,
|
limit,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
sorting,
|
||||||
}: UseRolesQueryParams): RoleListParams {
|
}: UseRolesQueryParams): RoleListParams {
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
search_term: searchTerm || undefined,
|
search_term: searchTerm || undefined,
|
||||||
effective_status: statusFilter === 'all' ? undefined : statusFilter === 'active',
|
effective_status: statusFilter === 'all' ? undefined : statusFilter === 'active',
|
||||||
sort_by: 'created_at',
|
...getServerSortParams(sorting),
|
||||||
sort_order: 'desc',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useRolesQuery(params: UseRolesQueryParams) {
|
export function useRolesQuery(params: UseRolesQueryParams) {
|
||||||
const { skip, limit, searchTerm, statusFilter } = params;
|
const { skip, limit, searchTerm, statusFilter, sorting } = params;
|
||||||
const listParams = useMemo(
|
const listParams = useMemo(
|
||||||
() => buildRoleListParams({ skip, limit, searchTerm, statusFilter }),
|
() => buildRoleListParams({ skip, limit, searchTerm, statusFilter, sorting }),
|
||||||
[limit, searchTerm, skip, statusFilter],
|
[limit, searchTerm, skip, sorting, statusFilter],
|
||||||
);
|
);
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ export default function RolesPage() {
|
|||||||
skip,
|
skip,
|
||||||
setSkip,
|
setSkip,
|
||||||
limit,
|
limit,
|
||||||
|
setLimit,
|
||||||
|
sorting,
|
||||||
|
setSorting,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
debouncedSearchTerm,
|
debouncedSearchTerm,
|
||||||
setSearchTerm,
|
setSearchTerm,
|
||||||
@@ -42,6 +45,7 @@ export default function RolesPage() {
|
|||||||
limit,
|
limit,
|
||||||
searchTerm: debouncedSearchTerm,
|
searchTerm: debouncedSearchTerm,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
sorting,
|
||||||
});
|
});
|
||||||
const permissionsQuery = usePermissionsTreeQuery(isSheetOpen);
|
const permissionsQuery = usePermissionsTreeQuery(isSheetOpen);
|
||||||
const roleForm = useRoleForm({
|
const roleForm = useRoleForm({
|
||||||
@@ -108,8 +112,8 @@ export default function RolesPage() {
|
|||||||
icon={ShieldCheck}
|
icon={ShieldCheck}
|
||||||
actions={
|
actions={
|
||||||
<PermissionGuard permissions={PERMISSIONS.ROLE.CREATE}>
|
<PermissionGuard permissions={PERMISSIONS.ROLE.CREATE}>
|
||||||
<Button onClick={openCreate}>
|
<Button onClick={openCreate} size="sm">
|
||||||
<Plus className="mr-2 size-4" />
|
<Plus />
|
||||||
Add Role
|
Add Role
|
||||||
</Button>
|
</Button>
|
||||||
</PermissionGuard>
|
</PermissionGuard>
|
||||||
@@ -124,7 +128,10 @@ export default function RolesPage() {
|
|||||||
skip={skip}
|
skip={skip}
|
||||||
limit={limit}
|
limit={limit}
|
||||||
total={total}
|
total={total}
|
||||||
|
sorting={sorting}
|
||||||
onPageChange={setSkip}
|
onPageChange={setSkip}
|
||||||
|
onLimitChange={setLimit}
|
||||||
|
onSortingChange={setSorting}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<PoweredBy />
|
<PoweredBy />
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ export function useTenantColumns({
|
|||||||
columns.push({
|
columns.push({
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
header: () => <div className="text-right">Actions</div>,
|
header: () => <div className="text-right">Actions</div>,
|
||||||
|
enableSorting: false,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const tenant = row.original;
|
const tenant = row.original;
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Input } from '@/components/ui/input';
|
import { TableSearchInput } from '@/components/data-table/TableSearchInput';
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -25,11 +25,10 @@ export function TenantFilters({
|
|||||||
}: TenantFiltersProps) {
|
}: TenantFiltersProps) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
||||||
<Input
|
<TableSearchInput
|
||||||
value={searchTerm}
|
value={searchTerm}
|
||||||
onChange={(event) => onSearchChange(event.target.value)}
|
onChange={onSearchChange}
|
||||||
placeholder="Search tenants"
|
placeholder="Search tenants"
|
||||||
className="md:max-w-sm"
|
|
||||||
/>
|
/>
|
||||||
<Select
|
<Select
|
||||||
value={statusFilter}
|
value={statusFilter}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import type { ColumnDef } from '@tanstack/react-table';
|
import type { ColumnDef, SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
import { DataTable } from '@/components/data-table';
|
import { DataTable } from '@/components/data-table';
|
||||||
import type { Tenant } from '@/types';
|
import type { Tenant } from '@/types';
|
||||||
@@ -14,7 +14,10 @@ interface TenantTableProps {
|
|||||||
skip: number;
|
skip: number;
|
||||||
limit: number;
|
limit: number;
|
||||||
total: number;
|
total: number;
|
||||||
|
sorting: SortingState;
|
||||||
onPageChange: (skip: number) => void;
|
onPageChange: (skip: number) => void;
|
||||||
|
onLimitChange: (limit: number) => void;
|
||||||
|
onSortingChange: (sorting: SortingState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TenantTable({
|
export function TenantTable({
|
||||||
@@ -25,7 +28,10 @@ export function TenantTable({
|
|||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
total,
|
total,
|
||||||
|
sorting,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
|
onLimitChange,
|
||||||
|
onSortingChange,
|
||||||
}: TenantTableProps) {
|
}: TenantTableProps) {
|
||||||
return (
|
return (
|
||||||
<DataTable
|
<DataTable
|
||||||
@@ -40,8 +46,10 @@ export function TenantTable({
|
|||||||
limit,
|
limit,
|
||||||
totalItems: total,
|
totalItems: total,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onLimitChange: () => undefined,
|
onLimitChange,
|
||||||
}}
|
}}
|
||||||
|
sorting={sorting}
|
||||||
|
onSortingChange={onSortingChange}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
import type { SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
import { useDebounce } from '@/hooks/useDebounce';
|
import { useDebounce } from '@/hooks/useDebounce';
|
||||||
|
|
||||||
@@ -8,7 +9,8 @@ export type TenantStatusFilter = 'all' | 'active' | 'inactive';
|
|||||||
|
|
||||||
export function useTenantFilters() {
|
export function useTenantFilters() {
|
||||||
const [skip, setSkip] = useState(0);
|
const [skip, setSkip] = useState(0);
|
||||||
const [limit] = useState(10);
|
const [limit, setLimitValue] = useState(10);
|
||||||
|
const [sorting, setSortingValue] = useState<SortingState>([]);
|
||||||
const [searchTerm, setSearchTermValue] = useState('');
|
const [searchTerm, setSearchTermValue] = useState('');
|
||||||
const [statusFilter, setStatusFilterValue] = useState<TenantStatusFilter>('all');
|
const [statusFilter, setStatusFilterValue] = useState<TenantStatusFilter>('all');
|
||||||
const debouncedSearchTerm = useDebounce(searchTerm.trim(), 400);
|
const debouncedSearchTerm = useDebounce(searchTerm.trim(), 400);
|
||||||
@@ -23,10 +25,23 @@ export function useTenantFilters() {
|
|||||||
setSkip(0);
|
setSkip(0);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const setLimit = useCallback((value: number) => {
|
||||||
|
setLimitValue(value);
|
||||||
|
setSkip(0);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const setSorting = useCallback((value: SortingState) => {
|
||||||
|
setSortingValue(value);
|
||||||
|
setSkip(0);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
setSkip,
|
setSkip,
|
||||||
limit,
|
limit,
|
||||||
|
setLimit,
|
||||||
|
sorting,
|
||||||
|
setSorting,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
debouncedSearchTerm,
|
debouncedSearchTerm,
|
||||||
setSearchTerm,
|
setSearchTerm,
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import type { SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
|
import { getServerSortParams } from '@/components/data-table/sorting';
|
||||||
import { clientService, planService, tenantService } from '@/services/api';
|
import { clientService, planService, tenantService } from '@/services/api';
|
||||||
import type { TenantListParams } from '@/types';
|
import type { TenantListParams } from '@/types';
|
||||||
|
|
||||||
@@ -14,6 +16,7 @@ interface UseTenantsQueryParams {
|
|||||||
limit: number;
|
limit: number;
|
||||||
searchTerm: string;
|
searchTerm: string;
|
||||||
statusFilter: TenantStatusFilter;
|
statusFilter: TenantStatusFilter;
|
||||||
|
sorting: SortingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientLookupParams = {
|
const clientLookupParams = {
|
||||||
@@ -37,14 +40,14 @@ function buildTenantListParams({
|
|||||||
limit,
|
limit,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
sorting,
|
||||||
}: UseTenantsQueryParams): TenantListParams {
|
}: UseTenantsQueryParams): TenantListParams {
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
search_term: searchTerm || undefined,
|
search_term: searchTerm || undefined,
|
||||||
is_active: statusFilter === 'all' ? undefined : statusFilter === 'active',
|
is_active: statusFilter === 'all' ? undefined : statusFilter === 'active',
|
||||||
sort_by: 'created_at',
|
...getServerSortParams(sorting),
|
||||||
sort_order: 'desc',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ export default function TenantsPage() {
|
|||||||
skip,
|
skip,
|
||||||
setSkip,
|
setSkip,
|
||||||
limit,
|
limit,
|
||||||
|
setLimit,
|
||||||
|
sorting,
|
||||||
|
setSorting,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
debouncedSearchTerm,
|
debouncedSearchTerm,
|
||||||
setSearchTerm,
|
setSearchTerm,
|
||||||
@@ -42,6 +45,7 @@ export default function TenantsPage() {
|
|||||||
limit,
|
limit,
|
||||||
searchTerm: debouncedSearchTerm,
|
searchTerm: debouncedSearchTerm,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
sorting,
|
||||||
});
|
});
|
||||||
const clientsLookupQuery = useClientLookupQuery(isSheetOpen);
|
const clientsLookupQuery = useClientLookupQuery(isSheetOpen);
|
||||||
const plansLookupQuery = usePlanLookupQuery(isSheetOpen);
|
const plansLookupQuery = usePlanLookupQuery(isSheetOpen);
|
||||||
@@ -162,7 +166,10 @@ export default function TenantsPage() {
|
|||||||
skip={skip}
|
skip={skip}
|
||||||
limit={limit}
|
limit={limit}
|
||||||
total={total}
|
total={total}
|
||||||
|
sorting={sorting}
|
||||||
onPageChange={setSkip}
|
onPageChange={setSkip}
|
||||||
|
onLimitChange={setLimit}
|
||||||
|
onSortingChange={setSorting}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<PoweredBy />
|
<PoweredBy />
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ export function useUserColumns({
|
|||||||
{
|
{
|
||||||
accessorKey: 'roles',
|
accessorKey: 'roles',
|
||||||
header: 'Roles',
|
header: 'Roles',
|
||||||
|
enableSorting: false,
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="flex flex-wrap gap-1">
|
<div className="flex flex-wrap gap-1">
|
||||||
{row.original.roles?.length ? (
|
{row.original.roles?.length ? (
|
||||||
@@ -93,6 +94,7 @@ export function useUserColumns({
|
|||||||
columns.push({
|
columns.push({
|
||||||
id: 'actions',
|
id: 'actions',
|
||||||
header: () => <div className="text-right">Actions</div>,
|
header: () => <div className="text-right">Actions</div>,
|
||||||
|
enableSorting: false,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const user = row.original;
|
const user = row.original;
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Input } from '@/components/ui/input';
|
import { TableSearchInput } from '@/components/data-table/TableSearchInput';
|
||||||
import {
|
import {
|
||||||
Select,
|
Select,
|
||||||
SelectContent,
|
SelectContent,
|
||||||
@@ -25,11 +25,10 @@ export function UserFilters({
|
|||||||
}: UserFiltersProps) {
|
}: UserFiltersProps) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
||||||
<Input
|
<TableSearchInput
|
||||||
value={searchTerm}
|
value={searchTerm}
|
||||||
onChange={(event) => onSearchChange(event.target.value)}
|
onChange={onSearchChange}
|
||||||
placeholder="Search users"
|
placeholder="Search users"
|
||||||
className="md:max-w-sm"
|
|
||||||
/>
|
/>
|
||||||
<Select value={statusFilter} onValueChange={(value) => onStatusChange(value as StatusFilter)}>
|
<Select value={statusFilter} onValueChange={(value) => onStatusChange(value as StatusFilter)}>
|
||||||
<SelectTrigger className="md:w-44">
|
<SelectTrigger className="md:w-44">
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import type { ComponentProps } from 'react';
|
import { useRef, type ComponentProps } from 'react';
|
||||||
|
|
||||||
import type { UseFormRegister } from 'react-hook-form';
|
import type { UseFormRegister } from 'react-hook-form';
|
||||||
|
|
||||||
import { Loader2 } from 'lucide-react';
|
import { Loader2 } from 'lucide-react';
|
||||||
|
|
||||||
|
import { RoleCombobox } from '@/components/lookups/RoleCombobox';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
@@ -13,54 +17,64 @@ import {
|
|||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from '@/components/ui/dialog';
|
} from '@/components/ui/dialog';
|
||||||
|
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
|
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from '@/components/ui/select';
|
|
||||||
import type { Role } from '@/types';
|
|
||||||
import type { UserFormValues } from '../hooks/useUserForm';
|
import type { UserFormValues } from '../hooks/useUserForm';
|
||||||
|
|
||||||
interface UserSheetProps {
|
interface UserSheetProps {
|
||||||
open: boolean;
|
open: boolean;
|
||||||
|
|
||||||
onOpenChange: (open: boolean) => void;
|
onOpenChange: (open: boolean) => void;
|
||||||
|
|
||||||
userId?: number;
|
userId?: number;
|
||||||
|
|
||||||
register: UseFormRegister<UserFormValues>;
|
register: UseFormRegister<UserFormValues>;
|
||||||
|
|
||||||
onSubmit: ComponentProps<'form'>['onSubmit'];
|
onSubmit: ComponentProps<'form'>['onSubmit'];
|
||||||
|
|
||||||
roleId: string;
|
roleId: string;
|
||||||
|
|
||||||
onRoleChange: (roleId: string) => void;
|
onRoleChange: (roleId: string) => void;
|
||||||
roles: Role[];
|
|
||||||
isRolesLoading: boolean;
|
|
||||||
isSaving: boolean;
|
isSaving: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function UserSheet({
|
export function UserSheet({
|
||||||
open,
|
open,
|
||||||
|
|
||||||
onOpenChange,
|
onOpenChange,
|
||||||
|
|
||||||
userId,
|
userId,
|
||||||
|
|
||||||
register,
|
register,
|
||||||
|
|
||||||
onSubmit,
|
onSubmit,
|
||||||
|
|
||||||
roleId,
|
roleId,
|
||||||
|
|
||||||
onRoleChange,
|
onRoleChange,
|
||||||
roles,
|
|
||||||
isRolesLoading,
|
|
||||||
isSaving,
|
isSaving,
|
||||||
}: UserSheetProps) {
|
}: UserSheetProps) {
|
||||||
|
const roleComboboxPortalRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="max-h-[calc(100vh-2rem)] overflow-y-auto sm:max-w-xl">
|
<DialogContent className="max-h-[calc(100vh-2rem)] overflow-y-auto sm:max-w-xl">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>{userId ? 'Edit User' : 'Create User'}</DialogTitle>
|
<DialogTitle>{userId ? 'Edit User' : 'Create User'}</DialogTitle>
|
||||||
|
|
||||||
<DialogDescription>Assign user details and a role.</DialogDescription>
|
<DialogDescription>Assign user details and a role.</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<form onSubmit={onSubmit} className="flex flex-1 flex-col gap-5 px-4">
|
<form onSubmit={onSubmit} className="flex flex-1 flex-col gap-5 px-4">
|
||||||
<div className="grid gap-4 md:grid-cols-2">
|
<div className="grid gap-4 md:grid-cols-2">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="first-name">First Name</Label>
|
<Label htmlFor="first-name">First Name</Label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
id="first-name"
|
id="first-name"
|
||||||
placeholder="Enter first name"
|
placeholder="Enter first name"
|
||||||
@@ -68,8 +82,10 @@ export function UserSheet({
|
|||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="last-name">Last Name</Label>
|
<Label htmlFor="last-name">Last Name</Label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
id="last-name"
|
id="last-name"
|
||||||
placeholder="Enter last name"
|
placeholder="Enter last name"
|
||||||
@@ -81,6 +97,7 @@ export function UserSheet({
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="email">Email</Label>
|
<Label htmlFor="email">Email</Label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
id="email"
|
id="email"
|
||||||
type="email"
|
type="email"
|
||||||
@@ -92,6 +109,7 @@ export function UserSheet({
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="phone-number">Phone Number</Label>
|
<Label htmlFor="phone-number">Phone Number</Label>
|
||||||
|
|
||||||
<Input
|
<Input
|
||||||
id="phone-number"
|
id="phone-number"
|
||||||
placeholder="Enter phone number"
|
placeholder="Enter phone number"
|
||||||
@@ -101,18 +119,17 @@ export function UserSheet({
|
|||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label>Role</Label>
|
<Label>Role</Label>
|
||||||
<Select value={roleId} onValueChange={onRoleChange}>
|
|
||||||
<SelectTrigger>
|
<RoleCombobox
|
||||||
<SelectValue placeholder={isRolesLoading ? 'Loading roles...' : 'Select role'} />
|
value={roleId}
|
||||||
</SelectTrigger>
|
onValueChange={onRoleChange}
|
||||||
<SelectContent>
|
enabled={open}
|
||||||
{roles.map((role) => (
|
disabled={isSaving}
|
||||||
<SelectItem key={role.id} value={String(role.id)}>
|
portalContainer={roleComboboxPortalRef}
|
||||||
{role.display_name || role.name}
|
/>
|
||||||
</SelectItem>
|
|
||||||
))}
|
<div ref={roleComboboxPortalRef} />
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
<input
|
<input
|
||||||
type="hidden"
|
type="hidden"
|
||||||
{...register('role_id', { required: true })}
|
{...register('role_id', { required: true })}
|
||||||
@@ -130,8 +147,10 @@ export function UserSheet({
|
|||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button type="submit" disabled={isSaving}>
|
<Button type="submit" disabled={isSaving}>
|
||||||
{isSaving ? <Loader2 className="mr-2 size-4 animate-spin" /> : null}
|
{isSaving ? <Loader2 className="mr-2 size-4 animate-spin" /> : null}
|
||||||
|
|
||||||
{userId ? 'Update User' : 'Create User'}
|
{userId ? 'Update User' : 'Create User'}
|
||||||
</Button>
|
</Button>
|
||||||
</DialogFooter>
|
</DialogFooter>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import type { ColumnDef } from '@tanstack/react-table';
|
import type { ColumnDef, SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
import { DataTable } from '@/components/data-table';
|
import { DataTable } from '@/components/data-table';
|
||||||
import type { AdministrationUser } from '@/types';
|
import type { AdministrationUser } from '@/types';
|
||||||
@@ -14,7 +14,10 @@ interface UserTableProps {
|
|||||||
skip: number;
|
skip: number;
|
||||||
limit: number;
|
limit: number;
|
||||||
total: number;
|
total: number;
|
||||||
|
sorting: SortingState;
|
||||||
onPageChange: (skip: number) => void;
|
onPageChange: (skip: number) => void;
|
||||||
|
onLimitChange: (limit: number) => void;
|
||||||
|
onSortingChange: (sorting: SortingState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function UserTable({
|
export function UserTable({
|
||||||
@@ -25,7 +28,10 @@ export function UserTable({
|
|||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
total,
|
total,
|
||||||
|
sorting,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
|
onLimitChange,
|
||||||
|
onSortingChange,
|
||||||
}: UserTableProps) {
|
}: UserTableProps) {
|
||||||
return (
|
return (
|
||||||
<DataTable
|
<DataTable
|
||||||
@@ -40,8 +46,10 @@ export function UserTable({
|
|||||||
limit,
|
limit,
|
||||||
totalItems: total,
|
totalItems: total,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onLimitChange: () => undefined,
|
onLimitChange,
|
||||||
}}
|
}}
|
||||||
|
sorting={sorting}
|
||||||
|
onSortingChange={onSortingChange}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,15 @@
|
|||||||
|
|
||||||
import { useDebounce } from '@/hooks/useDebounce';
|
import { useDebounce } from '@/hooks/useDebounce';
|
||||||
import type { UserStatus } from '@/types';
|
import type { UserStatus } from '@/types';
|
||||||
|
import type { SortingState } from '@tanstack/react-table';
|
||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
|
|
||||||
export type StatusFilter = 'all' | UserStatus;
|
export type StatusFilter = 'all' | UserStatus;
|
||||||
|
|
||||||
export function useUserFilters() {
|
export function useUserFilters() {
|
||||||
const [skip, setSkip] = useState(0);
|
const [skip, setSkip] = useState(0);
|
||||||
const [limit] = useState(10);
|
const [limit, setLimitValue] = useState(10);
|
||||||
|
const [sorting, setSortingValue] = useState<SortingState>([]);
|
||||||
const [searchTerm, setSearchTermValue] = useState('');
|
const [searchTerm, setSearchTermValue] = useState('');
|
||||||
const [statusFilter, setStatusFilterValue] = useState<StatusFilter>('all');
|
const [statusFilter, setStatusFilterValue] = useState<StatusFilter>('all');
|
||||||
const debouncedSearchTerm = useDebounce(searchTerm.trim(), 400);
|
const debouncedSearchTerm = useDebounce(searchTerm.trim(), 400);
|
||||||
@@ -23,10 +25,23 @@ export function useUserFilters() {
|
|||||||
setSkip(0);
|
setSkip(0);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const setLimit = useCallback((value: number) => {
|
||||||
|
setLimitValue(value);
|
||||||
|
setSkip(0);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const setSorting = useCallback((value: SortingState) => {
|
||||||
|
setSortingValue(value);
|
||||||
|
setSkip(0);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
setSkip,
|
setSkip,
|
||||||
limit,
|
limit,
|
||||||
|
setLimit,
|
||||||
|
sorting,
|
||||||
|
setSorting,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
debouncedSearchTerm,
|
debouncedSearchTerm,
|
||||||
setSearchTerm,
|
setSearchTerm,
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import type { SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
import { roleService, userService } from '@/services/api';
|
import { getServerSortParams } from '@/components/data-table/sorting';
|
||||||
import type { RoleListParams, UserListParams } from '@/types';
|
import { userService } from '@/services/api';
|
||||||
import { roleKeys } from '../../roles/queries/roleKeys';
|
import type { UserListParams } from '@/types';
|
||||||
import { userKeys } from '../queries/userKeys';
|
import { userKeys } from '../queries/userKeys';
|
||||||
import type { StatusFilter } from './useUserFilters';
|
import type { StatusFilter } from './useUserFilters';
|
||||||
|
|
||||||
@@ -14,37 +15,30 @@ interface UseUsersQueryParams {
|
|||||||
limit: number;
|
limit: number;
|
||||||
searchTerm: string;
|
searchTerm: string;
|
||||||
statusFilter: StatusFilter;
|
statusFilter: StatusFilter;
|
||||||
|
sorting: SortingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
const roleLookupParams: RoleListParams = {
|
|
||||||
skip: 0,
|
|
||||||
limit: 100,
|
|
||||||
effective_status: true,
|
|
||||||
sort_by: 'display_name',
|
|
||||||
sort_order: 'asc',
|
|
||||||
};
|
|
||||||
|
|
||||||
function buildUserListParams({
|
function buildUserListParams({
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
sorting,
|
||||||
}: UseUsersQueryParams): UserListParams {
|
}: UseUsersQueryParams): UserListParams {
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
search_term: searchTerm || undefined,
|
search_term: searchTerm || undefined,
|
||||||
effective_status: statusFilter === 'all' ? undefined : statusFilter,
|
effective_status: statusFilter === 'all' ? undefined : statusFilter,
|
||||||
sort_by: 'created_at',
|
...getServerSortParams(sorting),
|
||||||
sort_order: 'desc',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useUsersQuery(params: UseUsersQueryParams) {
|
export function useUsersQuery(params: UseUsersQueryParams) {
|
||||||
const { skip, limit, searchTerm, statusFilter } = params;
|
const { skip, limit, searchTerm, statusFilter, sorting } = params;
|
||||||
const listParams = useMemo(
|
const listParams = useMemo(
|
||||||
() => buildUserListParams({ skip, limit, searchTerm, statusFilter }),
|
() => buildUserListParams({ skip, limit, searchTerm, statusFilter, sorting }),
|
||||||
[limit, searchTerm, skip, statusFilter],
|
[limit, searchTerm, skip, sorting, statusFilter],
|
||||||
);
|
);
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
@@ -52,13 +46,3 @@ export function useUsersQuery(params: UseUsersQueryParams) {
|
|||||||
queryFn: () => userService.getUsers(listParams),
|
queryFn: () => userService.getUsers(listParams),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useRoleLookupQuery(enabled: boolean) {
|
|
||||||
return useQuery({
|
|
||||||
queryKey: roleKeys.list(roleLookupParams),
|
|
||||||
queryFn: () => roleService.getRoles(roleLookupParams),
|
|
||||||
enabled,
|
|
||||||
staleTime: 5 * 60 * 1000,
|
|
||||||
gcTime: 30 * 60 * 1000,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import { UserTable } from './components/UserTable';
|
|||||||
import { useUserFilters } from './hooks/useUserFilters';
|
import { useUserFilters } from './hooks/useUserFilters';
|
||||||
import { useUserForm } from './hooks/useUserForm';
|
import { useUserForm } from './hooks/useUserForm';
|
||||||
import { useUserStatusMutation } from './hooks/useUserMutations';
|
import { useUserStatusMutation } from './hooks/useUserMutations';
|
||||||
import { useRoleLookupQuery, useUsersQuery } from './hooks/useUserQueries';
|
import { useUsersQuery } from './hooks/useUserQueries';
|
||||||
|
|
||||||
export default function UsersPage() {
|
export default function UsersPage() {
|
||||||
const [isSheetOpen, setIsSheetOpen] = useState(false);
|
const [isSheetOpen, setIsSheetOpen] = useState(false);
|
||||||
@@ -26,6 +26,9 @@ export default function UsersPage() {
|
|||||||
skip,
|
skip,
|
||||||
setSkip,
|
setSkip,
|
||||||
limit,
|
limit,
|
||||||
|
setLimit,
|
||||||
|
sorting,
|
||||||
|
setSorting,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
debouncedSearchTerm,
|
debouncedSearchTerm,
|
||||||
setSearchTerm,
|
setSearchTerm,
|
||||||
@@ -38,8 +41,8 @@ export default function UsersPage() {
|
|||||||
limit,
|
limit,
|
||||||
searchTerm: debouncedSearchTerm,
|
searchTerm: debouncedSearchTerm,
|
||||||
statusFilter,
|
statusFilter,
|
||||||
|
sorting,
|
||||||
});
|
});
|
||||||
const rolesQuery = useRoleLookupQuery(isSheetOpen);
|
|
||||||
const userForm = useUserForm({
|
const userForm = useUserForm({
|
||||||
onSaved: () => setIsSheetOpen(false),
|
onSaved: () => setIsSheetOpen(false),
|
||||||
});
|
});
|
||||||
@@ -84,7 +87,6 @@ export default function UsersPage() {
|
|||||||
|
|
||||||
const total = usersQuery.data?.total ?? 0;
|
const total = usersQuery.data?.total ?? 0;
|
||||||
const users = usersQuery.data?.items ?? [];
|
const users = usersQuery.data?.items ?? [];
|
||||||
const roleOptions = rolesQuery.data?.items ?? [];
|
|
||||||
const toolbar = useMemo(
|
const toolbar = useMemo(
|
||||||
() => (
|
() => (
|
||||||
<UserFilters
|
<UserFilters
|
||||||
@@ -106,8 +108,8 @@ export default function UsersPage() {
|
|||||||
icon={Users}
|
icon={Users}
|
||||||
actions={
|
actions={
|
||||||
<PermissionGuard permissions={PERMISSIONS.USER.CREATE}>
|
<PermissionGuard permissions={PERMISSIONS.USER.CREATE}>
|
||||||
<Button onClick={openCreate}>
|
<Button onClick={openCreate} size="sm">
|
||||||
<Plus className="mr-2 size-4" />
|
<Plus />
|
||||||
Add User
|
Add User
|
||||||
</Button>
|
</Button>
|
||||||
</PermissionGuard>
|
</PermissionGuard>
|
||||||
@@ -129,7 +131,10 @@ export default function UsersPage() {
|
|||||||
skip={skip}
|
skip={skip}
|
||||||
limit={limit}
|
limit={limit}
|
||||||
total={total}
|
total={total}
|
||||||
|
sorting={sorting}
|
||||||
onPageChange={setSkip}
|
onPageChange={setSkip}
|
||||||
|
onLimitChange={setLimit}
|
||||||
|
onSortingChange={setSorting}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<PoweredBy />
|
<PoweredBy />
|
||||||
@@ -143,8 +148,6 @@ export default function UsersPage() {
|
|||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
roleId={roleId}
|
roleId={roleId}
|
||||||
onRoleChange={setRoleId}
|
onRoleChange={setRoleId}
|
||||||
roles={roleOptions}
|
|
||||||
isRolesLoading={rolesQuery.isLoading}
|
|
||||||
isSaving={isSaving}
|
isSaving={isSaving}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|||||||
156
src/components/async-combobox/AsyncCombobox.tsx
Normal file
156
src/components/async-combobox/AsyncCombobox.tsx
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useCallback, useRef, useState } from 'react';
|
||||||
|
import { Loader2 } from 'lucide-react';
|
||||||
|
import type { Virtualizer } from '@tanstack/react-virtual';
|
||||||
|
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
Combobox,
|
||||||
|
ComboboxContent,
|
||||||
|
ComboboxEmpty,
|
||||||
|
ComboboxInput,
|
||||||
|
ComboboxList,
|
||||||
|
ComboboxTrigger,
|
||||||
|
ComboboxValue,
|
||||||
|
} from '@/components/ui/combobox';
|
||||||
|
|
||||||
|
import type { AsyncComboboxOption, AsyncComboboxProps } from './AsyncCombobox.types';
|
||||||
|
import { VirtualComboboxList } from './VirtualComboboxList';
|
||||||
|
|
||||||
|
type VirtualizerHandle = Virtualizer<HTMLDivElement, Element>;
|
||||||
|
|
||||||
|
export function AsyncCombobox({
|
||||||
|
lookup,
|
||||||
|
onValueChange,
|
||||||
|
placeholder = 'Select option',
|
||||||
|
searchPlaceholder = 'Search...',
|
||||||
|
emptyMessage = 'No items found.',
|
||||||
|
disabled = false,
|
||||||
|
portalContainer,
|
||||||
|
}: AsyncComboboxProps) {
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
const virtualizerRef = useRef<VirtualizerHandle | null>(null);
|
||||||
|
const {
|
||||||
|
options,
|
||||||
|
selectedOption,
|
||||||
|
search,
|
||||||
|
setSearch,
|
||||||
|
isLoading,
|
||||||
|
isFetchingNextPage,
|
||||||
|
isError,
|
||||||
|
errorMessage,
|
||||||
|
hasNextPage,
|
||||||
|
fetchNextPage,
|
||||||
|
} = lookup;
|
||||||
|
|
||||||
|
const handleOpenChange = useCallback(
|
||||||
|
(nextOpen: boolean) => {
|
||||||
|
setOpen(nextOpen);
|
||||||
|
if (!nextOpen) {
|
||||||
|
setSearch('');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[setSearch],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleValueChange = useCallback(
|
||||||
|
(item: AsyncComboboxOption | null) => {
|
||||||
|
if (item?.value) {
|
||||||
|
onValueChange(item.value);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[onValueChange],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleItemHighlighted = useCallback(
|
||||||
|
(
|
||||||
|
_item: AsyncComboboxOption | undefined,
|
||||||
|
event: { reason: string; index: number },
|
||||||
|
) => {
|
||||||
|
const virtualizer = virtualizerRef.current;
|
||||||
|
if (!virtualizer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { reason, index } = event;
|
||||||
|
const isStart = index === 0;
|
||||||
|
const isEnd = index === virtualizer.options.count - 1;
|
||||||
|
const shouldScroll =
|
||||||
|
reason === 'none' || (reason === 'keyboard' && (isStart || isEnd));
|
||||||
|
|
||||||
|
if (shouldScroll) {
|
||||||
|
queueMicrotask(() => {
|
||||||
|
virtualizer.scrollToIndex(index, { align: isEnd ? 'start' : 'end' });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleLoadMore = useCallback(() => {
|
||||||
|
void fetchNextPage();
|
||||||
|
}, [fetchNextPage]);
|
||||||
|
|
||||||
|
const isDisabled = disabled || isLoading;
|
||||||
|
const triggerPlaceholder = isLoading ? 'Loading...' : placeholder;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Combobox
|
||||||
|
virtualized
|
||||||
|
items={options}
|
||||||
|
value={selectedOption}
|
||||||
|
onValueChange={handleValueChange}
|
||||||
|
open={open}
|
||||||
|
onOpenChange={handleOpenChange}
|
||||||
|
inputValue={search}
|
||||||
|
onInputValueChange={setSearch}
|
||||||
|
filter={null}
|
||||||
|
disabled={isDisabled}
|
||||||
|
itemToStringLabel={(item) => item.label}
|
||||||
|
isItemEqualToValue={(item, currentValue) => item.value === currentValue.value}
|
||||||
|
onItemHighlighted={handleItemHighlighted}
|
||||||
|
>
|
||||||
|
<ComboboxTrigger
|
||||||
|
render={
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
className="w-full justify-between font-normal"
|
||||||
|
disabled={isDisabled}
|
||||||
|
>
|
||||||
|
{isLoading && !selectedOption ? (
|
||||||
|
<span className="flex items-center gap-2 text-muted-foreground">
|
||||||
|
<Loader2 className="size-4 animate-spin" />
|
||||||
|
Loading...
|
||||||
|
</span>
|
||||||
|
) : (
|
||||||
|
<ComboboxValue placeholder={triggerPlaceholder} />
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<ComboboxContent container={portalContainer}>
|
||||||
|
<ComboboxInput showTrigger={false} placeholder={searchPlaceholder} disabled={isDisabled} />
|
||||||
|
{isError ? (
|
||||||
|
<div className="px-3 py-2 text-sm text-destructive">
|
||||||
|
{errorMessage || 'Unable to load options.'}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<ComboboxEmpty>{emptyMessage}</ComboboxEmpty>
|
||||||
|
<ComboboxList className="p-0">
|
||||||
|
<VirtualComboboxList
|
||||||
|
open={open}
|
||||||
|
virtualizerRef={virtualizerRef}
|
||||||
|
hasNextPage={hasNextPage}
|
||||||
|
isFetchingNextPage={isFetchingNextPage}
|
||||||
|
onLoadMore={handleLoadMore}
|
||||||
|
/>
|
||||||
|
</ComboboxList>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ComboboxContent>
|
||||||
|
</Combobox>
|
||||||
|
);
|
||||||
|
}
|
||||||
50
src/components/async-combobox/AsyncCombobox.types.ts
Normal file
50
src/components/async-combobox/AsyncCombobox.types.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import type { RefObject } from 'react';
|
||||||
|
|
||||||
|
export type AsyncComboboxOption = {
|
||||||
|
value: string;
|
||||||
|
label: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PaginatedResult<T> = {
|
||||||
|
items: T[];
|
||||||
|
total: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PaginatedLookupConfig<T> = {
|
||||||
|
enabled?: boolean;
|
||||||
|
pageSize?: number;
|
||||||
|
debounceMs?: number;
|
||||||
|
selectedValue?: string;
|
||||||
|
queryKey: (searchTerm: string) => readonly unknown[];
|
||||||
|
queryFn: (args: {
|
||||||
|
searchTerm: string;
|
||||||
|
skip: number;
|
||||||
|
limit: number;
|
||||||
|
}) => Promise<PaginatedResult<T>>;
|
||||||
|
mapOption: (item: T) => AsyncComboboxOption;
|
||||||
|
resolveSelected?: (value: string) => Promise<T | null>;
|
||||||
|
resolveSelectedQueryKey?: (value: string) => readonly unknown[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface PaginatedLookupState {
|
||||||
|
options: AsyncComboboxOption[];
|
||||||
|
selectedOption: AsyncComboboxOption | null;
|
||||||
|
search: string;
|
||||||
|
setSearch: (value: string) => void;
|
||||||
|
isLoading: boolean;
|
||||||
|
isFetchingNextPage: boolean;
|
||||||
|
isError: boolean;
|
||||||
|
errorMessage?: string;
|
||||||
|
hasNextPage: boolean;
|
||||||
|
fetchNextPage: () => void | Promise<unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface AsyncComboboxProps {
|
||||||
|
lookup: PaginatedLookupState;
|
||||||
|
onValueChange: (value: string) => void;
|
||||||
|
placeholder?: string;
|
||||||
|
searchPlaceholder?: string;
|
||||||
|
emptyMessage?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
portalContainer?: RefObject<HTMLDivElement | null>;
|
||||||
|
}
|
||||||
125
src/components/async-combobox/VirtualComboboxList.tsx
Normal file
125
src/components/async-combobox/VirtualComboboxList.tsx
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useCallback, useEffect, useImperativeHandle, useRef, type RefObject } from 'react';
|
||||||
|
import { Combobox } from '@base-ui/react/combobox';
|
||||||
|
import { useVirtualizer, type Virtualizer } from '@tanstack/react-virtual';
|
||||||
|
import { Loader2 } from 'lucide-react';
|
||||||
|
|
||||||
|
import { ComboboxItem } from '@/components/ui/combobox';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
import type { AsyncComboboxOption } from './AsyncCombobox.types';
|
||||||
|
|
||||||
|
type VirtualizerHandle = Virtualizer<HTMLDivElement, Element>;
|
||||||
|
const LOAD_MORE_THRESHOLD = 3;
|
||||||
|
|
||||||
|
interface VirtualComboboxListProps {
|
||||||
|
open: boolean;
|
||||||
|
virtualizerRef: RefObject<VirtualizerHandle | null>;
|
||||||
|
hasNextPage: boolean;
|
||||||
|
isFetchingNextPage: boolean;
|
||||||
|
onLoadMore: () => void;
|
||||||
|
estimateSize?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function VirtualComboboxList({
|
||||||
|
open,
|
||||||
|
virtualizerRef,
|
||||||
|
hasNextPage,
|
||||||
|
isFetchingNextPage,
|
||||||
|
onLoadMore,
|
||||||
|
estimateSize = 36,
|
||||||
|
}: VirtualComboboxListProps) {
|
||||||
|
const filteredItems = Combobox.useFilteredItems<AsyncComboboxOption>();
|
||||||
|
const scrollElementRef = useRef<HTMLDivElement | null>(null);
|
||||||
|
const itemCount = filteredItems.length + (hasNextPage ? 1 : 0);
|
||||||
|
|
||||||
|
const virtualizer = useVirtualizer({
|
||||||
|
enabled: open,
|
||||||
|
count: itemCount,
|
||||||
|
getScrollElement: () => scrollElementRef.current,
|
||||||
|
estimateSize: () => estimateSize,
|
||||||
|
overscan: 8,
|
||||||
|
paddingStart: 4,
|
||||||
|
paddingEnd: 4,
|
||||||
|
});
|
||||||
|
|
||||||
|
useImperativeHandle(virtualizerRef, () => virtualizer, [virtualizer]);
|
||||||
|
|
||||||
|
const handleScrollElementRef = useCallback(
|
||||||
|
(element: HTMLDivElement | null) => {
|
||||||
|
scrollElementRef.current = element;
|
||||||
|
if (element) {
|
||||||
|
virtualizer.measure();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[virtualizer],
|
||||||
|
);
|
||||||
|
|
||||||
|
const virtualItems = virtualizer.getVirtualItems();
|
||||||
|
const totalSize = virtualizer.getTotalSize();
|
||||||
|
const lastVirtualIndex = virtualItems[virtualItems.length - 1]?.index ?? -1;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (lastVirtualIndex < 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
lastVirtualIndex >= filteredItems.length - LOAD_MORE_THRESHOLD &&
|
||||||
|
hasNextPage &&
|
||||||
|
!isFetchingNextPage
|
||||||
|
) {
|
||||||
|
onLoadMore();
|
||||||
|
}
|
||||||
|
}, [filteredItems.length, hasNextPage, isFetchingNextPage, lastVirtualIndex, onLoadMore]);
|
||||||
|
|
||||||
|
if (!filteredItems.length && !hasNextPage) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={handleScrollElementRef}
|
||||||
|
className={cn(
|
||||||
|
'max-h-[min(21.75rem,calc(var(--available-height)-2.25rem))] overflow-y-auto overscroll-contain p-1',
|
||||||
|
)}
|
||||||
|
style={{ height: Math.min(totalSize + 8, 348) }}
|
||||||
|
>
|
||||||
|
<div className="relative w-full" style={{ height: totalSize }}>
|
||||||
|
{virtualItems.map((virtualItem) => {
|
||||||
|
const isLoaderRow = virtualItem.index >= filteredItems.length;
|
||||||
|
const item = filteredItems[virtualItem.index];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={virtualItem.key}
|
||||||
|
data-index={virtualItem.index}
|
||||||
|
ref={virtualizer.measureElement}
|
||||||
|
className="absolute top-0 left-0 w-full"
|
||||||
|
style={{
|
||||||
|
height: virtualItem.size,
|
||||||
|
transform: `translateY(${virtualItem.start}px)`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{isLoaderRow ? (
|
||||||
|
<div className="flex items-center justify-center py-2 text-muted-foreground">
|
||||||
|
<Loader2 className="size-4 animate-spin" />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<ComboboxItem
|
||||||
|
value={item}
|
||||||
|
index={virtualItem.index}
|
||||||
|
aria-setsize={filteredItems.length}
|
||||||
|
aria-posinset={virtualItem.index + 1}
|
||||||
|
>
|
||||||
|
{item.label}
|
||||||
|
</ComboboxItem>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
9
src/components/async-combobox/index.ts
Normal file
9
src/components/async-combobox/index.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export { AsyncCombobox } from './AsyncCombobox';
|
||||||
|
export { usePaginatedLookup } from './usePaginatedLookup';
|
||||||
|
export type {
|
||||||
|
AsyncComboboxProps,
|
||||||
|
AsyncComboboxOption,
|
||||||
|
PaginatedLookupState,
|
||||||
|
PaginatedLookupConfig,
|
||||||
|
PaginatedResult,
|
||||||
|
} from './AsyncCombobox.types';
|
||||||
94
src/components/async-combobox/usePaginatedLookup.ts
Normal file
94
src/components/async-combobox/usePaginatedLookup.ts
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useMemo, useState } from 'react';
|
||||||
|
import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import { useDebounce } from '@/hooks/useDebounce';
|
||||||
|
|
||||||
|
import type { AsyncComboboxOption, PaginatedLookupConfig } from './AsyncCombobox.types';
|
||||||
|
|
||||||
|
export function usePaginatedLookup<T>({
|
||||||
|
enabled = true,
|
||||||
|
pageSize = 20,
|
||||||
|
debounceMs = 400,
|
||||||
|
selectedValue = '',
|
||||||
|
queryKey,
|
||||||
|
queryFn,
|
||||||
|
mapOption,
|
||||||
|
resolveSelected,
|
||||||
|
resolveSelectedQueryKey,
|
||||||
|
}: PaginatedLookupConfig<T>) {
|
||||||
|
const [search, setSearch] = useState('');
|
||||||
|
const debouncedSearch = useDebounce(search.trim(), debounceMs);
|
||||||
|
|
||||||
|
const infiniteQuery = useInfiniteQuery({
|
||||||
|
queryKey: queryKey(debouncedSearch),
|
||||||
|
queryFn: ({ pageParam }) =>
|
||||||
|
queryFn({
|
||||||
|
searchTerm: debouncedSearch,
|
||||||
|
skip: pageParam,
|
||||||
|
limit: pageSize,
|
||||||
|
}),
|
||||||
|
initialPageParam: 0,
|
||||||
|
getNextPageParam: (lastPage, allPages) => {
|
||||||
|
if (lastPage.items.length === 0) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const loadedCount = allPages.reduce((count, page) => count + page.items.length, 0);
|
||||||
|
return loadedCount < lastPage.total ? loadedCount : undefined;
|
||||||
|
},
|
||||||
|
enabled,
|
||||||
|
staleTime: 5 * 60 * 1000,
|
||||||
|
gcTime: 30 * 60 * 1000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const options = useMemo<AsyncComboboxOption[]>(() => {
|
||||||
|
const items = infiniteQuery.data?.pages.flatMap((page) => page.items) ?? [];
|
||||||
|
return items.map(mapOption);
|
||||||
|
}, [infiniteQuery.data?.pages, mapOption]);
|
||||||
|
|
||||||
|
const selectedInList = useMemo(
|
||||||
|
() => options.find((option) => option.value === selectedValue) ?? null,
|
||||||
|
[options, selectedValue],
|
||||||
|
);
|
||||||
|
|
||||||
|
const resolvedSelectedQuery = useQuery({
|
||||||
|
queryKey: resolveSelectedQueryKey?.(selectedValue) ?? [
|
||||||
|
...queryKey(''),
|
||||||
|
'selected',
|
||||||
|
selectedValue,
|
||||||
|
],
|
||||||
|
queryFn: async () => {
|
||||||
|
if (!selectedValue || !resolveSelected) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const item = await resolveSelected(selectedValue);
|
||||||
|
return item ? mapOption(item) : null;
|
||||||
|
},
|
||||||
|
enabled: enabled && Boolean(selectedValue) && !selectedInList && Boolean(resolveSelected),
|
||||||
|
staleTime: 5 * 60 * 1000,
|
||||||
|
gcTime: 30 * 60 * 1000,
|
||||||
|
});
|
||||||
|
|
||||||
|
const selectedOption = selectedInList ?? resolvedSelectedQuery.data ?? null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
search,
|
||||||
|
setSearch,
|
||||||
|
options,
|
||||||
|
selectedOption,
|
||||||
|
isLoading: infiniteQuery.isLoading,
|
||||||
|
isError: infiniteQuery.isError || resolvedSelectedQuery.isError,
|
||||||
|
errorMessage:
|
||||||
|
infiniteQuery.error instanceof Error
|
||||||
|
? infiniteQuery.error.message
|
||||||
|
: resolvedSelectedQuery.error instanceof Error
|
||||||
|
? resolvedSelectedQuery.error.message
|
||||||
|
: undefined,
|
||||||
|
isFetchingNextPage: infiniteQuery.isFetchingNextPage,
|
||||||
|
hasNextPage: infiniteQuery.hasNextPage ?? false,
|
||||||
|
fetchNextPage: infiniteQuery.fetchNextPage,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,38 +1,79 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Table } from '@tanstack/react-table';
|
import { Table } from '@tanstack/react-table';
|
||||||
|
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@/components/ui/select';
|
||||||
|
|
||||||
|
const PAGE_SIZE_OPTIONS = [10, 20, 40, 50, 100];
|
||||||
|
|
||||||
export function TableFooter<TData>({
|
export function TableFooter<TData>({
|
||||||
table,
|
table,
|
||||||
totalItems,
|
totalItems,
|
||||||
|
pageSize,
|
||||||
|
onPageSizeChange,
|
||||||
}: {
|
}: {
|
||||||
table: Table<TData>;
|
table: Table<TData>;
|
||||||
totalItems: number;
|
totalItems: number;
|
||||||
|
pageSize?: number;
|
||||||
|
onPageSizeChange?: (pageSize: number) => void;
|
||||||
}) {
|
}) {
|
||||||
const rows = table.getRowModel().rows.length;
|
const rows = table.getRowModel().rows.length;
|
||||||
|
const currentPageSize = pageSize ?? table.getState().pagination.pageSize;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center justify-between gap-3 text-sm text-muted-foreground">
|
<div className="flex flex-col gap-3 text-sm text-muted-foreground sm:flex-row sm:items-center sm:justify-between">
|
||||||
<span>
|
<div className="flex flex-wrap items-center gap-3">
|
||||||
Showing {rows} of {totalItems}
|
<span>
|
||||||
</span>
|
Showing {rows} of {totalItems}
|
||||||
|
</span>
|
||||||
|
{onPageSizeChange ? (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span >Rows per page</span>
|
||||||
|
<Select
|
||||||
|
value={String(currentPageSize)}
|
||||||
|
onValueChange={(value) => onPageSizeChange(Number(value))}
|
||||||
|
>
|
||||||
|
<SelectTrigger className="h-8 w-18 bg-background">
|
||||||
|
<SelectValue />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{PAGE_SIZE_OPTIONS.map((size) => (
|
||||||
|
<SelectItem key={size} value={String(size)}>
|
||||||
|
{size}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="sm"
|
size="sm"
|
||||||
onClick={() => table.previousPage()}
|
onClick={() => table.previousPage()}
|
||||||
disabled={!table.getCanPreviousPage()}
|
disabled={!table.getCanPreviousPage()}
|
||||||
>
|
>
|
||||||
Previous
|
<ChevronLeft className="size-4" />
|
||||||
</Button>
|
Previous
|
||||||
<Button
|
</Button>
|
||||||
variant="outline"
|
<Button
|
||||||
size="sm"
|
variant="outline"
|
||||||
onClick={() => table.nextPage()}
|
size="sm"
|
||||||
disabled={!table.getCanNextPage()}
|
onClick={() => table.nextPage()}
|
||||||
>
|
disabled={!table.getCanNextPage()}
|
||||||
Next
|
>
|
||||||
</Button>
|
Next
|
||||||
|
<ChevronRight className="size-4" />
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,21 +2,47 @@
|
|||||||
import { flexRender } from '@tanstack/react-table';
|
import { flexRender } from '@tanstack/react-table';
|
||||||
import { TableHead, TableHeader as ShadTableHeader, TableRow } from '@/components/ui/table';
|
import { TableHead, TableHeader as ShadTableHeader, TableRow } from '@/components/ui/table';
|
||||||
import { Table } from '@tanstack/react-table';
|
import { Table } from '@tanstack/react-table';
|
||||||
|
import { ArrowDownWideNarrow, ArrowUpDown, ArrowUpNarrowWide } from 'lucide-react';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
const TableHeader = <TData, _>({ table }: { table: Table<TData> }) => {
|
const TableHeader = <TData, _>({ table }: { table: Table<TData> }) => {
|
||||||
return (
|
return (
|
||||||
<ShadTableHeader className="sticky top-0 z-10 bg-card">
|
<ShadTableHeader className="sticky top-0 z-10 bg-card/80 backdrop-blur-xl">
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
<TableRow key={headerGroup.id}>
|
<TableRow key={headerGroup.id}>
|
||||||
{headerGroup.headers.map((header) => {
|
{headerGroup.headers.map((header) => {
|
||||||
|
const canSort = header.column.getCanSort();
|
||||||
|
const sortDirection = header.column.getIsSorted();
|
||||||
|
const SortIcon =
|
||||||
|
sortDirection === 'asc'
|
||||||
|
? ArrowUpNarrowWide
|
||||||
|
: sortDirection === 'desc'
|
||||||
|
? ArrowDownWideNarrow
|
||||||
|
: ArrowUpDown;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableHead
|
<TableHead
|
||||||
key={header.id}
|
key={header.id}
|
||||||
className="h-10 px-2 text-foreground bg-card"
|
onClick={canSort ? header.column.getToggleSortingHandler() : undefined}
|
||||||
|
className={cn(
|
||||||
|
'h-10 bg-card/80 px-2 text-foreground backdrop-blur-xl transition-colors',
|
||||||
|
canSort && 'cursor-pointer select-none hover:bg-muted/60',
|
||||||
|
sortDirection && 'bg-muted/70',
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
{header.isPlaceholder ? null : (
|
{header.isPlaceholder ? null : (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex min-h-8 w-full items-center justify-between gap-2">
|
||||||
{flexRender(header.column.columnDef.header, header.getContext())}
|
<span className="truncate">
|
||||||
|
{flexRender(header.column.columnDef.header, header.getContext())}
|
||||||
|
</span>
|
||||||
|
{canSort ? (
|
||||||
|
<SortIcon
|
||||||
|
className={cn(
|
||||||
|
'size-3.5 shrink-0 transition-colors',
|
||||||
|
sortDirection ? 'text-foreground' : 'text-muted-foreground/60',
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
|
|||||||
37
src/components/data-table/TableSearchInput.tsx
Normal file
37
src/components/data-table/TableSearchInput.tsx
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { Search } from 'lucide-react';
|
||||||
|
|
||||||
|
import {
|
||||||
|
InputGroup,
|
||||||
|
InputGroupAddon,
|
||||||
|
InputGroupInput,
|
||||||
|
} from '@/components/ui/input-group';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
interface TableSearchInputProps {
|
||||||
|
value: string;
|
||||||
|
onChange: (value: string) => void;
|
||||||
|
placeholder?: string;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TableSearchInput({
|
||||||
|
value,
|
||||||
|
onChange,
|
||||||
|
placeholder = 'Search...',
|
||||||
|
className,
|
||||||
|
}: TableSearchInputProps) {
|
||||||
|
return (
|
||||||
|
<InputGroup className={cn('md:max-w-xs', className)}>
|
||||||
|
<InputGroupAddon>
|
||||||
|
<Search />
|
||||||
|
</InputGroupAddon>
|
||||||
|
<InputGroupInput
|
||||||
|
value={value}
|
||||||
|
onChange={(event) => onChange(event.target.value)}
|
||||||
|
placeholder={placeholder}
|
||||||
|
/>
|
||||||
|
</InputGroup>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -38,6 +38,8 @@ export interface DataTableProps<TData, TValue> {
|
|||||||
onPageChange: (newSkip: number) => void;
|
onPageChange: (newSkip: number) => void;
|
||||||
onLimitChange: (newLimit: number) => void;
|
onLimitChange: (newLimit: number) => void;
|
||||||
};
|
};
|
||||||
|
sorting?: SortingState;
|
||||||
|
onSortingChange?: (sorting: SortingState) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function DataTable<TData, TValue>({
|
export function DataTable<TData, TValue>({
|
||||||
@@ -53,9 +55,24 @@ export function DataTable<TData, TValue>({
|
|||||||
emptyTitle = 'No results found.',
|
emptyTitle = 'No results found.',
|
||||||
emptyDescription = 'Try adjusting your filters or search terms.',
|
emptyDescription = 'Try adjusting your filters or search terms.',
|
||||||
pagination,
|
pagination,
|
||||||
|
sorting: controlledSorting,
|
||||||
|
onSortingChange,
|
||||||
}: DataTableProps<TData, TValue>) {
|
}: DataTableProps<TData, TValue>) {
|
||||||
const [rowSelection, setRowSelection] = React.useState({});
|
const [rowSelection, setRowSelection] = React.useState({});
|
||||||
const [sorting, setSorting] = React.useState<SortingState>([]);
|
const [internalSorting, setInternalSorting] = React.useState<SortingState>([]);
|
||||||
|
const sorting = controlledSorting ?? internalSorting;
|
||||||
|
const isManualSorting = Boolean(onSortingChange);
|
||||||
|
const handleSortingChange = React.useCallback(
|
||||||
|
(updater: SortingState | ((old: SortingState) => SortingState)) => {
|
||||||
|
const nextSorting = typeof updater === 'function' ? updater(sorting) : updater;
|
||||||
|
if (onSortingChange) {
|
||||||
|
onSortingChange(nextSorting);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setInternalSorting(nextSorting);
|
||||||
|
},
|
||||||
|
[onSortingChange, sorting],
|
||||||
|
);
|
||||||
|
|
||||||
const columns = React.useMemo(() => {
|
const columns = React.useMemo(() => {
|
||||||
const cols: ColumnDef<TData, TValue>[] = [...initialColumns];
|
const cols: ColumnDef<TData, TValue>[] = [...initialColumns];
|
||||||
@@ -105,10 +122,11 @@ export function DataTable<TData, TValue>({
|
|||||||
columns,
|
columns,
|
||||||
getCoreRowModel: getCoreRowModel(),
|
getCoreRowModel: getCoreRowModel(),
|
||||||
onRowSelectionChange: setRowSelection,
|
onRowSelectionChange: setRowSelection,
|
||||||
onSortingChange: setSorting,
|
onSortingChange: handleSortingChange,
|
||||||
getSortedRowModel: getSortedRowModel(),
|
getSortedRowModel: getSortedRowModel(),
|
||||||
getPaginationRowModel: getPaginationRowModel(),
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
manualPagination: !!pagination,
|
manualPagination: !!pagination,
|
||||||
|
manualSorting: isManualSorting,
|
||||||
pageCount: pagination?.totalItems ? Math.ceil(pagination.totalItems / pagination.limit) : -1,
|
pageCount: pagination?.totalItems ? Math.ceil(pagination.totalItems / pagination.limit) : -1,
|
||||||
state: {
|
state: {
|
||||||
rowSelection,
|
rowSelection,
|
||||||
@@ -126,7 +144,14 @@ export function DataTable<TData, TValue>({
|
|||||||
pageIndex: Math.floor(pagination.skip / pagination.limit),
|
pageIndex: Math.floor(pagination.skip / pagination.limit),
|
||||||
pageSize: pagination.limit,
|
pageSize: pagination.limit,
|
||||||
});
|
});
|
||||||
pagination.onLimitChange(newState.pageSize);
|
const pageSizeChanged = newState.pageSize !== pagination.limit;
|
||||||
|
|
||||||
|
if (pageSizeChanged) {
|
||||||
|
pagination.onLimitChange(newState.pageSize);
|
||||||
|
pagination.onPageChange(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
pagination.onPageChange(newState.pageIndex * newState.pageSize);
|
pagination.onPageChange(newState.pageIndex * newState.pageSize);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -144,7 +169,7 @@ export function DataTable<TData, TValue>({
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<Table
|
<Table
|
||||||
containerClassName="max-h-[calc(100vh-300px)] overflow-y-auto"
|
containerClassName="max-h-[calc(100vh-350px)] overflow-y-auto"
|
||||||
className="border-separate border-spacing-0"
|
className="border-separate border-spacing-0"
|
||||||
>
|
>
|
||||||
<TableHeader table={table} />
|
<TableHeader table={table} />
|
||||||
@@ -154,7 +179,7 @@ export function DataTable<TData, TValue>({
|
|||||||
<TableRow key={idx}>
|
<TableRow key={idx}>
|
||||||
{columns.map((_, colIdx) => (
|
{columns.map((_, colIdx) => (
|
||||||
<TableCell key={colIdx}>
|
<TableCell key={colIdx}>
|
||||||
<Skeleton className="h-4 w-full max-w-[140px]" />
|
<Skeleton className="h-4 w-full max-w-35" />
|
||||||
</TableCell>
|
</TableCell>
|
||||||
))}
|
))}
|
||||||
</TableRow>
|
</TableRow>
|
||||||
@@ -185,7 +210,12 @@ export function DataTable<TData, TValue>({
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
<TableFooter table={table} totalItems={pagination?.totalItems ?? data.length} />
|
<TableFooter
|
||||||
|
table={table}
|
||||||
|
totalItems={pagination?.totalItems ?? data.length}
|
||||||
|
pageSize={pagination?.limit}
|
||||||
|
onPageSizeChange={pagination?.onLimitChange}
|
||||||
|
/>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
14
src/components/data-table/sorting.ts
Normal file
14
src/components/data-table/sorting.ts
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import type { SortingState } from '@tanstack/react-table';
|
||||||
|
|
||||||
|
export function getServerSortParams(sorting: SortingState) {
|
||||||
|
const activeSort = sorting[0];
|
||||||
|
|
||||||
|
if (!activeSort) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
sort_by: activeSort.id,
|
||||||
|
sort_order: activeSort.desc ? 'desc' : 'asc',
|
||||||
|
};
|
||||||
|
}
|
||||||
74
src/components/lookups/RoleCombobox.tsx
Normal file
74
src/components/lookups/RoleCombobox.tsx
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { AsyncCombobox, usePaginatedLookup } from '@/components/async-combobox';
|
||||||
|
import type { AsyncComboboxOption } from '@/components/async-combobox';
|
||||||
|
import { roleService } from '@/services/api';
|
||||||
|
import type { Role } from '@/types';
|
||||||
|
|
||||||
|
import { roleKeys } from '@/app/(modules)/roles/queries/roleKeys';
|
||||||
|
import type { RoleComboboxProps } from './RoleCombobox.types';
|
||||||
|
|
||||||
|
const ROLE_PAGE_SIZE = 20;
|
||||||
|
|
||||||
|
function parseRoleId(value: string) {
|
||||||
|
const roleId = Number(value);
|
||||||
|
return Number.isFinite(roleId) ? roleId : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapRoleOption(role: Role): AsyncComboboxOption {
|
||||||
|
return {
|
||||||
|
value: String(role.id),
|
||||||
|
label: role.display_name || role.name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RoleCombobox({
|
||||||
|
value,
|
||||||
|
onValueChange,
|
||||||
|
enabled = true,
|
||||||
|
disabled = false,
|
||||||
|
portalContainer,
|
||||||
|
}: RoleComboboxProps) {
|
||||||
|
const lookup = usePaginatedLookup<Role>({
|
||||||
|
enabled,
|
||||||
|
selectedValue: value,
|
||||||
|
pageSize: ROLE_PAGE_SIZE,
|
||||||
|
queryKey: (searchTerm) =>
|
||||||
|
[
|
||||||
|
...roleKeys.lists(),
|
||||||
|
'async-lookup',
|
||||||
|
searchTerm,
|
||||||
|
ROLE_PAGE_SIZE,
|
||||||
|
] as const,
|
||||||
|
queryFn: ({ searchTerm, skip, limit }) =>
|
||||||
|
roleService.getRoles({
|
||||||
|
search_term: searchTerm || undefined,
|
||||||
|
skip,
|
||||||
|
limit,
|
||||||
|
effective_status: true,
|
||||||
|
sort_by: 'display_name',
|
||||||
|
sort_order: 'asc',
|
||||||
|
}),
|
||||||
|
mapOption: mapRoleOption,
|
||||||
|
resolveSelected: (roleId) => {
|
||||||
|
const numericRoleId = parseRoleId(roleId);
|
||||||
|
return numericRoleId ? roleService.getRoleById(numericRoleId) : Promise.resolve(null);
|
||||||
|
},
|
||||||
|
resolveSelectedQueryKey: (roleId) => {
|
||||||
|
const numericRoleId = parseRoleId(roleId);
|
||||||
|
return numericRoleId ? roleKeys.detail(numericRoleId) : [...roleKeys.details(), 'invalid', roleId];
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<AsyncCombobox
|
||||||
|
lookup={lookup}
|
||||||
|
onValueChange={onValueChange}
|
||||||
|
disabled={disabled}
|
||||||
|
placeholder="Select role"
|
||||||
|
searchPlaceholder="Search roles..."
|
||||||
|
emptyMessage="No roles found."
|
||||||
|
portalContainer={portalContainer}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
9
src/components/lookups/RoleCombobox.types.ts
Normal file
9
src/components/lookups/RoleCombobox.types.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import type { RefObject } from 'react';
|
||||||
|
|
||||||
|
export interface RoleComboboxProps {
|
||||||
|
value: string;
|
||||||
|
onValueChange: (value: string) => void;
|
||||||
|
enabled?: boolean;
|
||||||
|
disabled?: boolean;
|
||||||
|
portalContainer?: RefObject<HTMLDivElement | null>;
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import { CheckboxTree } from '@/components/ui/tree';
|
import { CheckboxTree } from '@/components/ui/tree';
|
||||||
import type { PermissionTreeItem, PermissionTreeNode } from '@/types';
|
import type { PermissionTreeItem, PermissionTreeNode } from '@/types';
|
||||||
|
|
||||||
@@ -46,11 +45,7 @@ export function PermissionTree({
|
|||||||
selectedIds={selectedIds}
|
selectedIds={selectedIds}
|
||||||
onSelectedIdsChange={onChange}
|
onSelectedIdsChange={onChange}
|
||||||
emptyMessage="No permissions available."
|
emptyMessage="No permissions available."
|
||||||
renderMeta={(item) => (
|
showDescription={false}
|
||||||
<Badge variant="outline" className="text-[10px] capitalize">
|
|
||||||
{item.type}
|
|
||||||
</Badge>
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,58 +1,64 @@
|
|||||||
import * as React from 'react';
|
import * as React from "react"
|
||||||
import { Slot } from '@radix-ui/react-slot';
|
import { cva, type VariantProps } from "class-variance-authority"
|
||||||
import { cva, type VariantProps } from 'class-variance-authority';
|
import { Slot } from "radix-ui"
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
const buttonVariants = cva(
|
const buttonVariants = cva(
|
||||||
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
"inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
variant: {
|
variant: {
|
||||||
default: 'bg-primary text-primary-foreground hover:bg-primary/90',
|
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
||||||
destructive:
|
destructive:
|
||||||
'bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60',
|
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40",
|
||||||
outline:
|
outline:
|
||||||
'border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50',
|
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
||||||
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
|
secondary:
|
||||||
ghost: 'hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50',
|
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
||||||
link: 'text-primary underline-offset-4 hover:underline',
|
ghost:
|
||||||
|
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
|
||||||
|
link: "text-primary underline-offset-4 hover:underline",
|
||||||
},
|
},
|
||||||
size: {
|
size: {
|
||||||
default: 'h-9 px-4 py-2 has-[>svg]:px-3',
|
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
||||||
sm: 'h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5',
|
xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
|
||||||
lg: 'h-10 rounded-md px-6 has-[>svg]:px-4',
|
sm: "h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",
|
||||||
icon: 'size-9',
|
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
||||||
'icon-sm': 'size-8',
|
icon: "size-9",
|
||||||
'icon-lg': 'size-10',
|
"icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
|
||||||
|
"icon-sm": "size-8",
|
||||||
|
"icon-lg": "size-10",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
defaultVariants: {
|
defaultVariants: {
|
||||||
variant: 'default',
|
variant: "default",
|
||||||
size: 'default',
|
size: "default",
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
);
|
)
|
||||||
|
|
||||||
function Button({
|
function Button({
|
||||||
className,
|
className,
|
||||||
variant,
|
variant = "default",
|
||||||
size,
|
size = "default",
|
||||||
asChild = false,
|
asChild = false,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<'button'> &
|
}: React.ComponentProps<"button"> &
|
||||||
VariantProps<typeof buttonVariants> & {
|
VariantProps<typeof buttonVariants> & {
|
||||||
asChild?: boolean;
|
asChild?: boolean
|
||||||
}) {
|
}) {
|
||||||
const Comp = asChild ? Slot : 'button';
|
const Comp = asChild ? Slot.Root : "button"
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Comp
|
<Comp
|
||||||
data-slot="button"
|
data-slot="button"
|
||||||
|
data-variant={variant}
|
||||||
|
data-size={size}
|
||||||
className={cn(buttonVariants({ variant, size, className }))}
|
className={cn(buttonVariants({ variant, size, className }))}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Button, buttonVariants };
|
export { Button, buttonVariants }
|
||||||
|
|||||||
313
src/components/ui/combobox.tsx
Normal file
313
src/components/ui/combobox.tsx
Normal file
@@ -0,0 +1,313 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { Combobox as ComboboxPrimitive } from "@base-ui/react"
|
||||||
|
import { CheckIcon, ChevronDownIcon, XIcon } from "lucide-react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import {
|
||||||
|
InputGroup,
|
||||||
|
InputGroupAddon,
|
||||||
|
InputGroupButton,
|
||||||
|
InputGroupInput,
|
||||||
|
} from "@/components/ui/input-group"
|
||||||
|
|
||||||
|
const Combobox = ComboboxPrimitive.Root
|
||||||
|
|
||||||
|
function ComboboxValue({ ...props }: ComboboxPrimitive.Value.Props) {
|
||||||
|
return <ComboboxPrimitive.Value data-slot="combobox-value" {...props} />
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxTrigger({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: ComboboxPrimitive.Trigger.Props) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.Trigger
|
||||||
|
data-slot="combobox-trigger"
|
||||||
|
className={cn("[&_svg:not([class*='size-'])]:size-4", className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<ChevronDownIcon
|
||||||
|
data-slot="combobox-trigger-icon"
|
||||||
|
className="pointer-events-none size-4 text-muted-foreground"
|
||||||
|
/>
|
||||||
|
</ComboboxPrimitive.Trigger>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxClear({ className, ...props }: ComboboxPrimitive.Clear.Props) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.Clear
|
||||||
|
data-slot="combobox-clear"
|
||||||
|
render={<InputGroupButton variant="ghost" size="icon-xs" />}
|
||||||
|
className={cn(className)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
<XIcon className="pointer-events-none" />
|
||||||
|
</ComboboxPrimitive.Clear>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxInput({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
disabled = false,
|
||||||
|
showTrigger = true,
|
||||||
|
showClear = false,
|
||||||
|
...props
|
||||||
|
}: ComboboxPrimitive.Input.Props & {
|
||||||
|
showTrigger?: boolean
|
||||||
|
showClear?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<InputGroup className={cn("w-auto", className)}>
|
||||||
|
<ComboboxPrimitive.Input
|
||||||
|
render={<InputGroupInput disabled={disabled} />}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
<InputGroupAddon align="inline-end">
|
||||||
|
{showTrigger && (
|
||||||
|
<InputGroupButton
|
||||||
|
size="icon-xs"
|
||||||
|
variant="ghost"
|
||||||
|
asChild
|
||||||
|
data-slot="input-group-button"
|
||||||
|
className="group-has-data-[slot=combobox-clear]/input-group:hidden data-pressed:bg-transparent"
|
||||||
|
disabled={disabled}
|
||||||
|
>
|
||||||
|
<ComboboxTrigger />
|
||||||
|
</InputGroupButton>
|
||||||
|
)}
|
||||||
|
{showClear && <ComboboxClear disabled={disabled} />}
|
||||||
|
</InputGroupAddon>
|
||||||
|
{children}
|
||||||
|
</InputGroup>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxContent({
|
||||||
|
className,
|
||||||
|
side = "bottom",
|
||||||
|
sideOffset = 6,
|
||||||
|
align = "start",
|
||||||
|
alignOffset = 0,
|
||||||
|
anchor,
|
||||||
|
container,
|
||||||
|
...props
|
||||||
|
}: ComboboxPrimitive.Popup.Props &
|
||||||
|
Pick<
|
||||||
|
ComboboxPrimitive.Positioner.Props,
|
||||||
|
"side" | "align" | "sideOffset" | "alignOffset" | "anchor"
|
||||||
|
> & {
|
||||||
|
container?: ComboboxPrimitive.Portal.Props["container"]
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.Portal container={container}>
|
||||||
|
<ComboboxPrimitive.Positioner
|
||||||
|
side={side}
|
||||||
|
sideOffset={sideOffset}
|
||||||
|
align={align}
|
||||||
|
alignOffset={alignOffset}
|
||||||
|
anchor={anchor}
|
||||||
|
className="isolate z-50"
|
||||||
|
>
|
||||||
|
<ComboboxPrimitive.Popup
|
||||||
|
data-slot="combobox-content"
|
||||||
|
data-chips={!!anchor}
|
||||||
|
className={cn(
|
||||||
|
"group/combobox-content relative max-h-96 w-[var(--anchor-width)] max-w-[var(--available-width)] min-w-[calc(var(--anchor-width)+1.75rem)] origin-[var(--transform-origin)] overflow-hidden rounded-md bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[chips=true]:min-w-[var(--anchor-width)] data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 *:data-[slot=input-group]:m-1 *:data-[slot=input-group]:mb-0 *:data-[slot=input-group]:h-8 *:data-[slot=input-group]:border-input/30 *:data-[slot=input-group]:bg-input/30 *:data-[slot=input-group]:shadow-none data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
</ComboboxPrimitive.Positioner>
|
||||||
|
</ComboboxPrimitive.Portal>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxList({ className, ...props }: ComboboxPrimitive.List.Props) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.List
|
||||||
|
data-slot="combobox-list"
|
||||||
|
className={cn(
|
||||||
|
"max-h-[min(21.75rem,calc(var(--available-height)-2.25rem))] scroll-py-1 overflow-y-auto p-1 data-empty:p-0",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxItem({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: ComboboxPrimitive.Item.Props) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.Item
|
||||||
|
data-slot="combobox-item"
|
||||||
|
className={cn(
|
||||||
|
"relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-highlighted:bg-accent data-highlighted:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
<ComboboxPrimitive.ItemIndicator
|
||||||
|
data-slot="combobox-item-indicator"
|
||||||
|
render={
|
||||||
|
<span className="pointer-events-none absolute right-2 flex size-4 items-center justify-center" />
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<CheckIcon className="pointer-events-none size-4 pointer-coarse:size-5" />
|
||||||
|
</ComboboxPrimitive.ItemIndicator>
|
||||||
|
</ComboboxPrimitive.Item>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxGroup({ className, ...props }: ComboboxPrimitive.Group.Props) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.Group
|
||||||
|
data-slot="combobox-group"
|
||||||
|
className={cn(className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxLabel({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: ComboboxPrimitive.GroupLabel.Props) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.GroupLabel
|
||||||
|
data-slot="combobox-label"
|
||||||
|
className={cn(
|
||||||
|
"px-2 py-1.5 text-xs text-muted-foreground pointer-coarse:px-3 pointer-coarse:py-2 pointer-coarse:text-sm",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxCollection({ ...props }: ComboboxPrimitive.Collection.Props) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.Collection data-slot="combobox-collection" {...props} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxEmpty({ className, ...props }: ComboboxPrimitive.Empty.Props) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.Empty
|
||||||
|
data-slot="combobox-empty"
|
||||||
|
className={cn(
|
||||||
|
"hidden w-full justify-center py-2 text-center text-sm text-muted-foreground group-data-empty/combobox-content:flex",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxSeparator({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: ComboboxPrimitive.Separator.Props) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.Separator
|
||||||
|
data-slot="combobox-separator"
|
||||||
|
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxChips({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentPropsWithRef<typeof ComboboxPrimitive.Chips> &
|
||||||
|
ComboboxPrimitive.Chips.Props) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.Chips
|
||||||
|
data-slot="combobox-chips"
|
||||||
|
className={cn(
|
||||||
|
"flex min-h-9 flex-wrap items-center gap-1.5 rounded-md border border-input bg-transparent bg-clip-padding px-2.5 py-1.5 text-sm shadow-xs transition-[color,box-shadow] focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50 has-aria-invalid:border-destructive has-aria-invalid:ring-[3px] has-aria-invalid:ring-destructive/20 has-data-[slot=combobox-chip]:px-1.5 dark:bg-input/30 dark:has-aria-invalid:border-destructive/50 dark:has-aria-invalid:ring-destructive/40",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxChip({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
showRemove = true,
|
||||||
|
...props
|
||||||
|
}: ComboboxPrimitive.Chip.Props & {
|
||||||
|
showRemove?: boolean
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.Chip
|
||||||
|
data-slot="combobox-chip"
|
||||||
|
className={cn(
|
||||||
|
"flex h-[calc(--spacing(5.5))] w-fit items-center justify-center gap-1 rounded-sm bg-muted px-1.5 text-xs font-medium whitespace-nowrap text-foreground has-disabled:pointer-events-none has-disabled:cursor-not-allowed has-disabled:opacity-50 has-data-[slot=combobox-chip-remove]:pr-0",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
{showRemove && (
|
||||||
|
<ComboboxPrimitive.ChipRemove
|
||||||
|
render={<Button variant="ghost" size="icon-xs" />}
|
||||||
|
className="-ml-1 opacity-50 hover:opacity-100"
|
||||||
|
data-slot="combobox-chip-remove"
|
||||||
|
>
|
||||||
|
<XIcon className="pointer-events-none" />
|
||||||
|
</ComboboxPrimitive.ChipRemove>
|
||||||
|
)}
|
||||||
|
</ComboboxPrimitive.Chip>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ComboboxChipsInput({
|
||||||
|
className,
|
||||||
|
children,
|
||||||
|
...props
|
||||||
|
}: ComboboxPrimitive.Input.Props) {
|
||||||
|
return (
|
||||||
|
<ComboboxPrimitive.Input
|
||||||
|
data-slot="combobox-chip-input"
|
||||||
|
className={cn("min-w-16 flex-1 outline-none", className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function useComboboxAnchor() {
|
||||||
|
return React.useRef<HTMLDivElement | null>(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Combobox,
|
||||||
|
ComboboxInput,
|
||||||
|
ComboboxContent,
|
||||||
|
ComboboxList,
|
||||||
|
ComboboxItem,
|
||||||
|
ComboboxGroup,
|
||||||
|
ComboboxLabel,
|
||||||
|
ComboboxCollection,
|
||||||
|
ComboboxEmpty,
|
||||||
|
ComboboxSeparator,
|
||||||
|
ComboboxChips,
|
||||||
|
ComboboxChip,
|
||||||
|
ComboboxChipsInput,
|
||||||
|
ComboboxTrigger,
|
||||||
|
ComboboxValue,
|
||||||
|
useComboboxAnchor,
|
||||||
|
}
|
||||||
@@ -1,26 +1,34 @@
|
|||||||
'use client';
|
"use client"
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from "react"
|
||||||
import { XIcon } from 'lucide-react';
|
import { XIcon } from "lucide-react"
|
||||||
import { Dialog as DialogPrimitive } from 'radix-ui';
|
import { Dialog as DialogPrimitive } from "radix-ui"
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from "@/lib/utils"
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from "@/components/ui/button"
|
||||||
|
|
||||||
function Dialog({ ...props }: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
function Dialog({
|
||||||
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
||||||
|
return <DialogPrimitive.Root data-slot="dialog" {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function DialogTrigger({ ...props }: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
function DialogTrigger({
|
||||||
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
||||||
|
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function DialogPortal({ ...props }: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
function DialogPortal({
|
||||||
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
||||||
|
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function DialogClose({ ...props }: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
function DialogClose({
|
||||||
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
||||||
|
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function DialogOverlay({
|
function DialogOverlay({
|
||||||
@@ -31,21 +39,22 @@ function DialogOverlay({
|
|||||||
<DialogPrimitive.Overlay
|
<DialogPrimitive.Overlay
|
||||||
data-slot="dialog-overlay"
|
data-slot="dialog-overlay"
|
||||||
className={cn(
|
className={cn(
|
||||||
'fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0',
|
"fixed inset-0 z-50 bg-black/50 backdrop-blur-xs data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DialogContent({
|
function DialogContent({
|
||||||
className,
|
className,
|
||||||
children,
|
children,
|
||||||
showCloseButton = true,
|
showCloseButton = true,
|
||||||
|
onInteractOutside,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
||||||
showCloseButton?: boolean;
|
showCloseButton?: boolean
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<DialogPortal data-slot="dialog-portal">
|
<DialogPortal data-slot="dialog-portal">
|
||||||
@@ -53,9 +62,13 @@ function DialogContent({
|
|||||||
<DialogPrimitive.Content
|
<DialogPrimitive.Content
|
||||||
data-slot="dialog-content"
|
data-slot="dialog-content"
|
||||||
className={cn(
|
className={cn(
|
||||||
'fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg',
|
"fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
|
onInteractOutside={(event) => {
|
||||||
|
event.preventDefault()
|
||||||
|
onInteractOutside?.(event)
|
||||||
|
}}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@@ -70,17 +83,17 @@ function DialogContent({
|
|||||||
)}
|
)}
|
||||||
</DialogPrimitive.Content>
|
</DialogPrimitive.Content>
|
||||||
</DialogPortal>
|
</DialogPortal>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DialogHeader({ className, ...props }: React.ComponentProps<'div'>) {
|
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
data-slot="dialog-header"
|
data-slot="dialog-header"
|
||||||
className={cn('flex flex-col gap-2 text-center sm:text-left', className)}
|
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DialogFooter({
|
function DialogFooter({
|
||||||
@@ -88,13 +101,16 @@ function DialogFooter({
|
|||||||
showCloseButton = false,
|
showCloseButton = false,
|
||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<'div'> & {
|
}: React.ComponentProps<"div"> & {
|
||||||
showCloseButton?: boolean;
|
showCloseButton?: boolean
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
data-slot="dialog-footer"
|
data-slot="dialog-footer"
|
||||||
className={cn('flex flex-col-reverse gap-2 sm:flex-row sm:justify-end', className)}
|
className={cn(
|
||||||
|
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
||||||
|
className
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@@ -104,17 +120,20 @@ function DialogFooter({
|
|||||||
</DialogPrimitive.Close>
|
</DialogPrimitive.Close>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DialogTitle({ className, ...props }: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
function DialogTitle({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
||||||
return (
|
return (
|
||||||
<DialogPrimitive.Title
|
<DialogPrimitive.Title
|
||||||
data-slot="dialog-title"
|
data-slot="dialog-title"
|
||||||
className={cn('text-lg leading-none font-semibold', className)}
|
className={cn("text-lg leading-none font-semibold", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DialogDescription({
|
function DialogDescription({
|
||||||
@@ -124,10 +143,10 @@ function DialogDescription({
|
|||||||
return (
|
return (
|
||||||
<DialogPrimitive.Description
|
<DialogPrimitive.Description
|
||||||
data-slot="dialog-description"
|
data-slot="dialog-description"
|
||||||
className={cn('text-sm text-muted-foreground', className)}
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -141,4 +160,4 @@ export {
|
|||||||
DialogPortal,
|
DialogPortal,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
};
|
}
|
||||||
|
|||||||
@@ -1,25 +1,34 @@
|
|||||||
'use client';
|
"use client"
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from "react"
|
||||||
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
|
||||||
import { CheckIcon, ChevronRightIcon, CircleIcon } from 'lucide-react';
|
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui"
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
function DropdownMenu({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
function DropdownMenu({
|
||||||
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />;
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
|
||||||
|
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuPortal({
|
function DropdownMenuPortal({
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
|
||||||
return <DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />;
|
return (
|
||||||
|
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuTrigger({
|
function DropdownMenuTrigger({
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
|
||||||
return <DropdownMenuPrimitive.Trigger data-slot="dropdown-menu-trigger" {...props} />;
|
return (
|
||||||
|
<DropdownMenuPrimitive.Trigger
|
||||||
|
data-slot="dropdown-menu-trigger"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuContent({
|
function DropdownMenuContent({
|
||||||
@@ -33,27 +42,31 @@ function DropdownMenuContent({
|
|||||||
data-slot="dropdown-menu-content"
|
data-slot="dropdown-menu-content"
|
||||||
sideOffset={sideOffset}
|
sideOffset={sideOffset}
|
||||||
className={cn(
|
className={cn(
|
||||||
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md',
|
"z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
</DropdownMenuPrimitive.Portal>
|
</DropdownMenuPrimitive.Portal>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuGroup({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
function DropdownMenuGroup({
|
||||||
return <DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />;
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
|
||||||
|
return (
|
||||||
|
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuItem({
|
function DropdownMenuItem({
|
||||||
className,
|
className,
|
||||||
inset,
|
inset,
|
||||||
variant = 'default',
|
variant = "default",
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
|
||||||
inset?: boolean;
|
inset?: boolean
|
||||||
variant?: 'default' | 'destructive';
|
variant?: "default" | "destructive"
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<DropdownMenuPrimitive.Item
|
<DropdownMenuPrimitive.Item
|
||||||
@@ -61,12 +74,12 @@ function DropdownMenuItem({
|
|||||||
data-inset={inset}
|
data-inset={inset}
|
||||||
data-variant={variant}
|
data-variant={variant}
|
||||||
className={cn(
|
className={cn(
|
||||||
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuCheckboxItem({
|
function DropdownMenuCheckboxItem({
|
||||||
@@ -79,8 +92,8 @@ function DropdownMenuCheckboxItem({
|
|||||||
<DropdownMenuPrimitive.CheckboxItem
|
<DropdownMenuPrimitive.CheckboxItem
|
||||||
data-slot="dropdown-menu-checkbox-item"
|
data-slot="dropdown-menu-checkbox-item"
|
||||||
className={cn(
|
className={cn(
|
||||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
checked={checked}
|
checked={checked}
|
||||||
{...props}
|
{...props}
|
||||||
@@ -92,13 +105,18 @@ function DropdownMenuCheckboxItem({
|
|||||||
</span>
|
</span>
|
||||||
{children}
|
{children}
|
||||||
</DropdownMenuPrimitive.CheckboxItem>
|
</DropdownMenuPrimitive.CheckboxItem>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuRadioGroup({
|
function DropdownMenuRadioGroup({
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
|
||||||
return <DropdownMenuPrimitive.RadioGroup data-slot="dropdown-menu-radio-group" {...props} />;
|
return (
|
||||||
|
<DropdownMenuPrimitive.RadioGroup
|
||||||
|
data-slot="dropdown-menu-radio-group"
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuRadioItem({
|
function DropdownMenuRadioItem({
|
||||||
@@ -110,8 +128,8 @@ function DropdownMenuRadioItem({
|
|||||||
<DropdownMenuPrimitive.RadioItem
|
<DropdownMenuPrimitive.RadioItem
|
||||||
data-slot="dropdown-menu-radio-item"
|
data-slot="dropdown-menu-radio-item"
|
||||||
className={cn(
|
className={cn(
|
||||||
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
@@ -122,7 +140,7 @@ function DropdownMenuRadioItem({
|
|||||||
</span>
|
</span>
|
||||||
{children}
|
{children}
|
||||||
</DropdownMenuPrimitive.RadioItem>
|
</DropdownMenuPrimitive.RadioItem>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuLabel({
|
function DropdownMenuLabel({
|
||||||
@@ -130,16 +148,19 @@ function DropdownMenuLabel({
|
|||||||
inset,
|
inset,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
|
||||||
inset?: boolean;
|
inset?: boolean
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<DropdownMenuPrimitive.Label
|
<DropdownMenuPrimitive.Label
|
||||||
data-slot="dropdown-menu-label"
|
data-slot="dropdown-menu-label"
|
||||||
data-inset={inset}
|
data-inset={inset}
|
||||||
className={cn('px-2 py-1.5 text-sm font-medium data-[inset]:pl-8', className)}
|
className={cn(
|
||||||
|
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
|
||||||
|
className
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuSeparator({
|
function DropdownMenuSeparator({
|
||||||
@@ -149,24 +170,32 @@ function DropdownMenuSeparator({
|
|||||||
return (
|
return (
|
||||||
<DropdownMenuPrimitive.Separator
|
<DropdownMenuPrimitive.Separator
|
||||||
data-slot="dropdown-menu-separator"
|
data-slot="dropdown-menu-separator"
|
||||||
className={cn('bg-border -mx-1 my-1 h-px', className)}
|
className={cn("-mx-1 my-1 h-px bg-border", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuShortcut({ className, ...props }: React.ComponentProps<'span'>) {
|
function DropdownMenuShortcut({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"span">) {
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
data-slot="dropdown-menu-shortcut"
|
data-slot="dropdown-menu-shortcut"
|
||||||
className={cn('text-muted-foreground ml-auto text-xs tracking-widest', className)}
|
className={cn(
|
||||||
|
"ml-auto text-xs tracking-widest text-muted-foreground",
|
||||||
|
className
|
||||||
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuSub({ ...props }: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
function DropdownMenuSub({
|
||||||
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />;
|
...props
|
||||||
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
|
||||||
|
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuSubTrigger({
|
function DropdownMenuSubTrigger({
|
||||||
@@ -175,22 +204,22 @@ function DropdownMenuSubTrigger({
|
|||||||
children,
|
children,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
|
||||||
inset?: boolean;
|
inset?: boolean
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<DropdownMenuPrimitive.SubTrigger
|
<DropdownMenuPrimitive.SubTrigger
|
||||||
data-slot="dropdown-menu-sub-trigger"
|
data-slot="dropdown-menu-sub-trigger"
|
||||||
data-inset={inset}
|
data-inset={inset}
|
||||||
className={cn(
|
className={cn(
|
||||||
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
"flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
<ChevronRightIcon className="ml-auto size-4" />
|
<ChevronRightIcon className="ml-auto size-4" />
|
||||||
</DropdownMenuPrimitive.SubTrigger>
|
</DropdownMenuPrimitive.SubTrigger>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function DropdownMenuSubContent({
|
function DropdownMenuSubContent({
|
||||||
@@ -201,12 +230,12 @@ function DropdownMenuSubContent({
|
|||||||
<DropdownMenuPrimitive.SubContent
|
<DropdownMenuPrimitive.SubContent
|
||||||
data-slot="dropdown-menu-sub-content"
|
data-slot="dropdown-menu-sub-content"
|
||||||
className={cn(
|
className={cn(
|
||||||
'bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg',
|
"z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -225,4 +254,4 @@ export {
|
|||||||
DropdownMenuSub,
|
DropdownMenuSub,
|
||||||
DropdownMenuSubTrigger,
|
DropdownMenuSubTrigger,
|
||||||
DropdownMenuSubContent,
|
DropdownMenuSubContent,
|
||||||
};
|
}
|
||||||
|
|||||||
170
src/components/ui/input-group.tsx
Normal file
170
src/components/ui/input-group.tsx
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import * as React from "react"
|
||||||
|
import { cva, type VariantProps } from "class-variance-authority"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
import { Button } from "@/components/ui/button"
|
||||||
|
import { Input } from "@/components/ui/input"
|
||||||
|
import { Textarea } from "@/components/ui/textarea"
|
||||||
|
|
||||||
|
function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
data-slot="input-group"
|
||||||
|
role="group"
|
||||||
|
className={cn(
|
||||||
|
"group/input-group relative flex w-full items-center rounded-md border border-input shadow-xs transition-[color,box-shadow] outline-none dark:bg-input/30",
|
||||||
|
"h-9 min-w-0 has-[>textarea]:h-auto",
|
||||||
|
|
||||||
|
// Variants based on alignment.
|
||||||
|
"has-[>[data-align=inline-start]]:[&>input]:pl-2",
|
||||||
|
"has-[>[data-align=inline-end]]:[&>input]:pr-2",
|
||||||
|
"has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3",
|
||||||
|
"has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3",
|
||||||
|
|
||||||
|
// Focus state.
|
||||||
|
"has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50",
|
||||||
|
|
||||||
|
// Error state.
|
||||||
|
"has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",
|
||||||
|
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputGroupAddonVariants = cva(
|
||||||
|
"flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
align: {
|
||||||
|
"inline-start":
|
||||||
|
"order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]",
|
||||||
|
"inline-end":
|
||||||
|
"order-last pr-3 has-[>button]:mr-[-0.45rem] has-[>kbd]:mr-[-0.35rem]",
|
||||||
|
"block-start":
|
||||||
|
"order-first w-full justify-start px-3 pt-3 group-has-[>input]/input-group:pt-2.5 [.border-b]:pb-3",
|
||||||
|
"block-end":
|
||||||
|
"order-last w-full justify-start px-3 pb-3 group-has-[>input]/input-group:pb-2.5 [.border-t]:pt-3",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
align: "inline-start",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
function InputGroupAddon({
|
||||||
|
className,
|
||||||
|
align = "inline-start",
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
role="group"
|
||||||
|
data-slot="input-group-addon"
|
||||||
|
data-align={align}
|
||||||
|
className={cn(inputGroupAddonVariants({ align }), className)}
|
||||||
|
onClick={(e) => {
|
||||||
|
if ((e.target as HTMLElement).closest("button")) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.currentTarget.parentElement?.querySelector("input")?.focus()
|
||||||
|
}}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const inputGroupButtonVariants = cva(
|
||||||
|
"flex items-center gap-2 text-sm shadow-none",
|
||||||
|
{
|
||||||
|
variants: {
|
||||||
|
size: {
|
||||||
|
xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 [&>svg:not([class*='size-'])]:size-3.5",
|
||||||
|
sm: "h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5",
|
||||||
|
"icon-xs":
|
||||||
|
"size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
|
||||||
|
"icon-sm": "size-8 p-0 has-[>svg]:p-0",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
defaultVariants: {
|
||||||
|
size: "xs",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
function InputGroupButton({
|
||||||
|
className,
|
||||||
|
type = "button",
|
||||||
|
variant = "ghost",
|
||||||
|
size = "xs",
|
||||||
|
...props
|
||||||
|
}: Omit<React.ComponentProps<typeof Button>, "size"> &
|
||||||
|
VariantProps<typeof inputGroupButtonVariants>) {
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
type={type}
|
||||||
|
data-size={size}
|
||||||
|
variant={variant}
|
||||||
|
className={cn(inputGroupButtonVariants({ size }), className)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
"flex items-center gap-2 text-sm text-muted-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function InputGroupInput({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"input">) {
|
||||||
|
return (
|
||||||
|
<Input
|
||||||
|
data-slot="input-group-control"
|
||||||
|
className={cn(
|
||||||
|
"flex-1 rounded-none border-0 bg-transparent shadow-none focus-visible:ring-0 dark:bg-transparent",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function InputGroupTextarea({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<"textarea">) {
|
||||||
|
return (
|
||||||
|
<Textarea
|
||||||
|
data-slot="input-group-control"
|
||||||
|
className={cn(
|
||||||
|
"flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
InputGroup,
|
||||||
|
InputGroupAddon,
|
||||||
|
InputGroupButton,
|
||||||
|
InputGroupText,
|
||||||
|
InputGroupInput,
|
||||||
|
InputGroupTextarea,
|
||||||
|
}
|
||||||
@@ -1,21 +1,21 @@
|
|||||||
import * as React from 'react';
|
import * as React from "react"
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
function Input({ className, type, ...props }: React.ComponentProps<'input'>) {
|
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
type={type}
|
type={type}
|
||||||
data-slot="input"
|
data-slot="input"
|
||||||
className={cn(
|
className={cn(
|
||||||
'file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm',
|
"h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30",
|
||||||
'focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]',
|
"focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50",
|
||||||
'aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive',
|
"aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Input };
|
export { Input }
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ function SelectContent({
|
|||||||
<SelectPrimitive.Content
|
<SelectPrimitive.Content
|
||||||
data-slot="select-content"
|
data-slot="select-content"
|
||||||
className={cn(
|
className={cn(
|
||||||
'relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
|
'relative z-50 max-h-(--radix-select-content-available-height) min-w-32 origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95',
|
||||||
position === 'popper' &&
|
position === 'popper' &&
|
||||||
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
|
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
|
||||||
className,
|
className,
|
||||||
@@ -70,7 +70,7 @@ function SelectContent({
|
|||||||
className={cn(
|
className={cn(
|
||||||
'p-1',
|
'p-1',
|
||||||
position === 'popper' &&
|
position === 'popper' &&
|
||||||
'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1',
|
'h-(--radix-select-trigger-height) w-full min-w-(--radix-select-trigger-width) scroll-my-1',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
@@ -100,7 +100,7 @@ function SelectItem({
|
|||||||
<SelectPrimitive.Item
|
<SelectPrimitive.Item
|
||||||
data-slot="select-item"
|
data-slot="select-item"
|
||||||
className={cn(
|
className={cn(
|
||||||
"relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
"relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||||
className,
|
className,
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
@@ -1,25 +1,31 @@
|
|||||||
'use client';
|
"use client"
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from "react"
|
||||||
import * as SheetPrimitive from '@radix-ui/react-dialog';
|
import { XIcon } from "lucide-react"
|
||||||
import { XIcon } from 'lucide-react';
|
import { Dialog as SheetPrimitive } from "radix-ui"
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {
|
function Sheet({ ...props }: React.ComponentProps<typeof SheetPrimitive.Root>) {
|
||||||
return <SheetPrimitive.Root data-slot="sheet" {...props} />;
|
return <SheetPrimitive.Root data-slot="sheet" {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function SheetTrigger({ ...props }: React.ComponentProps<typeof SheetPrimitive.Trigger>) {
|
function SheetTrigger({
|
||||||
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />;
|
...props
|
||||||
|
}: React.ComponentProps<typeof SheetPrimitive.Trigger>) {
|
||||||
|
return <SheetPrimitive.Trigger data-slot="sheet-trigger" {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function SheetClose({ ...props }: React.ComponentProps<typeof SheetPrimitive.Close>) {
|
function SheetClose({
|
||||||
return <SheetPrimitive.Close data-slot="sheet-close" {...props} />;
|
...props
|
||||||
|
}: React.ComponentProps<typeof SheetPrimitive.Close>) {
|
||||||
|
return <SheetPrimitive.Close data-slot="sheet-close" {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function SheetPortal({ ...props }: React.ComponentProps<typeof SheetPrimitive.Portal>) {
|
function SheetPortal({
|
||||||
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />;
|
...props
|
||||||
|
}: React.ComponentProps<typeof SheetPrimitive.Portal>) {
|
||||||
|
return <SheetPrimitive.Portal data-slot="sheet-portal" {...props} />
|
||||||
}
|
}
|
||||||
|
|
||||||
function SheetOverlay({
|
function SheetOverlay({
|
||||||
@@ -30,21 +36,23 @@ function SheetOverlay({
|
|||||||
<SheetPrimitive.Overlay
|
<SheetPrimitive.Overlay
|
||||||
data-slot="sheet-overlay"
|
data-slot="sheet-overlay"
|
||||||
className={cn(
|
className={cn(
|
||||||
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50',
|
"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function SheetContent({
|
function SheetContent({
|
||||||
className,
|
className,
|
||||||
children,
|
children,
|
||||||
side = 'right',
|
side = "right",
|
||||||
|
showCloseButton = true,
|
||||||
...props
|
...props
|
||||||
}: React.ComponentProps<typeof SheetPrimitive.Content> & {
|
}: React.ComponentProps<typeof SheetPrimitive.Content> & {
|
||||||
side?: 'top' | 'right' | 'bottom' | 'left';
|
side?: "top" | "right" | "bottom" | "left"
|
||||||
|
showCloseButton?: boolean
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<SheetPortal>
|
<SheetPortal>
|
||||||
@@ -52,57 +60,62 @@ function SheetContent({
|
|||||||
<SheetPrimitive.Content
|
<SheetPrimitive.Content
|
||||||
data-slot="sheet-content"
|
data-slot="sheet-content"
|
||||||
className={cn(
|
className={cn(
|
||||||
'bg-background data-[state=open]:animate-in data-[state=closed]:animate-out fixed z-50 flex flex-col gap-4 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500',
|
"fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out data-[state=closed]:animate-out data-[state=closed]:duration-300 data-[state=open]:animate-in data-[state=open]:duration-500",
|
||||||
side === 'right' &&
|
side === "right" &&
|
||||||
'data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right inset-y-0 right-0 h-full w-3/4 border-l sm:max-w-sm',
|
"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm",
|
||||||
side === 'left' &&
|
side === "left" &&
|
||||||
'data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left inset-y-0 left-0 h-full w-3/4 border-r sm:max-w-sm',
|
"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",
|
||||||
side === 'top' &&
|
side === "top" &&
|
||||||
'data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top inset-x-0 top-0 h-auto border-b',
|
"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",
|
||||||
side === 'bottom' &&
|
side === "bottom" &&
|
||||||
'data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom inset-x-0 bottom-0 h-auto border-t',
|
"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",
|
||||||
className,
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
<SheetPrimitive.Close className="ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none">
|
{showCloseButton && (
|
||||||
<XIcon className="size-4" />
|
<SheetPrimitive.Close className="absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-secondary">
|
||||||
<span className="sr-only">Close</span>
|
<XIcon className="size-4" />
|
||||||
</SheetPrimitive.Close>
|
<span className="sr-only">Close</span>
|
||||||
|
</SheetPrimitive.Close>
|
||||||
|
)}
|
||||||
</SheetPrimitive.Content>
|
</SheetPrimitive.Content>
|
||||||
</SheetPortal>
|
</SheetPortal>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function SheetHeader({ className, ...props }: React.ComponentProps<'div'>) {
|
function SheetHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
data-slot="sheet-header"
|
data-slot="sheet-header"
|
||||||
className={cn('flex flex-col gap-1.5 p-4', className)}
|
className={cn("flex flex-col gap-1.5 p-4", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function SheetFooter({ className, ...props }: React.ComponentProps<'div'>) {
|
function SheetFooter({ className, ...props }: React.ComponentProps<"div">) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
data-slot="sheet-footer"
|
data-slot="sheet-footer"
|
||||||
className={cn('mt-auto flex flex-col gap-2 p-4', className)}
|
className={cn("mt-auto flex flex-col gap-2 p-4", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function SheetTitle({ className, ...props }: React.ComponentProps<typeof SheetPrimitive.Title>) {
|
function SheetTitle({
|
||||||
|
className,
|
||||||
|
...props
|
||||||
|
}: React.ComponentProps<typeof SheetPrimitive.Title>) {
|
||||||
return (
|
return (
|
||||||
<SheetPrimitive.Title
|
<SheetPrimitive.Title
|
||||||
data-slot="sheet-title"
|
data-slot="sheet-title"
|
||||||
className={cn('text-foreground font-semibold', className)}
|
className={cn("font-semibold text-foreground", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function SheetDescription({
|
function SheetDescription({
|
||||||
@@ -112,10 +125,10 @@ function SheetDescription({
|
|||||||
return (
|
return (
|
||||||
<SheetPrimitive.Description
|
<SheetPrimitive.Description
|
||||||
data-slot="sheet-description"
|
data-slot="sheet-description"
|
||||||
className={cn('text-muted-foreground text-sm', className)}
|
className={cn("text-sm text-muted-foreground", className)}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
@@ -127,4 +140,4 @@ export {
|
|||||||
SheetFooter,
|
SheetFooter,
|
||||||
SheetTitle,
|
SheetTitle,
|
||||||
SheetDescription,
|
SheetDescription,
|
||||||
};
|
}
|
||||||
|
|||||||
18
src/components/ui/textarea.tsx
Normal file
18
src/components/ui/textarea.tsx
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import * as React from "react"
|
||||||
|
|
||||||
|
import { cn } from "@/lib/utils"
|
||||||
|
|
||||||
|
function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
||||||
|
return (
|
||||||
|
<textarea
|
||||||
|
data-slot="textarea"
|
||||||
|
className={cn(
|
||||||
|
"flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:ring-destructive/40",
|
||||||
|
className
|
||||||
|
)}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Textarea }
|
||||||
@@ -38,7 +38,7 @@ function TreeCheckbox({
|
|||||||
type="checkbox"
|
type="checkbox"
|
||||||
checked={checked}
|
checked={checked}
|
||||||
onChange={(event) => onChange(event.target.checked)}
|
onChange={(event) => onChange(event.target.checked)}
|
||||||
className="size-4 rounded border-border accent-primary"
|
className="size-4 shrink-0 rounded border-border accent-primary"
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -48,11 +48,13 @@ function CheckboxTreeNode<TItem extends TreeItem>({
|
|||||||
selectedIds,
|
selectedIds,
|
||||||
onToggle,
|
onToggle,
|
||||||
renderMeta,
|
renderMeta,
|
||||||
|
showDescription = true,
|
||||||
}: {
|
}: {
|
||||||
item: TItem;
|
item: TItem;
|
||||||
selectedIds: Set<number>;
|
selectedIds: Set<number>;
|
||||||
onToggle: (item: TItem, checked: boolean) => void;
|
onToggle: (item: TItem, checked: boolean) => void;
|
||||||
renderMeta?: (item: TItem) => ReactNode;
|
renderMeta?: (item: TItem) => ReactNode;
|
||||||
|
showDescription?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const [isExpanded, setIsExpanded] = useState(true);
|
const [isExpanded, setIsExpanded] = useState(true);
|
||||||
const itemIds = collectTreeItemIds(item);
|
const itemIds = collectTreeItemIds(item);
|
||||||
@@ -63,35 +65,35 @@ function CheckboxTreeNode<TItem extends TreeItem>({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<li className="space-y-2">
|
<li className="space-y-2">
|
||||||
<div className="flex items-start gap-2 rounded-md border border-border/60 bg-background px-3 py-2">
|
<div className="rounded-md border border-border/60 bg-background px-3 py-2">
|
||||||
{hasChildren ? (
|
<div className="flex items-center gap-2">
|
||||||
<button
|
{hasChildren ? (
|
||||||
type="button"
|
<button
|
||||||
onClick={() => setIsExpanded((current) => !current)}
|
type="button"
|
||||||
aria-label={isExpanded ? `Collapse ${item.label}` : `Expand ${item.label}`}
|
onClick={() => setIsExpanded((current) => !current)}
|
||||||
className="mt-0.5 inline-flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground transition hover:bg-muted hover:text-foreground"
|
aria-label={isExpanded ? `Collapse ${item.label}` : `Expand ${item.label}`}
|
||||||
>
|
className="inline-flex size-5 shrink-0 items-center justify-center rounded text-muted-foreground transition hover:bg-muted hover:text-foreground"
|
||||||
<ChevronDown
|
>
|
||||||
className={`size-4 transition-transform ${isExpanded ? '' : '-rotate-90'}`}
|
<ChevronDown
|
||||||
/>
|
className={`size-4 transition-transform ${isExpanded ? '' : '-rotate-90'}`}
|
||||||
</button>
|
/>
|
||||||
) : (
|
</button>
|
||||||
<span className="size-5 shrink-0" aria-hidden="true" />
|
) : (
|
||||||
)}
|
<span className="size-5 shrink-0" aria-hidden="true" />
|
||||||
<TreeCheckbox
|
)}
|
||||||
checked={checked}
|
<TreeCheckbox
|
||||||
indeterminate={indeterminate}
|
checked={checked}
|
||||||
onChange={(isChecked) => onToggle(item, isChecked)}
|
indeterminate={indeterminate}
|
||||||
/>
|
onChange={(isChecked) => onToggle(item, isChecked)}
|
||||||
<div className="min-w-0 flex-1 leading-none">
|
/>
|
||||||
<div className="flex min-h-5 flex-wrap items-center gap-2">
|
<div className="flex min-w-0 flex-1 items-center gap-2">
|
||||||
<span className="text-sm font-medium leading-5">{item.label}</span>
|
<span className="truncate text-sm font-medium leading-none">{item.label}</span>
|
||||||
{renderMeta?.(item)}
|
{renderMeta?.(item)}
|
||||||
</div>
|
</div>
|
||||||
{item.description ? (
|
|
||||||
<p className="mt-1 text-xs text-muted-foreground">{item.description}</p>
|
|
||||||
) : null}
|
|
||||||
</div>
|
</div>
|
||||||
|
{showDescription && item.description ? (
|
||||||
|
<p className="mt-1.5 pl-11 text-xs text-muted-foreground">{item.description}</p>
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
{hasChildren && isExpanded ? (
|
{hasChildren && isExpanded ? (
|
||||||
<ul className="ml-5 space-y-2 border-l border-border/70 pl-3">
|
<ul className="ml-5 space-y-2 border-l border-border/70 pl-3">
|
||||||
@@ -102,6 +104,7 @@ function CheckboxTreeNode<TItem extends TreeItem>({
|
|||||||
selectedIds={selectedIds}
|
selectedIds={selectedIds}
|
||||||
onToggle={onToggle}
|
onToggle={onToggle}
|
||||||
renderMeta={renderMeta}
|
renderMeta={renderMeta}
|
||||||
|
showDescription={showDescription}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -116,12 +119,14 @@ export function CheckboxTree<TItem extends TreeItem>({
|
|||||||
onSelectedIdsChange,
|
onSelectedIdsChange,
|
||||||
renderMeta,
|
renderMeta,
|
||||||
emptyMessage = 'No items available.',
|
emptyMessage = 'No items available.',
|
||||||
|
showDescription = true,
|
||||||
}: {
|
}: {
|
||||||
items: TItem[];
|
items: TItem[];
|
||||||
selectedIds: number[];
|
selectedIds: number[];
|
||||||
onSelectedIdsChange: (ids: number[]) => void;
|
onSelectedIdsChange: (ids: number[]) => void;
|
||||||
renderMeta?: (item: TItem) => ReactNode;
|
renderMeta?: (item: TItem) => ReactNode;
|
||||||
emptyMessage?: string;
|
emptyMessage?: string;
|
||||||
|
showDescription?: boolean;
|
||||||
}) {
|
}) {
|
||||||
const selectedSet = useMemo(() => new Set(selectedIds), [selectedIds]);
|
const selectedSet = useMemo(() => new Set(selectedIds), [selectedIds]);
|
||||||
|
|
||||||
@@ -154,6 +159,7 @@ export function CheckboxTree<TItem extends TreeItem>({
|
|||||||
selectedIds={selectedSet}
|
selectedIds={selectedSet}
|
||||||
onToggle={handleToggle}
|
onToggle={handleToggle}
|
||||||
renderMeta={renderMeta}
|
renderMeta={renderMeta}
|
||||||
|
showDescription={showDescription}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user