Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: empty state will not show on api fail(#241) #242

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading