Skip to content

Commit

Permalink
feat(clerk-js): Delete pending invitations when updating enrolment mo…
Browse files Browse the repository at this point in the history
…de of domain (#1632)

* feat(clerk-js): Delete pending invitations when updating enrollment mode of domain

* chore(clerk-js): Remove BlockWithAction as it unused

* chore(clerk-js): Add changeset
  • Loading branch information
panteliselef authored Aug 25, 2023
1 parent 9f32fd7 commit b2296d6
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 253 deletions.
7 changes: 7 additions & 0 deletions .changeset/shy-readers-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@clerk/localizations': patch
'@clerk/clerk-js': patch
'@clerk/types': patch
---

When updating enrollment mode of a domain uses can now delete any pending invitations or suggestions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
import type { OrganizationEnrollmentMode } from '@clerk/types';

import { useCoreOrganization, useEnvironment } from '../../contexts';
import { Col, descriptors, Flex, localizationKeys, Spinner } from '../../customizables';
import {
BlockWithAction,
ContentPage,
Form,
FormButtons,
Header,
useCardState,
withCardStateProvider,
} from '../../elements';
import { useFetch } from '../../hooks';
import { Col, Flex, localizationKeys, Spinner } from '../../customizables';
import { ContentPage, Form, FormButtons, Header, useCardState, withCardStateProvider } from '../../elements';
import { useFetch, useNavigateToFlowStart } from '../../hooks';
import { useRouter } from '../../router';
import { handleError, useFormControl } from '../../utils';
import { EnrollmentBadge } from './EnrollmentBadge';
import { OrganizationProfileBreadcrumbs } from './OrganizationProfileNavbar';

export const VerifiedDomainPage = withCardStateProvider(() => {
const card = useCardState();
const { organizationSettings } = useEnvironment();
const { organization } = useCoreOrganization();
const { params, navigate } = useRouter();
const { domains } = useCoreOrganization({
domains: {
infinite: true,
},
});
const { navigateToFlowStart } = useNavigateToFlowStart();
const { params, navigate, queryParams } = useRouter();
const mode = (queryParams.mode ?? 'edit') as 'select' | 'edit';

const title = localizationKeys('organizationProfile.verifiedDomainPage.title');
const allowsEdit = mode === 'edit';

const enrollmentMode = useFormControl('enrollmentMode', '', {
type: 'radio',
Expand All @@ -32,9 +30,11 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
? [
{
value: 'manual_invitation',
label: localizationKeys('organizationProfile.verifiedDomainPage.manualInvitationOption__label'),
label: localizationKeys(
'organizationProfile.verifiedDomainPage.enrollmentTab.manualInvitationOption__label',
),
description: localizationKeys(
'organizationProfile.verifiedDomainPage.manualInvitationOption__description',
'organizationProfile.verifiedDomainPage.enrollmentTab.manualInvitationOption__description',
),
},
]
Expand All @@ -43,9 +43,11 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
? [
{
value: 'automatic_invitation',
label: localizationKeys('organizationProfile.verifiedDomainPage.automaticInvitationOption__label'),
label: localizationKeys(
'organizationProfile.verifiedDomainPage.enrollmentTab.automaticInvitationOption__label',
),
description: localizationKeys(
'organizationProfile.verifiedDomainPage.automaticInvitationOption__description',
'organizationProfile.verifiedDomainPage.enrollmentTab.automaticInvitationOption__description',
),
},
]
Expand All @@ -54,16 +56,23 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
? [
{
value: 'automatic_suggestion',
label: localizationKeys('organizationProfile.verifiedDomainPage.automaticSuggestionOption__label'),
label: localizationKeys(
'organizationProfile.verifiedDomainPage.enrollmentTab.automaticSuggestionOption__label',
),
description: localizationKeys(
'organizationProfile.verifiedDomainPage.automaticSuggestionOption__description',
'organizationProfile.verifiedDomainPage.enrollmentTab.automaticSuggestionOption__description',
),
},
]
: []),
],
});

const deletePending = useFormControl('deleteExistingInvitationsSuggestions', '', {
label: localizationKeys('formFieldLabel__organizationDomainDeletePending'),
type: 'checkbox',
});

const { data: domain, status: domainStatus } = useFetch(
organization?.getDomain,
{
Expand All @@ -76,6 +85,7 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
},
);

const isFormDirty = deletePending.checked || domain?.enrollmentMode !== enrollmentMode.value;
const updateEnrollmentMode = async () => {
if (!domain || !organization) {
return;
Expand All @@ -84,8 +94,11 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
try {
await domain.updateEnrollmentMode({
enrollmentMode: enrollmentMode.value as OrganizationEnrollmentMode,
deletePending: deletePending.checked,
});

await (domains as any).unstable__mutate();

await navigate('../../');
} catch (e) {
handleError(e, [enrollmentMode], card.setError);
Expand Down Expand Up @@ -115,36 +128,23 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
);
}

if (!(domain.verification && domain.verification.status === 'verified')) {
void navigateToFlowStart();
}
return (
<ContentPage
headerTitle={title}
headerTitle={domain.name}
gap={4}
Breadcrumbs={OrganizationProfileBreadcrumbs}
>
<BlockWithAction
elementDescriptor={descriptors.accordionTriggerButton}
badge={<EnrollmentBadge organizationDomain={domain} />}
sx={t => ({
backgroundColor: t.colors.$blackAlpha50,
padding: `${t.space.$3} ${t.space.$4}`,
minHeight: t.sizes.$10,
})}
actionSx={t => ({
color: t.colors.$danger500,
})}
actionLabel={localizationKeys('organizationProfile.verifiedDomainPage.actionLabel__remove')}
onActionClick={() => navigate(`../../domain/${domain.id}/remove`)}
>
{domain.name}
</BlockWithAction>

<Col gap={2}>
<Header.Root>
<Header.Title
localizationKey={localizationKeys('organizationProfile.verifiedDomainPage.formTitle')}
localizationKey={localizationKeys('organizationProfile.verifiedDomainPage.start.headerTitle__enrollment')}
textVariant='largeMedium'
/>
<Header.Subtitle
localizationKey={localizationKeys('organizationProfile.verifiedDomainPage.formSubtitle')}
localizationKey={localizationKeys('organizationProfile.verifiedDomainPage.enrollmentTab.subtitle')}
variant='regularRegular'
/>
</Header.Root>
Expand All @@ -154,7 +154,16 @@ export const VerifiedDomainPage = withCardStateProvider(() => {
<Form.Control {...enrollmentMode.props} />
</Form.ControlRow>

<FormButtons isDisabled={domainStatus.isLoading || !domain} />
{allowsEdit && (
<Form.ControlRow elementId={deletePending.id}>
<Form.Control {...deletePending.props} />
</Form.ControlRow>
)}

<FormButtons
localizationKey={localizationKeys('organizationProfile.verifiedDomainPage.enrollmentTab.formButton__save')}
isDisabled={domainStatus.isLoading || !domain || !isFormDirty}
/>
</Form.Root>
</Col>
</ContentPage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useCoreOrganization, useEnvironment } from '../../contexts';
import { Button, descriptors, Flex, localizationKeys, Spinner } from '../../customizables';
import type { VerificationCodeCardProps } from '../../elements';
import {
BlockWithAction,
ContentPage,
Form,
FormButtonContainer,
Expand All @@ -18,14 +17,13 @@ import { CodeForm } from '../../elements/CodeForm';
import { useFetch, useLoadingStatus, useNavigateToFlowStart } from '../../hooks';
import { useRouter } from '../../router';
import { handleError, sleep, useFormControl } from '../../utils';
import { EnrollmentBadge } from './EnrollmentBadge';
import { OrganizationProfileBreadcrumbs } from './OrganizationProfileNavbar';

export const VerifyDomainPage = withCardStateProvider(() => {
const card = useCardState();
const { organizationSettings } = useEnvironment();
const { organization } = useCoreOrganization();
const { params, navigate } = useRouter();
const { params } = useRouter();
const { navigateToFlowStart } = useNavigateToFlowStart();

const [success, setSuccess] = React.useState(false);
Expand Down Expand Up @@ -134,23 +132,6 @@ export const VerifyDomainPage = withCardStateProvider(() => {
headerSubtitle={subtitle}
Breadcrumbs={OrganizationProfileBreadcrumbs}
>
<BlockWithAction
elementDescriptor={descriptors.accordionTriggerButton}
badge={<EnrollmentBadge organizationDomain={domain} />}
sx={t => ({
backgroundColor: t.colors.$blackAlpha50,
padding: `${t.space.$3} ${t.space.$4}`,
minHeight: t.sizes.$10,
})}
actionLabel={localizationKeys('organizationProfile.verifyDomainPage.actionLabel__remove')}
onActionClick={() => navigate(`../../../domain/${domain.id}/remove`)}
actionSx={t => ({
color: t.colors.$danger500,
})}
>
{domain.name}
</BlockWithAction>

<Form.Root onSubmit={onSubmitPrepare}>
<Form.ControlRow elementId={emailField.id}>
<Form.Control
Expand Down
164 changes: 0 additions & 164 deletions packages/clerk-js/src/ui/elements/BlockWithAction.tsx

This file was deleted.

Loading

0 comments on commit b2296d6

Please sign in to comment.