@@ -2,10 +2,11 @@ import { useQueryClient } from '@tanstack/react-query'
22import cs from 'classnames'
33import PropTypes from 'prop-types'
44import { Component , useEffect } from 'react'
5- import { useHistory } from 'react-router-dom'
5+ import { useHistory , useLocation } from 'react-router-dom'
66
77import config from 'config'
88
9+ import { useUser } from 'services/user'
910import A from 'ui/A'
1011import Button from 'ui/Button'
1112
@@ -67,11 +68,11 @@ const graphQLErrorToUI = {
6768 } ,
6869}
6970
70- export const NetworkErrorMessage = ( ) => {
71+ export const DocErrorMessage = ( { capitalize = true } ) => {
7172 if ( config . IS_SELF_HOSTED ) {
7273 return (
73- < p className = "my-4 px-3 sm:px-0" >
74- Please see{ ' ' }
74+ < >
75+ { capitalize ? ' Please' : 'please' } see{ ' ' }
7576 < A
7677 rel = "noreferrer"
7778 className = "text-ds-blue-default"
@@ -82,13 +83,13 @@ export const NetworkErrorMessage = () => {
8283 our docs
8384 </ A > { ' ' }
8485 for common support.
85- </ p >
86+ </ >
8687 )
8788 }
8889
8990 return (
90- < p className = "my-4 px-3 sm:px-0" >
91- Check on{ ' ' }
91+ < >
92+ { capitalize ? ' Check' : 'check' } on{ ' ' }
9293 < A
9394 rel = "noreferrer"
9495 className = "text-ds-blue-default"
@@ -109,13 +110,40 @@ export const NetworkErrorMessage = () => {
109110 our docs
110111 </ A > { ' ' }
111112 for common support.
113+ </ >
114+ )
115+ }
116+
117+ DocErrorMessage . propTypes = {
118+ capitalize : PropTypes . bool ,
119+ }
120+
121+ export const NetworkErrorMessage = ( { statusCode } ) => {
122+ if ( statusCode === 404 ) {
123+ return (
124+ < p className = "my-4 max-w-2xl px-3 text-center sm:px-0" >
125+ To view private repositories ensure you are logged in, you can also{ ' ' }
126+ < DocErrorMessage capitalize = { false } />
127+ </ p >
128+ )
129+ }
130+
131+ return (
132+ < p className = "my-4 max-w-2xl px-3 text-center sm:px-0" >
133+ < DocErrorMessage capitalize = { true } />
112134 </ p >
113135 )
114136}
115137
116- function ResetHandler ( { logoutUser = false , reset } ) {
138+ NetworkErrorMessage . propTypes = {
139+ statusCode : PropTypes . number ,
140+ }
141+
142+ function ResetHandler ( { logoutUser = false , reset, statusCode } ) {
117143 const queryClient = useQueryClient ( )
118144 const history = useHistory ( )
145+ const location = useLocation ( )
146+ const { data : user } = useUser ( )
119147
120148 useEffect ( ( ) => {
121149 let unMounted = false
@@ -148,17 +176,27 @@ function ResetHandler({ logoutUser = false, reset }) {
148176 }
149177
150178 return (
151- < div className = "my-4" >
179+ < div className = "my-4 flex items-center gap-2 " >
152180 < Button onClick = { logoutUser ? handleSignOut : handleReset } >
153181 { logoutUser ? 'Return to login' : 'Return to previous page' }
154182 </ Button >
183+ { /* if the user is logged in, we don't want to show the login button */ }
184+ { statusCode === 404 && ! user ? (
185+ < Button
186+ variant = "primary"
187+ to = { { pageName : 'login' , options : { to : location . pathname } } }
188+ >
189+ Login
190+ </ Button >
191+ ) : null }
155192 </ div >
156193 )
157194}
158195
159196ResetHandler . propTypes = {
160197 reset : PropTypes . func ,
161198 logoutUser : PropTypes . bool ,
199+ statusCode : PropTypes . number ,
162200}
163201
164202class NetworkErrorBoundary extends Component {
@@ -211,8 +249,11 @@ class NetworkErrorBoundary extends Component {
211249 src = { illustration }
212250 />
213251 < h1 className = "mt-6 text-2xl" > { title } </ h1 >
214- < NetworkErrorMessage />
215- < ResetHandler reset = { this . resetErrorBoundary } />
252+ < NetworkErrorMessage statusCode = { this . state . error . status } />
253+ < ResetHandler
254+ reset = { this . resetErrorBoundary }
255+ statusCode = { this . state . error . status }
256+ />
216257 </ article >
217258 )
218259 }
@@ -230,13 +271,14 @@ class NetworkErrorBoundary extends Component {
230271 />
231272 < h1 className = "mt-6 text-2xl" > { title } </ h1 >
232273 { description ? < p className = "mt-2" > { description ( data ) } </ p > : null }
233- { showDocs ? < NetworkErrorMessage /> : null }
274+ { showDocs ? < NetworkErrorMessage statusCode = { status } /> : null }
234275 < p >
235276 < strong > Error { status } </ strong >
236277 </ p >
237278 < ResetHandler
238279 logoutUser = { status === 429 }
239280 reset = { this . resetErrorBoundary }
281+ statusCode = { status }
240282 />
241283 </ article >
242284 )
0 commit comments