Added template previewing with non-functional GQL editor BOD-126

This commit is contained in:
Patrick Fic
2020-09-03 16:14:30 -07:00
parent f4fed87f61
commit 051be83303
16 changed files with 50580 additions and 40 deletions

View File

@@ -0,0 +1,75 @@
import { Button } from "antd";
import axios from "axios";
import gql from "graphql-tag";
import inlineCss from "inline-css";
import { JsonEditor as Editor } from "jsoneditor-react";
import "jsoneditor-react/es/editor.min.css";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import { connect } from "react-redux";
import { createStructuredSelector } from "reselect";
import { client } from "../../App/App.container";
import { selectBodyshop } from "../../redux/user/user.selectors";
import { displayTemplateInWindowNoprint } from "../../utils/RenderTemplate";
const mapStateToProps = createStructuredSelector({
bodyshop: selectBodyshop,
});
const mapDispatchToProps = (dispatch) => ({
//setUserLanguage: language => dispatch(setUserLanguage(language))
});
export function ShopTemplateTestRender({ bodyshop, query, emailEditorRef }) {
const [variables, setVariables] = useState({ id: "uuid" });
const [loading, setLoading] = useState(false);
const { t } = useTranslation();
const handleTestRender = async () => {
try {
setLoading(true);
emailEditorRef.current.exportHtml(async (data) => {
inlineCss(data.html, {
url: `${window.location.protocol}://${window.location.host}/`,
}).then(async function (inlineHtml) {
try {
const { data: contextData } = await client.query({
query: gql(query),
variables: variables,
fetchPolicy: "network-only",
});
const { data } = await axios.post("/render", {
view: inlineHtml,
context: { ...contextData, bodyshop: bodyshop },
});
displayTemplateInWindowNoprint(data);
setLoading(false);
} catch (error) {
setLoading(false);
alert(error);
}
});
});
} catch (error) {
setLoading(false);
alert(error);
}
};
return (
<div>
<Button loading={loading} onClick={handleTestRender}>
{t("bodyshop.actions.testrender")}
</Button>
<div style={{ width: "20rem" }}>
<Editor value={variables} onChange={(e) => setVariables(e)} />
</div>
</div>
);
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(ShopTemplateTestRender);