Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added delete confirmation for managing projects #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions src/components/modals/EditProjectsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,31 @@
import type { Project } from '$ts/common/types';
import ModalShell from './ModalShell.svelte';
import api from '$ts/client/api';
import { writable } from 'svelte/store';

export let projects: Project[];

const deleteProject = async (projectId: string) => {
await api.project.delete(projectId);
await invalidateAll();
let showConfirmation = writable(false);
let projectToDelete: string | null = null;

const confirmDelete = (projectId: string) => {
projectToDelete = projectId;
showConfirmation.set(true);
};

const deleteProject = async () => {
if (projectToDelete) {
await api.project.delete(projectToDelete);
await invalidateAll();
// Close the confirmation dialog after deletion
showConfirmation.set(false);
projectToDelete = null;
}
};

const cancelDelete = () => {
showConfirmation.set(false);
projectToDelete = null;
};
</script>

Expand Down Expand Up @@ -37,10 +56,29 @@
class="rounded-md border border-yellow-500 bg-yellow-600 p-1 px-2 text-sm">Edit</button
>
<button
on:click={() => deleteProject(project.id)}
on:click={() => confirmDelete(project.id)}
class="rounded-md border border-red-500 bg-red-600 p-1 px-2 text-sm">Delete</button
>
</div>
{/each}
</ModalShell>
{/if}

{#if $showConfirmation}
<div class="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-50">
<div class="bg-white p-6 rounded-md shadow-lg">
<p class="text-center mb-4">Are you sure you want to delete this project?</p>
<div class="flex justify-between">
<button
on:click={deleteProject}
class="bg-red-500 text-white px-4 py-2 rounded-md hover:bg-red-600"
>Delete</button>
<button
on:click={cancelDelete}
class="bg-gray-500 text-white px-4 py-2 rounded-md hover:bg-gray-600"
>Cancel</button>
</div>
</div>
</div>
{/if}