feat: implement delete confirmation dialog component for better UX refactor: update supplier and role index pages to utilize new form dialog and delete confirm dialog components feat: add reusable form dialog component for creating and editing entities feat: introduce filter popover component for enhanced filtering options in data tables feat: create image preview button component for displaying images with modal preview feat: add page header component for consistent page layout feat: implement row actions component for handling actions on table rows feat: add status badge component for displaying entity statuses feat: create toggle status component for easily toggling entity states feat: implement draft save hook for auto-saving form data feat: add server table hook for managing server-side pagination and filtering feat: create utility functions for formatting dates and numbers feat: add constants for month names and measurement units
63 lines
1.6 KiB
TypeScript
63 lines
1.6 KiB
TypeScript
export type DraftType = 'create' | 'edit';
|
|
|
|
export type DraftStore<D> = {
|
|
save(type: DraftType, data: D, userId?: number, extraId?: number): boolean;
|
|
load(type: DraftType, userId?: number, extraId?: number): D | null;
|
|
clear(type: DraftType, userId?: number, extraId?: number): void;
|
|
};
|
|
|
|
export function createDraftStore<D>(prefix: string): DraftStore<D> {
|
|
function getKey(
|
|
type: DraftType,
|
|
userId?: number,
|
|
extraId?: number,
|
|
): string {
|
|
if (type === 'edit' && extraId) {
|
|
return `${prefix}-edit-${userId ?? 'anon'}-${extraId}`;
|
|
}
|
|
|
|
return `${prefix}-create-${userId ?? 'anon'}`;
|
|
}
|
|
|
|
return {
|
|
save(type, data, userId, extraId) {
|
|
if (type !== 'create') {
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
const key = getKey(type, userId, extraId);
|
|
localStorage.setItem(key, JSON.stringify(data));
|
|
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
},
|
|
|
|
load(type, userId, extraId) {
|
|
try {
|
|
const key = getKey(type, userId, extraId);
|
|
const raw = localStorage.getItem(key);
|
|
|
|
if (!raw) {
|
|
return null;
|
|
}
|
|
|
|
return JSON.parse(raw) as D;
|
|
} catch {
|
|
return null;
|
|
}
|
|
},
|
|
|
|
clear(type, userId, extraId) {
|
|
try {
|
|
const key = getKey(type, userId, extraId);
|
|
localStorage.removeItem(key);
|
|
} catch {
|
|
// ignore
|
|
}
|
|
},
|
|
};
|
|
}
|