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 { ChevronRight, Folder, MoreVertical, Palette, Pencil, Pin, Plus, Shield, Tag, Trash2, Users } from 'lucide-react';
|
||||
import { FolderPermissionDialog } from './FolderPermissionDialog';
|
||||
import { useToast } from '@/components/ui/Toast';
|
||||
|
||||
export type ContactFilter = 'all' | 'company' | 'person' | `tag:${string}` | `folder:${string}`;
|
||||
|
||||
@@ -267,6 +268,7 @@ export function ContactFolderTree({
|
||||
onMultiSelectChange,
|
||||
}: ContactFolderTreeProps) {
|
||||
const { t } = useTranslation();
|
||||
const toast = useToast();
|
||||
const [tagsOpen, setTagsOpen] = useState(true);
|
||||
const [dropdown, setDropdown] = useState<DropdownState | null>(null);
|
||||
const [colorPicker, setColorPicker] = useState<{ folderId: string; color: string } | null>(null);
|
||||
@@ -303,19 +305,34 @@ export function ContactFolderTree({
|
||||
const handleNewFolder = () => {
|
||||
const name = prompt('Ordnername:');
|
||||
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 folder = folderList.find((f) => f.id === id);
|
||||
const newName = prompt('Neuer Name:', folder?.name || '');
|
||||
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) => {
|
||||
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) => {
|
||||
|
||||
@@ -45,6 +45,7 @@ export function ContactsListPage() {
|
||||
const { hasPermission } = usePermission();
|
||||
const authUser = useAuthStore((state) => state.user);
|
||||
const canAccess = (perm: string): boolean => {
|
||||
if (!authUser?.permissions && authUser?.is_system_admin === undefined) return true;
|
||||
return hasPermission(perm);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user