fix: remove TopBar quick-create button + canAccess fallback in ContactDetail + ContactDetailPage + ContactsList + duplicate import fix
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user