Skip to content
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
44 changes: 44 additions & 0 deletions packages/web/src/pages/ProjectList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
PencilSquareIcon,
} from "@heroicons/react/24/outline";
import {
deleteProject,
getProjects,
resetDatabase,
updateProject,
Expand Down Expand Up @@ -35,6 +36,8 @@ export function ProjectList(_props: RoutableProps) {
);
const [resetting, setResetting] = useState(false);
const [resetConfirmOpen, setResetConfirmOpen] = useState(false);
const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
const [deleting, setDeleting] = useState(false);

useEffect(() => {
refreshProjects();
Expand Down Expand Up @@ -137,6 +140,25 @@ export function ProjectList(_props: RoutableProps) {
}
};

const handleDelete = () => {
if (editingProject && !saving && !deleting) {
setDeleteConfirmOpen(true);
}
};

const handleDeleteConfirmed = async () => {
if (!editingProject || deleting) return;
setDeleting(true);
try {
await deleteProject(editingProject.id);
await refreshProjects();
setDeleteConfirmOpen(false);
closeEditModal(true);
} finally {
setDeleting(false);
}
};

const apiOrigin =
typeof window === "undefined" ? "" : window.location.origin;
const apiLocation = import.meta.env.DEV
Expand Down Expand Up @@ -421,6 +443,15 @@ export function ProjectList(_props: RoutableProps) {
</div>

<div class="modal-action">
<button
type="button"
class="btn btn-error btn-outline"
onClick={handleDelete}
disabled={saving || deleting}
>
Delete
</button>
<div class="flex-1" />
<button
type="button"
class="btn btn-ghost"
Expand Down Expand Up @@ -455,6 +486,19 @@ export function ProjectList(_props: RoutableProps) {
}}
isLoading={resetting}
/>

<ConfirmModal
isOpen={deleteConfirmOpen}
title="Delete Project?"
description="This will permanently delete the project and ALL its epics and tasks. This action cannot be undone."
confirmLabel="Delete"
confirmClassName="btn-error"
onConfirm={handleDeleteConfirmed}
onClose={() => {
if (!deleting) setDeleteConfirmOpen(false);
}}
isLoading={deleting}
/>
</div>
);
}