Skip to content

Commit

Permalink
COM-2583 - update trainer directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie Moustard committed Dec 29, 2021
1 parent fc1d07a commit 6bbd0b1
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 41 deletions.
14 changes: 8 additions & 6 deletions src/modules/vendor/components/trainers/ProfileInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
<ni-input v-model.trim="userProfile.identity.firstname" caption="Prénom"
@focus="saveTmp('identity.firstname')" @blur="updateUser('identity.firstname')" />
<ni-input v-model.trim="userProfile.identity.lastname" caption="Nom" @focus="saveTmp('identity.lastname')"
@blur="updateUser('identity.lastname')" :error="$v.userProfile.identity.lastname.$error" />
@blur="updateUser('identity.lastname')" :error="v$.userProfile.identity.lastname.$error" />
<div class="col-12 col-md-6 row items-center">
<div class="col-xs-11">
<ni-input ref="userEmail" name="emailInput" caption="Adresse email" type="email" lower-case
:error="$v.userProfile.local.email.$error" :error-message="emailError($v.userProfile)"
:error="v$.userProfile.local.email.$error" :error-message="emailError(v$.userProfile)"
:disable="emailLock" v-model.trim="userProfile.local.email" @focus="saveTmp('local.email')" />
</div>
<div :class="['col-xs-1', 'row', 'justify-end', { 'cursor-pointer': emailLock }]">
<ni-button :icon="lockIcon" color="copper-grey-500" @click="toggleEmailLock(!emailLock)" />
</div>
</div>
<ni-input v-model.trim="userProfile.contact.phone" @focus="saveTmp('contact.phone')"
:error-message="phoneNbrError($v.userProfile)" @blur="updateUser('contact.phone')" caption="Téléphone"
:error="$v.userProfile.contact.phone.$error" />
:error-message="phoneNbrError(v$.userProfile)" @blur="updateUser('contact.phone')" caption="Téléphone"
:error="v$.userProfile.contact.phone.$error" />
</div>
<div class="row gutter-profile q-mb-xl">
<ni-input caption="Biographie" v-model="userProfile.biography" type="textarea"
Expand All @@ -39,10 +39,12 @@ import { required, email } from 'vuelidate/lib/validators';
import { validationMixin } from '@mixins/validationMixin';
import { TRAINER } from '@data/constants';
import { frPhoneNumber } from '@helpers/vuelidateCustomVal';
import useVuelidate from '@vuelidate/core';
export default {
name: 'ProfileInfo',
mixins: [validationMixin, userMixin],
setup () { return { v$: useVuelidate() }; },
components: {
'ni-input': Input,
'ni-button': Button,
Expand Down Expand Up @@ -70,8 +72,8 @@ export default {
}),
...mapGetters({ vendorRole: 'main/getVendorRole' }),
},
async mounted () {
this.$v.userProfile.$touch();
mounted () {
this.v$.userProfile.$touch();
this.isLoaded = true;
},
methods: {
Expand Down
21 changes: 11 additions & 10 deletions src/modules/vendor/components/trainers/TrainerCreationModal.vue
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<template>
<ni-modal :value="value" @hide="hide" @input="input">
<ni-modal :model-value="modelValue" @hide="hide" @update:model-value="input">
<template #title>
Ajouter une <span class="text-weight-bold">personne</span>
</template>
<ni-input in-modal :value="newTrainer.local.email" @input="update($event.trim(), 'local.email')" required-field
<ni-input in-modal :model-value="newTrainer.local.email" @update:model-value="update($event.trim(), 'local.email')"
@blur="validations.local.email.$touch" caption="Email" :error="validations.local.email.$error"
:error-message="emailError" :last="firstStep" :disable="!firstStep" />
<template v-if="!firstStep">
<ni-input in-modal :value="newTrainer.identity.firstname" @input="update($event.trim(), 'identity.firstname')"
caption="Prénom" />
<ni-input in-modal :value="newTrainer.identity.lastname" @input="update($event.trim(), 'identity.lastname')"
:error="validations.identity.lastname.$error" @blur="validations.identity.lastname.$touch" required-field
caption="Nom" last />
<ni-input in-modal :model-value="newTrainer.identity.firstname" caption="Prénom"
@update:model-value="update($event.trim(), 'identity.firstname')" />
<ni-input in-modal :model-value="newTrainer.identity.lastname" @blur="validations.identity.lastname.$touch"
@update:model-value="update($event.trim(), 'identity.lastname')" :error="validations.identity.lastname.$error"
required-field caption="Nom" last />
</template>
<template #footer>
<q-btn v-if="firstStep" no-caps class="full-width modal-btn" label="Suivant" color="primary"
Expand All @@ -30,7 +30,7 @@ import set from 'lodash/set';
export default {
name: 'TrainerCreationModal',
props: {
value: { type: Boolean, default: false },
modelValue: { type: Boolean, default: false },
newTrainer: { type: Object, default: () => ({}) },
validations: { type: Object, default: () => ({}) },
loading: { type: Boolean, default: false },
Expand All @@ -41,12 +41,13 @@ export default {
'ni-input': Input,
'ni-modal': Modal,
},
emits: ['update:model-value', 'hide', 'submit', 'go-to-next-step', 'update:new-trainer'],
methods: {
hide () {
this.$emit('hide');
},
input (event) {
this.$emit('input', event);
this.$emit('update:model-value', event);
},
submit () {
this.$emit('submit');
Expand All @@ -55,7 +56,7 @@ export default {
this.$emit('go-to-next-step');
},
update (event, path) {
this.$emit('update:newTrainer', set({ ...this.newTrainer }, path, event));
this.$emit('update:new-trainer', set({ ...this.newTrainer }, path, event));
},
},
};
Expand Down
4 changes: 2 additions & 2 deletions src/modules/vendor/pages/ni/users/trainers/TrainerProfile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default {
if (this.vendorRole !== TRAINER) {
await this.$store.dispatch('userProfile/fetchUserProfile', { userId: this.trainerId });
}
this.userIdentity = formatIdentity(get(this, 'userProfile.identity'), 'FL');
this.userIdentity = formatIdentity(get(this.userProfile, 'identity'), 'FL');
},
computed: {
...mapState({
Expand All @@ -57,7 +57,7 @@ export default {
},
watch: {
async userProfile () {
this.userIdentity = formatIdentity(get(this, 'userProfile.identity'), 'FL');
this.userIdentity = formatIdentity(get(this.userProfile, 'identity'), 'FL');
if (this.vendorRole !== TRAINER) await this.$store.dispatch('userProfile/updateNotifications');
},
},
Expand Down
38 changes: 16 additions & 22 deletions src/modules/vendor/pages/ni/users/trainers/TrainersDirectory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
<q-page class="vendor-background" padding>
<ni-directory-header title="Répertoire formateurs" search-placeholder="Rechercher un profil"
@update-search="updateSearch" :search="searchStr" />
<ni-table-list :data="filteredTrainers" :columns="columns" :loading="tableLoading" :pagination.sync="pagination"
<ni-table-list :data="filteredTrainers" :columns="columns" :loading="tableLoading" v-model:pagination="pagination"
@go-to="goToTrainerProfile" />
<q-btn class="fixed fab-custom" no-caps rounded color="primary" icon="add" label="Ajouter une personne"
@click="trainerCreationModal = true" :disable="tableLoading" />

<trainer-creation-modal v-model="trainerCreationModal" @hide="resetCreationModal" @submit="createTrainer"
:new-trainer.sync="newTrainer" :validations="$v.newTrainer" :loading="modalLoading" @go-to-next-step="nextStep"
:email-error="emailError($v.newTrainer)" :first-step="firstStep" />
v-model:new-trainer="newTrainer" :validations="v$.newTrainer" :loading="modalLoading" @go-to-next-step="nextStep"
:email-error="emailError(v$.newTrainer)" :first-step="firstStep" />
</q-page>
</template>

<script>
import useVuelidate from '@vuelidate/core';
import pick from 'lodash/pick';
import get from 'lodash/get';
import escapeRegExp from 'lodash/escapeRegExp';
Expand All @@ -37,6 +38,7 @@ export default {
'trainer-creation-modal': TrainerCreationModal,
},
mixins: [userMixin],
setup () { return { v$: useVuelidate() }; },
data () {
return {
trainers: [],
Expand Down Expand Up @@ -65,26 +67,24 @@ export default {
methods: {
async nextStep () {
try {
this.$v.newTrainer.local.email.$touch();
if (this.$v.newTrainer.local.email.$error) {
return NotifyWarning('Champ(s) invalide(s)');
}
this.v$.newTrainer.local.email.$touch();
if (this.v$.newTrainer.local.email.$error) return NotifyWarning('Champ(s) invalide(s)');
this.modalLoading = true;
const userInfo = await Users.exists({ email: this.newTrainer.local.email });
if (userInfo.exists && get(userInfo, 'user.role.vendor')) {
NotifyNegative('Compte déjà existant.');
} else if (userInfo.exists) {
if (!userInfo.exists) this.firstStep = false;
else if (get(userInfo, 'user.role.vendor')) NotifyNegative('Compte déjà existant.');
else {
const roles = await Roles.list({ name: TRAINER });
if (roles.length === 0) throw new Error('Role not found');
await Users.updateById(userInfo.user._id, { role: roles[0]._id });
NotifyPositive('Compte créé');
await this.refreshTrainers();
this.resetCreationModal();
this.trainerCreationModal = false;
} else {
this.firstStep = false;
}
} catch (e) {
NotifyNegative('Erreur lors de la création du compte.');
Expand All @@ -96,7 +96,7 @@ export default {
resetCreationModal () {
this.firstStep = true;
this.newTrainer = { identity: { lastname: '', firstname: '' }, local: { email: '' } };
this.$v.newTrainer.$reset();
this.v$.newTrainer.$reset();
},
updateSearch (value) {
this.searchStr = value;
Expand All @@ -107,11 +107,7 @@ export default {
formatTrainer (trainer) {
const formattedName = formatIdentity(trainer.identity, 'FL');
return {
...trainer,
name: formattedName,
noDiacriticsName: removeDiacritics(formattedName),
};
return { ...trainer, name: formattedName, noDiacriticsName: removeDiacritics(formattedName) };
},
async refreshTrainers () {
try {
Expand All @@ -129,10 +125,8 @@ export default {
},
async createTrainer () {
try {
this.$v.newTrainer.$touch();
if (this.$v.newTrainer.$error) {
return NotifyWarning('Champ(s) invalide(s)');
}
this.v$.newTrainer.$touch();
if (this.v$.newTrainer.$error) return NotifyWarning('Champ(s) invalide(s)');
this.modalLoading = true;
Expand Down
2 changes: 1 addition & 1 deletion src/store/userProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default {
const user = await Users.getById(params.userId);

const userClientRole = store.getters['main/getClientRole'];
if (userClientRole && !/\/ad\//.test(router.currentRoute.path)) {
if (userClientRole && !/\/ad\//.test(router.currentRoute.value.path)) {
const loggedUserCompany = store.getters['main/getCompany'];
if (get(user, 'company._id') !== loggedUserCompany._id) return router.replace({ path: '/404' });
}
Expand Down

0 comments on commit 6bbd0b1

Please sign in to comment.