mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
[Household members editor] add address suggestion on menage creation
This commit is contained in:
@@ -37,7 +37,20 @@ const fetchHouseholdSuggestionByAccompanyingPeriod = (personId) => {
|
||||
;
|
||||
};
|
||||
|
||||
const fetchAddressSuggestionByPerson = (personId) => {
|
||||
const url = `/api/1.0/person/address/suggest/by-person/${personId}.json`;
|
||||
return window.fetch(url)
|
||||
.then(response => {
|
||||
if (response.ok) {
|
||||
return response.json();
|
||||
}
|
||||
|
||||
throw Error({m: 'Error while fetch address suggestion', status: response.status});
|
||||
});
|
||||
}
|
||||
|
||||
export {
|
||||
householdMove,
|
||||
fetchHouseholdSuggestionByAccompanyingPeriod,
|
||||
fetchAddressSuggestionByPerson,
|
||||
};
|
||||
|
@@ -5,6 +5,38 @@
|
||||
<div>
|
||||
<household-viewer :household="household"></household-viewer>
|
||||
</div>
|
||||
<div v-if="isHouseholdNew && !hasHouseholdAddress">
|
||||
|
||||
<h3>À quelle adresse habite ce ménage ?</h3>
|
||||
|
||||
<ul v-if="filterAddressesSuggestion.length > 0">
|
||||
<li v-for="a in filterAddressesSuggestion">
|
||||
<show-address :address="a"></show-address>
|
||||
<button class="btn" @click="setHouseholdAddress(a)">
|
||||
Le ménage habite cette adresse
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<ul class="record_actions">
|
||||
<li >
|
||||
<button class="btn">
|
||||
Créer une adresse
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
<div v-if="isHouseholdNew && hasHouseholdAddress">
|
||||
<ul class="record_actions">
|
||||
<li >
|
||||
<button class="btn" @click="removeHouseholdAddress">
|
||||
Supprimer cette adresse
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div v-else-if="isForceLeaveWithoutHousehold">
|
||||
{{ $t('household_members_editor.household.will_leave_any_household') }}
|
||||
@@ -23,7 +55,7 @@
|
||||
countHouseholdSuggestion) }}
|
||||
</button>
|
||||
</li>
|
||||
<li v-if="showHouseholdSuggestion">
|
||||
<li v-if="showHouseholdSuggestion && hasHouseholdSuggestion">
|
||||
<button
|
||||
class="btn btn-misc"
|
||||
@click="toggleHouseholdSuggestion"
|
||||
@@ -46,10 +78,15 @@
|
||||
<i class="fa fa-sign-out"></i>{{ $t('household_members_editor.household.leave_without_household') }}
|
||||
</button>
|
||||
</li>
|
||||
<li v-if="allowRemoveHousehold">
|
||||
<button @click="removeHousehold" class="btn">
|
||||
{{ $t('household_members_editor.household.change') }}
|
||||
</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="householdSuggestions">
|
||||
<div v-if="showHouseholdSuggestion">
|
||||
<div v-if="showHouseholdSuggestion && hasHouseholdSuggestion">
|
||||
<p>{{ $t('household_members_editor.household_for_participants_accompanying_period') }}:</p>
|
||||
<div class="householdSuggestionList">
|
||||
<div
|
||||
@@ -98,11 +135,13 @@
|
||||
|
||||
import { mapGetters, mapState } from 'vuex';
|
||||
import HouseholdViewer from 'ChillPersonAssets/vuejs/_components/Household/Household.vue';
|
||||
import ShowAddress from 'ChillMainAssets/vuejs/Address/components/ShowAddress.vue';
|
||||
|
||||
export default {
|
||||
name: 'Household',
|
||||
components: {
|
||||
HouseholdViewer,
|
||||
ShowAddress,
|
||||
},
|
||||
computed: {
|
||||
...mapGetters([
|
||||
@@ -111,6 +150,8 @@ export default {
|
||||
'hasHouseholdSuggestion',
|
||||
'countHouseholdSuggestion',
|
||||
'filterHouseholdSuggestionByAccompanyingPeriod',
|
||||
'filterAddressesSuggestion',
|
||||
'hasHouseholdAddress',
|
||||
]),
|
||||
...mapState([
|
||||
'showHouseholdSuggestion',
|
||||
@@ -119,14 +160,22 @@ export default {
|
||||
return this.$store.state.household;
|
||||
},
|
||||
allowHouseholdCreate() {
|
||||
return this.$store.state.allowHouseholdCreate;
|
||||
return this.$store.state.allowHouseholdCreate && !this.$store.getters.hasHousehold;
|
||||
},
|
||||
allowHouseholdSearch() {
|
||||
return false;
|
||||
return this.$store.state.allowHouseholdSearch;
|
||||
return this.$store.state.allowHouseholdSearch && !this.$store.getters.hasHousehold;
|
||||
},
|
||||
allowLeaveWithoutHousehold() {
|
||||
return this.$store.state.allowLeaveWithoutHousehold;
|
||||
return this.$store.state.allowLeaveWithoutHousehold && !this.$store.getters.hasHousehold;
|
||||
},
|
||||
allowRemoveHousehold() {
|
||||
return this.$store.getters.hasHousehold &&
|
||||
(
|
||||
this.allowHouseholdCreate || this.allowHouseholdSearch ||
|
||||
this.allowLeaveWithoutHousehold
|
||||
)
|
||||
;
|
||||
},
|
||||
allowChangeHousehold() {
|
||||
return this.allowHouseholdCreate || this.allowHouseholdSearch ||
|
||||
@@ -148,6 +197,15 @@ export default {
|
||||
},
|
||||
selectHousehold(h) {
|
||||
this.$store.dispatch('selectHousehold', h);
|
||||
},
|
||||
removeHousehold() {
|
||||
this.$store.dispatch('removeHousehold');
|
||||
},
|
||||
setHouseholdAddress(a) {
|
||||
this.$store.commit('setHouseholdAddress', a);
|
||||
},
|
||||
removeHouseholdAddress() {
|
||||
this.$store.commit('removeHouseholdAddress');
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import { createStore } from 'vuex';
|
||||
import { householdMove, fetchHouseholdSuggestionByAccompanyingPeriod } from './../api.js';
|
||||
import { householdMove, fetchHouseholdSuggestionByAccompanyingPeriod, fetchAddressSuggestionByPerson} from './../api.js';
|
||||
import { datetimeToISO } from 'ChillMainAssets/chill/js/date.js';
|
||||
|
||||
const debug = process.env.NODE_ENV !== 'production';
|
||||
@@ -37,6 +37,7 @@ const store = createStore({
|
||||
forceLeaveWithoutHousehold: false,
|
||||
householdSuggestionByAccompanyingPeriod: [],
|
||||
showHouseholdSuggestion: window.household_members_editor_expand_suggestions === 1,
|
||||
addressesSuggestion: [],
|
||||
warnings: [],
|
||||
errors: []
|
||||
},
|
||||
@@ -47,6 +48,12 @@ const store = createStore({
|
||||
}
|
||||
return !Number.isInteger(state.household.id);
|
||||
},
|
||||
hasHouseholdAddress(state) {
|
||||
if (null === state.household) {
|
||||
return false;
|
||||
}
|
||||
return state.household.current_address !== null;
|
||||
},
|
||||
hasHousehold(state) {
|
||||
return state.household !== null;
|
||||
},
|
||||
@@ -68,6 +75,18 @@ const store = createStore({
|
||||
.filter(h => h.id !== state.household.id)
|
||||
;
|
||||
},
|
||||
filterAddressesSuggestion(state) {
|
||||
if (state.household === null) {
|
||||
return state.addressesSuggestion;
|
||||
}
|
||||
|
||||
if (state.household.current_address === null) {
|
||||
return state.addressesSuggestion;
|
||||
}
|
||||
|
||||
return state.addressesSuggestion
|
||||
.filter(a => a.address_id !== state.household.current_address.address_id);
|
||||
},
|
||||
hasPersonsWellPositionnated(state, getters) {
|
||||
return getters.needsPositionning === false
|
||||
|| (getters.persons.length > 0 && getters.concUnpositionned.length === 0);
|
||||
@@ -106,7 +125,7 @@ const store = createStore({
|
||||
needsPositionning(state) {
|
||||
return state.forceLeaveWithoutHousehold === false;
|
||||
},
|
||||
buildPayload: (state) => {
|
||||
buildPayload: (state, getters) => {
|
||||
let
|
||||
conc,
|
||||
payload_conc,
|
||||
@@ -119,8 +138,13 @@ const store = createStore({
|
||||
if (state.forceLeaveWithoutHousehold === false) {
|
||||
payload.destination = {
|
||||
id: state.household.id,
|
||||
type: state.household.type
|
||||
type: state.household.type,
|
||||
};
|
||||
|
||||
if (getters.isHouseholdNew && state.household.current_address !== null) {
|
||||
console.log(state.household);
|
||||
payload.destination.forceAddress = { id: state.household.current_address.address_id };
|
||||
}
|
||||
}
|
||||
|
||||
for (let i in state.concerned) {
|
||||
@@ -187,9 +211,29 @@ const store = createStore({
|
||||
)
|
||||
},
|
||||
createHousehold(state) {
|
||||
state.household = { type: 'household', members: [], current_address: null }
|
||||
state.household = { type: 'household', members: [], current_address: null, current_members_id: [] }
|
||||
state.forceLeaveWithoutHousehold = false;
|
||||
},
|
||||
removeHousehold(state) {
|
||||
state.household = null;
|
||||
state.forceLeaveWithoutHousehold = false;
|
||||
},
|
||||
setHouseholdAddress(state, address) {
|
||||
if (null === state.household) {
|
||||
console.error("no household");
|
||||
throw new Error("No household");
|
||||
}
|
||||
|
||||
state.household.current_address = address;
|
||||
},
|
||||
removeHouseholdAddress(state, address) {
|
||||
if (null === state.household) {
|
||||
console.error("no household");
|
||||
throw new Error("No household");
|
||||
}
|
||||
|
||||
state.household.current_address = null;
|
||||
},
|
||||
forceLeaveWithoutHousehold(state) {
|
||||
state.household = null;
|
||||
state.forceLeaveWithoutHousehold = true;
|
||||
@@ -221,11 +265,22 @@ const store = createStore({
|
||||
setErrors(state, errors) {
|
||||
state.errors = errors;
|
||||
},
|
||||
addAddressesSuggestion(state, addresses) {
|
||||
let existingIds = state.addressesSuggestion
|
||||
.map(a => a.address_id);
|
||||
|
||||
for (let i in addresses) {
|
||||
if (!existingIds.includes(addresses[i].address_id)) {
|
||||
state.addressesSuggestion.push(addresses[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
addConcerned({ commit, dispatch }, person) {
|
||||
commit('addConcerned', person);
|
||||
dispatch('computeWarnings');
|
||||
dispatch('fetchAddressSuggestions');
|
||||
},
|
||||
markPosition({ commit, state, dispatch }, { person_id, position_id }) {
|
||||
commit('markPosition', { person_id, position_id });
|
||||
@@ -242,6 +297,11 @@ const store = createStore({
|
||||
removeConcerned({ commit, dispatch }, conc) {
|
||||
commit('removeConcerned', conc);
|
||||
dispatch('computeWarnings');
|
||||
dispatch('fetchAddressSuggestions');
|
||||
},
|
||||
removeHousehold({ commit, dispatch }) {
|
||||
commit('removeHousehold');
|
||||
dispatch('computeWarnings');
|
||||
},
|
||||
createHousehold({ commit, dispatch }) {
|
||||
commit('createHousehold');
|
||||
@@ -268,6 +328,17 @@ const store = createStore({
|
||||
commit('setHouseholdSuggestionByAccompanyingPeriod', households);
|
||||
});
|
||||
},
|
||||
fetchAddressSuggestions({ commit, state }) {
|
||||
for (let i in state.concerned) {
|
||||
fetchAddressSuggestionByPerson(state.concerned[i].person.id)
|
||||
.then(addresses => {
|
||||
commit('addAddressesSuggestion', addresses);
|
||||
})
|
||||
.catch(e => {
|
||||
console.log(e);
|
||||
});
|
||||
}
|
||||
},
|
||||
computeWarnings({ commit, state, getters }) {
|
||||
let warnings = [],
|
||||
payload;
|
||||
@@ -321,6 +392,7 @@ const store = createStore({
|
||||
});
|
||||
|
||||
store.dispatch('computeWarnings');
|
||||
store.dispatch('fetchAddressSuggestions');
|
||||
|
||||
if (concerned.length > 0) {
|
||||
concerned.forEach(c => {
|
||||
|
Reference in New Issue
Block a user