mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-12-12 16:29:01 +05:30
63 lines
1.4 KiB
JavaScript
63 lines
1.4 KiB
JavaScript
import { UPDATE, SET, CHANGE_LANG } from './actions';
|
|
|
|
|
|
const defaults = {
|
|
id: null,
|
|
uuid: null,
|
|
username: '',
|
|
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,
|
|
shouldAcceptRules: false, // whether user need to review updated rules
|
|
passwordChangedAt: null,
|
|
hasMojangUsernameCollision: false,
|
|
|
|
// frontend specific attributes
|
|
isGuest: true,
|
|
goal: null // the goal with wich user entered site
|
|
};
|
|
|
|
export default function user(
|
|
state = null,
|
|
{type, payload = null}
|
|
) {
|
|
switch (type) {
|
|
case CHANGE_LANG:
|
|
if (!payload || !payload.lang) {
|
|
throw new Error('payload.lang is required for user reducer');
|
|
}
|
|
|
|
return {
|
|
...state,
|
|
lang: payload.lang
|
|
};
|
|
|
|
case UPDATE:
|
|
if (!payload) {
|
|
throw new Error('payload is required for user reducer');
|
|
}
|
|
|
|
return {
|
|
...state,
|
|
...payload
|
|
};
|
|
|
|
case SET:
|
|
payload = payload || {};
|
|
|
|
return {
|
|
...defaults,
|
|
...payload
|
|
};
|
|
|
|
default:
|
|
return state || {
|
|
...defaults
|
|
};
|
|
}
|
|
}
|