From 488e316550a2c3342cbff5eef1590ac68c69e7a9 Mon Sep 17 00:00:00 2001 From: Patrick Fic <> Date: Fri, 21 Aug 2020 13:35:44 -0700 Subject: [PATCH] Added automatic duplication for templates of existing template BOD-253 --- .../shop-template-add.component.jsx | 25 +++++++++++++------ client/src/graphql/templates.queries.js | 12 +++++++++ client/src/redux/user/user.sagas.js | 3 ++- 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/client/src/components/shop-template-add/shop-template-add.component.jsx b/client/src/components/shop-template-add/shop-template-add.component.jsx index 4f4325667..68d5e088d 100644 --- a/client/src/components/shop-template-add/shop-template-add.component.jsx +++ b/client/src/components/shop-template-add/shop-template-add.component.jsx @@ -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: `