HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/assets/vue/widgets/CommWidget/components/EmailScreen.vue
<template>
  <card screen="email-screen">
    <template v-slot:header>
      <div
        class="hed-sec selection"
        v-if="messageError === null && !email.emailSend"
      >
        <button class="btn-back" @click="navigateBack">
          <img :src="LeftArrowIcon" />
        </button>
        <div class="icn" :style="themeStylesMediumShades">
          <span class="blue" :style="themeStyles">
            <img :src="iconUrl" />
          </span>
        </div>
        <h3>{{ email.title }}</h3>
      </div>
    </template>
    <template v-slot:default>
      <div class="msg-area worng" v-if="messageError">
        <h3>Oops!</h3>
        <p>{{ messageError }}</p>
        <img :src="errorImage" />
        <button class="btn-snd" @click="reset">Try again</button>
      </div>
      <div class="msg-area worng" v-else-if="isEmailSend">
        <h3>Email Successfully Send...</h3>
        <img :src="CallConnectedImg" />
      </div>
      <div class="msg-area" v-else>
        <p class="text">{{ email.subTitle }}</p>
        <form @submit.prevent="formSubmit">
          <div class="form-group-chat" v-if="formVisibility.firstname">
            <input
              type="text"
              class="form-control-chat"
              v-model="form.firstname"
              placeholder="First Name"
              :class="{
                error: submitted && $v.form.firstname.$error,
              }"
            />
            <template v-if="submitted && $v.form.firstname.$error">
              <span class="error-msg" v-if="!$v.form.firstname.required"
                >This is required.</span
              >
            </template>
          </div>

          <div class="form-group-chat" v-if="formVisibility.lastname">
            <input
              type="text"
              class="form-control-chat"
              placeholder="Last Name"
              v-model="form.lastname"
              :class="{
                error: submitted && $v.form.lastname.$error,
              }"
            />
            <template v-if="submitted && $v.form.lastname.$error">
              <span class="error-msg" v-if="!$v.form.lastname.required"
                >This is required.</span
              >
            </template>
          </div>
          <div class="form-group-chat" v-if="formVisibility.phonenum">
            <input
              type="text"
              class="form-control-chat"
              v-model="form.phonenum"
              placeholder="Phone Number"
              :class="{
                error: submitted && $v.form.phonenum.$error,
              }"
            />
            <template v-if="submitted && $v.form.phonenum.$error">
              <span class="error-msg" v-if="!$v.form.phonenum.required"
                >This is required.</span
              >
              <span
                class="error-msg"
                v-else-if="!$v.form.phonenum.phoneNumer"
                >{{ formvalidationMessages.phoneNumerValidatorMessage }}</span
              >
            </template>
          </div>
          <div class="form-group-chat" v-if="formVisibility.email">
            <input
              type="text"
              class="form-control-chat"
              v-model="form.email"
              placeholder="Email Address"
              :class="{
                error: submitted && $v.form.email.$error,
              }"
            />
            <template v-if="submitted && $v.form.email.$error">
              <span class="error-msg" v-if="!$v.form.email.required"
                >This is required.</span
              >
              <span class="error-msg" v-else-if="!$v.form.email.email"
                >Please provide a valid email.</span
              >
            </template>
          </div>
          <div class="form-group-chat message" v-if="formVisibility.message">
            <textarea
              type="text"
              class="form-control-chat"
              placeholder="Message"
              v-model="form.message"
              :class="{
                error: submitted && $v.form.message.$error,
              }"
            ></textarea>
            <template v-if="submitted && $v.form.message.$error">
              <span class="error-msg" v-if="!$v.form.message.required"
                >This is required.</span
              >
            </template>
          </div>

          <button class="btn-snd" type="submit" :style="themeStyles">
            <img :src="iconUrl" />

            Send Email
            <img
              :src="SpinnerIcon"
              :style="{ width: '35px' }"
              v-if="loadingSendEmailCall"
            />
          </button>
        </form>
      </div>
    </template>
  </card>
</template>
<script>
import Card from './Card.vue';
import { mapGetters, mapActions } from 'vuex';
import LeftArrowIcon from '../../../../styles/2021-theme/images/comm_widget/left-arrow.png';
import EmailSmallIcon from '../../../../styles/2021-theme/images/comm_widget/msg-sml.png';

import SpinnerIcon from '../../../../styles/2021-theme/images/comm_widget/spinner.svg';
import GeneralErrorImg from '../../../../styles/2021-theme/images/comm_widget/widget_error.svg';
import CallConnectedImg from '../../../../styles/2021-theme/images/comm_widget/call_connected.svg';

