Fixed one more usecase, simplified the code

main
Boris Sekachev 5 years ago
parent 9bca53577e
commit ccaca4526d

@ -40,7 +40,7 @@ export const authActions = {
authorizeSuccess: (user: any) => createAction(AuthActionTypes.AUTHORIZED_SUCCESS, { user }),
authorizeFailed: (error: any) => createAction(AuthActionTypes.AUTHORIZED_FAILED, { error }),
login: () => createAction(AuthActionTypes.LOGIN),
loginSuccess: (user: any, next: string | null) => createAction(AuthActionTypes.LOGIN_SUCCESS, { user, next }),
loginSuccess: (user: any) => createAction(AuthActionTypes.LOGIN_SUCCESS, { user }),
loginFailed: (error: any) => createAction(AuthActionTypes.LOGIN_FAILED, { error }),
register: () => createAction(AuthActionTypes.REGISTER),
registerSuccess: (user: any) => createAction(AuthActionTypes.REGISTER_SUCCESS, { user }),
@ -98,16 +98,14 @@ export const registerAsync = (
}
};
export const loginAsync = (username: string, password: string, next: string | null): ThunkAction => async (
dispatch,
) => {
export const loginAsync = (username: string, password: string): ThunkAction => async (dispatch) => {
dispatch(authActions.login());
try {
await cvat.server.login(username, password);
const users = await cvat.users.get({ self: true });
dispatch(authActions.loginSuccess(users[0], next));
dispatch(authActions.loginSuccess(users[0]));
} catch (error) {
dispatch(authActions.loginFailed(error));
}

@ -64,7 +64,6 @@ interface CVATAppProps {
authActionsInitialized: boolean;
notifications: NotificationsState;
user: any;
next: string | null;
isModelPluginActive: boolean;
}
@ -238,7 +237,6 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
switchShortcutsDialog,
switchSettingsDialog,
user,
next,
keyMap,
location,
isModelPluginActive,
@ -320,7 +318,10 @@ class CVATApplication extends React.PureComponent<CVATAppProps & RouteComponentP
{isModelPluginActive && (
<Route exact path='/models' component={ModelsPageContainer} />
)}
<Redirect push to={next || '/tasks'} />
<Redirect
push
to={new URLSearchParams(location.search).get('next') || '/tasks'}
/>
</Switch>
</GlobalHotKeys>
{/* eslint-disable-next-line */}

@ -15,7 +15,6 @@ import CookieDrawer from './cookie-policy-drawer';
interface LoginPageComponentProps {
fetching: boolean;
renderResetPassword: boolean;
next: string;
onLogin: (username: string, password: string, next: string | null) => void;
}
@ -28,11 +27,7 @@ function LoginPageComponent(props: LoginPageComponentProps & RouteComponentProps
xl: { span: 4 },
};
const {
fetching, onLogin, renderResetPassword, location,
} = props;
const search = new URLSearchParams(location.search);
const { fetching, onLogin, renderResetPassword } = props;
return (
<>
@ -42,7 +37,7 @@ function LoginPageComponent(props: LoginPageComponentProps & RouteComponentProps
<LoginForm
fetching={fetching}
onSubmit={(loginData: LoginData): void => {
onLogin(loginData.username, loginData.password, search.get('next'));
onLogin(loginData.username, loginData.password);
}}
/>
<Row type='flex' justify='start' align='top'>

@ -26,7 +26,7 @@ export default function LoginWithTokenComponent(): JSX.Element {
);
if (cookies.sessionid && cookies.csrftoken) {
return <Redirect to={search.has('next') ? (search.get('next') as string) : '/tasks'} />;
return <Redirect to={search.get('next') || '/tasks'} />;
}
return <></>;
}

@ -45,7 +45,6 @@ interface StateToProps {
allowResetPassword: boolean;
notifications: NotificationsState;
user: any;
next: string | null;
keyMap: Record<string, ExtendedKeyMapOptions>;
isModelPluginActive: boolean;
}
@ -92,7 +91,6 @@ function mapStateToProps(state: CombinedState): StateToProps {
allowResetPassword: auth.allowResetPassword,
notifications: state.notifications,
user: auth.user,
next: auth.next,
keyMap: shortcuts.keyMap,
isModelPluginActive: plugins.list.MODELS,
};

@ -10,7 +10,6 @@ const defaultState: AuthState = {
initialized: false,
fetching: false,
user: null,
next: null,
authActionsFetching: false,
authActionsInitialized: false,
allowChangePassword: false,
@ -41,7 +40,6 @@ export default function (state = defaultState, action: AuthActions | BoundariesA
...state,
fetching: false,
user: action.payload.user,
next: action.payload.next,
};
case AuthActionTypes.LOGIN_FAILED:
return {

@ -14,7 +14,6 @@ export interface AuthState {
initialized: boolean;
fetching: boolean;
user: any;
next: string | null;
authActionsFetching: boolean;
authActionsInitialized: boolean;
showChangePasswordDialog: boolean;

Loading…
Cancel
Save