BOD-11 BOD-12 BOD-10 Updated packages + changes apollo hooks imports

This commit is contained in:
Patrick Fic
2020-03-23 11:29:37 -07:00
parent c55f5ebafc
commit 192d2ee0f0
45 changed files with 1040 additions and 590 deletions

View File

@@ -1,8 +1,8 @@
import React, { useState } from "react";
import React, { useState, useEffect } from "react";
import JobsCreateComponent from "./jobs-create.component";
import { Form } from "antd";
import JobCreateContext from "./jobs-create.context";
import { useMutation, useLazyQuery } from "react-apollo";
import { useMutation, useLazyQuery } from "@apollo/react-hooks";
import { INSERT_NEW_JOB } from "../../graphql/jobs.queries";
import { QUERY_OWNER_FOR_JOB_CREATION } from "../../graphql/owners.queries";
import { connect } from "react-redux";
@@ -22,11 +22,27 @@ function JobsCreateContainer({ bodyshop }) {
const [form] = Form.useForm();
const [state] = contextState;
const [insertJob] = useMutation(INSERT_NEW_JOB);
const [loadOwner] = useLazyQuery(QUERY_OWNER_FOR_JOB_CREATION);
const [loadOwner, RemoteOwnerData] = useLazyQuery(
QUERY_OWNER_FOR_JOB_CREATION
);
useEffect(() => {
if (!!state.owner.selectedid) {
console.log("Loading Selected Owner ID");
loadOwner({
variables: { id: state.owner.selectedid }
});
}
}, [state.owner.selectedid]);
const runInsertJob = job => {
console.log("Job To Save", job);
insertJob({ variables: { job: job } });
};
const handleFinish = values => {
console.log("Form Values", values);
console.log("state", state);
console.log("Progress State", state);
let job = Object.assign(
{},
values,
@@ -43,30 +59,19 @@ function JobsCreateContainer({ bodyshop }) {
shopid: bodyshop.id
}
);
//TODO Logic to ensure the owner is actually fetched.
let ownerData;
if (!!job.owner) {
//spread the owner into to the job
console.log("Spread New Owner");
let ownerData = job.owner.data;
ownerData = job.owner.data;
delete ownerData.allow_text_message;
delete ownerData.preferred_contact;
job = { ...job, ...ownerData };
runInsertJob(job);
} else {
//lookup the owner and spread it then.
loadOwner({
variables: { id: state.owner.selectedid },
onCompleted: data => {
console.log("data", data);
runInsertJob({ ...job, ...data.owners_by_pk });
}
});
ownerData = RemoteOwnerData.data.owners_by_pk;
delete ownerData.id;
delete ownerData.__typename;
}
};
const runInsertJob = job => {
console.log("Job To Save", job);
insertJob({ variables: { job: job } });
job = { ...job, ...ownerData };
runInsertJob(job);
};
return (