mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
fix upload button
This commit is contained in:
parent
75c50204c2
commit
d9e36bb2a4
@ -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"
|
||||
|
||||
|
@ -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>
|
||||
}
|
@ -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",
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user