From 3c99197e1eb215ca3005e24d42d1a71dfd15b166 Mon Sep 17 00:00:00 2001 From: Muhsin Keloth Date: Tue, 22 Jul 2025 16:57:13 +0400 Subject: [PATCH] chore: cleanup code --- .../components/WhatsappTemplateParser.vue | 157 ++++++++++-------- .../WhatsappTemplates/TemplatesPicker.vue | 44 ++--- .../i18n/locale/en/whatsappTemplates.json | 6 + 3 files changed, 112 insertions(+), 95 deletions(-) diff --git a/app/javascript/dashboard/components-next/NewConversation/components/WhatsappTemplateParser.vue b/app/javascript/dashboard/components-next/NewConversation/components/WhatsappTemplateParser.vue index 12cfbf39f..9e747023d 100644 --- a/app/javascript/dashboard/components-next/NewConversation/components/WhatsappTemplateParser.vue +++ b/app/javascript/dashboard/components-next/NewConversation/components/WhatsappTemplateParser.vue @@ -54,15 +54,17 @@ const buttonComponents = computed(() => { }); const interactiveComponents = computed(() => { - return templateComponents.value.filter( - component => ['LIST', 'PRODUCT', 'CATALOG'].includes(component.type) + return templateComponents.value.filter(component => + ['LIST', 'PRODUCT', 'CATALOG'].includes(component.type) ); }); const isInteractiveTemplate = computed(() => { const hasInteractiveButtons = buttonComponents.value.some(component => component.buttons?.some(button => - ['quick_reply', 'url', 'phone_number', 'catalog_browse'].includes(button.type) + ['quick_reply', 'url', 'phone_number', 'catalog_browse'].includes( + button.type + ) ) ); return hasInteractiveButtons || interactiveComponents.value.length > 0; @@ -105,13 +107,16 @@ const processedStringWithVariableHighlight = computed(() => { const rules = computed(() => { const paramRules = {}; Object.keys(processedParams.value).forEach(key => { - if (key === 'header' && processedParams.value.header.location_type === 'location') { + if ( + key === 'header' && + processedParams.value.header.location_type === 'location' + ) { // Add specific validation for location parameters paramRules[key] = { location: { latitude: { required: requiredIf(true) }, - longitude: { required: requiredIf(true) } - } + longitude: { required: requiredIf(true) }, + }, }; } else { paramRules[key] = { required: requiredIf(true) }; @@ -131,10 +136,6 @@ const getFieldErrorType = key => { const generateVariables = () => { const allVariables = {}; - - // Debug: Log template structure - console.log('Template components:', templateComponents.value); - console.log('Header component:', headerComponent.value); // Process body variables const bodyVars = templateString.value.match(/{{([^}]+)}}/g) || []; @@ -191,7 +192,6 @@ const generateVariables = () => { headerComponent.value.format === 'LOCATION' ) { // Location headers need location data - console.log('Detected LOCATION header template:', headerComponent.value); allVariables.header = { location: { latitude: '', @@ -262,19 +262,19 @@ const generateVariables = () => { allVariables.interactive = { type: 'list', button_text: 'Select Option', - sections: component.sections || [] + sections: component.sections || [], }; } else if (component.type === 'PRODUCT') { allVariables.interactive = { type: 'product', catalog_id: component.catalog_id || '', - product_id: component.product_id || '' + product_id: component.product_id || '', }; } else if (component.type === 'CATALOG') { allVariables.interactive = { type: 'catalog', catalog_id: component.catalog_id || '', - title: component.title || 'Browse Products' + title: component.title || 'Browse Products', }; } }); @@ -450,7 +450,7 @@ onMounted(() => {
-

+

{{ t('WHATSAPP_TEMPLATES.PARSER.HEADER_PARAMETERS') || 'Header Parameters' @@ -459,18 +459,22 @@ onMounted(() => {
-
-
+
+
- Location Details + Location Details
- +
-
-
- +
-
- +
-
- -
- 💡 Tip: You can get coordinates by searching your location on Google Maps, - right-clicking the pin, and copying the latitude/longitude values. + +
+ 💡 Tip: You can get coordinates by searching your + location on Google Maps, right-clicking the pin, and copying the + latitude/longitude values.
-
+
- - {{ getHeaderFieldLabel(key) }} - - + + {{ getHeaderFieldLabel(key) }} + +
-

+

{{ t('WHATSAPP_TEMPLATES.PARSER.BODY_PARAMETERS') || 'Body Parameters' }} @@ -570,7 +575,7 @@ onMounted(() => {
{
-

+

{{ t('WHATSAPP_TEMPLATES.PARSER.FOOTER_PARAMETERS') || 'Footer Parameters' @@ -600,7 +605,7 @@ onMounted(() => {
{
-

+

{{ t('WHATSAPP_TEMPLATES.PARSER.INTERACTIVE_PARAMETERS') || 'Interactive Parameters' }}

- + -
+
- + { />
- + {
-
+
- + { />
- + {
-
+
- + { />
- List sections are configured in the template and cannot be modified here. + List sections are configured in the template and cannot be modified + here.
-

+

{{ t('WHATSAPP_TEMPLATES.PARSER.BUTTON_PARAMETERS') || 'Button Parameters' @@ -702,7 +727,7 @@ onMounted(() => {
{
{ />
-
+