Show error message for report details

This commit is contained in:
Viet Anh Nguyen 2024-02-06 11:08:36 +07:00
parent 403e6cbea8
commit c0ddb950ce
2 changed files with 24 additions and 9 deletions

View File

@ -33,6 +33,7 @@ const HeaderContainer = styled(Space)`
`;
const ReportDetail = () => {
const [error, setError] = useState(null);
const [fileObject, setFileObject] = useState(null);
const [pagination, setPagination] = useState({
page: 1,
@ -60,14 +61,22 @@ const ReportDetail = () => {
// Download and show report
useEffect(() => {
downloadReport(id, (fileDetails) => {
var blob = new Blob(
[fileDetails.file],
{type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,"}
);
let blobUrl = URL.createObjectURL(blob);
setFileObject(blobUrl);
});
try {
downloadReport(id, (fileDetails) => {
if (!fileDetails?.file) {
setError("The report has not been ready to preview.");
}
var blob = new Blob(
[fileDetails.file],
{type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,"}
);
let blobUrl = URL.createObjectURL(blob);
setFileObject(blobUrl);
});
} catch (error) {
setError("The report has not been ready to preview.");
console.log(error);
}
}, []);
const handleBack = () => {
@ -129,7 +138,9 @@ const ReportDetail = () => {
</Typography.Title>
</HeaderContainer>
<ReportContainer>
{fileObject && <SheetViewer file={fileObject} />}
{(fileObject && !error) && <SheetViewer file={fileObject} />}
{(!fileObject && !error) && <Typography.Title level={5}>Loading...</Typography.Title>}
{error && <Typography.Title level={5}>{error}</Typography.Title>}
</ReportContainer>
</>
);

View File

@ -113,6 +113,10 @@ export async function downloadReport(report_id: string, downloadFinishedCallback
filename: filename,
}
} catch (error) {
downloadFinishedCallback && downloadFinishedCallback({
file: null,
filename: null,
});
notification.error({
message: `${error?.message}`,
});