feat: settings page update

This commit is contained in:
ivannoskov
2026-02-02 21:29:06 +03:00
parent 735077e707
commit 233bdf7907
6 changed files with 140 additions and 112 deletions

View File

@@ -226,10 +226,10 @@ export function FiltersModal({
<DialogHeader>
<DialogTitle className="flex items-center gap-2">
<Filter className="h-5 w-5" />
Фильтры
Фильтры и сортировка
</DialogTitle>
<DialogDescription>
Настройте фильтры для каналов и размещений
Настройте фильтры и сортировку для каналов и размещений
</DialogDescription>
</DialogHeader>
@@ -254,7 +254,6 @@ export function FiltersModal({
: "border-transparent text-muted-foreground hover:text-foreground"
)}
>
<ArrowUpDown className="h-4 w-4" />
Размещения
</button>
</div>
@@ -553,84 +552,87 @@ export function FiltersModal({
</div>
</div>
<div className="space-y-3 pt-2 border-t">
<Label className="text-sm font-medium flex items-center gap-2">
<ArrowUpDown className="h-4 w-4" />
Сортировка внутри каналов
</Label>
<div className="flex gap-2 items-center">
<Select
value={filters.sort?.field || ""}
onValueChange={(field) =>
setFilters({
...filters,
sort: filters.sort
? { ...filters.sort, field }
: { field, direction: "asc" },
})
}
>
<SelectTrigger className="h-8 text-sm w-48">
<SelectValue placeholder="Без сортировки" />
</SelectTrigger>
<SelectContent>
{PLACEMENT_SORT_FIELDS.map((field) => (
<SelectItem key={field.key} value={field.key}>
{field.label}
</SelectItem>
))}
</SelectContent>
</Select>
{filters.sort && (
<div className="flex gap-1 p-0.5 border rounded-md">
<button
onClick={() =>
setFilters({
...filters,
sort: { ...filters.sort!, direction: "asc" },
})
}
className={cn(
"flex items-center justify-center px-3 py-1 rounded-sm transition-colors text-xs",
filters.sort.direction === "asc"
? "bg-primary text-primary-foreground"
: "hover:bg-muted"
)}
title="По возрастанию"
>
<ArrowUp className="h-3 w-3 mr-1" />
А-Я
</button>
<button
onClick={() =>
setFilters({
...filters,
sort: { ...filters.sort!, direction: "desc" },
})
}
className={cn(
"flex items-center justify-center px-3 py-1 rounded-sm transition-colors text-xs",
filters.sort.direction === "desc"
? "bg-primary text-primary-foreground"
: "hover:bg-muted"
)}
title="По убыванию"
>
<ArrowDown className="h-3 w-3 mr-1" />
Я-А
</button>
</div>
)}
{filters.sort && (
<button
onClick={() =>
setFilters({ ...filters, sort: null })
<div className="pt-4 mt-4 border-t">
<div className="flex items-center gap-2 mb-3">
<ArrowUpDown className="h-4 w-4 text-muted-foreground" />
<h3 className="text-sm font-semibold">Сортировка</h3>
</div>
<div className="space-y-3">
<Label className="text-xs text-muted-foreground">Сортировать размещения внутри каналов</Label>
<div className="flex gap-2 items-center">
<Select
value={filters.sort?.field || ""}
onValueChange={(field) =>
setFilters({
...filters,
sort: filters.sort
? { ...filters.sort, field }
: { field, direction: "asc" },
})
}
className="text-xs text-muted-foreground hover:text-foreground underline"
>
Сбросить
</button>
)}
<SelectTrigger className="h-8 text-sm w-48">
<SelectValue placeholder="Без сортировки" />
</SelectTrigger>
<SelectContent>
{PLACEMENT_SORT_FIELDS.map((field) => (
<SelectItem key={field.key} value={field.key}>
{field.label}
</SelectItem>
))}
</SelectContent>
</Select>
{filters.sort && (
<div className="flex gap-1 p-0.5 border rounded-md">
<button
onClick={() =>
setFilters({
...filters,
sort: { ...filters.sort!, direction: "asc" },
})
}
className={cn(
"flex items-center justify-center px-3 py-1 rounded-sm transition-colors text-xs",
filters.sort.direction === "asc"
? "bg-primary text-primary-foreground"
: "hover:bg-muted"
)}
title="По возрастанию"
>
<ArrowUp className="h-3 w-3 mr-1" />
А-Я
</button>
<button
onClick={() =>
setFilters({
...filters,
sort: { ...filters.sort!, direction: "desc" },
})
}
className={cn(
"flex items-center justify-center px-3 py-1 rounded-sm transition-colors text-xs",
filters.sort.direction === "desc"
? "bg-primary text-primary-foreground"
: "hover:bg-muted"
)}
title="По убыванию"
>
<ArrowDown className="h-3 w-3 mr-1" />
Я-А
</button>
</div>
)}
{filters.sort && (
<button
onClick={() =>
setFilters({ ...filters, sort: null })
}
className="text-xs text-muted-foreground hover:text-foreground underline"
>
Сбросить
</button>
)}
</div>
</div>
</div>
</div>

View File

@@ -100,7 +100,7 @@ interface NavItem {
url: string;
icon?: LucideIcon;
isActive?: boolean;
requiredPermission?: "projects_read" | "placements_read" | "analytics_read" | "admin_full";
requiredPermission?: "admin_full" | "projects_read" | "projects_write" | "creatives_read" | "creatives_write" | "placements_read" | "placements_write" | "analytics_read" | "analytics_without_clicks" | "analytics_own_creatives";
tooltip?: string;
items?: {
title: string;
@@ -404,8 +404,8 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
});
}
// 5. Аналитика — только подразделы
if (hasPermission("analytics_read")) {
// 5. Аналитика — проверяем любой из аналитических доступов
if (hasPermission("analytics_read") || hasPermission("analytics_without_clicks") || hasPermission("analytics_own_creatives")) {
items.push({
title: "Аналитика",
url: buildRoute.analytics(workspaceId),

View File

@@ -53,7 +53,7 @@ interface WorkspaceContextType {
// Permissions
permissions: Permission[];
hasPermission: (key: PermissionKey, projectId?: string) => boolean;
hasPermission: (key: PermissionKey, projectId?: string, creativeId?: string, placementId?: string) => boolean;
isAdmin: boolean;
// Check if user is admin in a specific workspace
isWorkspaceAdmin: (workspaceId: string) => Promise<boolean>;
@@ -141,7 +141,7 @@ export const WorkspaceProvider: React.FC<WorkspaceProviderProps> = ({
const isAdmin = permissions.some((p) => p.key === "admin_full");
const hasPermission = useCallback(
(key: PermissionKey, projectId?: string): boolean => {
(key: PermissionKey, projectId?: string, creativeId?: string, placementId?: string): boolean => {
// Admin has all permissions
if (isAdmin) return true;
@@ -154,13 +154,30 @@ export const WorkspaceProvider: React.FC<WorkspaceProviderProps> = ({
// If projectId provided, check if it's in scopes
if (projectId) {
return permission.scopes.some(
const hasProjectScope = permission.scopes.some(
(s) => s.type === "project" && s.id === projectId
);
if (hasProjectScope) return true;
}
// Permission exists but is scoped - need projectId to verify
return true;
// If creativeId provided, check if it's in scopes
if (creativeId) {
const hasCreativeScope = permission.scopes.some(
(s) => s.type === "creative" && s.id === creativeId
);
if (hasCreativeScope) return true;
}
// If placementId provided, check if it's in scopes
if (placementId) {
const hasPlacementScope = permission.scopes.some(
(s) => s.type === "placement" && s.id === placementId
);
if (hasPlacementScope) return true;
}
// Permission exists but is scoped and no matching scope found
return false;
},
[permissions, isAdmin]
);