46 lines
1.0 KiB
TypeScript
46 lines
1.0 KiB
TypeScript
import { createDraftStore } from '@/lib/draft-store';
|
|
|
|
export type PurchaseDraftData = {
|
|
name: string;
|
|
unit: string;
|
|
supplierId: string;
|
|
discount: number;
|
|
shippingCost: number;
|
|
notes: string;
|
|
variants: Array<{
|
|
variant: string;
|
|
price: number;
|
|
stock: string;
|
|
photo_keys?: string[];
|
|
}>;
|
|
mode?: 'new' | 'existing';
|
|
selectedMaterialName?: string;
|
|
quantities?: Record<string, string>;
|
|
photo?: string;
|
|
};
|
|
|
|
export const purchaseDraftStore =
|
|
createDraftStore<PurchaseDraftData>('purchase-draft');
|
|
|
|
export function savePurchaseDraft(
|
|
type: 'create' | 'edit',
|
|
data: PurchaseDraftData,
|
|
userId?: number,
|
|
): boolean {
|
|
return purchaseDraftStore.save(type, data, userId);
|
|
}
|
|
|
|
export function loadPurchaseDraft(
|
|
type: 'create' | 'edit',
|
|
userId?: number,
|
|
): PurchaseDraftData | null {
|
|
return purchaseDraftStore.load(type, userId);
|
|
}
|
|
|
|
export function clearPurchaseDraft(
|
|
type: 'create' | 'edit',
|
|
userId?: number,
|
|
): void {
|
|
purchaseDraftStore.clear(type, userId);
|
|
}
|