Initial commit: ArchiTools modular dashboard platform
Complete Next.js 16 application with 13 fully implemented modules: Email Signature, Word XML Generator, Registratura, Dashboard, Tag Manager, IT Inventory, Address Book, Password Vault, Mini Utilities, Prompt Generator, Digital Signatures, Word Templates, and AI Chat. Includes core platform systems (module registry, feature flags, storage abstraction, i18n, theming, auth stub, tagging), 16 technical documentation files, Docker deployment config, and legacy HTML tool reference. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
103
src/modules/registratura/hooks/use-registry.ts
Normal file
103
src/modules/registratura/hooks/use-registry.ts
Normal file
@@ -0,0 +1,103 @@
|
||||
'use client';
|
||||
|
||||
import { useState, useEffect, useCallback } from 'react';
|
||||
import { useStorage } from '@/core/storage';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import type { RegistryEntry, RegistryEntryType, RegistryEntryStatus } from '../types';
|
||||
import { getAllEntries, saveEntry, deleteEntry, generateRegistryNumber } from '../services/registry-service';
|
||||
|
||||
export interface RegistryFilters {
|
||||
search: string;
|
||||
type: RegistryEntryType | 'all';
|
||||
status: RegistryEntryStatus | 'all';
|
||||
company: string;
|
||||
}
|
||||
|
||||
export function useRegistry() {
|
||||
const storage = useStorage('registratura');
|
||||
const [entries, setEntries] = useState<RegistryEntry[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [filters, setFilters] = useState<RegistryFilters>({
|
||||
search: '',
|
||||
type: 'all',
|
||||
status: 'all',
|
||||
company: 'all',
|
||||
});
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
setLoading(true);
|
||||
const items = await getAllEntries(storage);
|
||||
setEntries(items);
|
||||
setLoading(false);
|
||||
}, [storage]);
|
||||
|
||||
// eslint-disable-next-line react-hooks/set-state-in-effect
|
||||
useEffect(() => { refresh(); }, [refresh]);
|
||||
|
||||
const addEntry = useCallback(async (data: Omit<RegistryEntry, 'id' | 'number' | 'createdAt' | 'updatedAt'>) => {
|
||||
const now = new Date().toISOString();
|
||||
const nextIndex = entries.length + 1;
|
||||
const entry: RegistryEntry = {
|
||||
...data,
|
||||
id: uuid(),
|
||||
number: generateRegistryNumber(data.date, nextIndex),
|
||||
createdAt: now,
|
||||
updatedAt: now,
|
||||
};
|
||||
await saveEntry(storage, entry);
|
||||
await refresh();
|
||||
return entry;
|
||||
}, [storage, refresh, entries.length]);
|
||||
|
||||
const updateEntry = useCallback(async (id: string, updates: Partial<RegistryEntry>) => {
|
||||
const existing = entries.find((e) => e.id === id);
|
||||
if (!existing) return;
|
||||
const updated: RegistryEntry = {
|
||||
...existing,
|
||||
...updates,
|
||||
id: existing.id,
|
||||
number: existing.number,
|
||||
createdAt: existing.createdAt,
|
||||
updatedAt: new Date().toISOString(),
|
||||
};
|
||||
await saveEntry(storage, updated);
|
||||
await refresh();
|
||||
}, [storage, refresh, entries]);
|
||||
|
||||
const removeEntry = useCallback(async (id: string) => {
|
||||
await deleteEntry(storage, id);
|
||||
await refresh();
|
||||
}, [storage, refresh]);
|
||||
|
||||
const updateFilter = useCallback(<K extends keyof RegistryFilters>(key: K, value: RegistryFilters[K]) => {
|
||||
setFilters((prev) => ({ ...prev, [key]: value }));
|
||||
}, []);
|
||||
|
||||
const filteredEntries = entries.filter((entry) => {
|
||||
if (filters.type !== 'all' && entry.type !== filters.type) return false;
|
||||
if (filters.status !== 'all' && entry.status !== filters.status) return false;
|
||||
if (filters.company !== 'all' && entry.company !== filters.company) return false;
|
||||
if (filters.search) {
|
||||
const q = filters.search.toLowerCase();
|
||||
return (
|
||||
entry.subject.toLowerCase().includes(q) ||
|
||||
entry.sender.toLowerCase().includes(q) ||
|
||||
entry.recipient.toLowerCase().includes(q) ||
|
||||
entry.number.includes(q)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
return {
|
||||
entries: filteredEntries,
|
||||
allEntries: entries,
|
||||
loading,
|
||||
filters,
|
||||
updateFilter,
|
||||
addEntry,
|
||||
updateEntry,
|
||||
removeEntry,
|
||||
refresh,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user