Skip to content

Commit

Permalink
move the trial banner component to the trial module
Browse files Browse the repository at this point in the history
  • Loading branch information
nilscox committed Jan 8, 2025
1 parent 6e6cdcf commit 3cc9d8c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
4 changes: 3 additions & 1 deletion src/intl/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1369,13 +1369,15 @@
},
"footer": "For the next 7 days, enjoy all Pro account features.",
"cta": "Let's go!"
},
"banner": {
"content": "Your trial is active for the next <strong>{days, plural, =1 {{days} day} other {{days} days}}</strong> or until your <strong>credit runs out</strong>. Enjoy exploring or <upgrade>upgrade to Pro</upgrade>!"
}
},
"layouts": {
"createOrganization": "Create organization",
"main": {
"accountUnderReview": "We need more information to approve your account. Please <link>verify your identity</link> to prevent account suspension.",
"trial": "Your trial is active for the next <strong>{days, plural, =1 {{days} day} other {{days} days}}</strong> or until your <strong>credit runs out</strong>. Enjoy exploring or <upgrade>upgrade to Pro</upgrade>!",
"sessionTokenWarning": "You are currently seeing the organization {organizationName}",
"paymentFailure": "We tried to charge your card, but the payment has failed. Please <stripe>update your payment method</stripe> and pay your past due invoices.",
"subscriptionHasPendingUpdate": "The provided payment details could not be processed. Please check your payment information in the <stripe>billing portal</stripe> to resolve the issue.",
Expand Down
22 changes: 1 addition & 21 deletions src/layouts/main/main-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { useMutation } from '@tanstack/react-query';
import clsx from 'clsx';
import { intervalToDuration } from 'date-fns';
import { Suspense, useEffect, useRef, useState } from 'react';
import { z } from 'zod';

Expand All @@ -23,9 +22,9 @@ import { useThemeModeOrPreferred } from 'src/hooks/theme';
import { createTranslate } from 'src/intl/translate';
import { CommandPalette } from 'src/modules/command-palette/command-palette';
import { CreateServiceDialog } from 'src/modules/create-service-dialog/create-service-dialog';
import { TrialBanner } from 'src/modules/trial/trial-banner';
import { TrialWelcomeDialog } from 'src/modules/trial/trial-welcome-dialog';
import { inArray } from 'src/utils/arrays';
import { defined } from 'src/utils/assert';

import { AppBreadcrumbs } from './app-breadcrumbs';
import { EstimatedCosts } from './estimated-costs';
Expand Down Expand Up @@ -152,25 +151,6 @@ function useBanner(): 'session' | 'trial' | void {
}
}

function TrialBanner() {
const trial = defined(useOrganization().trial);
const { days } = intervalToDuration({ start: new Date(), end: trial.endsAt });

const upgrade = (children: React.ReactNode) => (
<Link to={routes.organizationSettings.plans()} className="underline">
{children}
</Link>
);

return (
<FeatureFlag feature="trial">
<div className="bg-green/10 px-4 py-1.5 text-center text-green md:h-full md:whitespace-nowrap">
<T id="trial" values={{ days: defined(days) + 1, upgrade }} />
</div>
</FeatureFlag>
);
}

function SessionTokenBanner() {
const organization = useOrganization();
const { clearToken } = useToken();
Expand Down
29 changes: 29 additions & 0 deletions src/modules/trial/trial-banner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { intervalToDuration } from 'date-fns';

import { useOrganization } from 'src/api/hooks/session';
import { routes } from 'src/application/routes';
import { Link } from 'src/components/link';
import { FeatureFlag } from 'src/hooks/feature-flag';
import { createTranslate } from 'src/intl/translate';
import { defined } from 'src/utils/assert';

const T = createTranslate('trial.banner');

export function TrialBanner() {
const trial = defined(useOrganization().trial);
const { days } = intervalToDuration({ start: new Date(), end: trial.endsAt });

const upgrade = (children: React.ReactNode) => (
<Link to={routes.organizationSettings.plans()} className="underline">
{children}
</Link>
);

return (
<FeatureFlag feature="trial">
<div className="bg-green/10 px-4 py-1.5 text-center text-green md:h-full md:whitespace-nowrap">
<T id="content" values={{ days: defined(days) + 1, upgrade }} />
</div>
</FeatureFlag>
);
}

0 comments on commit 3cc9d8c

Please sign in to comment.