WIP for document upload on invoice enter.
This commit is contained in:
@@ -2,13 +2,14 @@ import { UploadOutlined } from "@ant-design/icons";
|
|||||||
import { Button, Upload } from "antd";
|
import { Button, Upload } from "antd";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
export default function DocumentsUploadComponent({ handleUpload }) {
|
export default function DocumentsUploadComponent({ handleUpload, UploadRef }) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Upload
|
<Upload
|
||||||
multiple={true}
|
multiple={true}
|
||||||
customRequest={handleUpload}
|
customRequest={handleUpload}
|
||||||
accept="audio/*,video/*,image/*"
|
accept="audio/*,video/*,image/*"
|
||||||
|
ref={UploadRef}
|
||||||
>
|
>
|
||||||
<Button>
|
<Button>
|
||||||
<UploadOutlined /> Click to Upload
|
<UploadOutlined /> Click to Upload
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { notification } from "antd";
|
import { notification } from "antd";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import React from "react";
|
import React, { useRef } from "react";
|
||||||
import { useMutation } from "@apollo/react-hooks";
|
import { useMutation } from "@apollo/react-hooks";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import Resizer from "react-image-file-resizer";
|
import Resizer from "react-image-file-resizer";
|
||||||
@@ -9,30 +9,29 @@ import { createStructuredSelector } from "reselect";
|
|||||||
import { INSERT_NEW_DOCUMENT } from "../../graphql/documents.queries";
|
import { INSERT_NEW_DOCUMENT } from "../../graphql/documents.queries";
|
||||||
import {
|
import {
|
||||||
selectBodyshop,
|
selectBodyshop,
|
||||||
selectCurrentUser
|
selectCurrentUser,
|
||||||
} from "../../redux/user/user.selectors";
|
} from "../../redux/user/user.selectors";
|
||||||
import { generateCdnThumb } from "../../utils/DocHelpers";
|
import { generateCdnThumb } from "../../utils/DocHelpers";
|
||||||
import DocumentsUploadComponent from "./documents-upload.component";
|
import DocumentsUploadComponent from "./documents-upload.component";
|
||||||
|
|
||||||
const mapStateToProps = createStructuredSelector({
|
const mapStateToProps = createStructuredSelector({
|
||||||
currentUser: selectCurrentUser,
|
currentUser: selectCurrentUser,
|
||||||
bodyshop: selectBodyshop
|
bodyshop: selectBodyshop,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(
|
export function DocumentsUploadContainer({
|
||||||
mapStateToProps,
|
|
||||||
null
|
|
||||||
)(function DocumentsUploadContainer({
|
|
||||||
jobId,
|
jobId,
|
||||||
invoiceId,
|
invoiceId,
|
||||||
currentUser,
|
currentUser,
|
||||||
bodyshop,
|
bodyshop,
|
||||||
callbackAfterUpload
|
callbackAfterUpload,
|
||||||
|
onChange,
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [insertNewDocument] = useMutation(INSERT_NEW_DOCUMENT);
|
const [insertNewDocument] = useMutation(INSERT_NEW_DOCUMENT);
|
||||||
|
const UploadRef = useRef(null);
|
||||||
|
|
||||||
const handleUpload = ev => {
|
const handleUpload = (ev) => {
|
||||||
const { onError, onSuccess, onProgress } = ev;
|
const { onError, onSuccess, onProgress } = ev;
|
||||||
//If PDF, upload directly.
|
//If PDF, upload directly.
|
||||||
//If JPEG, resize and upload.
|
//If JPEG, resize and upload.
|
||||||
@@ -49,7 +48,7 @@ export default connect(
|
|||||||
"PNG",
|
"PNG",
|
||||||
75,
|
75,
|
||||||
0,
|
0,
|
||||||
uri => {
|
(uri) => {
|
||||||
let file = new File([uri], ev.file.name, {});
|
let file = new File([uri], ev.file.name, {});
|
||||||
file.uid = ev.file.uid;
|
file.uid = ev.file.uid;
|
||||||
uploadToS3(key, file.type, file, onError, onSuccess, onProgress);
|
uploadToS3(key, file.type, file, onError, onSuccess, onProgress);
|
||||||
@@ -69,9 +68,9 @@ export default connect(
|
|||||||
axios
|
axios
|
||||||
.post("/sign_s3", {
|
.post("/sign_s3", {
|
||||||
fileName,
|
fileName,
|
||||||
fileType
|
fileType,
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
var returnData = response.data.data.returnData;
|
var returnData = response.data.data.returnData;
|
||||||
var signedRequest = returnData.signedRequest;
|
var signedRequest = returnData.signedRequest;
|
||||||
var url = returnData.url;
|
var url = returnData.url;
|
||||||
@@ -79,16 +78,16 @@ export default connect(
|
|||||||
// Put the fileType in the headers for the upload
|
// Put the fileType in the headers for the upload
|
||||||
var options = {
|
var options = {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": fileType
|
"Content-Type": fileType,
|
||||||
},
|
},
|
||||||
onUploadProgress: e => {
|
onUploadProgress: (e) => {
|
||||||
onProgress({ percent: (e.loaded / e.total) * 100 });
|
onProgress({ percent: (e.loaded / e.total) * 100 });
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.put(signedRequest, file, options)
|
.put(signedRequest, file, options)
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
insertNewDocument({
|
insertNewDocument({
|
||||||
variables: {
|
variables: {
|
||||||
docInput: [
|
docInput: [
|
||||||
@@ -101,43 +100,55 @@ export default connect(
|
|||||||
? "application/pdf"
|
? "application/pdf"
|
||||||
: generateCdnThumb(fileName),
|
: generateCdnThumb(fileName),
|
||||||
key: fileName,
|
key: fileName,
|
||||||
invoiceid: invoiceId
|
invoiceid: invoiceId,
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
}
|
},
|
||||||
}).then(r => {
|
}).then((r) => {
|
||||||
onSuccess({
|
onSuccess({
|
||||||
uid: r.data.insert_documents.returning[0].id,
|
uid: r.data.insert_documents.returning[0].id,
|
||||||
url: r.data.insert_documents.returning[0].thumb_url,
|
url: r.data.insert_documents.returning[0].thumb_url,
|
||||||
name: r.data.insert_documents.returning[0].name,
|
name: r.data.insert_documents.returning[0].name,
|
||||||
status: "done",
|
status: "done",
|
||||||
full_url: r.data.insert_documents.returning[0].url,
|
full_url: r.data.insert_documents.returning[0].url,
|
||||||
key: r.data.insert_documents.returning[0].key
|
key: r.data.insert_documents.returning[0].key,
|
||||||
});
|
});
|
||||||
notification["success"]({
|
notification["success"]({
|
||||||
message: t("documents.successes.insert")
|
message: t("documents.successes.insert"),
|
||||||
});
|
});
|
||||||
if (callbackAfterUpload) {
|
if (callbackAfterUpload) {
|
||||||
callbackAfterUpload();
|
callbackAfterUpload();
|
||||||
}
|
}
|
||||||
|
console.log("ref", UploadRef.current.state.fileList);
|
||||||
|
if (onChange) {
|
||||||
|
//Used in a form.
|
||||||
|
onChange(UploadRef.current.state.fileList);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
onError(error);
|
onError(error);
|
||||||
notification["error"]({
|
notification["error"]({
|
||||||
message: t("documents.errors.insert", {
|
message: t("documents.errors.insert", {
|
||||||
message: JSON.stringify(error)
|
message: JSON.stringify(error),
|
||||||
})
|
}),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch((error) => {
|
||||||
notification["error"]({
|
notification["error"]({
|
||||||
message: t("documents.errors.getpresignurl", {
|
message: t("documents.errors.getpresignurl", {
|
||||||
message: JSON.stringify(error)
|
message: JSON.stringify(error),
|
||||||
})
|
}),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
return <DocumentsUploadComponent handleUpload={handleUpload} />;
|
return (
|
||||||
});
|
<DocumentsUploadComponent
|
||||||
|
handleUpload={handleUpload}
|
||||||
|
UploadRef={UploadRef}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps, null)(DocumentsUploadContainer);
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import CurrencyInput from "../form-items-formatted/currency-form-item.component"
|
|||||||
import JobSearchSelect from "../job-search-select/job-search-select.component";
|
import JobSearchSelect from "../job-search-select/job-search-select.component";
|
||||||
import VendorSearchSelect from "../vendor-search-select/vendor-search-select.component";
|
import VendorSearchSelect from "../vendor-search-select/vendor-search-select.component";
|
||||||
import InvoiceEnterModalLinesComponent from "./invoice-enter-modal.lines.component";
|
import InvoiceEnterModalLinesComponent from "./invoice-enter-modal.lines.component";
|
||||||
|
import DocumentsUploadContainer from "../documents-upload/documents-upload.container";
|
||||||
|
|
||||||
export default function InvoiceEnterModalComponent({
|
export default function InvoiceEnterModalComponent({
|
||||||
form,
|
form,
|
||||||
@@ -12,7 +13,7 @@ export default function InvoiceEnterModalComponent({
|
|||||||
vendorAutoCompleteOptions,
|
vendorAutoCompleteOptions,
|
||||||
lineData,
|
lineData,
|
||||||
responsibilityCenters,
|
responsibilityCenters,
|
||||||
loadLines
|
loadLines,
|
||||||
}) {
|
}) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@@ -31,8 +32,8 @@ export default function InvoiceEnterModalComponent({
|
|||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: t("general.validation.required")
|
message: t("general.validation.required"),
|
||||||
}
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<JobSearchSelect
|
<JobSearchSelect
|
||||||
@@ -50,8 +51,8 @@ export default function InvoiceEnterModalComponent({
|
|||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: t("general.validation.required")
|
message: t("general.validation.required"),
|
||||||
}
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<VendorSearchSelect
|
<VendorSearchSelect
|
||||||
@@ -67,8 +68,8 @@ export default function InvoiceEnterModalComponent({
|
|||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: t("general.validation.required")
|
message: t("general.validation.required"),
|
||||||
}
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Input />
|
<Input />
|
||||||
@@ -79,8 +80,8 @@ export default function InvoiceEnterModalComponent({
|
|||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: t("general.validation.required")
|
message: t("general.validation.required"),
|
||||||
}
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<DatePicker />
|
<DatePicker />
|
||||||
@@ -98,8 +99,8 @@ export default function InvoiceEnterModalComponent({
|
|||||||
rules={[
|
rules={[
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: t("general.validation.required")
|
message: t("general.validation.required"),
|
||||||
}
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<CurrencyInput />
|
<CurrencyInput />
|
||||||
@@ -111,6 +112,20 @@ export default function InvoiceEnterModalComponent({
|
|||||||
form={form}
|
form={form}
|
||||||
responsibilityCenters={responsibilityCenters}
|
responsibilityCenters={responsibilityCenters}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<Form.Item
|
||||||
|
name="upload"
|
||||||
|
label="Upload"
|
||||||
|
>
|
||||||
|
<DocumentsUploadContainer jobId={form.getFieldValue("jobid")} />
|
||||||
|
</Form.Item>
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
console.log(form.getFieldsValue());
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
a
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,27 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import InvoiceDetailPageComponent from "./invoice-detail.page.component";
|
import InvoiceDetailPageComponent from "./invoice-detail.page.component";
|
||||||
|
import { useQuery } from "@apollo/react-hooks";
|
||||||
|
import { QUERY_INVOICE_BY_PK } from "../../graphql/invoices.queries";
|
||||||
|
import AlertComponent from "../../components/alert/alert.component";
|
||||||
|
import LoadingSpinner from "../../components/loading-spinner/loading-spinner.component";
|
||||||
|
import { Form } from "antd";
|
||||||
|
|
||||||
export default function InvoiceDetailPageContainer() {
|
export default function InvoiceDetailPageContainer() {
|
||||||
const { invoiceId } = useParams();
|
const { invoiceId } = useParams();
|
||||||
|
const [form] = Form.useForm();
|
||||||
|
|
||||||
|
const { loading, error, data } = useQuery(QUERY_INVOICE_BY_PK, {
|
||||||
|
variables: { invoiceid: invoiceId },
|
||||||
|
skip: !!!invoiceId,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (loading) return <LoadingSpinner />;
|
||||||
|
if (error) return <AlertComponent message={error.message} type="error" />;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Form form={form} initialValues={data ? data.invoices_by_pk : {}}>
|
||||||
<InvoiceDetailPageComponent />
|
<InvoiceDetailPageComponent />
|
||||||
</div>
|
</Form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user