From 01cc2301367f0d835445b5dad5223d0d2b378d85 Mon Sep 17 00:00:00 2001
From: Mathieu Jaumotte
Date: Thu, 5 Aug 2021 22:04:41 +0200
Subject: [PATCH] Submitting address, and validFrom field
---
.../Resources/public/vuejs/Address/App.vue | 29 +++---
.../vuejs/Address/components/AddAddress.vue | 75 +++++++++++----
.../vuejs/Address/components/ShowAddress.vue | 95 ++++++++++++-------
3 files changed, 134 insertions(+), 65 deletions(-)
diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue
index a820c253d..efe444075 100644
--- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue
+++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue
@@ -1,10 +1,19 @@
+
+ {{ error }}
+
+
+
+ {{ addAddress.result.address_id }}
+
+
@@ -24,10 +33,8 @@ export default {
personId: window.personId,
addressId: window.addressId,
backUrl: `/fr/person/${window.personId}/address/list`, //TODO better way to pass this
- validFrom: new Date().toISOString().split('T')[0]
},
addAddress: {
- key: 'person',
options: {
/// Options override default
@@ -39,19 +46,15 @@ export default {
/// Display each step in page or Modal
//bindModal: { step1: false, step2: false } //TODO true-false must not be possible
- }
+ },
+ type: 'person',
+ result: null // <== returned from addAddress component
}
}
},
methods: {
- submitAddress({ submited, flag }) {
- console.log('@@@ CLICK button submitAddress');
-
- console.log('address to post:', submited);
- console.log('datas by refs: ', this.$refs.addAddress.entity.address.text);
-
- this.$refs.addAddress.initForm(); // to cast child method
- flag.showPane = false;
+ displayErrors() {
+ return this.$refs.addAddress.errorMsg;
}
}
}
diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue
index fc38f630b..0199dff4d 100644
--- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue
+++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue
@@ -26,7 +26,8 @@
v-bind:options="this.options"
v-bind:default="this.default"
v-bind:entity="this.entity"
- v-bind:flag="this.flag">
+ v-bind:flag="this.flag"
+ ref="showAddress">
@@ -36,7 +37,7 @@
{{ $t('action.edit')}}
@@ -51,8 +52,9 @@
v-bind:default="this.default"
v-bind:entity="this.entity"
v-bind:flag="this.flag"
+ ref="showAddress"
v-bind:insideModal="false" @openEditPane="openEditPane"
- @submitAddress="$emit('submitAddress', { getSubmited , flag })">
+ @submitAddress="submitAddress">
@@ -122,8 +124,7 @@ import {
export default {
name: "AddAddress",
- props: ['context', 'options'],
- emits: ['submitAddress'],
+ props: ['context', 'options', 'result'],
components: {
Modal,
ShowAddress,
@@ -173,6 +174,10 @@ export default {
zoom: 12
},
},
+ valid: {
+ from: null,
+ to: null
+ },
errorMsg: []
}
},
@@ -197,11 +202,8 @@ export default {
return (this.context.edit) ? this.options.title.edit : this.options.title.create;
}
return (this.context.edit) ? this.default.title.edit : this.default.title.create;
- },
-
- getSubmited() {
- return this.entity.address;
}
+
},
mounted() {
if (!this.step1WithModal) {
@@ -221,11 +223,13 @@ export default {
}
this.flag.showPane = true;
},
+
openEditPane() {
console.log('open the Edit panel');
this.initForm();
this.getCountries();
},
+
closeEditPane() {
console.log('close the Edit Panel (with validation)');
this.applyChanges();
@@ -373,7 +377,6 @@ export default {
* then update existing address with backend datas when promise is resolved
*/
updateAddress(payload) {
- console.log('updateAddress payload', payload);
// TODO change the condition because it writes new postal code in edit mode now: !writeNewPostalCode
this.flag.loading = true;
@@ -387,7 +390,6 @@ export default {
body.postcode = {'id': postalCode.id },
patchAddress(payload.addressId, body)
.then(address => new Promise((resolve, reject) => {
- console.log('update address');
this.entity.address = address;
this.flag.loading = false;
resolve();
@@ -401,7 +403,6 @@ export default {
} else {
patchAddress(payload.addressId, payload.newAddress)
.then(address => new Promise((resolve, reject) => {
- console.log('update address');
this.entity.address = address;
this.flag.loading = false;
resolve();
@@ -418,7 +419,6 @@ export default {
* creating new address, and receive backend datas when promise is resolved
*/
addAddress(payload) {
- console.log('addAddress payload', payload);
this.flag.loading = true;
if('newPostcode' in payload){
@@ -431,7 +431,6 @@ export default {
body.postcode = {'id': postalCode.id},
postAddress(body)
.then(address => new Promise((resolve, reject) => {
- console.log('add address');
this.entity.address = address;
resolve();
this.flag.loading = false;
@@ -445,7 +444,6 @@ export default {
} else {
postAddress(payload)
.then(address => new Promise((resolve, reject) => {
- console.log('add address');
this.entity.address = address;
resolve();
this.flag.loading = false;
@@ -455,9 +453,52 @@ export default {
this.flag.loading = false;
});
}
+ },
+
+ /*
+ * When submited
+ */
+ submitAddress() {
+ console.log('@@@ CLICK button submitAddress');
+ this.addDateToAddressAndAddressToPerson({
+ personId: this.context.personId,
+ addressId: this.entity.address.address_id,
+ body: { validFrom: { datetime: `${this.$refs.showAddress.validFrom}T00:00:00+0100`}},
+ backUrl: this.context.backUrl
+ });
+ this.initForm();
+ this.flag.showPane = false;
+ },
+
+ addDateToAddressAndAddressToPerson(payload) {
+ console.log('addDateToAddressAndAddressToPerson payload', payload);
+ this.flag.loading = true;
+ patchAddress(payload.addressId, payload.body)
+ .then(address => new Promise((resolve, reject) => {
+ this.valid.from = address.validFrom;
+ resolve();
+ }).then(
+ postAddressToPerson(payload.personId, payload.addressId)
+ .then(person => new Promise((resolve, reject) => {
+
+ console.log('commit addAddressToPerson !!!', person);
+ this.result = person;
+
+ this.flag.loading = false;
+ this.flag.success = true;
+ window.location.assign(payload.backUrl);
+ resolve();
+ }))
+ .catch((error) => {
+ this.errorMsg.push(error);
+ this.flag.loading = false;
+ })
+ ))
+ .catch((error) => {
+ this.errorMsg.push(error);
+ this.flag.loading = false;
+ });
}
-
-
}
}
diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue
index c59104aca..e19c4f333 100644
--- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue
+++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowAddress.vue
@@ -20,41 +20,63 @@
{{ address.country.name.fr }}
+
+
+
+ {{ $t('floor') }}: {{ address.floor }}
+
+
+
+
+ {{ $t('corridor') }}: {{ address.corridor }}
+
+
+
+
+ {{ $t('steps') }}: {{ address.steps }}
+
+
+
+
+ {{ $t('flat') }}: {{ address.flat }}
+
+
+
+
+ {{ $t('buildingName') }}: {{ address.buildingName }}
+
+
+
+
+
+
+
+ {{ $t('distribution') }}: {{ address.distribution }}
+
+
+
-
-
- {{ $t('floor') }}: {{ address.floor }}
-
-
-
-
- {{ $t('corridor') }}: {{ address.corridor }}
-
-
-
-
- {{ $t('steps') }}: {{ address.steps }}
-
-
-
-
- {{ $t('flat') }}: {{ address.flat }}
-
-
-
-
- {{ $t('buildingName') }}: {{ address.buildingName }}
-
-
-
-
-
-
-
- {{ $t('distribution') }}: {{ address.distribution }}
-
+
+
{{ $t('date') }}
+
+
+
+
+
+
+ {{ $t('loading') }}
+
+
+ {{ $t('person_address_creation_success') }}
+
@@ -93,7 +115,7 @@ export default {
'errorMsg',
'insideModal'
],
- emits: ['openEditPane', 'submitAddress'],
+ emits: ['openEditPane', 'submitAddress', 'validFrom'],
computed: {
address() {
return this.entity.address;
@@ -109,6 +131,9 @@ export default {
},
getSubmited() {
return this.entity.address;
+ },
+ validFrom() {
+ return new Date().toISOString().split('T')[0];
}
}
};