mirror of
https://github.com/hexastack/hexabot
synced 2025-05-08 06:44:49 +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 CloudUploadIcon from "@mui/icons-material/CloudUpload";
|
||||||
import FolderCopyIcon from "@mui/icons-material/FolderCopy";
|
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 { ChangeEvent, DragEvent, FC, useState } from "react";
|
||||||
|
|
||||||
import { useUpload } from "@/hooks/crud/useUpload";
|
import { useUpload } from "@/hooks/crud/useUpload";
|
||||||
@ -84,17 +92,20 @@ const AttachmentUploader: FC<FileUploadProps> = ({
|
|||||||
const dialogs = useDialogs();
|
const dialogs = useDialogs();
|
||||||
const [isDragOver, setIsDragOver] = useState<boolean>(false);
|
const [isDragOver, setIsDragOver] = useState<boolean>(false);
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { mutate: uploadAttachment } = useUpload(EntityType.ATTACHMENT, {
|
const { mutate: uploadAttachment, isLoading } = useUpload(
|
||||||
onError: () => {
|
EntityType.ATTACHMENT,
|
||||||
toast.error(t("message.upload_failed"));
|
{
|
||||||
|
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) => {
|
const stopDefaults = (e: DragEvent) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@ -167,7 +178,9 @@ const AttachmentUploader: FC<FileUploadProps> = ({
|
|||||||
alignItems="center"
|
alignItems="center"
|
||||||
sx={{ padding: "20px" }}
|
sx={{ padding: "20px" }}
|
||||||
>
|
>
|
||||||
{attachment ? (
|
{isLoading ? (
|
||||||
|
<CircularProgress />
|
||||||
|
) : attachment ? (
|
||||||
<AttachmentThumbnail
|
<AttachmentThumbnail
|
||||||
id={attachment.id}
|
id={attachment.id}
|
||||||
format="full"
|
format="full"
|
||||||
|
Loading…
Reference in New Issue
Block a user