Skip to content

Commit

Permalink
refactor: complete captcha refactor [WTEL-4251]
Browse files Browse the repository at this point in the history
  • Loading branch information
dlohvinov committed Mar 12, 2024
1 parent 43a9fc7 commit c713592
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 43 deletions.
2 changes: 2 additions & 0 deletions src/app/components/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import WtIconBtn from './wt-icon-btn.vue';
import WtInput from './wt-input.vue';
import WtLabel from './wt-label.vue';
import WtTextarea from './wt-textarea.vue';
import WtSnackBar from './wt-snack-bar.vue';

const Components = {
WtButton,
WtIconBtn,
WtInput,
WtLabel,
WtTextarea,
WtSnackBar,
};

Object.keys(Components).forEach((name) => {
Expand Down
141 changes: 141 additions & 0 deletions src/app/components/utils/wt-snack-bar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<template>
<aside
class="wt-snack-bar"
>
<transition-group name="snack-pop-up">
<article
class="wt-snack-bar-item"
v-for="({ type, text, id }) of stack"
:key="id"
:class="`wt-snack-bar-item--${type}`"
>
<p
class="wt-snack-bar-item-text"
>
{{ text || type }}
</p>
<wt-icon-btn
icon="close"
size="sm"
@click="close(id)"
></wt-icon-btn>
</article>
</transition-group>
</aside>
</template>

<script>
import eventBus from '@webitel/ui-sdk/src/scripts/eventBus';
import { v4 as uuid } from 'uuid';
export default {
name: 'wt-snack-bar',
data: () => ({
stack: [],
}),
methods: {
close(id) {
const newStack = [...this.stack];
const index = newStack.findIndex((item) => item.id === id);
newStack.splice(index, 1);
this.stack = newStack;
},
addSnack({
type,
title,
text,
}) {
const newItem = {
id: uuid(),
type,
title,
text,
};
this.stack.push(newItem);
setTimeout(() => {
this.close(newItem.id);
}, 3000);
},
},
mounted() {
eventBus.$on('snack', this.addSnack);
},
destroyed() {
eventBus.$off('snack', this.addSnack);
},
};
</script>

<style scoped lang="scss">
#wt-omni-widget {
.wt-snack-bar {
position: absolute;
z-index: 1111;
bottom: 0;
left: 0;
right: 0;
}
.wt-snack-bar-item {
position: absolute;
right: 0;
bottom: 0;
left: 0;
display: flex;
align-content: center;
justify-content: space-between;
gap: 5px;
padding: 15px;
border-radius: 0 0 var(--border-radius--square) var(--border-radius--square);
background: var(--negative-color);
&--error {
background: var(--negative-color);
}
}
.wt-snack-bar-item-text {
@extend %typo-body-md;
color: var(--main-color);
}
.wt-snack-bar-item {
&--error {
.wt-snack-bar-item-header {
color: var(--main-color);
}
.wt-snack-bar-item-text {
color: var(--main-color);
}
}
}
&.wt-omni-widget--rounded {
.wt-snack-bar-item {
border-radius: 0 0 var(--border-radius--rounded) var(--border-radius--rounded);
}
}
.snack-pop-up-enter-active,
.snack-pop-up-leave-active {
transition: all 0.2s ease;
}
.snack-pop-up-enter,
.snack-pop-up-leave-to {
opacity: 0;
transform: translateY(20px);
}
.snack-pop-up-enter-to,
.snack-pop-up-leave {
transform: translateY(0);
opacity: 1;
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@
<aside class="wt-omni-widget-popup">
<section class="wt-omni-widget-popup__popup">
<wt-omni-widget-header
:channel="WidgetChannel.APPOINTMENT"
@close="close"
></wt-omni-widget-header>
<article class="wt-omni-widget-popup__main">
<slot name="main">
<the-appointment></the-appointment>
</slot>
</article>
<wt-snack-bar />
</section>
</aside>
</template>

<script>
import TheAppointment from '../../../modules/appointment/components/wt-omni-widget-appointment.vue';
import WidgetChannel from '../../enums/WidgetChannel.enum';
import WtOmniWidgetHeader from '../wt-omni-widget-window/wt-omni-widget-window-header/wt-omni-widget-window-header.vue';
export default {
name: 'wt-omni-widget-popup',
data: () => ({
WidgetChannel,
}),
components: {
WtOmniWidgetHeader,
TheAppointment,
Expand Down Expand Up @@ -53,6 +59,7 @@ export default {
}
.wt-omni-widget-popup__popup {
position: relative;
z-index: 1;
display: flex;
flex-direction: column;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:is="`${channel}-wrapper`"
:namespace="namespace"
></component>
<wt-snack-bar />
</section>
</template>

Expand Down Expand Up @@ -65,6 +66,7 @@ export default {
border-radius: var(--border-radius--square);
background: var(--background-color);
box-shadow: var(--morf-style-font);
position: relative;
::v-deep .wt-omni-widget-window-content-wrapper {
flex-grow: 1;
Expand Down
5 changes: 5 additions & 0 deletions src/app/locale/en/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export default {
close: 'Close',
ok: 'Ok',
},
captcha: {
error: {
text: 'Oops! Something went wrong. Please, try again.',
},
},
chat: {
inputPlaceholder: 'Message',
events: {
Expand Down
5 changes: 5 additions & 0 deletions src/app/locale/ru/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export default {
close: 'Закрыть',
ok: 'Oк',
},
captcha: {
error: {
text: 'Йоой! Что-то пошло не так. Пожалуйста, попробуйте позже.',
},
},
chat: {
inputPlaceholder: 'Сообщение',
events: {
Expand Down
5 changes: 5 additions & 0 deletions src/app/locale/ua/ua.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ export default {
close: 'Закрити',
ok: 'Oк',
},
captcha: {
error: {
text: 'Йоой! Щось пішло не так. Будь ласка, спробуйте пізніше.',
},
},
chat: {
inputPlaceholder: 'Повідомлення',
events: {
Expand Down
19 changes: 15 additions & 4 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import eventBus from '@webitel/ui-sdk/src/scripts/eventBus';

import globalConfigMixin from './app/mixins/globalConfigMixin';

import { initializeReCAPTCHA } from './modules/reCAPTCHA-verification/api/reCAPTCHA';
import {
initializeReCAPTCHA,
} from './modules/reCAPTCHA-verification/api/reCAPTCHA';

import './app/assets/icons/sprite';
import './app/css/fonts/_fonts.scss';
Expand Down Expand Up @@ -53,12 +55,21 @@ const defaultConfig = merge(devConfig, {
export default class WtOmniWidget {
constructor(selector, _config = {}) {
const config = merge(defaultConfig, _config);
this.mountApp({ selector, config });
this.mountApp({
selector,
config,
});
}

async mountApp({ selector, config }) {
async mountApp({
selector,
config,
}) {
await this.setConfig(config);
await initializeReCAPTCHA(config.reCAPTCHA.sitekey);
await initializeReCAPTCHA({
sitekey: config.reCAPTCHA.sitekey,
verifyUrl: config.reCAPTCHA.verifyUrl,
});
Instance.$mount(selector);
}

Expand Down
3 changes: 2 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default new WtOmniWidget('#wt-omni-widget', {
id: 'dania-webchat',
},
reCAPTCHA: {
sitekey: '',
sitekey: '6LdTJJUpAAAAAFlzlOqs3mtaPhEnr0MOgBlc3W4N',
verifyUrl: 'https://dev.webitel.com/chat/dania-webchat/captcha',
},
});
15 changes: 13 additions & 2 deletions src/modules/appointment/components/wt-omni-widget-appointment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
</template>

<script>
import eventBus from '@webitel/ui-sdk/src/scripts/eventBus';
import { mapActions, mapState } from 'vuex';
import getNamespacedState from '@webitel/ui-sdk/src/store/helpers/getNamespacedState';
import reCAPTCHify from '../../reCAPTCHA-verification/scripts/reCAPTCHify';
import AppointmentList from './list/wt-omni-widget-appointment-list.vue';
import AppointmentSuccess from './success/wt-omni-widget-appointment-success.vue';
import AppointmentState from '../enum/AppointmentState.enum';
Expand Down Expand Up @@ -39,8 +41,17 @@ export default {
loadAppointmentData: 'LOAD_APPOINTMENT_DATA',
}),
},
created() {
this.loadAppointmentData();
async created() {
try {
(await reCAPTCHify(() => {
this.loadAppointmentData();
}))();
} catch (err) {
eventBus.$emit('snack', {
type: 'error',
text: this.$t('captcha.error.text'),
});
}
},
};
</script>
Expand Down
10 changes: 6 additions & 4 deletions src/modules/call/components/wt-omni-widget-call-start.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
color="success"
@click="call"
></wt-icon-btn>
err: {{ err }}
</call-actions-wrapper>
</section>
</template>

<script>
import getNamespacedState from '@webitel/ui-sdk/src/store/helpers/getNamespacedState';
import { mapActions, mapState } from 'vuex';
import eventBus from '@webitel/ui-sdk/src/scripts/eventBus';
import reCAPTCHify from '../../reCAPTCHA-verification/scripts/reCAPTCHify';
import CallActionsWrapper from './utils/wt-omni-widget-call-actions-wrapper.vue';
import CallTitleWrapper from './utils/wt-omni-widget-call-title-wrapper.vue';
Expand All @@ -50,7 +50,6 @@ export default {
},
data: () => ({
initWithMuted: false,
err: null,
}),
computed: {
...mapState({
Expand All @@ -71,8 +70,11 @@ export default {
this.makeCall({ initWithMuted: this.initWithMuted });
});
} catch (err) {
console.error(err);
this.err = err;
eventBus.$emit('snack', {
type: 'error',
text: this.$t('captcha.error.text'),
});
throw err;
}
},
},
Expand Down
Loading

0 comments on commit c713592

Please sign in to comment.