bigbuffet-rw/app/soapbox/reducers/verification.ts

52 lines
1.5 KiB
TypeScript
Raw Normal View History

import { Map as ImmutableMap, Record as ImmutableRecord, fromJS } from 'immutable';
2022-03-21 11:09:01 -07:00
import {
PEPE_FETCH_INSTANCE_SUCCESS,
FETCH_CHALLENGES_SUCCESS,
FETCH_TOKEN_SUCCESS,
SET_CHALLENGES_COMPLETE,
SET_LOADING,
SET_NEXT_CHALLENGE,
Challenge,
2022-03-21 11:09:01 -07:00
} from '../actions/verification';
import type { AnyAction } from 'redux';
const ReducerRecord = ImmutableRecord({
ageMinimum: null as string | null,
currentChallenge: null as Challenge | null,
2022-03-21 11:09:01 -07:00
isLoading: false,
isComplete: false as boolean | null,
token: null as string | null,
instance: ImmutableMap<string, any>(),
2022-03-21 11:09:01 -07:00
});
export default function verification(state = ReducerRecord(), action: AnyAction) {
2022-03-21 11:09:01 -07:00
switch (action.type) {
2022-05-11 14:06:35 -07:00
case PEPE_FETCH_INSTANCE_SUCCESS:
return state.set('instance', ImmutableMap(fromJS(action.instance)));
2022-05-11 14:06:35 -07:00
case FETCH_CHALLENGES_SUCCESS:
return state
.set('ageMinimum', action.ageMinimum)
.set('currentChallenge', action.currentChallenge)
.set('isLoading', false)
.set('isComplete', action.isComplete);
case FETCH_TOKEN_SUCCESS:
return state
.set('isLoading', false)
.set('token', action.value);
case SET_CHALLENGES_COMPLETE:
return state
.set('isLoading', false)
.set('isComplete', true);
case SET_NEXT_CHALLENGE:
return state
.set('currentChallenge', action.challenge)
.set('isLoading', false);
case SET_LOADING:
return state.set('isLoading', typeof action.value === 'boolean' ? action.value : true);
default:
return state;
2022-03-21 11:09:01 -07:00
}
}