Skip to content

The open alternative to Salesforce, designed for AI.

Use shared settings dialog layouts (#28436)

Raphaël Bosi3dc35efb4857
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceCreditGrantModal.tsx b/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceCreditGrantModal.tsx
index a622d948d6a..003af0e0e3f 100644
--- a/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceCreditGrantModal.tsx
+++ b/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceCreditGrantModal.tsx
@@ -13,7 +13,6 @@ import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { useState } from 'react';
import { useToast } from 'twenty-ui/components/feedback';
-import { Section } from 'twenty-ui/components/layout';
import { Button } from 'twenty-ui/primitives/input';
import { Dialog } from 'twenty-ui/primitives/surfaces';
import { themeCssVariables } from 'twenty-ui/theme';
@@ -27,22 +26,12 @@ type SettingsAdminWorkspaceCreditGrantModalProps = {
workspaceId: string;
};
-const StyledSectionContainer = styled.div`
- margin-bottom: ${themeCssVariables.spacing[6]};
-`;
-
const StyledFields = styled.div`
display: flex;
flex-direction: column;
gap: ${themeCssVariables.spacing[4]};
`;
-const StyledModalActions = styled.div`
- display: flex;
- gap: ${themeCssVariables.spacing[2]};
- margin-top: ${themeCssVariables.spacing[6]};
-`;
-
const StyledActionSlot = styled.div`
flex: 1;
`;
@@ -141,71 +130,66 @@ export const SettingsAdminWorkspaceCreditGrantModal = ({
{({ onKeyDown }) => (
<Dialog.Popup
onKeyDown={onKeyDown}
- size="md"
+ size="compact"
data-globally-prevent-click-outside
- style={{
- padding: 'var(--t-spacing-6)',
- borderRadius: 'var(--t-spacing-1)',
- width: '360px',
- }}
>
- <Dialog.Title>{t`Grant credits`}</Dialog.Title>
- <StyledSectionContainer>
- <Section.Root align="center" color="primary">
+ <Dialog.Header>
+ <Dialog.Title>{t`Grant credits`}</Dialog.Title>
+ <Dialog.Description>
{t`Credits are added on top of the plan allowance and are spent only once it runs out. They carry over in full from one billing period to the next, and stay available until they are used up or, where an expiry is set, until the end of the billing period that expiry falls in.`}
- </Section.Root>
- </StyledSectionContainer>
-
- <StyledFields>
- <SettingsTextInput
- instanceId={`${modalInstanceId}-amount`}
- label={t`Amount`}
- placeholder="200"
- type="number"
- min={0}
- leftAdornment="$"
- value={amount}
- onChange={setAmount}
- autoFocusOnMount
- fullWidth
- />
-
- <Select
- dropdownId={`${modalInstanceId}-type`}
- label={t`Type`}
- value={type}
- options={GRANTABLE_CREDIT_GRANT_TYPES.map((grantType) => ({
- value: grantType,
- label: t(CREDIT_GRANT_TYPE_LABELS[grantType]),
- }))}
- onChange={setType}
- fullWidth
- />
-
- <Select
- dropdownId={`${modalInstanceId}-expires-in-days`}
- label={t`Expires`}
- value={expiresInDays}
- options={CREDIT_GRANT_EXPIRY_OPTIONS.map((option) => ({
- value: option.value,
- label: t(option.label),
- }))}
- onChange={setExpiresInDays}
- fullWidth
- />
-
- <SettingsTextInput
- instanceId={`${modalInstanceId}-reason`}
- label={t`Reason`}
- placeholder={t`Goodwill gesture after the March incident`}
- value={reason}
- onChange={setReason}
- maxLength={500}
- fullWidth
- />
- </StyledFields>
-
- <StyledModalActions>
+ </Dialog.Description>
+ </Dialog.Header>
+ <Dialog.Body>
+ <StyledFields>
+ <SettingsTextInput
+ instanceId={`${modalInstanceId}-amount`}
+ label={t`Amount`}
+ placeholder="200"
+ type="number"
+ min={0}
+ leftAdornment="$"
+ value={amount}
+ onChange={setAmount}
+ autoFocusOnMount
+ fullWidth
+ />
+
+ <Select
+ dropdownId={`${modalInstanceId}-type`}
+ label={t`Type`}
+ value={type}
+ options={GRANTABLE_CREDIT_GRANT_TYPES.map((grantType) => ({
+ value: grantType,
+ label: t(CREDIT_GRANT_TYPE_LABELS[grantType]),
+ }))}
+ onChange={setType}
+ fullWidth
+ />
+
+ <Select
+ dropdownId={`${modalInstanceId}-expires-in-days`}
+ label={t`Expires`}
+ value={expiresInDays}
+ options={CREDIT_GRANT_EXPIRY_OPTIONS.map((option) => ({
+ value: option.value,
+ label: t(option.label),
+ }))}
+ onChange={setExpiresInDays}
+ fullWidth
+ />
+
+ <SettingsTextInput
+ instanceId={`${modalInstanceId}-reason`}
+ label={t`Reason`}
+ placeholder={t`Goodwill gesture after the March incident`}
+ value={reason}
+ onChange={setReason}
+ maxLength={500}
+ fullWidth
+ />
+ </StyledFields>
+ </Dialog.Body>
+ <Dialog.Footer>
<StyledActionSlot>
<Button
onClick={handleClose}
@@ -222,7 +206,7 @@ export const SettingsAdminWorkspaceCreditGrantModal = ({
color="accent"
>{t`Grant`}</Button>
</StyledActionSlot>
- </StyledModalActions>
+ </Dialog.Footer>
</Dialog.Popup>
)}
</DialogInstance>
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceUsageLimitModal.tsx b/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceUsageLimitModal.tsx
index e7f024f9dd3..80d0d3e13f5 100644
--- a/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceUsageLimitModal.tsx
+++ b/packages/twenty-front/src/modules/settings/admin-panel/components/SettingsAdminWorkspaceUsageLimitModal.tsx
@@ -4,7 +4,6 @@ import { useLingui } from '@lingui/react/macro';
import { useState } from 'react';
import { isDefined, isNonEmptyString } from 'twenty-shared/utils';
import { useToast } from 'twenty-ui/components/feedback';
-import { Section } from 'twenty-ui/components/layout';
import { Button } from 'twenty-ui/primitives/input';
import { Dialog } from 'twenty-ui/primitives/surfaces';
import { themeCssVariables } from 'twenty-ui/theme';
@@ -30,22 +29,12 @@ type SettingsAdminWorkspaceUsageLimitModalProps = {
row: AdminUsageLimitRow;
};
-const StyledSectionContainer = styled.div`
- margin-bottom: ${themeCssVariables.spacing[6]};
-`;
-
const StyledFields = styled.div`
display: flex;
flex-direction: column;
gap: ${themeCssVariables.spacing[4]};
`;
-const StyledActions = styled.div`
- display: flex;
- gap: ${themeCssVariables.spacing[2]};
- margin-top: ${themeCssVariables.spacing[6]};
-`;
-
const StyledActionSlot = styled.div`
flex: 1;
`;
@@ -201,48 +190,43 @@ export const SettingsAdminWorkspaceUsageLimitModal = ({
{({ onKeyDown }) => (
<Dialog.Popup
onKeyDown={onKeyDown}
- size="md"
+ size="compact"
data-globally-prevent-click-outside
- style={{
- padding: 'var(--t-spacing-6)',
- borderRadius: 'var(--t-spacing-1)',
- width: '360px',
- }}
>
- <Dialog.Title>{t`Set limit for this workspace`}</Dialog.Title>
- <StyledSectionContainer>
- <Section.Root align="center" color="primary">
+ <Dialog.Header>
+ <Dialog.Title>{t`Set limit for this workspace`}</Dialog.Title>
+ <Dialog.Description>
{t`${scopeLabel} — the instance default is ${defaultText}. Saving applies to this workspace only.`}
- </Section.Root>
- </StyledSectionContainer>
-
- <StyledFields>
- <SettingsTextInput
- instanceId={`${dialogId}-limit-value`}
- label={t(unitLabel.name)}
- type="number"
- min={1}
- value={limitValue}
- onChange={setLimitValue}
- autoFocusOnMount
- fullWidth
- />
-
- {isBurstAllowed && (
+ </Dialog.Description>
+ </Dialog.Header>
+ <Dialog.Body>
+ <StyledFields>
<SettingsTextInput
- instanceId={`${dialogId}-burst-value`}
- label={t`Burst`}
- placeholder={t`Same as the limit`}
+ instanceId={`${dialogId}-limit-value`}
+ label={t(unitLabel.name)}
type="number"
min={1}
- value={burstValue}
- onChange={setBurstValue}
+ value={limitValue}
+ onChange={setLimitValue}
+ autoFocusOnMount
fullWidth
/>
- )}
- </StyledFields>
- <StyledActions>
+ {isBurstAllowed && (
+ <SettingsTextInput
+ instanceId={`${dialogId}-burst-value`}
+ label={t`Burst`}
+ placeholder={t`Same as the limit`}
+ type="number"
+ min={1}
+ value={burstValue}
+ onChange={setBurstValue}
+ fullWidth
+ />
+ )}
+ </StyledFields>
+ </Dialog.Body>
+ <Dialog.Footer>
{row.isOverridden && (
<StyledActionSlot>
<Button
@@ -270,7 +254,7 @@ export const SettingsAdminWorkspaceUsageLimitModal = ({
color="accent"
>{t`Save`}</Button>
</StyledActionSlot>
- </StyledActions>
+ </Dialog.Footer>
</Dialog.Popup>
)}
</DialogInstance>
diff --git a/packages/twenty-front/src/modules/settings/billing/components/AddCreditCardModal.tsx b/packages/twenty-front/src/modules/settings/billing/components/AddCreditCardModal.tsx
index 9fd67fef78d..ae14e177bbe 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/AddCreditCardModal.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/AddCreditCardModal.tsx
@@ -1,12 +1,9 @@
import { DialogInstance } from '@/ui/layout/dialog/components/DialogInstance';
import { AddPaymentMethodForm } from '@/settings/billing/components/AddPaymentMethodForm';
import { useDialog } from '@/ui/layout/dialog/hooks/useDialog';
-import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
-import { Section } from 'twenty-ui/components/layout';
import { Dialog } from 'twenty-ui/primitives/surfaces';
import { Button } from 'twenty-ui/primitives/input';
-import { themeCssVariables } from 'twenty-ui/theme';
type AddCreditCardModalProps = {
modalInstanceId: string;
@@ -14,14 +11,6 @@ type AddCreditCardModalProps = {
onPaymentMethodAdded: () => Promise<void>;
};
-const StyledSectionContainer = styled.div`
- margin-bottom: ${themeCssVariables.spacing[6]};
-`;
-
-const StyledCancelButtonContainer = styled.div`
- margin-top: ${themeCssVariables.spacing[4]};
-`;
-
export const AddCreditCardModal = ({
modalInstanceId,
finalRedirectPath,
@@ -47,28 +36,26 @@ export const AddCreditCardModal = ({
onKeyDown={onKeyDown}
size="md"
data-globally-prevent-click-outside
- style={{
- padding: 'var(--t-spacing-6)',
- borderRadius: 'var(--t-spacing-1)',
- }}
>
- <Dialog.Title>{t`Add your credit card`}</Dialog.Title>
- <StyledSectionContainer>
- <Section.Root align="center" color="primary">
+ <Dialog.Header>
+ <Dialog.Title>{t`Add your credit card`}</Dialog.Title>
+ <Dialog.Description>
{t`Add your credit card below. Once added, your subscription will start automatically.`}
- </Section.Root>
- </StyledSectionContainer>
- <AddPaymentMethodForm
- finalRedirectPath={finalRedirectPath}
- onPaymentMethodAdded={handlePaymentMethodAdded}
- />
- <StyledCancelButtonContainer>
+ </Dialog.Description>
+ </Dialog.Header>
+ <Dialog.Body>
+ <AddPaymentMethodForm
+ finalRedirectPath={finalRedirectPath}
+ onPaymentMethodAdded={handlePaymentMethodAdded}
+ />
+ </Dialog.Body>
+ <Dialog.Footer>
<Button
onClick={() => closeDialog(modalInstanceId)}
fullWidth
variant="outline"
>{t`Cancel`}</Button>
- </StyledCancelButtonContainer>
+ </Dialog.Footer>
</Dialog.Popup>
)}
</DialogInstance>
diff --git a/packages/twenty-front/src/modules/settings/billing/components/UpdatePaymentMethodModal.tsx b/packages/twenty-front/src/modules/settings/billing/components/UpdatePaymentMethodModal.tsx
index 1d87d16fa09..000c85a08fb 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/UpdatePaymentMethodModal.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/UpdatePaymentMethodModal.tsx
@@ -5,26 +5,15 @@ import { isSubscriptionPaymentOverdue } from '@/settings/billing/utils/isSubscri
import { DialogInstance } from '@/ui/layout/dialog/components/DialogInstance';
import { useDialog } from '@/ui/layout/dialog/hooks/useDialog';
import { useSubscriptionStatus } from '@/workspace/hooks/useSubscriptionStatus';
-import { styled } from '@linaria/react';
import { useLingui } from '@lingui/react/macro';
import { useToast } from 'twenty-ui/components/feedback';
-import { Section } from 'twenty-ui/components/layout';
import { Button } from 'twenty-ui/primitives/input';
import { Dialog } from 'twenty-ui/primitives/surfaces';
-import { themeCssVariables } from 'twenty-ui/theme';
type UpdatePaymentMethodModalProps = {
modalInstanceId: string;
};
-const StyledSectionContainer = styled.div`
- margin-bottom: ${themeCssVariables.spacing[6]};
-`;
-
-const StyledCancelButtonContainer = styled.div`
- margin-top: ${themeCssVariables.spacing[4]};
-`;
-
export const UpdatePaymentMethodModal = ({
modalInstanceId,
}: UpdatePaymentMethodModalProps) => {
@@ -61,28 +50,26 @@ export const UpdatePaymentMethodModal = ({
onKeyDown={onKeyDown}
size="md"
data-globally-prevent-click-outside
- style={{
- padding: 'var(--t-spacing-6)',
- borderRadius: 'var(--t-spacing-1)',
- }}
>
- <Dialog.Title>{t`Update your payment method`}</Dialog.Title>
- <StyledSectionContainer>
- <Section.Root align="center" color="primary">
+ <Dialog.Header>
+ <Dialog.Title>{t`Update your payment method`}</Dialog.Title>
+ <Dialog.Description>
{t`Add a card below to update your billing details and retry your payment.`}
- </Section.Root>
- </StyledSectionContainer>
- <AddPaymentMethodForm
- onPaymentMethodAdded={handlePaymentMethodAdded}
- shouldStartSubscriptionAfterPaymentMethod={false}
- />
- <StyledCancelButtonContainer>
+ </Dialog.Description>
+ </Dialog.Header>
+ <Dialog.Body>
+ <AddPaymentMethodForm
+ onPaymentMethodAdded={handlePaymentMethodAdded}
+ shouldStartSubscriptionAfterPaymentMethod={false}
+ />
+ </Dialog.Body>
+ <Dialog.Footer>
<Button
onClick={() => closeDialog(modalInstanceId)}
fullWidth
variant="outline"
>{t`Cancel`}</Button>
- </StyledCancelButtonContainer>
+ </Dialog.Footer>
</Dialog.Popup>
)}
</DialogInstance>
diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/ResourceCreditPackagePickerModal.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/ResourceCreditPackagePickerModal.tsx
index 6600c698d0a..21c3fc9afc6 100644
--- a/packages/twenty-front/src/modules/settings/billing/components/internal/ResourceCreditPackagePickerModal.tsx
+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/ResourceCreditPackagePickerModal.tsx
@@ -6,7 +6,6 @@ import { t } from '@lingui/core/macro';
import { AnimatePresence, motion } from 'framer-motion';
import { type ElementType, type ReactNode } from 'react';
import { isDefined } from 'twenty-shared/utils';
-import { Section } from 'twenty-ui/components/layout';
import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
import {
IconCoins,
@@ -21,22 +20,6 @@ import { themeCssVariables, useTheme } from 'twenty-ui/theme';
const PACKAGE_SUMMARY_ROW_HEIGHT = 24;
const PACKAGE_SUMMARY_ROW_GAP = 4;
-const StyledCenteredTitle = styled.div`
- text-align: center;
-
- h2 {
- margin-bottom: ${themeCssVariables.spacing[6]};
- }
-`;
-
-const StyledSectionContainer = styled.div`
- font-size: ${themeCssVariables.font.size.md};
- line-height: 1.4;
- margin-bottom: ${themeCssVariables.spacing[6]};
- text-box-edge: cap alphabetic;
- text-box-trim: trim-both;
-`;
-
const StyledPackageCard = styled.div`
background-color: ${themeCssVariables.background.secondary};
border: 1px solid ${themeCssVariables.border.color.medium};
@@ -166,12 +149,6 @@ const StyledCurrentValueText = styled.span`
}
`;
-const StyledModalActions = styled.div`
- display: flex;
- gap: ${themeCssVariables.spacing[2]};
- margin-top: ${themeCssVariables.spacing[6]};
-`;
-
const StyledActionSlot = styled.div`
flex: 1;
`;
@@ -258,153 +235,148 @@ export const ResourceCreditPackagePickerModal = ({
{({ onKeyDown }) => (
<Dialog.Popup
onKeyDown={onKeyDown}
- size="md"
+ size="compact"
data-globally-prevent-click-outside
- style={{
- padding: 'var(--t-spacing-6)',
- borderRadius: 'var(--t-spacing-1)',
- width: '360px',
- }}
>
- <StyledCenteredTitle>
+ <Dialog.Header>
<Dialog.Title>{t`Choose ${intervalAdjective} credits`}</Dialog.Title>
- </StyledCenteredTitle>
- <StyledSectionContainer>
- <Section.Root align="center" color="primary">
+ <Dialog.Description>
{t`Select the credit package to add to your ${intervalAdjective} bill.`}
- </Section.Root>
- </StyledSectionContainer>
- <StyledPackageCard>
- <StyledPackageHeader>
- <StyledPackageHeaderRow>
- <StyledPackageHeaderTitle>
- <IconCoins
- size={theme.icon.size.md}
- color={themeCssVariables.color.green9}
- />
- <StyledPackageCreditAmount>
+ </Dialog.Description>
+ </Dialog.Header>
+ <Dialog.Body>
+ <StyledPackageCard>
+ <StyledPackageHeader>
+ <StyledPackageHeaderRow>
+ <StyledPackageHeaderTitle>
+ <IconCoins
+ size={theme.icon.size.md}
+ color={themeCssVariables.color.green9}
+ />
+ <StyledPackageCreditAmount>
+ <AnimatedFormattedNumber
+ value={selectedCreditAmountValue}
+ formatValue={formatAnimatedCreditAmount}
+ />{' '}
+ {t`credits`}
+ </StyledPackageCreditAmount>
+ </StyledPackageHeaderTitle>
+ <StyledPackagePrice>
+ $
<AnimatedFormattedNumber
- value={selectedCreditAmountValue}
- formatValue={formatAnimatedCreditAmount}
- />{' '}
- {t`credits`}
- </StyledPackageCreditAmount>
- </StyledPackageHeaderTitle>
- <StyledPackagePrice>
- $
- <AnimatedFormattedNumber
- value={selectedPriceAmountValue}
- formatValue={formatAnimatedPriceAmount}
- />
- /{intervalLabel}
- </StyledPackagePrice>
- </StyledPackageHeaderRow>
- <Slider.Root
- min={0}
- max={Math.max(1, priceCount - 1)}
- step={1}
- value={selectedPriceIndex}
- onValueChange={onSliderValueChange}
- disabled={isUpdating || priceCount < 2}
- color="success"
- >
- <Slider.Control>
- <Slider.Track>
- <Slider.Indicator />
- <Slider.Thumb aria-label={t`Credit package`} />
- </Slider.Track>
- </Slider.Control>
- </Slider.Root>
- </StyledPackageHeader>
- <StyledPackageDetails>
- <StyledPackageDivider />
- <StyledPackageSummaryRows>
- {renderPackageSummaryRow({
- Icon: IconHistory,
- label: t`Current`,
- value: (
- <>
- <StyledCurrentValueText
- data-strikethrough={isChanged || undefined}
- >
- {t`${currentCreditAmountDisplay} credits `}
- </StyledCurrentValueText>
- <StyledMutedText>
+ value={selectedPriceAmountValue}
+ formatValue={formatAnimatedPriceAmount}
+ />
+ /{intervalLabel}
+ </StyledPackagePrice>
+ </StyledPackageHeaderRow>
+ <Slider.Root
+ min={0}
+ max={Math.max(1, priceCount - 1)}
+ step={1}
+ value={selectedPriceIndex}
+ onValueChange={onSliderValueChange}
+ disabled={isUpdating || priceCount < 2}
+ color="success"
+ >
+ <Slider.Control>
+ <Slider.Track>
+ <Slider.Indicator />
+ <Slider.Thumb aria-label={t`Credit package`} />
+ </Slider.Track>
+ </Slider.Control>
+ </Slider.Root>
+ </StyledPackageHeader>
+ <StyledPackageDetails>
+ <StyledPackageDivider />
+ <StyledPackageSummaryRows>
+ {renderPackageSummaryRow({
+ Icon: IconHistory,
+ label: t`Current`,
+ value: (
+ <>
<StyledCurrentValueText
data-strikethrough={isChanged || undefined}
>
- {t`($${currentCreditPriceDisplay}/${intervalLabel})`}
+ {t`${currentCreditAmountDisplay} credits `}
</StyledCurrentValueText>
- </StyledMutedText>
- </>
- ),
- })}
- <AnimatePresence initial={false}>
- {isChanged && (
- <StyledAnimatedPackageSummaryRow
- key="new-credit-package-summary-row"
- initial={{
- height: 0,
- marginBottom: 0,
- opacity: 0,
- y: -2,
- }}
- animate={{
- height: PACKAGE_SUMMARY_ROW_HEIGHT,
- marginBottom: PACKAGE_SUMMARY_ROW_GAP,
- opacity: 1,
- y: 0,
- }}
- exit={{
- height: 0,
- marginBottom: 0,
- opacity: 0,
- y: -2,
- }}
- transition={{
- duration: theme.animation.duration.fast,
- ease: 'easeInOut',
- }}
- >
- <StyledPackageSummaryLabel>
- <IconSparkles
- size={theme.icon.size.md}
- stroke={theme.icon.stroke.sm}
- color={themeCssVariables.font.color.tertiary}
- />
- <PackageSummaryLabelText label={t`New credit pack`} />
- </StyledPackageSummaryLabel>
- <StyledPackageSummaryValue>
- <span>
- $
- <AnimatedFormattedNumber
- value={selectedPriceAmountValue}
- formatValue={formatAnimatedPriceAmount}
- />
- {t` per ${intervalLabel}`}
- </span>
- </StyledPackageSummaryValue>
- </StyledAnimatedPackageSummaryRow>
- )}
- </AnimatePresence>
- {isDefined(newRolloverLimit) &&
- renderPackageSummaryRow({
- Icon: IconRefreshDot,
- label: t`New rollover limit`,
- value: (
- <StyledAmountWithUnit>
- <AnimatedFormattedNumber
- value={newRolloverLimitValue}
- formatValue={formatAnimatedRolloverLimit}
- />
- <span>{t`credits`}</span>
- </StyledAmountWithUnit>
+ <StyledMutedText>
+ <StyledCurrentValueText
+ data-strikethrough={isChanged || undefined}
+ >
+ {t`($${currentCreditPriceDisplay}/${intervalLabel})`}
+ </StyledCurrentValueText>
+ </StyledMutedText>
+ </>
),
})}
- </StyledPackageSummaryRows>
- </StyledPackageDetails>
- </StyledPackageCard>
- <StyledModalActions>
+ <AnimatePresence initial={false}>
+ {isChanged && (
+ <StyledAnimatedPackageSummaryRow
+ key="new-credit-package-summary-row"
+ initial={{
+ height: 0,
+ marginBottom: 0,
+ opacity: 0,
+ y: -2,
+ }}
+ animate={{
+ height: PACKAGE_SUMMARY_ROW_HEIGHT,
+ marginBottom: PACKAGE_SUMMARY_ROW_GAP,
+ opacity: 1,
+ y: 0,
+ }}
+ exit={{
+ height: 0,
+ marginBottom: 0,
+ opacity: 0,
+ y: -2,
+ }}
+ transition={{
+ duration: theme.animation.duration.fast,
+ ease: 'easeInOut',
+ }}
+ >
+ <StyledPackageSummaryLabel>
+ <IconSparkles
+ size={theme.icon.size.md}
+ stroke={theme.icon.stroke.sm}
+ color={themeCssVariables.font.color.tertiary}
+ />
+ <PackageSummaryLabelText label={t`New credit pack`} />
+ </StyledPackageSummaryLabel>
+ <StyledPackageSummaryValue>
+ <span>
+ $
+ <AnimatedFormattedNumber
+ value={selectedPriceAmountValue}
+ formatValue={formatAnimatedPriceAmount}
+ />
+ {t` per ${intervalLabel}`}
+ </span>
+ </StyledPackageSummaryValue>
+ </StyledAnimatedPackageSummaryRow>
+ )}
+ </AnimatePresence>
+ {isDefined(newRolloverLimit) &&
+ renderPackageSummaryRow({
+ Icon: IconRefreshDot,
+ label: t`New rollover limit`,
+ value: (
+ <StyledAmountWithUnit>
+ <AnimatedFormattedNumber
+ value={newRolloverLimitValue}
+ formatValue={formatAnimatedRolloverLimit}
+ />
+ <span>{t`credits`}</span>
+ </StyledAmountWithUnit>
+ ),
+ })}
+ </StyledPackageSummaryRows>
+ </StyledPackageDetails>
+ </StyledPackageCard>
+ </Dialog.Body>
+ <Dialog.Footer>
<StyledActionSlot>
<Button
onClick={onCancel}
@@ -421,7 +393,7 @@ export const ResourceCreditPackagePickerModal = ({
color="accent"
>{t`Confirm`}</Button>
</StyledActionSlot>
- </StyledModalActions>
+ </Dialog.Footer>
</Dialog.Popup>
)}
</DialogInstance>
diff --git a/packages/twenty-front/src/modules/settings/billing/components/internal/__stories__/ResourceCreditPackagePickerModal.stories.tsx b/packages/twenty-front/src/modules/settings/billing/components/internal/__stories__/ResourceCreditPackagePickerModal.stories.tsx
new file mode 100644
index 00000000000..c621c05c82d
--- /dev/null
+++ b/packages/twenty-front/src/modules/settings/billing/components/internal/__stories__/ResourceCreditPackagePickerModal.stories.tsx
@@ -0,0 +1,95 @@
+import {
+ type Decorator,
+ type Meta,
+ type StoryObj,
+} from '@storybook/react-vite';
+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
+import { ComponentDecorator } from 'twenty-ui/testing';
+
+import { ResourceCreditPackagePickerModal } from '@/settings/billing/components/internal/ResourceCreditPackagePickerModal';
+import { BILLING_MODAL_IDS } from '@/settings/billing/constants/BillingModalIds';
+import { isDialogOpenedComponentState } from '@/ui/layout/dialog/states/isDialogOpenedComponentState';
+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 { RootDecorator } from '~/testing/decorators/RootDecorator';
+
+const OpenDialogDecorator: Decorator = (Story) => {
+ const dialogId = BILLING_MODAL_IDS.creditPackagePicker;
+
+ jotaiStore.set(
+ isDialogOpenedComponentState.atomFamily({ instanceId: dialogId }),
+ true,
+ );
+ jotaiStore.set(focusStackState.atom, [
+ {
+ focusId: dialogId,
+ componentInstance: {
+ componentType: FocusComponentType.MODAL,
+ componentInstanceId: dialogId,
+ },
+ globalHotkeysConfig: {
+ enableGlobalHotkeysWithModifiers: true,
+ enableGlobalHotkeysConflictingWithKeyboard: true,
+ },
+ },
+ ]);
+
+ return <Story />;
+};
+
+const meta: Meta<typeof ResourceCreditPackagePickerModal> = {
+ title: 'Modules/Settings/Billing/ResourceCreditPackagePickerModal',
+ component: ResourceCreditPackagePickerModal,
+ decorators: [OpenDialogDecorator, RootDecorator, ComponentDecorator],
+ parameters: { disableHotkeyInitialization: true },
+ args: {
+ currentCreditAmountDisplay: '100',
+ currentCreditPriceDisplay: '10',
+ formatAnimatedCreditAmount: (value) => value.toFixed(0),
+ formatAnimatedPriceAmount: (value) => value.toFixed(0),
+ formatAnimatedRolloverLimit: (value) => value.toFixed(0),
+ intervalAdjective: 'monthly',
+ intervalLabel: 'month',
+ isChanged: true,
+ isConfirmDisabled: false,
+ isUpdating: false,
+ newRolloverLimit: 400,
+ newRolloverLimitValue: 400,
+ onCancel: fn(),
+ onConfirm: fn(),
+ onSliderValueChange: fn(),
+ priceCount: 3,
+ selectedCreditAmountValue: 200,
+ selectedPriceAmountValue: 20,
+ selectedPriceIndex: 1,
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof ResourceCreditPackagePickerModal>;
+
+export const KeyboardSelection: Story = {
+ play: async ({ canvasElement, args }) => {
+ const dialog = await within(canvasElement.ownerDocument.body).findByRole(
+ 'dialog',
+ { name: 'Choose monthly credits' },
+ );
+ const canvas = within(dialog);
+ const slider = canvas.getByRole('slider', { name: 'Credit package' });
+
+ await waitFor(() => expect(dialog).toBeVisible());
+ await expect(dialog).toHaveAccessibleDescription(
+ 'Select the credit package to add to your monthly bill.',
+ );
+ await userEvent.click(slider);
+ await userEvent.keyboard('{ArrowRight}');
+ await expect(args.onSliderValueChange).toHaveBeenLastCalledWith(
+ 2,
+ expect.objectContaining({ reason: 'keyboard' }),
+ );
+ await userEvent.click(canvas.getByRole('button', { name: 'Confirm' }));
+ await expect(args.onConfirm).toHaveBeenCalledOnce();
+ await expect(args.onCancel).not.toHaveBeenCalled();
+ },
+};