@@ -1,73 +1,71 @@
|
||||
import { UploadOutlined } from "@ant-design/icons";
|
||||
import { Upload } from "antd";
|
||||
import React, { useState } from "react";
|
||||
import {UploadOutlined} from "@ant-design/icons";
|
||||
import {Upload} from "antd";
|
||||
import React, {useState} from "react";
|
||||
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import {
|
||||
selectBodyshop,
|
||||
selectCurrentUser,
|
||||
} from "../../redux/user/user.selectors";
|
||||
import { handleUpload } from "./documents-local-upload.utility";
|
||||
import {connect} from "react-redux";
|
||||
import {createStructuredSelector} from "reselect";
|
||||
import {selectBodyshop, selectCurrentUser,} from "../../redux/user/user.selectors";
|
||||
import {handleUpload} from "./documents-local-upload.utility";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
currentUser: selectCurrentUser,
|
||||
bodyshop: selectBodyshop,
|
||||
currentUser: selectCurrentUser,
|
||||
bodyshop: selectBodyshop,
|
||||
});
|
||||
|
||||
export function DocumentsLocalUploadComponent({
|
||||
children,
|
||||
currentUser,
|
||||
bodyshop,
|
||||
job,
|
||||
vendorid,
|
||||
invoice_number,
|
||||
callbackAfterUpload,
|
||||
allowAllTypes,
|
||||
}) {
|
||||
const [fileList, setFileList] = useState([]);
|
||||
children,
|
||||
currentUser,
|
||||
bodyshop,
|
||||
job,
|
||||
vendorid,
|
||||
invoice_number,
|
||||
callbackAfterUpload,
|
||||
allowAllTypes,
|
||||
}) {
|
||||
const [fileList, setFileList] = useState([]);
|
||||
|
||||
const handleDone = (uid) => {
|
||||
setTimeout(() => {
|
||||
setFileList((fileList) => fileList.filter((x) => x.uid !== uid));
|
||||
}, 2000);
|
||||
};
|
||||
const handleDone = (uid) => {
|
||||
setTimeout(() => {
|
||||
setFileList((fileList) => fileList.filter((x) => x.uid !== uid));
|
||||
}, 2000);
|
||||
};
|
||||
|
||||
return (
|
||||
<Upload.Dragger
|
||||
multiple={true}
|
||||
fileList={fileList}
|
||||
onChange={(f) => {
|
||||
if (f.event && f.event.percent === 100) handleDone(f.file.uid);
|
||||
return (
|
||||
<Upload.Dragger
|
||||
multiple={true}
|
||||
fileList={fileList}
|
||||
onChange={(f) => {
|
||||
if (f.event && f.event.percent === 100) handleDone(f.file.uid);
|
||||
|
||||
setFileList(f.fileList);
|
||||
}}
|
||||
customRequest={(ev) =>
|
||||
handleUpload({
|
||||
ev,
|
||||
context: {
|
||||
jobid: job.id,
|
||||
vendorid,
|
||||
invoice_number,
|
||||
callback: callbackAfterUpload,
|
||||
},
|
||||
})
|
||||
}
|
||||
{...(!allowAllTypes && {
|
||||
accept: "audio/*, video/*, image/*, .pdf, .doc, .docx, .xls, .xlsx",
|
||||
})}
|
||||
>
|
||||
{children || (
|
||||
<>
|
||||
<p className="ant-upload-drag-icon">
|
||||
<UploadOutlined />
|
||||
</p>
|
||||
<p className="ant-upload-text">
|
||||
Click or drag files to this area to upload.
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</Upload.Dragger>
|
||||
);
|
||||
setFileList(f.fileList);
|
||||
}}
|
||||
customRequest={(ev) =>
|
||||
handleUpload({
|
||||
ev,
|
||||
context: {
|
||||
jobid: job.id,
|
||||
vendorid,
|
||||
invoice_number,
|
||||
callback: callbackAfterUpload,
|
||||
},
|
||||
})
|
||||
}
|
||||
{...(!allowAllTypes && {
|
||||
accept: "audio/*, video/*, image/*, .pdf, .doc, .docx, .xls, .xlsx",
|
||||
})}
|
||||
>
|
||||
{children || (
|
||||
<>
|
||||
<p className="ant-upload-drag-icon">
|
||||
<UploadOutlined/>
|
||||
</p>
|
||||
<p className="ant-upload-text">
|
||||
Click or drag files to this area to upload.
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
</Upload.Dragger>
|
||||
);
|
||||
}
|
||||
|
||||
export default connect(mapStateToProps, null)(DocumentsLocalUploadComponent);
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
import cleanAxios from "../../utils/CleanAxios";
|
||||
import { store } from "../../redux/store";
|
||||
import { addMediaForJob } from "../../redux/media/media.actions";
|
||||
import {store} from "../../redux/store";
|
||||
import {addMediaForJob} from "../../redux/media/media.actions";
|
||||
import normalizeUrl from "normalize-url";
|
||||
import { notification } from "antd";
|
||||
import {notification} from "antd";
|
||||
import i18n from "i18next";
|
||||
|
||||
export const handleUpload = async ({ ev, context }) => {
|
||||
const { onError, onSuccess, onProgress, file } = ev;
|
||||
const { jobid, invoice_number, vendorid, callbackAfterUpload } = context;
|
||||
export const handleUpload = async ({ev, context}) => {
|
||||
const {onError, onSuccess, onProgress, file} = ev;
|
||||
const {jobid, invoice_number, vendorid, callbackAfterUpload} = context;
|
||||
|
||||
const bodyshop = store.getState().user.bodyshop;
|
||||
var options = {
|
||||
headers: {
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
ims_token: bodyshop.localmediatoken,
|
||||
},
|
||||
onUploadProgress: (e) => {
|
||||
if (!!onProgress) onProgress({ percent: (e.loaded / e.total) * 100 });
|
||||
},
|
||||
};
|
||||
const bodyshop = store.getState().user.bodyshop;
|
||||
var options = {
|
||||
headers: {
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
ims_token: bodyshop.localmediatoken,
|
||||
},
|
||||
onUploadProgress: (e) => {
|
||||
if (!!onProgress) onProgress({percent: (e.loaded / e.total) * 100});
|
||||
},
|
||||
};
|
||||
|
||||
const formData = new FormData();
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append("jobid", jobid);
|
||||
if (invoice_number) {
|
||||
formData.append("invoice_number", invoice_number);
|
||||
formData.append("vendorid", vendorid);
|
||||
}
|
||||
formData.append("file", file);
|
||||
|
||||
const imexMediaServerResponse = await cleanAxios.post(
|
||||
normalizeUrl(
|
||||
`${bodyshop.localmediaserverhttp}/${
|
||||
invoice_number ? "bills" : "jobs"
|
||||
}/upload`
|
||||
),
|
||||
formData,
|
||||
{
|
||||
...options,
|
||||
formData.append("jobid", jobid);
|
||||
if (invoice_number) {
|
||||
formData.append("invoice_number", invoice_number);
|
||||
formData.append("vendorid", vendorid);
|
||||
}
|
||||
);
|
||||
formData.append("file", file);
|
||||
|
||||
if (imexMediaServerResponse.status !== 200) {
|
||||
if (!!onError) {
|
||||
onError(imexMediaServerResponse.statusText);
|
||||
}
|
||||
} else {
|
||||
onSuccess && onSuccess(file);
|
||||
notification.open({
|
||||
type: "success",
|
||||
key: "docuploadsuccess",
|
||||
message: i18n.t("documents.successes.insert"),
|
||||
});
|
||||
store.dispatch(
|
||||
addMediaForJob({
|
||||
jobid,
|
||||
media: imexMediaServerResponse.data.map((d) => {
|
||||
return {
|
||||
...d,
|
||||
selected: false,
|
||||
src: normalizeUrl(`${bodyshop.localmediaserverhttp}/${d.src}`),
|
||||
...(d.optimized && {
|
||||
optimized: normalizeUrl(
|
||||
`${bodyshop.localmediaserverhttp}/${d.optimized}`
|
||||
),
|
||||
}),
|
||||
thumbnail: normalizeUrl(
|
||||
`${bodyshop.localmediaserverhttp}/${d.thumbnail}`
|
||||
),
|
||||
};
|
||||
}),
|
||||
})
|
||||
const imexMediaServerResponse = await cleanAxios.post(
|
||||
normalizeUrl(
|
||||
`${bodyshop.localmediaserverhttp}/${
|
||||
invoice_number ? "bills" : "jobs"
|
||||
}/upload`
|
||||
),
|
||||
formData,
|
||||
{
|
||||
...options,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (callbackAfterUpload) {
|
||||
callbackAfterUpload();
|
||||
}
|
||||
if (imexMediaServerResponse.status !== 200) {
|
||||
if (!!onError) {
|
||||
onError(imexMediaServerResponse.statusText);
|
||||
}
|
||||
} else {
|
||||
onSuccess && onSuccess(file);
|
||||
notification.open({
|
||||
type: "success",
|
||||
key: "docuploadsuccess",
|
||||
message: i18n.t("documents.successes.insert"),
|
||||
});
|
||||
store.dispatch(
|
||||
addMediaForJob({
|
||||
jobid,
|
||||
media: imexMediaServerResponse.data.map((d) => {
|
||||
return {
|
||||
...d,
|
||||
selected: false,
|
||||
src: normalizeUrl(`${bodyshop.localmediaserverhttp}/${d.src}`),
|
||||
...(d.optimized && {
|
||||
optimized: normalizeUrl(
|
||||
`${bodyshop.localmediaserverhttp}/${d.optimized}`
|
||||
),
|
||||
}),
|
||||
thumbnail: normalizeUrl(
|
||||
`${bodyshop.localmediaserverhttp}/${d.thumbnail}`
|
||||
),
|
||||
};
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (callbackAfterUpload) {
|
||||
callbackAfterUpload();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user