Align admin, community, search, library, learning and course management with the mockup. Add saved courses, download history, public community feed, instructor directory, backend search, course views, admin content tools and community moderation. Harden API and Nginx for production.
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import React, { useEffect } from 'react';
|
|
import { createPortal } from 'react-dom';
|
|
|
|
interface ConfirmDialogProps {
|
|
open: boolean;
|
|
title: string;
|
|
message: string;
|
|
confirmLabel?: string;
|
|
busy?: boolean;
|
|
onCancel: () => void;
|
|
onConfirm: () => void;
|
|
}
|
|
|
|
/** In-app confirmation dialog instead of window.confirm. */
|
|
export const ConfirmDialog: React.FC<ConfirmDialogProps> = ({ open, title, message, confirmLabel = 'Confirmar', busy = false, onCancel, onConfirm }) => {
|
|
useEffect(() => {
|
|
if (!open) return;
|
|
const onKey = (event: KeyboardEvent) => { if (event.key === 'Escape') onCancel(); };
|
|
document.addEventListener('keydown', onKey);
|
|
return () => document.removeEventListener('keydown', onKey);
|
|
}, [open, onCancel]);
|
|
|
|
if (!open) return null;
|
|
return createPortal(<div className="scrim" role="dialog" aria-modal="true" aria-label={title} onMouseDown={(event) => { if (event.target === event.currentTarget) onCancel(); }}>
|
|
<div className="dialog" style={{ maxWidth: 420 }}>
|
|
<header><div><h2>{title}</h2><p>{message}</p></div></header>
|
|
<footer>
|
|
<button className="btn sec" type="button" onClick={onCancel} disabled={busy}>Cancelar</button>
|
|
<button className="btn danger" type="button" onClick={onConfirm} disabled={busy}>{busy ? 'Aguarde…' : confirmLabel}</button>
|
|
</footer>
|
|
</div>
|
|
</div>, document.body);
|
|
};
|