fix upload button

This commit is contained in:
SrGooglo 2023-04-09 20:44:42 +00:00
parent 75c50204c2
commit d9e36bb2a4
4 changed files with 6 additions and 71 deletions

View File

@ -1,7 +1,7 @@
import React from "react"
import loadable from "@loadable/component"
import { Modal } from "antd"
import UploadButton from "../components/uploadButton"
import UploadButton from "components/UploadButton"
import "./index.less"

View File

@ -1,69 +0,0 @@
import React from "react"
import { Button, Upload } from "antd"
import { Icons } from "components/Icons"
export default (props) => {
const [uploading, setUploading] = React.useState(false)
const handleUpload = async (req) => {
console.log(req)
setUploading(true)
const formData = new FormData()
formData.append("files", req.file)
const { data } = await window.app.cores.api.customRequest({
url: "/upload",
method: "POST",
data: formData
}).catch((error) => {
console.error(error)
app.message.error(error.respose.data.message)
return false
})
setUploading(false)
if (data) {
// check failed uploads
if (data.failed.length > 0) {
data.failed.forEach((file) => {
app.notification.error({
message: "Failed to upload file",
description: `Could not upload file ${file.fileName} cause > ${file.error}`
})
})
}
props.ctx.dispatchUpdate(data.files[0].url)
}
}
return <Upload
customRequest={handleUpload}
multiple={false}
accept="image/*"
progress={false}
fileList={[]}
>
<Button
icon={props.icon ?? <Icons.Upload
style={{
margin: 0
}}
/>}
loading={uploading}
type={
props.type ?? "round"
}
>
{
props.children ?? "Upload"
}
</Button>
</Upload>
}

View File

@ -1,7 +1,7 @@
import React from "react"
import { UserModel } from "models"
import loadable from "@loadable/component"
import UploadButton from "../components/uploadButton"
import UploadButton from "components/UploadButton"
export default {
id: "profile",

View File

@ -46,6 +46,10 @@ export default (props) => {
}
if (response.data.files.length > 0) {
if (typeof props.ctx?.onUpdateItem === "function") {
props.ctx.onUpdateItem(response.data.files[0].url)
}
if (typeof props.onUploadDone === "function") {
if (props.multiple) {
await props.onUploadDone(response.data.files)