Add receipt status management functionality, allowing users to update receipt statuses through a new server action. Introduce STATUS_OPTIONS for consistent status handling across components. Enhance UI to support status selection and display, improving overall user experience in receipt management.
CI / build (push) Has been skipped
CI / deploy (push) Successful in 1m18s

This commit is contained in:
eewing
2026-02-26 14:26:15 -06:00
parent e3d96b8818
commit c89329dada
7 changed files with 174 additions and 23 deletions
@@ -2,6 +2,7 @@
import { fail } from "@sveltejs/kit";
import type { Actions, PageServerLoad } from "./$types";
import type { StackqReceipt } from "$lib/types/receipts";
import { STATUS_OPTIONS } from "$lib/types/receipts";
import { convertHeicFileToJpegIfNeeded } from "$lib/convert-heic-server";
import { validateImageUpload } from "$lib/validate-image-upload";
@@ -80,5 +81,30 @@ export const actions = {
return { success: true };
},
setStatus: async ({ request, locals }: import('./$types').RequestEvent) => {
const user = locals.user as { id: string; Admin?: boolean } | null;
if (!user?.id) return fail(401, { error: "Not logged in", setStatus: null });
const form = await request.formData();
const id = (form.get("id") as string)?.trim();
const Status = (form.get("Status") as string)?.trim() || "New";
if (!id) return fail(400, { error: "Missing receipt id", setStatus: null });
if (!STATUS_OPTIONS.includes(Status as (typeof STATUS_OPTIONS)[number])) {
return fail(400, { error: "Invalid status", setStatus: null });
}
const isAdmin = user.Admin === true;
try {
const existing = await locals.pb.collection(COLLECTION).getOne<StackqReceipt>(id);
if (!isAdmin && existing.User !== user.id) {
return fail(404, { error: "Receipt not found", setStatus: null });
}
await locals.pb.collection(COLLECTION).update(id, { Status });
} catch (e: unknown) {
const is404 = e && typeof e === "object" && "status" in e && (e as { status: number }).status === 404;
if (is404) return fail(404, { error: "Receipt not found", setStatus: null });
return fail(500, { error: "Failed to update status", setStatus: null });
}
return { success: true, setStatus: id };
},
};
;null as any as Actions;