@openlettermarketing/olc-react-sdk 2.1.7 → 2.1.8

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/build/index.js +1 -1
  2. package/build/index.js.map +1 -1
  3. package/build/types/version.d.ts +1 -1
  4. package/package.json +7 -6
  5. package/.eslintignore +0 -1
  6. package/.eslintrc.cjs +0 -18
  7. package/.eslintrc.yml +0 -47
  8. package/.github/workflows/publish-beta.yml +0 -154
  9. package/.github/workflows/publish-production.yml +0 -143
  10. package/.prettierignore +0 -3
  11. package/.prettierrc.yml +0 -5
  12. package/CHANGELOG.md +0 -4
  13. package/babel.config.json +0 -10
  14. package/examples/.eslintrc.yml +0 -4
  15. package/index.html +0 -18
  16. package/public/vite.svg +0 -1
  17. package/src/App.tsx +0 -209
  18. package/src/assets/Fonts/Lexi-Regular.ttf +0 -0
  19. package/src/assets/images/create-template/prebuilt.svg +0 -13
  20. package/src/assets/images/create-template/scratch.svg +0 -4
  21. package/src/assets/images/input/cancel.tsx +0 -20
  22. package/src/assets/images/input/search.tsx +0 -20
  23. package/src/assets/images/input/select-cancel.tsx +0 -17
  24. package/src/assets/images/modal-icons/add.tsx +0 -36
  25. package/src/assets/images/modal-icons/cancel-file.tsx +0 -12
  26. package/src/assets/images/modal-icons/cancel-input.tsx +0 -13
  27. package/src/assets/images/modal-icons/cancel.tsx +0 -35
  28. package/src/assets/images/modal-icons/close-new.svg +0 -3
  29. package/src/assets/images/modal-icons/confirm-close-icon.tsx +0 -14
  30. package/src/assets/images/modal-icons/confirm-new.tsx +0 -22
  31. package/src/assets/images/modal-icons/confirm.svg +0 -12
  32. package/src/assets/images/modal-icons/cross.tsx +0 -23
  33. package/src/assets/images/modal-icons/del.tsx +0 -19
  34. package/src/assets/images/modal-icons/design-icon.tsx +0 -22
  35. package/src/assets/images/modal-icons/doc.tsx +0 -43
  36. package/src/assets/images/modal-icons/docx.tsx +0 -43
  37. package/src/assets/images/modal-icons/envelope-icon.tsx +0 -26
  38. package/src/assets/images/modal-icons/info.tsx +0 -19
  39. package/src/assets/images/modal-icons/jpeg.tsx +0 -43
  40. package/src/assets/images/modal-icons/jpg.tsx +0 -43
  41. package/src/assets/images/modal-icons/modal-cros.svg +0 -4
  42. package/src/assets/images/modal-icons/modal-cross.tsx +0 -37
  43. package/src/assets/images/modal-icons/new-cancel.tsx +0 -11
  44. package/src/assets/images/modal-icons/order-download.tsx +0 -42
  45. package/src/assets/images/modal-icons/pdf.tsx +0 -51
  46. package/src/assets/images/modal-icons/png.tsx +0 -43
  47. package/src/assets/images/modal-icons/save.tsx +0 -23
  48. package/src/assets/images/modal-icons/template-copy.tsx +0 -25
  49. package/src/assets/images/modal-icons/tool-cancel.tsx +0 -25
  50. package/src/assets/images/products/bi-new.svg +0 -23
  51. package/src/assets/images/products/left-arrow.svg +0 -17
  52. package/src/assets/images/products/personal-new.tsx +0 -31
  53. package/src/assets/images/products/postcard-new.tsx +0 -27
  54. package/src/assets/images/products/professional-new.tsx +0 -24
  55. package/src/assets/images/products/real-new.tsx +0 -30
  56. package/src/assets/images/products/right-arrow.svg +0 -17
  57. package/src/assets/images/products/snap-new.svg +0 -31
  58. package/src/assets/images/templates/actions.svg +0 -3
  59. package/src/assets/images/templates/address-block-icon.tsx +0 -62
  60. package/src/assets/images/templates/archive.svg +0 -3
  61. package/src/assets/images/templates/arrow-down.tsx +0 -27
  62. package/src/assets/images/templates/back-arrow.tsx +0 -19
  63. package/src/assets/images/templates/bi-fold-self-mailers.tsx +0 -28
  64. package/src/assets/images/templates/check.svg +0 -3
  65. package/src/assets/images/templates/code.svg +0 -10
  66. package/src/assets/images/templates/content-copy-icon.tsx +0 -24
  67. package/src/assets/images/templates/custom-add-on-icon.tsx +0 -18
  68. package/src/assets/images/templates/custom-qr-section-icon.tsx +0 -9
  69. package/src/assets/images/templates/custom-template.tsx +0 -23
  70. package/src/assets/images/templates/designer.tsx +0 -43
  71. package/src/assets/images/templates/dot.tsx +0 -22
  72. package/src/assets/images/templates/download-v2.svg +0 -4
  73. package/src/assets/images/templates/download.svg +0 -4
  74. package/src/assets/images/templates/dummy-template.tsx +0 -76
  75. package/src/assets/images/templates/dynamic-field.tsx +0 -119
  76. package/src/assets/images/templates/edit-pencil-icon.tsx +0 -21
  77. package/src/assets/images/templates/edit.svg +0 -3
  78. package/src/assets/images/templates/epo-icon.tsx +0 -16
  79. package/src/assets/images/templates/field.tsx +0 -29
  80. package/src/assets/images/templates/gsv-icon.tsx +0 -31
  81. package/src/assets/images/templates/info-icon.tsx +0 -37
  82. package/src/assets/images/templates/left-arrow.svg +0 -17
  83. package/src/assets/images/templates/pencil.svg +0 -3
  84. package/src/assets/images/templates/personal-letter.tsx +0 -53
  85. package/src/assets/images/templates/postcard.tsx +0 -32
  86. package/src/assets/images/templates/professional-letter.tsx +0 -53
  87. package/src/assets/images/templates/qr-code.tsx +0 -13
  88. package/src/assets/images/templates/real-penned-letters.tsx +0 -57
  89. package/src/assets/images/templates/right-arrow.svg +0 -17
  90. package/src/assets/images/templates/size-image-lg.tsx +0 -20
  91. package/src/assets/images/templates/size-image-mid.tsx +0 -20
  92. package/src/assets/images/templates/size-image-xl.tsx +0 -20
  93. package/src/assets/images/templates/size-image.tsx +0 -20
  94. package/src/assets/images/templates/snap-pack.tsx +0 -67
  95. package/src/assets/images/templates/template-default-design.tsx +0 -21
  96. package/src/assets/images/templates/trash-upload.svg +0 -3
  97. package/src/assets/images/templates/trash.svg +0 -3
  98. package/src/assets/images/templates/tri-fold-self-mailers.tsx +0 -93
  99. package/src/assets/images/templates/upload-image.svg +0 -10
  100. package/src/assets/images/templates/x.svg +0 -3
  101. package/src/assets/images/thumbnails/one.svg +0 -9
  102. package/src/assets/images/tooltip/tool-arrow.tsx +0 -25
  103. package/src/components/CreateTemplate/V2/index.tsx +0 -527
  104. package/src/components/CreateTemplate/V2/styles.scss +0 -372
  105. package/src/components/CreateTemplate/index.tsx +0 -508
  106. package/src/components/CreateTemplate/styles.scss +0 -404
  107. package/src/components/GenericUIBlocks/Button/index.tsx +0 -54
  108. package/src/components/GenericUIBlocks/Button/styles.scss +0 -43
  109. package/src/components/GenericUIBlocks/CircularProgress/index.tsx +0 -18
  110. package/src/components/GenericUIBlocks/CircularProgress/styles.scss +0 -93
  111. package/src/components/GenericUIBlocks/CustomTooltip/index.tsx +0 -88
  112. package/src/components/GenericUIBlocks/CustomTooltip/styles.scss +0 -19
  113. package/src/components/GenericUIBlocks/Dialog/V2/index.tsx +0 -227
  114. package/src/components/GenericUIBlocks/Dialog/V2/styles.scss +0 -289
  115. package/src/components/GenericUIBlocks/Dialog/index.tsx +0 -185
  116. package/src/components/GenericUIBlocks/Dialog/styles.scss +0 -227
  117. package/src/components/GenericUIBlocks/Divider/index.tsx +0 -12
  118. package/src/components/GenericUIBlocks/Divider/styles.scss +0 -7
  119. package/src/components/GenericUIBlocks/GeneralSelect/index.tsx +0 -114
  120. package/src/components/GenericUIBlocks/GeneralSelect/styles.scss +0 -406
  121. package/src/components/GenericUIBlocks/GeneralTooltip/index.tsx +0 -25
  122. package/src/components/GenericUIBlocks/GeneralTooltip/styles.scss +0 -20
  123. package/src/components/GenericUIBlocks/GenericSnackbar/Toast/index.tsx +0 -91
  124. package/src/components/GenericUIBlocks/GenericSnackbar/Toast/styles.scss +0 -92
  125. package/src/components/GenericUIBlocks/Grid/index.tsx +0 -82
  126. package/src/components/GenericUIBlocks/Input/index.tsx +0 -269
  127. package/src/components/GenericUIBlocks/Input/styles.scss +0 -332
  128. package/src/components/GenericUIBlocks/Tabs/index.tsx +0 -71
  129. package/src/components/GenericUIBlocks/Tabs/styles.scss +0 -42
  130. package/src/components/GenericUIBlocks/Typography/index.tsx +0 -18
  131. package/src/components/GenericUIBlocks/Typography/styles.scss +0 -27
  132. package/src/components/SidePanel/CustomAddOns/index.tsx +0 -342
  133. package/src/components/SidePanel/CustomAddOns/styles.scss +0 -86
  134. package/src/components/SidePanel/CustomBlockColors/index.tsx +0 -211
  135. package/src/components/SidePanel/CustomBlockColors/styles.scss +0 -80
  136. package/src/components/SidePanel/CustomFields/customFieldSection.tsx +0 -547
  137. package/src/components/SidePanel/CustomFields/styles.scss +0 -64
  138. package/src/components/SidePanel/CustomQRCode/V2/QRCodeModal/index.tsx +0 -172
  139. package/src/components/SidePanel/CustomQRCode/V2/QRCodeModal/styles.scss +0 -46
  140. package/src/components/SidePanel/CustomQRCode/index.tsx +0 -1070
  141. package/src/components/SidePanel/CustomQRCode/styles.scss +0 -149
  142. package/src/components/SidePanel/CustomUploads/V2/index.tsx +0 -542
  143. package/src/components/SidePanel/CustomUploads/V2/styles.scss +0 -267
  144. package/src/components/SidePanel/CustomUploads/index.tsx +0 -301
  145. package/src/components/SidePanel/Templates/ModalGallery/HireDesigner/index.tsx +0 -424
  146. package/src/components/SidePanel/Templates/ModalGallery/HireDesigner/styles.scss +0 -180
  147. package/src/components/SidePanel/Templates/ModalGallery/V2/index.tsx +0 -235
  148. package/src/components/SidePanel/Templates/ModalGallery/V2/styles.scss +0 -244
  149. package/src/components/SidePanel/Templates/ModalGallery/index.tsx +0 -231
  150. package/src/components/SidePanel/Templates/SideBarGallery/index.tsx +0 -233
  151. package/src/components/SidePanel/Templates/SideBarGallery/styles.scss +0 -152
  152. package/src/components/SidePanel/Templates/TemplatesCard/V2/index.tsx +0 -149
  153. package/src/components/SidePanel/Templates/TemplatesCard/V2/styles.scss +0 -156
  154. package/src/components/SidePanel/Templates/TemplatesCard/index.tsx +0 -160
  155. package/src/components/SidePanel/Templates/TemplatesCard/styles.scss +0 -98
  156. package/src/components/SidePanel/Templates/customTemplateSection.tsx +0 -793
  157. package/src/components/SidePanel/Templates/styles.scss +0 -244
  158. package/src/components/SidePanel/index.tsx +0 -160
  159. package/src/components/TemplateBuilder/index.tsx +0 -585
  160. package/src/components/TemplateBuilder/styles.scss +0 -100
  161. package/src/components/TemplateTypes/index.tsx +0 -96
  162. package/src/components/TemplateTypes/styles.scss +0 -91
  163. package/src/components/TopNavigation/ConfirmNavigateDialog/index.tsx +0 -81
  164. package/src/components/TopNavigation/ConfirmNavigateDialog/styles.scss +0 -123
  165. package/src/components/TopNavigation/DuplicateTemplateModal.tsx +0 -103
  166. package/src/components/TopNavigation/EditTemplateNameModel/index.tsx +0 -71
  167. package/src/components/TopNavigation/EditTemplateNameModel/styles.scss +0 -88
  168. package/src/components/TopNavigation/SaveTemplateModel/index.tsx +0 -201
  169. package/src/components/TopNavigation/SaveTemplateModel/styles.scss +0 -128
  170. package/src/components/TopNavigation/index.tsx +0 -938
  171. package/src/components/TopNavigation/styles.scss +0 -303
  172. package/src/importMeta.d.ts +0 -31
  173. package/src/index.scss +0 -131
  174. package/src/index.tsx +0 -238
  175. package/src/libs/test.ts +0 -7
  176. package/src/redux/actions/action-types.ts +0 -52
  177. package/src/redux/actions/customQRCodeActions.ts +0 -54
  178. package/src/redux/actions/snackbarActions.ts +0 -16
  179. package/src/redux/actions/templateActions.ts +0 -236
  180. package/src/redux/reducers/customFieldReducer.ts +0 -99
  181. package/src/redux/reducers/customQRCodeReducer.ts +0 -58
  182. package/src/redux/reducers/index.ts +0 -15
  183. package/src/redux/reducers/snackbarReducer.ts +0 -40
  184. package/src/redux/reducers/templateReducer.ts +0 -485
  185. package/src/redux/store.ts +0 -18
  186. package/src/styles/colors.scss +0 -61
  187. package/src/test/mocks.js +0 -89
  188. package/src/test/setupJest.js +0 -1
  189. package/src/utils/api.ts +0 -36
  190. package/src/utils/constants.ts +0 -182
  191. package/src/utils/customStyles.ts +0 -45
  192. package/src/utils/fetchWrapper.ts +0 -73
  193. package/src/utils/fonts.json +0 -1597
  194. package/src/utils/helper.ts +0 -205
  195. package/src/utils/local-storage.ts +0 -15
  196. package/src/utils/message.ts +0 -162
  197. package/src/utils/products.ts +0 -186
  198. package/src/utils/template-builder.ts +0 -328
  199. package/src/utils/templateIdentifierArea/biFold.ts +0 -107
  200. package/src/utils/templateIdentifierArea/index.ts +0 -35
  201. package/src/utils/templateIdentifierArea/personal.ts +0 -107
  202. package/src/utils/templateIdentifierArea/postCards.ts +0 -163
  203. package/src/utils/templateIdentifierArea/professional.ts +0 -125
  204. package/src/utils/templateIdentifierArea/snapPack.ts +0 -107
  205. package/src/utils/templateIdentifierArea/triFold.ts +0 -107
  206. package/src/utils/templateRestrictedArea/biFold.ts +0 -329
  207. package/src/utils/templateRestrictedArea/nonWindowProfessional.ts +0 -90
  208. package/src/utils/templateRestrictedArea/personal.ts +0 -90
  209. package/src/utils/templateRestrictedArea/postCard.ts +0 -334
  210. package/src/utils/templateRestrictedArea/postCardJumbo.tsx +0 -408
  211. package/src/utils/templateRestrictedArea/professional.ts +0 -318
  212. package/src/utils/templateRestrictedArea/realPenned.ts +0 -233
  213. package/src/utils/templateRestrictedArea/snapPack.ts +0 -1009
  214. package/src/utils/templateRestrictedArea/triFold.ts +0 -330
  215. package/src/utils/templateSafetyBorders/biFold.ts +0 -91
  216. package/src/utils/templateSafetyBorders/index.ts +0 -43
  217. package/src/utils/templateSafetyBorders/personal.ts +0 -41
  218. package/src/utils/templateSafetyBorders/postCards.ts +0 -259
  219. package/src/utils/templateSafetyBorders/professional.ts +0 -78
  220. package/src/utils/templateSafetyBorders/snapPack.ts +0 -165
  221. package/src/utils/templateSafetyBorders/triFold.ts +0 -114
  222. package/src/utils/templateSafetyBorders/types.d.ts +0 -68
  223. package/src/utils/types.ts +0 -12
  224. package/src/v2Theme.scss +0 -142
  225. package/tsconfig.json +0 -29
  226. package/tsconfig.node.json +0 -12
  227. package/update-version.js +0 -23
  228. package/version.js +0 -1
  229. package/vite.config.ts +0 -8
  230. package/webpack.config.js +0 -80
@@ -1,793 +0,0 @@
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;