mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
code restore process finished
This commit is contained in:
parent
078c531e93
commit
e227c9660e
6 changed files with 61 additions and 18 deletions
|
@ -44,7 +44,6 @@ const Component: FC<IProps> = ({ modal: { is_shown } }) => {
|
|||
<Route path={URLS.NODE_URL(':id')} component={NodeLayout} />
|
||||
<Route path={URLS.BORIS} component={BorisLayout} />
|
||||
<Route path={URLS.ERRORS.NOT_FOUND} component={ErrorNotFound} />
|
||||
<Route path="/restore/:code" component={ErrorNotFound} />
|
||||
|
||||
<Redirect to="/" />
|
||||
</Switch>
|
||||
|
|
|
@ -18,7 +18,7 @@ const mapStateToProps = state => ({
|
|||
restore: selectAuthRestore(state),
|
||||
});
|
||||
|
||||
const mapDispatchToProps = pick(['authRequestRestoreCode', 'authSetRestore'], AUTH_ACTIONS);
|
||||
const mapDispatchToProps = pick(['authRestorePassword', 'authSetRestore'], AUTH_ACTIONS);
|
||||
|
||||
type IProps = IDialogProps & ReturnType<typeof mapStateToProps> & typeof mapDispatchToProps & {};
|
||||
|
||||
|
@ -26,7 +26,7 @@ const RestorePasswordDialogUnconnected: FC<IProps> = ({
|
|||
restore: { error, is_loading, is_succesfull, user },
|
||||
authSetRestore,
|
||||
onRequestClose,
|
||||
authRequestRestoreCode,
|
||||
authRestorePassword,
|
||||
}) => {
|
||||
const [password, setPassword] = useState('');
|
||||
const [password_again, setPasswordAgain] = useState('');
|
||||
|
@ -41,11 +41,10 @@ const RestorePasswordDialogUnconnected: FC<IProps> = ({
|
|||
event.preventDefault();
|
||||
|
||||
if (doesnt_match) return;
|
||||
// if (!field) return;
|
||||
//
|
||||
// authRequestRestoreCode(field);
|
||||
|
||||
authRestorePassword(password);
|
||||
},
|
||||
[doesnt_match]
|
||||
[doesnt_match, authRestorePassword]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
|
@ -69,7 +68,8 @@ const RestorePasswordDialogUnconnected: FC<IProps> = ({
|
|||
<Group className={styles.shade}>
|
||||
<Icon icon="check" size={64} />
|
||||
|
||||
<div>Отлично, добро пожаловать домой!</div>
|
||||
<div>Пароль обновлен</div>
|
||||
<div>Добро пожаловать домой, ~{user.username}!</div>
|
||||
|
||||
<div />
|
||||
|
||||
|
|
|
@ -91,3 +91,8 @@ export const authShowRestoreModal = (code: string) => ({
|
|||
type: AUTH_USER_ACTIONS.SHOW_RESTORE_MODAL,
|
||||
code,
|
||||
});
|
||||
|
||||
export const authRestorePassword = (password: string) => ({
|
||||
type: AUTH_USER_ACTIONS.RESTORE_PASSWORD,
|
||||
password,
|
||||
});
|
||||
|
|
|
@ -78,3 +78,9 @@ export const apiCheckRestoreCode = ({ code }): Promise<IResultWithStatus<{}>> =>
|
|||
.get(API.USER.REQUEST_CODE(code))
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
|
||||
export const apiRestoreCode = ({ code, password }): Promise<IResultWithStatus<{}>> =>
|
||||
api
|
||||
.post(API.USER.REQUEST_CODE(code), { password })
|
||||
.then(resultMiddleware)
|
||||
.catch(errorMiddleware);
|
||||
|
|
|
@ -22,6 +22,7 @@ export const AUTH_USER_ACTIONS = {
|
|||
SET_RESTORE: 'SET_RESTORE',
|
||||
REQUEST_RESTORE_CODE: 'REQUEST_RESTORE_CODE',
|
||||
SHOW_RESTORE_MODAL: 'SHOW_RESTORE_MODAL',
|
||||
RESTORE_PASSWORD: 'RESTORE_PASSWORD',
|
||||
};
|
||||
|
||||
export const USER_ERRORS = {
|
||||
|
|
|
@ -17,6 +17,7 @@ import {
|
|||
authShowRestoreModal,
|
||||
authSetRestore,
|
||||
authRequestRestoreCode,
|
||||
authRestorePassword,
|
||||
} from '~/redux/auth/actions';
|
||||
import {
|
||||
apiUserLogin,
|
||||
|
@ -28,9 +29,16 @@ import {
|
|||
apiUpdateUser,
|
||||
apiRequestRestoreCode,
|
||||
apiCheckRestoreCode,
|
||||
apiRestoreCode,
|
||||
} from '~/redux/auth/api';
|
||||
import { modalSetShown, modalShowDialog } from '~/redux/modal/actions';
|
||||
import { selectToken, selectAuthProfile, selectAuthUser, selectAuthUpdates } from './selectors';
|
||||
import {
|
||||
selectToken,
|
||||
selectAuthProfile,
|
||||
selectAuthUser,
|
||||
selectAuthUpdates,
|
||||
selectAuthRestore,
|
||||
} from './selectors';
|
||||
import { IResultWithStatus, INotification, IMessageNotification } from '../types';
|
||||
import { IUser, IAuthState } from './types';
|
||||
import { REHYDRATE, RehydrateAction } from 'redux-persist';
|
||||
|
@ -293,12 +301,7 @@ function* requestRestoreCode({ field }: ReturnType<typeof authRequestRestoreCode
|
|||
|
||||
function* showRestoreModal({ code }: ReturnType<typeof authShowRestoreModal>) {
|
||||
if (!code && !code.length) {
|
||||
return yield put(
|
||||
authSetRestore({
|
||||
error: ERRORS.CODE_IS_INVALID,
|
||||
is_loading: false,
|
||||
})
|
||||
);
|
||||
return yield put(authSetRestore({ error: ERRORS.CODE_IS_INVALID, is_loading: false }));
|
||||
}
|
||||
|
||||
yield put(authSetRestore({ user: null, is_loading: true }));
|
||||
|
@ -306,13 +309,41 @@ function* showRestoreModal({ code }: ReturnType<typeof authShowRestoreModal>) {
|
|||
const { error, data } = yield call(apiCheckRestoreCode, { code });
|
||||
|
||||
if (data.error || error || !data.user) {
|
||||
yield put(
|
||||
authSetRestore({ is_loading: false, error: data.error || error || ERRORS.CODE_IS_INVALID })
|
||||
);
|
||||
|
||||
return yield put(modalShowDialog(DIALOGS.RESTORE_PASSWORD));
|
||||
}
|
||||
|
||||
yield put(authSetRestore({ user: data.user, code, is_loading: false }));
|
||||
yield put(modalShowDialog(DIALOGS.RESTORE_PASSWORD));
|
||||
}
|
||||
|
||||
function* restorePassword({ password }: ReturnType<typeof authRestorePassword>) {
|
||||
if (!password) return;
|
||||
|
||||
yield put(authSetRestore({ is_loading: true }));
|
||||
const { code } = yield select(selectAuthRestore);
|
||||
|
||||
if (!code) {
|
||||
return yield put(authSetRestore({ error: ERRORS.CODE_IS_INVALID, is_loading: false }));
|
||||
}
|
||||
|
||||
const { error, data } = yield call(apiRestoreCode, { code, password });
|
||||
|
||||
if (data.error || error || !data.user || !data.token) {
|
||||
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 }));
|
||||
yield put(authSetToken(data.token));
|
||||
yield put(authSetUser(data.user));
|
||||
|
||||
yield put(authSetRestore({ is_loading: false, is_succesfull: true, error: null }));
|
||||
|
||||
yield call(refreshUser);
|
||||
}
|
||||
|
||||
function* authSaga() {
|
||||
|
@ -327,8 +358,9 @@ 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.SHOW_RESTORE_MODAL, showRestoreModal);
|
||||
yield takeLatest(AUTH_USER_ACTIONS.REQUEST_RESTORE_CODE, requestRestoreCode);
|
||||
yield takeLatest(AUTH_USER_ACTIONS.SHOW_RESTORE_MODAL, showRestoreModal);
|
||||
yield takeLatest(AUTH_USER_ACTIONS.RESTORE_PASSWORD, restorePassword);
|
||||
}
|
||||
|
||||
export default authSaga;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue