@openlettermarketing/olc-react-sdk 2.1.4 → 2.1.5-beta.2

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.
Files changed (230) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc.cjs +18 -0
  3. package/.eslintrc.yml +47 -0
  4. package/.github/workflows/publish-beta.yml +154 -0
  5. package/.github/workflows/publish-production.yml +143 -0
  6. package/.prettierignore +3 -0
  7. package/.prettierrc.yml +5 -0
  8. package/CHANGELOG.md +4 -0
  9. package/babel.config.json +10 -0
  10. package/build/index.js +82 -82
  11. package/build/index.js.map +1 -1
  12. package/build/types/version.d.ts +1 -1
  13. package/examples/.eslintrc.yml +4 -0
  14. package/index.html +18 -0
  15. package/package.json +1 -1
  16. package/public/vite.svg +1 -0
  17. package/src/App.tsx +209 -0
  18. package/src/assets/Fonts/Lexi-Regular.ttf +0 -0
  19. package/src/assets/images/create-template/prebuilt.svg +13 -0
  20. package/src/assets/images/create-template/scratch.svg +4 -0
  21. package/src/assets/images/input/cancel.tsx +20 -0
  22. package/src/assets/images/input/search.tsx +20 -0
  23. package/src/assets/images/input/select-cancel.tsx +17 -0
  24. package/src/assets/images/modal-icons/add.tsx +36 -0
  25. package/src/assets/images/modal-icons/cancel-file.tsx +12 -0
  26. package/src/assets/images/modal-icons/cancel-input.tsx +13 -0
  27. package/src/assets/images/modal-icons/cancel.tsx +35 -0
  28. package/src/assets/images/modal-icons/close-new.svg +3 -0
  29. package/src/assets/images/modal-icons/confirm-close-icon.tsx +14 -0
  30. package/src/assets/images/modal-icons/confirm-new.tsx +22 -0
  31. package/src/assets/images/modal-icons/confirm.svg +12 -0
  32. package/src/assets/images/modal-icons/cross.tsx +23 -0
  33. package/src/assets/images/modal-icons/del.tsx +19 -0
  34. package/src/assets/images/modal-icons/design-icon.tsx +22 -0
  35. package/src/assets/images/modal-icons/doc.tsx +43 -0
  36. package/src/assets/images/modal-icons/docx.tsx +43 -0
  37. package/src/assets/images/modal-icons/envelope-icon.tsx +26 -0
  38. package/src/assets/images/modal-icons/info.tsx +19 -0
  39. package/src/assets/images/modal-icons/jpeg.tsx +43 -0
  40. package/src/assets/images/modal-icons/jpg.tsx +43 -0
  41. package/src/assets/images/modal-icons/modal-cros.svg +4 -0
  42. package/src/assets/images/modal-icons/modal-cross.tsx +37 -0
  43. package/src/assets/images/modal-icons/new-cancel.tsx +11 -0
  44. package/src/assets/images/modal-icons/order-download.tsx +42 -0
  45. package/src/assets/images/modal-icons/pdf.tsx +51 -0
  46. package/src/assets/images/modal-icons/png.tsx +43 -0
  47. package/src/assets/images/modal-icons/save.tsx +23 -0
  48. package/src/assets/images/modal-icons/template-copy.tsx +25 -0
  49. package/src/assets/images/modal-icons/tool-cancel.tsx +25 -0
  50. package/src/assets/images/products/bi-new.svg +23 -0
  51. package/src/assets/images/products/left-arrow.svg +17 -0
  52. package/src/assets/images/products/personal-new.tsx +31 -0
  53. package/src/assets/images/products/postcard-new.tsx +27 -0
  54. package/src/assets/images/products/professional-new.tsx +24 -0
  55. package/src/assets/images/products/real-new.tsx +30 -0
  56. package/src/assets/images/products/right-arrow.svg +17 -0
  57. package/src/assets/images/products/snap-new.svg +31 -0
  58. package/src/assets/images/templates/actions.svg +3 -0
  59. package/src/assets/images/templates/address-block-icon.tsx +62 -0
  60. package/src/assets/images/templates/archive.svg +3 -0
  61. package/src/assets/images/templates/arrow-down.tsx +27 -0
  62. package/src/assets/images/templates/back-arrow.tsx +19 -0
  63. package/src/assets/images/templates/bi-fold-self-mailers.tsx +28 -0
  64. package/src/assets/images/templates/check.svg +3 -0
  65. package/src/assets/images/templates/code.svg +10 -0
  66. package/src/assets/images/templates/content-copy-icon.tsx +24 -0
  67. package/src/assets/images/templates/custom-add-on-icon.tsx +18 -0
  68. package/src/assets/images/templates/custom-qr-section-icon.tsx +9 -0
  69. package/src/assets/images/templates/custom-template.tsx +23 -0
  70. package/src/assets/images/templates/designer.tsx +43 -0
  71. package/src/assets/images/templates/dot.tsx +22 -0
  72. package/src/assets/images/templates/download-v2.svg +4 -0
  73. package/src/assets/images/templates/download.svg +4 -0
  74. package/src/assets/images/templates/dummy-template.tsx +76 -0
  75. package/src/assets/images/templates/dynamic-field.tsx +119 -0
  76. package/src/assets/images/templates/edit-pencil-icon.tsx +21 -0
  77. package/src/assets/images/templates/edit.svg +3 -0
  78. package/src/assets/images/templates/epo-icon.tsx +16 -0
  79. package/src/assets/images/templates/field.tsx +29 -0
  80. package/src/assets/images/templates/gsv-icon.tsx +31 -0
  81. package/src/assets/images/templates/info-icon.tsx +37 -0
  82. package/src/assets/images/templates/left-arrow.svg +17 -0
  83. package/src/assets/images/templates/pencil.svg +3 -0
  84. package/src/assets/images/templates/personal-letter.tsx +53 -0
  85. package/src/assets/images/templates/postcard.tsx +32 -0
  86. package/src/assets/images/templates/professional-letter.tsx +53 -0
  87. package/src/assets/images/templates/qr-code.tsx +13 -0
  88. package/src/assets/images/templates/real-penned-letters.tsx +57 -0
  89. package/src/assets/images/templates/right-arrow.svg +17 -0
  90. package/src/assets/images/templates/size-image-lg.tsx +20 -0
  91. package/src/assets/images/templates/size-image-mid.tsx +20 -0
  92. package/src/assets/images/templates/size-image-xl.tsx +20 -0
  93. package/src/assets/images/templates/size-image.tsx +20 -0
  94. package/src/assets/images/templates/snap-pack.tsx +67 -0
  95. package/src/assets/images/templates/template-default-design.tsx +21 -0
  96. package/src/assets/images/templates/trash-upload.svg +3 -0
  97. package/src/assets/images/templates/trash.svg +3 -0
  98. package/src/assets/images/templates/tri-fold-self-mailers.tsx +93 -0
  99. package/src/assets/images/templates/upload-image.svg +10 -0
  100. package/src/assets/images/templates/x.svg +3 -0
  101. package/src/assets/images/thumbnails/one.svg +9 -0
  102. package/src/assets/images/tooltip/tool-arrow.tsx +25 -0
  103. package/src/components/CreateTemplate/V2/index.tsx +525 -0
  104. package/src/components/CreateTemplate/V2/styles.scss +372 -0
  105. package/src/components/CreateTemplate/index.tsx +508 -0
  106. package/src/components/CreateTemplate/styles.scss +404 -0
  107. package/src/components/GenericUIBlocks/Button/index.tsx +54 -0
  108. package/src/components/GenericUIBlocks/Button/styles.scss +43 -0
  109. package/src/components/GenericUIBlocks/CircularProgress/index.tsx +18 -0
  110. package/src/components/GenericUIBlocks/CircularProgress/styles.scss +93 -0
  111. package/src/components/GenericUIBlocks/CustomTooltip/index.tsx +88 -0
  112. package/src/components/GenericUIBlocks/CustomTooltip/styles.scss +19 -0
  113. package/src/components/GenericUIBlocks/Dialog/V2/index.tsx +227 -0
  114. package/src/components/GenericUIBlocks/Dialog/V2/styles.scss +289 -0
  115. package/src/components/GenericUIBlocks/Dialog/index.tsx +185 -0
  116. package/src/components/GenericUIBlocks/Dialog/styles.scss +227 -0
  117. package/src/components/GenericUIBlocks/Divider/index.tsx +12 -0
  118. package/src/components/GenericUIBlocks/Divider/styles.scss +7 -0
  119. package/src/components/GenericUIBlocks/GeneralSelect/index.tsx +114 -0
  120. package/src/components/GenericUIBlocks/GeneralSelect/styles.scss +406 -0
  121. package/src/components/GenericUIBlocks/GeneralTooltip/index.tsx +25 -0
  122. package/src/components/GenericUIBlocks/GeneralTooltip/styles.scss +20 -0
  123. package/src/components/GenericUIBlocks/GenericSnackbar/Toast/index.tsx +91 -0
  124. package/src/components/GenericUIBlocks/GenericSnackbar/Toast/styles.scss +92 -0
  125. package/src/components/GenericUIBlocks/Grid/index.tsx +82 -0
  126. package/src/components/GenericUIBlocks/Input/index.tsx +269 -0
  127. package/src/components/GenericUIBlocks/Input/styles.scss +332 -0
  128. package/src/components/GenericUIBlocks/Tabs/index.tsx +71 -0
  129. package/src/components/GenericUIBlocks/Tabs/styles.scss +42 -0
  130. package/src/components/GenericUIBlocks/Typography/index.tsx +18 -0
  131. package/src/components/GenericUIBlocks/Typography/styles.scss +27 -0
  132. package/src/components/SidePanel/CustomAddOns/index.tsx +342 -0
  133. package/src/components/SidePanel/CustomAddOns/styles.scss +86 -0
  134. package/src/components/SidePanel/CustomBlockColors/index.tsx +211 -0
  135. package/src/components/SidePanel/CustomBlockColors/styles.scss +80 -0
  136. package/src/components/SidePanel/CustomFields/customFieldSection.tsx +547 -0
  137. package/src/components/SidePanel/CustomFields/styles.scss +64 -0
  138. package/src/components/SidePanel/CustomQRCode/V2/QRCodeModal/index.tsx +172 -0
  139. package/src/components/SidePanel/CustomQRCode/V2/QRCodeModal/styles.scss +46 -0
  140. package/src/components/SidePanel/CustomQRCode/index.tsx +1070 -0
  141. package/src/components/SidePanel/CustomQRCode/styles.scss +149 -0
  142. package/src/components/SidePanel/CustomUploads/V2/index.tsx +542 -0
  143. package/src/components/SidePanel/CustomUploads/V2/styles.scss +267 -0
  144. package/src/components/SidePanel/CustomUploads/index.tsx +301 -0
  145. package/src/components/SidePanel/Templates/ModalGallery/HireDesigner/index.tsx +424 -0
  146. package/src/components/SidePanel/Templates/ModalGallery/HireDesigner/styles.scss +180 -0
  147. package/src/components/SidePanel/Templates/ModalGallery/V2/index.tsx +235 -0
  148. package/src/components/SidePanel/Templates/ModalGallery/V2/styles.scss +244 -0
  149. package/src/components/SidePanel/Templates/ModalGallery/index.tsx +231 -0
  150. package/src/components/SidePanel/Templates/SideBarGallery/index.tsx +233 -0
  151. package/src/components/SidePanel/Templates/SideBarGallery/styles.scss +152 -0
  152. package/src/components/SidePanel/Templates/TemplatesCard/V2/index.tsx +149 -0
  153. package/src/components/SidePanel/Templates/TemplatesCard/V2/styles.scss +156 -0
  154. package/src/components/SidePanel/Templates/TemplatesCard/index.tsx +160 -0
  155. package/src/components/SidePanel/Templates/TemplatesCard/styles.scss +98 -0
  156. package/src/components/SidePanel/Templates/customTemplateSection.tsx +793 -0
  157. package/src/components/SidePanel/Templates/styles.scss +244 -0
  158. package/src/components/SidePanel/index.tsx +160 -0
  159. package/src/components/TemplateBuilder/index.tsx +585 -0
  160. package/src/components/TemplateBuilder/styles.scss +100 -0
  161. package/src/components/TemplateTypes/index.tsx +96 -0
  162. package/src/components/TemplateTypes/styles.scss +91 -0
  163. package/src/components/TopNavigation/ConfirmNavigateDialog/index.tsx +81 -0
  164. package/src/components/TopNavigation/ConfirmNavigateDialog/styles.scss +123 -0
  165. package/src/components/TopNavigation/DuplicateTemplateModal.tsx +103 -0
  166. package/src/components/TopNavigation/EditTemplateNameModel/index.tsx +71 -0
  167. package/src/components/TopNavigation/EditTemplateNameModel/styles.scss +88 -0
  168. package/src/components/TopNavigation/SaveTemplateModel/index.tsx +201 -0
  169. package/src/components/TopNavigation/SaveTemplateModel/styles.scss +128 -0
  170. package/src/components/TopNavigation/index.tsx +938 -0
  171. package/src/components/TopNavigation/styles.scss +303 -0
  172. package/src/importMeta.d.ts +31 -0
  173. package/src/index.scss +131 -0
  174. package/src/index.tsx +238 -0
  175. package/src/libs/test.ts +7 -0
  176. package/src/redux/actions/action-types.ts +52 -0
  177. package/src/redux/actions/customQRCodeActions.ts +54 -0
  178. package/src/redux/actions/snackbarActions.ts +16 -0
  179. package/src/redux/actions/templateActions.ts +236 -0
  180. package/src/redux/reducers/customFieldReducer.ts +99 -0
  181. package/src/redux/reducers/customQRCodeReducer.ts +58 -0
  182. package/src/redux/reducers/index.ts +15 -0
  183. package/src/redux/reducers/snackbarReducer.ts +40 -0
  184. package/src/redux/reducers/templateReducer.ts +485 -0
  185. package/src/redux/store.ts +18 -0
  186. package/src/styles/colors.scss +61 -0
  187. package/src/test/mocks.js +89 -0
  188. package/src/test/setupJest.js +1 -0
  189. package/src/utils/api.ts +36 -0
  190. package/src/utils/constants.ts +182 -0
  191. package/src/utils/customStyles.ts +45 -0
  192. package/src/utils/fetchWrapper.ts +73 -0
  193. package/src/utils/fonts.json +1597 -0
  194. package/src/utils/helper.ts +205 -0
  195. package/src/utils/local-storage.ts +15 -0
  196. package/src/utils/message.ts +162 -0
  197. package/src/utils/products.ts +186 -0
  198. package/src/utils/template-builder.ts +328 -0
  199. package/src/utils/templateIdentifierArea/biFold.ts +107 -0
  200. package/src/utils/templateIdentifierArea/index.ts +35 -0
  201. package/src/utils/templateIdentifierArea/personal.ts +107 -0
  202. package/src/utils/templateIdentifierArea/postCards.ts +163 -0
  203. package/src/utils/templateIdentifierArea/professional.ts +125 -0
  204. package/src/utils/templateIdentifierArea/snapPack.ts +107 -0
  205. package/src/utils/templateIdentifierArea/triFold.ts +107 -0
  206. package/src/utils/templateRestrictedArea/biFold.ts +329 -0
  207. package/src/utils/templateRestrictedArea/nonWindowProfessional.ts +90 -0
  208. package/src/utils/templateRestrictedArea/personal.ts +90 -0
  209. package/src/utils/templateRestrictedArea/postCard.ts +334 -0
  210. package/src/utils/templateRestrictedArea/postCardJumbo.tsx +408 -0
  211. package/src/utils/templateRestrictedArea/professional.ts +318 -0
  212. package/src/utils/templateRestrictedArea/realPenned.ts +233 -0
  213. package/src/utils/templateRestrictedArea/snapPack.ts +1009 -0
  214. package/src/utils/templateRestrictedArea/triFold.ts +330 -0
  215. package/src/utils/templateSafetyBorders/biFold.ts +91 -0
  216. package/src/utils/templateSafetyBorders/index.ts +43 -0
  217. package/src/utils/templateSafetyBorders/personal.ts +41 -0
  218. package/src/utils/templateSafetyBorders/postCards.ts +259 -0
  219. package/src/utils/templateSafetyBorders/professional.ts +78 -0
  220. package/src/utils/templateSafetyBorders/snapPack.ts +165 -0
  221. package/src/utils/templateSafetyBorders/triFold.ts +114 -0
  222. package/src/utils/templateSafetyBorders/types.d.ts +68 -0
  223. package/src/utils/types.ts +12 -0
  224. package/src/v2Theme.scss +142 -0
  225. package/tsconfig.json +29 -0
  226. package/tsconfig.node.json +12 -0
  227. package/update-version.js +23 -0
  228. package/version.js +1 -0
  229. package/vite.config.ts +8 -0
  230. package/webpack.config.js +80 -0
