Added automatic duplication for templates of existing template BOD-253
This commit is contained in:
@@ -7,10 +7,14 @@ import { useTranslation } from "react-i18next";
|
||||
import { connect } from "react-redux";
|
||||
import { useHistory, useLocation } from "react-router-dom";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { INSERT_TEMPLATE } from "../../graphql/templates.queries";
|
||||
import {
|
||||
INSERT_TEMPLATE,
|
||||
QUERY_TEMPLATES_BY_NAME_FOR_DUPE,
|
||||
} from "../../graphql/templates.queries";
|
||||
import { selectBodyshop } from "../../redux/user/user.selectors";
|
||||
import { TemplateList } from "../../utils/TemplateConstants";
|
||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
||||
import { client } from "../../App/App.container";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
@@ -37,18 +41,23 @@ export function ShopTemplateAddComponent({
|
||||
const handleAdd = async (item) => {
|
||||
logImEXEvent("shop_template_add");
|
||||
|
||||
const defaultTemplateData = await client.query({
|
||||
query: QUERY_TEMPLATES_BY_NAME_FOR_DUPE,
|
||||
variables: { name: item.key },
|
||||
});
|
||||
|
||||
const template = defaultTemplateData.data.templates.filter(
|
||||
(t) => t.bodyshopid === null
|
||||
)[0];
|
||||
|
||||
const result = await insertTemplate({
|
||||
variables: {
|
||||
template: {
|
||||
name: item.key,
|
||||
bodyshopid: bodyshop.id,
|
||||
html: `<div>Insert your custom template here.</div>`,
|
||||
query: `query JOBS {
|
||||
jobs{
|
||||
id
|
||||
ro_number
|
||||
}
|
||||
}`,
|
||||
jsontemplate: template && template.jsontemplate,
|
||||
html: template && template.html,
|
||||
query: template && template.query,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user