Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <template>
- <div class="signup-page edit-expert">
- <div class="block-form" v-loading="initIsLoading">
- <el-form :model="joinForm" :rules="rules" ref="joinForm" id="joinForm">
- <div class="d-flex change-img">
- <el-col :xl="3" :lg="5" :md="5" :sm="24" :xs="24">
- <div class="user-img" :style="{ 'background-image' : `url( '../../../static/img/default-image.png')` , 'background-size' : 'cover' }" v-if="!item.image"></div>
- <div class="user-img" :style="{ 'background-image' : `url( ${ item.image } )` }" v-if="item.image && !changeImg"></div>
- <div class="user-img" :style="{ 'background-image' : `url(${ item.image } )` }" v-if="item.image && changeImg"></div>
- </el-col>
- <el-col :xl="21" :lg="19" :md="19" :sm="24" :xs="24">
- <el-button type="button" class="add-img" :loading="addImage_isLoading">
- Add Image
- <input type="file" @change="onFileChange($event)">
- </el-button>
- </el-col>
- </div>
- <el-row>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <h2>YOUR DETAILS</h2>
- </el-col>
- </el-row>
- <el-row>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item label="Title" prop="title">
- <el-select v-model="joinForm.title" placeholder="Select">
- <el-option v-for="title in titles" :label="title.value" :value="title.id" :key="title.id"></el-option>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item required label="First name" prop="first_name">
- <el-input v-model="joinForm.first_name" placeholder="Your first name" />
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Surname" prop="last_name">
- <el-input v-model="joinForm.last_name" placeholder="Your surname" />
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Email address" prop="email">
- <el-input type="email" v-model="joinForm.email" placeholder="Your email address" disabled/>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Timezone" prop="timezone">
- <el-select v-model="joinForm.timezone" filterable placeholder="Select timezone">
- <el-option v-for="timezone in timezones[0]" :value="timezone.timezone" :label="`${timezone.timezone} ${timezone.pretty_offset}`" :key="timezone.timezone"></el-option>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Country" prop="company_country_id">
- <el-select v-model="joinForm.company_country_id" filterable placeholder="Select country">
- <el-option v-for="companyCountry in companyCountries[0]" :value="companyCountry.id" :label="companyCountry.name" :key="companyCountry.id"></el-option>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24" class="edit-profile-industry">
- <el-form-item required label="Industry sector" prop="group_ids">
- <el-select v-model="joinForm.group_ids" multiple placeholder="Select industry sectors" :disabled="true">
- <el-option v-for="group in groups[0]" :value="group.id" :label="group.name" :key="group.id" />
- </el-select>
- <label class="el-form-item__label text-left">
- Info: Please get in touch with our support to update these.
- </label>
- </el-form-item>
- </el-col>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24" class="edit-profile-tags">
- <el-form-item required label="Areas of expertise" prop="tag_ids">
- <el-select v-model="joinForm.tag_ids" multiple placeholder="Select area of expertises" :disabled="true">
- <el-option v-for="tag in tags[0]" :value="tag.id" :label="tag.name" :key="tag.id" />
- </el-select>
- <label class="el-form-item__label text-left">
- Info: Please get in touch with our support to update these.
- </label>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <h2>COMPANY DETAILS</h2>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item label="Name" prop="company_name">
- <el-input v-model="joinForm.company_name" placeholder="Company name" />
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item label="Position" prop="company_position">
- <el-input v-model="joinForm.company_position" placeholder="Company position" />
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item label="Street number or name" prop="company_street">
- <el-input v-model="joinForm.company_street" placeholder="Company street number or name" />
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item label="Town" prop="company_town">
- <el-input v-model="joinForm.company_town" placeholder="Company town" />
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item label="Region/State" prop="company_region">
- <el-input v-model="joinForm.company_region" placeholder="Company region/state" />
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item label="Postcode" prop="company_postcode">
- <el-input v-model="joinForm.company_postcode" placeholder="Company postcode" />
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item label="Vat Number" prop="company_vat_no">
- <el-input v-model="joinForm.company_vat_no" placeholder="Company VAT Number" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <h2>OTHER DETAILS</h2>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Hourly rate (in GBP)" prop="hour_rate">
- <div class="el-input">
- <vue-numeric currency="£" separator="," :precision="2" v-model="joinForm.hour_rate" class="el-input__inner" :disabled="true"></vue-numeric>
- </div>
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Day rate (in GBP)" prop="day_rate">
- <div class="el-input">
- <vue-numeric currency="£" separator="," :precision="2" v-model="joinForm.day_rate" class="el-input__inner" :disabled="true"></vue-numeric>
- </div>
- </el-form-item>
- </el-col>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Languages" prop="languages">
- <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" placeholder="Your languages" v-model="joinForm.languages" />
- </el-form-item>
- </el-col>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Availability" prop="availability">
- <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" placeholder="Your availability" v-model="joinForm.availability" />
- </el-form-item>
- </el-col>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Education" prop="education">
- <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" placeholder="Your education" v-model="joinForm.education" />
- </el-form-item>
- </el-col>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Memberships" prop="memberships">
- <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" placeholder="Your memberships" v-model="joinForm.memberships" />
- </el-form-item>
- </el-col>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Professional experience" prop="professional_experience">
- <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" placeholder="Your professional experience" v-model="joinForm.professional_experience" />
- </el-form-item>
- </el-col>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <el-form-item required label="Past projects" prop="past_projects">
- <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" placeholder="Your past projects" v-model="joinForm.past_projects" />
- </el-form-item>
- </el-col>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <el-form-item required label="References" prop="references">
- <el-input type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" placeholder="Your references" v-model="joinForm.references" />
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <h2>UPDATE PASSWORD</h2>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item label="New password (min 6 characters)" prop="pass">
- <el-input type="password" v-model="joinForm.password" auto-complete="off" placeholder="Create a password"></el-input>
- </el-form-item>
- </el-col>
- <el-col :xl="12" :lg="12" :md="24" :sm="24" :xs="24">
- <el-form-item label="Confirm new password" prop="checkPass">
- <el-input type="password" v-model="joinForm.checkPass" auto-complete="off" placeholder="Confirm password"></el-input>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24">
- <h2>UPDATE TERMS AND CONDITIONS</h2>
- </el-col>
- <el-col :xl="24" :lg="24" :md="24" :sm="24" :xs="24" class="btn-group save-updates-btn upload-terms text-left" style="margin-top:15px;">
- <p class="pull-left fileName" v-if="user.terms">
- <svg-terms></svg-terms>
- <a :href="user.terms.path">
- {{user.terms.original_filename}}
- </a>
- <i class="el-icon-error" @click="removeTermsCondition(user.terms)"></i>
- </p>
- <terms-condition-upload
- :entity="user.terms"
- :parent-id="$store.state.id"
- :types="termsAcceptType"
- :uploadUrl="uploadUrl"
- @fileWasUploaded="termsUploaded"
- ></terms-condition-upload>
- </el-col>
- </el-row>
- <el-row>
- <el-col :xl="24" class="save-updates-btn">
- <el-button type="submit" :loading="saveUpdates_isLoading" @click.native="updateProfile('joinForm', $event)">SAVE UPDATES</el-button>
- </el-col>
- </el-row>
- </el-form>
- </div>
- </div>
- </template>
- <script>
- import store from '../../store'
- import router from '../../router'
- import axios from 'axios'
- import { Message } from 'element-ui'
- import * as config from '../../config'
- import termsConditionUpload from './terms-condition-upload'
- import termsSvg from '../../components/assets/svg-terms'
- export default {
- beforeCreate () {
- if (!store.state.isLogged) {
- this.$router.push('/login')
- }
- },
- components: {
- 'terms-condition-upload': termsConditionUpload,
- 'svg-terms': termsSvg,
- },
- computed: {
- uploadUrl() {
- return `${config.apiUrl}users/profile/terms-conditions`;
- },
- },
- data() {
- let validatePass = (rule, value, callback) => {
- if (value === '') {
- callback(new Error('Please input your password'));
- } else if(value.length < 6) {
- callback(new Error('Your password contains less than 6 characters'));
- }
- else {
- if (this.joinForm.checkPass !== '') {
- this.$refs.joinForm.validateField('checkPass');
- }
- callback();
- }
- };
- let validatePass2 = (rule, value, callback) => {
- if (value === '' && this.joinForm.password != '') {
- callback(new Error('Please input your password again'));
- } else if (value !== this.joinForm.password && this.joinForm.password != '' ) {
- callback(new Error('Your passwords don\'t match!'));
- } else {
- callback();
- }
- };
- let validateCompanyName = (rule, value, callback) => {
- if ((value === false || value === '')) {
- callback(new Error('Company name is required.'))
- } else {
- callback()
- }
- }
- return {
- joinForm: {
- email: '',
- password: '',
- checkPass: ''
- },
- rules: {
- first_name: [
- { required: true, message: 'First name is required' },
- ],
- last_name: [
- { required: true, message: 'Surname is required' }
- ],
- timezone: [
- { required: true, message: 'Timezone is required' }
- ],
- company_country_id: [
- { required: true, message: 'Country is required' }
- ],
- company_name: [
- { validator: validateCompanyName, required: true }
- ],
- hour_rate: [
- { required: true, message: 'Hourly rate is required' }
- ],
- day_rate: [
- { required: true, message: 'Day rate is required' }
- ],
- languages: [
- { required: true, message: 'Languages is required' }
- ],
- availability: [
- { required: true, message: 'Availability is required' }
- ],
- education: [
- { required: true, message: 'Education is required' }
- ],
- memberships: [
- { required: true, message: 'Memberships is required' }
- ],
- professional_experience: [
- { required: true, message: 'Professional experience is required' }
- ],
- past_projects: [
- { required: true, message: 'Past projects is required' }
- ],
- password: [
- { validator: validatePass, required: false }
- ],
- checkPass: [
- { validator: validatePass2, required: false }
- ]
- },
- item: {
- image: store.state.avatar
- },
- user: {
- first_name: store.state.firstName,
- last_name: store.state.lastName,
- email: store.state.email,
- group_ids: this.getGroupTagsIds(store.state.groups),
- tag_ids: this.getGroupTagsIds(store.state.tags, true),
- company_name: store.state.company_name,
- company_country_id: store.state.company_country_id,
- company_number: store.state.company_number,
- company_street: store.state.company_street,
- company_town: store.state.company_town,
- company_region: store.state.company_region,
- company_postcode: store.state.company_postcode,
- company_vat_registered: false,
- company_vat_no: store.state.company_vat_no,
- company_position: store.state.company_position,
- timezone: store.state.timezone,
- hour_rate: store.state.hour_rate ? parseInt(store.state.hour_rate) : '',
- day_rate: store.state.day_rate ? parseInt(store.state.day_rate) : '',
- languages: store.state.languages,
- availability: store.state.availability,
- professional_experience: store.state.experience,
- past_projects: store.state.past_projects,
- education: store.state.education,
- memberships: store.state.memberships,
- references: store.state.references,
- title: store.state.title,
- password: null,
- checkPass:null,
- terms: store.state.terms
- },
- changeImg: false,
- addImage_isLoading: false,
- saveUpdates_isLoading: false,
- companyCountries: [],
- groups: [],
- timezones: [],
- tags: [],
- companyCode: 'ALEGRANT2018',
- initIsLoading: true,
- termsAcceptType: null,
- genders: [
- {
- id: 1,
- value: 'Male'
- },
- {
- id: 2,
- value: 'Female'
- },
- {
- id: 3,
- value: 'Rather not say'
- }
- ],
- titles: [
- {
- id: 1,
- value: 'Mr.'
- },
- {
- id: 2,
- value: 'Mrs.'
- },
- {
- id: 3,
- value: 'Miss'
- },
- {
- id: 4,
- value: 'Ms'
- },
- {
- id: 5,
- value: 'Dr.'
- }
- ],
- }
- },
- created() {
- // Change window title
- this.fetchGroups();
- this.fetchExpert();
- this.fetchCountries();
- this.fetchTimezones();
- this.fetchTags();
- this.uploadAcceptTypes();
- document.title = this.$route.meta.title;
- this.joinForm = {...this.joinForm, ...this.user};
- this.joinForm.gender = store.state.gender
- },
- methods: {
- getGroupTagsIds(entityIds, isTag){
- let ids = [];
- _.each(entityIds, (entity) => {
- ids.push(entity.id);
- });
- return ids;
- },
- onFileChange(event) {
- this.addImage_isLoading = true;
- let files = event.target.files || event.dataTransfer.files;
- if (!files.length)
- return;
- this.createImage(this.item, files[0]);
- },
- createImage(item, file) {
- let image = new Image();
- let reader = new FileReader();
- let self = this;
- reader.onload = (e) => {
- item.image = e.target.result;
- };
- this.changeImg = true;
- reader.readAsDataURL(file);
- let formData = new FormData();
- formData.append("avatar", file);
- axios({
- method: 'post',
- url: config.apiUrl + 'users/profile/avatar',
- headers: {
- ApiKey: config.apiKey,
- Authorization: store.state.token,
- 'Content-Type': 'multipart/form-data'
- },
- data: formData
- }).then(response => {
- self.addImage_isLoading = false;
- store.commit('CHANGE_AVATAR', response.data.avatar);
- Message.success('Your Avatar is updated successfully')
- });
- },
- updateProfile(formName, e) {
- e.preventDefault();
- this.saveUpdates_isLoading = true;
- let self = this;
- this.$refs[formName].validate((valid) => {
- if (valid) {
- let params = {
- first_name: this.joinForm.first_name,
- last_name: this.joinForm.last_name,
- email: this.joinForm.email,
- timezone: this.joinForm.timezone,
- company_country_id: this.joinForm.company_country_id,
- group_ids: this.user.group_ids,
- tag_ids: this.user.tag_ids,
- has_company: this.joinForm.has_company,
- company_name: this.joinForm.company_name,
- company_position: this.joinForm.company_position,
- company_town: this.joinForm.company_town,
- company_region: this.joinForm.company_region,
- company_postcode: this.joinForm.company_postcode,
- company_vat_registered: this.joinForm.company_vat_registered,
- company_vat_no: this.joinForm.company_vat_no,
- hour_rate: store.state.hour_rate ? parseInt(store.state.hour_rate) : '',
- day_rate: store.state.day_rate ? parseInt(store.state.day_rate) : '',
- languages: this.joinForm.languages,
- availability: this.joinForm.availability,
- education: this.joinForm.education,
- memberships: this.joinForm.memberships,
- professional_experience: this.joinForm.professional_experience,
- past_projects: this.joinForm.past_projects,
- references: this.joinForm.references,
- title: this.joinForm.title,
- company_street: this.joinForm.street,
- password: this.joinForm.password ? this.joinForm.password : '',
- password_confirmation:this.joinForm.checkPass ? this.joinForm.checkPass : '',
- };
- axios({
- method: 'post',
- url: config.apiUrl + 'users/profile',
- headers: {
- ApiKey: config.apiKey,
- Authorization: store.state.token,
- },
- data: params
- }).then(response => {
- self.saveUpdates_isLoading = false
- store.commit('LOGIN_USER', response.data);
- Message.success('Your Profile is updated successfully')
- }).catch(error => {
- self.saveUpdates_isLoading = false;
- if (error.response && error.response.status == 422 && error.response.data) {
- _.each(error.response.data.errors, function (obj, index) {
- Message.error(obj[0])
- });
- } else {
- Message.error('An error occurred, please try again later.')
- }
- });
- } else {
- self.saveUpdates_isLoading = false
- console.log('form is not valid');
- }
- });
- },
- fetchGroups() {
- axios({
- method: 'get',
- url: config.apiUrl + 'groups',
- headers: {
- ApiKey: config.apiKey,
- },
- params: {
- is_joinable: 1,
- is_public: 0,
- per_page: 9999,
- page: 1
- }
- }).then(response => {
- this.groups.push(response.data.data)
- })
- },
- uploadAcceptTypes() {
- const vm = this;
- vm.termsAcceptType = ['application/*'];
- },
- fetchCountries() {
- let url = `${config.apiUrl}companies/countries?company_code=${this.companyCode}`
- axios({
- method: 'get',
- url: url,
- headers: {
- ApiKey: config.apiKey,
- },
- }).then(response => {
- this.companyCountries.push(response.data.data)
- })
- },
- fetchTimezones () {
- axios({
- method: 'get',
- url: config.apiUrl + 'timezones',
- headers: {
- ApiKey: config.apiKey,
- }
- }).then(response => {
- this.timezones.push(response.data)
- })
- },
- fetchTags () {
- axios({
- method: 'get',
- url: config.apiUrl + 'tags',
- headers: {
- ApiKey: config.apiKey,
- },
- params: {
- is_generic: true,
- per_page: 9999,
- page: 1,
- order_by: 'name',
- order: 'asc'
- }
- }).then(response => {
- this.tags.push(response.data.data)
- })
- },
- isInitialLoadComplete () {
- if (this.companyCountries.length > 0 && this.groups.length > 0 && this.timezones.length > 0 && this.tags.length > 0) {
- this.initIsLoading = false
- }
- },
- termsUploaded(response) {
- this.user.terms = response.data;
- },
- removeTermsCondition(terms) {
- let vm = this
- let url = `${config.apiUrl}users/profile/delete-terms-conditions`
- axios({
- method: 'delete',
- url: url,
- params: {
- id: terms.id
- },
- headers: {
- ApiKey: config.apiKey,
- Authorization: store.state.token,
- 'Content-Type': 'multipart/form-data'
- },
- }).then(response => {
- vm.user.terms = null;
- store.commit('RESET_TERMS');
- })
- },
- fetchExpert() {
- const vm = this;
- axios({
- method: 'get',
- url: `${config.apiUrl}experts/${store.state.id}`,
- headers: {
- ApiKey: config.apiKey,
- Authorization: store.state.token
- },
- }).then(response => {
- if(response.data) {
- vm.joinForm = response.data;
- vm.joinForm.group_ids = this.getGroupTagsIds(store.state.groups);
- vm.joinForm.tag_ids = this.getGroupTagsIds(store.state.tags, true);
- vm.joinForm.professional_experience = store.state.experience;
- response.data.token = store.state.token;
- store.commit('LOGIN_USER', response.data);
- }
- }).catch(error => {
- Message.error('An error occured, please refresh the page.')
- });
- },
- },
- watch: {
- companyCountries () {
- this.isInitialLoadComplete()
- },
- groups () {
- this.isInitialLoadComplete()
- },
- tags () {
- this.isInitialLoadComplete()
- },
- timezones () {
- this.isInitialLoadComplete()
- },
- }
- }
- </script>
Add Comment
Please, Sign In to add comment