65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
import axios from 'axios';
|
|
|
|
import { createStore } from 'vuex';
|
|
import { PATIENT_LIST_API } from './constants.js';
|
|
export default createStore({
|
|
state: {
|
|
isLoading: false,
|
|
patientList:[]
|
|
},
|
|
mutations: {
|
|
setLoading(state, payload) {
|
|
console.log('payload');
|
|
state.isLoading = payload
|
|
},
|
|
setPtientList(state, payload) {
|
|
state.patientList = payload
|
|
}
|
|
},
|
|
actions: {
|
|
|
|
async updateIsLoading({ commit }, payload) {
|
|
commit('setLoading', payload)
|
|
},
|
|
async patientList({ commit }, payload) {
|
|
commit('setLoading', true)
|
|
console.log(localStorage.getItem('admin_access_token'))
|
|
await axios.post(PATIENT_LIST_API, {}, {
|
|
headers: {
|
|
'Authorization': `Bearer ${localStorage.getItem('admin_access_token')}`,
|
|
}
|
|
}) .then(response => {
|
|
commit('setLoading', false)
|
|
console.log('Response:', response.data.patients);
|
|
let dataArray =[]
|
|
for (let data of response.data.patients) {
|
|
let dataObject = {}
|
|
dataObject.name = data.first_name + ' ' + data.last_name
|
|
dataObject.first_name = data.first_name
|
|
dataObject.last_name = data.last_name
|
|
dataObject.email = data.email
|
|
dataObject.dob = data.dob
|
|
dataObject.phone_no = data.phone_no
|
|
dataObject.avatar = ''
|
|
dataArray.push(dataObject)
|
|
}
|
|
console.log(dataArray)
|
|
commit('setPtientList',dataArray)
|
|
|
|
})
|
|
.catch(error => {
|
|
commit('setLoading', false)
|
|
console.error('Error:', error);
|
|
});
|
|
},
|
|
},
|
|
getters: {
|
|
getIsLoading(state){
|
|
return state.isLoading
|
|
},
|
|
getPatientList(state){
|
|
return state.patientList
|
|
},
|
|
}
|
|
})
|