diff options
| -rw-r--r-- | src/routes/(app)/invoice/[id]/tip/+page.server.ts | 27 | ||||
| -rw-r--r-- | src/routes/(app)/invoice/[id]/tip/+page.svelte | 13 | ||||
| -rw-r--r-- | src/routes/(app)/send/invoice/[id]/+page.server.ts | 6 |
3 files changed, 18 insertions, 28 deletions
diff --git a/src/routes/(app)/invoice/[id]/tip/+page.server.ts b/src/routes/(app)/invoice/[id]/tip/+page.server.ts index 1e159697..23e3a07c 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.server.ts +++ b/src/routes/(app)/invoice/[id]/tip/+page.server.ts @@ -1,6 +1,5 @@ -import invoice from "$lib/invoice"; import getRates from "$lib/rates"; -import { auth, get, post } from "$lib/utils"; +import { auth, fd, get, post } from "$lib/utils"; import { fail, redirect } from "@sveltejs/kit"; export async function load({ cookies, params, parent }) { @@ -15,17 +14,11 @@ export async function load({ cookies, params, parent }) { const trusted = trust.includes(invoice.uid); if (trusted && (pin || !user.haspin)) { let p; - console.log("YE"); try { if (invoice.tip === null && invoice.user.prompt) { - console.log("OHH"); if (user.tip > 0) { invoice.tip = Math.round(invoice.amount * (user.tip / 100)); - invoice = await post( - "/invoice", - { invoice, user: subject }, - auth(cookies), - ); + invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies)); } else { throw new Error("tip"); } @@ -33,7 +26,6 @@ export async function load({ cookies, params, parent }) { p = await post("/payments", { ...invoice, pin }, auth(cookies)); } catch (e) { const { message } = e as Error; - console.log("MSG", message); if (message === "tip") redirect(307, `/invoice/${id}/tip`); fail(400, { message }); } @@ -47,5 +39,18 @@ export async function load({ cookies, params, parent }) { } export const actions = { - default: invoice, + default: async ({ cookies, request }) => { + const form = await fd(request); + const invoice = { + tip: form.tip ?? null, + }; + + const { id } = await post( + `/invoice/${form.id}`, + { invoice }, + auth(cookies), + ); + + redirect(307, `/invoice/${id}`); + }, }; diff --git a/src/routes/(app)/invoice/[id]/tip/+page.svelte b/src/routes/(app)/invoice/[id]/tip/+page.svelte index 4f0f306f..a1ea3586 100644 --- a/src/routes/(app)/invoice/[id]/tip/+page.svelte +++ b/src/routes/(app)/invoice/[id]/tip/+page.svelte @@ -97,19 +97,8 @@ <div class="container px-4 max-w-lg text-center mx-auto"> <form method="POST" use:enhance class="space-y-5"> - <input type="hidden" name="aid" value={aid} /> - <input type="hidden" name="amount" value={amount} /> + <input type="hidden" name="id" value={id} /> <input type="hidden" name="tip" value={tip} /> - <input type="hidden" name="username" value={username} /> - <input type="hidden" name="rate" value={invoice.rate} /> - <input type="hidden" name="prompt" value={invoice.prompt} /> - <input type="hidden" name="type" value={type} /> - <input type="hidden" name="hash" value={hash} /> - <input type="hidden" name="items" value={JSON.stringify(items)} /> - - {#if invoice.memoPrompt} - <input type="hidden" name="memoPrompt" value={invoice.memoPrompt} /> - {/if} <h1 class="text-4xl font-semibold my-8">{$t("invoice.addTipq")}</h1> {#if !showCustomAmount} diff --git a/src/routes/(app)/send/invoice/[id]/+page.server.ts b/src/routes/(app)/send/invoice/[id]/+page.server.ts index 38507343..70b007a8 100644 --- a/src/routes/(app)/send/invoice/[id]/+page.server.ts +++ b/src/routes/(app)/send/invoice/[id]/+page.server.ts @@ -18,11 +18,7 @@ export async function load({ cookies, depends, params: { id }, parent }) { if (!invoice.tip && invoice.user.prompt) { if (user.tip > 0) { invoice.tip = Math.round(invoice.amount * (user.tip / 100)); - invoice = await post( - "/invoice", - { invoice, user: subject }, - auth(cookies), - ); + invoice = await post(`/invoice/${id}`, { invoice }, auth(cookies)); } else { throw new Error("tip"); } |
