dstpabuaran.com/resources/js/lib/restock-draft.ts
Yoga Pangestu cf0e772159 feat: implement restock management functionality
- Add RestockIndex component for displaying and managing restocks.
- Create RestockCardRow component for rendering individual restock items.
- Implement RestockItemSubRow component for displaying detailed item information.
- Define routes for restock management in web.php.
- Create RestockTest to cover various scenarios for restock creation, updating, and deletion.
- Ensure proper handling of permissions for restock actions.
- Add validation for restock data and ensure correct relationships are maintained.
2026-08-02 22:34:10 +07:00

68 lines
1.4 KiB
TypeScript

const DRAFT_PREFIX = 'restock-draft';
export type RestockDraftData = {
stockType: 'good' | 'reject';
selectedProductId: string;
quantities: Record<string, number>;
notes: string;
photo?: string;
};
function getKey(type: 'create' | 'edit', userId?: number): string {
if (type === 'edit') {
return `${DRAFT_PREFIX}-edit-${userId ?? 'anon'}`;
}
return `${DRAFT_PREFIX}-create-${userId ?? 'anon'}`;
}
export function saveRestockDraft(
type: 'create' | 'edit',
data: RestockDraftData,
userId?: number,
): boolean {
if (type !== 'create') {
return false;
}
try {
const key = getKey(type, userId);
localStorage.setItem(key, JSON.stringify(data));
return true;
} catch {
return false;
}
}
export function loadRestockDraft(
type: 'create' | 'edit',
userId?: number,
): RestockDraftData | null {
try {
const key = getKey(type, userId);
const raw = localStorage.getItem(key);
if (!raw) {
return null;
}
return JSON.parse(raw) as RestockDraftData;
} catch {
return null;
}
}
export function clearRestockDraft(
type: 'create' | 'edit',
userId?: number,
): void {
try {
const key = getKey(type, userId);
localStorage.removeItem(key);
} catch {
// ignore
}
}