@openlettermarketing/olc-react-sdk 0.0.18 → 0.0.20

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 (138) hide show
  1. package/build/index.js +3 -3
  2. package/build/index.js.map +1 -1
  3. package/build/types/App.d.ts +1 -0
  4. package/build/types/components/TemplateBuilder/index.d.ts +1 -0
  5. package/build/types/components/TopNavigation/index.d.ts +1 -0
  6. package/build/types/index.d.ts +3 -2
  7. package/package.json +1 -1
  8. package/.eslintignore +0 -1
  9. package/.eslintrc.cjs +0 -18
  10. package/.eslintrc.yml +0 -47
  11. package/.prettierignore +0 -3
  12. package/.prettierrc.yml +0 -5
  13. package/CHANGELOG.md +0 -4
  14. package/babel.config.json +0 -10
  15. package/examples/.eslintrc.yml +0 -4
  16. package/index.html +0 -18
  17. package/public/vite.svg +0 -1
  18. package/src/App.tsx +0 -72
  19. package/src/assets/Fonts/Lexi-Regular.ttf +0 -0
  20. package/src/assets/images/input/cancel.tsx +0 -20
  21. package/src/assets/images/input/search.tsx +0 -20
  22. package/src/assets/images/modal-icons/cancelIcon.png +0 -0
  23. package/src/assets/images/modal-icons/del.tsx +0 -19
  24. package/src/assets/images/modal-icons/delete.svg +0 -3
  25. package/src/assets/images/modal-icons/modal-cross.tsx +0 -23
  26. package/src/assets/images/modal-icons/save.tsx +0 -23
  27. package/src/assets/images/templates/add-icon.svg +0 -5
  28. package/src/assets/images/templates/back-arrow.tsx +0 -19
  29. package/src/assets/images/templates/back-dialog-icon.png +0 -0
  30. package/src/assets/images/templates/back-dialog-icon.svg +0 -3
  31. package/src/assets/images/templates/barcode.png +0 -0
  32. package/src/assets/images/templates/bi-fold-self-mailers.tsx +0 -28
  33. package/src/assets/images/templates/black-trash-icon.svg +0 -3
  34. package/src/assets/images/templates/cancel.svg +0 -4
  35. package/src/assets/images/templates/cancelIcon.png +0 -0
  36. package/src/assets/images/templates/clipboard.svg +0 -3
  37. package/src/assets/images/templates/contact-search.svg +0 -3
  38. package/src/assets/images/templates/content-copy-icon.tsx +0 -24
  39. package/src/assets/images/templates/cross.svg +0 -3
  40. package/src/assets/images/templates/custom-template-icon-black.svg +0 -3
  41. package/src/assets/images/templates/custom-template-icon.svg +0 -3
  42. package/src/assets/images/templates/custom-template.tsx +0 -23
  43. package/src/assets/images/templates/dummy-template.svg +0 -21
  44. package/src/assets/images/templates/dynamic-field.tsx +0 -119
  45. package/src/assets/images/templates/edit-pencil-icon.tsx +0 -21
  46. package/src/assets/images/templates/filter-2.svg +0 -13
  47. package/src/assets/images/templates/info-icon.svg +0 -12
  48. package/src/assets/images/templates/info-icon.tsx +0 -37
  49. package/src/assets/images/templates/one-barcode.png +0 -0
  50. package/src/assets/images/templates/personal-letter.tsx +0 -53
  51. package/src/assets/images/templates/plus-icon.svg +0 -5
  52. package/src/assets/images/templates/postcard.tsx +0 -32
  53. package/src/assets/images/templates/professional-letter.tsx +0 -53
  54. package/src/assets/images/templates/real-penned-letters.tsx +0 -57
  55. package/src/assets/images/templates/search.svg +0 -3
  56. package/src/assets/images/templates/size-image-lg.tsx +0 -20
  57. package/src/assets/images/templates/size-image-mid.tsx +0 -20
  58. package/src/assets/images/templates/size-image.tsx +0 -20
  59. package/src/assets/images/templates/template-copy.svg +0 -3
  60. package/src/assets/images/templates/template-default-design.tsx +0 -21
  61. package/src/assets/images/templates/template-delete.svg +0 -3
  62. package/src/assets/images/templates/template-edit.svg +0 -4
  63. package/src/assets/images/templates/template-save-icon.svg +0 -3
  64. package/src/assets/images/templates/template-search-2.svg +0 -9
  65. package/src/assets/images/templates/template-search.svg +0 -4
  66. package/src/assets/images/templates/thumbnail.svg +0 -10
  67. package/src/assets/images/templates/trash-icon.svg +0 -13
  68. package/src/assets/images/templates/tri-fold-self-mailers.tsx +0 -93
  69. package/src/components/CreateTemplate/index.tsx +0 -379
  70. package/src/components/CreateTemplate/styles.scss +0 -363
  71. package/src/components/GenericUIBlocks/Button/index.tsx +0 -21
  72. package/src/components/GenericUIBlocks/Button/styles.scss +0 -15
  73. package/src/components/GenericUIBlocks/CircularProgress/index.tsx +0 -18
  74. package/src/components/GenericUIBlocks/CircularProgress/styles.scss +0 -98
  75. package/src/components/GenericUIBlocks/Dialog/index.tsx +0 -127
  76. package/src/components/GenericUIBlocks/Dialog/styles.scss +0 -106
  77. package/src/components/GenericUIBlocks/Divider/index.tsx +0 -12
  78. package/src/components/GenericUIBlocks/Divider/styles.scss +0 -7
  79. package/src/components/GenericUIBlocks/GeneralSelect/index.tsx +0 -86
  80. package/src/components/GenericUIBlocks/GeneralSelect/styles.scss +0 -77
  81. package/src/components/GenericUIBlocks/GeneralTooltip/index.tsx +0 -24
  82. package/src/components/GenericUIBlocks/GeneralTooltip/styles.scss +0 -9
  83. package/src/components/GenericUIBlocks/GenericSnackbar/index.tsx +0 -53
  84. package/src/components/GenericUIBlocks/GenericSnackbar/styles.scss +0 -34
  85. package/src/components/GenericUIBlocks/Grid/index.tsx +0 -82
  86. package/src/components/GenericUIBlocks/Input/index.tsx +0 -89
  87. package/src/components/GenericUIBlocks/Input/styles.scss +0 -80
  88. package/src/components/GenericUIBlocks/Typography/index.tsx +0 -18
  89. package/src/components/GenericUIBlocks/Typography/styles.scss +0 -27
  90. package/src/components/SidePanel/customFields/customFieldSection.tsx +0 -173
  91. package/src/components/SidePanel/customFields/styles.scss +0 -47
  92. package/src/components/SidePanel/index.tsx +0 -42
  93. package/src/components/SidePanel/templates/customTemplateSection.tsx +0 -503
  94. package/src/components/SidePanel/templates/styles.scss +0 -151
  95. package/src/components/TemplateBuilder/index.tsx +0 -301
  96. package/src/components/TemplateBuilder/styles.scss +0 -66
  97. package/src/components/TopNavigation/ConfirmNavigateDialog/index.tsx +0 -58
  98. package/src/components/TopNavigation/ConfirmNavigateDialog/styles.scss +0 -123
  99. package/src/components/TopNavigation/EditTemplateNameModel/index.tsx +0 -98
  100. package/src/components/TopNavigation/EditTemplateNameModel/styles.scss +0 -88
  101. package/src/components/TopNavigation/SaveTemplateModel/index.tsx +0 -60
  102. package/src/components/TopNavigation/SaveTemplateModel/styles.scss +0 -128
  103. package/src/components/TopNavigation/index.tsx +0 -405
  104. package/src/components/TopNavigation/styles.scss +0 -83
  105. package/src/importMeta.d.ts +0 -9
  106. package/src/index.scss +0 -137
  107. package/src/index.tsx +0 -80
  108. package/src/libs/test.ts +0 -7
  109. package/src/redux/actions/action-types.ts +0 -42
  110. package/src/redux/actions/customFieldAction.ts +0 -28
  111. package/src/redux/actions/snackbarActions.ts +0 -16
  112. package/src/redux/actions/templateActions.ts +0 -456
  113. package/src/redux/reducers/customFieldReducer.ts +0 -97
  114. package/src/redux/reducers/index.ts +0 -14
  115. package/src/redux/reducers/snackbarReducer.ts +0 -41
  116. package/src/redux/reducers/templateReducer.ts +0 -353
  117. package/src/redux/store.ts +0 -18
  118. package/src/styles/colors.scss +0 -61
  119. package/src/test/mocks.js +0 -89
  120. package/src/test/setupJest.js +0 -1
  121. package/src/utils/api.ts +0 -36
  122. package/src/utils/constants.ts +0 -40
  123. package/src/utils/customStyles.ts +0 -135
  124. package/src/utils/fetchWrapper.ts +0 -68
  125. package/src/utils/fonts.json +0 -1597
  126. package/src/utils/helper.ts +0 -19
  127. package/src/utils/local-storage.ts +0 -15
  128. package/src/utils/message.ts +0 -71
  129. package/src/utils/template-builder.ts +0 -147
  130. package/src/utils/templateRestrictedArea/biFold.ts +0 -433
  131. package/src/utils/templateRestrictedArea/postCard.ts +0 -439
  132. package/src/utils/templateRestrictedArea/professional.ts +0 -422
  133. package/src/utils/templateRestrictedArea/realPenned.ts +0 -244
  134. package/src/utils/templateRestrictedArea/triFold.ts +0 -434
  135. package/tsconfig.json +0 -29
  136. package/tsconfig.node.json +0 -12
  137. package/vite.config.ts +0 -8
  138. package/webpack.config.js +0 -80
