File tree Expand file tree Collapse file tree 4 files changed +32
-8
lines changed Expand file tree Collapse file tree 4 files changed +32
-8
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ import { SUBMIT_NEWS_ITEM_MUTATION } from '../src/data/mutations/submit-news-ite
1010import { withDataAndRouter } from '../src/helpers/with-data' ;
1111import { MainLayout } from '../src/layouts/main-layout' ;
1212
13+ import { ErrorAction } from '../src/components/error-action' ;
14+
1315interface ISubmitPageProps {
1416 router ;
1517}
@@ -22,11 +24,16 @@ function SubmitPage(props: ISubmitPageProps): JSX.Element {
2224 const [ url , setUrl ] = useState < string > ( '' ) ;
2325 const [ text , setText ] = useState < string > ( '' ) ;
2426 const [ submitValidationMessage , setSubmitValidationMessage ] = useState < string > ( '' ) ;
27+ const [ notLoggedIn , setNotLoggedIn ] = React . useState ( false ) ;
28+
29+ const onCancel = ( ) => {
30+ setNotLoggedIn ( false ) ;
31+ }
2532
2633 const validateSubmit = ( e : React . FormEvent < HTMLFormElement > ) : void => {
2734 if ( ! ( data ?. me ) ) {
2835 e . preventDefault ( ) ;
29- Router . push ( '/login' ) ;
36+ setNotLoggedIn ( true ) ;
3037 } else {
3138 try {
3239 validateTitle ( { title} ) ;
@@ -47,6 +54,7 @@ function SubmitPage(props: ISubmitPageProps): JSX.Element {
4754 }
4855 } ,
4956 onError ( err ) {
57+
5058 console . error ( err ) ;
5159 } ,
5260 } ) ;
@@ -58,6 +66,8 @@ function SubmitPage(props: ISubmitPageProps): JSX.Element {
5866 isNavVisible = { true }
5967 isFooterVisible = { true }
6068 >
69+ < React . Fragment >
70+ < div > < ErrorAction onNotLoggedIn = { notLoggedIn } onCancel = { onCancel } /> </ div >
6171 < tr >
6272 < td >
6373 < form onSubmit = { ( e ) : void => validateSubmit ( e ) } >
@@ -164,6 +174,7 @@ function SubmitPage(props: ISubmitPageProps): JSX.Element {
164174 </ form >
165175 </ td >
166176 </ tr >
177+ </ React . Fragment >
167178 </ MainLayout >
168179 ) ;
169180}
Original file line number Diff line number Diff line change @@ -40,8 +40,6 @@ export interface IUserPageQuery {
4040function UserPage ( props : IUserPageProps ) : JSX . Element {
4141 const { router } = props ;
4242
43- console . log ( router ) ;
44-
4543 const userId = ( router . query && router . query . id ) || '' ;
4644
4745 const { data } = useQuery < IUserPageQuery > ( query , { variables : { id : userId } } ) ;
Original file line number Diff line number Diff line change @@ -3,13 +3,24 @@ import { useRouter } from 'next/router';
33import Modal from 'react-bootstrap/Modal'
44import "bootstrap/dist/css/bootstrap.min.css" ;
55
6- export function ErrorAction ( ) : JSX . Element {
7-
8- const [ show , setShow ] = React . useState ( true ) ;
6+ export interface IErrorActionProps {
7+ onCancel : any ;
8+ onNotLoggedIn : boolean ;
9+ }
910
11+ export function ErrorAction ( props : IErrorActionProps ) : JSX . Element {
12+ const { onCancel, onNotLoggedIn } = props ;
13+ const [ show , setShow ] = React . useState ( onNotLoggedIn ) ;
1014 const router = useRouter ( ) ;
15+
16+ React . useEffect ( ( ) => {
17+ setShow ( onNotLoggedIn ) ;
18+ } , [ onNotLoggedIn ] ) ;
1119
12- const handleClose = ( ) => setShow ( false ) ;
20+ const handleClose = ( ) => {
21+ setShow ( false ) ;
22+ onCancel ( ) ;
23+ } ;
1324
1425 const handleLogin = ( ) => {
1526 router . push ( `/login?goto=${ router . pathname } ` ) ;
Original file line number Diff line number Diff line change @@ -30,6 +30,10 @@ export function NewsTitle(props: INewsTitleProps): JSX.Element {
3030
3131 const [ notLoggedIn , setNotLoggedIn ] = React . useState ( false ) ;
3232
33+ const onCancel = ( ) => {
34+ setNotLoggedIn ( false ) ;
35+ }
36+
3337 const [ upvoteNewsItem ] = useMutation ( UPVOTE_NEWS_ITEM_MUTATION , {
3438 onError : ( ) => {
3539 setNotLoggedIn ( true ) ;
@@ -54,7 +58,7 @@ export function NewsTitle(props: INewsTitleProps): JSX.Element {
5458 </ a >
5559 ) }
5660 </ div >
57- < div > { notLoggedIn && ( < ErrorAction /> ) } </ div >
61+ < div > < ErrorAction onNotLoggedIn = { notLoggedIn } onCancel = { onCancel } /> </ div >
5862 </ td >
5963 < td className = "title" >
6064 < a className = "storylink" target = "_blank" href = { url || `item?id=${ id } ` } >
You can’t perform that action at this time.
0 commit comments