fix: remove TopBar quick-create button + canAccess fallback in ContactDetail + ContactDetailPage + ContactsList + duplicate import fix
This commit is contained in:
@@ -161,6 +161,13 @@ export function ContactDetail({ contact, loading, onEdit, onDeleted }: ContactDe
|
||||
const toast = useToast();
|
||||
const deleteMutation = useDeleteUnifiedContact();
|
||||
const { hasPermission, hasFieldAccess } = usePermission();
|
||||
const authUser = useAuthStore((state) => state.user);
|
||||
const canAccess = (perm: string): boolean => {
|
||||
if (authUser?.is_system_admin) return true;
|
||||
const perms = authUser?.permissions || [];
|
||||
if (perms.length === 0) return true;
|
||||
return hasPermission(perm);
|
||||
};
|
||||
const createPersonMutation = useCreateContactPerson();
|
||||
const updatePersonMutation = useUpdateContactPerson();
|
||||
const deletePersonMutation = useDeleteContactPerson();
|
||||
@@ -294,10 +301,10 @@ export function ContactDetail({ contact, loading, onEdit, onDeleted }: ContactDe
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 flex-shrink-0">
|
||||
{hasPermission('contacts:write') && onEdit && (
|
||||
{canAccess('contacts:write') && onEdit && (
|
||||
<Button variant="ghost" size="sm" onClick={onEdit}>{t('common.edit')}</Button>
|
||||
)}
|
||||
{hasPermission('contacts:delete') && (
|
||||
{canAccess('contacts:delete') && (
|
||||
<Button variant="ghost" size="sm" onClick={handleDelete} isLoading={deleteMutation.isPending}>{t('common.delete')}</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useLogout } from '@/api/hooks';
|
||||
import { Avatar } from '@/components/ui/Avatar';
|
||||
import { SearchDropdown } from '@/components/shared/SearchDropdown';
|
||||
import { SuggestionBadge } from '@/components/ai/SuggestionBadge';
|
||||
import { Building, ChevronDown, Menu, Zap, Bot, Layers, Code, Plus } from 'lucide-react';
|
||||
import { Building, ChevronDown, Menu, Zap, Bot, Layers, Code } from 'lucide-react';
|
||||
import { NotificationBell } from '@/components/layout/NotificationBell';
|
||||
import { useWindowStore } from '@/store/windowStore';
|
||||
import { usePermission } from '@/hooks/usePermission';
|
||||
@@ -90,18 +90,6 @@ export function TopBar() {
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<NotificationBell />
|
||||
{/* Quick Create */}
|
||||
{canAccess('contacts:write') && (
|
||||
<button
|
||||
onClick={() => navigate('/contacts/new')}
|
||||
className="flex items-center gap-1.5 bg-primary-600 text-white px-3 py-1.5 rounded-md text-sm font-medium hover:bg-primary-700 min-h-touch focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500"
|
||||
aria-label={t('topbar.quickCreate')}
|
||||
title={t('topbar.quickCreate', 'Neuer Kontakt')}
|
||||
>
|
||||
<Plus className="w-4 h-4" aria-hidden="true" strokeWidth={2} />
|
||||
<span className="hidden md:inline">{t('topbar.quickCreate', 'Neu')}</span>
|
||||
</button>
|
||||
)}
|
||||
{/* Minimized windows */}
|
||||
{minimizedWindows.length > 0 && (
|
||||
<div className="flex items-center gap-1.5">
|
||||
|
||||
@@ -13,6 +13,7 @@ import { Button } from '@/components/ui/Button';
|
||||
import { ChevronLeft } from 'lucide-react';
|
||||
import { PrintButton } from '@/components/common/PrintButton';
|
||||
import { usePermission } from '@/hooks/usePermission';
|
||||
import { useAuthStore } from '@/store/authStore';
|
||||
|
||||
export function ContactDetailPage() {
|
||||
const { t } = useTranslation();
|
||||
@@ -21,6 +22,13 @@ export function ContactDetailPage() {
|
||||
const { data: contact, isLoading } = useUnifiedContact(id);
|
||||
const openWindow = useWindowStore((s) => s.openWindow);
|
||||
const { hasPermission } = usePermission();
|
||||
const authUser = useAuthStore((state) => state.user);
|
||||
const canAccess = (perm: string): boolean => {
|
||||
if (authUser?.is_system_admin) return true;
|
||||
const perms = authUser?.permissions || [];
|
||||
if (perms.length === 0) return true;
|
||||
return hasPermission(perm);
|
||||
};
|
||||
|
||||
const handleEdit = () => {
|
||||
if (contact) {
|
||||
@@ -53,13 +61,13 @@ export function ContactDetailPage() {
|
||||
<span>{t('contacts.title')}</span>
|
||||
</button>
|
||||
<div className="flex-1" />
|
||||
{hasPermission('contacts:read') && <PrintButton targetId="contact-detail" />}
|
||||
{canAccess('contacts:read') && <PrintButton targetId="contact-detail" />}
|
||||
</div>
|
||||
<div className="flex-1 overflow-y-auto" id="contact-detail">
|
||||
<ContactDetail
|
||||
contact={contact ?? null}
|
||||
loading={isLoading}
|
||||
onEdit={hasPermission('contacts:write') ? handleEdit : undefined}
|
||||
onEdit={canAccess('contacts:write') ? handleEdit : undefined}
|
||||
onDeleted={handleDeleted}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -36,12 +36,20 @@ import {
|
||||
import { useContactFolders } from '@/api/contacts';
|
||||
import { useCustomFieldDefinitions } from '@/api/customFieldDefinitions';
|
||||
import { usePermission } from '@/hooks/usePermission';
|
||||
import { useAuthStore } from '@/store/authStore';
|
||||
|
||||
const PAGE_SIZE = 25;
|
||||
|
||||
export function ContactsListPage() {
|
||||
const { t } = useTranslation();
|
||||
const { hasPermission } = usePermission();
|
||||
const authUser = useAuthStore((state) => state.user);
|
||||
const canAccess = (perm: string): boolean => {
|
||||
if (authUser?.is_system_admin) return true;
|
||||
const perms = authUser?.permissions || [];
|
||||
if (perms.length === 0) return true;
|
||||
return hasPermission(perm);
|
||||
};
|
||||
|
||||
const [selectedFilter, setSelectedFilter] = useState<ContactFilter>('all');
|
||||
const [search, setSearch] = useState('');
|
||||
@@ -358,7 +366,7 @@ export function ContactsListPage() {
|
||||
useEffect(() => {
|
||||
const items = [
|
||||
// New contact — ganz links
|
||||
...(hasPermission('contacts:write') ? [{
|
||||
...(canAccess('contacts:write') ? [{
|
||||
id: 'new',
|
||||
plugin: 'contacts',
|
||||
label: t('contacts.create'),
|
||||
@@ -457,7 +465,7 @@ export function ContactsListPage() {
|
||||
onClick: () => setSavedFiltersOpen(true),
|
||||
},
|
||||
// Print — icon only, right side
|
||||
...(hasPermission('contacts:read') ? [{
|
||||
...(canAccess('contacts:read') ? [{
|
||||
id: 'print',
|
||||
plugin: 'contacts',
|
||||
label: t('common.print', 'Drucken'),
|
||||
|
||||
Reference in New Issue
Block a user