feat: enhance contract template display with user type and improved status badges
This commit is contained in:
parent
35b0abd005
commit
5920104756
@ -13,11 +13,16 @@ type ContractTemplate = {
|
|||||||
name: string;
|
name: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
contract_type?: string | null;
|
contract_type?: string | null;
|
||||||
|
user_type?: string | null;
|
||||||
version: number;
|
version: number;
|
||||||
status: 'draft' | 'published' | 'archived' | string;
|
status: 'draft' | 'published' | 'archived' | string;
|
||||||
updatedAt?: string;
|
updatedAt?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function Pill({ children, className }: { children: React.ReactNode; className: string }) {
|
||||||
|
return <span className={`px-2 py-0.5 rounded text-xs font-semibold border ${className}`}>{children}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
function StatusBadge({ status }: { status: string }) {
|
function StatusBadge({ status }: { status: string }) {
|
||||||
const map: Record<string, string> = {
|
const map: Record<string, string> = {
|
||||||
draft: 'bg-gray-100 text-gray-800 border border-gray-300',
|
draft: 'bg-gray-100 text-gray-800 border border-gray-300',
|
||||||
@ -57,6 +62,7 @@ export default function ContractTemplateList({ refreshKey = 0, onEdit }: Props)
|
|||||||
name: x.name ?? 'Untitled',
|
name: x.name ?? 'Untitled',
|
||||||
type: x.type,
|
type: x.type,
|
||||||
contract_type: x.contract_type ?? x.contractType ?? null,
|
contract_type: x.contract_type ?? x.contractType ?? null,
|
||||||
|
user_type: x.user_type ?? x.userType ?? null,
|
||||||
version: Number(x.version ?? 1),
|
version: Number(x.version ?? 1),
|
||||||
status: (x.state === 'active') ? 'published' : 'draft',
|
status: (x.state === 'active') ? 'published' : 'draft',
|
||||||
updatedAt: x.updatedAt ?? x.modifiedAt ?? x.updated_at,
|
updatedAt: x.updatedAt ?? x.modifiedAt ?? x.updated_at,
|
||||||
@ -94,7 +100,9 @@ export default function ContractTemplateList({ refreshKey = 0, onEdit }: Props)
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const updated = await updateTemplateState(id, target as 'active' | 'inactive');
|
const updated = await updateTemplateState(id, target as 'active' | 'inactive');
|
||||||
|
// Update clicked item immediately, then refresh list to reflect any auto-deactivations.
|
||||||
setItems((prev) => prev.map((i) => i.id === id ? { ...i, status: updated.state === 'active' ? 'published' : 'draft' } : i));
|
setItems((prev) => prev.map((i) => i.id === id ? { ...i, status: updated.state === 'active' ? 'published' : 'draft' } : i));
|
||||||
|
await load();
|
||||||
} catch {}
|
} catch {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -138,10 +146,20 @@ export default function ContractTemplateList({ refreshKey = 0, onEdit }: Props)
|
|||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<p className="font-semibold text-lg text-gray-900 truncate">{c.name}</p>
|
<p className="font-semibold text-lg text-gray-900 truncate">{c.name}</p>
|
||||||
<StatusBadge status={c.status} />
|
<StatusBadge status={c.status} />
|
||||||
{c.type === 'contract' && c.contract_type && (
|
{c.type && (
|
||||||
<span className="px-2 py-0.5 rounded text-xs font-semibold bg-indigo-50 text-indigo-800 border border-indigo-200">
|
<Pill className="bg-slate-50 text-slate-800 border-slate-200">
|
||||||
|
{c.type === 'contract' ? 'Contract' : c.type === 'bill' ? 'Bill' : 'Other'}
|
||||||
|
</Pill>
|
||||||
|
)}
|
||||||
|
{c.type === 'contract' && (
|
||||||
|
<Pill className="bg-indigo-50 text-indigo-800 border-indigo-200">
|
||||||
{c.contract_type === 'gdpr' ? 'GDPR' : 'Contract'}
|
{c.contract_type === 'gdpr' ? 'GDPR' : 'Contract'}
|
||||||
</span>
|
</Pill>
|
||||||
|
)}
|
||||||
|
{c.user_type && (
|
||||||
|
<Pill className="bg-emerald-50 text-emerald-800 border-emerald-200">
|
||||||
|
{c.user_type === 'personal' ? 'Personal' : c.user_type === 'company' ? 'Company' : 'Both'}
|
||||||
|
</Pill>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
<p className="text-xs text-gray-500">Version {c.version}{c.updatedAt ? ` • Updated ${new Date(c.updatedAt).toLocaleString()}` : ''}</p>
|
<p className="text-xs text-gray-500">Version {c.version}{c.updatedAt ? ` • Updated ${new Date(c.updatedAt).toLocaleString()}` : ''}</p>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user