mirror of
https://github.com/lingble/chatwoot.git
synced 2025-11-01 11:37:58 +00:00
# Pull Request Template ## Description This PR fixes RTL alignment issues in the new conversation form, removes the unused [`form-checkbox`](https://github.com/chatwoot/chatwoot/pull/12151#discussion_r2266333315) class name and drops the `app-rtl--wrapper` class, which was previously used for RTL detection in `rtl.scss` (removed earlier) Fixes https://linear.app/chatwoot/issue/CW-5410/rtl-issues ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## How Has This Been Tested? ### Screenshots <img width="868" height="474" alt="image" src="https://github.com/user-attachments/assets/45995652-2895-49d5-a651-179090c949ec" /> <img width="868" height="656" alt="image" src="https://github.com/user-attachments/assets/a1cb4415-3fd4-4c9a-bc46-5e07e437d757" /> <img width="868" height="656" alt="image" src="https://github.com/user-attachments/assets/77c8981f-364e-4bf0-bea8-a4c42a76d065" /> ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
131 lines
3.9 KiB
Vue
131 lines
3.9 KiB
Vue
<script setup>
|
|
import { computed, ref } from 'vue';
|
|
import { useI18n } from 'vue-i18n';
|
|
|
|
import Icon from 'dashboard/components-next/icon/Icon.vue';
|
|
import Button from 'dashboard/components-next/button/Button.vue';
|
|
import WhatsappTemplateParser from './WhatsappTemplateParser.vue';
|
|
|
|
const props = defineProps({
|
|
messageTemplates: {
|
|
type: Array,
|
|
default: () => [],
|
|
},
|
|
});
|
|
|
|
const emit = defineEmits(['sendMessage']);
|
|
|
|
const { t } = useI18n();
|
|
|
|
// TODO: Remove this when we support all formats
|
|
const formatsToRemove = ['DOCUMENT', 'IMAGE', 'VIDEO'];
|
|
|
|
const searchQuery = ref('');
|
|
const selectedTemplate = ref(null);
|
|
|
|
const showTemplatesMenu = ref(false);
|
|
|
|
const whatsAppTemplateMessages = computed(() => {
|
|
// Add null check and ensure it's an array
|
|
const templates = Array.isArray(props.messageTemplates)
|
|
? props.messageTemplates
|
|
: [];
|
|
|
|
// TODO: Remove the last filter when we support all formats
|
|
return templates
|
|
.filter(template => template?.status?.toLowerCase() === 'approved')
|
|
.filter(template => {
|
|
return template?.components?.every(component => {
|
|
return !formatsToRemove.includes(component.format);
|
|
});
|
|
});
|
|
});
|
|
|
|
const filteredTemplates = computed(() => {
|
|
return whatsAppTemplateMessages.value.filter(template =>
|
|
template.name.toLowerCase().includes(searchQuery.value.toLowerCase())
|
|
);
|
|
});
|
|
|
|
const getTemplateBody = template => {
|
|
return template.components.find(component => component.type === 'BODY').text;
|
|
};
|
|
|
|
const handleTriggerClick = () => {
|
|
searchQuery.value = '';
|
|
showTemplatesMenu.value = !showTemplatesMenu.value;
|
|
};
|
|
|
|
const handleTemplateClick = template => {
|
|
selectedTemplate.value = template;
|
|
showTemplatesMenu.value = false;
|
|
};
|
|
|
|
const handleBack = () => {
|
|
selectedTemplate.value = null;
|
|
showTemplatesMenu.value = true;
|
|
};
|
|
|
|
const handleSendMessage = template => {
|
|
emit('sendMessage', template);
|
|
selectedTemplate.value = null;
|
|
};
|
|
</script>
|
|
|
|
<template>
|
|
<div class="relative">
|
|
<Button
|
|
icon="i-ri-whatsapp-line"
|
|
:label="t('COMPOSE_NEW_CONVERSATION.FORM.WHATSAPP_OPTIONS.LABEL')"
|
|
color="slate"
|
|
size="sm"
|
|
:disabled="selectedTemplate"
|
|
class="!text-xs font-medium"
|
|
@click="handleTriggerClick"
|
|
/>
|
|
<div
|
|
v-if="showTemplatesMenu"
|
|
class="absolute top-full mt-1.5 max-h-96 overflow-y-auto ltr:left-0 rtl:right-0 flex flex-col gap-2 p-4 items-center w-[21.875rem] h-auto bg-n-solid-2 border border-n-strong shadow-sm rounded-lg"
|
|
>
|
|
<div class="relative w-full">
|
|
<Icon
|
|
icon="i-lucide-search"
|
|
class="absolute size-3.5 top-2 ltr:left-3 rtl:right-3"
|
|
/>
|
|
<input
|
|
v-model="searchQuery"
|
|
type="search"
|
|
:placeholder="
|
|
t(
|
|
'COMPOSE_NEW_CONVERSATION.FORM.WHATSAPP_OPTIONS.SEARCH_PLACEHOLDER'
|
|
)
|
|
"
|
|
class="w-full h-8 py-2 ltr:pl-10 rtl:pr-10 ltr:pr-2 rtl:pl-2 text-sm reset-base outline-none border-none rounded-lg bg-n-alpha-black2 dark:bg-n-solid-1 text-n-slate-12"
|
|
/>
|
|
</div>
|
|
<div
|
|
v-for="template in filteredTemplates"
|
|
:key="template.id"
|
|
class="flex flex-col w-full gap-2 p-2 rounded-lg cursor-pointer dark:hover:bg-n-alpha-3 hover:bg-n-alpha-1"
|
|
@click="handleTemplateClick(template)"
|
|
>
|
|
<span class="text-sm text-n-slate-12">{{ template.name }}</span>
|
|
<p class="mb-0 text-xs leading-5 text-n-slate-11 line-clamp-2">
|
|
{{ getTemplateBody(template) }}
|
|
</p>
|
|
</div>
|
|
<template v-if="filteredTemplates.length === 0">
|
|
<p class="w-full pt-2 text-sm text-n-slate-11">
|
|
{{ t('COMPOSE_NEW_CONVERSATION.FORM.WHATSAPP_OPTIONS.EMPTY_STATE') }}
|
|
</p>
|
|
</template>
|
|
</div>
|
|
<WhatsappTemplateParser
|
|
v-if="selectedTemplate"
|
|
:template="selectedTemplate"
|
|
@send-message="handleSendMessage"
|
|
@back="handleBack"
|
|
/>
|
|
</div>
|
|
</template>
|