[Vuejs]-Promise not waiting for store.dispatch

3๐Ÿ‘

โœ…

You are not returning the Promise axios.get(..).then(..) creates in getPatientList({ commit }, date) and thus the then() in your Component is immediately called. Change getPatientList to:

        getPatientList({ commit }, date) {
            console.log(`[In Store::getPatientList, getting patient list...]`);
            return axios.get(constants.API_GETPATIENT_LIST, {
                params: {
                ....                
                },
            }).then(({ data }) => {
                console.log(`Got data is`);
                console.log(data);                
                let patientSeen = data.results.filter(
                    (checkin) => checkin.consulted == 1
                );
                let patientNotSeen = data.results.filter(
                    (checkin) => checkin.consulted == 0
                );
                console.log(`patientSeen is`);
                console.log(patientSeen);
                console.log(`patientNotSeen is`);
                console.log(patientNotSeen);
                console.log(`[Finished action for Store::getPatientList]`);
                commit("STORE_PATIENT_LIST", {
                    seen: patientSeen,
                    notseen: patientNotSeen,
                });
            })
            .catch((error) => {
                console.log(
                    "In Store::getPatientList,Could not get data from API. Maybe not logged in, or dont have token?"
                    console.log(error);
            )})
        },
๐Ÿ‘คpuelo

Leave a comment