-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
220 additions
and
12 deletions.
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
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
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,110 @@ | ||
import clsx from 'clsx'; | ||
import { useState } from 'react'; | ||
|
||
import { Badge, Floating } from '@koyeb/design-system'; | ||
import { useOrganizationUnsafe } from 'src/api/hooks/session'; | ||
import { routes } from 'src/application/routes'; | ||
import { LinkButton } from 'src/components/link'; | ||
import { PlanIcon } from 'src/components/plan-icon'; | ||
import { useFeatureFlag } from 'src/hooks/feature-flag'; | ||
import { createTranslate, TranslateEnum } from 'src/intl/translate'; | ||
import { TrialSummaryPopup } from 'src/modules/trial/trial-summary-popup'; | ||
|
||
import { EstimatedCosts } from './estimated-costs'; | ||
|
||
const T = createTranslate('layouts.main.organizationPlan'); | ||
|
||
export function OrganizationPlan() { | ||
const [open, setOpen] = useState(false); | ||
const organization = useOrganizationUnsafe(); | ||
const trial = useFeatureFlag('trial') && organization?.trial !== undefined; | ||
|
||
if (organization?.plan === 'hobby') { | ||
return <HobbyPlan />; | ||
} | ||
|
||
return ( | ||
<Floating | ||
open={open} | ||
setOpen={setOpen} | ||
hover | ||
strategy="fixed" | ||
placement="right-end" | ||
offset={8} | ||
renderReference={(ref, props) => ( | ||
<div | ||
ref={ref} | ||
className={clsx('col gap-4 px-3 py-2 text-start transition-colors', open && 'bg-muted/50')} | ||
{...props} | ||
> | ||
<div className="row items-center gap-2"> | ||
<div> | ||
<PlanIcon plan={organization?.plan} className="size-6 text-dim" /> | ||
</div> | ||
|
||
<div> | ||
<T | ||
id="currentPlan" | ||
values={{ plan: organization && <TranslateEnum enum="plans" value={organization.plan} /> }} | ||
/> | ||
</div> | ||
|
||
{trial && ( | ||
<Badge size={1} color="green" className="ms-auto"> | ||
Trial | ||
</Badge> | ||
)} | ||
</div> | ||
|
||
{organization?.trial && ( | ||
<LinkButton | ||
variant="outline" | ||
size={1} | ||
href={routes.organizationSettings.plans()} | ||
className="w-full" | ||
> | ||
<T id="upgrade" /> | ||
</LinkButton> | ||
)} | ||
</div> | ||
)} | ||
renderFloating={(ref, props) => | ||
trial ? ( | ||
<TrialSummaryPopup ref={ref} onClose={() => setOpen(false)} className="z-30" {...props} /> | ||
) : ( | ||
<div ref={ref} {...props} className="z-30 w-56 rounded-md border bg-popover"> | ||
<EstimatedCosts /> | ||
</div> | ||
) | ||
} | ||
/> | ||
); | ||
} | ||
|
||
function HobbyPlan() { | ||
return ( | ||
<div className="col gap-3 px-3 py-2"> | ||
<div className="row items-center justify-between gap-2"> | ||
<T id="currentPlan" values={{ plan: <TranslateEnum enum="plans" value="hobby" /> }} /> | ||
|
||
<Badge size={1} color="green"> | ||
<T id="free" /> | ||
</Badge> | ||
</div> | ||
|
||
<div className="col gap-1"> | ||
<div> | ||
<T id="upsell.title" /> | ||
</div> | ||
|
||
<div className="text-xs text-dim"> | ||
<T id="upsell.description" /> | ||
</div> | ||
</div> | ||
|
||
<LinkButton color="gray" size={1} href={routes.organizationSettings.plans()} className="w-full"> | ||
<T id="upsell.cta" /> | ||
</LinkButton> | ||
</div> | ||
); | ||
} |
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,60 @@ | ||
import clsx from 'clsx'; | ||
import { forwardRef } from 'react'; | ||
|
||
import { Badge, ProgressBar } from '@koyeb/design-system'; | ||
import { useOrganization } from 'src/api/hooks/session'; | ||
import { routes } from 'src/application/routes'; | ||
import { LinkButton } from 'src/components/link'; | ||
import { createTranslate, TranslateEnum } from 'src/intl/translate'; | ||
|
||
const T = createTranslate('modules.trial.summaryPopup'); | ||
|
||
type TrialSummaryPopupProps = React.ComponentProps<'div'> & { | ||
onClose: () => void; | ||
}; | ||
|
||
export const TrialSummaryPopup = forwardRef<HTMLDivElement, TrialSummaryPopupProps>( | ||
function TrialSummaryPopup({ onClose, className, ...props }, ref) { | ||
const organization = useOrganization(); | ||
|
||
return ( | ||
<div ref={ref} {...props} className={clsx('w-56 rounded-md border bg-popover', className)}> | ||
<div className="row justify-between border-b p-3"> | ||
<T id="currentPlan" values={{ plan: <TranslateEnum enum="plans" value={organization.plan} /> }} /> | ||
|
||
<Badge size={1} color="green" className="ms-auto"> | ||
<T id="badge" /> | ||
</Badge> | ||
</div> | ||
|
||
<div className="col gap-3 p-3"> | ||
<div className="row justify-between text-dim"> | ||
<div> | ||
<T id="usage" /> | ||
</div> | ||
<div>$0.00</div> | ||
</div> | ||
|
||
<hr /> | ||
|
||
<div className="row justify-between"> | ||
<div className="font-medium"> | ||
<T id="creditLeft" /> | ||
</div> | ||
<div className="text-green">$10.00</div> | ||
</div> | ||
|
||
<ProgressBar progress={1} label={false} /> | ||
|
||
<div className="text-center text-xs text-dim"> | ||
<T id="timeLeft" values={{ days: 7 }} /> | ||
</div> | ||
|
||
<LinkButton color="gray" href={routes.organizationSettings.billing()} onClick={onClose}> | ||
<T id="cta" /> | ||
</LinkButton> | ||
</div> | ||
</div> | ||
); | ||
}, | ||
); |