import React, { useState, useEffect } from 'react'; // Libraries/Packages import { Routes, Route } from 'react-router-dom'; import { createStore, StoreType } from 'polotno/model/store'; // components import TemplateTypes from './components/TemplateTypes'; import CreateTemplate from './components/CreateTemplate'; import CreateTemplateV2 from './components/CreateTemplate/V2'; import TemplateBuilder from './components/TemplateBuilder'; import { createGlobalStyle } from 'styled-components'; import GenericSnackbar from './components/GenericUIBlocks/GenericSnackbar/Toast'; // Initialize Plotno Store const initializeStore = (secretKey: string) => { return createStore({ key: secretKey, // you can hide back-link on a paid license // but it will be good if you can keep it for Polotno project support showCredit: false, }); }; interface AppProps { secretKey: string; platformName?: string | null; templateGalleryModal?: boolean; createTemplateRoute?: string | null; templateBuilderRoute?: string | null; olcTemplate?: Record; designerTemplateQuery?: Record | null; allowSenderFields?: boolean; excludedFields?: string[] | null; designerQueryAmount?: string | number; allowPropertyFields?: boolean; allowedAddOns?: any; allowedTemplateSections?: any; allowAdditionalPage?: boolean; restrictedProducts?: any; disallowedProducts?: string[] | null | undefined; propertyOfferCost?: number; customPropertyOfferCost?: number; gsvCost?: number; showTemplateTypesPage?: boolean; currentTheme?: string | null | undefined; styles?: any; onReturnAndNavigate?: () => void; onCreateCustomTemplateQuery?: (payload: any) => Promise; onGetOneTemplate?: (payload: any) => Promise; onGetTemplates?: (payload: any) => Promise; onGetCustomFields?: () => Promise; onDuplicateTemplate?: (payload: any) => Promise; onGetBrandingImages?: (payload: any) => Promise; onDeleteBrandingImage?: (id: string | number) => Promise; onUploadBrandingImage?: (payload: any) => Promise; onGetQRCodes?: (payload: any) => Promise; onDeleteQRCodes?: (id: string | number) => Promise; onUploadQRCode?: (payload: any) => Promise; onEditQRCode?: (payload: any) => Promise; onSubmit?: (payload: any) => Promise; } const App: React.FC = ({ secretKey, platformName, templateGalleryModal, createTemplateRoute, templateBuilderRoute, olcTemplate, designerTemplateQuery, allowSenderFields, excludedFields, designerQueryAmount, allowPropertyFields, allowedAddOns, allowedTemplateSections, allowAdditionalPage, restrictedProducts, disallowedProducts, propertyOfferCost, customPropertyOfferCost, showTemplateTypesPage, gsvCost, currentTheme, styles, onReturnAndNavigate, onCreateCustomTemplateQuery, onGetOneTemplate, onGetCustomFields, onDuplicateTemplate, onGetTemplates, onGetBrandingImages, onDeleteBrandingImage, onUploadBrandingImage, onGetQRCodes, onDeleteQRCodes, onUploadQRCode, onEditQRCode, onSubmit, }) => { const [store, setStore] = useState(initializeStore(secretKey)); const [selectedTemplateType, setSelectedTemplateType] = useState(null); const [templateTypeSelected, setTemplateTypeSelected] = useState(false); const currentPath = window?.location?.pathname; useEffect(() => { if ( currentPath === createTemplateRoute || currentPath === '/create-template' || designerTemplateQuery ) { const newStore = initializeStore(secretKey); setStore(newStore); } }, [currentPath]); const GlobalStyle = styles && Object.keys(styles).length ? createGlobalStyle` :root { ${styles ? Object.entries(styles.root) .map(([key, value]) => `${key}: ${value} !important;`) .join(' ') : '' } } ` : createGlobalStyle`<>`; return (
: currentTheme === 'v2' ? : } /> } />
); }; export default App;