2020-07-22 05:10:39 +05:30
|
|
|
import { Action } from './actions';
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export interface User {
|
2020-05-24 04:38:24 +05:30
|
|
|
id: number | null;
|
|
|
|
uuid: string | null;
|
|
|
|
token: string;
|
|
|
|
username: string;
|
|
|
|
email: string;
|
|
|
|
avatar: string;
|
|
|
|
lang: string;
|
|
|
|
isGuest: boolean;
|
|
|
|
isActive: boolean;
|
2020-07-27 12:58:37 +05:30
|
|
|
isDeleted: boolean;
|
2020-05-24 04:38:24 +05:30
|
|
|
isOtpEnabled: boolean;
|
|
|
|
passwordChangedAt: number;
|
|
|
|
hasMojangUsernameCollision: boolean;
|
|
|
|
maskedEmail?: string;
|
|
|
|
shouldAcceptRules?: boolean;
|
2019-12-07 16:58:52 +05:30
|
|
|
}
|
2017-06-08 23:29:31 +05:30
|
|
|
|
2020-07-22 05:10:39 +05:30
|
|
|
export type State = User;
|
2019-01-28 00:42:58 +05:30
|
|
|
|
2020-07-22 05:10:39 +05:30
|
|
|
const defaults: State = {
|
2020-05-24 04:38:24 +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,
|
2020-07-27 12:58:37 +05:30
|
|
|
isDeleted: false,
|
2020-05-24 04:38:24 +05:30
|
|
|
isOtpEnabled: false,
|
|
|
|
shouldAcceptRules: false, // whether user need to review updated rules
|
|
|
|
passwordChangedAt: 0,
|
|
|
|
hasMojangUsernameCollision: false,
|
2017-01-12 11:42:56 +05:30
|
|
|
|
2020-05-24 04:38:24 +05:30
|
|
|
// frontend specific attributes
|
|
|
|
isGuest: true,
|
2017-01-12 11:42:56 +05:30
|
|
|
};
|
|
|
|
|
2020-07-22 05:10:39 +05:30
|
|
|
export default function user(state: State = defaults, action: Action): State {
|
|
|
|
switch (action.type) {
|
|
|
|
case 'user:changeLang':
|
2020-05-24 04:38:24 +05:30
|
|
|
return {
|
|
|
|
...state,
|
2020-07-22 05:10:39 +05:30
|
|
|
lang: action.payload,
|
2020-05-24 04:38:24 +05:30
|
|
|
};
|
2020-07-22 05:10:39 +05:30
|
|
|
case 'user:update':
|
2020-05-24 04:38:24 +05:30
|
|
|
return {
|
|
|
|
...state,
|
2020-07-22 05:10:39 +05:30
|
|
|
...action.payload,
|
2020-05-24 04:38:24 +05:30
|
|
|
};
|
2020-07-22 05:10:39 +05:30
|
|
|
case 'user:set':
|
2020-05-24 04:38:24 +05:30
|
|
|
return {
|
|
|
|
...defaults,
|
2020-07-22 05:10:39 +05:30
|
|
|
...action.payload,
|
2020-05-24 04:38:24 +05:30
|
|
|
};
|
|
|
|
default:
|
|
|
|
return (
|
|
|
|
state || {
|
|
|
|
...defaults,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2016-02-13 20:58:47 +05:30
|
|
|
}
|