1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 21:06:42 +07:00

user settings mechanism

This commit is contained in:
Fedor Katurov 2019-11-13 18:02:09 +07:00
parent 5fe0deca17
commit a90285a4ac
10 changed files with 162 additions and 4 deletions

View file

@ -71,3 +71,8 @@ export const authSetLastSeenMessages = (
type: AUTH_USER_ACTIONS.SET_LAST_SEEN_MESSAGES,
last_seen_messages,
});
export const authPatchUser = (user: Partial<IUser>) => ({
type: AUTH_USER_ACTIONS.PATCH_USER,
user,
});

View file

@ -17,6 +17,7 @@ export const AUTH_USER_ACTIONS = {
SET_UPDATES: 'SET_UPDATES',
SET_LAST_SEEN_MESSAGES: 'SET_LAST_SEEN_MESSAGES',
PATCH_USER: 'PATCH_USER',
};
export const USER_ERRORS = {

View file

@ -29,6 +29,7 @@ const INITIAL_STATE: IAuthState = {
user: null,
messages: [],
messages_error: null,
patch_errors: {},
},
};

View file

@ -13,6 +13,7 @@ import {
authSetUpdates,
authLoggedIn,
authSetLastSeenMessages,
authPatchUser,
} from '~/redux/auth/actions';
import {
apiUserLogin,
@ -90,7 +91,7 @@ function* refreshUser() {
function* checkUserSaga({ key }: RehydrateAction) {
if (key !== 'auth') return;
yield call(refreshUser);
// yield put(authOpenProfile('gvorcek'));
yield put(authOpenProfile('gvorcek', 'settings'));
}
function* gotPostMessageSaga({ token }: ReturnType<typeof gotAuthPostMessage>) {
@ -256,6 +257,17 @@ function* setLastSeenMessages({ last_seen_messages }: ReturnType<typeof authSetL
yield call(reqWrapper, apiUpdateUser, { user: { last_seen_messages } });
}
function* patchUser({ user }: ReturnType<typeof authPatchUser>) {
const { error, data } = yield call(reqWrapper, apiUpdateUser, { user });
if (error || !data.user || data.errors) {
return yield put(authSetProfile({ patch_errors: data.errors }));
}
yield put(authSetUser(data.user));
yield put(authSetProfile({ user: { ...data.user }, tab: 'profile' }));
}
function* authSaga() {
yield takeLatest(REHYDRATE, checkUserSaga);
yield takeLatest([REHYDRATE, AUTH_USER_ACTIONS.LOGGED_IN], startPollingSaga);
@ -267,6 +279,7 @@ function* authSaga() {
yield takeLatest(AUTH_USER_ACTIONS.GET_MESSAGES, getMessages);
yield takeLatest(AUTH_USER_ACTIONS.SEND_MESSAGE, sendMessage);
yield takeLatest(AUTH_USER_ACTIONS.SET_LAST_SEEN_MESSAGES, setLastSeenMessages);
yield takeLatest(AUTH_USER_ACTIONS.PATCH_USER, patchUser);
}
export default authSaga;

View file

@ -46,5 +46,7 @@ export type IAuthState = Readonly<{
user: IUser;
messages: IMessage[];
messages_error: string;
patch_errors: Record<string, string>;
};
}>;