2017-07-13 00:00:05 +05:30
|
|
|
// @flow
|
2016-05-20 01:11:43 +05:30
|
|
|
import { UPDATE, SET, CHANGE_LANG } from './actions';
|
2016-02-13 20:58:47 +05:30
|
|
|
|
2017-08-08 01:41:39 +05:30
|
|
|
export type User = {|
|
2017-07-13 00:00:05 +05:30
|
|
|
id: ?number,
|
|
|
|
uuid: ?string,
|
2017-06-08 23:29:31 +05:30
|
|
|
token: string,
|
|
|
|
username: string,
|
|
|
|
email: string,
|
|
|
|
avatar: string,
|
2017-08-08 01:41:39 +05:30
|
|
|
lang: string,
|
|
|
|
isGuest: bool,
|
|
|
|
isActive: bool,
|
2017-08-20 21:15:21 +05:30
|
|
|
isOtpEnabled: bool,
|
2017-12-31 03:08:54 +05:30
|
|
|
passwordChangedAt: number,
|
2017-06-08 23:29:31 +05:30
|
|
|
hasMojangUsernameCollision: bool,
|
2017-08-08 01:41:39 +05:30
|
|
|
maskedEmail?: string,
|
|
|
|
shouldAcceptRules?: bool,
|
|
|
|
|};
|
2017-06-08 23:29:31 +05:30
|
|
|
|
2017-07-13 00:00:05 +05:30
|
|
|
const defaults: User = {
|
2017-01-12 11:42:56 +05:30
|
|
|
id: null,
|
|
|
|
uuid: null,
|
|
|
|
username: '',
|
2017-07-13 00:00:05 +05:30
|
|
|
token: '',
|
2017-01-12 11:42:56 +05:30
|
|
|
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,
|
2017-08-20 21:15:21 +05:30
|
|
|
isOtpEnabled: false,
|
2017-01-12 11:42:56 +05:30
|
|
|
shouldAcceptRules: false, // whether user need to review updated rules
|
2017-12-31 03:08:54 +05:30
|
|
|
passwordChangedAt: 0,
|
2017-01-12 11:42:56 +05:30
|
|
|
hasMojangUsernameCollision: false,
|
|
|
|
|
|
|
|
// frontend specific attributes
|
2017-08-08 01:41:39 +05:30
|
|
|
isGuest: true
|
2017-01-12 11:42:56 +05:30
|
|
|
};
|
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
export default function user(
|
2017-07-13 00:00:05 +05:30
|
|
|
state: User = defaults,
|
|
|
|
{type, payload}: {type: string, payload: ?Object}
|
2016-02-13 20:58:47 +05:30
|
|
|
) {
|
|
|
|
switch (type) {
|
2016-05-20 01:11:43 +05:30
|
|
|
case CHANGE_LANG:
|
|
|
|
if (!payload || !payload.lang) {
|
|
|
|
throw new Error('payload.lang is required for user reducer');
|
|
|
|
}
|
|
|
|
|
2017-01-12 11:42:56 +05:30
|
|
|
return {
|
2016-05-20 01:11:43 +05:30
|
|
|
...state,
|
|
|
|
lang: payload.lang
|
2017-01-12 11:42:56 +05:30
|
|
|
};
|
2016-05-20 01:11:43 +05:30
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
case UPDATE:
|
|
|
|
if (!payload) {
|
|
|
|
throw new Error('payload is required for user reducer');
|
|
|
|
}
|
|
|
|
|
2017-01-12 11:42:56 +05:30
|
|
|
return {
|
2016-02-13 20:58:47 +05:30
|
|
|
...state,
|
|
|
|
...payload
|
2017-01-12 11:42:56 +05:30
|
|
|
};
|
2016-02-26 23:43:41 +05:30
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
case SET:
|
2017-01-12 11:42:56 +05:30
|
|
|
payload = payload || {};
|
|
|
|
|
|
|
|
return {
|
|
|
|
...defaults,
|
|
|
|
...payload
|
|
|
|
};
|
2016-02-13 20:58:47 +05:30
|
|
|
|
|
|
|
default:
|
2017-01-12 11:42:56 +05:30
|
|
|
return state || {
|
|
|
|
...defaults
|
|
|
|
};
|
2016-02-13 20:58:47 +05:30
|
|
|
}
|
|
|
|
}
|