From 57c420e9dda39bec522f2a433e1435b9ef36cbd6 Mon Sep 17 00:00:00 2001 From: Mathieu Jaumotte Date: Sat, 8 May 2021 15:31:13 +0200 Subject: [PATCH] no store for AddPersons, move store in data component note: this allow to use same addPersons component to add participations, requestor, or interlocutors. each addPersons component has his own data() --- .../components/PersonsAssociated.vue | 12 ++-- .../vuejs/AccompanyingCourse/store/index.js | 10 +-- .../public/vuejs/_components/AddPersons.vue | 71 ++++++++++++++----- .../vuejs/_components/PersonSuggestion.vue | 18 +++-- 4 files changed, 78 insertions(+), 33 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue index 05359ca78..ee30dd34e 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/components/PersonsAssociated.vue @@ -25,9 +25,10 @@ + v-bind:key="addPersons.key" + v-bind:options="addPersons.options" + @addNewPersons="addNewPersons" + ref="addPersons"> @@ -46,7 +47,7 @@ export default { }, data() { return { - addNewPersons: { + addPersons: { key: 'persons_associated', options: { type: ['person'], @@ -62,6 +63,7 @@ export default { }), methods: { removeParticipation(item) { + console.log('@@ CLICK remove participation: item', item); this.$store.dispatch('removeParticipation', item); }, closeParticipation(item) { @@ -71,10 +73,10 @@ export default { addNewPersons({ selected, modal }) { console.log('@@@ CLICK button addNewPersons', selected); selected.forEach(function(item) { - //console.log('# dispatch action for each item', item); this.$store.dispatch('addParticipation', item); }, this ); + this.$refs.addPersons.resetSearch(); // to cast child method modal.showModal = false; } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js index ab26379a6..b48cb43b7 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/AccompanyingCourse/store/index.js @@ -1,6 +1,6 @@ import 'es6-promise/auto'; import { createStore } from 'vuex'; -import addPersons from './modules/addPersons' +//import addPersons from './modules/addPersons' import { getAccompanyingCourse, postParticipation } from '../api'; const debug = process.env.NODE_ENV !== 'production'; @@ -13,7 +13,7 @@ let initPromise = getAccompanyingCourse(id) const store = createStore({ strict: debug, modules: { - addPersons + //addPersons }, state: { accompanyingCourse: accompanying_course, @@ -53,12 +53,12 @@ let initPromise = getAccompanyingCourse(id) state.errorMsg.push(error.message); }); }, - addParticipation(addPersons, payload) { + addParticipation({ commit }, payload) { //console.log('## action: fetch post participation: payload', payload.id); postParticipation(id, payload.id, 'POST') .then(participation => new Promise((resolve, reject) => { - addPersons.commit('addParticipation', participation); - addPersons.commit('resetState', payload); + commit('addParticipation', participation); + //addPersons.commit('resetState', payload); resolve(); })) .catch((error) => { diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue index e2084c711..de2a1f6f3 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/_components/AddPersons.vue @@ -44,8 +44,10 @@ + v-bind:search="search" + @updateSelected="updateSelected">