Skip to content

Commit adc7508

Browse files
author
haitaoo
committed
fix(Login): Dealing with external login links not jumping properly
1 parent 26ad0dd commit adc7508

File tree

3 files changed

+77
-89
lines changed

3 files changed

+77
-89
lines changed

ui/src/components/Header/index.tsx

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020

2121
import classnames from 'classnames';
2222

23-
import { floppyNavigation, userCenter } from '@/utils';
23+
import { userCenter } from '@/utils';
2424
import {
2525
loggedUserInfoStore,
2626
siteInfoStore,
@@ -29,7 +29,6 @@ import {
2929
themeSettingStore,
3030
} from '@/stores';
3131
import { logout, useQueryNotificationStatus } from '@/services';
32-
import { RouteAlias } from '@/router/alias';
3332

3433
import NavItems from './components/NavItems';
3534

@@ -73,19 +72,6 @@ const Header: FC = () => {
7372
clearUserStore();
7473
window.location.replace(window.location.href);
7574
};
76-
const onLoginClick = (evt) => {
77-
if (location.pathname === RouteAlias.login) {
78-
evt.preventDefault();
79-
window.location.reload();
80-
return;
81-
}
82-
if (floppyNavigation.shouldProcessLinkClick(evt)) {
83-
evt.preventDefault();
84-
floppyNavigation.navigateToLogin({
85-
handler: navigate,
86-
});
87-
}
88-
};
8975

9076
useEffect(() => {
9177
if (q) {
@@ -155,7 +141,6 @@ const Header: FC = () => {
155141
'link-light': navbarStyle === 'theme-colored',
156142
'link-primary': navbarStyle !== 'theme-colored',
157143
})}
158-
onClick={onLoginClick}
159144
href={userCenter.getLoginUrl()}>
160145
{t('btns.login')}
161146
</Button>
@@ -243,7 +228,6 @@ const Header: FC = () => {
243228
'link-light': navbarStyle === 'theme-colored',
244229
'link-primary': navbarStyle !== 'theme-colored',
245230
})}
246-
onClick={onLoginClick}
247231
href={userCenter.getLoginUrl()}>
248232
{t('btns.login')}
249233
</Button>

ui/src/pages/Users/Login/index.tsx

