File tree Expand file tree Collapse file tree 3 files changed +50
-4
lines changed Expand file tree Collapse file tree 3 files changed +50
-4
lines changed Original file line number Diff line number Diff line change 11// Functions calling API
22import {
33 getAccount ,
4+ getAccounts ,
45 getAccountsOrgs ,
56 getIdentity ,
67 getMe as getMeQuartz ,
@@ -282,3 +283,31 @@ export const updateDefaultOrgByAccountID = async ({
282283
283284 // success status code is 204; no response body expected.
284285}
286+
287+ // fetch user default account's default org
288+ export const getDefaultAccountDefaultOrg = async ( ) : Promise < OrganizationSummaries [ number ] > => {
289+ const response = await getAccounts ( { } )
290+
291+ if ( response . status === 401 ) {
292+ throw new UnauthorizedError ( response . data . message )
293+ }
294+
295+ if ( response . status === 500 ) {
296+ throw new ServerError ( response . data . message )
297+ }
298+ const { data} = response
299+
300+ if ( Array . isArray ( data ) && data . length ) {
301+ const defaultAccount = data . find ( account => account . isDefault )
302+
303+ // fetch default org
304+ if ( defaultAccount ) {
305+ const quartzOrg = await fetchOrgsByAccountID ( defaultAccount . id )
306+ const defaultQuartzOrg =
307+ quartzOrg . find ( org => org . isDefault ) || quartzOrg [ 0 ]
308+
309+ return defaultQuartzOrg
310+ }
311+ throw new GenericError ( 'No default account found' )
312+ }
313+ }
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ import {getOrg as fetchOrg} from 'src/organizations/apis'
2121// Utils
2222import { buildDeepLinkingMap } from 'src/utils/deepLinks'
2323import { event } from 'src/cloud/utils/reporting'
24+ import { shouldUseQuartzIdentity } from 'src/identity/utils/shouldUseQuartzIdentity'
2425
2526// Components
2627import LogoWithCubo from 'src/checkout/LogoWithCubo'
@@ -30,6 +31,9 @@ import {Organization} from 'src/types'
3031// Constants
3132import { CLOUD } from 'src/shared/constants'
3233
34+ // API
35+ import { getDefaultAccountDefaultOrg } from 'src/identity/apis/auth'
36+
3337const NotFoundNew : FC = ( ) => (
3438 < AppWrapper type = "funnel" className = "page-not-found" testID = "not-found" >
3539 < FunnelPage enableGraphic = { true } className = "page-not-found-funnel" >
@@ -136,10 +140,20 @@ const NotFound: FC = () => {
136140
137141 const handleDeepLink = useCallback ( async ( ) => {
138142 if ( ! org . current ) {
139- setIsFetchingOrg ( true )
140- org . current = await fetchOrg ( )
143+ if ( shouldUseQuartzIdentity ( ) ) {
144+ try {
145+ setIsFetchingOrg ( true )
146+ const defaultQuartzOrg = await getDefaultAccountDefaultOrg ( )
147+ org . current = defaultQuartzOrg
148+ } catch {
149+ history . push ( `/no-orgs` )
150+ return
151+ }
152+ } else {
153+ setIsFetchingOrg ( true )
154+ org . current = await fetchOrg ( )
155+ }
141156 }
142-
143157 const deepLinkingMap = buildDeepLinkingMap ( org . current )
144158
145159 if ( deepLinkingMap . hasOwnProperty ( location . pathname ) ) {
Original file line number Diff line number Diff line change 11import { Organization } from 'src/client'
2+ import { OrganizationSummaries } from 'src/client/unityRoutes'
23import { PROJECT_NAME_PLURAL } from 'src/flows'
34
4- export const buildDeepLinkingMap = ( org : Organization ) => ( {
5+ export const buildDeepLinkingMap = (
6+ org : Organization | OrganizationSummaries [ number ]
7+ ) => ( {
58 '/me/about' : `/orgs/${ org . id } /about` ,
69 '/me/alerts' : `/orgs/${ org . id } /alerting` ,
710 '/me/billing' : `/orgs/${ org . id } /billing` ,
You can’t perform that action at this time.
0 commit comments