-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #312 from kloudlite/update/environments
WEB: Discard changes working fine when switching tab of app settings
- Loading branch information
Showing
7 changed files
with
119 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { useCallback } from 'react'; | ||
import useCustomSwr from '~/root/lib/client/hooks/use-custom-swr'; | ||
import { useConsoleApi } from '../server/gql/api-provider'; | ||
|
||
export const useIsOwner = ({ accountName }: { accountName: string }) => { | ||
const api = useConsoleApi(); | ||
const { data: teamMembers, isLoading: teamMembersLoading } = useCustomSwr( | ||
`${accountName}-owners`, | ||
async () => { | ||
return api.listMembershipsForAccount({ | ||
accountName, | ||
}); | ||
} | ||
); | ||
|
||
const { data: currentUser, isLoading: currentUserLoading } = useCustomSwr( | ||
'current-user', | ||
async () => { | ||
return api.whoAmI(); | ||
} | ||
); | ||
|
||
const isOwner = useCallback(() => { | ||
if (!teamMembers || !currentUser) return false; | ||
|
||
const owner = teamMembers.find((member) => member.role === 'account_owner'); | ||
|
||
return owner?.user?.email === currentUser?.email; | ||
}, [teamMembers, currentUser]); | ||
|
||
return { | ||
isOwner: isOwner(), | ||
isLoading: teamMembersLoading || currentUserLoading, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters