Added basic pages for template editing BOD-85

This commit is contained in:
Patrick Fic
2020-05-11 21:32:11 -07:00
parent 630e7df3fd
commit b518f84f5f
20 changed files with 455 additions and 197 deletions

View File

@@ -0,0 +1,34 @@
import { useQuery } from "@apollo/react-hooks";
import queryString from "query-string";
import React, { useState } from "react";
import { useLocation } from "react-router-dom";
import { QUERY_TEMPLATE_BY_PK } from "../../graphql/templates.queries";
import AlertComponent from "../alert/alert.component";
import LoadingSpinner from "../loading-spinner/loading-spinner.component";
import ShopTemplateEditorComponent from "./shop-template-editor.component";
export default function ShopTemplateEditorContainer() {
const search = queryString.parse(useLocation().search);
const editorState = useState({ html: "", gql: "" });
const { loading, error, data } = useQuery(QUERY_TEMPLATE_BY_PK, {
variables: {
templateId: search.customTemplateId,
},
skip: !!!search.customTemplateId,
});
if (!!!search.customTemplateId) return <span>No selection.</span>;
if (error) return <AlertComponent message={error.message} type='error' />;
return (
<LoadingSpinner loading={loading}>
<ShopTemplateEditorComponent
templateId={search.customTemplateId}
html={data ? data.templates_by_pk.html : ""}
gql={data ? data.templates_by_pk.query : ""}
editorState={editorState}
/>
</LoadingSpinner>
);
}