import {
	GET_RECEIVERS_TOKEN,
	GET_RECEIVERS_TOKEN_SUCCESS,
	GET_RECEIVERS_TOKEN_ERROR,
} from '~/store/actionTypes';

export const initialState = {
	receiversToken: '',
	meta: {
		loading: false,
		error: '',
	},
};

export const receivers = (state = initialState, action) => {
	switch (action.type) {
		case GET_RECEIVERS_TOKEN:
			return action.payload;
		case GET_RECEIVERS_TOKEN_SUCCESS:
			return {
				...state,
				receiversToken: action.payload.receivers.receiversToken,
				meta: { ...state.meta, loading: true, error: '' },
			};
		case GET_RECEIVERS_TOKEN_ERROR:
			return { ...state, meta: { ...state.meta, loading: false, error: action.payload.error } };
		default:
			return state;
	}
};
