Skip to content

The open alternative to Salesforce, designed for AI.

Use shared confirmation dialog layouts (#28437)

Raphaël Bosib20837b60a2c
diff --git a/packages/twenty-front/src/modules/command-menu-item/confirmation-modal/components/CommandMenuConfirmationModalManager.tsx b/packages/twenty-front/src/modules/command-menu-item/confirmation-modal/components/CommandMenuConfirmationModalManager.tsx
index 7b831004524..53786e43367 100644
--- a/packages/twenty-front/src/modules/command-menu-item/confirmation-modal/components/CommandMenuConfirmationModalManager.tsx
+++ b/packages/twenty-front/src/modules/command-menu-item/confirmation-modal/components/CommandMenuConfirmationModalManager.tsx
@@ -1,5 +1,3 @@
-import { styled } from '@linaria/react';
-import { themeCssVariables } from 'twenty-ui/theme';
import { NavigationButton } from '@/ui/input/components/NavigationButton';
import { COMMAND_MENU_CONFIRMATION_MODAL_INSTANCE_ID } from '@/command-menu-item/confirmation-modal/constants/CommandMenuItemConfirmationModalId';
@@ -16,11 +14,6 @@ import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomState
import { useSetAtomState } from '@/ui/utilities/state/jotai/hooks/useSetAtomState';
import { isDefined } from 'twenty-shared/utils';
-const StyledCenteredNavigationButton = styled(NavigationButton)`
- box-sizing: border-box;
- margin-top: ${themeCssVariables.spacing[2]};
-`;
-
export const CommandMenuConfirmationModalManager = () => {
const commandMenuItemConfirmationModalConfig = useAtomStateValue(
commandMenuItemConfirmationModalConfigState,
@@ -78,14 +71,14 @@ export const CommandMenuConfirmationModalManager = () => {
}
AdditionalButtons={
isDefined(linkButton) ? (
- <StyledCenteredNavigationButton
+ <NavigationButton
to={linkButton.to}
onClick={() => emitConfirmationResult('cancel')}
fullWidth
variant="outline"
>
{linkButton.title}
- </StyledCenteredNavigationButton>
+ </NavigationButton>
) : undefined
}
/>
diff --git a/packages/twenty-front/src/modules/settings/data-model/object-details/components/SettingsUpdateDataModelObjectAboutForm.tsx b/packages/twenty-front/src/modules/settings/data-model/object-details/components/SettingsUpdateDataModelObjectAboutForm.tsx
index 1ffc467daac..52373e8455e 100644
--- a/packages/twenty-front/src/modules/settings/data-model/object-details/components/SettingsUpdateDataModelObjectAboutForm.tsx
+++ b/packages/twenty-front/src/modules/settings/data-model/object-details/components/SettingsUpdateDataModelObjectAboutForm.tsx
@@ -1,6 +1,4 @@
import { Button } from 'twenty-ui/primitives/input';
-import { styled } from '@linaria/react';
-import { themeCssVariables } from 'twenty-ui/theme';
import { isDDLLockedState } from '@/client-config/states/isDDLLockedState';
import { type EnrichedObjectMetadataItem } from '@/object-metadata/types/EnrichedObjectMetadataItem';
import { isObjectMetadataReadOnly } from '@/object-record/read-only/utils/isObjectMetadataReadOnly';
@@ -15,11 +13,6 @@ import { useAtomStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomState
import { useLingui } from '@lingui/react/macro';
import { FormProvider, type UseFormReturn } from 'react-hook-form';
-const StyledCenteredButton = styled(Button)`
- box-sizing: border-box;
- margin-top: ${themeCssVariables.spacing[2]};
-`;
-
type SettingsUpdateDataModelObjectAboutFormProps = {
objectMetadataItem: EnrichedObjectMetadataItem;
formConfig: UseFormReturn<SettingsDataModelObjectAboutFormValues>;
@@ -66,11 +59,11 @@ export const SettingsUpdateDataModelObjectAboutForm = ({
onConfirmClick={saveAsTranslation}
onClose={cancelPendingSave}
AdditionalButtons={
- <StyledCenteredButton
+ <Button
fullWidth
onClick={handleRenameForAllLanguages}
variant="outline"
- >{t`Rename for all languages`}</StyledCenteredButton>
+ >{t`Rename for all languages`}</Button>
}
/>
</FormProvider>
diff --git a/packages/twenty-front/src/modules/ui/layout/dialog/components/ConfirmationDialog.tsx b/packages/twenty-front/src/modules/ui/layout/dialog/components/ConfirmationDialog.tsx
index dc016861107..d3c3c2a4013 100644
--- a/packages/twenty-front/src/modules/ui/layout/dialog/components/ConfirmationDialog.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/dialog/components/ConfirmationDialog.tsx
@@ -1,7 +1,6 @@
import { Button } from 'twenty-ui/primitives/input';
import { DialogInstance } from '@/ui/layout/dialog/components/DialogInstance';
import { type ConfirmationDialogProps } from '@/ui/layout/dialog/types/ConfirmationDialogProps';
-import { styled } from '@linaria/react';
import { isNonEmptyString } from '@sniptt/guards';
import { useState } from 'react';
@@ -10,21 +9,7 @@ import { SettingsTextInput } from '@/ui/input/components/SettingsTextInput';
import { useDialog } from '@/ui/layout/dialog/hooks/useDialog';
import { msg } from '@lingui/core/macro';
import { useLingui } from '@lingui/react/macro';
-import { Section } from 'twenty-ui/components/layout';
import { Dialog } from 'twenty-ui/primitives/surfaces';
-import { themeCssVariables } from 'twenty-ui/theme';
-
-const StyledCenteredButton = styled(Button)`
- box-sizing: border-box;
- margin-top: ${themeCssVariables.spacing[2]};
-`;
-
-const StyledDescription = styled(Dialog.Description)`
- color: inherit;
- font-size: inherit;
- line-height: inherit;
- margin-bottom: ${themeCssVariables.spacing[6]};
-`;
const defaultConfirmButtonText = msg`Confirm`;
@@ -92,20 +77,14 @@ export const ConfirmationDialog = ({
<Dialog.Popup
onKeyDown={onKeyDown}
data-globally-prevent-click-outside
- style={{
- padding: 'var(--t-spacing-6)',
- borderRadius: 'var(--t-spacing-1)',
- width: 'calc(400px - var(--t-spacing-32))',
- }}
+ size="sm"
>
- <Dialog.Title>{title}</Dialog.Title>
- <StyledDescription render={<div />}>
- <Section.Root align="center" color="primary">
- {subtitle}
- </Section.Root>
- </StyledDescription>
+ <Dialog.Header>
+ <Dialog.Title>{title}</Dialog.Title>
+ <Dialog.Description render={<div />}>{subtitle}</Dialog.Description>
+ </Dialog.Header>
{isNonEmptyString(confirmationValue) && (
- <Section.Root>
+ <Dialog.Body>
<SettingsTextInput
instanceId="confirmation-modal-input"
dataTestId="confirmation-modal-input"
@@ -116,29 +95,31 @@ export const ConfirmationDialog = ({
disableHotkeys
key={'input-' + confirmationValue}
/>
- </Section.Root>
- )}
- {!hideCancelButton && (
- <StyledCenteredButton
- onClick={handleCancelClick}
- fullWidth
- data-testid="confirmation-modal-cancel-button"
- variant="outline"
- >{t`Cancel`}</StyledCenteredButton>
+ </Dialog.Body>
)}
+ <Dialog.Footer>
+ {!hideCancelButton && (
+ <Button
+ onClick={handleCancelClick}
+ fullWidth
+ data-testid="confirmation-modal-cancel-button"
+ variant="outline"
+ >{t`Cancel`}</Button>
+ )}
- {AdditionalButtons}
+ {AdditionalButtons}
- <StyledCenteredButton
- onClick={handleConfirmClick}
- disabled={!isValidValue || loading}
- fullWidth
- data-testid="confirmation-modal-confirm-button"
- variant={confirmButtonColor === 'neutral' ? 'outline' : 'solid'}
- color={confirmButtonColor}
- >
- {translatedConfirmButtonText}
- </StyledCenteredButton>
+ <Button
+ onClick={handleConfirmClick}
+ disabled={!isValidValue || loading}
+ fullWidth
+ data-testid="confirmation-modal-confirm-button"
+ variant={confirmButtonColor === 'neutral' ? 'outline' : 'solid'}
+ color={confirmButtonColor}
+ >
+ {translatedConfirmButtonText}
+ </Button>
+ </Dialog.Footer>
</Dialog.Popup>
)}
</DialogInstance>
diff --git a/packages/twenty-front/src/modules/ui/layout/dialog/components/__stories__/ConfirmationDialog.stories.tsx b/packages/twenty-front/src/modules/ui/layout/dialog/components/__stories__/ConfirmationDialog.stories.tsx
index 66eeca14d2e..d3531e876c0 100644
--- a/packages/twenty-front/src/modules/ui/layout/dialog/components/__stories__/ConfirmationDialog.stories.tsx
+++ b/packages/twenty-front/src/modules/ui/layout/dialog/components/__stories__/ConfirmationDialog.stories.tsx
@@ -10,6 +10,8 @@ import { isDialogOpenedComponentState } from '@/ui/layout/dialog/states/isDialog
import { focusStackState } from '@/ui/utilities/focus/states/focusStackState';
import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';
import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
+import { Button } from 'twenty-ui/primitives/input';
+import { isDefined } from 'twenty-shared/utils';
import { ComponentDecorator } from 'twenty-ui/testing';
import { RootDecorator } from '~/testing/decorators/RootDecorator';
@@ -62,30 +64,54 @@ export const Default: Story = {
{ name: 'Pariatur labore.' },
);
const title = within(dialog).getByRole('heading', { level: 2 });
- const subtitle = within(dialog).getByText(
- 'Velit dolore aliquip laborum occaecat fugiat.',
- );
+ const header = title.parentElement;
const description = canvasElement.ownerDocument.getElementById(
dialog.getAttribute('aria-describedby') ?? '',
);
+ const confirmButton = within(dialog).getByRole('button', {
+ name: 'Delete',
+ });
+ const footer = confirmButton.parentElement;
+ if (!isDefined(header) || !isDefined(description) || !isDefined(footer)) {
+ throw new Error('Confirmation dialog parts are missing');
+ }
+
+ await waitFor(() => expect(dialog).toBeVisible());
expect(dialog).toHaveAccessibleDescription(
'Velit dolore aliquip laborum occaecat fugiat.',
);
- expect(getComputedStyle(dialog).width).toBe('272px');
- expect(getComputedStyle(dialog).padding).toBe('24px');
- expect(getComputedStyle(title).marginBlockEnd).toBe('16px');
- expect(getComputedStyle(title).textAlign).toBe('center');
- expect(title).toHaveAttribute('data-size', 'lg');
- expect(getComputedStyle(subtitle).textAlign).toBe('center');
- expect(getComputedStyle(subtitle).color).toBe(
- getComputedStyle(dialog).color,
+ expect(dialog).toHaveAttribute('data-size', 'sm');
+ const dialogStyle = getComputedStyle(dialog);
+ expect(dialogStyle.width).toBe('300px');
+ expect(dialogStyle.padding).toBe('0px');
+ expect(dialogStyle.borderRadius).toBe(
+ dialogStyle.getPropertyValue('--t-border-radius-md').trim(),
);
- expect(getComputedStyle(subtitle).lineHeight).toBe(
- getComputedStyle(dialog).lineHeight,
+ expect(header).toHaveStyle({ padding: '24px', gap: '8px' });
+ expect(title).toHaveStyle({
+ 'margin-block-end': '0px',
+ textAlign: 'center',
+ });
+ expect(title).toHaveAttribute('data-size', 'lg');
+ expect(description).toHaveStyle({
+ color: getComputedStyle(dialog).getPropertyValue(
+ '--t-font-color-secondary',
+ ),
+ margin: '0px',
+ textAlign: 'center',
+ });
+ const descriptionStyle = getComputedStyle(description);
+ expect(Number.parseFloat(descriptionStyle.lineHeight)).toBe(
+ Number.parseFloat(descriptionStyle.fontSize) * 1.5,
);
- expect(description).not.toBeNull();
- expect(getComputedStyle(description!).marginBottom).toBe('24px');
+ expect(footer).toHaveStyle({
+ gap: '8px',
+ padding: '0px 24px 24px',
+ });
+ for (const button of within(footer).getAllByRole('button')) {
+ expect(button).toHaveStyle({ width: '252px', 'margin-top': '0px' });
+ }
},
};
@@ -124,6 +150,30 @@ export const InputConfirmation: Story = {
confirmationValue: '[email protected]',
confirmationPlaceholder: '[email protected]',
...Default.args,
+ onConfirmClick: fn(),
+ },
+ play: async ({ canvasElement, args }) => {
+ const body = within(canvasElement.ownerDocument.body);
+ const dialog = await body.findByRole('dialog', {
+ name: 'Pariatur labore.',
+ });
+ const input = within(dialog).getByTestId('confirmation-modal-input');
+ const confirmButton = within(dialog).getByRole('button', {
+ name: 'Delete',
+ });
+
+ await waitFor(() => expect(input).toHaveFocus());
+ expect(confirmButton).toBeDisabled();
+ await userEvent.type(input, 'incorrect');
+ await userEvent.keyboard('{Enter}');
+ expect(args.onConfirmClick).not.toHaveBeenCalled();
+ expect(dialog).toBeInTheDocument();
+ await userEvent.clear(input);
+ await userEvent.type(input, '[email protected]');
+ await waitFor(() => expect(confirmButton).toBeEnabled());
+ await userEvent.keyboard('{Enter}');
+ await waitFor(() => expect(args.onConfirmClick).toHaveBeenCalledOnce());
+ await waitFor(() => expect(dialog).not.toBeInTheDocument());
},
};
@@ -316,3 +366,61 @@ export const PreventConfirmationWhileLoading: Story = {
expect(dialog).toBeInTheDocument();
},
};
+
+export const AdditionalActions: Story = {
+ args: {
+ ...Default.args,
+ AdditionalButtons: (
+ <Button fullWidth variant="outline">
+ Alternative action
+ </Button>
+ ),
+ },
+ play: async ({ canvasElement }) => {
+ const dialog = await within(canvasElement.ownerDocument.body).findByRole(
+ 'dialog',
+ { name: 'Pariatur labore.' },
+ );
+ const buttons = within(dialog).getAllByRole('button');
+ expect(buttons.map((button) => button.textContent)).toEqual([
+ 'Cancel',
+ 'Alternative action',
+ 'Delete',
+ ]);
+ await waitFor(() => expect(buttons[0]).toHaveFocus());
+ await userEvent.tab();
+ expect(buttons[1]).toHaveFocus();
+ await userEvent.tab();
+ expect(buttons[2]).toHaveFocus();
+ for (const button of buttons) {
+ expect(button).toHaveStyle({ width: '252px', 'margin-top': '0px' });
+ }
+ },
+};
+
+export const HiddenCancelWithAdditionalAction: Story = {
+ args: {
+ ...AdditionalActions.args,
+ hideCancelButton: true,
+ onConfirmClick: fn(),
+ },
+ play: async ({ canvasElement, args }) => {
+ const dialog = await within(canvasElement.ownerDocument.body).findByRole(
+ 'dialog',
+ { name: 'Pariatur labore.' },
+ );
+ expect(within(dialog).queryByRole('button', { name: 'Cancel' })).toBeNull();
+ const additionalButton = within(dialog).getByRole('button', {
+ name: 'Alternative action',
+ });
+ const confirmButton = within(dialog).getByRole('button', {
+ name: 'Delete',
+ });
+ await waitFor(() => expect(additionalButton).toHaveFocus());
+ await userEvent.tab();
+ expect(confirmButton).toHaveFocus();
+ await userEvent.click(confirmButton);
+ await waitFor(() => expect(args.onConfirmClick).toHaveBeenCalledOnce());
+ await waitFor(() => expect(dialog).not.toBeInTheDocument());
+ },
+};
diff --git a/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminApplicationRegistrationDangerZone.tsx b/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminApplicationRegistrationDangerZone.tsx
index 97a2764a5fc..c8301c536e9 100644
--- a/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminApplicationRegistrationDangerZone.tsx
+++ b/packages/twenty-front/src/pages/settings/admin-panel/SettingsAdminApplicationRegistrationDangerZone.tsx
@@ -39,14 +39,6 @@ const TRANSFER_OWNERSHIP_MODAL_ID =
const DELETE_REGISTRATION_BUTTON_ID = 'delete-registration-button';
-const StyledActionButton = styled(Button)`
- margin-top: ${themeCssVariables.spacing[2]};
-`;
-
-const StyledDescriptionSection = styled(Section.Root)`
- margin-bottom: ${themeCssVariables.spacing[6]};
-`;
-
const StyledDangerButtonGroup = styled.div`
display: flex;
gap: ${themeCssVariables.spacing[2]};
@@ -300,17 +292,15 @@ export const SettingsAdminApplicationRegistrationDangerZone = ({
<Dialog.Popup
onKeyDown={onKeyDown}
data-globally-prevent-click-outside
- style={{
- padding: 'var(--t-spacing-6)',
- borderRadius: 'var(--t-spacing-1)',
- width: 'calc(400px - var(--t-spacing-32))',
- }}
+ size="sm"
>
- <Dialog.Title>{t`Transfer ownership`}</Dialog.Title>
- <StyledDescriptionSection align="center" color="primary">
- {t`Enter the workspace subdomain to transfer this app to. You will lose access to manage it.`}
- </StyledDescriptionSection>
- <Section.Root>
+ <Dialog.Header>
+ <Dialog.Title>{t`Transfer ownership`}</Dialog.Title>
+ <Dialog.Description>
+ {t`Enter the workspace subdomain to transfer this app to. You will lose access to manage it.`}
+ </Dialog.Description>
+ </Dialog.Header>
+ <Dialog.Body>
<SettingsTextInput
instanceId="transfer-ownership-subdomain"
value={transferSubdomain}
@@ -321,24 +311,26 @@ export const SettingsAdminApplicationRegistrationDangerZone = ({
label={t`Target workspace subdomain`}
autoFocusOnMount
/>
- </Section.Root>
- <StyledActionButton
- onClick={() => {
- closeDialog(TRANSFER_OWNERSHIP_MODAL_ID);
- setTransferSubdomain('');
- }}
- fullWidth
- variant="outline"
- >{t`Cancel`}</StyledActionButton>
- <StyledActionButton
- onClick={handleTransferOwnership}
- disabled={
- !isNonEmptyString(transferSubdomain.trim()) || isTransferring
- }
- fullWidth
- variant="outline"
- color="danger"
- >{t`Transfer`}</StyledActionButton>
+ </Dialog.Body>
+ <Dialog.Footer>
+ <Button
+ onClick={() => {
+ closeDialog(TRANSFER_OWNERSHIP_MODAL_ID);
+ setTransferSubdomain('');
+ }}
+ fullWidth
+ variant="outline"
+ >{t`Cancel`}</Button>
+ <Button
+ onClick={handleTransferOwnership}
+ disabled={
+ !isNonEmptyString(transferSubdomain.trim()) || isTransferring
+ }
+ fullWidth
+ variant="outline"
+ color="danger"
+ >{t`Transfer`}</Button>
+ </Dialog.Footer>
</Dialog.Popup>
)}
</DialogInstance>
diff --git a/packages/twenty-front/src/pages/settings/admin-panel/__stories__/SettingsAdminApplicationRegistrationDangerZone.stories.tsx b/packages/twenty-front/src/pages/settings/admin-panel/__stories__/SettingsAdminApplicationRegistrationDangerZone.stories.tsx
new file mode 100644
index 00000000000..e87ff6f991a
--- /dev/null
+++ b/packages/twenty-front/src/pages/settings/admin-panel/__stories__/SettingsAdminApplicationRegistrationDangerZone.stories.tsx
@@ -0,0 +1,170 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { graphql, HttpResponse } from 'msw';
+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
+import { isDefined } from 'twenty-shared/utils';
+
+import { currentUserWorkspaceState } from '@/auth/states/currentUserWorkspaceState';
+import { ApolloAdminClientContext } from '@/settings/admin-panel/apollo/contexts/ApolloAdminClientContext';
+import { jotaiStore } from '@/ui/utilities/state/jotai/jotaiStore';
+import {
+ ApplicationRegistrationSourceType,
+ PermissionFlagType,
+ type ApplicationRegistration,
+ type TransferApplicationRegistrationOwnershipMutation,
+ type TransferApplicationRegistrationOwnershipMutationVariables,
+} from '~/generated-metadata/graphql';
+import { SettingsAdminApplicationRegistrationDangerZone } from '~/pages/settings/admin-panel/SettingsAdminApplicationRegistrationDangerZone';
+import { ComponentDecorator } from 'twenty-ui/testing';
+import { ToastStoryContainer } from '~/testing/components/ToastStoryContainer';
+import { MemoryRouterDecorator } from '~/testing/decorators/MemoryRouterDecorator';
+import { ToastDecorator } from '~/testing/decorators/ToastDecorator';
+import { mockedApolloClient } from '~/testing/mockedApolloClient';
+
+const REGISTRATION: ApplicationRegistration = {
+ id: '20202020-1a2b-4c3d-8e4f-000000000001',
+ name: 'Acme app',
+ universalIdentifier: 'acme-app',
+ oAuthClientId: 'acme-app-client',
+ oAuthRedirectUris: [],
+ oAuthScopes: [],
+ galleryImagesUrls: [],
+ sourceType: ApplicationRegistrationSourceType.NPM,
+ isConfigured: true,
+ isListed: false,
+ isPreInstalled: false,
+ isVetted: false,
+ ownerWorkspaceId: '20202020-1a2b-4c3d-8e4f-000000000002',
+ createdAt: '2026-01-01T00:00:00.000Z',
+ updatedAt: '2026-01-01T00:00:00.000Z',
+};
+
+const transferOwnershipRequest = fn();
+let finishTransferRequest: (() => void) | undefined;
+
+const meta: Meta<typeof SettingsAdminApplicationRegistrationDangerZone> = {
+ title:
+ 'Pages/Settings/AdminPanel/SettingsAdminApplicationRegistrationDangerZone',
+ component: SettingsAdminApplicationRegistrationDangerZone,
+ args: { registration: REGISTRATION },
+ decorators: [
+ (Story) => (
+ <ApolloAdminClientContext.Provider value={mockedApolloClient}>
+ <ToastStoryContainer>
+ <Story />
+ </ToastStoryContainer>
+ </ApolloAdminClientContext.Provider>
+ ),
+ ToastDecorator,
+ MemoryRouterDecorator,
+ ComponentDecorator,
+ ],
+ beforeEach: async () => {
+ await mockedApolloClient.clearStore();
+ transferOwnershipRequest.mockClear();
+ finishTransferRequest = undefined;
+ jotaiStore.set(currentUserWorkspaceState.atom, {
+ permissionFlags: [PermissionFlagType.APPLICATIONS],
+ objectsPermissions: [],
+ twoFactorAuthenticationMethodSummary: [],
+ isImpersonating: false,
+ });
+
+ return () => finishTransferRequest?.();
+ },
+ parameters: {
+ msw: {
+ handlers: [
+ graphql.query('FindApplicationRegistrationInstallCount', () =>
+ HttpResponse.json({
+ data: { findApplicationRegistrationStats: { activeInstalls: 0 } },
+ }),
+ ),
+ graphql.mutation<
+ TransferApplicationRegistrationOwnershipMutation,
+ TransferApplicationRegistrationOwnershipMutationVariables
+ >('TransferApplicationRegistrationOwnership', async ({ variables }) => {
+ transferOwnershipRequest(variables);
+ await new Promise<void>((resolve) => {
+ finishTransferRequest = resolve;
+ });
+ return HttpResponse.json({
+ errors: [{ message: 'Transfer failed' }],
+ });
+ }),
+ ],
+ },
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof SettingsAdminApplicationRegistrationDangerZone>;
+
+export const TransferFailurePreservesInput: Story = {
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+ const openTransferButton = canvas.getByRole('button', {
+ name: 'Transfer ownership',
+ });
+ await userEvent.click(openTransferButton);
+ const dialog = await body.findByRole('dialog', {
+ name: 'Transfer ownership',
+ });
+ const input = within(dialog).getByRole('textbox', {
+ name: 'Target workspace subdomain',
+ });
+ const transferButton = within(dialog).getByRole('button', {
+ name: 'Transfer',
+ });
+
+ await waitFor(() => expect(input).toHaveFocus());
+ expect(transferButton).toBeDisabled();
+ expect(transferButton).toHaveAttribute('data-color', 'danger');
+ expect(transferButton).toHaveAttribute('data-variant', 'outline');
+ await userEvent.type(input, ' ');
+ expect(transferButton).toBeDisabled();
+ await userEvent.clear(input);
+ await userEvent.type(input, ' target-workspace ');
+ await waitFor(() => expect(transferButton).toBeEnabled());
+ await userEvent.keyboard('{Enter}');
+ expect(transferOwnershipRequest).not.toHaveBeenCalled();
+ expect(transferButton).toBeEnabled();
+ await userEvent.click(transferButton);
+ await waitFor(() =>
+ expect(transferOwnershipRequest).toHaveBeenCalledWith({
+ applicationRegistrationId: REGISTRATION.id,
+ targetWorkspaceSubdomain: 'target-workspace',
+ }),
+ );
+ expect(transferOwnershipRequest).toHaveBeenCalledOnce();
+ await waitFor(() => expect(transferButton).toBeDisabled());
+ expect(dialog).toBeVisible();
+
+ if (!isDefined(finishTransferRequest)) {
+ throw new Error('Transfer request has not started');
+ }
+ finishTransferRequest();
+
+ await body.findByText(
+ 'Failed to transfer ownership. Check that the subdomain is correct.',
+ );
+ await waitFor(() => expect(transferButton).toBeEnabled());
+ expect(dialog).toBeVisible();
+ expect(input).toHaveValue('target-workspace ');
+ await userEvent.click(
+ within(dialog).getByRole('button', { name: 'Cancel' }),
+ );
+ await waitFor(() => expect(dialog).not.toBeInTheDocument());
+ await userEvent.click(openTransferButton);
+ const reopenedDialog = await body.findByRole('dialog', {
+ name: 'Transfer ownership',
+ });
+ const reopenedInput = within(reopenedDialog).getByRole('textbox', {
+ name: 'Target workspace subdomain',
+ });
+ await waitFor(() => expect(reopenedInput).toHaveFocus());
+ expect(reopenedInput).toHaveValue('');
+ await userEvent.keyboard('{Escape}');
+ await waitFor(() => expect(reopenedDialog).not.toBeInTheDocument());
+ },
+};