From e02d5142e5d913757585176900d0641b9692d7cc Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 21 Mar 2022 15:23:57 -0400 Subject: [PATCH] Properly handle navigating to previous page if 'backHref' is undefined --- app/soapbox/components/ui/column/column.tsx | 22 ++- app/soapbox/features/edit_profile/index.js | 170 ++++++++++---------- 2 files changed, 99 insertions(+), 93 deletions(-) diff --git a/app/soapbox/components/ui/column/column.tsx b/app/soapbox/components/ui/column/column.tsx index a9c5f0d2e..08ef17b9a 100644 --- a/app/soapbox/components/ui/column/column.tsx +++ b/app/soapbox/components/ui/column/column.tsx @@ -1,10 +1,11 @@ import React from 'react'; +import { RouteComponentProps, withRouter } from 'react-router-dom'; import Helmet from 'soapbox/components/helmet'; import { Card, CardBody, CardHeader, CardTitle } from '../card/card'; -interface IColumn { +interface IColumn extends RouteComponentProps { backHref?: string, label?: string, transparent?: boolean, @@ -12,7 +13,20 @@ interface IColumn { } const Column: React.FC = React.forwardRef((props, ref: React.ForwardedRef): JSX.Element => { - const { backHref, children, label, transparent = false, withHeader = true } = props; + const { backHref, children, label, history, transparent = false, withHeader = true } = props; + + const handleBackClick = () => { + if (backHref) { + history.push(backHref); + return; + } + + if (history.length === 1) { + history.push('/'); + } else { + history.goBack(); + } + }; const renderChildren = () => { if (transparent) { @@ -22,7 +36,7 @@ const Column: React.FC = React.forwardRef((props, ref: React.ForwardedR return ( {withHeader ? ( - + ) : null} @@ -43,4 +57,4 @@ const Column: React.FC = React.forwardRef((props, ref: React.ForwardedR ); }); -export default Column; +export default withRouter(Column); diff --git a/app/soapbox/features/edit_profile/index.js b/app/soapbox/features/edit_profile/index.js index 4939bd13e..008711462 100644 --- a/app/soapbox/features/edit_profile/index.js +++ b/app/soapbox/features/edit_profile/index.js @@ -22,7 +22,7 @@ import { makeGetAccount } from 'soapbox/selectors'; import { getFeatures } from 'soapbox/utils/features'; import resizeImage from 'soapbox/utils/resize_image'; -import { Button, Card, CardBody, CardHeader, CardTitle, Column, Form, FormActions, FormGroup, Input, Textarea } from '../../components/ui'; +import { Button, Column, Form, FormActions, FormGroup, Input, Textarea } from '../../components/ui'; import ProfilePreview from './components/profile_preview'; @@ -246,82 +246,76 @@ class EditProfile extends ImmutablePureComponent { const canEditName = verifiedCanEditName || !verified; return ( - - - - - + +
+ } + hintText={!canEditName && intl.formatMessage(messages.verified)} + > + + - - + } + > + + + + } + > + + + + } + > +