Lines changed: 75 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -175,86 +175,90 @@ const Index: React.FC = () => {
175175
return (
176176
<Container style={{ paddingTop: '4rem', paddingBottom: '5rem' }}>
177177
<WelcomeTitle />
178-
{step === 1 && canOriginalLogin ? (
178+
{step === 1 ? (
179179
<Col className="mx-auto" md={6} lg={4} xl={3}>
180180
{ucAgentInfo ? (
181181
<PluginUcLogin className="mb-5" />
182182
) : (
183183
<PluginOauth className="mb-5" />
184184
)}
185-
<Form noValidate onSubmit={handleSubmit}>
186-
<Form.Group controlId="email" className="mb-3">
187-
<Form.Label>{t('email.label')}</Form.Label>
188-
<Form.Control
189-
required
190-
tabIndex={1}
191-
type="email"
192-
value={formData.e_mail.value}
193-
isInvalid={formData.e_mail.isInvalid}
194-
onChange={(e) =>
195-
handleChange({
196-
e_mail: {
197-
value: e.target.value,
198-
isInvalid: false,
199-
errorMsg: '',
200-
},
201-
})
202-
}
203-
/>
204-
<Form.Control.Feedback type="invalid">
205-
{formData.e_mail.errorMsg}
206-
</Form.Control.Feedback>
207-
</Form.Group>
185+
{canOriginalLogin ? (
186+
<>
187+
<Form noValidate onSubmit={handleSubmit}>
188+
<Form.Group controlId="email" className="mb-3">
189+
<Form.Label>{t('email.label')}</Form.Label>
190+
<Form.Control
191+
required
192+
tabIndex={1}
193+
type="email"
194+
value={formData.e_mail.value}
195+
isInvalid={formData.e_mail.isInvalid}
196+
onChange={(e) =>
197+
handleChange({
198+
e_mail: {
199+
value: e.target.value,
200+
isInvalid: false,
201+
errorMsg: '',
202+
},
203+
})
204+
}
205+
/>
206+
<Form.Control.Feedback type="invalid">
207+
{formData.e_mail.errorMsg}
208+
</Form.Control.Feedback>
209+
</Form.Group>
208210

209-
<Form.Group controlId="password" className="mb-3">
210-
<div className="d-flex justify-content-between">
211-
<Form.Label>{t('password.label')}</Form.Label>
212-
<Link to="/users/account-recovery" tabIndex={2}>
213-
<small>{t('forgot_pass')}</small>
214-
</Link>
215-
</div>
211+
<Form.Group controlId="password" className="mb-3">
212+
<div className="d-flex justify-content-between">
213+
<Form.Label>{t('password.label')}</Form.Label>
214+
<Link to="/users/account-recovery" tabIndex={2}>
215+
<small>{t('forgot_pass')}</small>
216+
</Link>
217+
</div>
216218

217-
<Form.Control
218-
required
219-
tabIndex={1}
220-
type="password"
221-
// value={formData.pass.value}
222-
maxLength={32}
223-
isInvalid={formData.pass.isInvalid}
224-
onChange={(e) =>
225-
handleChange({
226-
pass: {
227-
value: e.target.value,
228-
isInvalid: false,
229-
errorMsg: '',
230-
},
231-
})
232-
}
233-
/>
234-
<Form.Control.Feedback type="invalid">
235-
{formData.pass.errorMsg}
236-
</Form.Control.Feedback>
237-
</Form.Group>
219+
<Form.Control
220+
required
221+
tabIndex={1}
222+
type="password"
223+
// value={formData.pass.value}
224+
maxLength={32}
225+
isInvalid={formData.pass.isInvalid}
226+
onChange={(e) =>
227+
handleChange({
228+
pass: {
229+
value: e.target.value,
230+
isInvalid: false,
231+
errorMsg: '',
232+
},
233+
})
234+
}
235+
/>
236+
<Form.Control.Feedback type="invalid">
237+
{formData.pass.errorMsg}
238+
</Form.Control.Feedback>
239+
</Form.Group>
238240

239-
<div className="d-grid">
240-
<Button variant="primary" type="submit" tabIndex={1}>
241-
{t('login', { keyPrefix: 'btns' })}
242-
</Button>
243-
</div>
244-
</Form>
245-
{loginSetting.allow_new_registrations && (
246-
<div className="text-center mt-5">
247-
<Trans i18nKey="login.info_sign" ns="translation">
248-
Don’t have an account?
249-
<Link
250-
to={userCenter.getSignUpUrl()}
251-
tabIndex={2}
252-
onClick={floppyNavigation.handleRouteLinkClick}>
253-
Sign up
254-
</Link>
255-
</Trans>
256-
</div>
257-
)}
241+
<div className="d-grid">
242+
<Button variant="primary" type="submit" tabIndex={1}>
243+
{t('login', { keyPrefix: 'btns' })}
244+
</Button>
245+
</div>
246+
</Form>
247+
{loginSetting.allow_new_registrations && (
248+
<div className="text-center mt-5">
249+
<Trans i18nKey="login.info_sign" ns="translation">
250+
Don’t have an account?
251+
<Link
252+
to={userCenter.getSignUpUrl()}
253+
tabIndex={2}
254+
onClick={floppyNavigation.handleRouteLinkClick}>
255+
Sign up
256+
</Link>
257+
</Trans>
258+
</div>
259+
)}
260+
</>
261+
) : null}
258262
</Col>
259263
) : null}
260264

ui/src/utils/floppyNavigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const navigate = (to: string | number, config: NavigateConfig = {}) => {
6262
* 2. Auto storage login redirect
6363
*/
6464
if (to === RouteAlias.login || to === getLoginUrl()) {
65-
if (equalToCurrentHref(RouteAlias.login)) {
65+
if (equalToCurrentHref(to)) {
6666
return;
6767
}
6868
storageLoginRedirect();

0 commit comments

Comments
 (0)