Spaces:
Sleeping
Sleeping
Commit ·
2b4c12e
1
Parent(s): 857fbc2
fix(ui): explicit payer choice, validated settle-up prefill, sticky delete confirm, degraded balances
Browse files
src/lib/components/SettlementForm.svelte
CHANGED
|
@@ -28,6 +28,7 @@
|
|
| 28 |
<div>
|
| 29 |
<label for="from">Who paid</label>
|
| 30 |
<select id="from" name="from" value={values.from}>
|
|
|
|
| 31 |
{#each members as m (m.id)}<option value={m.id}>{m.displayName}</option>{/each}
|
| 32 |
</select>
|
| 33 |
<FormError message={errors.from} />
|
|
|
|
| 28 |
<div>
|
| 29 |
<label for="from">Who paid</label>
|
| 30 |
<select id="from" name="from" value={values.from}>
|
| 31 |
+
<option value="">Choose…</option>
|
| 32 |
{#each members as m (m.id)}<option value={m.id}>{m.displayName}</option>{/each}
|
| 33 |
</select>
|
| 34 |
<FormError message={errors.from} />
|
src/routes/balances/+page.server.ts
CHANGED
|
@@ -14,12 +14,20 @@ export const load: PageServerLoad = ({ locals }) => {
|
|
| 14 |
.map((u) => ({ id: u.id, name: u.displayName, active: u.active, net: nets.get(u.id) ?? 0 }))
|
| 15 |
.sort((a, b) => b.net - a.net || a.name.localeCompare(b.name));
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
return { rows, debts, myNet: nets.get(me.id) ?? 0 };
|
| 25 |
};
|
|
|
|
| 14 |
.map((u) => ({ id: u.id, name: u.displayName, active: u.active, net: nets.get(u.id) ?? 0 }))
|
| 15 |
.sort((a, b) => b.net - a.net || a.name.localeCompare(b.name));
|
| 16 |
|
| 17 |
+
let debts: Array<{ from: string; to: string; cents: number; fromName: string; toName: string; settleHref: string }>;
|
| 18 |
+
let integrityWarning: string | null = null;
|
| 19 |
+
try {
|
| 20 |
+
debts = simplifyDebts(nets).map((d) => ({
|
| 21 |
+
...d,
|
| 22 |
+
fromName: name(d.from),
|
| 23 |
+
toName: name(d.to),
|
| 24 |
+
settleHref: `/settlements/new?from=${encodeURIComponent(d.from)}&to=${encodeURIComponent(d.to)}&amount=${centsToInput(d.cents)}`
|
| 25 |
+
}));
|
| 26 |
+
} catch (err) {
|
| 27 |
+
console.error(err);
|
| 28 |
+
debts = [];
|
| 29 |
+
integrityWarning = 'Balances do not add up — suggested payments are unavailable until the data is repaired.';
|
| 30 |
+
}
|
| 31 |
|
| 32 |
+
return { rows, debts, myNet: nets.get(me.id) ?? 0, integrityWarning };
|
| 33 |
};
|
src/routes/balances/+page.svelte
CHANGED
|
@@ -33,7 +33,11 @@
|
|
| 33 |
<h2 class="mb-2 text-sm font-semibold tracking-wide text-gray-500 uppercase">
|
| 34 |
Suggested payments
|
| 35 |
</h2>
|
| 36 |
-
{#if data.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
<p class="rounded-xl bg-white p-4 text-gray-500 shadow-sm">Nobody owes anything. 🎉</p>
|
| 38 |
{:else}
|
| 39 |
<ul class="divide-y divide-gray-200 rounded-xl bg-white shadow-sm">
|
|
|
|
| 33 |
<h2 class="mb-2 text-sm font-semibold tracking-wide text-gray-500 uppercase">
|
| 34 |
Suggested payments
|
| 35 |
</h2>
|
| 36 |
+
{#if data.integrityWarning}
|
| 37 |
+
<p class="rounded-xl border border-amber-300 bg-amber-50 p-4 text-amber-800" role="alert">
|
| 38 |
+
{data.integrityWarning}
|
| 39 |
+
</p>
|
| 40 |
+
{:else if data.debts.length === 0}
|
| 41 |
<p class="rounded-xl bg-white p-4 text-gray-500 shadow-sm">Nobody owes anything. 🎉</p>
|
| 42 |
{:else}
|
| 43 |
<ul class="divide-y divide-gray-200 rounded-xl bg-white shadow-sm">
|
src/routes/expenses/[id]/+page.svelte
CHANGED
|
@@ -71,7 +71,7 @@
|
|
| 71 |
{#if !confirming}
|
| 72 |
<a href="?confirm" class="block text-center text-red-700">Delete expense</a>
|
| 73 |
{:else}
|
| 74 |
-
<form method="POST" action="?/delete" use:enhance class="flex gap-2">
|
| 75 |
<input type="hidden" name="version" value={e.version} />
|
| 76 |
<button type="submit" class="flex-1 rounded-lg bg-red-700 py-2 font-semibold text-white"
|
| 77 |
>Confirm delete</button
|
|
|
|
| 71 |
{#if !confirming}
|
| 72 |
<a href="?confirm" class="block text-center text-red-700">Delete expense</a>
|
| 73 |
{:else}
|
| 74 |
+
<form method="POST" action="?confirm&/delete" use:enhance class="flex gap-2">
|
| 75 |
<input type="hidden" name="version" value={e.version} />
|
| 76 |
<button type="submit" class="flex-1 rounded-lg bg-red-700 py-2 font-semibold text-white"
|
| 77 |
>Confirm delete</button
|
src/routes/settlements/[id]/+page.svelte
CHANGED
|
@@ -42,7 +42,7 @@
|
|
| 42 |
{#if !confirming}
|
| 43 |
<a href="?confirm" class="block text-center text-red-700">Delete payment</a>
|
| 44 |
{:else}
|
| 45 |
-
<form method="POST" action="?/delete" use:enhance class="flex gap-2">
|
| 46 |
<input type="hidden" name="version" value={s.version} />
|
| 47 |
<button type="submit" class="flex-1 rounded-lg bg-red-700 py-2 font-semibold text-white"
|
| 48 |
>Confirm delete</button
|
|
|
|
| 42 |
{#if !confirming}
|
| 43 |
<a href="?confirm" class="block text-center text-red-700">Delete payment</a>
|
| 44 |
{:else}
|
| 45 |
+
<form method="POST" action="?confirm&/delete" use:enhance class="flex gap-2">
|
| 46 |
<input type="hidden" name="version" value={s.version} />
|
| 47 |
<button type="submit" class="flex-1 rounded-lg bg-red-700 py-2 font-semibold text-white"
|
| 48 |
>Confirm delete</button
|
src/routes/settlements/new/+page.server.ts
CHANGED
|
@@ -8,10 +8,15 @@ import {
|
|
| 8 |
import { fail, redirect } from '@sveltejs/kit';
|
| 9 |
import type { Actions, PageServerLoad } from './$types';
|
| 10 |
|
| 11 |
-
export const load: PageServerLoad = ({ locals, url }) =>
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
export const actions: Actions = {
|
| 17 |
default: async ({ request, locals }) => {
|
|
|
|
| 8 |
import { fail, redirect } from '@sveltejs/kit';
|
| 9 |
import type { Actions, PageServerLoad } from './$types';
|
| 10 |
|
| 11 |
+
export const load: PageServerLoad = ({ locals, url }) => {
|
| 12 |
+
const values = settlementFormFromQuery(url.searchParams, locals.user!.id, today());
|
| 13 |
+
if (!locals.app.users.isActiveMember(values.from)) values.from = '';
|
| 14 |
+
if (!locals.app.users.isActiveMember(values.to)) values.to = '';
|
| 15 |
+
return {
|
| 16 |
+
members: locals.app.users.activeMembers().map(toPublicUser),
|
| 17 |
+
values
|
| 18 |
+
};
|
| 19 |
+
};
|
| 20 |
|
| 21 |
export const actions: Actions = {
|
| 22 |
default: async ({ request, locals }) => {
|