-
Notifications
You must be signed in to change notification settings - Fork 252
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
5️⃣ <OrganizationProfile/> List, add, edit, remove Domains #1560
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
32a9776
feat(localizations,types): Create localization keys for Organization …
panteliselef 7d8d97b
feat(types): Update appearance element keys for Organization domains
panteliselef 15b8eb9
feat(clerk-js): Add Verified domains section and all routes to suppor…
panteliselef 5943c19
feat(localizations,types): Update localization
panteliselef 92c9edf
chore(clerk-js): Replace ArrowBlockButton with BlockWithAction
panteliselef df359f1
feat(clerk-js): Share domain list between members and settings
panteliselef 4a38aaa
feat(clerk-js): Create RemoveDomainPage
panteliselef 1a582f4
feat(clerk-js): Finalize VerifiedDomainPage
panteliselef cdda613
fix(clerk-js): Rename to `prepareAffiliationVerification`
panteliselef 3977bb7
test(clerk-js): Update OrganizationDomain snapshot
panteliselef 32180ce
test(clerk-js): Update OrganizationMembers
panteliselef 09fbf7a
test(clerk-js): Update OrganizationSettings
panteliselef 29775d6
chore(clerk-js): Add changeset
panteliselef b73df88
chore(clerk-js): Increase OrganizationProfile bundle size limit
panteliselef 1ca8e3e
chore(clerk-js): Introduce useFetch
panteliselef 2a5c9a9
chore(clerk-js): Improve readability
panteliselef c211d2a
chore(clerk-js): Move CalloutWithAction under common ui
panteliselef 3dc622a
Revert "chore(clerk-js): Increase OrganizationProfile bundle size limit"
panteliselef File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@clerk/localizations': patch | ||
'@clerk/clerk-js': patch | ||
'@clerk/types': patch | ||
--- | ||
|
||
Introduces domains and invitations in <OrganizationProfile /> | ||
|
||
- The "Members" page now accommodates Domain and Individual invitations | ||
- The "Settings" page allows for the addition, edit and removal of a domain |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import type { MouseEvent } from 'react'; | ||
|
||
import { Col, Flex, Link, Text } from '../customizables'; | ||
import type { LocalizationKey } from '../localization'; | ||
|
||
type CalloutWithActionProps = { | ||
text: LocalizationKey; | ||
actionLabel?: LocalizationKey; | ||
onClick?: (e: MouseEvent<HTMLAnchorElement>) => Promise<any>; | ||
}; | ||
export const CalloutWithAction = (props: CalloutWithActionProps) => { | ||
const { text, actionLabel, onClick: onClickProp } = props; | ||
|
||
const onClick = (e: MouseEvent<HTMLAnchorElement>) => { | ||
if (onClickProp) { | ||
void onClickProp?.(e); | ||
} | ||
}; | ||
|
||
return ( | ||
<Flex | ||
sx={theme => ({ | ||
background: theme.colors.$blackAlpha50, | ||
padding: theme.space.$4, | ||
justifyContent: 'space-between', | ||
alignItems: 'flex-start', | ||
borderRadius: theme.radii.$md, | ||
})} | ||
> | ||
<Col gap={4}> | ||
<Text | ||
sx={t => ({ | ||
lineHeight: t.lineHeights.$tall, | ||
})} | ||
localizationKey={text} | ||
/> | ||
|
||
<Link | ||
colorScheme={'primary'} | ||
variant='regularMedium' | ||
localizationKey={actionLabel} | ||
onClick={onClick} | ||
/> | ||
</Col> | ||
</Flex> | ||
); | ||
}; |
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
62 changes: 62 additions & 0 deletions
62
packages/clerk-js/src/ui/components/OrganizationProfile/AddDomainPage.tsx
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,62 @@ | ||
import React from 'react'; | ||
|
||
import { useCoreOrganization } from '../../contexts'; | ||
import { localizationKeys } from '../../customizables'; | ||
import { ContentPage, Form, FormButtons, useCardState, withCardStateProvider } from '../../elements'; | ||
import { useRouter } from '../../router'; | ||
import { handleError, useFormControl } from '../../utils'; | ||
import { OrganizationProfileBreadcrumbs } from './OrganizationProfileNavbar'; | ||
|
||
export const AddDomainPage = withCardStateProvider(() => { | ||
const title = localizationKeys('organizationProfile.createDomainPage.title'); | ||
const subtitle = localizationKeys('organizationProfile.createDomainPage.subtitle'); | ||
const card = useCardState(); | ||
const { organization } = useCoreOrganization(); | ||
const { navigate } = useRouter(); | ||
|
||
const nameField = useFormControl('name', '', { | ||
type: 'text', | ||
label: localizationKeys('formFieldLabel__organizationEmailDomain'), | ||
placeholder: localizationKeys('formFieldInputPlaceholder__organizationName'), | ||
}); | ||
|
||
if (!organization) { | ||
return null; | ||
} | ||
|
||
const canSubmit = organization.name !== nameField.value; | ||
|
||
const onSubmit = (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
return organization | ||
.createDomain(nameField.value) | ||
.then(res => { | ||
if (res.verification && res.verification.status === 'verified') { | ||
return navigate(`../domain/${res.id}`); | ||
} | ||
return navigate(`../domain/${res.id}/verify`); | ||
}) | ||
.catch(err => { | ||
handleError(err, [nameField], card.setError); | ||
}); | ||
}; | ||
|
||
return ( | ||
<ContentPage | ||
headerTitle={title} | ||
headerSubtitle={subtitle} | ||
Breadcrumbs={OrganizationProfileBreadcrumbs} | ||
> | ||
<Form.Root onSubmit={onSubmit}> | ||
<Form.ControlRow elementId={nameField.id}> | ||
<Form.Control | ||
{...nameField.props} | ||
autoFocus | ||
required | ||
/> | ||
</Form.ControlRow> | ||
<FormButtons isDisabled={!canSubmit} /> | ||
</Form.Root> | ||
</ContentPage> | ||
); | ||
}); |
133 changes: 133 additions & 0 deletions
133
packages/clerk-js/src/ui/components/OrganizationProfile/DomainList.tsx
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,133 @@ | ||
import type { GetDomainsParams, OrganizationEnrollmentMode } from '@clerk/types'; | ||
import type { OrganizationDomainVerificationStatus } from '@clerk/types'; | ||
import React, { useMemo } from 'react'; | ||
|
||
import { useCoreOrganization } from '../../contexts'; | ||
import { Badge, Box, Col, descriptors, Spinner } from '../../customizables'; | ||
import { ArrowBlockButton } from '../../elements'; | ||
import { useInView } from '../../hooks'; | ||
import { useRouter } from '../../router'; | ||
|
||
type DomainListProps = GetDomainsParams & { | ||
verificationStatus?: OrganizationDomainVerificationStatus; | ||
enrollmentMode?: OrganizationEnrollmentMode; | ||
/** | ||
* Enables internal links to navigate to the correct page | ||
* based on when this component is used | ||
*/ | ||
redirectSubPath: string; | ||
fallback?: React.ReactNode; | ||
}; | ||
|
||
export const DomainList = (props: DomainListProps) => { | ||
const { verificationStatus, enrollmentMode, redirectSubPath, fallback, ...rest } = props; | ||
const { organization, membership, domains } = useCoreOrganization({ | ||
domains: { | ||
infinite: true, | ||
...rest, | ||
}, | ||
}); | ||
|
||
const { ref } = useInView({ | ||
threshold: 0, | ||
onChange: inView => { | ||
if (inView) { | ||
void domains?.fetchNext?.(); | ||
} | ||
}, | ||
}); | ||
const { navigate } = useRouter(); | ||
|
||
const isAdmin = membership?.role === 'admin'; | ||
|
||
const domainList = useMemo(() => { | ||
if (!domains?.data) { | ||
return []; | ||
} | ||
|
||
return domains.data.filter(d => { | ||
let matchesStatus = true; | ||
let matchesMode = true; | ||
if (verificationStatus) { | ||
matchesStatus = !!d.verification && d.verification.status === verificationStatus; | ||
} | ||
if (enrollmentMode) { | ||
matchesMode = d.enrollmentMode === enrollmentMode; | ||
} | ||
|
||
return matchesStatus && matchesMode; | ||
}); | ||
}, [domains?.data]); | ||
|
||
if (!organization || !isAdmin) { | ||
return null; | ||
} | ||
|
||
// TODO: Split this to smaller components | ||
return ( | ||
<Col> | ||
{domainList.length === 0 && !domains?.isLoading && fallback} | ||
{domainList.map(d => ( | ||
<ArrowBlockButton | ||
key={d.id} | ||
elementDescriptor={descriptors.accordionTriggerButton} | ||
variant='ghost' | ||
colorScheme='neutral' | ||
badge={ | ||
!verificationStatus ? ( | ||
d.verification && d.verification.status === 'verified' ? ( | ||
<Badge textVariant={'extraSmallRegular'}>Verified</Badge> | ||
) : ( | ||
<Badge | ||
textVariant={'extraSmallRegular'} | ||
colorScheme={'warning'} | ||
> | ||
Unverified | ||
</Badge> | ||
) | ||
) : undefined | ||
} | ||
sx={t => ({ | ||
padding: `${t.space.$3} ${t.space.$4}`, | ||
minHeight: t.sizes.$10, | ||
})} | ||
onClick={() => { | ||
d.verification && d.verification.status === 'verified' | ||
? void navigate(`${redirectSubPath}${d.id}`) | ||
: void navigate(`${redirectSubPath}${d.id}/verify`); | ||
}} | ||
> | ||
{d.name} | ||
</ArrowBlockButton> | ||
))} | ||
{(domains?.hasNextPage || domains?.isFetching) && ( | ||
<Box | ||
ref={domains?.isFetching ? undefined : ref} | ||
sx={[ | ||
t => ({ | ||
width: '100%', | ||
height: t.space.$10, | ||
position: 'relative', | ||
}), | ||
]} | ||
> | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
margin: 'auto', | ||
position: 'absolute', | ||
left: '50%', | ||
top: '50%', | ||
transform: 'translateY(-50%) translateX(-50%)', | ||
}} | ||
> | ||
<Spinner | ||
size='md' | ||
colorScheme='primary' | ||
/> | ||
</Box> | ||
</Box> | ||
)} | ||
</Col> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Why do we need to filter the
domainList
? Shouldn't FAPI take care of that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, FAPI should be in charge of that.
At that moment filtering not available tho. A following PR aims to fix that.