ilink-world/redux/insurance/insurance.reducer.js

140 lines
3.6 KiB
JavaScript

/**
* Project YooLearn
* File skills.reducer
* Path app/redux/skills
* Created by BRICE ZELE
* Date: 13/09/2021
*/
import InsuranceActions from "./insurance.type";
interface SkillsActions {
payload?: any;
type: string;
}
const INITIAL_STATE = {
loading: false,
result: null,
error: null,
};
export const insuranceListReducer = (state = INITIAL_STATE, action: InsuranceActions) => {
switch (action.type) {
case InsuranceActions.GET_INSURANCE_LIST_PENDING:
return {
...state,
loading: true
}
case InsuranceActions.GET_INSURANCE_LIST_SUCCESS:
return {
loading: false,
result: action.payload,
error: null
}
case InsuranceActions.GET_INSURANCE_LIST_ERROR:
return {
...state,
loading: false,
result: null,
error: action.payload
}
case InsuranceActions.GET_INSURANCE_LIST_RESET:
return INITIAL_STATE;
default:
return state
}
};
export const subscribeInsuranceReducer = (state = INITIAL_STATE, action: InsuranceActions) => {
switch (action.type) {
case InsuranceActions.SUBSCRIBE_INSURANCE_PENDING:
return {
...state,
loading: true
}
case InsuranceActions.SUBSCRIBE_INSURANCE_SUCCESS:
return {
loading: false,
result: action.payload,
error: null
}
case InsuranceActions.SUBSCRIBE_INSURANCE_ERROR:
return {
...state,
loading: false,
result: null,
error: action.payload
}
case InsuranceActions.SUBSCRIBE_INSURANCE_RESET:
return INITIAL_STATE;
default:
return state
}
};
export const getInsurancePrimeAmountReducer = (state = INITIAL_STATE, action: InsuranceActions) => {
switch (action.type) {
case InsuranceActions.GET_INSURANCE_PRIME_AMOUNT_PENDING:
return {
...state,
loading: true
}
case InsuranceActions.GET_INSURANCE_PRIME_AMOUNT_SUCCESS:
return {
loading: false,
result: action.payload,
error: null
}
case InsuranceActions.GET_INSURANCE_PRIME_AMOUNT_ERROR:
return {
...state,
loading: false,
result: null,
error: action.payload
}
case InsuranceActions.GET_INSURANCE_PRIME_AMOUNT_RESET:
return INITIAL_STATE;
default:
return state
}
};
export const uploadInsuranceImagesReducer = (state = INITIAL_STATE, action: InsuranceActions) => {
switch (action.type) {
case InsuranceActions.UPLOAD_INSURANCE_IMAGES_PENDING:
return {
...state,
loading: true
}
case InsuranceActions.UPLOAD_INSURANCE_IMAGES_SUCCESS:
return {
loading: false,
result: action.payload,
error: null
}
case InsuranceActions.UPLOAD_INSURANCE_IMAGES_ERROR:
return {
...state,
loading: false,
result: null,
error: action.payload
}
case InsuranceActions.UPLOAD_INSURANCE_IMAGES_RESET:
return INITIAL_STATE;
default:
return state
}
};