Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {produce} from 'immer';
- export interface ValidationResult {
- status: 'success' | 'pending' | 'failure';
- resultCode?: 'valid' | 'products_limit_reached' | 'no_products';
- }
- export interface State {
- validationResults: { [correlationId: string]: ValidationResult };
- }
- const initialState: State = {
- validationResults: {}
- };
- export const producer = (draft: State, action: Action) => {
- switch(action.type) {
- case 'LOAD_VALIDATION_RESULT':
- draft.validationResults[action.payload.correlationId] = {
- resultCode: null,
- status: 'pending'
- };
- break;
- case 'LOAD_VALIDATION_RESULT_SUCCESS':
- draft.validationResults[action.payload.correlationId] = {
- resultCode: action.payload.resultCode,
- status: 'success'
- };
- break;
- case 'LOAD_VALIDATION_RESULT_FAILURE':
- draft.validationResults[action.payload.correlationId] = {
- resultCode: null,
- status: 'failure'
- };
- break;
- }
- return draft;
- };
- export const reducer = produce(producer, initialState);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement