Enhance receipt display by adding conditional rendering for descriptions and editing capabilities. Introduce a derived state for edit permissions and update UI components to reflect these changes, improving user interaction and information visibility.
This commit is contained in:
@@ -27,7 +27,7 @@ export const load = async ({ locals }: Parameters<PageServerLoad>[0]) => {
|
||||
return [] as StackqReceipt[];
|
||||
});
|
||||
|
||||
return { receipts: list };
|
||||
return { receipts: list, canEdit: isAdmin };
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
@@ -93,11 +93,9 @@ export const actions = {
|
||||
return fail(400, { error: "Invalid status", setStatus: null });
|
||||
}
|
||||
const isAdmin = user.Admin === true;
|
||||
if (!isAdmin) return fail(403, { error: "Only admins can change status.", setStatus: null });
|
||||
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).getOne<StackqReceipt>(id);
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user