mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 12:56:41 +07:00
password restore dialog
This commit is contained in:
parent
0cfc6357b9
commit
078c531e93
14 changed files with 270 additions and 33 deletions
|
@ -87,7 +87,7 @@ export const authSetRestore = (restore: Partial<IAuthState['restore']>) => ({
|
|||
restore,
|
||||
});
|
||||
|
||||
export const authRestorePassword = (code: string) => ({
|
||||
type: AUTH_USER_ACTIONS.RESTORE_PASSWORD,
|
||||
export const authShowRestoreModal = (code: string) => ({
|
||||
type: AUTH_USER_ACTIONS.SHOW_RESTORE_MODAL,
|
||||
code,
|
||||
});
|
||||
|
|
|
@ -72,3 +72,9 @@ export const apiRequestRestoreCode = ({ field }): Promise<IResultWithStatus<{}>>
|
|||
.post(API.USER.REQUEST_CODE(), { field })
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
|
||||
export const apiCheckRestoreCode = ({ code }): Promise<IResultWithStatus<{}>> =>
|
||||
api
|
||||
.get(API.USER.REQUEST_CODE(code))
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
|
|
|
@ -21,7 +21,7 @@ export const AUTH_USER_ACTIONS = {
|
|||
|
||||
SET_RESTORE: 'SET_RESTORE',
|
||||
REQUEST_RESTORE_CODE: 'REQUEST_RESTORE_CODE',
|
||||
RESTORE_PASSWORD: 'RESTORE_PASSWORD',
|
||||
SHOW_RESTORE_MODAL: 'SHOW_RESTORE_MODAL',
|
||||
};
|
||||
|
||||
export const USER_ERRORS = {
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
authLoggedIn,
|
||||
authSetLastSeenMessages,
|
||||
authPatchUser,
|
||||
authRestorePassword,
|
||||
authShowRestoreModal,
|
||||
authSetRestore,
|
||||
authRequestRestoreCode,
|
||||
} from '~/redux/auth/actions';
|
||||
|
@ -27,6 +27,7 @@ import {
|
|||
apiAuthGetUpdates,
|
||||
apiUpdateUser,
|
||||
apiRequestRestoreCode,
|
||||
apiCheckRestoreCode,
|
||||
} from '~/redux/auth/api';
|
||||
import { modalSetShown, modalShowDialog } from '~/redux/modal/actions';
|
||||
import { selectToken, selectAuthProfile, selectAuthUser, selectAuthUpdates } from './selectors';
|
||||
|
@ -290,7 +291,7 @@ function* requestRestoreCode({ field }: ReturnType<typeof authRequestRestoreCode
|
|||
yield put(authSetRestore({ is_loading: false, is_succesfull: true }));
|
||||
}
|
||||
|
||||
function* restorePassword({ code }: ReturnType<typeof authRestorePassword>) {
|
||||
function* showRestoreModal({ code }: ReturnType<typeof authShowRestoreModal>) {
|
||||
if (!code && !code.length) {
|
||||
return yield put(
|
||||
authSetRestore({
|
||||
|
@ -299,6 +300,19 @@ function* restorePassword({ code }: ReturnType<typeof authRestorePassword>) {
|
|||
})
|
||||
);
|
||||
}
|
||||
|
||||
yield put(authSetRestore({ user: null, is_loading: true }));
|
||||
|
||||
const { error, data } = yield call(apiCheckRestoreCode, { code });
|
||||
|
||||
if (data.error || error || !data.user) {
|
||||
return yield put(
|
||||
authSetRestore({ is_loading: false, error: data.error || error || ERRORS.CODE_IS_INVALID })
|
||||
);
|
||||
}
|
||||
|
||||
yield put(modalShowDialog(DIALOGS.RESTORE_PASSWORD));
|
||||
yield put(authSetRestore({ user: data.user, is_loading: false }));
|
||||
}
|
||||
|
||||
function* authSaga() {
|
||||
|
@ -313,7 +327,7 @@ function* authSaga() {
|
|||
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);
|
||||
yield takeLatest(AUTH_USER_ACTIONS.RESTORE_PASSWORD, restorePassword);
|
||||
yield takeLatest(AUTH_USER_ACTIONS.SHOW_RESTORE_MODAL, showRestoreModal);
|
||||
yield takeLatest(AUTH_USER_ACTIONS.REQUEST_RESTORE_CODE, requestRestoreCode);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,4 @@
|
|||
import { ValueOf } from '~/redux/types';
|
||||
import { LoginDialog } from '~/containers/dialogs/LoginDialog';
|
||||
import { LoadingDialog } from '~/containers/dialogs/LoadingDialog';
|
||||
import { EditorDialogImage } from '~/containers/editors/EditorDialogImage';
|
||||
import { EditorDialogText } from '~/containers/editors/EditorDialogText';
|
||||
import { EditorDialogVideo } from '~/containers/editors/EditorDialogVideo';
|
||||
import { EditorDialogAudio } from '~/containers/editors/EditorDialogAudio';
|
||||
import { NODE_TYPES } from '../node/constants';
|
||||
import { TestDialog } from '~/containers/dialogs/TestDialog';
|
||||
import { ProfileDialog } from '~/containers/dialogs/ProfileDialog';
|
||||
import { RestoreRequestDialog } from '~/containers/dialogs/RestoreRequestDialog';
|
||||
|
||||
export const DIALOGS = {
|
||||
EDITOR_IMAGE: 'EDITOR_IMAGE',
|
||||
|
@ -19,6 +9,7 @@ export const DIALOGS = {
|
|||
LOADING: 'LOADING',
|
||||
PROFILE: 'PROFILE',
|
||||
RESTORE_REQUEST: 'RESTORE_REQUEST',
|
||||
RESTORE_PASSWORD: 'RESTORE_PASSWORD',
|
||||
TEST: 'TEST',
|
||||
};
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ export interface IModalState {
|
|||
}
|
||||
|
||||
const INITIAL_STATE: IModalState = {
|
||||
is_shown: true,
|
||||
dialog: DIALOGS.RESTORE_REQUEST,
|
||||
is_shown: false,
|
||||
dialog: null,
|
||||
};
|
||||
|
||||
export default createReducer(INITIAL_STATE, MODAL_HANDLERS);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { takeEvery, put } from 'redux-saga/effects';
|
||||
import { LocationChangeAction, LOCATION_CHANGE } from 'connected-react-router';
|
||||
import { authOpenProfile, authRestorePassword } from '../auth/actions';
|
||||
import { authOpenProfile, authShowRestoreModal } from '../auth/actions';
|
||||
|
||||
function* onPathChange({
|
||||
payload: {
|
||||
|
@ -14,7 +14,7 @@ function* onPathChange({
|
|||
|
||||
if (pathname.match(/^\/restore\/([\w\-]+)/)) {
|
||||
const [, code] = pathname.match(/^\/restore\/([\w\-]+)/);
|
||||
return yield put(authRestorePassword(code));
|
||||
return yield put(authShowRestoreModal(code));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue