feat: implement archiving functionality for counters and update related logic
This commit is contained in:
@@ -21,9 +21,11 @@ interface Props {
|
||||
image_path: string | null;
|
||||
}) => void;
|
||||
onDelete?: (id: number) => void;
|
||||
onArchive?: (id: number) => void;
|
||||
onUnarchive?: (id: number) => void;
|
||||
}
|
||||
|
||||
export default function CounterModal({ open, initial, groups, onClose, onSave, onDelete }: Props) {
|
||||
export default function CounterModal({ open, initial, groups, onClose, onSave, onDelete, onArchive, onUnarchive }: Props) {
|
||||
const [confirmDelete, setConfirmDelete] = useState(false);
|
||||
const deleteTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
||||
const [name, setName] = useState('');
|
||||
@@ -191,28 +193,48 @@ export default function CounterModal({ open, initial, groups, onClose, onSave, o
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between gap-3 pt-2">
|
||||
{/* Delete — only shown when editing an existing counter */}
|
||||
{initial && onDelete ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
if (confirmDelete) {
|
||||
if (deleteTimer.current) clearTimeout(deleteTimer.current);
|
||||
onDelete(initial.id);
|
||||
onClose();
|
||||
} else {
|
||||
setConfirmDelete(true);
|
||||
deleteTimer.current = setTimeout(() => setConfirmDelete(false), 3000);
|
||||
}
|
||||
}}
|
||||
className={`px-4 py-2 text-sm rounded-lg font-medium transition-colors ${
|
||||
confirmDelete
|
||||
? 'bg-ctp-red hover:bg-ctp-maroon text-ctp-base'
|
||||
: 'text-ctp-red hover:bg-ctp-red/10 border border-ctp-red/30'
|
||||
}`}
|
||||
>
|
||||
{confirmDelete ? 'Confirm delete' : 'Delete counter'}
|
||||
</button>
|
||||
{initial ? (
|
||||
initial.archived_at ? (
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { onUnarchive?.(initial.id); onClose(); }}
|
||||
className="px-4 py-2 text-sm rounded-lg font-medium border border-ctp-green/40 text-ctp-green hover:bg-ctp-green/10 transition-colors"
|
||||
>
|
||||
Unarchive
|
||||
</button>
|
||||
{onDelete && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
if (confirmDelete) {
|
||||
if (deleteTimer.current) clearTimeout(deleteTimer.current);
|
||||
onDelete(initial.id);
|
||||
onClose();
|
||||
} else {
|
||||
setConfirmDelete(true);
|
||||
deleteTimer.current = setTimeout(() => setConfirmDelete(false), 3000);
|
||||
}
|
||||
}}
|
||||
className={`px-4 py-2 text-sm rounded-lg font-medium transition-colors ${
|
||||
confirmDelete
|
||||
? 'bg-ctp-red hover:bg-ctp-maroon text-ctp-base'
|
||||
: 'text-ctp-red hover:bg-ctp-red/10 border border-ctp-red/30'
|
||||
}`}
|
||||
>
|
||||
{confirmDelete ? 'Confirm delete' : 'Delete'}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => { onArchive?.(initial.id); onClose(); }}
|
||||
className="px-4 py-2 text-sm rounded-lg font-medium border border-ctp-overlay1/40 text-ctp-subtext1 hover:bg-ctp-surface1 transition-colors"
|
||||
>
|
||||
Archive
|
||||
</button>
|
||||
)
|
||||
) : <span />}
|
||||
|
||||
<div className="flex gap-3">
|
||||
|
||||
Reference in New Issue
Block a user