Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 'use server'; import { revalidatePath } from 'next/cache'; import { requireSession } from '@/lib/session'; import { canSeeReception } from '@/lib/permissions'; import { logActivity } from '@/lib/activity'; export type ActionState = { error?: string; success?: string }; export async function receiveAtBranchAction(_prev: ActionState, formData: FormData): Promise<ActionState> { const session = await requireSession(); if (!canSeeReception(session.role)) return { error: 'ไม่มีสิทธิ์ใช้งาน' }; const branch = String(formData.get('branch') ?? '').trim(); const data = String(formData.get('data') ?? '').trim(); const note = String(formData.get('note') ?? '').trim(); if (!branch) return { error: 'Missing branch code' }; if (!data) return { error: 'กรุณาใส่ข้อมูลรหัสเฟส' }; await logActivity({ userId: session.sub, action: `reception:${branch}`, detail: note ? `${data.split('\n').length} รายการ — ${note}` : `${data.split('\n').length} รายการ`, }); revalidatePath('/reception'); return { success: `บันทึกการรับสินค้าเข้า ${branch} เรียบร้อย` }; } |