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/PartnershipSettings/index_old.vue
<template>
  <div>
    <div class="spinner-main">
      <Loader :loading="widgetLoading"> </Loader>
    </div>
    <template v-if="partnerSettings && !widgetLoading">
      <partner-info
        :partnerSettings="partnerSettings"
        @updatePartnerSettings="updatePartnerSettings"
        :updatePartnerSettingsLoading="updatePartnerSettingsLoading"
        @toast="$toast.open($event)"
      ></partner-info>
      <partner-notify-users
        :partnerSettings="partnerSettings"
        :deletePartnerNotificationUserLoading="
          deletePartnerNotificationUserLoading
        "
        @deletePartnerNotificationUser="deletePartnerNotificationUser"
        :updatePartnerNotificationUsersLoading="
          updatePartnerNotificationUsersLoading
        "
        :notificationUserModalClose="notificationUserModalClose"
        @resetModalClose="notificationUserModalClose = false"
        :partnerUsers="partnerUsers"
        @updatePartnerNotificationUsers="updatePartnerNotificationUsers"
      ></partner-notify-users>
    </template>
  </div>
</template>
<script>
import Loader from '../../components/Loader/loader.vue';
import { toastConfig } from '../../utils/util';
import PartnershipSettingsService from '../../service/partnershipSettingsService';
import PartnerNotifyUsers from './PartnerNotifyUsers.vue';
import PartnerInfo from './PartnerInfo_old.vue';
import * as _ from 'lodash';
import { required, email, url } from 'vuelidate/lib/validators';
import Multiselect from 'vue-multiselect';
import InputColorPicker from 'vue-native-color-picker';

import {
  formvalidation,
  formvalidationMessages,
  isFileWithinLimit,
} from '../../utils/util';

const { domainValidator } = formvalidation;

export default {
  components: {
    Loader,
    PartnerNotifyUsers,
    PartnerInfo,
  },
  data() {
    return {
      partnerSettingsLoading: false,
      updatePartnerSettingsLoading: false,
      getPartnerUsersLoading: false,
      updatePartnerNotificationUsersLoading: false,
      deletePartnerNotificationUserLoading: false,
      partnerSettings: null,
      partnerUsers: [],
      notificationUserModalClose: false,
    };
  },
  computed: {
    widgetLoading() {
      return this.partnerSettingsLoading || this.getPartnerUsersLoading;
    },
  },
  mounted() {
    this.getPartnerSettings();
    this.getPartnerUsers();
  },
  methods: {
    triggerNotificationUserModalClose() {
      this.notificationUserModalClose = true;
    },
    getPartnerSettings() {
      this.partnerSettingsLoading = true;
      PartnershipSettingsService.getPartnerSettings()
        .then(({ data: { success, message, data } }) => {
          if (success) {
            this.partnerSettingsLoading = false;
            this.partnerSettings = {
              ...data,
              notificationUsers: _.filter(
                data.notificationUsers,
                ({ email }) => email.length,
              ),
            };
          } else {
            this.$toast.open(toastConfig.toastError(message));
            this.partnerSettingsLoading = false;
            this.partnerSettings = null;
          }
        })
        .catch((e) => {
          this.partnerSettingsLoading = false;
          this.partnerSettings = null;
          console.log('error', e);
          this.$toast.open(
            toastConfig.toastError(
              'Something went wrong while fetching partner settings!',
            ),
          );
        });
    },
    getPartnerUsers() {
      this.getPartnerUsersLoading = true;
      PartnershipSettingsService.getPartnerUsers()
        .then(({ data: { success, message, data } }) => {
          if (success) {
            this.getPartnerUsersLoading = false;
            this.partnerUsers = data;
          } else {
            this.$toast.open(toastConfig.toastError(message));
            this.getPartnerUsersLoading = false;
            this.partnerUsers = [];
          }
        })
        .catch((e) => {
          this.getPartnerUsersLoading = false;
          this.partnerUsers = [];
          console.log('error', e);
          this.$toast.open(
            toastConfig.toastError(
              'Something went wrong while fetching partner users!',
            ),
          );
        });
    },
    updatePartnerNotificationUsers(postData) {
      this.updatePartnerNotificationUsersLoading = true;
      PartnershipSettingsService.updatePartnerNotificationUsers(postData)
        .then(({ data: { success, message, data } }) => {
          if (success) {
            this.updatePartnerNotificationUsersLoading = false;
            this.$toast.open(toastConfig.toastSuccess(message));
            this.getPartnerSettings();
            this.triggerNotificationUserModalClose();
          } else {
            this.$toast.open(toastConfig.toastError(message));
            this.updatePartnerNotificationUsersLoading = false;
          }
        })
        .catch((e) => {
          this.updatePartnerNotificationUsersLoading = false;
          console.log('error', e);
          this.$toast.open(
            toastConfig.toastError(
              'Something went wrong while updating partner notification users!',
            ),
          );
        });
    },
    deletePartnerNotificationUser(userId) {
      this.deletePartnerNotificationUserLoading = true;
      PartnershipSettingsService.deletePartnerNotificationUser(userId)
        .then(({ data: { success, message, data } }) => {
          if (success) {
            this.deletePartnerNotificationUserLoading = false;
            this.$toast.open(toastConfig.toastSuccess(message));
            this.getPartnerSettings();
          } else {
            this.$toast.open(toastConfig.toastError(message));
            this.deletePartnerNotificationUserLoading = false;
          }
        })
        .catch((e) => {
          this.deletePartnerNotificationUserLoading = false;
          console.log('error', e);
          this.$toast.open(
            toastConfig.toastError(
              'Something went wrong while removing partner notification user!',
            ),
          );
        });
    },
    updatePartnerSettings(postData) {
      this.updatePartnerSettingsLoading = true;
      PartnershipSettingsService.updatePartnerSettings(postData)
        .then(({ data: { success, message, data } }) => {
          if (success) {
            this.updatePartnerSettingsLoading = false;
            this.$toast.open(toastConfig.toastSuccess(message));
            this.getPartnerSettings();
          } else {
            this.$toast.open(toastConfig.toastError(message));
            this.updatePartnerSettingsLoading = false;
          }
        })
        .catch((e) => {
          this.updatePartnerSettingsLoading = false;
          console.log('error', e);
          this.$toast.open(
            toastConfig.toastError(
              'Something went wrong while updating partner notification users!',
            ),
          );
        });
    },
  },
};
</script>