diff --git a/src/lib/components/PaymentModal.svelte b/src/lib/components/PaymentModal.svelte
index 0af5747..ede8566 100644
--- a/src/lib/components/PaymentModal.svelte
+++ b/src/lib/components/PaymentModal.svelte
@@ -85,6 +85,34 @@
return `Custom split among ${payment.splits.length} people`;
}
}
+
+ let deleting = false;
+
+ async function deletePayment() {
+ if (!confirm('Are you sure you want to delete this payment? This action cannot be undone.')) {
+ return;
+ }
+
+ try {
+ deleting = true;
+ const response = await fetch(`/api/cospend/payments/${paymentId}`, {
+ method: 'DELETE'
+ });
+
+ if (!response.ok) {
+ throw new Error('Failed to delete payment');
+ }
+
+ // Close modal and dispatch event to refresh data
+ dispatch('paymentDeleted', paymentId);
+ closeModal();
+
+ } catch (err) {
+ error = err.message;
+ } finally {
+ deleting = false;
+ }
+ }
@@ -187,6 +215,13 @@
{#if payment && payment.createdBy === session?.user?.nickname}
Edit Payment
+
{/if}
@@ -462,6 +497,20 @@
background-color: #f5f5f5;
}
+ .btn-danger {
+ background-color: #d32f2f;
+ color: white;
+ }
+
+ .btn-danger:hover:not(:disabled) {
+ background-color: #c62828;
+ }
+
+ .btn-danger:disabled {
+ opacity: 0.6;
+ cursor: not-allowed;
+ }
+
@media (max-width: 600px) {
.payment-header {
flex-direction: column;
diff --git a/src/routes/cospend/payments/edit/[id]/+page.svelte b/src/routes/cospend/payments/edit/[id]/+page.svelte
index 4055393..15ca0c3 100644
--- a/src/routes/cospend/payments/edit/[id]/+page.svelte
+++ b/src/routes/cospend/payments/edit/[id]/+page.svelte
@@ -102,6 +102,33 @@
function formatDate(dateString) {
return new Date(dateString).toISOString().split('T')[0];
}
+
+ let deleting = false;
+
+ async function deletePayment() {
+ if (!confirm('Are you sure you want to delete this payment? This action cannot be undone.')) {
+ return;
+ }
+
+ try {
+ deleting = true;
+ const response = await fetch(`/api/cospend/payments/${data.paymentId}`, {
+ method: 'DELETE'
+ });
+
+ if (!response.ok) {
+ throw new Error('Failed to delete payment');
+ }
+
+ // Redirect to payments list after successful deletion
+ goto('/cospend/payments');
+
+ } catch (err) {
+ error = err.message;
+ } finally {
+ deleting = false;
+ }
+ }
@@ -243,12 +270,22 @@
{/if}
{/if}
@@ -382,11 +419,17 @@
.form-actions {
display: flex;
+ justify-content: space-between;
+ align-items: center;
gap: 1rem;
- justify-content: flex-end;
}
- .btn-primary, .btn-secondary {
+ .main-actions {
+ display: flex;
+ gap: 1rem;
+ }
+
+ .btn-primary, .btn-secondary, .btn-danger {
padding: 0.75rem 1.5rem;
border-radius: 0.5rem;
font-size: 1rem;
@@ -419,6 +462,21 @@
background-color: #e8e8e8;
}
+ .btn-danger {
+ background-color: #d32f2f;
+ color: white;
+ border: none;
+ }
+
+ .btn-danger:hover:not(:disabled) {
+ background-color: #c62828;
+ }
+
+ .btn-danger:disabled {
+ opacity: 0.6;
+ cursor: not-allowed;
+ }
+
.current-image {
margin-bottom: 1rem;
text-align: center;
@@ -502,6 +560,11 @@
.form-actions {
flex-direction: column;
+ align-items: stretch;
+ }
+
+ .main-actions {
+ flex-direction: column;
}
}
\ No newline at end of file
diff --git a/src/routes/cospend/payments/view/[id]/+page.svelte b/src/routes/cospend/payments/view/[id]/+page.svelte
index 814a47a..1cd7571 100644
--- a/src/routes/cospend/payments/view/[id]/+page.svelte
+++ b/src/routes/cospend/payments/view/[id]/+page.svelte
@@ -53,6 +53,33 @@
return `Custom split among ${payment.splits.length} people`;
}
}
+
+ let deleting = false;
+
+ async function deletePayment() {
+ if (!confirm('Are you sure you want to delete this payment? This action cannot be undone.')) {
+ return;
+ }
+
+ try {
+ deleting = true;
+ const response = await fetch(`/api/cospend/payments/${data.paymentId}`, {
+ method: 'DELETE'
+ });
+
+ if (!response.ok) {
+ throw new Error('Failed to delete payment');
+ }
+
+ // Redirect to dashboard after successful deletion
+ goto('/cospend');
+
+ } catch (err) {
+ error = err.message;
+ } finally {
+ deleting = false;
+ }
+ }
@@ -66,6 +93,13 @@
@@ -196,6 +230,8 @@
text-decoration: none;
font-size: 0.9rem;
transition: all 0.2s;
+ border: none;
+ cursor: pointer;
}
.btn-secondary {
@@ -208,6 +244,20 @@
background-color: #e8e8e8;
}
+ .btn-danger {
+ background-color: #d32f2f;
+ color: white;
+ }
+
+ .btn-danger:hover:not(:disabled) {
+ background-color: #c62828;
+ }
+
+ .btn-danger:disabled {
+ opacity: 0.6;
+ cursor: not-allowed;
+ }
+
.loading, .error {
text-align: center;
padding: 2rem;