Merge branch 'develop' into feat/email-forwarding
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
// Taken from thoughtbot/bourbon library timing functions
|
||||
|
||||
:root {
|
||||
--ease-in-cubic: cubic-bezier(0.17, 0.67, 0.83, 0.67);
|
||||
--ease-in-sine: cubic-bezier(0.47, 0, 0.745, 0.715);
|
||||
|
||||
--ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);
|
||||
--ease-out-sine: cubic-bezier(0.39, 0.575, 0.565, 1);
|
||||
|
||||
--ease-in-out-quad: cubic-bezier(0.455, 0.03, 0.515, 0.955);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
:root {
|
||||
--border-radius-small: 0.1875rem;
|
||||
--border-radius-normal: 0.3125rem;
|
||||
--border-radius-medium: 0.4375rem;
|
||||
--border-radius-large: 0.5625rem;
|
||||
--border-radius-full: 6.25rem;
|
||||
--border-radius-rounded: 50%;
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
:root {
|
||||
--white: #fff;
|
||||
--white-transparent: rgba(255, 255, 255, 0.9);
|
||||
--black-transparent: rgba(0, 0, 0, 0.9);
|
||||
|
||||
--w-25: #F5FAFF;
|
||||
--w-50: #EBF5FF;
|
||||
--w-75: #D6EBFF;
|
||||
--w-100: #C2E1FF;
|
||||
--w-200: #99CEFF;
|
||||
--w-300: #70BAFF;
|
||||
--w-400: #47A6FF;
|
||||
--w-500: #1F93FF;
|
||||
--w-600: #1976CC;
|
||||
--w-700: #135899;
|
||||
--w-800: #0C3B66;
|
||||
--w-900: #061D33;
|
||||
|
||||
--g-50: #E6F8E6;
|
||||
--g-100: #C4EEC2;
|
||||
--g-200: #9DE29A;
|
||||
--g-300: #6FD86F;
|
||||
--g-400: #44CE4B;
|
||||
--g-500: #00C41D;
|
||||
--g-600: #00B412;
|
||||
--g-700: #00A200;
|
||||
--g-800: #009000;
|
||||
--g-900: #007000;
|
||||
|
||||
--y-50: #FEFDE8;
|
||||
--y-100: #FDFCC4;
|
||||
--y-200: #FCF68C;
|
||||
--y-300: #F9E736;
|
||||
--y-400: #F6D819;
|
||||
--y-500: #E6C00C;
|
||||
--y-600: #C69608;
|
||||
--y-700: #9E6b0A;
|
||||
--y-800: #835510;
|
||||
--y-900: #6F4514;
|
||||
|
||||
--s-25: #F8FAFC;
|
||||
--s-50: #F1F5F8;
|
||||
--s-75: #EBF0F5;
|
||||
--s-100: #E4EBF1;
|
||||
--s-200: #C9D7E3;
|
||||
--s-300: #AEC3D5;
|
||||
--s-400: #93AFC8;
|
||||
--s-500: #779BBB;
|
||||
--s-600: #446888;
|
||||
--s-700: #37546D;
|
||||
--s-800: #293F51;
|
||||
--s-900: #1B2836;
|
||||
|
||||
--b-50: #F7F7F7;
|
||||
--b-100: #ECECED;
|
||||
--b-200: #DDDDE0;
|
||||
--b-300: #C6C7CA;
|
||||
--b-400: #ABACAF;
|
||||
--b-500: #96979C;
|
||||
--b-600: #6E6F73;
|
||||
--b-700: #5A5B5F;
|
||||
--b-800: #3C3D40;
|
||||
--b-900: #1B1C1F;
|
||||
|
||||
--r-50: #FFEBEE;
|
||||
--r-100: #FFCCD1;
|
||||
--r-200: #F69898;
|
||||
--r-300: #EF6F6F;
|
||||
--r-400: #F94B4A;
|
||||
--r-500: #FF382D;
|
||||
--r-600: #F02B2D;
|
||||
--r-700: #DE1E27;
|
||||
--r-800: #D11320;
|
||||
--r-900: #C30011;
|
||||
|
||||
--v-50: #FFFFFF;
|
||||
--v-100: #F5EBFF;
|
||||
--v-200: #DDB8FF;
|
||||
--v-300: #C585FF;
|
||||
--v-400: #AC52FF;
|
||||
--v-500: #941FFF;
|
||||
--v-600: #7B00EB;
|
||||
--v-700: #6000B8;
|
||||
--v-800: #450085;
|
||||
--v-900: #2B0052;
|
||||
|
||||
// Common color aliases
|
||||
--color-woot: var(--w-500);
|
||||
|
||||
--color-heading: #1f2d3d;
|
||||
--color-body: #3c4858;
|
||||
|
||||
--color-border: var(--s-75);
|
||||
--color-border-light: var(--s-50);
|
||||
--color-border-dark: var(--s-100);
|
||||
|
||||
--color-background: var(--s-50);
|
||||
--color-background-light: var(--s-25);
|
||||
|
||||
// Social and inboxes brand colors
|
||||
--color-facebook-brand: #3b5998;
|
||||
--color-twitter-brand: #1da1f2;
|
||||
--color-whatsapp-brand: #25d366;
|
||||
--color-sms-twilio: #f42f46;
|
||||
--color-cloud-generic: #18b7b0;
|
||||
|
||||
// Tech-debt
|
||||
--color-medium-gray: #8492a6;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
:root {
|
||||
--font-size-nano: 0.5rem;
|
||||
--font-size-micro: 0.625rem;
|
||||
--font-size-mini: 0.75rem;
|
||||
--font-size-small: 0.875rem;
|
||||
--font-size-default: 1rem;
|
||||
--font-size-medium: 1.125rem;
|
||||
--font-size-two: 1.25rem;
|
||||
--font-size-large: 1.375rem;
|
||||
--font-size-big: 1.5rem;
|
||||
--font-size-bigger: 1.875rem;
|
||||
--font-size-mega: 2.125rem;
|
||||
--font-size-giga: 2.5rem;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
:root {
|
||||
--font-weight-feather: 100;
|
||||
--font-weight-light: 300;
|
||||
--font-weight-normal: 400;
|
||||
--font-weight-medium: 500;
|
||||
--font-weight-bold: 600;
|
||||
--font-weight-black: 700;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
:root {
|
||||
--shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1),
|
||||
0 1px 2px 0 rgba(0, 0, 0, 0.06);
|
||||
--shadow-small: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
||||
--shadow-medium: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
|
||||
0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
||||
--shadow-large: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
|
||||
0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
||||
--shadow-larger: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
|
||||
0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
||||
--shadow-dropdown-pane:
|
||||
0 0.5rem 1rem rgb(50 50 93 / 8%),
|
||||
0 0.25rem 0.75rem rgb(0 0 0 / 7%);
|
||||
--shadow-bulk-action-container:
|
||||
6px 3px 22px 9px rgb(181 181 181 / 25%);
|
||||
--shadow-context-menu: rgb(22 23 24 / 30%) 0px 10px 38px -10px,
|
||||
rgb(22 23 24 / 20%) 0px 10px 20px -15px;
|
||||
--shadow-widget-builder: 0 0px 20px 5px rgb(0 0 0 / 10%);
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
:root {
|
||||
// spaces
|
||||
--space-zero: 0;
|
||||
--space-micro: 0.125rem;
|
||||
--space-smaller: 0.25rem;
|
||||
--space-small: 0.5rem;
|
||||
--space-one: 0.625rem;
|
||||
--space-slab: 0.75rem;
|
||||
--space-snug: 0.875rem;
|
||||
--space-normal: 1rem;
|
||||
--space-two: 1.25rem;
|
||||
--space-medium: 1.5rem;
|
||||
--space-large: 2rem;
|
||||
--space-larger: 3rem;
|
||||
--space-jumbo: 4rem;
|
||||
--space-mega: 6.25rem;
|
||||
--space-giga: 15rem;
|
||||
|
||||
--space-minus-micro: -0.125rem;
|
||||
--space-minus-smaller: -0.25rem;
|
||||
--space-minus-half: -0.3125rem;
|
||||
--space-minus-small: -0.5rem;
|
||||
--space-minus-one: -0.625rem;
|
||||
--space-minus-slab: -0.75rem;
|
||||
--space-minus-snug: -0.875rem;
|
||||
--space-minus-normal: -1rem;
|
||||
--space-minus-two: -1.25rem;
|
||||
--space-minus-medium: -1.5rem;
|
||||
--space-minus-large: -2rem;
|
||||
--space-minus-larger: -3rem;
|
||||
--space-minus-jumbo: -4rem;
|
||||
--space-minus-mega: -6.25rem;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
:root {
|
||||
// z-index
|
||||
--z-index-minus: -1;
|
||||
--z-index-zero: 0;
|
||||
--z-index-one: 1;
|
||||
--z-index-low: 10;
|
||||
--z-index-twenty: 20;
|
||||
--z-index-normal: 100;
|
||||
--z-index-high: 1000;
|
||||
--z-index-higher: 2000;
|
||||
--z-index-much-higher: 5000;
|
||||
--z-index-very-high: 9999;
|
||||
--z-index-highest: 10000;
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
<template>
|
||||
<div class="p-4 space-y-6 bg-white dark:bg-slate-900">
|
||||
<div class="p-4 space-y-6 bg-n-background">
|
||||
<div class="space-y-2 animate-loader-pulse">
|
||||
<div class="h-6 bg-slate-100 dark:bg-slate-700 rounded w-1/5" />
|
||||
<div class="h-10 bg-slate-100 dark:bg-slate-700 rounded w-3/5" />
|
||||
<div class="h-6 bg-n-slate-4 dark:bg-n-slate-6 rounded w-1/5" />
|
||||
<div class="h-10 bg-n-slate-4 dark:bg-n-slate-6 rounded w-3/5" />
|
||||
</div>
|
||||
<div class="space-y-2 animate-loader-pulse">
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded" />
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded" />
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded" />
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded w-4/5" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded w-4/5" />
|
||||
</div>
|
||||
<div class="space-y-2 animate-loader-pulse">
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded" />
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded" />
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded w-3/5" />
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded w-3/5" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded" />
|
||||
</div>
|
||||
<div class="space-y-2 animate-loader-pulse">
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded" />
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded" />
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded" />
|
||||
<div class="h-5 bg-slate-100 dark:bg-slate-700 rounded w-3/5" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded" />
|
||||
<div class="h-5 bg-n-slate-4 dark:bg-n-slate-6 rounded w-3/5" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script>
|
||||
import globalConfigMixin from 'shared/mixins/globalConfigMixin';
|
||||
import { useBranding } from 'shared/composables/useBranding';
|
||||
|
||||
const {
|
||||
LOGO_THUMBNAIL: logoThumbnail,
|
||||
@@ -8,13 +8,18 @@ const {
|
||||
} = window.globalConfig || {};
|
||||
|
||||
export default {
|
||||
mixins: [globalConfigMixin],
|
||||
props: {
|
||||
disableBranding: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
setup() {
|
||||
const { replaceInstallationName } = useBranding();
|
||||
return {
|
||||
replaceInstallationName,
|
||||
};
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
globalConfig: {
|
||||
@@ -28,13 +33,15 @@ export default {
|
||||
brandRedirectURL() {
|
||||
try {
|
||||
const referrerHost = this.$store.getters['appConfig/getReferrerHost'];
|
||||
const baseURL = `${this.globalConfig.widgetBrandURL}?utm_source=${
|
||||
referrerHost ? 'widget_branding' : 'survey_branding'
|
||||
}`;
|
||||
const url = new URL(this.globalConfig.widgetBrandURL);
|
||||
if (referrerHost) {
|
||||
return `${baseURL}&utm_referrer=${referrerHost}`;
|
||||
url.searchParams.set('utm_source', referrerHost);
|
||||
url.searchParams.set('utm_medium', 'widget');
|
||||
} else {
|
||||
url.searchParams.set('utm_medium', 'survey');
|
||||
}
|
||||
return baseURL;
|
||||
url.searchParams.set('utm_campaign', 'branding');
|
||||
return url.toString();
|
||||
} catch (e) {
|
||||
// Suppressing the error as getter is not defined in some cases
|
||||
}
|
||||
@@ -61,7 +68,7 @@ export default {
|
||||
:src="globalConfig.logoThumbnail"
|
||||
/>
|
||||
<span>
|
||||
{{ useInstallationName($t('POWERED_BY'), globalConfig.brandName) }}
|
||||
{{ replaceInstallationName($t('POWERED_BY')) }}
|
||||
</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@@ -27,11 +27,11 @@ export default {
|
||||
let className =
|
||||
'text-white py-3 px-4 rounded-lg shadow-sm leading-4 cursor-pointer disabled:opacity-50';
|
||||
if (this.type === 'clear') {
|
||||
className = 'flex mx-auto mt-4 text-xs leading-3 w-auto text-black-600';
|
||||
className = 'flex mx-auto mt-4 text-xs leading-3 w-auto text-n-gray-12';
|
||||
}
|
||||
|
||||
if (this.type === 'blue' && !Object.keys(this.buttonStyles).length) {
|
||||
className = `${className} bg-woot-500 hover:bg-woot-700`;
|
||||
className = `${className} bg-n-brand hover:brightness-110`;
|
||||
}
|
||||
if (this.block) {
|
||||
className = `${className} w-full`;
|
||||
|
||||
@@ -1,64 +1,56 @@
|
||||
<script>
|
||||
<script setup>
|
||||
import { ref, useTemplateRef, computed, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import ArticleSkeletonLoader from 'shared/components/ArticleSkeletonLoader.vue';
|
||||
|
||||
export default {
|
||||
name: 'IframeLoader',
|
||||
components: {
|
||||
ArticleSkeletonLoader,
|
||||
const props = defineProps({
|
||||
url: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
props: {
|
||||
url: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
isRtl: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
isRtl: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
isLoading: true,
|
||||
showEmptyState: !this.url,
|
||||
};
|
||||
isDirApplied: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
watch: {
|
||||
isRtl: {
|
||||
immediate: true,
|
||||
handler(value) {
|
||||
this.$nextTick(() => {
|
||||
const iframeElement = this.$el.querySelector('iframe');
|
||||
if (iframeElement) {
|
||||
iframeElement.onload = () => {
|
||||
try {
|
||||
const iframeDocument =
|
||||
iframeElement.contentDocument ||
|
||||
(iframeElement.contentWindow &&
|
||||
iframeElement.contentWindow.document);
|
||||
});
|
||||
|
||||
if (iframeDocument) {
|
||||
iframeDocument.documentElement.dir = value ? 'rtl' : 'ltr';
|
||||
}
|
||||
} catch (e) {
|
||||
// error
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
handleIframeLoad() {
|
||||
// Once loaded, the loading state is hidden
|
||||
this.isLoading = false;
|
||||
},
|
||||
handleIframeError() {
|
||||
// Hide the loading state and show the empty state when an error occurs
|
||||
this.isLoading = false;
|
||||
this.showEmptyState = true;
|
||||
},
|
||||
},
|
||||
const { t } = useI18n();
|
||||
|
||||
const iframe = useTemplateRef('iframe');
|
||||
const isLoading = ref(true);
|
||||
const showEmptyState = ref(!props.url);
|
||||
|
||||
const direction = computed(() => (props.isRtl ? 'rtl' : 'ltr'));
|
||||
|
||||
const applyDirection = () => {
|
||||
if (!iframe.value) return;
|
||||
if (!props.isDirApplied) return; // If direction is already applied through props, do not apply again (iframe case)
|
||||
try {
|
||||
const doc =
|
||||
iframe.value.contentDocument || iframe.value.contentWindow?.document;
|
||||
if (doc?.documentElement) {
|
||||
doc.documentElement.dir = direction.value;
|
||||
doc.documentElement.setAttribute('data-dir-applied', 'true');
|
||||
}
|
||||
} catch (e) {
|
||||
// error
|
||||
}
|
||||
};
|
||||
|
||||
watch(() => props.isRtl, applyDirection);
|
||||
|
||||
const handleIframeLoad = () => {
|
||||
isLoading.value = false;
|
||||
applyDirection();
|
||||
};
|
||||
|
||||
const handleIframeError = () => {
|
||||
isLoading.value = false;
|
||||
showEmptyState.value = true;
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -66,6 +58,7 @@ export default {
|
||||
<div class="relative overflow-hidden pb-1/2 h-full">
|
||||
<iframe
|
||||
v-if="url"
|
||||
ref="iframe"
|
||||
:src="url"
|
||||
class="absolute w-full h-full top-0 left-0"
|
||||
@load="handleIframeLoad"
|
||||
@@ -79,7 +72,7 @@ export default {
|
||||
v-if="showEmptyState"
|
||||
class="absolute w-full h-full top-0 left-0 flex justify-center items-center"
|
||||
>
|
||||
<p>{{ $t('PORTAL.IFRAME_ERROR') }}</p>
|
||||
<p>{{ t('PORTAL.IFRAME_ERROR') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -69,7 +69,7 @@ export default {
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
value() {
|
||||
modelValue() {
|
||||
this.resizeTextarea();
|
||||
// 🚨 watch triggers every time the value is changed, we cannot set this to focus then
|
||||
// when this runs, it sets the cursor to the end of the body, ignoring the signature
|
||||
|
||||
@@ -13,15 +13,15 @@ export default {
|
||||
computed: {
|
||||
colorSchemeClasses() {
|
||||
if (this.colorScheme === 'primary') {
|
||||
return 'before:!border-t-woot-500';
|
||||
return 'before:!border-t-n-brand';
|
||||
}
|
||||
|
||||
if (this.colorScheme === 'warning') {
|
||||
return 'before:!border-t-yellow-500';
|
||||
return 'before:!border-t-n-amber-6';
|
||||
}
|
||||
|
||||
if (this.colorScheme === 'success') {
|
||||
return 'before:!border-t-success-500';
|
||||
return 'before:!border-t-n-teal-9';
|
||||
}
|
||||
|
||||
return this.colorScheme;
|
||||
|
||||
@@ -38,23 +38,22 @@ export default {
|
||||
v-if="label"
|
||||
class="mb-2 text-xs font-medium"
|
||||
:class="{
|
||||
'text-black-800': !error,
|
||||
'text-red-400': error,
|
||||
'text-n-gray-12': !error,
|
||||
'text-n-ruby-9': error,
|
||||
}"
|
||||
>
|
||||
{{ label }}
|
||||
</div>
|
||||
<textarea
|
||||
v-model="computedModel"
|
||||
class="w-full px-3 py-2 leading-tight border rounded outline-none resize-none text-slate-700"
|
||||
class="w-full px-3 py-2 leading-tight border rounded outline-none resize-none text-n-gray-12"
|
||||
:class="{
|
||||
'border-black-200 hover:border-black-300 focus:border-black-300':
|
||||
!error,
|
||||
'border-red-200 hover:border-red-300 focus:border-red-300': error,
|
||||
'border-n-weak hover:border-n-weak focus:border-n-weak': !error,
|
||||
'border-n-ruby-9 hover:border-n-ruby-9 focus:border-n-ruby-9': error,
|
||||
}"
|
||||
:placeholder="placeholder"
|
||||
/>
|
||||
<div v-if="error" class="mt-2 text-xs font-medium text-red-400">
|
||||
<div v-if="error" class="mt-2 text-xs font-medium text-n-ruby-9">
|
||||
{{ error }}
|
||||
</div>
|
||||
</label>
|
||||
|
||||
@@ -210,23 +210,10 @@ export default {
|
||||
</style>
|
||||
|
||||
<style lang="scss">
|
||||
@import 'dashboard/assets/scss/mixins';
|
||||
|
||||
.emoji-dialog {
|
||||
&::before {
|
||||
$space-slab: 12px;
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
$color-bg-dark: #26292b;
|
||||
@include arrow(bottom, $color-bg-dark, $space-slab);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
$color-bg: #ebf0f5;
|
||||
@include arrow(bottom, $color-bg, $space-slab);
|
||||
}
|
||||
|
||||
@apply -bottom-3 absolute right-5;
|
||||
@apply absolute -bottom-3 h-3 w-6 bg-n-slate-3 content-[""];
|
||||
clip-path: polygon(50% 100%, 0% 0%, 100% 0%);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { OnClickOutside } from '@vueuse/components';
|
||||
import { useToggle } from '@vueuse/core';
|
||||
|
||||
import Button from 'dashboard/components-next/button/Button.vue';
|
||||
import Thumbnail from 'dashboard/components/widgets/Thumbnail.vue';
|
||||
import Avatar from 'next/avatar/Avatar.vue';
|
||||
import MultiselectDropdownItems from 'shared/components/ui/MultiselectDropdownItems.vue';
|
||||
|
||||
const props = defineProps({
|
||||
@@ -82,17 +82,22 @@ const hasValue = computed(() => {
|
||||
{{ selectedItem.name }}
|
||||
</h4>
|
||||
</div>
|
||||
<Thumbnail
|
||||
<Avatar
|
||||
v-if="hasValue && hasThumbnail"
|
||||
:src="selectedItem.thumbnail"
|
||||
size="24px"
|
||||
:status="selectedItem.availability_status"
|
||||
:username="selectedItem.name"
|
||||
:name="selectedItem.name"
|
||||
:size="24"
|
||||
hide-offline-status
|
||||
rounded-full
|
||||
/>
|
||||
</Button>
|
||||
<div
|
||||
:class="{ 'dropdown-pane--open': showSearchDropdown }"
|
||||
class="dropdown-pane"
|
||||
:class="{
|
||||
'block visible': showSearchDropdown,
|
||||
'hidden invisible': !showSearchDropdown,
|
||||
}"
|
||||
class="box-border top-[2.625rem] w-full border rounded-lg bg-n-alpha-3 backdrop-blur-[100px] absolute shadow-lg border-n-strong dark:border-n-strong p-2 z-[9999]"
|
||||
>
|
||||
<div class="flex items-center justify-between mb-1">
|
||||
<h4
|
||||
@@ -115,9 +120,3 @@ const hasValue = computed(() => {
|
||||
</div>
|
||||
</OnClickOutside>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.dropdown-pane {
|
||||
@apply box-border top-[2.625rem] w-full;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<script>
|
||||
import WootDropdownItem from 'shared/components/ui/dropdown/DropdownItem.vue';
|
||||
import WootDropdownMenu from 'shared/components/ui/dropdown/DropdownMenu.vue';
|
||||
import Thumbnail from 'dashboard/components/widgets/Thumbnail.vue';
|
||||
import Avatar from 'next/avatar/Avatar.vue';
|
||||
import NextButton from 'dashboard/components-next/button/Button.vue';
|
||||
|
||||
export default {
|
||||
components: {
|
||||
WootDropdownItem,
|
||||
WootDropdownMenu,
|
||||
Thumbnail,
|
||||
Avatar,
|
||||
NextButton,
|
||||
},
|
||||
|
||||
@@ -105,13 +105,14 @@ export default {
|
||||
{{ option.name }}
|
||||
</span>
|
||||
</div>
|
||||
<Thumbnail
|
||||
<Avatar
|
||||
v-if="hasThumbnail"
|
||||
:src="option.thumbnail"
|
||||
size="24px"
|
||||
:username="option.name"
|
||||
:name="option.name"
|
||||
:status="option.availability_status"
|
||||
has-border
|
||||
:size="24"
|
||||
hide-offline-status
|
||||
rounded-full
|
||||
/>
|
||||
</NextButton>
|
||||
</WootDropdownItem>
|
||||
@@ -133,7 +134,7 @@ export default {
|
||||
}
|
||||
|
||||
.search-input {
|
||||
@apply m-0 w-full border border-solid border-transparent h-8 text-sm text-slate-700 dark:text-slate-100 rounded-md focus:border-woot-500 bg-slate-50 dark:bg-slate-900;
|
||||
@apply m-0 w-full border border-solid border-transparent h-8 text-sm text-n-slate-12 rounded-md focus:border-n-brand bg-n-background dark:bg-n-background;
|
||||
}
|
||||
|
||||
.multiselect-dropdown--item {
|
||||
@@ -144,7 +145,7 @@ export default {
|
||||
}
|
||||
|
||||
&:hover {
|
||||
@apply bg-n-slate-2 dark:bg-n-solid-3 text-slate-800 dark:text-slate-100;
|
||||
@apply bg-n-slate-2 dark:bg-n-solid-3 text-n-slate-12;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -4,7 +4,7 @@ export default {};
|
||||
|
||||
<template>
|
||||
<li
|
||||
class="list-none my-1 mx-0 border-b border-slate-50 dark:border-slate-700"
|
||||
class="list-none my-1 mx-0 border-b border-n-weak"
|
||||
:tabindex="null"
|
||||
:aria-disabled="true"
|
||||
/>
|
||||
|
||||
@@ -13,7 +13,7 @@ export default {
|
||||
<template>
|
||||
<li class="inline-flex list-none" :tabindex="null" :aria-disabled="true">
|
||||
<span
|
||||
class="text-xs text-slate-600 dark:text-slate-100 mt-1 font-medium w-full block text-left rtl:text-right whitespace-nowrap p-2"
|
||||
class="text-xs text-n-slate-12 mt-1 font-medium w-full block text-left rtl:text-right whitespace-nowrap p-2"
|
||||
>
|
||||
{{ title }}
|
||||
</span>
|
||||
|
||||
@@ -18,20 +18,10 @@ export default {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<li class="sub-menu-container">
|
||||
<ul class="sub-menu-li-container">
|
||||
<li class="!mt-0.5">
|
||||
<ul class="!m-0">
|
||||
<WootDropdownHeader v-if="title" :title="title" />
|
||||
<slot />
|
||||
</ul>
|
||||
</li>
|
||||
</template>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.sub-menu-container {
|
||||
margin-top: var(--space-micro);
|
||||
}
|
||||
|
||||
.sub-menu-li-container {
|
||||
margin: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -114,12 +114,12 @@ export default {
|
||||
<div class="flex flex-col w-full max-h-[12.5rem]">
|
||||
<div class="flex items-center justify-center mb-1">
|
||||
<h4
|
||||
class="flex-grow m-0 overflow-hidden text-sm text-slate-800 dark:text-slate-100 whitespace-nowrap text-ellipsis"
|
||||
class="flex-grow m-0 overflow-hidden text-sm text-n-slate-12 whitespace-nowrap text-ellipsis"
|
||||
>
|
||||
{{ $t('CONTACT_PANEL.LABELS.LABEL_SELECT.TITLE') }}
|
||||
</h4>
|
||||
<Hotkey
|
||||
custom-class="border border-solid text-slate-800 dark:text-slate-100 bg-slate-50 dark:bg-slate-600 text-xxs border-slate-75 dark:border-slate-600 flex-shrink-0"
|
||||
custom-class="border border-solid text-n-slate-12 bg-n-slate-2 text-xxs border-n-strong flex-shrink-0"
|
||||
>
|
||||
{{ 'L' }}
|
||||
</Hotkey>
|
||||
@@ -150,13 +150,13 @@ export default {
|
||||
</woot-dropdown-menu>
|
||||
<div
|
||||
v-if="noResult"
|
||||
class="flex justify-center py-4 px-2.5 font-medium text-xs text-slate-700 dark:text-slate-200"
|
||||
class="flex justify-center py-4 px-2.5 font-medium text-xs text-n-slate-11"
|
||||
>
|
||||
{{ $t('CONTACT_PANEL.LABELS.LABEL_SELECT.NO_RESULT') }}
|
||||
</div>
|
||||
<div
|
||||
v-if="allowCreation && shouldShowCreate"
|
||||
class="flex pt-1 border-t border-solid border-slate-100 dark:border-slate-900"
|
||||
class="flex pt-1 border-t border-solid border-n-weak"
|
||||
>
|
||||
<NextButton
|
||||
icon="i-lucide-plus"
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
import { useBranding } from '../useBranding';
|
||||
import { useMapGetter } from 'dashboard/composables/store.js';
|
||||
|
||||
// Mock the store composable
|
||||
vi.mock('dashboard/composables/store.js', () => ({
|
||||
useMapGetter: vi.fn(),
|
||||
}));
|
||||
|
||||
describe('useBranding', () => {
|
||||
let mockGlobalConfig;
|
||||
|
||||
beforeEach(() => {
|
||||
mockGlobalConfig = {
|
||||
value: {
|
||||
installationName: 'MyCompany',
|
||||
},
|
||||
};
|
||||
|
||||
useMapGetter.mockReturnValue(mockGlobalConfig);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('replaceInstallationName', () => {
|
||||
it('should replace "Chatwoot" with installation name when both text and installation name are provided', () => {
|
||||
const { replaceInstallationName } = useBranding();
|
||||
const result = replaceInstallationName('Welcome to Chatwoot');
|
||||
|
||||
expect(result).toBe('Welcome to MyCompany');
|
||||
});
|
||||
|
||||
it('should replace multiple occurrences of "Chatwoot"', () => {
|
||||
const { replaceInstallationName } = useBranding();
|
||||
const result = replaceInstallationName(
|
||||
'Chatwoot is great! Use Chatwoot today.'
|
||||
);
|
||||
|
||||
expect(result).toBe('MyCompany is great! Use MyCompany today.');
|
||||
});
|
||||
|
||||
it('should return original text when installation name is not provided', () => {
|
||||
mockGlobalConfig.value = {};
|
||||
|
||||
const { replaceInstallationName } = useBranding();
|
||||
const result = replaceInstallationName('Welcome to Chatwoot');
|
||||
|
||||
expect(result).toBe('Welcome to Chatwoot');
|
||||
});
|
||||
|
||||
it('should return original text when globalConfig is not available', () => {
|
||||
mockGlobalConfig.value = undefined;
|
||||
|
||||
const { replaceInstallationName } = useBranding();
|
||||
const result = replaceInstallationName('Welcome to Chatwoot');
|
||||
|
||||
expect(result).toBe('Welcome to Chatwoot');
|
||||
});
|
||||
|
||||
it('should return original text when text is empty or null', () => {
|
||||
const { replaceInstallationName } = useBranding();
|
||||
|
||||
expect(replaceInstallationName('')).toBe('');
|
||||
expect(replaceInstallationName(null)).toBe(null);
|
||||
expect(replaceInstallationName(undefined)).toBe(undefined);
|
||||
});
|
||||
|
||||
it('should handle text without "Chatwoot" gracefully', () => {
|
||||
const { replaceInstallationName } = useBranding();
|
||||
const result = replaceInstallationName('Welcome to our platform');
|
||||
|
||||
expect(result).toBe('Welcome to our platform');
|
||||
});
|
||||
|
||||
it('should be case-sensitive for "Chatwoot"', () => {
|
||||
const { replaceInstallationName } = useBranding();
|
||||
const result = replaceInstallationName(
|
||||
'Welcome to chatwoot and CHATWOOT'
|
||||
);
|
||||
|
||||
expect(result).toBe('Welcome to chatwoot and CHATWOOT');
|
||||
});
|
||||
|
||||
it('should handle special characters in installation name', () => {
|
||||
mockGlobalConfig.value = {
|
||||
installationName: 'My-Company & Co.',
|
||||
};
|
||||
|
||||
const { replaceInstallationName } = useBranding();
|
||||
const result = replaceInstallationName('Welcome to Chatwoot');
|
||||
|
||||
expect(result).toBe('Welcome to My-Company & Co.');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Composable for branding-related utilities
|
||||
* Provides methods to customize text with installation-specific branding
|
||||
*/
|
||||
import { useMapGetter } from 'dashboard/composables/store.js';
|
||||
|
||||
export function useBranding() {
|
||||
const globalConfig = useMapGetter('globalConfig/get');
|
||||
/**
|
||||
* Replaces "Chatwoot" in text with the installation name from global config
|
||||
* @param {string} text - The text to process
|
||||
* @returns {string} - Text with "Chatwoot" replaced by installation name
|
||||
*/
|
||||
const replaceInstallationName = text => {
|
||||
if (!text) return text;
|
||||
|
||||
const installationName = globalConfig.value?.installationName;
|
||||
if (!installationName) return text;
|
||||
|
||||
return text.replace(/Chatwoot/g, installationName);
|
||||
};
|
||||
|
||||
return {
|
||||
replaceInstallationName,
|
||||
};
|
||||
}
|
||||
@@ -5,7 +5,6 @@ export const BUS_EVENTS = {
|
||||
SCROLL_TO_MESSAGE: 'SCROLL_TO_MESSAGE',
|
||||
MESSAGE_SENT: 'MESSAGE_SENT',
|
||||
FETCH_LABEL_SUGGESTIONS: 'FETCH_LABEL_SUGGESTIONS',
|
||||
TOGGLE_SIDEMENU: 'TOGGLE_SIDEMENU',
|
||||
ON_MESSAGE_LIST_SCROLL: 'ON_MESSAGE_LIST_SCROLL',
|
||||
WEBSOCKET_DISCONNECT: 'WEBSOCKET_DISCONNECT',
|
||||
WEBSOCKET_RECONNECT: 'WEBSOCKET_RECONNECT',
|
||||
|
||||
@@ -36,7 +36,6 @@ export const CONVERSATION_PRIORITY_ORDER = {
|
||||
|
||||
// Size in mega bytes
|
||||
export const MAXIMUM_FILE_UPLOAD_SIZE = 40;
|
||||
export const MAXIMUM_FILE_UPLOAD_SIZE_TWILIO_SMS_CHANNEL = 5;
|
||||
|
||||
export const ALLOWED_FILE_TYPES =
|
||||
'image/*,' +
|
||||
@@ -50,18 +49,6 @@ export const ALLOWED_FILE_TYPES =
|
||||
'application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,' +
|
||||
'application/vnd.openxmlformats-officedocument.wordprocessingml.document,';
|
||||
|
||||
export const ALLOWED_FILE_TYPES_FOR_TWILIO_WHATSAPP =
|
||||
'image/png, image/jpeg,' +
|
||||
'audio/mpeg, audio/opus, audio/ogg, audio/amr,' +
|
||||
'video/mp4,' +
|
||||
'application/pdf,';
|
||||
// https://developers.line.biz/en/reference/messaging-api/#image-message, https://developers.line.biz/en/reference/messaging-api/#video-message
|
||||
export const ALLOWED_FILE_TYPES_FOR_LINE = 'image/png, image/jpeg,video/mp4';
|
||||
|
||||
// https://developers.facebook.com/docs/instagram-platform/instagram-api-with-instagram-login/messaging-api#requirements
|
||||
export const ALLOWED_FILE_TYPES_FOR_INSTAGRAM =
|
||||
'image/png, image/jpeg, video/mp4, video/mov, video/webm';
|
||||
|
||||
export const CSAT_RATINGS = [
|
||||
{
|
||||
key: 'disappointed',
|
||||
@@ -157,6 +144,14 @@ export const MESSAGE_VARIABLES = [
|
||||
label: 'Agent email',
|
||||
key: 'agent.email',
|
||||
},
|
||||
{
|
||||
key: 'inbox.name',
|
||||
label: 'Inbox name',
|
||||
},
|
||||
{
|
||||
label: 'Inbox id',
|
||||
key: 'inbox.id',
|
||||
},
|
||||
];
|
||||
|
||||
export const ATTACHMENT_ICONS = {
|
||||
@@ -167,3 +162,9 @@ export const ATTACHMENT_ICONS = {
|
||||
location: 'location',
|
||||
fallback: 'link',
|
||||
};
|
||||
|
||||
export const TWILIO_CONTENT_TEMPLATE_TYPES = {
|
||||
TEXT: 'text',
|
||||
MEDIA: 'media',
|
||||
QUICK_REPLY: 'quick_reply',
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import fromUnixTime from 'date-fns/fromUnixTime';
|
||||
import format from 'date-fns/format';
|
||||
import isToday from 'date-fns/isToday';
|
||||
import isYesterday from 'date-fns/isYesterday';
|
||||
import { endOfDay, getUnixTime, startOfDay, differenceInDays } from 'date-fns';
|
||||
import { endOfDay, getUnixTime, startOfDay } from 'date-fns';
|
||||
|
||||
export const formatUnixDate = (date, dateFormat = 'MMM dd, yyyy') => {
|
||||
const unixDate = fromUnixTime(date);
|
||||
@@ -16,10 +16,6 @@ export const formatDate = ({ date, todayText, yesterdayText }) => {
|
||||
return date;
|
||||
};
|
||||
|
||||
export const formatDigitToString = val => {
|
||||
return val > 9 ? `${val}` : `0${val}`;
|
||||
};
|
||||
|
||||
export const isTimeAfter = (h1, m1, h2, m2) => {
|
||||
if (h1 < h2) {
|
||||
return false;
|
||||
@@ -45,8 +41,3 @@ export const generateRelativeTime = (value, unit, languageCode) => {
|
||||
});
|
||||
return rtf.format(value, unit);
|
||||
};
|
||||
|
||||
export const getDayDifferenceFromNow = (now, timestampInSeconds) => {
|
||||
const date = new Date(timestampInSeconds * 1000);
|
||||
return differenceInDays(now, date);
|
||||
};
|
||||
|
||||
@@ -2,11 +2,16 @@
|
||||
* Writes a text string to the system clipboard.
|
||||
*
|
||||
* @async
|
||||
* @param {string} text text to be written to the clipboard
|
||||
* @param {string} data text to be written to the clipboard
|
||||
* @throws {Error} unable to copy text to clipboard
|
||||
*/
|
||||
export const copyTextToClipboard = async text => {
|
||||
export const copyTextToClipboard = async data => {
|
||||
try {
|
||||
const text =
|
||||
typeof data === 'object' && data !== null
|
||||
? JSON.stringify(data, null, 2)
|
||||
: String(data ?? '');
|
||||
|
||||
await navigator.clipboard.writeText(text);
|
||||
} catch (error) {
|
||||
throw new Error(`Unable to copy text to clipboard: ${error.message}`);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* Document Helper - utilities for document display and formatting
|
||||
*/
|
||||
|
||||
// Constants for document processing
|
||||
const PDF_PREFIX = 'PDF:';
|
||||
const TIMESTAMP_PATTERN = /_\d{14}(?=\.pdf$)/; // Format: _YYYYMMDDHHMMSS before .pdf extension
|
||||
|
||||
/**
|
||||
* Checks if a document is a PDF based on its external link
|
||||
* @param {string} externalLink - The external link string
|
||||
* @returns {boolean} True if the document is a PDF
|
||||
*/
|
||||
export const isPdfDocument = externalLink => {
|
||||
if (!externalLink) return false;
|
||||
return externalLink.startsWith(PDF_PREFIX);
|
||||
};
|
||||
|
||||
/**
|
||||
* Formats the display link for documents
|
||||
* For PDF documents: removes 'PDF:' prefix and timestamp suffix
|
||||
* For regular URLs: returns as-is
|
||||
*
|
||||
* @param {string} externalLink - The external link string
|
||||
* @returns {string} Formatted display link
|
||||
*/
|
||||
export const formatDocumentLink = externalLink => {
|
||||
if (!externalLink) return '';
|
||||
|
||||
if (isPdfDocument(externalLink)) {
|
||||
// Remove 'PDF:' prefix
|
||||
const fullName = externalLink.substring(PDF_PREFIX.length);
|
||||
// Remove timestamp suffix if present
|
||||
return fullName.replace(TIMESTAMP_PATTERN, '');
|
||||
}
|
||||
|
||||
return externalLink;
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* Determine the best-matching locale from the list of locales allowed by the portal.
|
||||
*
|
||||
* The matching happens in the following order:
|
||||
* 1. Exact match – the visitor-selected locale equals one in the `allowedLocales` list
|
||||
* (e.g., `fr` ➜ `fr`).
|
||||
* 2. Base language match – the base part of a compound locale (before the underscore)
|
||||
* matches (e.g., `fr_CA` ➜ `fr`).
|
||||
* 3. Variant match – when the base language is selected but a regional variant exists
|
||||
* in the portal list (e.g., `fr` ➜ `fr_BE`).
|
||||
*
|
||||
* If none of these rules find a match, the function returns `null`,
|
||||
* Don't show popular articles if locale doesn't match with allowed locales
|
||||
*
|
||||
* @export
|
||||
* @param {string} selectedLocale The locale selected by the visitor (e.g., `fr_CA`).
|
||||
* @param {string[]} allowedLocales Array of locales enabled for the portal.
|
||||
* @returns {(string|null)} A locale string that should be used, or `null` if no suitable match.
|
||||
*/
|
||||
export const getMatchingLocale = (selectedLocale = '', allowedLocales = []) => {
|
||||
// Ensure inputs are valid
|
||||
if (
|
||||
!selectedLocale ||
|
||||
!Array.isArray(allowedLocales) ||
|
||||
!allowedLocales.length
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const [lang] = selectedLocale.split('_');
|
||||
|
||||
const priorityMatches = [
|
||||
selectedLocale, // exact match
|
||||
lang, // base language match
|
||||
allowedLocales.find(l => l.startsWith(`${lang}_`)), // first variant match
|
||||
];
|
||||
|
||||
// Return the first match that exists in the allowed list, or null
|
||||
return priorityMatches.find(l => l && allowedLocales.includes(l)) ?? null;
|
||||
};
|
||||
@@ -1,10 +1,8 @@
|
||||
import {
|
||||
formatDate,
|
||||
formatUnixDate,
|
||||
formatDigitToString,
|
||||
isTimeAfter,
|
||||
generateRelativeTime,
|
||||
getDayDifferenceFromNow,
|
||||
} from '../DateHelper';
|
||||
|
||||
describe('#DateHelper', () => {
|
||||
@@ -47,14 +45,6 @@ describe('#DateHelper', () => {
|
||||
).toEqual('Yesterday');
|
||||
});
|
||||
});
|
||||
describe('#formatDigitToString', () => {
|
||||
it('returns date compatabile string from number is less than 9', () => {
|
||||
expect(formatDigitToString(8)).toEqual('08');
|
||||
});
|
||||
it('returns date compatabile string from number is greater than 9', () => {
|
||||
expect(formatDigitToString(11)).toEqual('11');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#isTimeAfter', () => {
|
||||
it('return correct values', () => {
|
||||
@@ -121,25 +111,3 @@ describe('generateRelativeTime', () => {
|
||||
expect(actualResult).toBe(expectedResult);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getDayDifferenceFromNow', () => {
|
||||
it('should return the difference if in same day', () => {
|
||||
const now = new Date('2023-12-08T00:00:00.000Z');
|
||||
const timestampInSeconds = 1702020305; // 08/12/2023, 12:55:05 (GMT+05:30)
|
||||
const expectedResult = 0;
|
||||
|
||||
const actualResult = getDayDifferenceFromNow(now, timestampInSeconds);
|
||||
|
||||
expect(actualResult).toBe(expectedResult);
|
||||
});
|
||||
|
||||
it('should return the difference if in different day', () => {
|
||||
const now = new Date('2023-12-11T00:00:00.000Z');
|
||||
const timestampInSeconds = 1702020305; // 08/12/2023, 12:55:05 (GMT+05:30)
|
||||
const expectedResult = 2;
|
||||
|
||||
const actualResult = getDayDifferenceFromNow(now, timestampInSeconds);
|
||||
|
||||
expect(actualResult).toBe(expectedResult);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
import { copyTextToClipboard } from '../clipboard';
|
||||
|
||||
const mockWriteText = vi.fn();
|
||||
Object.assign(navigator, {
|
||||
clipboard: {
|
||||
writeText: mockWriteText,
|
||||
},
|
||||
});
|
||||
|
||||
describe('copyTextToClipboard', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('with string input', () => {
|
||||
it('copies plain text string to clipboard', async () => {
|
||||
const text = 'Hello World';
|
||||
await copyTextToClipboard(text);
|
||||
|
||||
expect(mockWriteText).toHaveBeenCalledWith('Hello World');
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('copies empty string to clipboard', async () => {
|
||||
const text = '';
|
||||
await copyTextToClipboard(text);
|
||||
|
||||
expect(mockWriteText).toHaveBeenCalledWith('');
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with number input', () => {
|
||||
it('converts number to string', async () => {
|
||||
await copyTextToClipboard(42);
|
||||
|
||||
expect(mockWriteText).toHaveBeenCalledWith('42');
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('converts zero to string', async () => {
|
||||
await copyTextToClipboard(0);
|
||||
|
||||
expect(mockWriteText).toHaveBeenCalledWith('0');
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with boolean input', () => {
|
||||
it('converts true to string', async () => {
|
||||
await copyTextToClipboard(true);
|
||||
|
||||
expect(mockWriteText).toHaveBeenCalledWith('true');
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('converts false to string', async () => {
|
||||
await copyTextToClipboard(false);
|
||||
|
||||
expect(mockWriteText).toHaveBeenCalledWith('false');
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with null/undefined input', () => {
|
||||
it('converts null to empty string', async () => {
|
||||
await copyTextToClipboard(null);
|
||||
|
||||
expect(mockWriteText).toHaveBeenCalledWith('');
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('converts undefined to empty string', async () => {
|
||||
await copyTextToClipboard(undefined);
|
||||
|
||||
expect(mockWriteText).toHaveBeenCalledWith('');
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with object input', () => {
|
||||
it('stringifies simple object with proper formatting', async () => {
|
||||
const obj = { name: 'John', age: 30 };
|
||||
await copyTextToClipboard(obj);
|
||||
|
||||
const expectedJson = JSON.stringify(obj, null, 2);
|
||||
expect(mockWriteText).toHaveBeenCalledWith(expectedJson);
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('stringifies nested object with proper formatting', async () => {
|
||||
const nestedObj = {
|
||||
severity: {
|
||||
user_id: 1181505,
|
||||
user_name: 'test',
|
||||
server_name: '[1253]test1253',
|
||||
},
|
||||
};
|
||||
await copyTextToClipboard(nestedObj);
|
||||
|
||||
const expectedJson = JSON.stringify(nestedObj, null, 2);
|
||||
expect(mockWriteText).toHaveBeenCalledWith(expectedJson);
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('stringifies array with proper formatting', async () => {
|
||||
const arr = [1, 2, { name: 'test' }];
|
||||
await copyTextToClipboard(arr);
|
||||
|
||||
const expectedJson = JSON.stringify(arr, null, 2);
|
||||
expect(mockWriteText).toHaveBeenCalledWith(expectedJson);
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('stringifies empty object', async () => {
|
||||
const obj = {};
|
||||
await copyTextToClipboard(obj);
|
||||
|
||||
expect(mockWriteText).toHaveBeenCalledWith('{}');
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('stringifies empty array', async () => {
|
||||
const arr = [];
|
||||
await copyTextToClipboard(arr);
|
||||
|
||||
expect(mockWriteText).toHaveBeenCalledWith('[]');
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('error handling', () => {
|
||||
it('throws error when clipboard API fails', async () => {
|
||||
const error = new Error('Clipboard access denied');
|
||||
mockWriteText.mockRejectedValueOnce(error);
|
||||
|
||||
await expect(copyTextToClipboard('test')).rejects.toThrow(
|
||||
'Unable to copy text to clipboard: Clipboard access denied'
|
||||
);
|
||||
});
|
||||
|
||||
it('handles clipboard API not available', async () => {
|
||||
// Temporarily remove clipboard API
|
||||
const originalClipboard = navigator.clipboard;
|
||||
delete navigator.clipboard;
|
||||
|
||||
await expect(copyTextToClipboard('test')).rejects.toThrow(
|
||||
'Unable to copy text to clipboard:'
|
||||
);
|
||||
|
||||
// Restore clipboard API
|
||||
navigator.clipboard = originalClipboard;
|
||||
});
|
||||
});
|
||||
|
||||
describe('edge cases', () => {
|
||||
it('handles Date objects', async () => {
|
||||
const date = new Date('2023-01-01T00:00:00.000Z');
|
||||
await copyTextToClipboard(date);
|
||||
|
||||
const expectedJson = JSON.stringify(date, null, 2);
|
||||
expect(mockWriteText).toHaveBeenCalledWith(expectedJson);
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('handles functions by converting to string', async () => {
|
||||
const func = () => 'test';
|
||||
await copyTextToClipboard(func);
|
||||
|
||||
expect(mockWriteText).toHaveBeenCalledWith(func.toString());
|
||||
expect(mockWriteText).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,111 @@
|
||||
import {
|
||||
isPdfDocument,
|
||||
formatDocumentLink,
|
||||
} from 'shared/helpers/documentHelper';
|
||||
|
||||
describe('documentHelper', () => {
|
||||
describe('#isPdfDocument', () => {
|
||||
it('returns true for PDF documents', () => {
|
||||
expect(isPdfDocument('PDF:document.pdf')).toBe(true);
|
||||
expect(isPdfDocument('PDF:my-file_20241227123045.pdf')).toBe(true);
|
||||
expect(isPdfDocument('PDF:report with spaces_20241227123045.pdf')).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it('returns false for regular URLs', () => {
|
||||
expect(isPdfDocument('https://example.com')).toBe(false);
|
||||
expect(isPdfDocument('http://docs.example.com/file.pdf')).toBe(false);
|
||||
expect(isPdfDocument('ftp://files.example.com/document.pdf')).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for empty or null values', () => {
|
||||
expect(isPdfDocument('')).toBe(false);
|
||||
expect(isPdfDocument(null)).toBe(false);
|
||||
expect(isPdfDocument(undefined)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for strings that contain PDF but do not start with PDF:', () => {
|
||||
expect(isPdfDocument('document PDF:file.pdf')).toBe(false);
|
||||
expect(isPdfDocument('My PDF:file.pdf')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#formatDocumentLink', () => {
|
||||
describe('PDF documents', () => {
|
||||
it('removes PDF: prefix from PDF documents', () => {
|
||||
expect(formatDocumentLink('PDF:document.pdf')).toBe('document.pdf');
|
||||
expect(formatDocumentLink('PDF:my-file.pdf')).toBe('my-file.pdf');
|
||||
});
|
||||
|
||||
it('removes timestamp suffix from PDF documents', () => {
|
||||
expect(formatDocumentLink('PDF:document_20241227123045.pdf')).toBe(
|
||||
'document.pdf'
|
||||
);
|
||||
expect(formatDocumentLink('PDF:report_20231215094530.pdf')).toBe(
|
||||
'report.pdf'
|
||||
);
|
||||
});
|
||||
|
||||
it('handles PDF documents with spaces in filename', () => {
|
||||
expect(formatDocumentLink('PDF:my document_20241227123045.pdf')).toBe(
|
||||
'my document.pdf'
|
||||
);
|
||||
expect(
|
||||
formatDocumentLink('PDF:Annual Report 2024_20241227123045.pdf')
|
||||
).toBe('Annual Report 2024.pdf');
|
||||
});
|
||||
|
||||
it('handles PDF documents without timestamp suffix', () => {
|
||||
expect(formatDocumentLink('PDF:document.pdf')).toBe('document.pdf');
|
||||
expect(formatDocumentLink('PDF:simple-file.pdf')).toBe(
|
||||
'simple-file.pdf'
|
||||
);
|
||||
});
|
||||
|
||||
it('handles PDF documents with partial timestamp patterns', () => {
|
||||
expect(formatDocumentLink('PDF:document_202412.pdf')).toBe(
|
||||
'document_202412.pdf'
|
||||
);
|
||||
expect(formatDocumentLink('PDF:file_123.pdf')).toBe('file_123.pdf');
|
||||
});
|
||||
|
||||
it('handles edge cases with timestamp pattern', () => {
|
||||
expect(
|
||||
formatDocumentLink('PDF:doc_20241227123045_final_20241227123045.pdf')
|
||||
).toBe('doc_20241227123045_final.pdf');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Regular URLs', () => {
|
||||
it('returns regular URLs unchanged', () => {
|
||||
expect(formatDocumentLink('https://example.com')).toBe(
|
||||
'https://example.com'
|
||||
);
|
||||
expect(formatDocumentLink('http://docs.example.com/api')).toBe(
|
||||
'http://docs.example.com/api'
|
||||
);
|
||||
expect(formatDocumentLink('https://github.com/user/repo')).toBe(
|
||||
'https://github.com/user/repo'
|
||||
);
|
||||
});
|
||||
|
||||
it('handles URLs with query parameters', () => {
|
||||
expect(formatDocumentLink('https://example.com?param=value')).toBe(
|
||||
'https://example.com?param=value'
|
||||
);
|
||||
expect(
|
||||
formatDocumentLink(
|
||||
'https://api.example.com/docs?version=v1&format=json'
|
||||
)
|
||||
).toBe('https://api.example.com/docs?version=v1&format=json');
|
||||
});
|
||||
|
||||
it('handles URLs with fragments', () => {
|
||||
expect(formatDocumentLink('https://example.com/docs#section1')).toBe(
|
||||
'https://example.com/docs#section1'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { getMatchingLocale } from 'shared/helpers/portalHelper';
|
||||
|
||||
describe('portalHelper - getMatchingLocale', () => {
|
||||
it('returns exact match when present', () => {
|
||||
const result = getMatchingLocale('fr', ['en', 'fr']);
|
||||
expect(result).toBe('fr');
|
||||
});
|
||||
|
||||
it('returns base language match when exact variant not present', () => {
|
||||
const result = getMatchingLocale('fr_CA', ['en', 'fr']);
|
||||
expect(result).toBe('fr');
|
||||
});
|
||||
|
||||
it('returns variant match when base language not present', () => {
|
||||
const result = getMatchingLocale('fr', ['en', 'fr_BE']);
|
||||
expect(result).toBe('fr_BE');
|
||||
});
|
||||
|
||||
it('returns null when no match found', () => {
|
||||
const result = getMatchingLocale('de', ['en', 'fr']);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for invalid inputs', () => {
|
||||
expect(getMatchingLocale('', [])).toBeNull();
|
||||
expect(getMatchingLocale(null, null)).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -4,6 +4,8 @@ import {
|
||||
dynamicTime,
|
||||
dateFormat,
|
||||
shortTimestamp,
|
||||
getDayDifferenceFromNow,
|
||||
hasOneDayPassed,
|
||||
} from 'shared/helpers/timeHelper';
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -90,3 +92,148 @@ describe('#shortTimestamp', () => {
|
||||
expect(shortTimestamp('4 years ago', true)).toEqual('4y ago');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getDayDifferenceFromNow', () => {
|
||||
it('returns 0 for timestamps from today', () => {
|
||||
// Mock current date: May 5, 2023
|
||||
const now = new Date(Date.UTC(2023, 4, 5, 12, 0, 0)); // 12:00 PM
|
||||
const todayTimestamp = Math.floor(now.getTime() / 1000); // Same day
|
||||
|
||||
expect(getDayDifferenceFromNow(now, todayTimestamp)).toEqual(0);
|
||||
});
|
||||
|
||||
it('returns 2 for timestamps from 2 days ago', () => {
|
||||
const now = new Date(Date.UTC(2023, 4, 5, 12, 0, 0)); // May 5, 2023
|
||||
const twoDaysAgoTimestamp = Math.floor(
|
||||
new Date(Date.UTC(2023, 4, 3, 10, 0, 0)).getTime() / 1000
|
||||
); // May 3, 2023
|
||||
|
||||
expect(getDayDifferenceFromNow(now, twoDaysAgoTimestamp)).toEqual(2);
|
||||
});
|
||||
|
||||
it('returns 7 for timestamps from a week ago', () => {
|
||||
const now = new Date(Date.UTC(2023, 4, 5, 12, 0, 0)); // May 5, 2023
|
||||
const weekAgoTimestamp = Math.floor(
|
||||
new Date(Date.UTC(2023, 3, 28, 8, 0, 0)).getTime() / 1000
|
||||
); // April 28, 2023
|
||||
|
||||
expect(getDayDifferenceFromNow(now, weekAgoTimestamp)).toEqual(7);
|
||||
});
|
||||
|
||||
it('returns 30 for timestamps from a month ago', () => {
|
||||
const now = new Date(Date.UTC(2023, 4, 5, 12, 0, 0)); // May 5, 2023
|
||||
const monthAgoTimestamp = Math.floor(
|
||||
new Date(Date.UTC(2023, 3, 5, 12, 0, 0)).getTime() / 1000
|
||||
); // April 5, 2023
|
||||
|
||||
expect(getDayDifferenceFromNow(now, monthAgoTimestamp)).toEqual(30);
|
||||
});
|
||||
|
||||
it('handles edge case with different times on same day', () => {
|
||||
const now = new Date(Date.UTC(2023, 4, 5, 23, 59, 59)); // May 5, 2023 11:59:59 PM
|
||||
const morningTimestamp = Math.floor(
|
||||
new Date(Date.UTC(2023, 4, 5, 0, 0, 1)).getTime() / 1000
|
||||
); // May 5, 2023 12:00:01 AM
|
||||
|
||||
expect(getDayDifferenceFromNow(now, morningTimestamp)).toEqual(0);
|
||||
});
|
||||
|
||||
it('handles cross-month boundaries correctly', () => {
|
||||
const now = new Date(Date.UTC(2023, 4, 1, 12, 0, 0)); // May 1, 2023
|
||||
const lastMonthTimestamp = Math.floor(
|
||||
new Date(Date.UTC(2023, 3, 30, 12, 0, 0)).getTime() / 1000
|
||||
); // April 30, 2023
|
||||
|
||||
expect(getDayDifferenceFromNow(now, lastMonthTimestamp)).toEqual(1);
|
||||
});
|
||||
|
||||
it('handles cross-year boundaries correctly', () => {
|
||||
const now = new Date(Date.UTC(2023, 0, 2, 12, 0, 0)); // January 2, 2023
|
||||
const lastYearTimestamp = Math.floor(
|
||||
new Date(Date.UTC(2022, 11, 31, 12, 0, 0)).getTime() / 1000
|
||||
); // December 31, 2022
|
||||
|
||||
expect(getDayDifferenceFromNow(now, lastYearTimestamp)).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#hasOneDayPassed', () => {
|
||||
beforeEach(() => {
|
||||
// Mock current date: May 5, 2023, 12:00 PM UTC (1683288000)
|
||||
const mockDate = new Date(1683288000 * 1000);
|
||||
vi.setSystemTime(mockDate);
|
||||
});
|
||||
|
||||
it('returns false for timestamps from today', () => {
|
||||
// Same day, different time - May 5, 2023 8:00 AM UTC
|
||||
const todayTimestamp = 1683273600;
|
||||
|
||||
expect(hasOneDayPassed(todayTimestamp)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for timestamps from yesterday (less than 24 hours)', () => {
|
||||
// Yesterday but less than 24 hours ago - May 4, 2023 6:00 PM UTC (18 hours ago)
|
||||
const yesterdayTimestamp = 1683230400;
|
||||
|
||||
expect(hasOneDayPassed(yesterdayTimestamp)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true for timestamps from exactly 1 day ago', () => {
|
||||
// Exactly 24 hours ago - May 4, 2023 12:00 PM UTC
|
||||
const oneDayAgoTimestamp = 1683201600;
|
||||
|
||||
expect(hasOneDayPassed(oneDayAgoTimestamp)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for timestamps from more than 1 day ago', () => {
|
||||
// 2 days ago - May 3, 2023 10:00 AM UTC
|
||||
const twoDaysAgoTimestamp = 1683108000;
|
||||
|
||||
expect(hasOneDayPassed(twoDaysAgoTimestamp)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for timestamps from a week ago', () => {
|
||||
// 7 days ago - April 28, 2023 8:00 AM UTC
|
||||
const weekAgoTimestamp = 1682668800;
|
||||
|
||||
expect(hasOneDayPassed(weekAgoTimestamp)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for null timestamp (defensive check)', () => {
|
||||
expect(hasOneDayPassed(null)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for undefined timestamp (defensive check)', () => {
|
||||
expect(hasOneDayPassed(undefined)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for zero timestamp (defensive check)', () => {
|
||||
expect(hasOneDayPassed(0)).toBe(true);
|
||||
});
|
||||
|
||||
it('returns true for empty string timestamp (defensive check)', () => {
|
||||
expect(hasOneDayPassed('')).toBe(true);
|
||||
});
|
||||
|
||||
it('handles cross-month boundaries correctly', () => {
|
||||
// Set current time to May 1, 2023 12:00 PM UTC (1682942400)
|
||||
const mayFirst = new Date(1682942400 * 1000);
|
||||
vi.setSystemTime(mayFirst);
|
||||
|
||||
// April 29, 2023 12:00 PM UTC (1682769600) - 2 days ago, crossing month boundary
|
||||
const crossMonthTimestamp = 1682769600;
|
||||
|
||||
expect(hasOneDayPassed(crossMonthTimestamp)).toBe(true);
|
||||
});
|
||||
|
||||
it('handles cross-year boundaries correctly', () => {
|
||||
// Set current time to January 2, 2023 12:00 PM UTC (1672660800)
|
||||
const newYear = new Date(1672660800 * 1000);
|
||||
vi.setSystemTime(newYear);
|
||||
|
||||
// December 30, 2022 12:00 PM UTC (1672401600) - 3 days ago, crossing year boundary
|
||||
const crossYearTimestamp = 1672401600;
|
||||
|
||||
expect(hasOneDayPassed(crossYearTimestamp)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
isSameYear,
|
||||
fromUnixTime,
|
||||
formatDistanceToNow,
|
||||
differenceInDays,
|
||||
} from 'date-fns';
|
||||
|
||||
/**
|
||||
@@ -91,3 +92,25 @@ export const shortTimestamp = (time, withAgo = false) => {
|
||||
.replace(' years ago', `y${suffix}`);
|
||||
return convertToShortTime;
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculates the difference in days between now and a given timestamp.
|
||||
* @param {Date} now - Current date/time.
|
||||
* @param {number} timestampInSeconds - Unix timestamp in seconds.
|
||||
* @returns {number} Number of days difference.
|
||||
*/
|
||||
export const getDayDifferenceFromNow = (now, timestampInSeconds) => {
|
||||
const date = new Date(timestampInSeconds * 1000);
|
||||
return differenceInDays(now, date);
|
||||
};
|
||||
|
||||
/**
|
||||
* Checks if more than 24 hours have passed since a given timestamp.
|
||||
* Useful for determining if retry/refresh actions should be disabled.
|
||||
* @param {number} timestamp - Unix timestamp.
|
||||
* @returns {boolean} True if more than 24 hours have passed.
|
||||
*/
|
||||
export const hasOneDayPassed = timestamp => {
|
||||
if (!timestamp) return true; // Defensive check
|
||||
return getDayDifferenceFromNow(new Date(), timestamp) >= 1;
|
||||
};
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
export const useInstallationName = (str, installationName) => {
|
||||
if (str && installationName) {
|
||||
return str.replace(/Chatwoot/g, installationName);
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
export default {
|
||||
methods: {
|
||||
useInstallationName,
|
||||
},
|
||||
};
|
||||
@@ -57,6 +57,9 @@ export default {
|
||||
isALineChannel() {
|
||||
return this.channelType === INBOX_TYPES.LINE;
|
||||
},
|
||||
isAVoiceChannel() {
|
||||
return this.channelType === INBOX_TYPES.VOICE;
|
||||
},
|
||||
isAnEmailChannel() {
|
||||
return this.channelType === INBOX_TYPES.EMAIL;
|
||||
},
|
||||
|
||||
@@ -1,263 +0,0 @@
|
||||
export const templates = [
|
||||
{
|
||||
name: 'sample_flight_confirmation',
|
||||
status: 'approved',
|
||||
category: 'TICKET_UPDATE',
|
||||
language: 'pt_BR',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{ type: 'HEADER', format: 'DOCUMENT' },
|
||||
{
|
||||
text: 'Esta é a sua confirmação de voo para {{1}}-{{2}} em {{3}}.',
|
||||
type: 'BODY',
|
||||
},
|
||||
{
|
||||
text: 'Esta mensagem é de uma empresa não verificada.',
|
||||
type: 'FOOTER',
|
||||
},
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'sample_issue_resolution',
|
||||
status: 'approved',
|
||||
category: 'ISSUE_RESOLUTION',
|
||||
language: 'pt_BR',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{
|
||||
text: 'Oi, {{1}}. Nós conseguimos resolver o problema que você estava enfrentando?',
|
||||
type: 'BODY',
|
||||
},
|
||||
{
|
||||
text: 'Esta mensagem é de uma empresa não verificada.',
|
||||
type: 'FOOTER',
|
||||
},
|
||||
{
|
||||
type: 'BUTTONS',
|
||||
buttons: [
|
||||
{ text: 'Sim', type: 'QUICK_REPLY' },
|
||||
{ text: 'Não', type: 'QUICK_REPLY' },
|
||||
],
|
||||
},
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'sample_issue_resolution',
|
||||
status: 'approved',
|
||||
category: 'ISSUE_RESOLUTION',
|
||||
language: 'es',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{
|
||||
text: 'Hola, {{1}}. ¿Pudiste solucionar el problema que tenías?',
|
||||
type: 'BODY',
|
||||
},
|
||||
{
|
||||
text: 'Este mensaje proviene de un negocio no verificado.',
|
||||
type: 'FOOTER',
|
||||
},
|
||||
{
|
||||
type: 'BUTTONS',
|
||||
buttons: [
|
||||
{ text: 'Sí', type: 'QUICK_REPLY' },
|
||||
{ text: 'No', type: 'QUICK_REPLY' },
|
||||
],
|
||||
},
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'sample_issue_resolution',
|
||||
status: 'approved',
|
||||
category: 'ISSUE_RESOLUTION',
|
||||
language: 'id',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{
|
||||
text: 'Halo {{1}}, apakah kami bisa mengatasi masalah yang sedang Anda hadapi?',
|
||||
type: 'BODY',
|
||||
},
|
||||
{
|
||||
text: 'Pesan ini berasal dari bisnis yang tidak terverifikasi.',
|
||||
type: 'FOOTER',
|
||||
},
|
||||
{
|
||||
type: 'BUTTONS',
|
||||
buttons: [
|
||||
{ text: 'Ya', type: 'QUICK_REPLY' },
|
||||
{ text: 'Tidak', type: 'QUICK_REPLY' },
|
||||
],
|
||||
},
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'sample_shipping_confirmation',
|
||||
status: 'approved',
|
||||
category: 'SHIPPING_UPDATE',
|
||||
language: 'pt_BR',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{
|
||||
text: 'Seu pacote foi enviado. Ele será entregue em {{1}} dias úteis.',
|
||||
type: 'BODY',
|
||||
},
|
||||
{
|
||||
text: 'Esta mensagem é de uma empresa não verificada.',
|
||||
type: 'FOOTER',
|
||||
},
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'sample_shipping_confirmation',
|
||||
status: 'approved',
|
||||
category: 'SHIPPING_UPDATE',
|
||||
language: 'id',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{
|
||||
text: 'Paket Anda sudah dikirim. Paket akan sampai dalam {{1}} hari kerja.',
|
||||
type: 'BODY',
|
||||
},
|
||||
{
|
||||
text: 'Pesan ini berasal dari bisnis yang tidak terverifikasi.',
|
||||
type: 'FOOTER',
|
||||
},
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'sample_shipping_confirmation',
|
||||
status: 'approved',
|
||||
category: 'SHIPPING_UPDATE',
|
||||
language: 'es',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{
|
||||
text: 'ó tu paquete. La entrega se realizará en {{1}} dí.',
|
||||
type: 'BODY',
|
||||
},
|
||||
{
|
||||
text: 'Este mensaje proviene de un negocio no verificado.',
|
||||
type: 'FOOTER',
|
||||
},
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'sample_flight_confirmation',
|
||||
status: 'approved',
|
||||
category: 'TICKET_UPDATE',
|
||||
language: 'id',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{ type: 'HEADER', format: 'DOCUMENT' },
|
||||
{
|
||||
text: 'Ini merupakan konfirmasi penerbangan Anda untuk {{1}}-{{2}} di {{3}}.',
|
||||
type: 'BODY',
|
||||
},
|
||||
{
|
||||
text: 'Pesan ini berasal dari bisnis yang tidak terverifikasi.',
|
||||
type: 'FOOTER',
|
||||
},
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'sample_issue_resolution',
|
||||
status: 'approved',
|
||||
category: 'ISSUE_RESOLUTION',
|
||||
language: 'en_US',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{
|
||||
text: 'Hi {{1}}, were we able to solve the issue that you were facing?',
|
||||
type: 'BODY',
|
||||
},
|
||||
{ text: 'This message is from an unverified business.', type: 'FOOTER' },
|
||||
{
|
||||
type: 'BUTTONS',
|
||||
buttons: [
|
||||
{ text: 'Yes', type: 'QUICK_REPLY' },
|
||||
{ text: 'No', type: 'QUICK_REPLY' },
|
||||
],
|
||||
},
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'sample_flight_confirmation',
|
||||
status: 'approved',
|
||||
category: 'TICKET_UPDATE',
|
||||
language: 'es',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{ type: 'HEADER', format: 'DOCUMENT' },
|
||||
{
|
||||
text: 'Confirmamos tu vuelo a {{1}}-{{2}} para el {{3}}.',
|
||||
type: 'BODY',
|
||||
},
|
||||
{
|
||||
text: 'Este mensaje proviene de un negocio no verificado.',
|
||||
type: 'FOOTER',
|
||||
},
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'sample_flight_confirmation',
|
||||
status: 'approved',
|
||||
category: 'TICKET_UPDATE',
|
||||
language: 'en_US',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{ type: 'HEADER', format: 'DOCUMENT' },
|
||||
{
|
||||
text: 'This is your flight confirmation for {{1}}-{{2}} on {{3}}.',
|
||||
type: 'BODY',
|
||||
},
|
||||
{ text: 'This message is from an unverified business.', type: 'FOOTER' },
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'sample_shipping_confirmation',
|
||||
status: 'approved',
|
||||
category: 'SHIPPING_UPDATE',
|
||||
language: 'en_US',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{
|
||||
text: 'Your package has been shipped. It will be delivered in {{1}} business days.',
|
||||
type: 'BODY',
|
||||
},
|
||||
{ text: 'This message is from an unverified business.', type: 'FOOTER' },
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
{
|
||||
name: 'no_variable_template',
|
||||
status: 'approved',
|
||||
category: 'TICKET_UPDATE',
|
||||
language: 'pt_BR',
|
||||
namespace: 'ed41a221_133a_4558_a1d6_192960e3aee9',
|
||||
components: [
|
||||
{
|
||||
type: 'HEADER',
|
||||
format: 'DOCUMENT',
|
||||
},
|
||||
{
|
||||
text: 'This is a test whatsapp template',
|
||||
type: 'BODY',
|
||||
},
|
||||
{
|
||||
text: 'Esta mensagem é de uma empresa não verificada.',
|
||||
type: 'FOOTER',
|
||||
},
|
||||
],
|
||||
rejected_reason: 'NONE',
|
||||
},
|
||||
];
|
||||
@@ -1,61 +0,0 @@
|
||||
import { shallowMount } from '@vue/test-utils';
|
||||
import TemplateParser from '../../../../dashboard/components/widgets/conversation/WhatsappTemplates/TemplateParser.vue';
|
||||
import { templates } from './fixtures';
|
||||
import { nextTick } from 'vue';
|
||||
|
||||
const config = {
|
||||
global: {
|
||||
stubs: {
|
||||
NextButton: { template: '<button />' },
|
||||
WootInput: { template: '<input />' },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
describe('#WhatsAppTemplates', () => {
|
||||
it('returns all variables from a template string', async () => {
|
||||
const wrapper = shallowMount(TemplateParser, {
|
||||
...config,
|
||||
props: { template: templates[0] },
|
||||
});
|
||||
await nextTick();
|
||||
expect(wrapper.vm.variables).toEqual(['{{1}}', '{{2}}', '{{3}}']);
|
||||
});
|
||||
|
||||
it('returns no variables from a template string if it does not contain variables', async () => {
|
||||
const wrapper = shallowMount(TemplateParser, {
|
||||
...config,
|
||||
props: { template: templates[12] },
|
||||
});
|
||||
await nextTick();
|
||||
expect(wrapper.vm.variables).toBeNull();
|
||||
});
|
||||
|
||||
it('returns the body of a template', async () => {
|
||||
const wrapper = shallowMount(TemplateParser, {
|
||||
...config,
|
||||
props: { template: templates[1] },
|
||||
});
|
||||
await nextTick();
|
||||
const expectedOutput =
|
||||
templates[1].components.find(i => i.type === 'BODY')?.text || '';
|
||||
expect(wrapper.vm.templateString).toEqual(expectedOutput);
|
||||
});
|
||||
|
||||
it('generates the templates from variable input', async () => {
|
||||
const wrapper = shallowMount(TemplateParser, {
|
||||
...config,
|
||||
props: { template: templates[0] },
|
||||
});
|
||||
await nextTick();
|
||||
|
||||
// Instead of using `setData`, directly modify the `processedParams` using the component's logic
|
||||
await wrapper.vm.$nextTick();
|
||||
wrapper.vm.processedParams = { 1: 'abc', 2: 'xyz', 3: 'qwerty' };
|
||||
await wrapper.vm.$nextTick();
|
||||
|
||||
const expectedOutput =
|
||||
'Esta é a sua confirmação de voo para abc-xyz em qwerty.';
|
||||
expect(wrapper.vm.processedString).toEqual(expectedOutput);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user