ReportContent: redirect back after logging in (#1733)
## Issue 1709 - If you sign in while reporting, you end up in the homepage ## Notes The other option is to just make `<Header>` always redirect back to where it came from using the full path. But existing code elsewhere seem to always trim off any params (e.g. `location.search`, `location.hash`) when doing redirects. So, ended up making it generic and let the caller decide where to redirect (and with what params).
This commit is contained in:
parent
9e4ac047ca
commit
63a2430a7c
3 changed files with 23 additions and 2 deletions
|
@ -21,6 +21,7 @@ import WunderBar from 'component/wunderbar';
|
||||||
type Props = {
|
type Props = {
|
||||||
authenticated: boolean,
|
authenticated: boolean,
|
||||||
authHeader: boolean,
|
authHeader: boolean,
|
||||||
|
authRedirect?: string, // Redirects to '/' by default.
|
||||||
backout: {
|
backout: {
|
||||||
backLabel?: string,
|
backLabel?: string,
|
||||||
backNavDefault?: string,
|
backNavDefault?: string,
|
||||||
|
@ -56,6 +57,7 @@ const Header = (props: Props) => {
|
||||||
const {
|
const {
|
||||||
authenticated,
|
authenticated,
|
||||||
authHeader,
|
authHeader,
|
||||||
|
authRedirect,
|
||||||
backout,
|
backout,
|
||||||
balance,
|
balance,
|
||||||
emailToVerify,
|
emailToVerify,
|
||||||
|
@ -106,6 +108,8 @@ const Header = (props: Props) => {
|
||||||
? __('Close sidebar - hide channels you are following.')
|
? __('Close sidebar - hide channels you are following.')
|
||||||
: __('Expand sidebar - view channels you are following.');
|
: __('Expand sidebar - view channels you are following.');
|
||||||
|
|
||||||
|
const authRedirectParam = authRedirect ? `?redirect=${authRedirect}` : '';
|
||||||
|
|
||||||
const onBackout = React.useCallback(
|
const onBackout = React.useCallback(
|
||||||
(e: any) => {
|
(e: any) => {
|
||||||
const { hasNavigated } = props;
|
const { hasNavigated } = props;
|
||||||
|
@ -169,8 +173,18 @@ const Header = (props: Props) => {
|
||||||
</>
|
</>
|
||||||
) : !isMobile ? (
|
) : !isMobile ? (
|
||||||
<div className="header__authButtons">
|
<div className="header__authButtons">
|
||||||
<Button navigate={`/$/${PAGES.AUTH_SIGNIN}`} button="link" label={__('Log In')} disabled={user === null} />
|
<Button
|
||||||
<Button navigate={`/$/${PAGES.AUTH}`} button="primary" label={__('Sign Up')} disabled={user === null} />
|
navigate={`/$/${PAGES.AUTH_SIGNIN}${authRedirectParam}`}
|
||||||
|
button="link"
|
||||||
|
label={__('Log In')}
|
||||||
|
disabled={user === null}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
navigate={`/$/${PAGES.AUTH}${authRedirectParam}`}
|
||||||
|
button="primary"
|
||||||
|
label={__('Sign Up')}
|
||||||
|
disabled={user === null}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<HeaderProfileMenuButton />
|
<HeaderProfileMenuButton />
|
||||||
|
|
|
@ -17,6 +17,7 @@ const Footer = lazyImport(() => import('web/component/footer' /* webpackChunkNam
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
authPage: boolean,
|
authPage: boolean,
|
||||||
|
authRedirect?: string, // Redirects to '/' by default.
|
||||||
backout: {
|
backout: {
|
||||||
backLabel?: string,
|
backLabel?: string,
|
||||||
backNavDefault?: string,
|
backNavDefault?: string,
|
||||||
|
@ -43,6 +44,7 @@ type Props = {
|
||||||
function Page(props: Props) {
|
function Page(props: Props) {
|
||||||
const {
|
const {
|
||||||
authPage = false,
|
authPage = false,
|
||||||
|
authRedirect,
|
||||||
backout,
|
backout,
|
||||||
chatDisabled,
|
chatDisabled,
|
||||||
children,
|
children,
|
||||||
|
@ -95,6 +97,7 @@ function Page(props: Props) {
|
||||||
{!noHeader && (
|
{!noHeader && (
|
||||||
<Header
|
<Header
|
||||||
authHeader={authPage}
|
authHeader={authPage}
|
||||||
|
authRedirect={authRedirect}
|
||||||
backout={backout}
|
backout={backout}
|
||||||
sidebarOpen={sidebarOpen}
|
sidebarOpen={sidebarOpen}
|
||||||
isAbsoluteSideNavHidden={isAbsoluteSideNavHidden}
|
isAbsoluteSideNavHidden={isAbsoluteSideNavHidden}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
// @flow
|
// @flow
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { useHistory } from 'react-router';
|
||||||
import Page from 'component/page';
|
import Page from 'component/page';
|
||||||
import ReportContent from 'component/reportContent';
|
import ReportContent from 'component/reportContent';
|
||||||
|
|
||||||
export default function ReportContentPage(props: any) {
|
export default function ReportContentPage(props: any) {
|
||||||
|
const { location } = useHistory();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page
|
<Page
|
||||||
noSideNavigation
|
noSideNavigation
|
||||||
|
@ -12,6 +15,7 @@ export default function ReportContentPage(props: any) {
|
||||||
backoutLabel: __('Done'),
|
backoutLabel: __('Done'),
|
||||||
title: __('Report content'),
|
title: __('Report content'),
|
||||||
}}
|
}}
|
||||||
|
authRedirect={`${location.pathname}${location.search}`} // 'report_content?claimId=xxx'
|
||||||
>
|
>
|
||||||
<ReportContent />
|
<ReportContent />
|
||||||
</Page>
|
</Page>
|
||||||
|
|
Loading…
Reference in a new issue