Fix UI bugs

This commit is contained in:
Atharv1705
2026-10-02 14:53:16 +05:30
parent 7304ebf096
commit ca0ab74d5a
16 changed files with 460 additions and 206 deletions
+28 -11
View File
@@ -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>