Skip to content

Commit

Permalink
fix(react-formio): Fix pagination reducers state
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Mar 23, 2021
1 parent f27333d commit 9c3b146
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 44 deletions.
80 changes: 38 additions & 42 deletions packages/react-formio/src/stores/forms/forms.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,47 +45,43 @@ const createInitialState = ({
};
};

export const formsReducer = createReducer<FormsState>(
{
[resetForms.toString()]: (_: any, _2: any, reset: any) => {
return reset();
},
[requestForms.toString()]: (state: any, { parameters }: any) => {
return {
...state,
parameters: {
...state.parameters,
...parameters
},
error: null,
data: [],
isActive: true
};
},
[receiveForms.toString()]: (state: any, { forms }: any) => {
const total = forms.serverCount;
const pageCount = Math.ceil(total / (state.pageSize || 10));
export const formsReducer = createReducer<FormsState>({}, createInitialState)
.on(resetForms, (_: any, _2: any, reset: any) => {
return reset();
})
.on(requestForms, (state: FormsState, { parameters }: any) => {
return {
...state,
parameters: {
...state.parameters,
...parameters
},
error: null,
data: [],
isActive: true
};
})
.on(receiveForms, (state: FormsState, { forms }: any) => {
const total = forms.serverCount;
const pageCount = Math.ceil(total / (state.parameters.pageSize || 10));

delete forms.serverCount;
delete forms.serverCount;

return {
...state,
data: forms,
isActive: false,
parameters: {
...state.parameters,
pageCount,
totalLength: total
}
};
},
[failForms.toString()]: (state: any, { error }: any) => {
return {
...state,
error,
isActive: false
};
}
},
createInitialState
);
return {
...state,
data: forms,
isActive: false,
parameters: {
...state.parameters,
pageCount,
totalLength: total
}
};
})
.on(failForms, (state: any, { error }: any) => {
return {
...state,
error,
isActive: false
};
});
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export const submissionsReducer = createReducer<SubmissionsState>(
isActive: true
};
})
.on(receiveSubmissions, (state: any, { submissions }: any) => {
.on(receiveSubmissions, (state: SubmissionsState, { submissions }: any) => {
const total = submissions.serverCount;
const pageCount = Math.ceil(total / (state.pageSize || 10));
const pageCount = Math.ceil(total / (state.parameters.pageSize || 10));

delete submissions.serverCount;

Expand Down

0 comments on commit 9c3b146

Please sign in to comment.