mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
added request code dialog
This commit is contained in:
parent
c0c832d158
commit
6dcb21e9e4
18 changed files with 292 additions and 88 deletions
|
@ -77,6 +77,11 @@ export const authPatchUser = (user: Partial<IUser>) => ({
|
|||
user,
|
||||
});
|
||||
|
||||
export const authRequestRestoreCode = (field: string) => ({
|
||||
type: AUTH_USER_ACTIONS.REQUEST_RESTORE_CODE,
|
||||
field,
|
||||
});
|
||||
|
||||
export const authSetRestore = (restore: Partial<IAuthState['restore']>) => ({
|
||||
type: AUTH_USER_ACTIONS.SET_RESTORE,
|
||||
restore,
|
||||
|
|
|
@ -1,17 +1,12 @@
|
|||
import {
|
||||
api,
|
||||
errorMiddleware,
|
||||
resultMiddleware,
|
||||
configWithToken
|
||||
} from "~/utils/api";
|
||||
import { API } from "~/constants/api";
|
||||
import { IResultWithStatus, IMessage } from "~/redux/types";
|
||||
import { userLoginTransform } from "~/redux/auth/transforms";
|
||||
import { IUser } from "./types";
|
||||
import { api, errorMiddleware, resultMiddleware, configWithToken } from '~/utils/api';
|
||||
import { API } from '~/constants/api';
|
||||
import { IResultWithStatus, IMessage } from '~/redux/types';
|
||||
import { userLoginTransform } from '~/redux/auth/transforms';
|
||||
import { IUser } from './types';
|
||||
|
||||
export const apiUserLogin = ({
|
||||
username,
|
||||
password
|
||||
password,
|
||||
}: {
|
||||
username: string;
|
||||
password: string;
|
||||
|
@ -22,9 +17,7 @@ export const apiUserLogin = ({
|
|||
.catch(errorMiddleware)
|
||||
.then(userLoginTransform);
|
||||
|
||||
export const apiAuthGetUser = ({
|
||||
access
|
||||
}): Promise<IResultWithStatus<{ user: IUser }>> =>
|
||||
export const apiAuthGetUser = ({ access }): Promise<IResultWithStatus<{ user: IUser }>> =>
|
||||
api
|
||||
.get(API.USER.ME, configWithToken(access))
|
||||
.then(resultMiddleware)
|
||||
|
@ -32,7 +25,7 @@ export const apiAuthGetUser = ({
|
|||
|
||||
export const apiAuthGetUserProfile = ({
|
||||
access,
|
||||
username
|
||||
username,
|
||||
}): Promise<IResultWithStatus<{ user: IUser }>> =>
|
||||
api
|
||||
.get(API.USER.PROFILE(username), configWithToken(access))
|
||||
|
@ -41,7 +34,7 @@ export const apiAuthGetUserProfile = ({
|
|||
|
||||
export const apiAuthGetUserMessages = ({
|
||||
access,
|
||||
username
|
||||
username,
|
||||
}): Promise<IResultWithStatus<{ messages: IMessage[] }>> =>
|
||||
api
|
||||
.get(API.USER.MESSAGES(username), configWithToken(access))
|
||||
|
@ -51,7 +44,7 @@ export const apiAuthGetUserMessages = ({
|
|||
export const apiAuthSendMessage = ({
|
||||
access,
|
||||
username,
|
||||
message
|
||||
message,
|
||||
}): Promise<IResultWithStatus<{ message: IMessage }>> =>
|
||||
api
|
||||
.post(API.USER.MESSAGE_SEND(username), { message }, configWithToken(access))
|
||||
|
@ -61,21 +54,21 @@ export const apiAuthSendMessage = ({
|
|||
export const apiAuthGetUpdates = ({
|
||||
access,
|
||||
exclude_dialogs,
|
||||
last
|
||||
last,
|
||||
}): Promise<IResultWithStatus<{ message: IMessage }>> =>
|
||||
api
|
||||
.get(
|
||||
API.USER.GET_UPDATES,
|
||||
configWithToken(access, { params: { exclude_dialogs, last } })
|
||||
)
|
||||
.get(API.USER.GET_UPDATES, configWithToken(access, { params: { exclude_dialogs, last } }))
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
|
||||
export const apiUpdateUser = ({
|
||||
access,
|
||||
user
|
||||
}): Promise<IResultWithStatus<{ user: IUser }>> =>
|
||||
export const apiUpdateUser = ({ access, user }): Promise<IResultWithStatus<{ user: IUser }>> =>
|
||||
api
|
||||
.patch(API.USER.ME, { user }, configWithToken(access))
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
|
||||
export const apiRequestRestoreCode = ({ field }): Promise<IResultWithStatus<{}>> =>
|
||||
api
|
||||
.post(API.USER.REQUEST_CODE(), { field })
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
|
|
|
@ -20,6 +20,7 @@ export const AUTH_USER_ACTIONS = {
|
|||
PATCH_USER: 'PATCH_USER',
|
||||
|
||||
SET_RESTORE: 'SET_RESTORE',
|
||||
REQUEST_RESTORE_CODE: 'REQUEST_RESTORE_CODE',
|
||||
RESTORE_PASSWORD: 'RESTORE_PASSWORD',
|
||||
};
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ const INITIAL_STATE: IAuthState = {
|
|||
user: null,
|
||||
is_loading: false,
|
||||
is_succesfull: false,
|
||||
errors: {},
|
||||
error: null,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
authPatchUser,
|
||||
authRestorePassword,
|
||||
authSetRestore,
|
||||
authRequestRestoreCode,
|
||||
} from '~/redux/auth/actions';
|
||||
import {
|
||||
apiUserLogin,
|
||||
|
@ -25,6 +26,7 @@ import {
|
|||
apiAuthSendMessage,
|
||||
apiAuthGetUpdates,
|
||||
apiUpdateUser,
|
||||
apiRequestRestoreCode,
|
||||
} from '~/redux/auth/api';
|
||||
import { modalSetShown, modalShowDialog } from '~/redux/modal/actions';
|
||||
import { selectToken, selectAuthProfile, selectAuthUser, selectAuthUpdates } from './selectors';
|
||||
|
@ -275,11 +277,26 @@ function* patchUser({ user }: ReturnType<typeof authPatchUser>) {
|
|||
yield put(authSetProfile({ user: { ...me, ...data.user }, tab: 'profile' }));
|
||||
}
|
||||
|
||||
function* requestRestoreCode({ field }: ReturnType<typeof authRequestRestoreCode>) {
|
||||
if (!field) return;
|
||||
|
||||
yield put(authSetRestore({ error: null, is_loading: true }));
|
||||
const { error, data } = yield call(apiRequestRestoreCode, { field });
|
||||
|
||||
console.log(data);
|
||||
|
||||
if (data.error || error) {
|
||||
return yield put(authSetRestore({ is_loading: false, error: data.error || error }));
|
||||
}
|
||||
|
||||
yield put(authSetRestore({ is_loading: false, is_succesfull: true }));
|
||||
}
|
||||
|
||||
function* restorePassword({ code }: ReturnType<typeof authRestorePassword>) {
|
||||
if (!code && !code.length) {
|
||||
return yield put(
|
||||
authSetRestore({
|
||||
errors: { code: ERRORS.CODE_IS_INVALID },
|
||||
error: ERRORS.CODE_IS_INVALID,
|
||||
is_loading: false,
|
||||
})
|
||||
);
|
||||
|
@ -300,6 +317,7 @@ function* authSaga() {
|
|||
yield takeLatest(AUTH_USER_ACTIONS.SET_LAST_SEEN_MESSAGES, setLastSeenMessages);
|
||||
yield takeLatest(AUTH_USER_ACTIONS.PATCH_USER, patchUser);
|
||||
yield takeLatest(AUTH_USER_ACTIONS.RESTORE_PASSWORD, restorePassword);
|
||||
yield takeLatest(AUTH_USER_ACTIONS.REQUEST_RESTORE_CODE, requestRestoreCode);
|
||||
}
|
||||
|
||||
export default authSaga;
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
import { IState } from '~/redux/store';
|
||||
|
||||
export const selectAuth = (state: IState): IState['auth'] => state.auth;
|
||||
export const selectUser = (state: IState): IState['auth']['user'] => state.auth.user;
|
||||
export const selectToken = (state: IState): IState['auth']['token'] => state.auth.token;
|
||||
export const selectAuthLogin = (state: IState): IState['auth']['login'] => state.auth.login;
|
||||
export const selectAuthProfile = (state: IState): IState['auth']['profile'] => state.auth.profile;
|
||||
export const selectAuthUser = (state: IState): IState['auth']['user'] => state.auth.user;
|
||||
export const selectAuthUpdates = (state: IState): IState['auth']['updates'] => state.auth.updates;
|
||||
export const selectAuth = (state: IState) => state.auth;
|
||||
export const selectUser = (state: IState) => state.auth.user;
|
||||
export const selectToken = (state: IState) => state.auth.token;
|
||||
export const selectAuthLogin = (state: IState) => state.auth.login;
|
||||
export const selectAuthProfile = (state: IState) => state.auth.profile;
|
||||
export const selectAuthUser = (state: IState) => state.auth.user;
|
||||
export const selectAuthUpdates = (state: IState) => state.auth.updates;
|
||||
export const selectAuthRestore = (state: IState) => state.auth.restore;
|
||||
|
|
|
@ -55,6 +55,6 @@ export type IAuthState = Readonly<{
|
|||
user: Pick<IUser, 'username' | 'photo'>;
|
||||
is_loading: boolean;
|
||||
is_succesfull: boolean;
|
||||
errors: Record<string, string>;
|
||||
error: string;
|
||||
};
|
||||
}>;
|
||||
|
|
|
@ -9,8 +9,8 @@ export interface IModalState {
|
|||
}
|
||||
|
||||
const INITIAL_STATE: IModalState = {
|
||||
is_shown: false,
|
||||
dialog: null,
|
||||
is_shown: true,
|
||||
dialog: DIALOGS.RESTORE_REQUEST,
|
||||
};
|
||||
|
||||
export default createReducer(INITIAL_STATE, MODAL_HANDLERS);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue