@dev.smartpricing/message-composer-layer 1.0.1

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 (169) hide show
  1. package/README.md +75 -0
  2. package/app/api/ai.ts +28 -0
  3. package/app/api/brands.ts +54 -0
  4. package/app/api/client.ts +56 -0
  5. package/app/api/compilation.ts +34 -0
  6. package/app/api/dynamicValues.ts +11 -0
  7. package/app/api/index.ts +11 -0
  8. package/app/api/languages.ts +6 -0
  9. package/app/api/media.ts +26 -0
  10. package/app/api/messageGroups.ts +49 -0
  11. package/app/api/messages.ts +22 -0
  12. package/app/api/meta.ts +18 -0
  13. package/app/api/tracking.ts +9 -0
  14. package/app/components/Brand/BrandDrawer.vue +281 -0
  15. package/app/components/Brand/BrandPreview.vue +137 -0
  16. package/app/components/Brand/Steps/BrandStepGeneral.vue +37 -0
  17. package/app/components/Brand/Steps/BrandStepSocials.vue +48 -0
  18. package/app/components/Brand/Steps/BrandStepVisual.vue +214 -0
  19. package/app/components/Common/BrandColorSwatches.vue +37 -0
  20. package/app/components/Common/ColorInput.vue +144 -0
  21. package/app/components/Common/EmojiPickerButton.vue +35 -0
  22. package/app/components/Common/FontFamilySelect.vue +39 -0
  23. package/app/components/Common/HtmlPreviewIframe.vue +68 -0
  24. package/app/components/Common/IncompleteTranslationsDialog.vue +97 -0
  25. package/app/components/Common/LanguageList.vue +356 -0
  26. package/app/components/Common/LoadingOverlay.vue +12 -0
  27. package/app/components/Common/MediaUploadOrSelect.vue +299 -0
  28. package/app/components/Common/MessagePreviewSlideover.vue +88 -0
  29. package/app/components/Common/MonacoEditor.vue +110 -0
  30. package/app/components/Common/PhoneInput.vue +804 -0
  31. package/app/components/Common/SectionHeader.vue +26 -0
  32. package/app/components/Common/TranslationActionBar.vue +139 -0
  33. package/app/components/Common/ViewLessMore.vue +40 -0
  34. package/app/components/CreateTemplateButton.vue +59 -0
  35. package/app/components/DynamicDataButton.vue +75 -0
  36. package/app/components/DynamicDataSlideover.vue +149 -0
  37. package/app/components/Editor/AiGenerateSlideover.vue +292 -0
  38. package/app/components/Editor/EditorLinkPopover.vue +154 -0
  39. package/app/components/Editor/RichTextEditor.vue +495 -0
  40. package/app/components/Email/Editor/BlockLibrary.vue +89 -0
  41. package/app/components/Email/Editor/BlockSettings.vue +60 -0
  42. package/app/components/Email/Editor/Blocks/ButtonBlock.vue +117 -0
  43. package/app/components/Email/Editor/Blocks/ButtonSettings.vue +228 -0
  44. package/app/components/Email/Editor/Blocks/DiscountCodeBlock.vue +74 -0
  45. package/app/components/Email/Editor/Blocks/DiscountCodeSettings.vue +162 -0
  46. package/app/components/Email/Editor/Blocks/DividerBlock.vue +31 -0
  47. package/app/components/Email/Editor/Blocks/DividerSettings.vue +108 -0
  48. package/app/components/Email/Editor/Blocks/FooterBlock.vue +61 -0
  49. package/app/components/Email/Editor/Blocks/FooterSettings.vue +123 -0
  50. package/app/components/Email/Editor/Blocks/GridBlock.vue +128 -0
  51. package/app/components/Email/Editor/Blocks/GridSettings.vue +109 -0
  52. package/app/components/Email/Editor/Blocks/HTMLBlock.vue +31 -0
  53. package/app/components/Email/Editor/Blocks/HTMLSettings.vue +85 -0
  54. package/app/components/Email/Editor/Blocks/HeaderBlock.vue +53 -0
  55. package/app/components/Email/Editor/Blocks/HeaderSettings.vue +113 -0
  56. package/app/components/Email/Editor/Blocks/HeadingBlock.vue +61 -0
  57. package/app/components/Email/Editor/Blocks/HeadingSettings.vue +156 -0
  58. package/app/components/Email/Editor/Blocks/ImageBlock.vue +49 -0
  59. package/app/components/Email/Editor/Blocks/ImageSettings.vue +53 -0
  60. package/app/components/Email/Editor/Blocks/IndexBlock.vue +155 -0
  61. package/app/components/Email/Editor/Blocks/ParagraphBlock.vue +61 -0
  62. package/app/components/Email/Editor/Blocks/ParagraphSettings.vue +157 -0
  63. package/app/components/Email/Editor/Blocks/SocialsBlock.vue +63 -0
  64. package/app/components/Email/Editor/Blocks/SocialsSettings.vue +117 -0
  65. package/app/components/Email/Editor/Blocks/SpacerBlock.vue +37 -0
  66. package/app/components/Email/Editor/Blocks/SpacerSettings.vue +95 -0
  67. package/app/components/Email/Editor/Blocks/TopProductsBlock.vue +47 -0
  68. package/app/components/Email/Editor/Blocks/TopProductsSettings.vue +87 -0
  69. package/app/components/Email/Editor/Blocks/UnsubscribeLinkBlock.vue +61 -0
  70. package/app/components/Email/Editor/Blocks/UnsubscribeLinkSettings.vue +123 -0
  71. package/app/components/Email/Editor/Canvas.vue +143 -0
  72. package/app/components/Email/Editor/GeneralStyleSettings.vue +125 -0
  73. package/app/components/Email/Editor/Index.vue +77 -0
  74. package/app/components/Email/Editor/LeftSidebar.vue +95 -0
  75. package/app/components/Email/InlinePreview.vue +124 -0
  76. package/app/components/Email/Preview.vue +126 -0
  77. package/app/components/Email/PreviewPanel.vue +57 -0
  78. package/app/components/Email/SendTestEmailModal.vue +121 -0
  79. package/app/components/Email/TranslationEditor.vue +198 -0
  80. package/app/components/Email/Translator/Button.vue +101 -0
  81. package/app/components/Email/Translator/Discount.vue +60 -0
  82. package/app/components/Email/Translator/Footer.vue +66 -0
  83. package/app/components/Email/Translator/Grid.vue +127 -0
  84. package/app/components/Email/Translator/Header.vue +90 -0
  85. package/app/components/Email/Translator/Heading.vue +66 -0
  86. package/app/components/Email/Translator/Image.vue +91 -0
  87. package/app/components/Email/Translator/Index.vue +138 -0
  88. package/app/components/Email/Translator/Paragraph.vue +66 -0
  89. package/app/components/Email/Translator/RawHtml.vue +64 -0
  90. package/app/components/Email/Translator/UnsubscribeLink.vue +59 -0
  91. package/app/components/TemplateList/BaseTable.vue +354 -0
  92. package/app/components/TemplateList/StatusCell.vue +67 -0
  93. package/app/components/Whatsapp/CategoryChanger.vue +63 -0
  94. package/app/components/Whatsapp/Editor/Body.vue +53 -0
  95. package/app/components/Whatsapp/Editor/Buttons.vue +341 -0
  96. package/app/components/Whatsapp/Editor/Footer.vue +70 -0
  97. package/app/components/Whatsapp/Editor/Header.vue +156 -0
  98. package/app/components/Whatsapp/Editor/Index.vue +89 -0
  99. package/app/components/Whatsapp/Editor/SyncWrapper.vue +166 -0
  100. package/app/components/Whatsapp/Preview.vue +197 -0
  101. package/app/components/Whatsapp/PreviewPanel.vue +24 -0
  102. package/app/components/Whatsapp/TranslationEditor.vue +150 -0
  103. package/app/components/Whatsapp/Translator/Body.vue +61 -0
  104. package/app/components/Whatsapp/Translator/Button.vue +209 -0
  105. package/app/components/Whatsapp/Translator/Footer.vue +56 -0
  106. package/app/components/Whatsapp/Translator/Header.vue +61 -0
  107. package/app/components/Whatsapp/Translator/HeaderMedia.vue +117 -0
  108. package/app/components/Whatsapp/Translator/Index.vue +159 -0
  109. package/app/composables/composerContext.ts +35 -0
  110. package/app/composables/useAutoTranslate.ts +242 -0
  111. package/app/composables/useAutoTranslateEmail.ts +294 -0
  112. package/app/composables/useChangeTracking.ts +212 -0
  113. package/app/composables/useChangeTrackingEmail.ts +227 -0
  114. package/app/composables/useChannels.ts +36 -0
  115. package/app/composables/useEmailBlockContext.ts +43 -0
  116. package/app/composables/useExitConfirmation.ts +39 -0
  117. package/app/composables/useGoBack.ts +15 -0
  118. package/app/composables/useIncompleteTranslations.ts +55 -0
  119. package/app/composables/useIncompleteTranslationsEmail.ts +56 -0
  120. package/app/composables/useMediaLimits.ts +42 -0
  121. package/app/composables/useTemplateFormValidation.ts +109 -0
  122. package/app/composables/useTemplateOperations.ts +147 -0
  123. package/app/composables/useTracking.ts +39 -0
  124. package/app/composables/useTranslationFilters.ts +176 -0
  125. package/app/composables/useTranslationFiltersEmail.ts +244 -0
  126. package/app/composables/useWhatsappTemplateBehaviors.ts +58 -0
  127. package/app/middleware/channel-guard.ts +13 -0
  128. package/app/pages/brands.vue +195 -0
  129. package/app/pages/images.vue +141 -0
  130. package/app/pages/index.vue +198 -0
  131. package/app/pages/preview/[id].vue +47 -0
  132. package/app/pages/template/email/[id].vue +596 -0
  133. package/app/pages/template/email/create.vue +562 -0
  134. package/app/pages/template/whatsapp/[id].vue +561 -0
  135. package/app/pages/template/whatsapp/create.vue +468 -0
  136. package/app/plugins/admin-shortcut.client.ts +7 -0
  137. package/app/plugins/tracking.client.ts +12 -0
  138. package/app/queries/ai.ts +20 -0
  139. package/app/queries/brands.ts +75 -0
  140. package/app/queries/compilation.ts +37 -0
  141. package/app/queries/dynamicValues.ts +13 -0
  142. package/app/queries/index.ts +9 -0
  143. package/app/queries/languages.ts +10 -0
  144. package/app/queries/media.ts +27 -0
  145. package/app/queries/messageGroups.ts +112 -0
  146. package/app/queries/messages.ts +42 -0
  147. package/app/queries/meta.ts +13 -0
  148. package/app/stores/adminStore.ts +50 -0
  149. package/app/stores/appContext.ts +99 -0
  150. package/app/stores/emailEditor.ts +220 -0
  151. package/app/stores/main.ts +3 -0
  152. package/app/stores/metaSubmission.ts +116 -0
  153. package/app/types/app-config.d.ts +14 -0
  154. package/app/types/hooks.d.ts +9 -0
  155. package/app/types/tracking.ts +148 -0
  156. package/app/utils/locale.ts +17 -0
  157. package/app/utils/notifyParent.ts +7 -0
  158. package/app/utils/resolveDefaultLanguage.ts +14 -0
  159. package/app/utils/socialDefaults.ts +42 -0
  160. package/app/utils/testIds.const.ts +728 -0
  161. package/app.config.ts +5 -0
  162. package/i18n/check-translations.ts +56 -0
  163. package/i18n/locales/de.ts +834 -0
  164. package/i18n/locales/en.ts +826 -0
  165. package/i18n/locales/es.ts +833 -0
  166. package/i18n/locales/fr.ts +837 -0
  167. package/i18n/locales/it.ts +831 -0
  168. package/nuxt.config.ts +65 -0
  169. package/package.json +64 -0
