Base changes to job upload screen.
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import cleanAxios from "../../utils/CleanAxios";
|
||||
import { store } from "../../redux/store";
|
||||
import { addMediaForJob } from "../../redux/media/media.actions";
|
||||
import normalizeUrl from "normalize-url";
|
||||
|
||||
export const handleUpload = async ({ ev, context }) => {
|
||||
const { onError, onSuccess, onProgress, file } = ev;
|
||||
const { jobid, callbackAfterUpload } = context;
|
||||
|
||||
var options = {
|
||||
headers: { "X-Requested-With": "XMLHttpRequest" },
|
||||
onUploadProgress: (e) => {
|
||||
if (!!onProgress) onProgress({ percent: (e.loaded / e.total) * 100 });
|
||||
},
|
||||
};
|
||||
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append("jobid", jobid);
|
||||
formData.append("file", file);
|
||||
const bodyshop = store.getState().user.bodyshop;
|
||||
|
||||
const imexMediaServerResponse = await cleanAxios.post(
|
||||
normalizeUrl(`${bodyshop.localmediaserverhttp}/jobs/upload`),
|
||||
formData,
|
||||
{
|
||||
...options,
|
||||
}
|
||||
);
|
||||
|
||||
if (imexMediaServerResponse.status !== 200) {
|
||||
if (!!onError) {
|
||||
onError(imexMediaServerResponse.statusText);
|
||||
}
|
||||
} else {
|
||||
onSuccess(file);
|
||||
store.dispatch(
|
||||
addMediaForJob({
|
||||
jobid,
|
||||
media: imexMediaServerResponse.data.map((d) => {
|
||||
return {
|
||||
...d,
|
||||
src: normalizeUrl(`${bodyshop.localmediaserverhttp}/${d.src}`),
|
||||
thumbnail: normalizeUrl(
|
||||
`${bodyshop.localmediaserverhttp}/${d.thumbnail}`
|
||||
),
|
||||
};
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (callbackAfterUpload) {
|
||||
callbackAfterUpload();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user