This commit is contained in:
Jonathan Chevalier
2022-10-11 17:15:24 +02:00
parent acdbde8b84
commit e653f9ff45
5 changed files with 66 additions and 33 deletions

View File

@@ -5,7 +5,7 @@ export default function (routeTo) {
const store = useMMCMStore() const store = useMMCMStore()
if (routeTo.path === '/delivery-option-step-1') { if (routeTo.path === '/delivery-option-step-1') {
return store.street !== '' && store.city !== '' && store.zipCode !== ''; return store.productList.length > 0;
} else if (routeTo.path === '/delivery-option-step-2') { } else if (routeTo.path === '/delivery-option-step-2') {
return store.withPrescription !== null return store.withPrescription !== null

View File

@@ -1,4 +1,17 @@
import {defineStore} from 'pinia' import {defineStore} from 'pinia'
import {add} from "date-fns";
const today = new Date();
const tomorrow =
add(new Date(), {
days: 1
})
const afterTomorrow =
add(new Date(), {
days: 2
})
export const useMMCMStore = defineStore('counter', { export const useMMCMStore = defineStore('counter', {
state: () => ({ state: () => ({
@@ -8,12 +21,15 @@ export const useMMCMStore = defineStore('counter', {
productList: [], productList: [],
withPrescription: null, withPrescription: null,
idProduct: null, idProduct: null,
dateDelivery: null dateDelivery: null,
dateCollect :null
}), }),
getters: { getters: {
fullAddress: (state) => state.street + ' ' + state.zipCode + ' ' + state.city, fullAddress: (state) => state.street + ' ' + state.zipCode + ' ' + state.city,
deliveryMethod: (state) => state.productList.filter(p => p.id === state.idProduct)[0].name, deliveryMethod: (state) => state.productList.filter(p => p.id === state.idProduct)[0].name,
dateDeliveryString: (state) => new Date(state.dateDelivery).toLocaleDateString("fr-FR") dateDeliveryString: (state) => new Date(state.dateDelivery).toLocaleDateString("fr-FR"),
minDateForDelivery : (state) => (state.productList.filter(p => p.id === state.idProduct)[0].ref === 'MMCM_EXPRESS') ? today : tomorrow ,
needPrescriptionDateCollect : (state) => !!(state.productList.filter(p => p.id === state.idProduct)[0].ref === 'MMCM_FACTEUR' && state.withPrescription),
}, },
actions: { actions: {
setStreet(street) { setStreet(street) {

View File

@@ -21,18 +21,29 @@
{{ item.properties.label }} {{ item.properties.label }}
</li> </li>
</ul> </ul>
<div class="alert alert-danger" role="alert" v-if="noOfferFound">
Nous sommes désolé mais votre adresse est trop eloignée de la pharmacie pour bénéficier de ce service<br/>
Nous vous invitions à utiliser le service de La Poste pour trouver une pharmacie proche de chez vous :
<a href="https://www.mesmedicamentschezmoi.com" target="_blank">Accéder à mesmedicamentschezmoi.com</a>
</div>
</template> </template>
<script> <script>
import {ref} from 'vue';
import {useMMCMStore} from '../stores/mmcm.js' import {useMMCMStore} from '../stores/mmcm.js'
export default { export default {
setup() { setup() {
const store = useMMCMStore() const store = useMMCMStore()
const noOfferFound = ref(false)
return { return {
store, store,
noOfferFound
} }
}, },
name: "address-check", name: "address-check",
@@ -47,6 +58,7 @@ export default {
methods: { methods: {
updateSearchResult: async function () { updateSearchResult: async function () {
this.isSearching = true this.isSearching = true
this.noOfferFound = false
this.searchResults = await fetch('https://api-adresse.data.gouv.fr/search/?q=' + this.query) this.searchResults = await fetch('https://api-adresse.data.gouv.fr/search/?q=' + this.query)
.then(function (response) { .then(function (response) {
return response.json(); return response.json();
@@ -61,8 +73,6 @@ export default {
this.store.setStreet(item.properties.name) this.store.setStreet(item.properties.name)
this.store.setZipCode(item.properties.postcode) this.store.setZipCode(item.properties.postcode)
this.store.setCity(item.properties.city) this.store.setCity(item.properties.city)
}, },
checkIdAddressIsEligible: async function () { checkIdAddressIsEligible: async function () {
this.isChecking = true this.isChecking = true
@@ -79,9 +89,17 @@ export default {
} }
}) })
this.store.setProductList(productList);
this.isChecking = false this.isChecking = false
this.$router.push({path: '/delivery-option-step-1'});
if (productList.length > 0) {
this.store.setProductList(productList);
this.$router.push({path: '/delivery-option-step-1'});
} else {
this.noOfferFound = true
}
} }
} }

View File

@@ -1,13 +1,28 @@
<template> <template>
<div v-if="store.needPrescriptionDateCollect">
<div class="step_title">Date de collecte de l'ordonnance :</div>
<div class="input-group has-validation">
<Datepicker v-model="dateCollect" autoApply @update:modelValue="isErrorCollect = false" model-type="timestamp"
select-text="Choisir" cancel-text="Annuler"
monthNameFormat="long" format="dd MMMM yyyy" :minDate="store.minDateForDelivery" :enableTimePicker="false"
:disabledWeekDays="[6, 0]" :format-locale="fr" locale="fr-FR"/>
<button class="btn btn-primary" @click="gotToNextStep"><i class="fa-regular fa-circle-check fa-fw"></i> Valider
</button>
<div v-if="isErrorCollect" class="invalid-feedback d-block text-start">
Merci de renseigner la date
</div>
</div>
</div>
<div class="step_title">Date de livraison des médicaments :</div> <div class="step_title">Date de livraison des médicaments :</div>
<div class="input-group has-validation"> <div class="input-group has-validation">
<Datepicker v-model="dateDelivery" autoApply @update:modelValue="isError = false" model-type="timestamp" <Datepicker v-model="dateDelivery" autoApply @update:modelValue="isErrorDelivery = false" model-type="timestamp"
select-text="Choisir" cancel-text="Annuler" select-text="Choisir" cancel-text="Annuler"
monthNameFormat="long" format="dd MMMM yyyy" :minDate="tomorrow" :enableTimePicker="false" monthNameFormat="long" format="dd MMMM yyyy" :minDate="store.minDateForDelivery" :enableTimePicker="false"
:disabledWeekDays="[6, 0]" :format-locale="fr" locale="fr-FR"/> :disabledWeekDays="[6, 0]" :format-locale="fr" locale="fr-FR"/>
<button class="btn btn-primary" @click="gotToNextStep"><i class="fa-regular fa-circle-check fa-fw"></i> Valider <button class="btn btn-primary" @click="gotToNextStep"><i class="fa-regular fa-circle-check fa-fw"></i> Valider
</button> </button>
<div v-if="isError" class="invalid-feedback d-block text-start"> <div v-if="isErrorDelivery" class="invalid-feedback d-block text-start">
Merci de renseigner la date Merci de renseigner la date
</div> </div>
</div> </div>
@@ -23,33 +38,17 @@ import {fr} from 'date-fns/locale';
export default { export default {
setup() { setup() {
const store = useMMCMStore() const store = useMMCMStore()
const isError = ref(false); const isErrorCollect = ref(false);
const isErrorDelivery = ref(false);
const {dateDelivery} = storeToRefs(store) const {dateDelivery, dateCollect} = storeToRefs(store)
const tomorrow =
add(new Date(), {
days: 1
})
const afterTomorrow =
add(new Date(), {
days: 2
})
const presetRanges = ref([
{label: 'Demain', range: [tomorrow, tomorrow]},
{label: 'Après demain', range: [afterTomorrow, afterTomorrow]},
{label: 'Semaine prochaine', range: [startOfMonth(new Date()), endOfMonth(new Date())]},
]);
return { return {
fr, fr,
isError, isErrorCollect,
tomorrow, isErrorDelivery,
dateDelivery, dateDelivery,
presetRanges, dateCollect,
store store
} }
}, },

View File

@@ -44,7 +44,7 @@ export default {
; ;
if(import.meta.env.DEV){ if(import.meta.env.DEV){
urlApi += '&ID_SESSION=4pzbjfYS' urlApi += '&ID_SESSION=xcn6c41b'
console.log(urlApi) console.log(urlApi)
} }