sprint2: frontend permission checks for ContactDetail + ContactsList + Field-Level UI
This commit is contained in:
@@ -15,6 +15,7 @@ import { useAIUIControlStore } from '@/store/aiUIControlStore';
|
||||
import { PluginPage } from '@/components/plugins/PluginLoader';
|
||||
import { useAuthStore } from '@/store/authStore';
|
||||
import { CustomFieldRenderer } from '@/components/contacts/CustomFieldRenderer';
|
||||
import { usePermission } from '@/hooks/usePermission';
|
||||
import { TagBadge } from '@/components/tags/TagBadge';
|
||||
import { EntityHistoryPanel } from '@/components/common/EntityHistoryPanel';
|
||||
import { useCustomFields } from '@/api/customFields';
|
||||
@@ -30,13 +31,19 @@ import {
|
||||
export interface ContactDetailProps {
|
||||
contact: UnifiedContact | null;
|
||||
loading?: boolean;
|
||||
onEdit: () => void;
|
||||
onEdit?: () => void;
|
||||
onDeleted: () => void;
|
||||
}
|
||||
|
||||
function Field({ label, value }: { label: string; value?: string | null }) {
|
||||
function Field({ label, value, fieldName }: { label: string; value?: string | null; fieldName?: string }) {
|
||||
const { hasFieldAccess } = usePermission();
|
||||
if (fieldName) {
|
||||
const access = hasFieldAccess('contacts', fieldName);
|
||||
if (access === 'hidden') return null;
|
||||
}
|
||||
const isReadonly = fieldName ? hasFieldAccess('contacts', fieldName) === 'readonly' : false;
|
||||
return (
|
||||
<div>
|
||||
<div className={isReadonly ? 'opacity-50 pointer-events-none' : ''}>
|
||||
<dt className="text-xs font-medium text-secondary-500">{label}</dt>
|
||||
<dd className="text-sm text-secondary-900">{value || '—'}</dd>
|
||||
</div>
|
||||
@@ -153,6 +160,7 @@ export function ContactDetail({ contact, loading, onEdit, onDeleted }: ContactDe
|
||||
const { t } = useTranslation();
|
||||
const toast = useToast();
|
||||
const deleteMutation = useDeleteUnifiedContact();
|
||||
const { hasPermission, hasFieldAccess } = usePermission();
|
||||
const createPersonMutation = useCreateContactPerson();
|
||||
const updatePersonMutation = useUpdateContactPerson();
|
||||
const deletePersonMutation = useDeleteContactPerson();
|
||||
@@ -286,8 +294,12 @@ export function ContactDetail({ contact, loading, onEdit, onDeleted }: ContactDe
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 flex-shrink-0">
|
||||
<Button variant="ghost" size="sm" onClick={onEdit}>{t('common.edit')}</Button>
|
||||
<Button variant="ghost" size="sm" onClick={handleDelete} isLoading={deleteMutation.isPending}>{t('common.delete')}</Button>
|
||||
{hasPermission('contacts:write') && onEdit && (
|
||||
<Button variant="ghost" size="sm" onClick={onEdit}>{t('common.edit')}</Button>
|
||||
)}
|
||||
{hasPermission('contacts:delete') && (
|
||||
<Button variant="ghost" size="sm" onClick={handleDelete} isLoading={deleteMutation.isPending}>{t('common.delete')}</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -378,52 +390,52 @@ export function ContactDetail({ contact, loading, onEdit, onDeleted }: ContactDe
|
||||
{/* Communication */}
|
||||
<Section title={t('contacts.communication')}>
|
||||
<dl className="grid grid-cols-2 gap-3">
|
||||
<Field label={t('contacts.phone') + ' 1'} value={contact.phone_1} />
|
||||
<Field label={t('contacts.phone') + ' 2'} value={contact.phone_2} />
|
||||
<Field label={t('contacts.email') + ' 1'} value={contact.email_1} />
|
||||
<Field label={t('contacts.email') + ' 2'} value={contact.email_2} />
|
||||
<Field label={t('contacts.website')} value={contact.website} />
|
||||
<Field label={t('contacts.phone') + ' 1'} value={contact.phone_1} fieldName="phone_1" />
|
||||
<Field label={t('contacts.phone') + ' 2'} value={contact.phone_2} fieldName="phone_2" />
|
||||
<Field label={t('contacts.email') + ' 1'} value={contact.email_1} fieldName="email_1" />
|
||||
<Field label={t('contacts.email') + ' 2'} value={contact.email_2} fieldName="email_2" />
|
||||
<Field label={t('contacts.website')} value={contact.website} fieldName="website" />
|
||||
</dl>
|
||||
</Section>
|
||||
|
||||
{/* Financial */}
|
||||
<Section title={t('contacts.financial')}>
|
||||
<dl className="grid grid-cols-2 gap-3">
|
||||
<Field label={t('contacts.vatCode')} value={contact.vat_code} />
|
||||
<Field label={t('contacts.fiscalCode')} value={contact.fiscal_code} />
|
||||
<Field label={t('contacts.commerceCode')} value={contact.commerce_code} />
|
||||
<Field label={t('contacts.purchaseNumber')} value={contact.purchase_number} />
|
||||
<Field label={t('contacts.bic')} value={contact.bic} />
|
||||
<Field label={t('contacts.bankAccount')} value={contact.bank_account} />
|
||||
<Field label={t('contacts.vatCode')} value={contact.vat_code} fieldName="vat_code" />
|
||||
<Field label={t('contacts.fiscalCode')} value={contact.fiscal_code} fieldName="fiscal_code" />
|
||||
<Field label={t('contacts.commerceCode')} value={contact.commerce_code} fieldName="commerce_code" />
|
||||
<Field label={t('contacts.purchaseNumber')} value={contact.purchase_number} fieldName="purchase_number" />
|
||||
<Field label={t('contacts.bic')} value={contact.bic} fieldName="bic" />
|
||||
<Field label={t('contacts.bankAccount')} value={contact.bank_account} fieldName="bank_account" />
|
||||
</dl>
|
||||
</Section>
|
||||
|
||||
{/* Discounts */}
|
||||
<Section title={t('contacts.discounts')}>
|
||||
<dl className="grid grid-cols-3 gap-3">
|
||||
<Field label={t('contacts.discountCrew')} value={contact.discount_crew ? String(contact.discount_crew) : '0'} />
|
||||
<Field label={t('contacts.discountTransport')} value={contact.discount_transport ? String(contact.discount_transport) : '0'} />
|
||||
<Field label={t('contacts.discountRental')} value={contact.discount_rental ? String(contact.discount_rental) : '0'} />
|
||||
<Field label={t('contacts.discountSale')} value={contact.discount_sale ? String(contact.discount_sale) : '0'} />
|
||||
<Field label={t('contacts.discountSubrent')} value={contact.discount_subrent ? String(contact.discount_subrent) : '0'} />
|
||||
<Field label={t('contacts.discountTotal')} value={contact.discount_total ? String(contact.discount_total) : '0'} />
|
||||
<Field label={t('contacts.discountCrew')} value={contact.discount_crew ? String(contact.discount_crew) : '0'} fieldName="discount_crew" />
|
||||
<Field label={t('contacts.discountTransport')} value={contact.discount_transport ? String(contact.discount_transport) : '0'} fieldName="discount_transport" />
|
||||
<Field label={t('contacts.discountRental')} value={contact.discount_rental ? String(contact.discount_rental) : '0'} fieldName="discount_rental" />
|
||||
<Field label={t('contacts.discountSale')} value={contact.discount_sale ? String(contact.discount_sale) : '0'} fieldName="discount_sale" />
|
||||
<Field label={t('contacts.discountSubrent')} value={contact.discount_subrent ? String(contact.discount_subrent) : '0'} fieldName="discount_subrent" />
|
||||
<Field label={t('contacts.discountTotal')} value={contact.discount_total ? String(contact.discount_total) : '0'} fieldName="discount_total" />
|
||||
</dl>
|
||||
</Section>
|
||||
|
||||
{/* Geo */}
|
||||
<Section title={t('contacts.geo')}>
|
||||
<dl className="grid grid-cols-2 gap-3">
|
||||
<Field label={t('contacts.latitude')} value={contact.latitude != null ? String(contact.latitude) : null} />
|
||||
<Field label={t('contacts.longitude')} value={contact.longitude != null ? String(contact.longitude) : null} />
|
||||
<Field label={t('contacts.latitude')} value={contact.latitude != null ? String(contact.latitude) : null} fieldName="latitude" />
|
||||
<Field label={t('contacts.longitude')} value={contact.longitude != null ? String(contact.longitude) : null} fieldName="longitude" />
|
||||
</dl>
|
||||
</Section>
|
||||
|
||||
{/* Notes & Tags */}
|
||||
<Section title={t('contacts.notes')}>
|
||||
<dl className="space-y-3">
|
||||
<Field label={t('contacts.projectnote')} value={contact.projectnote} />
|
||||
<Field label={t('contacts.projectnoteTitle')} value={contact.projectnote_title} />
|
||||
<Field label={t('contacts.contactWarning')} value={contact.contact_warning} />
|
||||
<Field label={t('contacts.projectnote')} value={contact.projectnote} fieldName="projectnote" />
|
||||
<Field label={t('contacts.projectnoteTitle')} value={contact.projectnote_title} fieldName="projectnote_title" />
|
||||
<Field label={t('contacts.contactWarning')} value={contact.contact_warning} fieldName="contact_warning" />
|
||||
<div>
|
||||
<dt className="text-xs font-medium text-secondary-500">{t('tags.title')}</dt>
|
||||
<dd>
|
||||
|
||||
Reference in New Issue
Block a user