Skip to content

Commit 8eb8c08

Browse files
committed
Code refactoring
1 parent 7628335 commit 8eb8c08

File tree

1 file changed

+48
-42
lines changed

1 file changed

+48
-42
lines changed

src/App.tsx

Lines changed: 48 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,33 @@ export default function App() {
127127

128128
useEffect(() => {
129129
// If not K8S_CLIENT then validateToken otherwise directly redirect
130+
async function validation() {
131+
try {
132+
await validateToken()
133+
defaultRedirection()
134+
} catch (err: any) {
135+
// push to login without breaking search
136+
if (err?.code === 401) {
137+
const loginPath = URLS.LOGIN_SSO
138+
const newSearch = location.pathname.includes(URLS.LOGIN_SSO)
139+
? location.search
140+
: `?continue=${location.pathname}`
141+
push(`${loginPath}${newSearch}`)
142+
} else {
143+
setErrorPage(true)
144+
showError(err)
145+
}
146+
} finally {
147+
setValidating(false)
148+
}
149+
}
130150
if (!window._env_.K8S_CLIENT) {
131151
// Pass validation for direct email approval notification
132-
if (location.pathname && location.pathname.includes('approve')) {
133-
redirectToDirectApprovalNotification()
134-
} else {
135-
validation()
136-
}
152+
// if (location.pathname && location.pathname.includes('approve')) {
153+
// redirectToDirectApprovalNotification()
154+
// } else {
155+
validation()
156+
// }
137157
} else {
138158
setValidating(false)
139159
defaultRedirection()
@@ -229,29 +249,6 @@ export default function App() {
229249
}
230250
}, [bgUpdated])
231251

232-
const renderFirstNavigatedPage = () => {
233-
if (location.pathname && location.pathname.includes('approve')) {
234-
console.log(`${approvalType?.toLocaleLowerCase()}/approve?token=${approvalToken}`)
235-
return (
236-
<Route
237-
exact
238-
path={`/${approvalType?.toLocaleLowerCase()}/approve`}
239-
render={() =>
240-
GenericDirectApprovalModal && <GenericDirectApprovalModal approvalType={approvalType} />
241-
}
242-
/>
243-
)
244-
} else {
245-
return (
246-
<>
247-
{!window._env_.K8S_CLIENT && <Route path={`/login`} component={Login} />}
248-
<Route path="/" render={() => <NavigationRoutes />} />
249-
<Redirect to={window._env_.K8S_CLIENT ? '/' : `${URLS.LOGIN_SSO}${location.search}`} />
250-
</>
251-
)
252-
}
253-
}
254-
255252
return (
256253
<Suspense fallback={null}>
257254
{validating ? (
@@ -268,20 +265,29 @@ export default function App() {
268265
<ErrorBoundary>
269266
<BreadcrumbStore>
270267
<Switch>
271-
{/* <Route
272-
exact
273-
path={`${approvalType?.toLocaleLowerCase()}/approve?token=${approvalToken}`}
274-
render={() =>
275-
GenericDirectApprovalModal && (
276-
<GenericDirectApprovalModal approvalType={approvalType} />
277-
)
278-
}
279-
/> */}
280-
{/* <Route path="/" render={() => <NavigationRoutes />} />
281-
<Redirect
282-
to={window._env_.K8S_CLIENT ? '/' : `${URLS.LOGIN_SSO}${location.search}`}
283-
/> */}
284-
{renderFirstNavigatedPage()}
268+
{/* {location.pathname && location.pathname.includes('approve') ? (
269+
<Route
270+
exact
271+
path={`/${approvalType?.toLocaleLowerCase()}/approve?token=${approvalToken}`}
272+
render={() =>
273+
GenericDirectApprovalModal && (
274+
<GenericDirectApprovalModal approvalType={approvalType} />
275+
)
276+
}
277+
/>
278+
) : ( */}
279+
<>
280+
{!window._env_.K8S_CLIENT && <Route path={`/login`} component={Login} />}
281+
<Route path="/" render={() => <NavigationRoutes />} />
282+
<Redirect
283+
to={
284+
window._env_.K8S_CLIENT
285+
? '/'
286+
: `${URLS.LOGIN_SSO}${location.search}`
287+
}
288+
/>
289+
</>
290+
{/* )} */}
285291
</Switch>
286292
<div id="full-screen-modal"></div>
287293
<div id="visible-modal"></div>

0 commit comments

Comments
 (0)