delete button more prominent
This commit is contained in:
@@ -85,6 +85,34 @@
|
|||||||
return `Custom split among ${payment.splits.length} people`;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="panel-content" bind:this={modal}>
|
<div class="panel-content" bind:this={modal}>
|
||||||
@@ -187,6 +215,13 @@
|
|||||||
<div class="panel-actions">
|
<div class="panel-actions">
|
||||||
{#if payment && payment.createdBy === session?.user?.nickname}
|
{#if payment && payment.createdBy === session?.user?.nickname}
|
||||||
<a href="/cospend/payments/edit/{paymentId}" class="btn btn-primary">Edit Payment</a>
|
<a href="/cospend/payments/edit/{paymentId}" class="btn btn-primary">Edit Payment</a>
|
||||||
|
<button
|
||||||
|
class="btn btn-danger"
|
||||||
|
on:click={deletePayment}
|
||||||
|
disabled={deleting}
|
||||||
|
>
|
||||||
|
{deleting ? 'Deleting...' : 'Delete'}
|
||||||
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
<button class="btn btn-secondary" on:click={closeModal}>Close</button>
|
<button class="btn btn-secondary" on:click={closeModal}>Close</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -462,6 +497,20 @@
|
|||||||
background-color: #f5f5f5;
|
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) {
|
@media (max-width: 600px) {
|
||||||
.payment-header {
|
.payment-header {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
@@ -102,6 +102,33 @@
|
|||||||
function formatDate(dateString) {
|
function formatDate(dateString) {
|
||||||
return new Date(dateString).toISOString().split('T')[0];
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -243,13 +270,23 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn-danger"
|
||||||
|
on:click={deletePayment}
|
||||||
|
disabled={deleting || saving}
|
||||||
|
>
|
||||||
|
{deleting ? 'Deleting...' : 'Delete Payment'}
|
||||||
|
</button>
|
||||||
|
<div class="main-actions">
|
||||||
<button type="button" class="btn-secondary" on:click={() => goto('/cospend/payments')}>
|
<button type="button" class="btn-secondary" on:click={() => goto('/cospend/payments')}>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
<button type="submit" class="btn-primary" disabled={saving}>
|
<button type="submit" class="btn-primary" disabled={saving || deleting}>
|
||||||
{saving ? 'Saving...' : 'Save Changes'}
|
{saving ? 'Saving...' : 'Save Changes'}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{/if}
|
{/if}
|
||||||
</main>
|
</main>
|
||||||
@@ -382,11 +419,17 @@
|
|||||||
|
|
||||||
.form-actions {
|
.form-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
gap: 1rem;
|
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;
|
padding: 0.75rem 1.5rem;
|
||||||
border-radius: 0.5rem;
|
border-radius: 0.5rem;
|
||||||
font-size: 1rem;
|
font-size: 1rem;
|
||||||
@@ -419,6 +462,21 @@
|
|||||||
background-color: #e8e8e8;
|
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 {
|
.current-image {
|
||||||
margin-bottom: 1rem;
|
margin-bottom: 1rem;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -502,6 +560,11 @@
|
|||||||
|
|
||||||
.form-actions {
|
.form-actions {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
align-items: stretch;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main-actions {
|
||||||
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
@@ -53,6 +53,33 @@
|
|||||||
return `Custom split among ${payment.splits.length} people`;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
@@ -66,6 +93,13 @@
|
|||||||
<div class="header-actions">
|
<div class="header-actions">
|
||||||
{#if payment && payment.createdBy === data.session.user.nickname}
|
{#if payment && payment.createdBy === data.session.user.nickname}
|
||||||
<a href="/cospend/payments/edit/{data.paymentId}" class="btn btn-secondary">Edit</a>
|
<a href="/cospend/payments/edit/{data.paymentId}" class="btn btn-secondary">Edit</a>
|
||||||
|
<button
|
||||||
|
class="btn btn-danger"
|
||||||
|
on:click={deletePayment}
|
||||||
|
disabled={deleting}
|
||||||
|
>
|
||||||
|
{deleting ? 'Deleting...' : 'Delete'}
|
||||||
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
<a href="/cospend/payments" class="btn btn-secondary">All Payments</a>
|
<a href="/cospend/payments" class="btn btn-secondary">All Payments</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -196,6 +230,8 @@
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
transition: all 0.2s;
|
transition: all 0.2s;
|
||||||
|
border: none;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-secondary {
|
.btn-secondary {
|
||||||
@@ -208,6 +244,20 @@
|
|||||||
background-color: #e8e8e8;
|
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 {
|
.loading, .error {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 2rem;
|
padding: 2rem;
|
||||||
|
Reference in New Issue
Block a user