33 useMyDelegatedChildAccountsQuery ,
44} from '@linode/queries' ;
55import {
6+ Box ,
67 Button ,
78 Drawer ,
89 LinkButton ,
@@ -14,6 +15,7 @@ import {
1415import React , { useMemo , useState } from 'react' ;
1516
1617import ErrorStateCloud from 'src/assets/icons/error-state-cloud.svg' ;
18+ import NoResultsState from 'src/assets/icons/no-results-state.svg' ;
1719import { DebouncedSearchTextField } from 'src/components/DebouncedSearchTextField' ;
1820import { useParentChildAuthentication } from 'src/features/Account/SwitchAccounts/useParentChildAuthentication' ;
1921import { useSwitchToParentAccount } from 'src/features/Account/SwitchAccounts/useSwitchToParentAccount' ;
@@ -217,6 +219,7 @@ export const SwitchAccountDrawer = (props: Props) => {
217219 const hasError = isIAMDelegationEnabled
218220 ? delegatedChildAccountsError
219221 : childAccountInfiniteError ;
222+
220223 return (
221224 < Drawer onClose = { handleClose } open = { open } title = "Switch Account" >
222225 { createTokenErrorReason && (
@@ -225,116 +228,144 @@ export const SwitchAccountDrawer = (props: Props) => {
225228 { isParentTokenError . length > 0 && (
226229 < Notice text = { isParentTokenError [ 0 ] . reason } variant = "error" />
227230 ) }
228- < Typography
229- sx = { ( theme ) => ( {
230- margin : `${ theme . spacingFunction ( 24 ) } 0` ,
231- } ) }
232- >
233- Select an account to view and manage its settings and configurations
234- { isProxyOrDelegateUserType && (
235- < >
236- { ' or ' }
237- < LinkButton
238- aria-label = "parent-account-link"
239- disabled = { isSubmitting }
240- onClick = { ( ) => {
241- sendSwitchToParentAccountEvent ( ) ;
242- handleSwitchToParentAccount ( ) ;
243- } }
244- >
245- switch back to your account
246- </ LinkButton >
247- </ >
248- ) }
249- .
250- </ Typography >
251-
252- { hasError ? (
253- < Stack alignItems = "center" gap = { 1 } justifyContent = "center" >
254- < ErrorStateCloud />
255- < Typography > Unable to load data.</ Typography >
256- < Typography >
257- Try again or contact support if the issue persists.
231+ { childAccounts &&
232+ childAccounts . length === 0 &&
233+ ! Object . prototype . hasOwnProperty . call ( filter , 'company' ) ? (
234+ < Box alignItems = "center" display = "flex" flexDirection = "column" mt = { 8 } >
235+ < NoResultsState />
236+ < Typography sx = { { mt : 2 , mb : 1 } } variant = "h2" >
237+ You don’t have access to other accounts.
238+ </ Typography >
239+ < Typography sx = { { textAlign : 'center' , maxWidth : 300 } } >
240+ You must be added to a delegation by an account administrator to
241+ have access to other accounts.
258242 </ Typography >
259243 < Button
260- buttonType = "primary"
261- onClick = { ( ) => refetchFn ( ) }
262- sx = { ( theme ) => ( {
263- marginTop : theme . spacingFunction ( 16 ) ,
264- } ) }
244+ buttonType = "outlined"
245+ onClick = { handleClose }
246+ sx = { { mt : 4 , alignSelf : 'flex-end' } }
265247 >
266- Try again
248+ Close
267249 </ Button >
268- </ Stack >
250+ </ Box >
269251 ) : (
270252 < >
271- < DebouncedSearchTextField
272- clearable
273- debounceTime = { 250 }
274- hideLabel
275- key = { `switch-search-${ searchQuery } ` }
276- label = "Search"
277- onSearch = { handleSearchQueryChange }
278- placeholder = "Search"
279- sx = { { marginBottom : theme . spacingFunction ( 12 ) } }
280- value = { searchQuery }
281- />
282- { searchQuery &&
283- childAccounts &&
284- childAccounts . length === 0 &&
285- ! isLoading && (
286- < Typography
287- sx = { {
288- fontStyle : 'italic' ,
289- marginTop : theme . spacingFunction ( 6 ) ,
290- } }
291- >
292- No search results
293- </ Typography >
253+ < Typography
254+ sx = { ( theme ) => ( {
255+ margin : `${ theme . spacingFunction ( 24 ) } 0` ,
256+ } ) }
257+ >
258+ Select an account to view and manage its settings and configurations
259+ { isProxyOrDelegateUserType && (
260+ < >
261+ { ' or ' }
262+ < LinkButton
263+ aria-label = "parent-account-link"
264+ disabled = { isSubmitting }
265+ onClick = { ( ) => {
266+ sendSwitchToParentAccountEvent ( ) ;
267+ handleSwitchToParentAccount ( ) ;
268+ } }
269+ >
270+ switch back to your account
271+ </ LinkButton >
272+ </ >
294273 ) }
274+ .
275+ </ Typography >
295276
296- { isIAMDelegationEnabled && (
297- < ChildAccountsTable
298- childAccounts = { childAccounts }
299- currentTokenWithBearer = {
300- isProxyOrDelegateUserType
301- ? currentParentTokenWithBearer
302- : currentTokenWithBearer
303- }
304- filter = { filter }
305- isLoading = { isLoading }
306- isSwitchingChildAccounts = { isSwitchingChildAccounts }
307- onClose = { onClose }
308- onPageChange = { handlePageChange }
309- onPageSizeChange = { handlePageSizeChange }
310- onSwitchAccount = { handleSwitchToChildAccount }
311- page = { page }
312- pageSize = { pageSize }
313- setIsSwitchingChildAccounts = { setIsSwitchingChildAccounts }
314- totalResults = { delegatedChildAccounts ?. results || 0 }
315- userType = { userType }
316- />
317- ) }
318- { ! isIAMDelegationEnabled && (
319- < ChildAccountList
320- childAccounts = { childAccounts }
321- currentTokenWithBearer = {
322- isProxyOrDelegateUserType
323- ? currentParentTokenWithBearer
324- : currentTokenWithBearer
325- }
326- fetchNextPage = { fetchNextPage }
327- filter = { filter }
328- hasNextPage = { hasNextPage }
329- isFetchingNextPage = { isFetchingNextPage }
330- isLoading = { isLoading }
331- isSwitchingChildAccounts = { isSwitchingChildAccounts }
332- onClose = { onClose }
333- onSwitchAccount = { handleSwitchToChildAccount }
334- refetchFn = { refetchFn }
335- setIsSwitchingChildAccounts = { setIsSwitchingChildAccounts }
336- userType = { userType }
337- />
277+ { hasError ? (
278+ < Stack alignItems = "center" gap = { 1 } justifyContent = "center" >
279+ < ErrorStateCloud />
280+ < Typography > Unable to load data.</ Typography >
281+ < Typography >
282+ Try again or contact support if the issue persists.
283+ </ Typography >
284+ < Button
285+ buttonType = "primary"
286+ onClick = { ( ) => refetchFn ( ) }
287+ sx = { ( theme ) => ( {
288+ marginTop : theme . spacingFunction ( 16 ) ,
289+ } ) }
290+ >
291+ Try again
292+ </ Button >
293+ </ Stack >
294+ ) : (
295+ < >
296+ { ( ( childAccounts && childAccounts . length !== 0 ) ||
297+ searchQuery ) && (
298+ < DebouncedSearchTextField
299+ clearable
300+ debounceTime = { 250 }
301+ hideLabel
302+ key = { `switch-search-${ searchQuery } ` }
303+ label = "Search"
304+ loading = { isLoading }
305+ onSearch = { handleSearchQueryChange }
306+ placeholder = "Search"
307+ sx = { { marginBottom : theme . spacingFunction ( 12 ) } }
308+ value = { searchQuery }
309+ />
310+ ) }
311+ { isIAMDelegationEnabled &&
312+ searchQuery &&
313+ childAccounts &&
314+ childAccounts . length === 0 &&
315+ ! isLoading && (
316+ < Typography
317+ sx = { {
318+ fontStyle : 'italic' ,
319+ marginTop : theme . spacingFunction ( 6 ) ,
320+ } }
321+ >
322+ No search results
323+ </ Typography >
324+ ) }
325+
326+ { isIAMDelegationEnabled && (
327+ < ChildAccountsTable
328+ childAccounts = { childAccounts }
329+ currentTokenWithBearer = {
330+ isProxyOrDelegateUserType
331+ ? currentParentTokenWithBearer
332+ : currentTokenWithBearer
333+ }
334+ isLoading = { isLoading }
335+ isSwitchingChildAccounts = { isSwitchingChildAccounts }
336+ onClose = { onClose }
337+ onPageChange = { handlePageChange }
338+ onPageSizeChange = { handlePageSizeChange }
339+ onSwitchAccount = { handleSwitchToChildAccount }
340+ page = { page }
341+ pageSize = { pageSize }
342+ setIsSwitchingChildAccounts = { setIsSwitchingChildAccounts }
343+ totalResults = { delegatedChildAccounts ?. results || 0 }
344+ userType = { userType }
345+ />
346+ ) }
347+ { ! isIAMDelegationEnabled && (
348+ < ChildAccountList
349+ childAccounts = { childAccounts }
350+ currentTokenWithBearer = {
351+ isProxyOrDelegateUserType
352+ ? currentParentTokenWithBearer
353+ : currentTokenWithBearer
354+ }
355+ fetchNextPage = { fetchNextPage }
356+ filter = { filter }
357+ hasNextPage = { hasNextPage }
358+ isFetchingNextPage = { isFetchingNextPage }
359+ isLoading = { isLoading }
360+ isSwitchingChildAccounts = { isSwitchingChildAccounts }
361+ onClose = { onClose }
362+ onSwitchAccount = { handleSwitchToChildAccount }
363+ refetchFn = { refetchFn }
364+ setIsSwitchingChildAccounts = { setIsSwitchingChildAccounts }
365+ userType = { userType }
366+ />
367+ ) }
368+ </ >
338369 ) }
339370 </ >
340371 ) }
0 commit comments