Skip to content

Commit

Permalink
Merge pull request #242 from R-Sourabh/#241-api-fail
Browse files Browse the repository at this point in the history
Improved: empty state will not show on api fail(#241)
  • Loading branch information
ymaheshwari1 authored Apr 18, 2024
2 parents 89af8c6 + f874abb commit 57f144c
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,19 @@ const actions: ActionTree<FacilityState, RootState> = {
...payload
}

let facilities = [], total = 0, facilityList = [];
const facilities = JSON.parse(JSON.stringify(state.facilities.list));
let total = 0, facilityList = [];

try {
const resp = await FacilityService.fetchFacilities(params)

if(!hasError(resp) && resp.data.count) {
facilities = resp.data.docs
if(payload.viewIndex && payload.viewIndex > 0) {
facilityList = facilities.concat(resp.data.docs)
} else {
facilityList = resp.data.docs
}
total = resp.data.count

if(payload.viewIndex && payload.viewIndex > 0) facilityList = JSON.parse(JSON.stringify(state.facilities.list)).concat(facilities)
} else {
throw resp.data
}
Expand Down Expand Up @@ -546,13 +549,14 @@ const actions: ActionTree<FacilityState, RootState> = {
},

async fetchVirtualFacilities({ commit, dispatch, state }, payload) {
let facilities = [], total = 0;
if (payload.viewIndex === 0) emitter.emit("presentLoader");

let archivedFacilityIds = []
if (state.archivedFacilities.length) {
archivedFacilityIds = JSON.parse(JSON.stringify(state.archivedFacilities)).map((facility: any) => facility.facilityId)
}

let facilities = JSON.parse(JSON.stringify(state.virtualFacilities.list)), total = 0;

try {
const params = {
Expand All @@ -575,11 +579,13 @@ const actions: ActionTree<FacilityState, RootState> = {

const resp = await FacilityService.fetchFacilities(params)

if (!hasError(resp) && resp.data.count) {
facilities = resp.data.docs
if (!hasError(resp) && resp.data.count) {
if (payload.viewIndex && payload.viewIndex > 0){
facilities = facilities.concat(resp.data.docs)
} else {
facilities = resp.data.docs
}
total = resp.data.count

if (payload.viewIndex && payload.viewIndex > 0) facilities = JSON.parse(JSON.stringify(state.virtualFacilities.list)).concat(facilities)
} else {
throw resp.data
}
Expand Down Expand Up @@ -676,10 +682,9 @@ const actions: ActionTree<FacilityState, RootState> = {

updateArchivedFacilities({ commit }, facilities) {
commit(types.FACILITY_ARCHIVED_UPDATED, facilities)
},
},

async fetchFacilityGroups({ commit, state, dispatch }, payload) {
let groups = [], total = 0;
if (payload.viewIndex === 0) emitter.emit("presentLoader");

const filters = {} as any
Expand All @@ -695,6 +700,9 @@ const actions: ActionTree<FacilityState, RootState> = {
filters['facilityGroupName_ic'] = 'Y'
filters['facilityGroupName_grp'] = '2'
}

let groups = JSON.parse(JSON.stringify(state.facilityGroups.list)) , total = 0;

try {
const params = {
inputFields: {
Expand All @@ -710,12 +718,13 @@ const actions: ActionTree<FacilityState, RootState> = {
const resp = await FacilityService.fetchFacilityGroups(params)

if (!hasError(resp) && resp.data.count) {
groups = resp.data.docs
total = resp.data.count

if (payload.viewIndex && payload.viewIndex > 0) {
groups = JSON.parse(JSON.stringify(state.facilityGroups.list)).concat(groups)
groups = groups.concat(resp.data.docs)
} else {
groups = resp.data.docs
}
total = resp.data.count
} else {
throw resp.data
}
Expand Down

0 comments on commit 57f144c

Please sign in to comment.