2016-05-20 01:11:43 +05:30
|
|
|
import { UPDATE, SET, CHANGE_LANG } from './actions';
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export interface User {
|
|
|
|
id: number | null;
|
|
|
|
uuid: string | null;
|
|
|
|
token: string;
|
|
|
|
username: string;
|
|
|
|
email: string;
|
|
|
|
avatar: string;
|
|
|
|
lang: string;
|
|
|
|
isGuest: boolean;
|
|
|
|
isActive: boolean;
|
|
|
|
isOtpEnabled: boolean;
|
|
|
|
passwordChangedAt: number;
|
|
|
|
hasMojangUsernameCollision: boolean;
|
|
|
|
maskedEmail?: string;
|
|
|
|
shouldAcceptRules?: boolean;
|
|
|
|
}
|
2017-06-08 23:29:31 +05:30
|
|
|
|
2019-01-28 00:42:58 +05:30
|
|
|
export type State = {
|
2019-12-29 17:27:44 +05:30
|
|
|
user: User;
|
2019-01-28 00:42:58 +05:30
|
|
|
};
|
|
|
|
|
2017-07-13 00:00:05 +05:30
|
|
|
const defaults: User = {
|
2019-11-27 14:33:32 +05:30
|
|
|
id: null,
|
|
|
|
uuid: null,
|
|
|
|
username: '',
|
|
|
|
token: '',
|
|
|
|
email: '',
|
|
|
|
// will contain user's email or masked email
|
|
|
|
// (e.g. ex**ple@em*il.c**) depending on what information user have already provided
|
|
|
|
maskedEmail: '',
|
|
|
|
avatar: '',
|
|
|
|
lang: '',
|
|
|
|
isActive: false,
|
|
|
|
isOtpEnabled: false,
|
|
|
|
shouldAcceptRules: false, // whether user need to review updated rules
|
|
|
|
passwordChangedAt: 0,
|
|
|
|
hasMojangUsernameCollision: false,
|
2017-01-12 11:42:56 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
// frontend specific attributes
|
|
|
|
isGuest: true,
|
2017-01-12 11:42:56 +05:30
|
|
|
};
|
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
export default function user(
|
2019-11-27 14:33:32 +05:30
|
|
|
state: User = defaults,
|
2019-12-07 16:58:52 +05:30
|
|
|
{ type, payload }: { type: string; payload: any },
|
2016-02-13 20:58:47 +05:30
|
|
|
) {
|
2019-11-27 14:33:32 +05:30
|
|
|
switch (type) {
|
|
|
|
case CHANGE_LANG:
|
|
|
|
if (!payload || !payload.lang) {
|
|
|
|
throw new Error('payload.lang is required for user reducer');
|
|
|
|
}
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
lang: payload.lang,
|
|
|
|
};
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
case UPDATE:
|
|
|
|
if (!payload) {
|
|
|
|
throw new Error('payload is required for user reducer');
|
|
|
|
}
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
...payload,
|
|
|
|
};
|
2016-02-26 23:43:41 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
case SET:
|
|
|
|
payload = payload || {};
|
2017-01-12 11:42:56 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
return {
|
|
|
|
...defaults,
|
|
|
|
...payload,
|
|
|
|
};
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
default:
|
|
|
|
return (
|
|
|
|
state || {
|
|
|
|
...defaults,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2016-02-13 20:58:47 +05:30
|
|
|
}
|