@openlettermarketing/olc-react-sdk 0.0.14 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openlettermarketing/olc-react-sdk",
3
3
  "private": false,
4
- "version": "0.0.14",
4
+ "version": "0.0.15",
5
5
  "type": "module",
6
6
  "description": "Simplify template builder integration for any product.",
7
7
  "main": "build/index.js",
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { useEffect, useState, useLayoutEffect } from 'react';
2
2
 
3
3
  // Import Polotno and third-party libraries
4
4
  import { PolotnoContainer, WorkspaceWrap } from 'polotno';
@@ -37,6 +37,7 @@ import LexiRegularFont from "../../assets/Fonts/Lexi-Regular.ttf";
37
37
  // Components
38
38
  import TopNavigation from '../TopNavigation';
39
39
  import SidePanel from '../SidePanel';
40
+ import GenericSnackbar from '../GenericUIBlocks/GenericSnackbar';
40
41
 
41
42
  import './styles.scss';
42
43
 
@@ -112,31 +113,37 @@ const TemplateBuilder: React.FC<TemplateBuilderProps> = ({ store, styles, return
112
113
  if (!product) {
113
114
  navigate('/create-template');
114
115
  }
116
+ }, []);
115
117
 
116
- setGoogleFonts(fonts);
117
- // remove this component from the history stack
118
118
 
119
- if (id) {
120
- // @ts-ignore
121
- dispatch(getOneTemplate(id));
122
- } else if (store.pages.length === 0) {
123
- createInitialPage();
124
-
125
- }
126
- dispatch(getAllCustomFields());
127
- const handleChange = () => {
128
- if (!isStoreUpdated) {
129
- setIsStoreUpdated(true);
119
+ useEffect(() => {
120
+ if (product) {
121
+ setGoogleFonts(fonts);
122
+ // remove this component from the history stack
123
+
124
+ if (id) {
125
+ // @ts-ignore
126
+ dispatch(getOneTemplate(id));
127
+ } else if (store.pages.length === 0) {
128
+ createInitialPage();
129
+
130
130
  }
131
- };
131
+ dispatch(getAllCustomFields());
132
132
 
133
- const off = store.on("change", handleChange);
133
+ const handleChange = () => {
134
+ if (!isStoreUpdated) {
135
+ setIsStoreUpdated(true);
136
+ }
137
+ };
134
138
 
135
- return () => {
136
- store.history.clear();
137
- store.clear();
138
- off();
139
- };
139
+ const off = store.on("change", handleChange);
140
+
141
+ return () => {
142
+ store.history.clear();
143
+ store.clear();
144
+ off();
145
+ };
146
+ }
140
147
  }, []);
141
148
 
142
149
  useEffect(() => {
@@ -284,6 +291,7 @@ const TemplateBuilder: React.FC<TemplateBuilderProps> = ({ store, styles, return
284
291
  <ZoomButtons store={store} />
285
292
  </WorkspaceWrap>
286
293
  </PolotnoContainer>
294
+ <GenericSnackbar />
287
295
  </div>
288
296
  )}
289
297
  </div>
package/src/index.tsx CHANGED
@@ -64,17 +64,17 @@ const TemplateBuilder = ({
64
64
 
65
65
  // Example to run the project locally for development. Comment out these lines when building the application
66
66
 
67
- // const rootElement = document.getElementById('root');
68
- // if (rootElement) {
69
- // TemplateBuilder({
70
- // container: rootElement,
71
- // apiKey: import.meta.env.VITE_APP_ACCESS_TOKEN,
72
- // mode: 'live',
73
- // secretKey: import.meta.env.VITE_APP_PLOTNO_API_KEY,
74
- // styles: {}
75
- // });
76
- // } else {
77
- // console.error("Root element '#root' not found in the document.");
78
- // }
67
+ const rootElement = document.getElementById('root');
68
+ if (rootElement) {
69
+ TemplateBuilder({
70
+ container: rootElement,
71
+ apiKey: import.meta.env.VITE_APP_ACCESS_TOKEN,
72
+ mode: 'live',
73
+ secretKey: import.meta.env.VITE_APP_PLOTNO_API_KEY,
74
+ styles: {}
75
+ });
76
+ } else {
77
+ console.error("Root element '#root' not found in the document.");
78
+ }
79
79
 
80
80
  export default TemplateBuilder;