fix: ContactsList canAccess fallback + ContactFolderTree error handling with toast
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
|||||||
import { buildFolderTree, type ContactFolderTreeNode, type ContactFolder } from '@/api/contactFolders';
|
import { buildFolderTree, type ContactFolderTreeNode, type ContactFolder } from '@/api/contactFolders';
|
||||||
import { ChevronRight, Folder, MoreVertical, Palette, Pencil, Pin, Plus, Shield, Tag, Trash2, Users } from 'lucide-react';
|
import { ChevronRight, Folder, MoreVertical, Palette, Pencil, Pin, Plus, Shield, Tag, Trash2, Users } from 'lucide-react';
|
||||||
import { FolderPermissionDialog } from './FolderPermissionDialog';
|
import { FolderPermissionDialog } from './FolderPermissionDialog';
|
||||||
|
import { useToast } from '@/components/ui/Toast';
|
||||||
|
|
||||||
export type ContactFilter = 'all' | 'company' | 'person' | `tag:${string}` | `folder:${string}`;
|
export type ContactFilter = 'all' | 'company' | 'person' | `tag:${string}` | `folder:${string}`;
|
||||||
|
|
||||||
@@ -267,6 +268,7 @@ export function ContactFolderTree({
|
|||||||
onMultiSelectChange,
|
onMultiSelectChange,
|
||||||
}: ContactFolderTreeProps) {
|
}: ContactFolderTreeProps) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const toast = useToast();
|
||||||
const [tagsOpen, setTagsOpen] = useState(true);
|
const [tagsOpen, setTagsOpen] = useState(true);
|
||||||
const [dropdown, setDropdown] = useState<DropdownState | null>(null);
|
const [dropdown, setDropdown] = useState<DropdownState | null>(null);
|
||||||
const [colorPicker, setColorPicker] = useState<{ folderId: string; color: string } | null>(null);
|
const [colorPicker, setColorPicker] = useState<{ folderId: string; color: string } | null>(null);
|
||||||
@@ -303,19 +305,34 @@ export function ContactFolderTree({
|
|||||||
const handleNewFolder = () => {
|
const handleNewFolder = () => {
|
||||||
const name = prompt('Ordnername:');
|
const name = prompt('Ordnername:');
|
||||||
if (!name) return;
|
if (!name) return;
|
||||||
createFolderMut.mutate({ name });
|
createFolderMut.mutate({ name }, {
|
||||||
|
onError: (err: any) => {
|
||||||
|
const msg = err?.response?.data?.detail?.detail || err?.response?.data?.detail || err?.message || 'Fehler beim Anlegen';
|
||||||
|
toast.error(typeof msg === 'string' ? msg : 'Fehler beim Anlegen des Ordners');
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleRename = (id: string) => {
|
const handleRename = (id: string) => {
|
||||||
const folder = folderList.find((f) => f.id === id);
|
const folder = folderList.find((f) => f.id === id);
|
||||||
const newName = prompt('Neuer Name:', folder?.name || '');
|
const newName = prompt('Neuer Name:', folder?.name || '');
|
||||||
if (!newName) return;
|
if (!newName) return;
|
||||||
updateFolderMut.mutate({ id, data: { name: newName } });
|
updateFolderMut.mutate({ id, data: { name: newName } }, {
|
||||||
|
onError: (err: any) => {
|
||||||
|
const msg = err?.response?.data?.detail?.detail || err?.response?.data?.detail || err?.message || 'Fehler beim Umbenennen';
|
||||||
|
toast.error(typeof msg === 'string' ? msg : 'Fehler beim Umbenennen');
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDelete = (id: string) => {
|
const handleDelete = (id: string) => {
|
||||||
if (!confirm('Ordner l\u00f6schen? Kontakte bleiben erhalten, werden aber keinem Ordner mehr zugeordnet.')) return;
|
if (!confirm('Ordner l\u00f6schen? Kontakte bleiben erhalten, werden aber keinem Ordner mehr zugeordnet.')) return;
|
||||||
deleteFolderMut.mutate(id);
|
deleteFolderMut.mutate(id, {
|
||||||
|
onError: (err: any) => {
|
||||||
|
const msg = err?.response?.data?.detail?.detail || err?.response?.data?.detail || err?.message || 'Fehler beim L\u00f6schen';
|
||||||
|
toast.error(typeof msg === 'string' ? msg : 'Fehler beim L\u00f6schen');
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleColor = (id: string) => {
|
const handleColor = (id: string) => {
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ export function ContactsListPage() {
|
|||||||
const { hasPermission } = usePermission();
|
const { hasPermission } = usePermission();
|
||||||
const authUser = useAuthStore((state) => state.user);
|
const authUser = useAuthStore((state) => state.user);
|
||||||
const canAccess = (perm: string): boolean => {
|
const canAccess = (perm: string): boolean => {
|
||||||
|
if (!authUser?.permissions && authUser?.is_system_admin === undefined) return true;
|
||||||
return hasPermission(perm);
|
return hasPermission(perm);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user