Fix UI bugs
This commit is contained in:
@@ -2,10 +2,14 @@ import { useEffect, useState, useRef, useCallback } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import { useAuth } from '../context/AuthContext';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import ConfirmModal from '../components/ConfirmModal';
|
||||
|
||||
export default function UploadBusiness() {
|
||||
const { authFetch } = useAuth();
|
||||
const { showToast } = useToast();
|
||||
const [confirmConfig, setConfirmConfig] = useState({
|
||||
isOpen: false, title: "", message: "", confirmText: "OK", isDestructive: false, onConfirm: () => {}
|
||||
});
|
||||
const [taxYear, setTaxYear] = useState(2025);
|
||||
const [docs, setDocs] = useState([]);
|
||||
const [templates, setTemplates] = useState([]);
|
||||
@@ -63,18 +67,27 @@ export default function UploadBusiness() {
|
||||
};
|
||||
|
||||
const deleteDoc = async (id) => {
|
||||
if (!window.confirm("Delete this document?\nThis action cannot be undone.")) return;
|
||||
try {
|
||||
const res = await authFetch(`/api/upload/business-documents/${id}`, { method: "DELETE" });
|
||||
if (res.ok) {
|
||||
showToast("Document deleted", "success");
|
||||
fetchTemplatesAndDocs();
|
||||
} else {
|
||||
showToast("Delete failed", "error");
|
||||
setConfirmConfig({
|
||||
isOpen: true,
|
||||
title: "Delete Document",
|
||||
message: "Delete this document?\nThis action cannot be undone.",
|
||||
isDestructive: true,
|
||||
confirmText: "Delete",
|
||||
onConfirm: async () => {
|
||||
setConfirmConfig(prev => ({ ...prev, isOpen: false }));
|
||||
try {
|
||||
const res = await authFetch(`/api/upload/business-documents/${id}`, { method: "DELETE" });
|
||||
if (res.ok) {
|
||||
showToast("Document deleted", "success");
|
||||
fetchTemplatesAndDocs();
|
||||
} else {
|
||||
showToast("Delete failed", "error");
|
||||
}
|
||||
} catch (err) { console.error(err);
|
||||
showToast("Delete failed", "error");
|
||||
}
|
||||
}
|
||||
} catch (err) { console.error(err);
|
||||
showToast("Delete failed", "error");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const viewDoc = async (storageKey) => {
|
||||
@@ -132,6 +145,10 @@ export default function UploadBusiness() {
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ConfirmModal
|
||||
{...confirmConfig}
|
||||
onCancel={() => setConfirmConfig(prev => ({ ...prev, isOpen: false }))}
|
||||
/>
|
||||
<div style={{marginBottom: '16px'}}>
|
||||
<Link to="/dashboard" className="fancy-link" style={{fontSize: '14px', fontWeight: 500}}>← Back to Dashboard</Link>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user