import {
  ROOT_SELECT_GLOBAL_CONFIG,
  EMAIL_SELECT_CAN_MOUNT,
  EMAIL_SELECT,
  ROOT_ACTION_SET_SCREEN_INFO,
  SCREEN_WELCOME,
  EMAIL_SELECT_FORM_OPTIONS,
  EMAIL_ACTION_SEND_EMAIL,
  ERR_GENERIC_MSG,
  EMAIL_SELECT_SEND_EMAIL_LOADING,
  EMAIL_SELECT_SEND_EMAIL_ERROR_EMAIL,
  ROOT_ACTION_RESET_STATE,
  ROOT_SELECT_WIDGET_ID,
  ROOT_SELECT_WIDGET_THEME_COLOR,
  ROOT_SELECT_WIDGET_THEME_COLOR_SHADE,
} from '../constants';
import WelcomeScreenItem from './WelcomeScreenItem.vue';
import * as _ from 'lodash';
import { requiredIf, email } from 'vuelidate/lib/validators';
import { formvalidation, formvalidationMessages } from '../../../utils/util';
const { phoneNumerValidator } = formvalidation;
//msg-sml
export default {
  data() {
    return {
      GeneralErrorImg,
      CallConnectedImg,
      SpinnerIcon,
      formvalidationMessages,
      LeftArrowIcon,
      submitted: false,
      form: {
        firstname: '',
        lastname: '',
        phonenum: '',
        email: '',
        message: '',
      },
    };
  },
  validations: {
    form: {
      firstname: {
        required: requiredIf(function () {
          return this.formVisibility.firstname;
        }),
      },
      lastname: {
        required: requiredIf(function () {
          return this.formVisibility.lastname;
        }),
      },
      message: {
        required: requiredIf(function () {
          return this.formVisibility.message;
        }),
      },
      phonenum: {
        required: requiredIf(function () {
          return this.formVisibility.phonenum;
        }),
        phoneNumerValidator,
      },
      email: {
        required: requiredIf(function () {
          return this.formVisibility.email;
        }),
        email,
      },
    },
  },
  components: {
    Card,
    WelcomeScreenItem,
  },
  computed: {
    themeStyles() {
      return {
        'background-color': `${this.themeColor}`,
      };
    },
    themeStylesShades() {
      return {
        'background-color': `${this.themeColorShade}`,
      };
    },
    themeStylesMediumShades() {
      return {
        background: `${_.replace(this.themeColorShade, '0.06', '0.18')}`,
      };
    },
    isEmailSend() {
      return this.email.emailSend;
    },
    errorImage() {
      return this.GeneralErrorImg;
    },
    ...mapGetters('root', {
      globalConfig: ROOT_SELECT_GLOBAL_CONFIG,
      widgetId: ROOT_SELECT_WIDGET_ID,
      themeColor: ROOT_SELECT_WIDGET_THEME_COLOR,
      themeColorShade: ROOT_SELECT_WIDGET_THEME_COLOR_SHADE,
    }),
    ...mapGetters('email', {
      loadingSendEmailCall: EMAIL_SELECT_SEND_EMAIL_LOADING,
      canEmailWidgetBeMount: EMAIL_SELECT_CAN_MOUNT,
      email: EMAIL_SELECT,
      formVisibility: EMAIL_SELECT_FORM_OPTIONS,
      messageError: EMAIL_SELECT_SEND_EMAIL_ERROR_EMAIL,
    }),

    iconUrl() {
      if (this.email.icon === 'msg-sml') {
        return EmailSmallIcon;
      }
      return EmailSmallIcon;
    },
  },
  methods: {
    formSubmit() {
      this.submitted = true;
      // this.$v.$touch();
      // if (this.$v.$invalid) {
      //   return;
      // }

      this.sendEmail({
        firstName: this.form.firstname,
        lastName: this.form.lastname,
        emailAddress: this.form.email,
        phoneNumber: this.form.phonenum,
        message: this.form.message,
        widgetId: this.widgetId,
        channel_id: this.email.channel_id,
      });
    },
    ...mapActions('root', {
      setScreenInfo: ROOT_ACTION_SET_SCREEN_INFO,
      reset: ROOT_ACTION_RESET_STATE,
    }),
    ...mapActions('email', {
      sendEmail: EMAIL_ACTION_SEND_EMAIL,
    }),

    navigateBack() {
      this.setScreenInfo({
        name: SCREEN_WELCOME,
        prev: '',
      });
    },
  },
};
</script>