feat(digital-signatures): add version history, expiration tracking, and metadata fields

- Version history with add-version dialog and history display
- Expiration date with expired/expiring-soon visual indicators
- Legal status and usage notes fields
- Delete confirmation dialog
- updatedAt timestamp support
- Image preview in version history

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Marius Tarau
2026-02-18 06:35:42 +02:00
parent c3abbf1c4b
commit 455d95a8c6
4 changed files with 178 additions and 16 deletions

View File

@@ -3,7 +3,7 @@
import { useState, useEffect, useCallback } from 'react';
import { useStorage } from '@/core/storage';
import { v4 as uuid } from 'uuid';
import type { SignatureAsset, SignatureAssetType } from '../types';
import type { SignatureAsset, SignatureAssetType, AssetVersion } from '../types';
const PREFIX = 'sig:';
@@ -36,8 +36,9 @@ export function useSignatures() {
// eslint-disable-next-line react-hooks/set-state-in-effect
useEffect(() => { refresh(); }, [refresh]);
const addAsset = useCallback(async (data: Omit<SignatureAsset, 'id' | 'createdAt'>) => {
const asset: SignatureAsset = { ...data, id: uuid(), createdAt: new Date().toISOString() };
const addAsset = useCallback(async (data: Omit<SignatureAsset, 'id' | 'createdAt' | 'updatedAt'>) => {
const now = new Date().toISOString();
const asset: SignatureAsset = { ...data, id: uuid(), createdAt: now, updatedAt: now };
await storage.set(`${PREFIX}${asset.id}`, asset);
await refresh();
return asset;
@@ -46,11 +47,23 @@ export function useSignatures() {
const updateAsset = useCallback(async (id: string, updates: Partial<SignatureAsset>) => {
const existing = assets.find((a) => a.id === id);
if (!existing) return;
const updated = { ...existing, ...updates, id: existing.id, createdAt: existing.createdAt };
const updated: SignatureAsset = {
...existing, ...updates,
id: existing.id, createdAt: existing.createdAt,
updatedAt: new Date().toISOString(),
};
await storage.set(`${PREFIX}${id}`, updated);
await refresh();
}, [storage, refresh, assets]);
const addVersion = useCallback(async (assetId: string, imageUrl: string, notes: string) => {
const existing = assets.find((a) => a.id === assetId);
if (!existing) return;
const version: AssetVersion = { id: uuid(), imageUrl, notes, createdAt: new Date().toISOString() };
const updatedVersions = [...existing.versions, version];
await updateAsset(assetId, { imageUrl, versions: updatedVersions });
}, [assets, updateAsset]);
const removeAsset = useCallback(async (id: string) => {
await storage.delete(`${PREFIX}${id}`);
await refresh();
@@ -69,5 +82,5 @@ export function useSignatures() {
return true;
});
return { assets: filteredAssets, allAssets: assets, loading, filters, updateFilter, addAsset, updateAsset, removeAsset, refresh };
return { assets: filteredAssets, allAssets: assets, loading, filters, updateFilter, addAsset, updateAsset, addVersion, removeAsset, refresh };
}