@@ -0,0 +1,117 @@
1
+ <script lang="ts" setup>
2
+ import type { ButtonBlock } from '@dev.smartpricing/message-composer-utils/types'
3
+ import { useEditor, EditorContent } from '@tiptap/vue-3'
4
+ import { getTipTapExtensions } from '@dev.smartpricing/message-composer-utils/utils'
5
+ import { useAppContextStore } from '@/stores/appContext'
6
+ const appContext = useAppContextStore()
7
+ const emailEditorStore = useEmailEditorStore()
8
+
9
+ const props = defineProps<{
10
+ block: ButtonBlock
11
+ }>()
12
+
13
+ const { t } = useI18n()
14
+
15
+ const editor = useEditor({
16
+ content: props.block.settings.content,
17
+ extensions: getTipTapExtensions({
18
+ preset: 'email',
19
+ dynamicValues: true,
20
+ }),
21
+ editable: false,
22
+ })
23
+
24
+ // Watch for changes in block content
25
+ watch(
26
+ () => props.block.settings.content,
27
+ (newContent) => {
28
+ if (editor.value && JSON.stringify(editor.value.getJSON()) !== JSON.stringify(newContent)) {
29
+ editor.value.commands.setContent(newContent || '')
30
+ }
31
+ },
32
+ )
33
+
34
+ const buttonStyles = computed(() => {
35
+ const resolved = emailEditorStore.resolvedSettings
36
+ const fontFamily = props.block.settings.fontFamily ?? resolved.fontFamily
37
+ const styles: Record<string, string> = {
38
+ fontFamily: `${fontFamily}, sans-serif`,
39
+ fontSize: `${props.block.settings.fontSize}px`,
40
+ color: props.block.settings.textColor ?? resolved.button.textColor,
41
+ backgroundColor: props.block.settings.backgroundColor ?? resolved.button.backgroundColor,
42
+ textAlign: 'center',
43
+ borderRadius:
44
+ props.block.settings.shape === 'square'
45
+ ? '0px'
46
+ : props.block.settings.shape === 'rounded'
47
+ ? '8px'
48
+ : '50px',
49
+ padding: '12px 24px',
50
+ border: 'none',
51
+ cursor: 'pointer',
52
+ display: 'inline-block',
53
+ textDecoration: 'none',
54
+ }
55
+
56
+ if (props.block.settings.width === 'full_width') {
57
+ styles.width = '100%'
58
+ }
59
+
60
+ return styles
61
+ })
62
+
63
+ const containerStyles = computed(() => ({
64
+ backgroundColor: props.block.settings.backgroundBlock,
65
+ display: 'flex',
66
+ justifyContent:
67
+ props.block.settings.alignment === 'left'
68
+ ? 'flex-start'
69
+ : props.block.settings.alignment === 'center'
70
+ ? 'center'
71
+ : 'flex-end',
72
+ padding: '16px',
73
+ }))
74
+
75
+ defineOptions({
76
+ name: 'ButtonBlock',
77
+ })
78
+ </script>
79
+
80
+ <template>
81
+ <div :style="containerStyles" :data-testid="buttonBlockTestIds.container">
82
+ <div
83
+ v-if="!block.settings.content"
84
+ class="inline-block rounded border border-dashed border-neutral-300 px-6 py-3"
85
+ :data-testid="buttonBlockTestIds.placeholder"
86
+ >
87
+ <span class="text-sm text-neutral-500">{{
88
+ $t('editor.email.blocks.button.placeholder')
89
+ }}</span>
90
+ </div>
91
+ <div v-else :style="buttonStyles" class="button-block" :data-testid="buttonBlockTestIds.button">
92
+ <EditorContent :editor="editor" class="button-content" />
93
+ </div>
94
+ </div>
95
+ </template>
96
+
97
+ <style scoped>
98
+ .button-content :deep(.ProseMirror) {
99
+ padding: 0 !important;
100
+ }
101
+
102
+ .button-content :deep(.tiptap) {
103
+ outline: none;
104
+ }
105
+
106
+ .button-content :deep(p) {
107
+ margin: 0;
108
+ }
109
+
110
+ .button-block {
111
+ transition: opacity 0.2s;
112
+ }
113
+
114
+ .button-block:hover {
115
+ opacity: 0.9;
116
+ }
117
+ </style>
@@ -0,0 +1,228 @@
1
+ <script lang="ts" setup>
2
+ import type { ButtonBlock } from '@dev.smartpricing/message-composer-utils/types'
3
+ import { DEFAULT_BUTTON_SETTINGS } from '@dev.smartpricing/message-composer-utils/types'
4
+ import RichTextEditor from '@/components/Editor/RichTextEditor.vue'
5
+ import PhoneInput from '@/components/Common/PhoneInput.vue'
6
+ import ColorInput from '~/components/Common/ColorInput.vue'
7
+ import FontFamilySelect from '~/components/Common/FontFamilySelect.vue'
8
+ import SectionHeader from '~/components/Common/SectionHeader.vue'
9
+ import type { TabsItem } from '#ui/types'
10
+
11
+ const props = defineProps<{
12
+ block: ButtonBlock
13
+ }>()
14
+
15
+ const emailEditorStore = useEmailEditorStore()
16
+ const { t } = useI18n()
17
+
18
+ const content = computed({
19
+ get: () => props.block.settings.content,
20
+ set: (value) => {
21
+ emailEditorStore.updateBlock(props.block.id, {
22
+ settings: { ...props.block.settings, content: value },
23
+ })
24
+ },
25
+ })
26
+
27
+ const linkTypeOptions = [
28
+ { value: 'web', label: t('editor.email.blocks.button.link_types.web') },
29
+ { value: 'email', label: t('editor.email.blocks.button.link_types.email') },
30
+ { value: 'phone', label: t('editor.email.blocks.button.link_types.phone') },
31
+ ]
32
+
33
+ const shapeOptions = [
34
+ { value: 'square', label: t('editor.email.blocks.button.shapes.square') },
35
+ { value: 'rounded', label: t('editor.email.blocks.button.shapes.rounded') },
36
+ { value: 'pill', label: t('editor.email.blocks.button.shapes.pill') },
37
+ ]
38
+
39
+ const widthOptions = [
40
+ { value: 'fit_to_text', label: t('editor.email.blocks.button.widths.fit_to_text') },
41
+ { value: 'full_width', label: t('editor.email.blocks.button.widths.full_width') },
42
+ ]
43
+
44
+ const alignmentOptions: TabsItem[] = [
45
+ { value: 'left', icon: 'ph:align-left' },
46
+ { value: 'center', icon: 'ph:align-center-horizontal' },
47
+ { value: 'right', icon: 'ph:align-right' },
48
+ ]
49
+
50
+ function resetTextStyle() {
51
+ emailEditorStore.updateBlock(props.block.id, {
52
+ settings: {
53
+ ...props.block.settings,
54
+ fontFamily: DEFAULT_BUTTON_SETTINGS.fontFamily,
55
+ fontSize: DEFAULT_BUTTON_SETTINGS.fontSize,
56
+ },
57
+ })
58
+ }
59
+
60
+ function resetColors() {
61
+ emailEditorStore.updateBlock(props.block.id, {
62
+ settings: {
63
+ ...props.block.settings,
64
+ textColor: DEFAULT_BUTTON_SETTINGS.textColor,
65
+ backgroundColor: DEFAULT_BUTTON_SETTINGS.backgroundColor,
66
+ backgroundBlock: DEFAULT_BUTTON_SETTINGS.backgroundBlock,
67
+ },
68
+ })
69
+ }
70
+
71
+ defineOptions({
72
+ name: 'ButtonSettings',
73
+ })
74
+ </script>
75
+
76
+ <template>
77
+ <div class="space-y-6 p-4" :data-testid="buttonSettingsTestIds.container">
78
+ <!-- Content Editor -->
79
+ <div class="space-y-3">
80
+ <p class="paragraph-md-bold">
81
+ {{ $t('editor.email.blocks.button.settings.content') }}
82
+ </p>
83
+ <RichTextEditor
84
+ v-model:text="content"
85
+ preset="email"
86
+ bold
87
+ italic
88
+ underline
89
+ lists
90
+ horizontal-rule
91
+ alignment
92
+ link
93
+ emoji
94
+ />
95
+ </div>
96
+
97
+ <!-- Link Type Section -->
98
+ <div class="space-y-3">
99
+ <UFormField
100
+ :label="$t('editor.email.blocks.button.settings.link_type')"
101
+ :data-testid="buttonSettingsTestIds.linkTypeField"
102
+ >
103
+ <USelect
104
+ v-model="block.settings.linkType"
105
+ :items="linkTypeOptions"
106
+ :data-testid="buttonSettingsTestIds.linkTypeSelect"
107
+ />
108
+ </UFormField>
109
+ <PhoneInput
110
+ v-if="block.settings.linkType === 'phone'"
111
+ v-model="block.settings.url"
112
+ default-prefix="+39"
113
+ :data-testid="buttonSettingsTestIds.phoneInput"
114
+ />
115
+ <UInput
116
+ v-else
117
+ v-model="block.settings.url"
118
+ type="text"
119
+ :placeholder="
120
+ block.settings.linkType === 'web' ? 'https://www.example.com' : 'email@example.com'
121
+ "
122
+ :data-testid="buttonSettingsTestIds.urlInput"
123
+ />
124
+ </div>
125
+
126
+ <!-- Text Type Section -->
127
+ <div class="space-y-3">
128
+ <SectionHeader
129
+ :title="$t('editor.email.blocks.button.settings.text_type')"
130
+ show-reset
131
+ @reset="resetTextStyle"
132
+ />
133
+
134
+ <!-- Font and Size -->
135
+ <div class="grid grid-cols-2 gap-3">
136
+ <FontFamilySelect
137
+ v-model="block.settings.fontFamily"
138
+ :label="$t('editor.email.blocks.button.settings.font')"
139
+ :default-value="emailEditorStore.resolvedSettings.fontFamily"
140
+ />
141
+ <UFormField
142
+ :label="$t('editor.email.blocks.button.settings.size')"
143
+ :data-testid="buttonSettingsTestIds.fontSizeField"
144
+ >
145
+ <UFieldGroup class="w-full">
146
+ <UInputNumber
147
+ v-model="block.settings.fontSize"
148
+ :data-testid="buttonSettingsTestIds.fontSizeInput"
149
+ />
150
+ <UBadge color="neutral" variant="outline">px</UBadge>
151
+ </UFieldGroup>
152
+ </UFormField>
153
+ </div>
154
+ </div>
155
+
156
+ <!-- Style Section -->
157
+ <div class="space-y-3">
158
+ <p class="paragraph-md-bold">
159
+ {{ $t('editor.email.blocks.button.settings.style') }}
160
+ </p>
161
+
162
+ <!-- Shape -->
163
+ <div>
164
+ <UTabs
165
+ v-model="block.settings.shape"
166
+ :items="shapeOptions"
167
+ :content="false"
168
+ size="sm"
169
+ :data-testid="buttonSettingsTestIds.shapeTabs"
170
+ />
171
+ </div>
172
+
173
+ <!-- Width -->
174
+ <div>
175
+ <UTabs
176
+ v-model="block.settings.width"
177
+ :items="widthOptions"
178
+ :content="false"
179
+ size="sm"
180
+ :data-testid="buttonSettingsTestIds.widthTabs"
181
+ />
182
+ </div>
183
+
184
+ <!-- Alignment -->
185
+ <div :class="{ 'opacity-50 cursor-not-allowed': block.settings.width === 'full_width' }">
186
+ <div :class="{ 'pointer-events-none': block.settings.width === 'full_width' }">
187
+ <UTabs
188
+ v-model="block.settings.alignment"
189
+ :items="alignmentOptions"
190
+ :content="false"
191
+ size="sm"
192
+ :data-testid="buttonSettingsTestIds.alignmentTabs"
193
+ />
194
+ </div>
195
+ </div>
196
+ </div>
197
+
198
+ <!-- Colors Section -->
199
+ <div class="space-y-3">
200
+ <SectionHeader
201
+ :title="$t('editor.email.blocks.button.settings.colors')"
202
+ show-reset
203
+ @reset="resetColors"
204
+ />
205
+
206
+ <!-- Text Color -->
207
+
208
+ <ColorInput
209
+ v-model="block.settings.textColor"
210
+ :label="$t('editor.email.blocks.button.settings.text')"
211
+ :default-value="emailEditorStore.resolvedSettings.button.textColor"
212
+ />
213
+
214
+ <!-- Background Color -->
215
+ <ColorInput
216
+ v-model="block.settings.backgroundColor"
217
+ :label="$t('editor.email.blocks.button.settings.background')"
218
+ :default-value="emailEditorStore.resolvedSettings.button.backgroundColor"
219
+ />
220
+
221
+ <!-- Background Block -->
222
+ <ColorInput
223
+ v-model="block.settings.backgroundBlock"
224
+ :label="$t('editor.email.blocks.button.settings.background_block')"
225
+ />
226
+ </div>
227
+ </div>
228
+ </template>
@@ -0,0 +1,74 @@
1
+ <script lang="ts" setup>
2
+ import type { DiscountBlock } from '@dev.smartpricing/message-composer-utils/types'
3
+ import { useEditor, EditorContent } from '@tiptap/vue-3'
4
+ import { getTipTapExtensions } from '@dev.smartpricing/message-composer-utils/utils'
5
+
6
+ const props = defineProps<{
7
+ block: DiscountBlock
8
+ }>()
9
+
10
+ const emailEditorStore = useEmailEditorStore()
11
+
12
+ const editor = useEditor({
13
+ content: props.block.settings.content,
14
+ extensions: getTipTapExtensions({ preset: 'email' }),
15
+ editable: false,
16
+ })
17
+
18
+ watch(
19
+ () => props.block.settings.content,
20
+ (newContent) => {
21
+ if (editor.value && newContent !== editor.value.getJSON()) {
22
+ editor.value.commands.setContent(newContent || '')
23
+ }
24
+ },
25
+ )
26
+
27
+ const discountCodeStyles = computed(() => {
28
+ const fontFamily = props.block.settings.fontFamily ?? emailEditorStore.resolvedSettings.fontFamily
29
+ const styles: Record<string, string> = {
30
+ fontFamily: `${fontFamily}, sans-serif`,
31
+ fontSize: `${props.block.settings.fontSize}px`,
32
+ color: props.block.settings.textColor ?? emailEditorStore.resolvedSettings.textColor,
33
+ backgroundColor: props.block.settings.backgroundComponent,
34
+ borderRadius:
35
+ props.block.settings.style === 'square'
36
+ ? '0px'
37
+ : props.block.settings.style === 'rounded'
38
+ ? '8px'
39
+ : '50px',
40
+ padding: '16px 24px',
41
+ textAlign: 'center',
42
+ display: 'inline-block',
43
+ }
44
+
45
+ if (props.block.settings.width === 'full_width') {
46
+ styles.width = '100%'
47
+ }
48
+
49
+ return styles
50
+ })
51
+
52
+ const containerStyles = computed(() => {
53
+ return {
54
+ backgroundColor: props.block.settings.backgroundBlock,
55
+ padding: '16px',
56
+ textAlign: 'center' as const,
57
+ }
58
+ })
59
+
60
+ defineOptions({
61
+ name: 'DiscountCodeBlock',
62
+ })
63
+ </script>
64
+
65
+ <template>
66
+ <div :style="containerStyles" :data-testid="discountCodeBlockTestIds.container">
67
+ <div :style="discountCodeStyles" :data-testid="discountCodeBlockTestIds.code">
68
+ <EditorContent v-if="editor" :editor="editor" />
69
+ <span v-else class="text-neutral-400">
70
+ {{ $t('editor.email.blocks.discount.placeholder') }}
71
+ </span>
72
+ </div>
73
+ </div>
74
+ </template>
@@ -0,0 +1,162 @@
1
+ <script lang="ts" setup>
2
+ import type { DiscountBlock } from '@dev.smartpricing/message-composer-utils/types'
3
+ import {
4
+ TAGS_DEFAULT_FONT_SIZE,
5
+ DEFAULT_DISCOUNT_SETTINGS,
6
+ } from '@dev.smartpricing/message-composer-utils/types'
7
+ import RichTextEditor from '@/components/Editor/RichTextEditor.vue'
8
+ import ColorInput from '~/components/Common/ColorInput.vue'
9
+ import FontFamilySelect from '~/components/Common/FontFamilySelect.vue'
10
+ import SectionHeader from '~/components/Common/SectionHeader.vue'
11
+
12
+ const props = defineProps<{
13
+ block: DiscountBlock
14
+ }>()
15
+
16
+ const emailEditorStore = useEmailEditorStore()
17
+ const { t } = useI18n()
18
+
19
+ const content = computed({
20
+ get: () => props.block.settings.content,
21
+ set: (value) => {
22
+ emailEditorStore.updateBlock(props.block.id, {
23
+ settings: { ...props.block.settings, content: value },
24
+ })
25
+ },
26
+ })
27
+
28
+ const styleOptions = [
29
+ { value: 'square', label: t('editor.email.blocks.discount.styles.square') },
30
+ { value: 'rounded', label: t('editor.email.blocks.discount.styles.rounded') },
31
+ { value: 'pill', label: t('editor.email.blocks.discount.styles.pill') },
32
+ ]
33
+
34
+ const widthOptions = [
35
+ { value: 'fit_to_text', label: t('editor.email.blocks.button.widths.fit_to_text') },
36
+ { value: 'full_width', label: t('editor.email.blocks.button.widths.full_width') },
37
+ ]
38
+
39
+ function resetTextStyle() {
40
+ emailEditorStore.updateBlock(props.block.id, {
41
+ settings: {
42
+ ...props.block.settings,
43
+ fontFamily: DEFAULT_DISCOUNT_SETTINGS.fontFamily,
44
+ fontSize: DEFAULT_DISCOUNT_SETTINGS.fontSize,
45
+ tag: DEFAULT_DISCOUNT_SETTINGS.tag,
46
+ },
47
+ })
48
+ }
49
+
50
+ function resetColors() {
51
+ emailEditorStore.updateBlock(props.block.id, {
52
+ settings: {
53
+ ...props.block.settings,
54
+ textColor: DEFAULT_DISCOUNT_SETTINGS.textColor,
55
+ backgroundComponent: DEFAULT_DISCOUNT_SETTINGS.backgroundComponent,
56
+ backgroundBlock: DEFAULT_DISCOUNT_SETTINGS.backgroundBlock,
57
+ },
58
+ })
59
+ }
60
+
61
+ defineOptions({
62
+ name: 'DiscountCodeSettings',
63
+ })
64
+ </script>
65
+
66
+ <template>
67
+ <div class="space-y-6 p-4" :data-testid="discountCodeSettingsTestIds.container">
68
+ <!-- Content Editor -->
69
+ <div class="space-y-3">
70
+ <p class="paragraph-md-bold">
71
+ {{ $t('editor.email.blocks.discount.settings.discount_code') }}
72
+ </p>
73
+ <RichTextEditor v-model:text="content" preset="email" bold alignment />
74
+ </div>
75
+
76
+ <!-- Text Type Section -->
77
+ <div class="space-y-3">
78
+ <SectionHeader
79
+ :title="$t('editor.email.blocks.discount.settings.text_type')"
80
+ show-reset
81
+ @reset="resetTextStyle"
82
+ />
83
+
84
+ <!-- Font and Size -->
85
+ <div class="grid grid-cols-2 gap-3">
86
+ <FontFamilySelect
87
+ v-model="block.settings.fontFamily"
88
+ :label="$t('editor.email.blocks.discount.settings.font')"
89
+ :default-value="emailEditorStore.resolvedSettings.fontFamily"
90
+ />
91
+ <UFormField
92
+ :label="$t('editor.email.blocks.discount.settings.size')"
93
+ :data-testid="discountCodeSettingsTestIds.fontSizeField"
94
+ >
95
+ <UFieldGroup class="w-full">
96
+ <UInputNumber
97
+ v-model="block.settings.fontSize"
98
+ :data-testid="discountCodeSettingsTestIds.fontSizeInput"
99
+ />
100
+ <UBadge color="neutral" variant="outline">px</UBadge>
101
+ </UFieldGroup>
102
+ </UFormField>
103
+ </div>
104
+ </div>
105
+
106
+ <!-- Style Section -->
107
+ <div class="space-y-3">
108
+ <p class="paragraph-md-bold">
109
+ {{ $t('editor.email.blocks.discount.settings.style') }}
110
+ </p>
111
+
112
+ <!-- Shape -->
113
+ <div>
114
+ <UTabs
115
+ v-model="block.settings.style"
116
+ :items="styleOptions"
117
+ :content="false"
118
+ size="sm"
119
+ :data-testid="discountCodeSettingsTestIds.styleTabs"
120
+ />
121
+ </div>
122
+ <div>
123
+ <UTabs
124
+ v-model="block.settings.width"
125
+ :items="widthOptions"
126
+ :content="false"
127
+ size="sm"
128
+ :data-testid="discountCodeSettingsTestIds.widthTabs"
129
+ />
130
+ </div>
131
+ </div>
132
+
133
+ <!-- Colors Section -->
134
+ <div class="space-y-3">
135
+ <SectionHeader
136
+ :title="$t('editor.email.blocks.discount.settings.colors')"
137
+ show-reset
138
+ @reset="resetColors"
139
+ />
140
+
141
+ <!-- Text Color -->
142
+
143
+ <ColorInput
144
+ v-model="block.settings.textColor"
145
+ :label="$t('editor.email.blocks.discount.settings.text')"
146
+ :default-value="emailEditorStore.resolvedSettings.textColor"
147
+ />
148
+
149
+ <!-- Background Component -->
150
+ <ColorInput
151
+ v-model="block.settings.backgroundComponent"
152
+ :label="$t('editor.email.blocks.discount.settings.background_component')"
153
+ />
154
+
155
+ <!-- Background Block -->
156
+ <ColorInput
157
+ v-model="block.settings.backgroundBlock"
158
+ :label="$t('editor.email.blocks.discount.settings.background_block')"
159
+ />
160
+ </div>
161
+ </div>
162
+ </template>
@@ -0,0 +1,31 @@
1
+ <script lang="ts" setup>
2
+ import type { DividerBlock } from '@dev.smartpricing/message-composer-utils/types'
3
+
4
+ const props = defineProps<{
5
+ block: DividerBlock
6
+ }>()
7
+
8
+ defineOptions({
9
+ name: 'DividerBlock',
10
+ })
11
+ </script>
12
+
13
+ <template>
14
+ <div
15
+ class="py-4"
16
+ :style="{ backgroundColor: block.settings.backgroundColor }"
17
+ :data-testid="dividerBlockTestIds.container"
18
+ >
19
+ <hr
20
+ :style="{
21
+ borderStyle: block.settings.style,
22
+ borderWidth: `${block.settings.thickness}px`,
23
+ borderColor: block.settings.color,
24
+ borderTop: 'none',
25
+ width: `${block.settings.width}%`,
26
+ margin: '0 auto',
27
+ }"
28
+ :data-testid="dividerBlockTestIds.rule"
29
+ />
30
+ </div>
31
+ </template>