mirror of
https://github.com/hexastack/hexabot
synced 2025-05-03 12:31:12 +00:00
Merge pull request #920 from Hexastack/153-request---add-loading-state-for-document-upload-in-attachmentuploader-component
feat: add loading spinner for document upload
This commit is contained in:
commit
dadb263176
@ -8,7 +8,15 @@
|
||||
|
||||
import CloudUploadIcon from "@mui/icons-material/CloudUpload";
|
||||
import FolderCopyIcon from "@mui/icons-material/FolderCopy";
|
||||
import { Box, Button, Divider, Grid, styled, Typography } from "@mui/material";
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
CircularProgress,
|
||||
Divider,
|
||||
Grid,
|
||||
styled,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
import { ChangeEvent, DragEvent, FC, useState } from "react";
|
||||
|
||||
import { useUpload } from "@/hooks/crud/useUpload";
|
||||
@ -84,17 +92,20 @@ const AttachmentUploader: FC<FileUploadProps> = ({
|
||||
const dialogs = useDialogs();
|
||||
const [isDragOver, setIsDragOver] = useState<boolean>(false);
|
||||
const { toast } = useToast();
|
||||
const { mutate: uploadAttachment } = useUpload(EntityType.ATTACHMENT, {
|
||||
onError: () => {
|
||||
toast.error(t("message.upload_failed"));
|
||||
const { mutate: uploadAttachment, isLoading } = useUpload(
|
||||
EntityType.ATTACHMENT,
|
||||
{
|
||||
onError: () => {
|
||||
toast.error(t("message.upload_failed"));
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
toast.success(t("message.success_save"));
|
||||
setAttachment(data);
|
||||
onChange?.(data);
|
||||
onUploadComplete?.();
|
||||
},
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
toast.success(t("message.success_save"));
|
||||
setAttachment(data);
|
||||
onChange && onChange(data);
|
||||
onUploadComplete && onUploadComplete();
|
||||
},
|
||||
});
|
||||
);
|
||||
const stopDefaults = (e: DragEvent) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
@ -167,7 +178,9 @@ const AttachmentUploader: FC<FileUploadProps> = ({
|
||||
alignItems="center"
|
||||
sx={{ padding: "20px" }}
|
||||
>
|
||||
{attachment ? (
|
||||
{isLoading ? (
|
||||
<CircularProgress />
|
||||
) : attachment ? (
|
||||
<AttachmentThumbnail
|
||||
id={attachment.id}
|
||||
format="full"
|
||||
|
Loading…
Reference in New Issue
Block a user