Skip to content

Instantly share code, notes, and snippets.

@xanf

xanf/demo.js Secret

Created January 18, 2017 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xanf/8eea0715ea516c819aed18553d4f1875 to your computer and use it in GitHub Desktop.
Save xanf/8eea0715ea516c819aed18553d4f1875 to your computer and use it in GitHub Desktop.
// @flow
import Vue from 'vue';
import component from 'vue-class-component';
import type { ErrorBag, ValidatorType } from 'vee-validate';
import get from 'lodash/get';
import api from 'src/api';
import config from 'src/config';
import { notify } from 'src/helpers/notifications';
type LeadEntryType = {
fullName: string,
email: string,
phoneNumber: string,
zip: string,
}
class ToolClickToCall extends Vue {
errors: ErrorBag
$validator: ValidatorType
lead: LeadEntryType = {
fullName: '',
email: '',
phoneNumber: '',
zip: '',
}
get isFormValid() { return !Object.values(this.lead).some(x => !x) && !this.errors.count(); }
async handleSubmit() {
if (!await this.$validator.validateAll()) return;
const { clickToCall } = config;
try {
await api().voip.clickToCall({
to: clickToCall.phoneNumber,
from: this.lead.phoneNumber.replace(/[^\d]/g, ''),
say: clickToCall.say,
play: clickToCall.play,
});
notify({
style: 'success',
position: 'bottom right',
title: 'Success',
text: 'You will receive call soon',
delay: 8000,
});
} catch (e) {
const message = get(e, 'response.data.message', e.message);
notify({
style: 'error',
position: 'bottom right',
title: 'Error',
text: message,
delay: 8000,
});
}
}
}
export default component()(ToolClickToCall);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment