Refactor receipt handling by removing status options from the server-side logic and simplifying the default status to "New". Update the receipt form to eliminate the status selection, enhancing user experience by focusing on essential fields. Improve image upload handling with WebP conversion support in both receipt creation and editing components.
This commit is contained in:
@@ -5,7 +5,6 @@ import type { StackqReceipt } from "$lib/types/receipts";
|
||||
|
||||
const COLLECTION = "Stackq_Receipts";
|
||||
|
||||
const STATUS_OPTIONS = ["New", "Data Entered", "Reviewed", "Consolidated"] as const;
|
||||
const TYPE_OPTIONS = ["Purchase", "Gas"] as const;
|
||||
|
||||
export const load = async ({ locals }: Parameters<PageServerLoad>[0]) => {
|
||||
@@ -29,13 +28,12 @@ export const actions = {
|
||||
if (!user?.id) return fail(401, { error: "You must be logged in to create a receipt." });
|
||||
|
||||
const form = await request.formData();
|
||||
const Status = (form.get("Status") as string)?.trim() || "New";
|
||||
const Type = (form.get("Type") as string)?.trim() || "Purchase";
|
||||
const imageFile = form.get("Image") as File | null;
|
||||
const hasImage = imageFile && imageFile.size > 0;
|
||||
|
||||
const body: Record<string, unknown> = {
|
||||
Status: STATUS_OPTIONS.includes(Status as (typeof STATUS_OPTIONS)[number]) ? Status : "New",
|
||||
Status: "New",
|
||||
Type: TYPE_OPTIONS.includes(Type as (typeof TYPE_OPTIONS)[number]) ? Type : "Purchase",
|
||||
User: user.id,
|
||||
};
|
||||
@@ -48,7 +46,7 @@ export const actions = {
|
||||
err && typeof err === "object" && "message" in err
|
||||
? String((err as { message: string }).message)
|
||||
: "Failed to create receipt.";
|
||||
return fail(500, { error: message, Status, Type });
|
||||
return fail(500, { error: message, Type });
|
||||
}
|
||||
|
||||
return { success: true };
|
||||
|
||||
Reference in New Issue
Block a user