verdnatura-chat/app/reducers/inviteLinks.ts

46 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

import { TActionInviteLinks } from '../actions/inviteLinks';
2020-01-28 13:22:35 +00:00
import { INVITE_LINKS } from '../actions/actionsTypes';
export type TInvite = { url: string; expires: string; maxUses: number; uses: number; [x: string]: any };
export interface IInviteLinks {
token: string;
days: number;
maxUses: number;
invite: TInvite;
}
export const initialState: IInviteLinks = {
2020-01-28 13:22:35 +00:00
token: '',
days: 1,
maxUses: 0,
invite: { url: '', expires: '', maxUses: 0, uses: 0 }
2020-01-28 13:22:35 +00:00
};
export default (state = initialState, action: TActionInviteLinks): IInviteLinks => {
2020-01-28 13:22:35 +00:00
switch (action.type) {
case INVITE_LINKS.SET_TOKEN:
return { ...state, token: action.token };
2020-01-28 13:22:35 +00:00
case INVITE_LINKS.SET_PARAMS:
return {
...state,
...action.params
};
case INVITE_LINKS.SET_INVITE:
return {
...state,
invite: action.invite
};
case INVITE_LINKS.REQUEST:
return state;
case INVITE_LINKS.SUCCESS:
return initialState;
case INVITE_LINKS.FAILURE:
return initialState;
case INVITE_LINKS.CLEAR:
return initialState;
default:
return state;
}
};