Skip to content
Merged
Show file tree
Hide file tree
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
135 changes: 135 additions & 0 deletions frontend/src/components/ConfirmModal.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
.overlay {
position: fixed;
inset: 0;
background-color: rgba(0, 0, 0, 0.75);
backdrop-filter: blur(6px);
display: flex;
align-items: center;
justify-content: center;
z-index: 100;
padding: 1.5rem;
}

.modal {
background-color: var(--color-card);
border: 1px solid var(--color-border);
border-radius: var(--radius);
width: 100%;
max-width: 420px;
display: flex;
flex-direction: column;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
animation: modal-in 0.18s cubic-bezier(0.16, 1, 0.3, 1);
overflow: hidden;
}

@keyframes modal-in {
from {
opacity: 0;
transform: scale(0.92) translateY(8px);
}
to {
opacity: 1;
transform: scale(1) translateY(0);
}
}

.iconWrap {
display: flex;
align-items: center;
justify-content: center;
width: 48px;
height: 48px;
border-radius: 50%;
background-color: rgba(239, 68, 68, 0.12);
border: 1px solid rgba(239, 68, 68, 0.2);
margin-bottom: 1rem;
}

.body {
padding: 1.75rem 1.75rem 1.25rem;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
}

.title {
font-size: 1.05rem;
font-weight: 700;
font-family: var(--font-mono);
color: var(--color-foreground);
margin-bottom: 0.5rem;
}

.message {
font-size: 0.85rem;
color: var(--color-muted-foreground);
line-height: 1.6;
}

.highlight {
font-weight: 600;
color: var(--color-foreground);
font-family: var(--font-mono);
}

.warning {
margin-top: 1rem;
font-size: 0.75rem;
font-family: var(--font-mono);
color: #ef4444;
background-color: rgba(239, 68, 68, 0.06);
border: 1px solid rgba(239, 68, 68, 0.15);
border-radius: var(--radius-sm);
padding: 0.375rem 0.75rem;
}

.footer {
padding: 1rem 1.75rem 1.5rem;
display: flex;
gap: 0.75rem;
justify-content: flex-end;
}

.btnCancel {
padding: 0.5rem 1.125rem;
font-size: 0.82rem;
font-weight: 500;
border: 1px solid var(--color-border);
background-color: transparent;
color: var(--color-foreground);
border-radius: var(--radius);
cursor: pointer;
transition: all 0.15s ease;
}

.btnCancel:hover {
background-color: var(--color-secondary);
}

.btnDelete {
padding: 0.5rem 1.125rem;
font-size: 0.82rem;
font-weight: 700;
background-color: #ef4444;
color: white;
border: 1px solid transparent;
border-radius: var(--radius);
cursor: pointer;
transition: all 0.15s ease;
display: flex;
align-items: center;
gap: 0.375rem;
}

.btnDelete:hover {
background-color: #dc2626;
box-shadow: 0 0 12px rgba(239, 68, 68, 0.35);
}

.btnDelete:disabled,
.btnCancel:disabled {
opacity: 0.5;
cursor: not-allowed;
}
133 changes: 133 additions & 0 deletions frontend/src/components/ConfirmModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import React, { useEffect, useRef } from "react";
import { AlertTriangle, Trash2 } from "lucide-react";
import styles from "./ConfirmModal.module.css";

interface ConfirmModalProps {
isOpen: boolean;
onClose: () => void;
onConfirm: () => void | Promise<void>;
title: string;
message: string;
itemName?: string;
warningText?: string;
isLoading?: boolean;
confirmLabel?: string;
}

export const ConfirmModal: React.FC<ConfirmModalProps> = ({
isOpen,
onClose,
onConfirm,
title,
message,
itemName,
warningText,
isLoading = false,
confirmLabel = "Delete",
}) => {
const previousActiveElement = useRef<HTMLElement | null>(null);
const modalRef = useRef<HTMLDivElement>(null);
const firstButtonRef = useRef<HTMLButtonElement>(null);

useEffect(() => {
if (isOpen) {
previousActiveElement.current = document.activeElement as HTMLElement;
setTimeout(() => {
firstButtonRef.current?.focus();
}, 0);
}

return () => {
if (previousActiveElement.current) {
previousActiveElement.current.focus();
}
};
}, [isOpen]);

useEffect(() => {
if (!isOpen) return;

const handleKeyDown = (e: KeyboardEvent) => {
if (e.key !== "Tab") return;

const modal = modalRef.current;
if (!modal) return;

const focusables = modal.querySelectorAll<HTMLElement>(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
);
if (focusables.length === 0) return;

const firstElement = focusables[0];
const lastElement = focusables[focusables.length - 1];

if (e.shiftKey) {
if (document.activeElement === firstElement) {
lastElement.focus();
e.preventDefault();
}
} else {
if (document.activeElement === lastElement) {
firstElement.focus();
e.preventDefault();
}
}
};

document.addEventListener("keydown", handleKeyDown);
return () => document.removeEventListener("keydown", handleKeyDown);
}, [isOpen]);

if (!isOpen) return null;

const handleConfirm = async () => {
await onConfirm();
};

return (
<div
className={styles.overlay}
onClick={() => !isLoading && onClose()}
>
<div
ref={modalRef}
className={styles.modal}
onClick={(e) => e.stopPropagation()}
role="dialog"
aria-modal="true"
aria-labelledby="confirm-modal-title"
>
<div className={styles.body}>
<div className={styles.iconWrap}>
<AlertTriangle size={22} color="#ef4444" />
</div>
<h2 id="confirm-modal-title" className={styles.title}>{title}</h2>
<p className={styles.message}>
{message}{" "}
{itemName && <span className={styles.highlight}>"{itemName}"</span>}?
</p>
{warningText && <p className={styles.warning}>{warningText}</p>}
</div>

<div className={styles.footer}>
<button
ref={firstButtonRef}
className={styles.btnCancel}
onClick={onClose}
disabled={isLoading}
>
Cancel
</button>
<button
className={styles.btnDelete}
onClick={handleConfirm}
disabled={isLoading}
>
<Trash2 size={13} />
<span>{isLoading ? "Deleting..." : confirmLabel}</span>
</button>
</div>
</div>
</div>
);
};
Loading