-
Notifications
You must be signed in to change notification settings - Fork 460
feat(clerk-js): Use org:sys_domains:read for improved fine grain control of the UI
#1896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
74a2cbe
28ec80d
c5622fb
8fb7cd2
b4eb751
c3092fd
d8acfa8
01f9db6
9a375d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@clerk/clerk-js': patch | ||
| '@clerk/types': patch | ||
| --- | ||
|
|
||
| Shows list of domains if member has the `org:sys_domain:read` permission. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| import type { GetDomainsParams, OrganizationEnrollmentMode } from '@clerk/types'; | ||
| import type { GetDomainsParams, OrganizationDomainResource, OrganizationEnrollmentMode } from '@clerk/types'; | ||
| import type { OrganizationDomainVerificationStatus } from '@clerk/types'; | ||
| import React, { useMemo } from 'react'; | ||
|
|
||
| import { withGate } from '../../common'; | ||
| import { stripOrigin, toURL, trimLeadingSlash } from '../../../utils'; | ||
| import { useGate, withGate } from '../../common'; | ||
| import { useCoreOrganization } from '../../contexts'; | ||
| import type { LocalizationKey } from '../../customizables'; | ||
| import { Box, Col, localizationKeys, Spinner } from '../../customizables'; | ||
| import { ArrowBlockButton, BlockWithTrailingComponent, ThreeDotsMenu } from '../../elements'; | ||
| import { useInView } from '../../hooks'; | ||
|
|
@@ -17,10 +19,61 @@ type DomainListProps = GetDomainsParams & { | |
| * Enables internal links to navigate to the correct page | ||
| * based on when this component is used | ||
| */ | ||
| redirectSubPath: string; | ||
| redirectSubPath: 'organization-settings/domain' | 'domain'; | ||
| fallback?: React.ReactNode; | ||
| }; | ||
|
|
||
| const useDomainList = () => { | ||
| const { isAuthorizedUser: canDeleteDomain } = useGate({ permission: 'org:sys_domains:delete' }); | ||
| const { isAuthorizedUser: canVerifyDomain } = useGate({ permission: 'org:sys_domains:manage' }); | ||
|
|
||
| return { | ||
| showDotMenu: canDeleteDomain || canVerifyDomain, | ||
| canVerifyDomain, | ||
| canDeleteDomain, | ||
| }; | ||
| }; | ||
|
|
||
| const buildDomainListRelativeURL = (parentPath: string, domainId: string, mode?: 'verify' | 'remove') => | ||
| trimLeadingSlash(stripOrigin(toURL(`${parentPath}/${domainId}/${mode || ''}`))); | ||
|
|
||
| const useMenuActions = ( | ||
| parentPath: string, | ||
| domainId: string, | ||
| ): { label: LocalizationKey; onClick: () => Promise<unknown>; isDestructive?: boolean }[] => { | ||
| const { canDeleteDomain, canVerifyDomain } = useDomainList(); | ||
| const { navigate } = useRouter(); | ||
|
|
||
| const menuActions = []; | ||
|
|
||
| if (canVerifyDomain) { | ||
| menuActions.push({ | ||
| label: localizationKeys('organizationProfile.profilePage.domainSection.unverifiedDomain_menuAction__verify'), | ||
| onClick: () => navigate(buildDomainListRelativeURL(parentPath, domainId, 'verify')), | ||
| }); | ||
| } | ||
|
|
||
| if (canDeleteDomain) { | ||
| menuActions.push({ | ||
| label: localizationKeys('organizationProfile.profilePage.domainSection.unverifiedDomain_menuAction__remove'), | ||
| isDestructive: true, | ||
| onClick: () => navigate(buildDomainListRelativeURL(parentPath, domainId, 'remove')), | ||
| }); | ||
| } | ||
|
|
||
| return menuActions; | ||
| }; | ||
|
|
||
| const DomainListDotMenu = ({ | ||
| redirectSubPath, | ||
| domainId, | ||
| }: Pick<DomainListProps, 'redirectSubPath'> & { | ||
| domainId: OrganizationDomainResource['id']; | ||
| }) => { | ||
| const actions = useMenuActions(redirectSubPath, domainId); | ||
| return <ThreeDotsMenu actions={actions} />; | ||
| }; | ||
|
|
||
| export const DomainList = withGate( | ||
| (props: DomainListProps) => { | ||
| const { verificationStatus, enrollmentMode, redirectSubPath, fallback, ...rest } = props; | ||
|
|
@@ -31,6 +84,7 @@ export const DomainList = withGate( | |
| }, | ||
| }); | ||
|
|
||
| const { showDotMenu } = useDomainList(); | ||
| const { ref } = useInView({ | ||
| threshold: 0, | ||
| onChange: inView => { | ||
|
|
@@ -69,7 +123,7 @@ export const DomainList = withGate( | |
| <Col> | ||
| {domainList.length === 0 && !domains?.isLoading && fallback} | ||
| {domainList.map(d => { | ||
| if (!(d.verification && d.verification.status === 'verified')) { | ||
| if (!(d.verification && d.verification.status === 'verified') || !showDotMenu) { | ||
| return ( | ||
| <BlockWithTrailingComponent | ||
| key={d.id} | ||
|
|
@@ -82,23 +136,12 @@ export const DomainList = withGate( | |
| })} | ||
| badge={<EnrollmentBadge organizationDomain={d} />} | ||
| trailingComponent={ | ||
| <ThreeDotsMenu | ||
| actions={[ | ||
| { | ||
| label: localizationKeys( | ||
| 'organizationProfile.profilePage.domainSection.unverifiedDomain_menuAction__verify', | ||
| ), | ||
| onClick: () => navigate(`${redirectSubPath}${d.id}/verify`), | ||
| }, | ||
| { | ||
| label: localizationKeys( | ||
| 'organizationProfile.profilePage.domainSection.unverifiedDomain_menuAction__remove', | ||
| ), | ||
| isDestructive: true, | ||
| onClick: () => navigate(`${redirectSubPath}${d.id}/remove`), | ||
| }, | ||
| ]} | ||
| /> | ||
| showDotMenu ? ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🙃
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Already tried that, seems like
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we update its types?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following has type of showDotMenu && (
<DomainListDotMenu
redirectSubPath={redirectSubPath}
domainId={d.id}
/>
)
So i would have to do (showDotMenu || null ) && (
<DomainListDotMenu
redirectSubPath={redirectSubPath}
domainId={d.id}
/>
)Which i'm not convinced it is better
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure I understand what you are talking about. Is this the type?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| <DomainListDotMenu | ||
| redirectSubPath={redirectSubPath} | ||
| domainId={d.id} | ||
| /> | ||
| ) : undefined | ||
| } | ||
| > | ||
| {d.name} | ||
|
|
@@ -116,7 +159,7 @@ export const DomainList = withGate( | |
| padding: `${t.space.$3} ${t.space.$4}`, | ||
| minHeight: t.sizes.$10, | ||
| })} | ||
| onClick={() => navigate(`${redirectSubPath}${d.id}`)} | ||
| onClick={() => navigate(buildDomainListRelativeURL(redirectSubPath, d.id))} | ||
| > | ||
| {d.name} | ||
| </ArrowBlockButton> | ||
|
|
@@ -154,6 +197,6 @@ export const DomainList = withGate( | |
| ); | ||
| }, | ||
| { | ||
| permission: 'org:sys_domains:manage', | ||
| permission: 'org:sys_domains:read', | ||
| }, | ||
| ); | ||

Uh oh!
There was an error while loading. Please reload this page.