@@ -1,88 +0,0 @@
1
- .editTemplateNameModal {
2
- .MuiPaper-root {
3
- width: 100% !important;
4
- max-width: 623px !important;
5
- height: 100% !important;
6
- max-height: 230px !important;
7
- margin: 0 auto !important;
8
- border-radius: 11px;
9
- background: #fff8ee;
10
- }
11
-
12
- .editTemplateNameModalTitle {
13
- color: #ed5c2f;
14
- text-align: center;
15
- font-size: 22px;
16
- font-style: normal;
17
- font-weight: 700;
18
- line-height: normal;
19
- padding: 16px 16px 0px !important;
20
- }
21
-
22
- .editTemplateNameModalContent {
23
- padding: 0px 30px !important;
24
-
25
- p {
26
- color: #303030;
27
- font-size: 14px;
28
- font-style: normal;
29
- font-weight: 400;
30
- line-height: normal;
31
- margin: 10px 0px 10px 0px;
32
- }
33
-
34
- .MuiInputBase-root {
35
- border-radius: 7px;
36
- border: 0.5px solid #303030;
37
- background: #fff;
38
- width: 100%;
39
- padding: 9.8px 22px;
40
-
41
- &:focus,
42
- &:focus-visible {
43
- outline: none !important;
44
- }
45
-
46
- &::after,
47
- &::before {
48
- display: none !important;
49
- }
50
- }
51
- }
52
-
53
- .actionBtns {
54
- justify-content: center;
55
- align-items: center;
56
- margin: 20px 0px;
57
- gap: 20px;
58
-
59
- button {
60
- border-radius: 5px;
61
- text-transform: capitalize;
62
- width: 100%;
63
- max-width: 107px;
64
- height: 100%;
65
- min-height: 41px;
66
-
67
- &:first-child {
68
- border: 0.5px solid rgba(48, 48, 48, 0.5);
69
- background: #fff;
70
- color: #000;
71
- font-size: 16px;
72
- font-style: normal;
73
- font-weight: 600;
74
- line-height: normal;
75
- }
76
-
77
- &:last-child {
78
- color: #fff;
79
- font-size: 16px;
80
- font-style: normal;
81
- font-weight: 600;
82
- line-height: normal;
83
- background: #ed5c2f;
84
- margin: 0;
85
- }
86
- }
87
- }
88
- }
@@ -1,60 +0,0 @@
1
- import React from 'react';
2
-
3
- // Utils
4
- import { MESSAGES } from '../../../utils/message';
5
-
6
- // Components
7
- import Dialog from '../../GenericUIBlocks/Dialog';
8
-
9
- // Icons
10
- import Save from '../../../assets/images/modal-icons/save';
11
-
12
- // Styles
13
- import './styles.scss';
14
-
15
- /**
16
- * Renders a modal dialog for deleting a template.
17
- *
18
- * @param {function} handleSave - Callback function to handle the save action.
19
- * @param {function} handleClose - Callback function to handle the close action.
20
- * @param {boolean} open - Boolean value indicating whether the modal is open or not.
21
- * @returns {JSX.Element} The delete template modal component.
22
- */
23
-
24
- const saveDialogStyles = {
25
- maxWidth: '433px',
26
- minHeight: '290px',
27
- };
28
-
29
- interface SaveTemplateModelProps {
30
- open: boolean;
31
- loading: boolean;
32
- handleClose: () => void;
33
- handleSave: () => void;
34
- }
35
-
36
- const SaveTemplateModel: React.FC<SaveTemplateModelProps> = ({
37
- handleSave,
38
- handleClose,
39
- open,
40
- loading,
41
- }) => {
42
- return (
43
- <Dialog
44
- icon={<Save fill="var(--primaryColor)" />}
45
- open={open}
46
- loading={loading}
47
- handleClose={handleClose}
48
- title={MESSAGES.TEMPLATE.SAVE.TITLE}
49
- subHeading={MESSAGES.TEMPLATE.SAVE.HEADING}
50
- description={MESSAGES.TEMPLATE.SAVE.PARAGRAPH}
51
- cancelText={MESSAGES.TEMPLATE.SAVE.CANCEL_BUTTON}
52
- submitText={MESSAGES.TEMPLATE.SAVE.SUBMIT_BUTTON}
53
- customStyles={saveDialogStyles}
54
- onSubmit={handleSave}
55
- onCancel={handleClose}
56
- />
57
- );
58
- };
59
-
60
- export default SaveTemplateModel;
@@ -1,128 +0,0 @@
1
- .confirmTemplateSaveModal {
2
- .MuiPaper-root {
3
- width: 100% !important;
4
- max-width: 433px !important;
5
- height: 100% !important;
6
- max-height: 290px !important;
7
- margin: 0 auto !important;
8
- border-radius: 11px;
9
- background: #fff8ee;
10
- }
11
-
12
- .confirmTemplateSaveModalTitle {
13
- color: #ed5c2f;
14
- text-align: center;
15
- font-size: 22px;
16
- font-style: normal;
17
- font-weight: 700;
18
- line-height: normal;
19
- }
20
-
21
- .confirmTemplateSaveModalContent {
22
- display: flex;
23
- flex-direction: column;
24
- gap: 20px;
25
- padding: 16px 16px 0px;
26
-
27
- .trashIconWrapper {
28
- text-align: center;
29
-
30
- p {
31
- color: #ed5c2f;
32
- text-align: center;
33
- font-size: 22px;
34
- font-style: normal;
35
- font-weight: 700;
36
- line-height: normal;
37
- margin-top: 10px;
38
- }
39
- }
40
-
41
- .confirmTemplateSaveText {
42
- display: flex;
43
- flex-direction: column;
44
- justify-content: center;
45
- align-items: center;
46
- gap: 10px;
47
-
48
- p {
49
- color: #000;
50
- text-align: center;
51
- font-size: 16px;
52
- font-style: normal;
53
- font-weight: 600;
54
- line-height: normal;
55
-
56
- &:last-child {
57
- color: #000;
58
- text-align: center;
59
- font-size: 14px;
60
- font-style: normal;
61
- font-weight: 400;
62
- line-height: 16px;
63
- /* 114.286% */
64
- letter-spacing: 0.28px;
65
- margin: 0;
66
- }
67
- }
68
- }
69
-
70
- .MuiInputBase-root {
71
- border-radius: 7px;
72
- border: 0.5px solid #303030;
73
- background: #fff;
74
- width: 100%;
75
- padding: 10px 22px;
76
-
77
- &:focus,
78
- &:focus-visible {
79
- outline: none !important;
80
- }
81
-
82
- &::after,
83
- &::before {
84
- display: none !important;
85
- }
86
- }
87
- }
88
-
89
- .actionBtns {
90
- justify-content: center;
91
- align-items: center;
92
- margin-bottom: 10px;
93
- gap: 20px;
94
-
95
- button {
96
- border-radius: 5px;
97
- text-transform: capitalize;
98
- width: 100%;
99
- max-width: 107px;
100
- height: 100%;
101
- min-height: 41px;
102
-
103
- &:first-child {
104
- border: 0.5px solid rgba(48, 48, 48, 0.5);
105
- background: #fff;
106
- color: #000;
107
- font-size: 16px;
108
- font-style: normal;
109
- font-weight: 600;
110
- line-height: normal;
111
- }
112
-
113
- &:last-child {
114
- color: #fff;
115
- font-size: 16px;
116
- font-style: normal;
117
- font-weight: 600;
118
- line-height: normal;
119
- background: #ed5c2f;
120
- margin: 0;
121
- }
122
-
123
- &:disabled {
124
- opacity: 0.5;
125
- }
126
- }
127
- }
128
- }
@@ -1,405 +0,0 @@
1
- import React, { useEffect, useState } from 'react';
2
-
3
- // Hooks
4
- import { useDispatch, useSelector } from 'react-redux';
5
- import { useNavigate, useParams } from 'react-router-dom';
6
- import { AppDispatch, RootState } from '../../redux/store';
7
-
8
- // Actions
9
- import {
10
- uploadTemplate,
11
- createTemplate,
12
- updateTemplate,
13
- clearTemplateFields,
14
- loadFormDataToStore,
15
- downloadProof,
16
- } from '../../redux/actions/templateActions';
17
- import { failure, success } from '../../redux/actions/snackbarActions';
18
-
19
- // Components
20
- import SaveTemplateModel from './SaveTemplateModel';
21
- import ConfirmNavigateDialog from './ConfirmNavigateDialog';
22
- import EditTemplateNameModel from './EditTemplateNameModel';
23
-
24
-
25
- // Utils
26
- import { downloadPDF, extractFontFamilies, multiPageTemplates } from '../../utils/template-builder';
27
- import { getItem, setItem } from '../../utils/local-storage';
28
- import { MESSAGES } from '../../utils/message';
29
- // @ts-ignore
30
- import fonts from '../../utils/fonts.json';
31
-
32
- // UI Components
33
- import Typography from "../GenericUIBlocks/Typography";
34
- import Button from "../GenericUIBlocks/Button";
35
- import CircularProgress from "../GenericUIBlocks/CircularProgress";
36
- import { GridContainer, GridItem } from '../GenericUIBlocks/Grid';
37
-
38
-
39
- // Icons
40
- // @ts-ignore
41
- import EditIcon from '../../assets/images/templates/edit-pencil-icon.tsx';
42
-
43
- // Styles
44
- import './styles.scss';
45
-
46
-
47
- /**
48
- * Represents the top navigation bar of a template builder application.
49
- * Handles saving and navigation logic, as well as displaying a confirmation dialog for unsaved changes.
50
- *
51
- * @param {Object} props - The component props.
52
- * @param {Object} props.store - The store object used for saving the template.
53
- * @param {boolean} props.isStoreUpdated - Indicates whether the store has been updated.
54
- * @returns {JSX.Element} The top navigation bar component.
55
- */
56
-
57
- const buttonStyles: React.CSSProperties = {
58
- maxWidth: '120px',
59
- minHeight: '40px',
60
- backgroundColor: 'var(--secondaryButtonBgColor)',
61
- color: 'var(--secondaryButtonTextColor)',
62
- border: '0.5px solid var(--borderColor)',
63
- fontSize: '15px',
64
- };
65
-
66
- const progressStyles: React.CSSProperties = {
67
- width: '20px',
68
- height: '20px',
69
- border: '2px solid var(--primaryColor)',
70
- };
71
-
72
- interface TopNavigationProps {
73
- store: any;
74
- returnRoute?: string | null;
75
- isStoreUpdated: boolean;
76
- }
77
-
78
- const TopNavigation: React.FC<TopNavigationProps> = ({
79
- store,
80
- returnRoute,
81
- isStoreUpdated,
82
- }) => {
83
-
84
- const [showNavigateDialog, setShowNavigateDialog] = useState<boolean>(false);
85
- const [isShowModel, setIsShowModel] = useState<{
86
- open: boolean;
87
- model: string;
88
- loading: boolean;
89
- }>({
90
- open: false,
91
- model: '',
92
- loading: false,
93
- });
94
- const [downloadingProof, setDownloaingProof] = useState<boolean>(false);
95
-
96
- const { id } = useParams<{ id: string }>();
97
-
98
- const dispatch: AppDispatch = useDispatch();
99
- const navigate = useNavigate();
100
-
101
- const title = useSelector((state: RootState) => state.templates.title);
102
- const product = useSelector((state: RootState) => state.templates.product) as Record<string, any>;
103
-
104
- const dynamicFields = useSelector(
105
- (state: RootState) => state.templates.dynamicFields
106
- );
107
- const defaultFields = useSelector(
108
- (state: RootState) => state.templates.defaultDynamicFields
109
- );
110
- const templateType = useSelector(
111
- (state: RootState) => state.templates.templateType
112
- );
113
- const envelopeType = useSelector(
114
- (state: RootState) => state.templates.envelopeType
115
- );
116
-
117
- useEffect(() => {
118
- if (!id) {
119
- const formData = getItem('formData');
120
- if (formData && !title) {
121
- dispatch(loadFormDataToStore(formData));
122
- } else {
123
- handleSaveFormData();
124
- }
125
- }
126
- }, [title]);
127
-
128
- const handleSaveFormData = () => {
129
- const data = { title, product, templateType, envelopeType };
130
- setItem('formData', JSON.stringify(data));
131
- };
132
-
133
- const handleBackPress = () => {
134
- if (isStoreUpdated) {
135
- setShowNavigateDialog(!showNavigateDialog);
136
- } else {
137
- handleNavigation(returnRoute ? returnRoute : '/create-template');
138
- }
139
- };
140
-
141
- const handleNavigation = async (route = '/') => {
142
- handleClearFilters();
143
- if (templateType === 'json' && product?.productType !== 'Real Penned Letter') {
144
- await store.history.clear();
145
- }
146
- navigate(route);
147
- };
148
-
149
- const handleClearFilters = () => dispatch(clearTemplateFields());
150
-
151
- const handleViewProofWithLamda = async () => {
152
- try {
153
- setDownloaingProof(true);
154
- const fields = [...defaultFields, ...Object.values(dynamicFields)];
155
- let json = store.toJSON();
156
- if (product?.productType === "Real Penned Letter") {
157
- let clonedJson = JSON.stringify(json)
158
- .replace(/\(\(/g, "{{")
159
- .replace(/\)\)/g, "}}");
160
- json = JSON.parse(clonedJson);
161
- }
162
- let jsonString = JSON.stringify(json);
163
- fields.forEach(({ key, defaultValue, value }) => {
164
- const regex = new RegExp(key, 'g');
165
- jsonString = jsonString.replace(regex, defaultValue || value);
166
- });
167
- const jsonWithDummyData = JSON.parse(jsonString);
168
- const response: any = await downloadProof({
169
- json: jsonWithDummyData,
170
- });
171
- if (response.status === 200) {
172
- const binaryData = atob(response.data.data.base64);
173
- // Create a Uint8Array from the binary data
174
- const uint8Array = new Uint8Array(binaryData.length);
175
- for (let i = 0; i < binaryData.length; i++) {
176
- uint8Array[i] = binaryData.charCodeAt(i);
177
- }
178
-
179
- // Create a Blob from the Uint8Array
180
- const blob = new Blob([uint8Array], { type: 'application/pdf' });
181
-
182
- // Create an Object URL for the Blob
183
- const url = URL.createObjectURL(blob);
184
- downloadPDF(title.substring(0, 20), url);
185
- dispatch(success('Download Proof generated successfully'));
186
- } else {
187
- dispatch(failure(response?.data?.message));
188
- }
189
- } catch (error: any) {
190
- dispatch(
191
- failure(
192
- error?.response?.data?.message ||
193
- error?.message ||
194
- 'Error while downloading proof'
195
- )
196
- );
197
- } finally {
198
- setDownloaingProof(false);
199
- }
200
- };
201
-
202
- const handleSave = async () => {
203
- try {
204
- const formData = new FormData();
205
- const allFields = [...defaultFields, ...Object.values(dynamicFields)];
206
- let selectedFields: typeof allFields = [];
207
- if (templateType === 'json') {
208
- const blob = await store.toBlob();
209
- let jsonData = store.toJSON();
210
-
211
- if (product?.productType === "Real Penned Letter") {
212
- let clonedJson = JSON.stringify(jsonData)
213
- .replace(/\(\(/g, "{{")
214
- .replace(/\)\)/g, "}}");
215
- jsonData = JSON.parse(clonedJson);
216
- }
217
-
218
- // get all fonts family from json
219
- const fontFamilies = extractFontFamilies(jsonData?.pages);
220
-
221
- // extract custom fonts and remove google fonts from that array
222
- const customFonts = fontFamilies.filter((item: any) => !fonts.includes(item));
223
-
224
- const availableBase64inJson = jsonData?.fonts?.map((font: any) => font?.fontFamily);
225
-
226
- const unAvailableFonts = customFonts.filter((item: any) => !availableBase64inJson?.includes(item));
227
-
228
- if (unAvailableFonts?.length) {
229
- dispatch(failure(`Please upload ${unAvailableFonts[0]} font in My Fonts section.`));
230
- return
231
- }
232
-
233
- if (multiPageTemplates.includes(product.productType)) {
234
- const backJsonData = { ...jsonData, pages: [jsonData.pages[1]] }
235
- await store.loadJSON(backJsonData);
236
- await store.waitLoading();
237
- const backBlob = await store.toBlob();
238
- formData.append('backThumbnail', backBlob, 'backLogo.png');
239
- store.loadJSON(jsonData);
240
- }
241
- const jsonString = JSON.stringify(jsonData);
242
- const blobData = new Blob([jsonString], { type: 'application/json' });
243
- formData.append('json', blobData, 'template.json');
244
- formData.append('thumbnail', blob, 'logo.png');
245
- selectedFields = allFields.filter(field => jsonString.includes(field.key));
246
- }
247
- setIsShowModel((prev) => ({ ...prev, loading: true }));
248
-
249
- const response: any = await uploadTemplate(formData);
250
- if (response?.status === 200) {
251
- if (!id) {
252
- setTimeout(async () => await handleCreateTemplate(response?.data?.data, selectedFields), 1000);
253
- } else {
254
- setTimeout(async () => await handleUpdateTemplate(response?.data?.data, selectedFields), 1000)
255
- }
256
- } else if (response?.status === 418 && response?.data?.message == "You have reached your Templates limit, updgrade you Plan to add more") {
257
- handleChangeModel('', 'false');
258
- } else {
259
- dispatch(
260
- failure(
261
- response?.data?.message ||
262
- MESSAGES.GENERAL_ERROR
263
- )
264
- );
265
- handleChangeModel('', 'false');
266
- }
267
- } catch (error) {
268
- return error;
269
- }
270
- };
271
-
272
- const handleCreateTemplate = async (data: any, selectedFields: any) => {
273
- try {
274
- const response: any = await createTemplate({
275
- title: title,
276
- productId: product?.id,
277
- fields: selectedFields,
278
- thumbnailPath: data.thumbnailPath,
279
- templatePath: data.templatePath,
280
- backTemplatePath: data.backTemplatePath || '',
281
- backThumbnailPath: data.backThumbnailPath || '',
282
- envelopeType,
283
- });
284
- if (response.status === 200) {
285
- dispatch(success(response.data.message));
286
- setTimeout(() => {
287
- handleNavigation();
288
- }, 2000);
289
- } else if (response.status == 418) {
290
- // nothing to do
291
- } else {
292
- dispatch(failure(response?.data?.message || response?.message));
293
- }
294
- } catch (error) {
295
- handleChangeModel('', 'false');
296
- } finally {
297
- setTimeout(() => {
298
- setIsShowModel((prev) => ({ ...prev, loading: false }));
299
- }, 2000);
300
- }
301
- };
302
-
303
- const handleUpdateTemplate = async (data: any, selectedFields: any) => {
304
- // @ts-ignore
305
- const response: any = await updateTemplate(id, {
306
- title: title,
307
- fields: selectedFields,
308
- thumbnailPath: data.thumbnailPath,
309
- templatePath: data.templatePath,
310
- backTemplatePath: data.backTemplatePath || '',
311
- backThumbnailPath: data.backThumbnailPath || '',
312
- });
313
- if (response.status === 200) {
314
- dispatch(success(response.data.message));
315
- handleNavigation();
316
- } else {
317
- dispatch(failure(response.data.message));
318
- }
319
- handleChangeModel('', 'false');
320
- };
321
-
322
-
323
- const handleChangeModel = (model: string = '', loading: string | null = null) => {
324
- setIsShowModel((prev) => ({
325
- ...prev,
326
- open: !prev.open,
327
- loading: loading === 'false' ? false : prev.loading,
328
- model,
329
- }));
330
- };
331
-
332
- return (
333
- <div className="top-navigation-container">
334
- {showNavigateDialog && (
335
- <ConfirmNavigateDialog
336
- open={showNavigateDialog}
337
- handleClose={() => setShowNavigateDialog(false)}
338
- handleNavigateAction={() => handleNavigation(returnRoute ? returnRoute : '/create-template')}
339
- />
340
- )}
341
- {isShowModel?.open && isShowModel?.model === 'edit' && (
342
- <EditTemplateNameModel
343
- open={isShowModel?.open}
344
- handleClose={() => handleChangeModel()}
345
- />
346
- )}
347
- {isShowModel.open && isShowModel.model === 'save' && (
348
- <SaveTemplateModel
349
- loading={isShowModel.loading}
350
- open={isShowModel.open}
351
- handleClose={() => handleChangeModel()}
352
- handleSave={handleSave}
353
- />
354
- )}
355
- <GridContainer style={{ alignItems: 'center' }}>
356
- <GridItem lg={4} md={4} sm={2} xs={12}></GridItem>
357
- <GridItem lg={4} md={2} sm={2} xs={12}>
358
- <div className="middle">
359
- <Typography>{title}</Typography>
360
- <div onClick={() => handleChangeModel('edit')}>
361
- <EditIcon fill="var(--textColor)" />
362
- </div>
363
- </div>
364
- </GridItem>
365
- <GridItem lg={4} md={6} sm={8} xs={12}>
366
- <div className="actionsBtnWrapper right">
367
- <Button
368
- style={{ ...buttonStyles, maxWidth: 'auto', minWidth: '100px' }}
369
- onClick={handleViewProofWithLamda}
370
- >
371
- {downloadingProof ? (
372
- <CircularProgress style={progressStyles} />
373
- ) : (
374
- MESSAGES.TEMPLATE.DOWNLOAD_PROOF_BUTTON
375
- )}
376
- </Button>
377
- <Button
378
- style={{
379
- ...buttonStyles,
380
- border: '0.5px solid var(--primaryColor)',
381
- color: 'var(--primaryColor)',
382
- }}
383
- onClick={() => handleBackPress()}
384
- >
385
- {MESSAGES.TEMPLATE.CANCEL_BUTTON}
386
- </Button>
387
- <Button
388
- style={{
389
- ...buttonStyles,
390
- border: 'none',
391
- backgroundColor: 'var(--primaryColor)',
392
- color: 'var(--primaryButtonTextColor)',
393
- }}
394
- onClick={() => handleChangeModel('save')}
395
- >
396
- {MESSAGES.TEMPLATE.SUBMIT_BUTTON}
397
- </Button>
398
- </div>
399
- </GridItem>
400
- </GridContainer>
401
- </div>
402
- );
403
- };
404
-
405
- export default TopNavigation;