mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
for each selected, loop for post participation, then get response and commit state
This commit is contained in:
@@ -30,22 +30,31 @@ let getDataPromise = getAccompanyingCourse(id)
|
||||
participation => participation !== item
|
||||
);
|
||||
},
|
||||
addParticipation(state, item) {
|
||||
//console.log('add new item');
|
||||
state.accompanying_course.participations.push(item);
|
||||
addParticipation(state, participation) {
|
||||
console.log('### mutation: add participation', participation);
|
||||
state.accompanying_course.participations.push(participation);
|
||||
console.log('count participations from state', state.accompanying_course.participations.length);
|
||||
|
||||
let item = { id: participation.person.id, text: participation.person.firstName + ' ' + participation.person.lastName };
|
||||
console.log('item', item);
|
||||
console.log('avant', state.add_persons.selected.length);
|
||||
state.add_persons.selected = state.add_persons.selected.filter(value => value !== item);
|
||||
console.log('après', state.add_persons.selected.length);
|
||||
},
|
||||
resetQuery() {
|
||||
console.log('### mutation: reset query');
|
||||
state.add_persons.query = "";
|
||||
},
|
||||
setQuery(state, query) {
|
||||
//console.log('q=', query);
|
||||
state.add_persons = Object.assign({}, state.add_persons, query);
|
||||
},
|
||||
loadSuggestions(state, suggested) {
|
||||
console.log('suggested', suggested);
|
||||
// doublons si on ré-affiche des suggestions avec certains selected
|
||||
//suggested.results.filter(selected => selected !== suggested.results);
|
||||
loadSuggestions(state, suggested) {
|
||||
// doublons qd on ré-affiche des suggestions avec certains selected
|
||||
state.add_persons.suggested = suggested;
|
||||
},
|
||||
updateSelected(state, value) {
|
||||
console.log('update value', value);
|
||||
console.log('update selected values', value);
|
||||
state.add_persons.selected = value;
|
||||
}
|
||||
},
|
||||
@@ -54,18 +63,23 @@ let getDataPromise = getAccompanyingCourse(id)
|
||||
commit('removeParticipation', payload);
|
||||
},
|
||||
addParticipation({ commit }, payload) {
|
||||
commit('addParticipation', payload);
|
||||
postParticipation(id, payload.id).catch((error) => {
|
||||
commit('removeParticipation', payload);
|
||||
state.errorMsg.push(error.message); // result action ??
|
||||
});
|
||||
console.log('## action: fetch post participation: payload', payload.id);
|
||||
postParticipation(id, payload.id, 'POST')
|
||||
.then(participation => new Promise((resolve, reject) => {
|
||||
commit('addParticipation', participation);
|
||||
resolve();
|
||||
}))
|
||||
.catch((error) => { // si y a une erreur
|
||||
//commit('removeParticipation', payload);
|
||||
state.errorMsg.push(error.message);
|
||||
});
|
||||
},
|
||||
setQuery({ commit }, payload) {
|
||||
commit('setQuery', payload);
|
||||
if (payload.query.length >= 3) {
|
||||
searchPersons(payload.query)
|
||||
.then(suggested => new Promise((resolve, reject) => {
|
||||
commit('loadSuggestions', suggested.results); // <====
|
||||
commit('loadSuggestions', suggested.results);
|
||||
resolve();
|
||||
}));
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user