Add click-to-edit pattern across all admin tables
Replace Actions columns with clickable rows that open edit modals directly. Delete is now an inline two-step confirm button in the edit modal footer. Games modal links to routes/bosses detail, route modal links to encounters, and boss modal has an Edit Team button. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { type FormEvent, type ReactNode } from 'react'
|
||||
import { type FormEvent, type ReactNode, useState, useEffect } from 'react'
|
||||
|
||||
interface FormModalProps {
|
||||
title: string
|
||||
@@ -7,6 +7,9 @@ interface FormModalProps {
|
||||
children: ReactNode
|
||||
submitLabel?: string
|
||||
isSubmitting?: boolean
|
||||
onDelete?: () => void
|
||||
isDeleting?: boolean
|
||||
headerExtra?: ReactNode
|
||||
}
|
||||
|
||||
export function FormModal({
|
||||
@@ -16,17 +19,46 @@ export function FormModal({
|
||||
children,
|
||||
submitLabel = 'Save',
|
||||
isSubmitting,
|
||||
onDelete,
|
||||
isDeleting,
|
||||
headerExtra,
|
||||
}: FormModalProps) {
|
||||
const [confirmingDelete, setConfirmingDelete] = useState(false)
|
||||
|
||||
// Reset confirm state when modal closes/reopens
|
||||
useEffect(() => {
|
||||
setConfirmingDelete(false)
|
||||
}, [onDelete])
|
||||
|
||||
return (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center">
|
||||
<div className="fixed inset-0 bg-black/50" onClick={onClose} />
|
||||
<div className="relative bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-lg w-full mx-4 max-h-[90vh] overflow-y-auto">
|
||||
<div className="px-6 py-4 border-b border-gray-200 dark:border-gray-700">
|
||||
<h2 className="text-lg font-semibold">{title}</h2>
|
||||
{headerExtra}
|
||||
</div>
|
||||
<form onSubmit={onSubmit}>
|
||||
<div className="px-6 py-4 space-y-4">{children}</div>
|
||||
<div className="px-6 py-4 border-t border-gray-200 dark:border-gray-700 flex justify-end gap-3">
|
||||
<div className="px-6 py-4 border-t border-gray-200 dark:border-gray-700 flex items-center gap-3">
|
||||
{onDelete && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={isDeleting}
|
||||
onClick={() => {
|
||||
if (confirmingDelete) {
|
||||
onDelete()
|
||||
} else {
|
||||
setConfirmingDelete(true)
|
||||
}
|
||||
}}
|
||||
onBlur={() => setConfirmingDelete(false)}
|
||||
className="px-4 py-2 text-sm font-medium rounded-md text-red-600 dark:text-red-400 border border-red-300 dark:border-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 disabled:opacity-50"
|
||||
>
|
||||
{isDeleting ? 'Deleting...' : confirmingDelete ? 'Confirm?' : 'Delete'}
|
||||
</button>
|
||||
)}
|
||||
<div className="flex-1" />
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
|
||||
Reference in New Issue
Block a user