@@ -0,0 +1,793 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+
3
+ // Polotno and third party libraries
4
+ import { observer } from 'mobx-react-lite';
5
+ import { SectionTab } from 'polotno/side-panel';
6
+ import type { StoreType } from 'polotno/model/store';
7
+ import type { TemplatesSection } from 'polotno/side-panel';
8
+
9
+ // Actions
10
+ import {
11
+ clearAllTemplates,
12
+ getAllTemplateCategories,
13
+ getAllTemplatesByTab,
14
+ setPageCount,
15
+ } from '../../../redux/actions/templateActions';
16
+ import {
17
+ SET_BLOCK_COLOR,
18
+ SET_ROS_OFFER_PERCENTAGE,
19
+ TEMPLATE_LOADING,
20
+ } from '../../../redux/actions/action-types';
21
+ import { failure } from '../../../redux/actions/snackbarActions';
22
+
23
+ // Hooks
24
+ import { useDispatch, useSelector } from 'react-redux';
25
+ import { AppDispatch, RootState } from '../../../redux/store';
26
+ import { clearQrFields } from '../../../redux/actions/customQRCodeActions';
27
+
28
+ // Utils
29
+ import {
30
+ multiPageLetters,
31
+ defaultTemplateTypes,
32
+ DPI,
33
+ DEFAULT_RESTRICTED_AREA_BG,
34
+ } from '../../../utils/constants';
35
+ import {
36
+ changeColorOfBoxesForSnapPack,
37
+ drawRestrictedAreaOnPage,
38
+ extractCustomRistrictedBoxColor,
39
+ getFileAsBlob,
40
+ } from '../../../utils/template-builder';
41
+ import { MESSAGES } from '../../../utils/message';
42
+ import { getItem, removeItem, setItem } from '../../../utils/local-storage';
43
+ import { addSafetyBordersForTemplates } from '../../../utils/templateSafetyBorders';
44
+ import { addIdentifiersForTemplates } from '../../../utils/templateIdentifierArea';
45
+ import { addElementsforRealPennedLetters } from '../../../utils/templateRestrictedArea/realPenned';
46
+
47
+ // Components
48
+ import Dialog from '../../GenericUIBlocks/Dialog';
49
+ import DialogV2 from '../../GenericUIBlocks/Dialog/V2';
50
+ import SideBarGallery from './SideBarGallery';
51
+ import ModalGallery from './ModalGallery';
52
+ import ModalGalleryV2 from './ModalGallery/V2';
53
+ import HireDesigner from './ModalGallery/HireDesigner';
54
+
55
+ // Icons
56
+ // @ts-ignore
57
+ import CustomTemplate from '../../../assets/images/templates/custom-template';
58
+ import ModalCross from '../../../assets/images/modal-icons/modal-cross';
59
+ import ConfirmNew from '../../../assets/images/modal-icons/confirm-new';
60
+
61
+ // styles
62
+ import './styles.scss';
63
+
64
+
65
+ type SideSection = typeof TemplatesSection;
66
+
67
+ const designDialogStyles = {
68
+ maxWidth: '430px',
69
+ minHeight: '265px',
70
+ };
71
+
72
+ const loadDialogStyles = {
73
+ maxWidth: '430px',
74
+ minHeight: '300px',
75
+ };
76
+
77
+ const loadDialogStylesV2 = {
78
+ maxWidth: '567px',
79
+ minHeight: '330px',
80
+ padding: '40px',
81
+ };
82
+
83
+
84
+ export type Payload = {
85
+ tab: string;
86
+ page: number;
87
+ pageSize: number;
88
+ productId: string | null;
89
+ search?: string;
90
+ categoryIds?: string[];
91
+ };
92
+
93
+ export type TemplateType = {
94
+ id: string;
95
+ label: string;
96
+ value: string;
97
+ };
98
+
99
+ export type TemplateCategory = {
100
+ id: string;
101
+ title: string;
102
+ totalTemplates: number;
103
+ label?: string;
104
+ };
105
+
106
+ export type TemplateRecord = {
107
+ id: string;
108
+ thumbnailUrl: string;
109
+ title: string;
110
+ };
111
+
112
+ type CustomTemplateSectionProps = {
113
+ store: StoreType;
114
+ active: boolean;
115
+ platformName?: string | null;
116
+ templateGalleryModal?: boolean;
117
+ selectedSection?: string;
118
+ designerQueryAmount?: string | number;
119
+ hireDesignerModal?: any;
120
+ setHireDesignerModal?: any;
121
+ allowedTemplateSections?: any;
122
+ allowedAddOns?: any;
123
+ currentTheme?: string | null | undefined;
124
+ onClick: () => void;
125
+ onCreateCustomTemplateQuery?: (payload: any) => Promise<any>;
126
+ onGetOneTemplate?: (payload: any) => Promise<any>;
127
+ onGetTemplates?: (payload: Payload) => Promise<any>;
128
+ selectedTemplateType?: string | null;
129
+ };
130
+
131
+ const CustomTemplateSection: SideSection = {
132
+ name: 'Templates',
133
+ Tab: observer(
134
+ (props: { store: StoreType; active: boolean; onClick: () => void }) => (
135
+ <SectionTab name="Templates" {...props}>
136
+ <CustomTemplate fill="var(--text-color)" />
137
+ </SectionTab>
138
+ )
139
+ ) as SideSection['Tab'],
140
+ Panel: observer(
141
+ ({
142
+ store,
143
+ platformName,
144
+ templateGalleryModal,
145
+ selectedSection,
146
+ designerQueryAmount,
147
+ hireDesignerModal,
148
+ setHireDesignerModal,
149
+ allowedTemplateSections,
150
+ allowedAddOns,
151
+ currentTheme,
152
+ selectedTemplateType,
153
+ onCreateCustomTemplateQuery,
154
+ onGetOneTemplate,
155
+ onGetTemplates,
156
+ }: CustomTemplateSectionProps) => {
157
+ const dispatch: AppDispatch = useDispatch();
158
+
159
+ const [openGalleryModal, setOpenGalleryModal] = useState(false);
160
+ const [templateTypes, setTemplateTypes] = useState<
161
+ TemplateType[] | null
162
+ >();
163
+ const [currentTemplateType, setCurrentTemplateType] =
164
+ useState<TemplateType>();
165
+ const [selectedCategory, setSelectedCategory] =
166
+ useState<TemplateCategory | null>(null);
167
+ const [selectedRecord, setSelectedRecord] =
168
+ useState<TemplateRecord | null>(null);
169
+ const [templateCategories, setTemplateCategories] = useState<
170
+ TemplateCategory[]
171
+ >([]);
172
+ const [myTemplates, setMyTemplates] = useState<TemplateRecord[]>([]);
173
+ const [teamTemplates, setTeamTemplates] = useState<TemplateRecord[]>([]);
174
+ const [olcTemplates, setOlcTemplates] = useState<TemplateRecord[]>([]);
175
+ const [searchApplied, setSearchApplied] = useState(false);
176
+ const [search, setSearch] = useState('');
177
+ const [loader, setLoader] = useState(false);
178
+ const [pagination, setPagination] = useState({
179
+ count: 0,
180
+ currentPage: 0,
181
+ perPage: 0,
182
+ total: 0,
183
+ });
184
+
185
+ const paginationRef = useRef(pagination);
186
+ const searchRef = useRef(search);
187
+ const currentTemplateTypeRef = useRef(currentTemplateType);
188
+ const selectedCategoryRef = useRef(selectedCategory);
189
+
190
+ const templates = useSelector(
191
+ (state: RootState) => state.templates.templates
192
+ ) as Record<string, any>;
193
+ const template = useSelector(
194
+ (state: RootState) => state.templates.template
195
+ ) as Record<string, any>;
196
+ const templatesPagination = useSelector(
197
+ (state: any) => state.templates.templatesPagination
198
+ );
199
+ const product = useSelector((state: any) => state.templates.product);
200
+ const envelopeType = useSelector(
201
+ (state: RootState) => state.templates.envelopeType
202
+ );
203
+ const templateLoading = useSelector(
204
+ (state: RootState) => state.templates.templateLoading
205
+ );
206
+
207
+ const [isShowDialog, setIsShowDialog] = useState({
208
+ open: false,
209
+ model: '',
210
+ });
211
+
212
+ const handleLoadTemplateModel = (record: any) => {
213
+ setSelectedRecord(record);
214
+ handleDialogChange('load-template');
215
+ };
216
+
217
+ const getTemplatesByTab = async (page = 1) => {
218
+ try {
219
+ page === 1 && setLoader(true);
220
+ const payload: Payload = {
221
+ tab:
222
+ currentTemplateTypeRef.current?.id === '1'
223
+ ? 'my-templates'
224
+ : currentTemplateTypeRef.current?.id === '2'
225
+ ? 'team-templates'
226
+ : 'olc-templates',
227
+ page: page,
228
+ pageSize: 10,
229
+ productId: product?.id,
230
+ };
231
+ searchRef.current.length
232
+ ? (payload.search = searchRef.current)
233
+ : undefined;
234
+ currentTemplateTypeRef.current?.id === '3'
235
+ ? (payload.categoryIds = selectedCategoryRef?.current?.id.split(','))
236
+ : undefined;
237
+ const isCustomTemplateType =
238
+ currentTemplateTypeRef.current?.id === '1' ||
239
+ currentTemplateTypeRef.current?.id === '2';
240
+ const templates: any =
241
+ isCustomTemplateType && onGetTemplates
242
+ ? await onGetTemplates(payload)
243
+ : await getAllTemplatesByTab(payload);
244
+ if (templates?.rows) {
245
+ const newTemplates = templates.rows;
246
+
247
+ if (currentTemplateTypeRef.current?.id === '1') {
248
+ if (templates.currentPage === 1) {
249
+ setMyTemplates(newTemplates);
250
+ } else {
251
+ setMyTemplates((prevTemplates) => [
252
+ ...prevTemplates,
253
+ ...newTemplates,
254
+ ]);
255
+ }
256
+ } else if (currentTemplateTypeRef.current?.id === '2') {
257
+ if (templates.currentPage === 1) {
258
+ setTeamTemplates(newTemplates);
259
+ } else {
260
+ setTeamTemplates((prevTemplates) => [
261
+ ...prevTemplates,
262
+ ...newTemplates,
263
+ ]);
264
+ }
265
+ } else if (currentTemplateTypeRef.current?.id === '3') {
266
+ if (templates.currentPage === 1) {
267
+ setOlcTemplates(newTemplates);
268
+ } else {
269
+ setOlcTemplates((prevTemplates) => [
270
+ ...prevTemplates,
271
+ ...newTemplates,
272
+ ]);
273
+ }
274
+ }
275
+ setPagination({
276
+ count: templates.count,
277
+ currentPage: templates.currentPage,
278
+ perPage: templates.perPage,
279
+ total: templates.total,
280
+ });
281
+ }
282
+ } catch (error) {
283
+ return error;
284
+ } finally {
285
+ setLoader(false);
286
+ }
287
+ };
288
+
289
+ const getAllCategories = async () => {
290
+ const categories: Record<string, any> = await dispatch(
291
+ getAllTemplateCategories
292
+ );
293
+ if (categories?.status === 200) {
294
+ if (categories?.data?.data) {
295
+ const allCategories = categories?.data?.data?.map((item: any) => ({
296
+ ...item,
297
+ label: item.title,
298
+ }));
299
+ if (allCategories.length === 1) {
300
+ setSelectedCategory(allCategories[0]);
301
+ }
302
+ setTemplateCategories(
303
+ allCategories.filter((item: any) => item.totalTemplates > 0)
304
+ );
305
+ }
306
+ }
307
+ };
308
+
309
+ const closeGalleryModal = () => {
310
+ let sideBar = document.getElementsByClassName('polotno-panel-container');
311
+ const firstSideBar = sideBar[0];
312
+ if (firstSideBar) {
313
+ //@ts-ignore
314
+ firstSideBar.style.display = 'block';
315
+ }
316
+ setOpenGalleryModal(false);
317
+ store.openSidePanel(selectedSection || 'text');
318
+ removeItem('currentTab');
319
+ document.body.classList.remove('no-scroll');
320
+ };
321
+
322
+ const closeHireDesignerModal = () => {
323
+ setHireDesignerModal(false);
324
+ let sideBar = document.getElementsByClassName('polotno-panel-container');
325
+ const firstSideBar = sideBar[0];
326
+ if (firstSideBar) {
327
+ //@ts-ignore
328
+ firstSideBar.style.display = 'block';
329
+ }
330
+ store.openSidePanel(selectedSection || 'text');
331
+ removeItem('currentTab');
332
+ removeItem('hireDesignerFormState');
333
+ removeItem('queryFiles');
334
+ document.body.classList.remove('no-scroll');
335
+ }
336
+
337
+ const handleTabChange = (tab: any) => {
338
+ setCurrentTemplateType(tab);
339
+ setItem('currentTab', JSON.stringify(tab));
340
+ };
341
+
342
+ const handleSearch = () => {
343
+ if (search) {
344
+ setSearchApplied(true);
345
+ getTemplatesByTab();
346
+ }
347
+ };
348
+
349
+ const removeSearchInput = () => {
350
+ setSearch('');
351
+ };
352
+
353
+ const searchKeyDown = (event: any) => {
354
+ if (event.key === 'Enter') {
355
+ handleSearch();
356
+ }
357
+ };
358
+
359
+ const handleLoadAllTemplate = (
360
+ dynamicPagination = false,
361
+ initialCall = false
362
+ ) => {
363
+ let page = dynamicPagination
364
+ ? ++paginationRef.current.currentPage
365
+ : paginationRef.current.currentPage;
366
+
367
+ if (initialCall) {
368
+ page = 1;
369
+ }
370
+
371
+ getTemplatesByTab(page);
372
+ };
373
+
374
+ const handleLoadTemplate = async (id: any, type = 'copy') => {
375
+ if (onGetOneTemplate) {
376
+ try {
377
+ const template = await onGetOneTemplate(id);
378
+ dispatch({ type: TEMPLATE_LOADING, payload: true });
379
+ dispatch(clearQrFields());
380
+ if (template) {
381
+ const workspaceElement = document.querySelector(
382
+ '.polotno-workspace-container'
383
+ );
384
+ if (workspaceElement) {
385
+ workspaceElement.classList.add('show-loader');
386
+ }
387
+ // @ts-ignore
388
+ const paperDimensions = template?.product?.paperSize.split('x');
389
+ store.setUnit({
390
+ unit: 'in',
391
+ dpi: 96,
392
+ });
393
+ store.setSize(
394
+ +paperDimensions[1] * DPI,
395
+ +paperDimensions[0] * DPI
396
+ );
397
+ let jsonData = await getFileAsBlob(template?.templateUrl);
398
+ if (template?.product?.productType === 'Real Penned Letter' && +template?.product?.id === 16) {
399
+ let clonedJson = JSON.stringify(jsonData)
400
+ .replace(/{{/g, '((')
401
+ .replace(/}}/g, '))');
402
+ jsonData = JSON.parse(clonedJson);
403
+ }
404
+ if (template?.product?.productType === 'Snap Pack Mailers') {
405
+ const updatedBoxes = changeColorOfBoxesForSnapPack(jsonData, true, true);
406
+ jsonData = updatedBoxes;
407
+ }
408
+ store.loadJSON(jsonData);
409
+ await store.waitLoading();
410
+ addSafetyBordersForTemplates(template?.product?.id, store);
411
+ const RistrictedBoxColor = extractCustomRistrictedBoxColor(jsonData);
412
+ dispatch({ type: SET_BLOCK_COLOR, payload: RistrictedBoxColor ? RistrictedBoxColor : DEFAULT_RESTRICTED_AREA_BG });
413
+ dispatch(setPageCount(store?.pages?.length));
414
+ if (allowedAddOns?.includes('custom_property_offer') && template?.meta?.rosOfferPercentage) {
415
+ dispatch({ type: SET_ROS_OFFER_PERCENTAGE, payload: template?.meta?.rosOfferPercentage });
416
+ } else {
417
+ dispatch({ type: SET_ROS_OFFER_PERCENTAGE, payload: '' });
418
+ }
419
+ dispatch({ type: TEMPLATE_LOADING, payload: false });
420
+ if (workspaceElement) {
421
+ workspaceElement.classList.add('hide-loader');
422
+ }
423
+ if (templateGalleryModal) {
424
+ closeGalleryModal();
425
+ }
426
+ }
427
+ } catch (error) {
428
+ return error;
429
+ } finally {
430
+ dispatch({ type: TEMPLATE_LOADING, payload: false });
431
+ handleDialogChange('');
432
+ }
433
+ } else {
434
+ dispatch(
435
+ failure(
436
+ 'Please provide onGetOneTemplate handler to load this template'
437
+ )
438
+ );
439
+ }
440
+ };
441
+
442
+ const handleDialogChange = (model = '') => {
443
+ setIsShowDialog((prev) => ({ open: !prev.open, model: model }));
444
+ };
445
+
446
+ const processPage = async (index: any, page: any) => {
447
+ return new Promise<void>((resolve) => {
448
+ let pageNumber = page.children.find(
449
+ (el: any) => el.custom?.name === 'page-number'
450
+ );
451
+ const text = index === 0 ? 'Front' : 'Back';
452
+
453
+ if (pageNumber) {
454
+ pageNumber.set({ text });
455
+ resolve();
456
+ } else {
457
+ page.addElement({
458
+ type: 'text',
459
+ custom: { name: 'page-number' },
460
+ text,
461
+ width: store.width,
462
+ align: 'center',
463
+ fontSize: 40,
464
+ x: -150,
465
+ y: -50,
466
+ selectable: false,
467
+ alwaysOnTop: true,
468
+ });
469
+ resolve();
470
+ }
471
+ });
472
+ };
473
+
474
+ const checkPageNumbers = async () => {
475
+ const promises = store.pages.map(async (page: any, index: any) => {
476
+ await processPage(index, page);
477
+ });
478
+
479
+ await Promise.all(promises); // Wait for all promises to resolve
480
+ };
481
+
482
+ const handleClearStore = () => {
483
+ store.clear();
484
+ dispatch(clearQrFields());
485
+ dispatch({ type: SET_ROS_OFFER_PERCENTAGE, payload: '' });
486
+ dispatch({ type: SET_BLOCK_COLOR, payload: DEFAULT_RESTRICTED_AREA_BG });
487
+ dispatch(setPageCount(store?.pages?.length));
488
+ let size: string | string[] = '';
489
+ let isPostCards = false;
490
+ let _product = product;
491
+ if (template?.product) {
492
+ size = template?.product?.paperSize;
493
+ isPostCards = template.product.productType === 'Postcards' || false;
494
+ _product = template.product;
495
+ } else if (product) {
496
+ size = product.selectedSize;
497
+ isPostCards = product.productType === 'Postcards' || false;
498
+ }
499
+ store.setUnit({
500
+ unit: 'in',
501
+ dpi: DPI,
502
+ });
503
+ size = (size as string)?.split('x');
504
+ store.setSize(+size[1] * DPI, +size[0] * DPI);
505
+ store.addPage();
506
+
507
+ if (multiPageLetters.includes(_product.productType)) {
508
+ store.addPage();
509
+ store.selectPage(store.pages[0].id);
510
+ }
511
+ drawRestrictedAreaOnPage(store, product, envelopeType);
512
+ addIdentifiersForTemplates(product.id, store);
513
+ if (product.productType === 'Real Penned Letter' && +product?.id === 16) {
514
+ addElementsforRealPennedLetters(store);
515
+ }
516
+ handleDialogChange('');
517
+ if (templateGalleryModal) {
518
+ closeGalleryModal();
519
+ }
520
+ };
521
+
522
+ const handleScroll = () => {
523
+ const div = document.querySelector('.templatesContent') || document.querySelector('.polotno-panel-container');
524
+ if (div) {
525
+ const isAtBottom =
526
+ div.scrollTop + div.clientHeight + 50 >= div.scrollHeight;
527
+ const isNeedToLoadMore =
528
+ paginationRef.current.currentPage * paginationRef.current.perPage <
529
+ paginationRef.current.count;
530
+ if (isAtBottom && !templatesPagination.loading && isNeedToLoadMore) {
531
+ handleLoadAllTemplate(true);
532
+ }
533
+ }
534
+ };
535
+
536
+ useEffect(() => {
537
+ if (templateLoading !== null && templateLoading === false) {
538
+ handleDialogChange('');
539
+ dispatch({ type: TEMPLATE_LOADING, payload: null });
540
+ }
541
+ }, [templateLoading]);
542
+
543
+ useEffect(() => {
544
+ if (!search && searchApplied) {
545
+ setSearchApplied(false);
546
+ setSearch('');
547
+ setTimeout(() => {
548
+ getTemplatesByTab();
549
+ }, 100);
550
+ }
551
+ }, [search]);
552
+
553
+ useEffect(() => {
554
+ searchRef.current = search;
555
+ }, [search]);
556
+
557
+ useEffect(() => {
558
+ currentTemplateTypeRef.current = currentTemplateType;
559
+ }, [currentTemplateType]);
560
+
561
+ useEffect(() => {
562
+ selectedCategoryRef.current = selectedCategory;
563
+ }, [selectedCategory]);
564
+
565
+ useEffect(() => {
566
+ paginationRef.current = pagination;
567
+ }, [pagination]);
568
+
569
+ useEffect(() => {
570
+ const newTemplateType: TemplateType = {
571
+ id: '3',
572
+ label: platformName ? `${platformName} Templates` : 'OLC Templates',
573
+ value: 'olc-templates'
574
+ };
575
+ if (onGetTemplates) {
576
+ let filteredTemplateTypes: TemplateType[] = [...defaultTemplateTypes, newTemplateType];
577
+ if (Array.isArray(allowedTemplateSections) && allowedTemplateSections.length > 0) {
578
+ filteredTemplateTypes = filteredTemplateTypes.filter((type) => allowedTemplateSections.includes(type.value));
579
+ }
580
+ setTemplateTypes(filteredTemplateTypes);
581
+ const lastSelectedTab = getItem('currentTab');
582
+ if (selectedTemplateType === 'prebuilt') {
583
+ setCurrentTemplateType(newTemplateType);
584
+ }
585
+ else if (lastSelectedTab) {
586
+ setCurrentTemplateType(JSON.parse(lastSelectedTab));
587
+ } else {
588
+ setCurrentTemplateType(defaultTemplateTypes[0]);
589
+ }
590
+ } else {
591
+ setTemplateTypes([newTemplateType]);
592
+ setCurrentTemplateType(newTemplateType);
593
+ }
594
+ getAllCategories();
595
+ return () => {
596
+ dispatch(clearAllTemplates());
597
+ };
598
+ }, []);
599
+
600
+ useEffect(() => {
601
+ if (currentTemplateType && Object.keys(currentTemplateType).length) {
602
+ getTemplatesByTab();
603
+ }
604
+ }, [currentTemplateType]);
605
+
606
+ useEffect(() => {
607
+ if (currentTemplateType && Object.keys(currentTemplateType).length && currentTemplateType?.id === '3' &&
608
+ templateCategories?.length >= 1) {
609
+ getTemplatesByTab();
610
+ }
611
+ }, [selectedCategory]);
612
+
613
+ useEffect(() => {
614
+ const div = document.querySelector('.templatesContent') || document.querySelector('.templatesContent-v2') || document.querySelector('.polotno-panel-container');
615
+
616
+ if (store.openedSidePanel === 'Templates' && templateGalleryModal) {
617
+ let sideBar = document.getElementsByClassName('polotno-panel-container');
618
+ const firstSideBar = sideBar[0];
619
+ if (firstSideBar) {
620
+ //@ts-ignore
621
+ firstSideBar.style.display = 'contents';
622
+ }
623
+ setOpenGalleryModal(true);
624
+ document.body.classList.add('no-scroll');
625
+ }
626
+
627
+ if (div) {
628
+ div.removeEventListener('scroll', handleScroll);
629
+ div.addEventListener('scroll', handleScroll);
630
+ }
631
+ return () => {
632
+ div?.removeEventListener('scroll', handleScroll);
633
+ };
634
+ }, [templates]);
635
+
636
+ return (
637
+ <>
638
+ {templateGalleryModal && !hireDesignerModal ? (
639
+ currentTheme === 'v2' ?
640
+ <ModalGalleryV2
641
+ product={product}
642
+ openGalleryModal={openGalleryModal}
643
+ pagination={pagination}
644
+ currentTemplateTypeRef={currentTemplateTypeRef}
645
+ selectedCategory={selectedCategory}
646
+ templateCategories={templateCategories}
647
+ currentTemplateType={currentTemplateType}
648
+ templateTypes={templateTypes}
649
+ search={search}
650
+ searchApplied={searchApplied}
651
+ loader={loader}
652
+ platformName={platformName}
653
+ myTemplates={myTemplates}
654
+ teamTemplates={teamTemplates}
655
+ olcTemplates={olcTemplates}
656
+ designerQueryAmount={designerQueryAmount}
657
+ setHireDesignerModal={setHireDesignerModal}
658
+ currentTheme={currentTheme}
659
+ setSearch={setSearch}
660
+ handleSearch={handleSearch}
661
+ removeSearchInput={removeSearchInput}
662
+ searchKeyDown={searchKeyDown}
663
+ setCurrentTemplateType={setCurrentTemplateType}
664
+ setSelectedCategory={setSelectedCategory}
665
+ handleLoadTemplateModel={handleLoadTemplateModel}
666
+ handleDialogChange={handleDialogChange}
667
+ handleTabChange={handleTabChange}
668
+ closeGalleryModal={closeGalleryModal}
669
+ setOpenGalleryModal={setOpenGalleryModal}
670
+ /> :
671
+ <ModalGallery
672
+ product={product}
673
+ openGalleryModal={openGalleryModal}
674
+ pagination={pagination}
675
+ currentTemplateTypeRef={currentTemplateTypeRef}
676
+ selectedCategory={selectedCategory}
677
+ templateCategories={templateCategories}
678
+ currentTemplateType={currentTemplateType}
679
+ templateTypes={templateTypes}
680
+ search={search}
681
+ searchApplied={searchApplied}
682
+ loader={loader}
683
+ platformName={platformName}
684
+ myTemplates={myTemplates}
685
+ teamTemplates={teamTemplates}
686
+ olcTemplates={olcTemplates}
687
+ designerQueryAmount={designerQueryAmount}
688
+ setHireDesignerModal={setHireDesignerModal}
689
+ setSearch={setSearch}
690
+ handleSearch={handleSearch}
691
+ removeSearchInput={removeSearchInput}
692
+ searchKeyDown={searchKeyDown}
693
+ setCurrentTemplateType={setCurrentTemplateType}
694
+ setSelectedCategory={setSelectedCategory}
695
+ handleLoadTemplateModel={handleLoadTemplateModel}
696
+ handleDialogChange={handleDialogChange}
697
+ handleTabChange={handleTabChange}
698
+ closeGalleryModal={closeGalleryModal}
699
+ setOpenGalleryModal={setOpenGalleryModal}
700
+ />
701
+ ) : !hireDesignerModal && (
702
+ <SideBarGallery
703
+ selectedCategory={selectedCategory}
704
+ templateCategories={templateCategories}
705
+ currentTemplateType={currentTemplateType}
706
+ templateTypes={templateTypes}
707
+ search={search}
708
+ searchApplied={searchApplied}
709
+ loader={loader}
710
+ platformName={platformName}
711
+ myTemplates={myTemplates}
712
+ teamTemplates={teamTemplates}
713
+ olcTemplates={olcTemplates}
714
+ setSearch={setSearch}
715
+ handleSearch={handleSearch}
716
+ removeSearchInput={removeSearchInput}
717
+ searchKeyDown={searchKeyDown}
718
+ setCurrentTemplateType={setCurrentTemplateType}
719
+ setSelectedCategory={setSelectedCategory}
720
+ handleLoadTemplateModel={handleLoadTemplateModel}
721
+ handleDialogChange={handleDialogChange}
722
+ />
723
+ )}
724
+
725
+ <div className="custom-template-section">
726
+ {isShowDialog.open && isShowDialog.model === 'design-own' && (
727
+ <Dialog
728
+ icon={<ModalCross />}
729
+ title={MESSAGES.TEMPLATE.DESIGN_YOUR_OWN.TITLE}
730
+ subHeading={MESSAGES.TEMPLATE.DESIGN_YOUR_OWN.HEADING}
731
+ description={MESSAGES.TEMPLATE.DESIGN_YOUR_OWN.PARAGRAPH}
732
+ open={isShowDialog.open}
733
+ handleClose={() => handleDialogChange('')}
734
+ onCancel={() => handleDialogChange('')}
735
+ onSubmit={handleClearStore}
736
+ customStyles={designDialogStyles}
737
+ cancelText="Cancel"
738
+ submitText="OK"
739
+ />
740
+ )}
741
+ {hireDesignerModal && (
742
+ <HireDesigner
743
+ open={hireDesignerModal}
744
+ onCreateCustomTemplateQuery={onCreateCustomTemplateQuery}
745
+ productId={product?.id}
746
+ onClose={closeHireDesignerModal}
747
+ />
748
+ )}
749
+ {isShowDialog.open && isShowDialog.model === 'load-template' && (
750
+ <>
751
+ {currentTheme === 'v2' ?
752
+ <DialogV2
753
+ icon={<ConfirmNew fill='var(--primary-color)' />}
754
+ title={MESSAGES.TEMPLATE.SELECT_TEMPLATE.TITLE}
755
+ subHeading=''
756
+ description="Are you sure you want to replace the current template with this one? Any unsaved changes will be lost. Save your changes first or click OK to proceed."
757
+ open={isShowDialog.open}
758
+ handleClose={() => handleDialogChange('')}
759
+ onCancel={() => handleDialogChange('')}
760
+ onSubmit={() => handleLoadTemplate(selectedRecord?.id)}
761
+ customStyles={loadDialogStylesV2}
762
+ loading={templateLoading || false}
763
+ cancelText="Cancel"
764
+ submitText="OK"
765
+ currentTheme="v2"
766
+ isGallery={false}
767
+ />
768
+ :
769
+ <Dialog
770
+ icon={<ModalCross />}
771
+ title={MESSAGES.TEMPLATE.SELECT_TEMPLATE.TITLE}
772
+ subHeading={MESSAGES.TEMPLATE.SELECT_TEMPLATE.HEADING}
773
+ description={MESSAGES.TEMPLATE.SELECT_TEMPLATE.PARAGRAPH}
774
+ open={isShowDialog.open}
775
+ handleClose={() => handleDialogChange('')}
776
+ onCancel={() => handleDialogChange('')}
777
+ onSubmit={() => handleLoadTemplate(selectedRecord?.id)}
778
+ customStyles={loadDialogStyles}
779
+ loading={templateLoading || false}
780
+ cancelText="Cancel"
781
+ submitText="OK"
782
+ />
783
+ }
784
+ </>
785
+ )}
786
+ </div>
787
+ </>
788
+ );
789
+ }
790
+ ) as unknown as SideSection['Panel'],
791
+ };
792
+
793
+ export default CustomTemplateSection;