Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat(billing): add onboarding page for AWS Marketplace

Thomas90b22881227a
diff --git a/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceAutoRenewalWarning.tsx b/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceAutoRenewalWarning.tsx
new file mode 100644
index 00000000000..e8056bd2bd4
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceAutoRenewalWarning.tsx
@@ -0,0 +1,37 @@
+import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_ } from 'ui'
+import dayjs from 'dayjs'
+import Link from 'next/link'
+
+interface Props {
+ awsContractEndDate: string
+ awsContractSettingsUrl: string
+}
+
+const AwsMarketplaceAutoRenewalWarning = ({
+ awsContractEndDate,
+ awsContractSettingsUrl,
+}: Props) => {
+ return (
+ <div className="mt-5 mb-10">
+ <Alert_Shadcn_ variant="warning">
+ <AlertTitle_Shadcn_ className="text-foreground font-bold text-orange-1000">
+ “Auto Renewal” is turned OFF for your AWS Marketplace subscription
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_ className="flex flex-col gap-3 break-words">
+ <div>
+ As a result, your Supabase organization will be downgraded to the Free Plan on{' '}
+ {dayjs(awsContractEndDate).format('MMMM DD')}. If you have more than 2 projects running,
+ all your projects will be paused. To ensure uninterrupted service, enable “Auto Renewal”
+ in your {''}
+ <Link href={awsContractSettingsUrl} target="_blank" className="underline">
+ AWS Marketplace subscription settings
+ </Link>
+ .
+ </div>
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ </div>
+ )
+}
+
+export default AwsMarketplaceAutoRenewalWarning
diff --git a/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx b/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx
new file mode 100644
index 00000000000..e9c9a2b7a9f
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg.tsx
@@ -0,0 +1,94 @@
+import { useAwsManagedOrganizationCreateMutation } from '../../../../data/organizations/organization-create-mutation'
+import { toast } from 'sonner'
+import { SubmitHandler } from 'react-hook-form'
+import NewAwsMarketplaceOrgForm, {
+ CREATE_AWS_MANAGED_ORG_FORM_ID,
+ NewMarketplaceOrgForm,
+} from './NewAwsMarketplaceOrgForm'
+import {
+ ScaffoldSection,
+ ScaffoldSectionContent,
+ ScaffoldSectionDetail,
+} from '../../../layouts/Scaffold'
+import Link from 'next/link'
+import { Button } from 'ui'
+import { useRouter } from 'next/router'
+import AwsMarketplaceAutoRenewalWarning from './AwsMarketplaceAutoRenewalWarning'
+import { CloudMarketplaceOnboardingInfo } from './cloud-marketplace-query'
+
+interface Props {
+ onboardingInfo?: CloudMarketplaceOnboardingInfo | undefined
+}
+
+const AwsMarketplaceCreateNewOrg = ({ onboardingInfo }: Props) => {
+ const router = useRouter()
+ const {
+ query: { buyer_id: buyerId },
+ } = router
+
+ const { mutate: createOrganization, isLoading: isCreatingOrganization } =
+ useAwsManagedOrganizationCreateMutation({
+ onSuccess: (org) => {
+ //TODO(thomas): send tracking event?
+ router.push(`/org/${org.slug}`)
+ },
+ onError: (res) => {
+ toast.error(res.message, {
+ duration: 7_000,
+ })
+ },
+ })
+
+ const onSubmit: SubmitHandler<NewMarketplaceOrgForm> = async (values) => {
+ createOrganization({ ...values, buyerId: buyerId as string })
+ }
+
+ return (
+ <>
+ {onboardingInfo && !onboardingInfo.aws_contract_auto_renewal && (
+ <AwsMarketplaceAutoRenewalWarning
+ awsContractEndDate={onboardingInfo.aws_contract_end_date}
+ awsContractSettingsUrl={onboardingInfo.aws_contract_settings_url}
+ />
+ )}
+ <ScaffoldSection>
+ <ScaffoldSectionDetail className="text-base">
+ <p>
+ You’ve subscribed to the Supabase {onboardingInfo?.plan_name_selected_on_marketplace}{' '}
+ Plan via the AWS Marketplace. As a final step, you need to create a Supabase
+ organization. That organization will be managed and billed through AWS Marketplace.
+ </p>
+ <p>
+ You can read more on billing through AWS in our {''}
+ {/*TODO(thomas): Update docs link once the new docs exist*/}
+ <Link
+ href="https://supabase.com/docs/guides/platform"
+ target="_blank"
+ className="underline"
+ >
+ Billing Docs.
+ </Link>
+ </p>
+ </ScaffoldSectionDetail>
+ <ScaffoldSectionContent className="lg:ml-10">
+ <div className="border-l px-10 pt-10">
+ <NewAwsMarketplaceOrgForm onSubmit={onSubmit} />
+
+ <div className="flex justify-end mt-10">
+ <Button
+ form={CREATE_AWS_MANAGED_ORG_FORM_ID}
+ htmlType="submit"
+ loading={isCreatingOrganization}
+ size="medium"
+ >
+ Create organization
+ </Button>
+ </div>
+ </div>
+ </ScaffoldSectionContent>
+ </ScaffoldSection>
+ </>
+ )
+}
+
+export default AwsMarketplaceCreateNewOrg
diff --git a/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx b/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx
new file mode 100644
index 00000000000..c00b2b3fa0e
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg.tsx
@@ -0,0 +1,342 @@
+import {
+ Button,
+ Collapsible_Shadcn_,
+ CollapsibleContent_Shadcn_,
+ CollapsibleTrigger_Shadcn_,
+ Form_Shadcn_,
+ FormField_Shadcn_,
+ Skeleton,
+} from 'ui'
+import { RadioGroupCard, RadioGroupCardItem } from '@ui/components/radio-group-card'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { cn } from '@ui/lib/utils'
+import { ActionCard } from '../../../ui/ActionCard'
+import { Boxes, ChevronRight } from 'lucide-react'
+import {
+ ScaffoldSection,
+ ScaffoldSectionContent,
+ ScaffoldSectionDetail,
+} from '../../../layouts/Scaffold'
+import { ButtonTooltip } from '../../../ui/ButtonTooltip'
+import { z } from 'zod'
+import { SubmitHandler, useForm } from 'react-hook-form'
+import { zodResolver } from '@hookform/resolvers/zod'
+import { useMemo, useState } from 'react'
+import { Organization } from '../../../../types'
+import { useProjectsQuery } from '../../../../data/projects/projects-query'
+import { useOrganizationLinkAwsMarketplaceMutation } from '../../../../data/organizations/organization-link-aws-marketplace-mutation'
+import { toast } from 'sonner'
+import AwsMarketplaceOnboardingSuccessModal from './AwsMarketplaceOnboardingSuccessModal'
+import NewAwsMarketplaceOrgModal from './NewAwsMarketplaceOrgModal'
+import { useRouter } from 'next/router'
+import AwsMarketplaceAutoRenewalWarning from './AwsMarketplaceAutoRenewalWarning'
+import { CloudMarketplaceOnboardingInfo } from './cloud-marketplace-query'
+import Link from 'next/link'
+
+interface Props {
+ organizations?: Organization[] | undefined
+ onboardingInfo?: CloudMarketplaceOnboardingInfo | undefined
+ isLoadingOnboardingInfo: boolean
+}
+
+const FormSchema = z.object({
+ orgSlug: z.string(),
+})
+
+export type LinkExistingOrgForm = z.infer<typeof FormSchema>
+
+const AwsMarketplaceLinkExistingOrg = ({
+ organizations,
+ onboardingInfo,
+ isLoadingOnboardingInfo,
+}: Props) => {
+ const router = useRouter()
+ const {
+ query: { buyer_id: buyerId },
+ } = router
+
+ const form = useForm<LinkExistingOrgForm>({
+ resolver: zodResolver(FormSchema),
+ defaultValues: {
+ orgSlug: undefined,
+ },
+ mode: 'onBlur',
+ reValidateMode: 'onChange',
+ })
+
+ const isDirty = !!Object.keys(form.formState.dirtyFields).length
+
+ // Sort organizations by name ascending
+ const sortedOrganizations = useMemo(() => {
+ return organizations?.slice().sort((a, b) => a.name.localeCompare(b.name))
+ }, [organizations])
+
+ const { orgsLinkable, orgsNotLinkable } = useMemo(() => {
+ const orgQualifiesForLinking = (org: Organization) => {
+ const validationResult = onboardingInfo?.organization_linking_eligibility.find(
+ (result) => result.slug === org.slug
+ )
+
+ return validationResult?.is_eligible ?? false
+ }
+
+ const linkable: Organization[] = []
+ const notLinkable: Organization[] = []
+ sortedOrganizations?.forEach((org) => {
+ if (orgQualifiesForLinking(org)) {
+ linkable.push(org)
+ } else {
+ notLinkable.push(org)
+ }
+ })
+ return { orgsLinkable: linkable, orgsNotLinkable: notLinkable }
+ }, [sortedOrganizations, onboardingInfo?.organization_linking_eligibility])
+
+ const { data: projects = [] } = useProjectsQuery()
+
+ const [isNotLinkableOrgListOpen, setIsNotLinkableOrgListOpen] = useState(false)
+ const [orgLinkedSuccessfully, setOrgLinkedSuccessfully] = useState(false)
+ const [showOrgCreationDialog, setShowOrgCreationDialog] = useState(false)
+ const [orgToRedirectTo, setOrgToRedirectTo] = useState('')
+
+ const { mutate: linkOrganization, isLoading: isLinkingOrganization } =
+ useOrganizationLinkAwsMarketplaceMutation({
+ onSuccess: (_) => {
+ //TODO(thomas): send tracking event?
+ setOrgLinkedSuccessfully(true)
+ setOrgToRedirectTo(form.getValues('orgSlug'))
+ },
+ onError: (res) => {
+ toast.error(res.message, {
+ duration: 7_000,
+ })
+ },
+ })
+
+ const onSubmit: SubmitHandler<LinkExistingOrgForm> = async (values) => {
+ linkOrganization({ slug: values.orgSlug, buyerId: buyerId as string })
+ }
+
+ return (
+ <>
+ {onboardingInfo && !onboardingInfo.aws_contract_auto_renewal && (
+ <AwsMarketplaceAutoRenewalWarning
+ awsContractEndDate={onboardingInfo.aws_contract_end_date}
+ awsContractSettingsUrl={onboardingInfo.aws_contract_settings_url}
+ />
+ )}
+ <ScaffoldSection>
+ <ScaffoldSectionDetail className="text-base">
+ <>
+ <p>
+ You’ve subscribed to the Supabase {onboardingInfo?.plan_name_selected_on_marketplace}{' '}
+ Plan via the AWS Marketplace. As a final step, you need to link a Supabase
+ organization to that subscription. Select the organization you want to be managed and
+ billed through AWS.
+ </p>
+
+ <p>
+ You can read more on billing through AWS in our {''}
+ {/*TODO(thomas): Update docs link once the new docs exist*/}
+ <Link
+ href="https://supabase.com/docs/guides/platform"
+ target="_blank"
+ className="underline"
+ >
+ Billing Docs.
+ </Link>
+ </p>
+
+ <p className="mt-10">
+ <span className="font-bold text-foreground-light">Want to start fresh?</span> Create a
+ new organization and it will be linked automatically.
+ </p>
+ <Button
+ size="tiny"
+ htmlType="submit"
+ type="primary"
+ onClick={async (e) => {
+ e.preventDefault()
+ setShowOrgCreationDialog(true)
+ }}
+ >
+ Create organization
+ </Button>
+ </>
+ </ScaffoldSectionDetail>
+
+ <ScaffoldSectionContent className="lg:ml-10">
+ <Form_Shadcn_ {...form}>
+ <form className="flex flex-col">
+ <FormField_Shadcn_
+ name="orgSlug"
+ control={form.control}
+ render={({ field }) => (
+ <RadioGroupCard
+ {...field}
+ defaultValue={field.value}
+ onValueChange={(value: string) => {
+ form.setValue('orgSlug', value, {
+ shouldDirty: true,
+ shouldValidate: false,
+ })
+ }}
+ >
+ <FormItemLayout id={field.name}>
+ <div className={'grid gap-4 grid-cols-1'}>
+ {isLoadingOnboardingInfo ? (
+ Array(3)
+ .fill(0)
+ .map((_, i) => (
+ <Skeleton key={i} className="w-full h-[110px] rounded-md" />
+ ))
+ ) : (
+ <>
+ <p className="font-bold text-foreground-light">
+ Organizations that can be linked
+ </p>
+ {orgsLinkable.length === 0 ? (
+ <p className="text-sm text-foreground-light">
+ None of your organizations can be linked to your AWS Marketplace
+ subscription at the moment.
+ </p>
+ ) : (
+ <>
+ {orgsLinkable.map((org) => {
+ const numProjects = projects.filter(
+ (p) => p.organization_slug === org.slug
+ ).length
+ return (
+ <RadioGroupCardItem
+ id={org.slug}
+ key={org.slug}
+ showIndicator={false}
+ value={org.slug}
+ className={cn(
+ 'relative text-sm text-left flex flex-col gap-0 p-0 [&_label]:w-full group] w-full'
+ )}
+ label={
+ <ActionCard
+ className="[&>div]:items-center border-0 bg-surface-0 group-data-[state=checked]:opacity-100"
+ key={org.id}
+ icon={
+ <Boxes
+ size={18}
+ strokeWidth={1}
+ className="text-foreground"
+ />
+ }
+ title={org.name}
+ description={`${org.plan.name} Plan • ${numProjects > 0 ? `${numProjects} Project${numProjects > 1 ? 's' : ''}` : '0 Projects'}`}
+ />
+ }
+ />
+ )
+ })}
+ </>
+ )}
+ </>
+ )}
+ </div>
+ </FormItemLayout>
+ </RadioGroupCard>
+ )}
+ />
+ </form>
+ </Form_Shadcn_>
+
+ {orgsNotLinkable.length > 0 && !isLoadingOnboardingInfo && (
+ <Collapsible_Shadcn_
+ className="-space-y-px"
+ open={isNotLinkableOrgListOpen || orgsLinkable.length === 0}
+ onOpenChange={() => setIsNotLinkableOrgListOpen((prev) => !prev)}
+ >
+ <CollapsibleTrigger_Shadcn_ className="py-2 w-full flex items-center group justify-between">
+ <p className="text-xs font-bold text-foreground-light">
+ Organizations that can't be linked
+ </p>
+ <ChevronRight
+ size={16}
+ className="text-foreground-lighter transition-all group-data-[state=open]:rotate-90"
+ strokeWidth={1}
+ />
+ </CollapsibleTrigger_Shadcn_>
+ <CollapsibleContent_Shadcn_
+ className={cn(
+ 'flex flex-col gap-4 transition-all',
+ 'data-[state=closed]:animate-collapsible-up data-[state=open]:animate-collapsible-down'
+ )}
+ >
+ <p className="text-foreground-light text-xs">
+ The following organizations can’t be linked to your AWS Marketplace subscription
+ at the moment. This may be due to missing permissions, outstanding invoices, or an
+ existing marketplace link. If you'd like to link one of these organizations,
+ please review the organization settings. You need to be Owner or Administrator of
+ the organization to link it.
+ </p>
+ <div className="text-sm text-left flex flex-col gap-4 p-0 [&_label]:w-full group] w-full opacity-60">
+ {orgsNotLinkable.map((org) => {
+ const numProjects = projects.filter(
+ (p) => p.organization_slug === org.slug
+ ).length
+ return (
+ <ActionCard
+ className="[&>div]:items-center cursor-not-allowed"
+ key={org.id}
+ icon={<Boxes size={18} strokeWidth={1} className="text-foreground" />}
+ title={org.name}
+ description={`${org.plan.name} Plan • ${numProjects > 0 ? `${numProjects} Project${numProjects > 1 ? 's' : ''}` : '0 Projects'}`}
+ />
+ )
+ })}
+ </div>
+ </CollapsibleContent_Shadcn_>
+ </Collapsible_Shadcn_>
+ )}
+
+ <div className={cn('flex gap-3 justify-end')}>
+ <ButtonTooltip
+ size="medium"
+ htmlType="submit"
+ type="primary"
+ onClick={async () => {
+ await onSubmit(form.getValues())
+ }}
+ loading={isLinkingOrganization}
+ disabled={!isDirty || isLinkingOrganization || isLoadingOnboardingInfo}
+ tooltip={{
+ content: {
+ side: 'top',
+ text: !isDirty ? 'No organization selected' : undefined,
+ },
+ }}
+ >
+ Link organization
+ </ButtonTooltip>
+ </div>
+ </ScaffoldSectionContent>
+ </ScaffoldSection>
+
+ <AwsMarketplaceOnboardingSuccessModal
+ visible={orgLinkedSuccessfully}
+ onClose={() => {
+ setOrgLinkedSuccessfully(false)
+ router.push(`/org/${orgToRedirectTo}`)
+ }}
+ />
+
+ <NewAwsMarketplaceOrgModal
+ visible={showOrgCreationDialog}
+ onClose={() => setShowOrgCreationDialog(false)}
+ buyerId={buyerId as string}
+ onSuccess={(newlyCreatedOrgSlug) => {
+ setShowOrgCreationDialog(false)
+ setOrgToRedirectTo(newlyCreatedOrgSlug)
+ setOrgLinkedSuccessfully(true)
+ }}
+ />
+ </>
+ )
+}
+
+export default AwsMarketplaceLinkExistingOrg
diff --git a/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceOnboardingPlaceholder.tsx b/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceOnboardingPlaceholder.tsx
new file mode 100644
index 00000000000..07f9c13abe4
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceOnboardingPlaceholder.tsx
@@ -0,0 +1,29 @@
+import {
+ ScaffoldSection,
+ ScaffoldSectionContent,
+ ScaffoldSectionDetail,
+} from '../../../layouts/Scaffold'
+import { Skeleton } from '@ui/components/shadcn/ui/skeleton'
+
+const AwsMarketplaceOnboardingPlaceholder = () => {
+ return (
+ <ScaffoldSection>
+ <ScaffoldSectionDetail>
+ {Array(1)
+ .fill(0)
+ .map((_, i) => (
+ <Skeleton key={i} className="w-full h-[110px] rounded-md" />
+ ))}
+ </ScaffoldSectionDetail>
+ <ScaffoldSectionContent className="lg:ml-10">
+ {Array(3)
+ .fill(0)
+ .map((_, i) => (
+ <Skeleton key={i} className="w-full h-[110px] rounded-md" />
+ ))}
+ </ScaffoldSectionContent>
+ </ScaffoldSection>
+ )
+}
+
+export default AwsMarketplaceOnboardingPlaceholder
diff --git a/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceOnboardingSuccessModal.tsx b/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceOnboardingSuccessModal.tsx
new file mode 100644
index 00000000000..1402382228b
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/CloudMarketplace/AwsMarketplaceOnboardingSuccessModal.tsx
@@ -0,0 +1,42 @@
+import { Dialog, DialogContent, DialogFooter, DialogSection } from '@ui/components/shadcn/ui/dialog'
+import { Button } from 'ui'
+
+interface Props {
+ visible: boolean
+ onClose: () => void
+}
+
+const AwsMarketplaceOnboardingSuccessModal = ({ visible, onClose }: Props) => {
+ return (
+ <Dialog
+ open={visible}
+ onOpenChange={(open) => {
+ if (!open) onClose()
+ }}
+ >
+ <DialogContent
+ onOpenAutoFocus={(event) => event.preventDefault()}
+ size="xlarge"
+ hideClose={true}
+ onEscapeKeyDown={(e) => e.preventDefault()}
+ onPointerDownOutside={(e) => e.preventDefault()}
+ >
+ <DialogSection>
+ <div className="p-4 flex flex-col">
+ <h1 className="text-xl mb-4">AWS Marketplace Setup completed</h1>
+ <p className="text-foreground-light text-sm">
+ The organization is now managed and billed through AWS Marketplace.
+ </p>
+ </div>
+ </DialogSection>
+ <DialogFooter>
+ <Button size="medium" onClick={onClose}>
+ Go to Organization
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+}
+
+export default AwsMarketplaceOnboardingSuccessModal
diff --git a/apps/studio/components/interfaces/Organization/CloudMarketplace/NewAwsMarketplaceOrgForm.tsx b/apps/studio/components/interfaces/Organization/CloudMarketplace/NewAwsMarketplaceOrgForm.tsx
new file mode 100644
index 00000000000..cc27b6389c3
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/CloudMarketplace/NewAwsMarketplaceOrgForm.tsx
@@ -0,0 +1,159 @@
+import { z } from 'zod'
+import {
+ Form_Shadcn_,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ Input_Shadcn_,
+ Label_Shadcn_,
+ Select_Shadcn_,
+ SelectContent_Shadcn_,
+ SelectItem_Shadcn_,
+ SelectTrigger_Shadcn_,
+ SelectValue_Shadcn_,
+} from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
+import { useForm } from 'react-hook-form'
+import { zodResolver } from '@hookform/resolvers/zod'
+
+const ORG_KIND_TYPES = {
+ PERSONAL: 'Personal',
+ EDUCATIONAL: 'Educational',
+ STARTUP: 'Startup',
+ AGENCY: 'Agency',
+ COMPANY: 'Company',
+ UNDISCLOSED: 'N/A',
+}
+
+const ORG_KIND_DEFAULT = 'PERSONAL'
+
+const ORG_SIZE_TYPES = {
+ '1': '1 - 10',
+ '10': '10 - 49',
+ '50': '50 - 99',
+ '100': '100 - 299',
+ '300': 'More than 300',
+}
+
+interface Props {
+ onSubmit: (values: NewMarketplaceOrgForm) => void
+}
+
+export const CREATE_AWS_MANAGED_ORG_FORM_ID = 'create-aws-managed-org-form'
+
+const FormSchema = z.object({
+ name: z.string().trim().min(1, 'Please provide an organization name'),
+ kind: z.string(),
+ size: z.string().optional(),
+})
+
+export type NewMarketplaceOrgForm = z.infer<typeof FormSchema>
+
+const NewAwsMarketplaceOrgForm = ({ onSubmit }: Props) => {
+ const form = useForm<NewMarketplaceOrgForm>({
+ resolver: zodResolver(FormSchema),
+ defaultValues: {
+ name: '',
+ kind: ORG_KIND_DEFAULT,
+ },
+ })
+
+ const kind = form.watch('kind')
+
+ return (
+ <Form_Shadcn_ {...form}>
+ <form id={CREATE_AWS_MANAGED_ORG_FORM_ID} onSubmit={form.handleSubmit(onSubmit)}>
+ <div className="flex flex-col gap-4">
+ <FormField_Shadcn_
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItemLayout label="Name" layout="horizontal">
+ <FormControl_Shadcn_>
+ <>
+ <Input_Shadcn_ {...field} placeholder="Organization name" />
+ <div className="mt-1">
+ <Label_Shadcn_
+ htmlFor="name"
+ className="text-foreground-lighter leading-normal text-sm"
+ >
+ What's the name of your company or team?
+ </Label_Shadcn_>
+ </div>
+ </>
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ <FormField_Shadcn_
+ control={form.control}
+ name="kind"
+ render={({ field }) => (
+ <FormItemLayout label="Type" layout="horizontal">
+ <FormControl_Shadcn_>
+ <>
+ <Select_Shadcn_ value={field.value} onValueChange={field.onChange}>
+ <SelectTrigger_Shadcn_>
+ <SelectValue_Shadcn_ />
+ </SelectTrigger_Shadcn_>
+ <SelectContent_Shadcn_>
+ {Object.entries(ORG_KIND_TYPES).map(([k, v]) => (
+ <SelectItem_Shadcn_ key={k} value={k}>
+ {v}
+ </SelectItem_Shadcn_>
+ ))}
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ <div className="mt-1">
+ <Label_Shadcn_
+ htmlFor="kind"
+ className="text-foreground-lighter leading-normal text-sm"
+ >
+ What would best describe your organization?
+ </Label_Shadcn_>
+ </div>
+ </>
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ {kind == 'COMPANY' && (
+ <FormField_Shadcn_
+ control={form.control}
+ name="size"
+ render={({ field }) => (
+ <FormItemLayout label="Company size" layout="horizontal">
+ <FormControl_Shadcn_>
+ <>
+ <Select_Shadcn_ value={field.value} onValueChange={field.onChange}>
+ <SelectTrigger_Shadcn_>
+ <SelectValue_Shadcn_ placeholder="How many people are in your company?" />
+ </SelectTrigger_Shadcn_>
+ <SelectContent_Shadcn_>
+ {Object.entries(ORG_SIZE_TYPES).map(([k, v]) => (
+ <SelectItem_Shadcn_ key={k} value={k}>
+ {v}
+ </SelectItem_Shadcn_>
+ ))}
+ </SelectContent_Shadcn_>
+ </Select_Shadcn_>
+ <div className="mt-1">
+ <Label_Shadcn_
+ htmlFor="size"
+ className="text-foreground-lighter leading-normal text-sm"
+ >
+ How many people are in your company?
+ </Label_Shadcn_>
+ </div>
+ </>
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ )}
+ </div>
+ </form>
+ </Form_Shadcn_>
+ )
+}
+
+export default NewAwsMarketplaceOrgForm
diff --git a/apps/studio/components/interfaces/Organization/CloudMarketplace/NewAwsMarketplaceOrgModal.tsx b/apps/studio/components/interfaces/Organization/CloudMarketplace/NewAwsMarketplaceOrgModal.tsx
new file mode 100644
index 00000000000..13a31c4be60
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/CloudMarketplace/NewAwsMarketplaceOrgModal.tsx
@@ -0,0 +1,84 @@
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogFooter,
+ DialogHeader,
+ DialogSection,
+ DialogSectionSeparator,
+ DialogTitle,
+} from '@ui/components/shadcn/ui/dialog'
+import { Button } from 'ui'
+import NewAwsMarketplaceOrgForm, {
+ CREATE_AWS_MANAGED_ORG_FORM_ID,
+ NewMarketplaceOrgForm,
+} from './NewAwsMarketplaceOrgForm'
+import { useAwsManagedOrganizationCreateMutation } from '../../../../data/organizations/organization-create-mutation'
+import { toast } from 'sonner'
+import { SubmitHandler } from 'react-hook-form'
+
+interface Props {
+ buyerId: string
+ visible: boolean
+ onSuccess: (newlyCreatedOrgSlug: string) => void
+ onClose: () => void
+}
+
+const NewAwsMarketplaceOrgModal = ({ buyerId, visible, onSuccess, onClose }: Props) => {
+ const { mutate: createOrganization, isLoading: isCreatingOrganization } =
+ useAwsManagedOrganizationCreateMutation({
+ onSuccess: (org) => {
+ //TODO(thomas): send tracking event?
+ onSuccess(org.slug)
+ },
+ onError: (res) => {
+ toast.error(res.message, {
+ duration: 7_000,
+ })
+ },
+ })
+
+ const onSubmit: SubmitHandler<NewMarketplaceOrgForm> = async (values) => {
+ createOrganization({ ...values, buyerId })
+ }
+
+ return (
+ <Dialog
+ open={visible}
+ onOpenChange={(open) => {
+ if (!open) onClose()
+ }}
+ >
+ <DialogContent
+ onOpenAutoFocus={(event) => event.preventDefault()}
+ size="xlarge"
+ onEscapeKeyDown={(e) => (isCreatingOrganization ? e.preventDefault() : onClose())}
+ onPointerDownOutside={(e) => (isCreatingOrganization ? e.preventDefault() : onClose())}
+ className="p-2"
+ >
+ <DialogHeader>
+ <DialogTitle>Create a new organization</DialogTitle>
+ <DialogDescription>
+ A new organization will be created and linked to your AWS Marketplace subscription
+ </DialogDescription>
+ </DialogHeader>
+ <DialogSectionSeparator />
+ <DialogSection>
+ <NewAwsMarketplaceOrgForm onSubmit={onSubmit}></NewAwsMarketplaceOrgForm>
+ </DialogSection>
+ <DialogFooter>
+ <Button
+ form={CREATE_AWS_MANAGED_ORG_FORM_ID}
+ htmlType="submit"
+ loading={isCreatingOrganization}
+ size="medium"
+ >
+ Create and link organization
+ </Button>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
+ )
+}
+
+export default NewAwsMarketplaceOrgModal
diff --git a/apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts b/apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts
new file mode 100644
index 00000000000..0b9d924aa4c
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query.ts
@@ -0,0 +1,50 @@
+import { get, handleError } from '../../../../data/fetchers'
+import type { ResponseError } from '../../../../types'
+import { useQuery, UseQueryOptions } from '@tanstack/react-query'
+import { useProfile } from '../../../../lib/profile'
+import { cloudMarketplaceKeys } from './keys'
+
+export type CloudMarketplaceOnboardingInfoVariables = {
+ buyerId: string
+}
+
+export async function getCloudMarketplaceOnboardingInfo(
+ { buyerId }: CloudMarketplaceOnboardingInfoVariables,
+ signal?: AbortSignal
+) {
+ const { data, error } = await get(
+ '/platform/cloud-marketplace/buyers/{buyer_id}/onboarding-info',
+ {
+ params: { path: { buyer_id: buyerId } },
+ signal,
+ }
+ )
+
+ if (error) handleError(error)
+
+ return data
+}
+
+export type CloudMarketplaceOnboardingInfo = Awaited<
+ ReturnType<typeof getCloudMarketplaceOnboardingInfo>
+>
+export type CloudMarketplaceOnboardingInfoError = ResponseError
+
+export const useCloudMarketplaceOnboardingInfoQuery = <TData = CloudMarketplaceOnboardingInfo>(
+ { buyerId }: CloudMarketplaceOnboardingInfoVariables,
+ {
+ enabled = true,
+ ...options
+ }: UseQueryOptions<
+ CloudMarketplaceOnboardingInfo,
+ CloudMarketplaceOnboardingInfoError,
+ TData
+ > = {}
+) => {
+ const { profile } = useProfile()
+ return useQuery<CloudMarketplaceOnboardingInfo, CloudMarketplaceOnboardingInfoError, TData>(
+ cloudMarketplaceKeys.onboardingInfo(buyerId),
+ ({ signal }) => getCloudMarketplaceOnboardingInfo({ buyerId }, signal),
+ { enabled: enabled && profile !== undefined, ...options, staleTime: 30 * 60 * 1000 }
+ )
+}
diff --git a/apps/studio/components/interfaces/Organization/CloudMarketplace/keys.ts b/apps/studio/components/interfaces/Organization/CloudMarketplace/keys.ts
new file mode 100644
index 00000000000..790b1e13329
--- /dev/null
+++ b/apps/studio/components/interfaces/Organization/CloudMarketplace/keys.ts
@@ -0,0 +1,3 @@
+export const cloudMarketplaceKeys = {
+ onboardingInfo: (buyerId: string) => ['cloud-marketplace', 'onboarding-info', buyerId],
+}
diff --git a/apps/studio/components/layouts/LinkAwsMarketplaceLayout.tsx b/apps/studio/components/layouts/LinkAwsMarketplaceLayout.tsx
new file mode 100644
index 00000000000..8baff253240
--- /dev/null
+++ b/apps/studio/components/layouts/LinkAwsMarketplaceLayout.tsx
@@ -0,0 +1,51 @@
+import { BASE_PATH } from 'lib/constants'
+import { useTheme } from 'next-themes'
+import Head from 'next/head'
+import Image from 'next/legacy/image'
+import type { PropsWithChildren } from 'react'
+import { Separator } from 'ui'
+import { withAuth } from '../../hooks/misc/withAuth'
+
+export interface LinkAwsMarketplaceLayoutProps {}
+
+const LinkAwsMarketplaceLayout = ({
+ children,
+}: PropsWithChildren<LinkAwsMarketplaceLayoutProps>) => {
+ const { resolvedTheme } = useTheme()
+ return (
+ <>
+ <Head>
+ <title>AWS Marketplace Setup | Supabase</title>
+ </Head>
+ <main className="flex flex-col flex-grow w-full h-full overflow-y-auto">
+ <div>
+ <div className="mx-auto px-4 sm:px-6">
+ <div className="max-w-xl flex justify-between items-center py-4">
+ <div className="flex justify-start lg:w-0 lg:flex-1">
+ <div>
+ <span className="sr-only">Supabase</span>
+ <Image
+ src={
+ resolvedTheme?.includes('dark')
+ ? `${BASE_PATH}/img/supabase-dark.svg`
+ : `${BASE_PATH}/img/supabase-light.svg`
+ }
+ alt="Supabase Logo"
+ height={20}
+ width={105}
+ />
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ <Separator />
+ <div className="flex flex-col justify-center flex-grow mx-auto w-[90vw] space-y-4">
+ {children}
+ </div>
+ </main>
+ </>
+ )
+}
+
+export default withAuth(LinkAwsMarketplaceLayout)
diff --git a/apps/studio/data/organizations/organization-create-mutation.ts b/apps/studio/data/organizations/organization-create-mutation.ts
index 5baffba7b98..93024acbb3b 100644
--- a/apps/studio/data/organizations/organization-create-mutation.ts
+++ b/apps/studio/data/organizations/organization-create-mutation.ts
@@ -93,3 +93,82 @@ export const useOrganizationCreateMutation = ({
}
)
}
+
+export type AwsManagedOrganizationCreateVariables = {
+ name: string
+ kind?: string
+ size?: string
+ buyerId: string
+}
+
+export async function createAwsManagedOrganization({
+ name,
+ kind,
+ size,
+ buyerId,
+}: AwsManagedOrganizationCreateVariables) {
+ const { data, error } = await post('/platform/organizations/cloud-marketplace', {
+ body: {
+ name,
+ kind,
+ size,
+ buyer_id: buyerId,
+ },
+ })
+
+ if (error) handleError(error)
+ return data
+}
+
+type AwsManagedOrganizationCreateData = Awaited<ReturnType<typeof createAwsManagedOrganization>>
+
+export const useAwsManagedOrganizationCreateMutation = ({
+ onSuccess,
+ onError,
+ ...options
+}: Omit<
+ UseMutationOptions<
+ AwsManagedOrganizationCreateData,
+ ResponseError,
+ AwsManagedOrganizationCreateVariables
+ >,
+ 'mutationFn'
+> = {}) => {
+ const queryClient = useQueryClient()
+
+ return useMutation<
+ AwsManagedOrganizationCreateData,
+ ResponseError,
+ AwsManagedOrganizationCreateVariables
+ >((vars) => createAwsManagedOrganization(vars), {
+ async onSuccess(data, variables, context) {
+ if (data) {
+ // [Joshen] We're manually updating the query client here as the org's subscription is
+ // created async, and the invalidation will happen too quick where the GET organizations
+ // endpoint will error out with a 500 since the subscription isn't created yet.
+ queryClient.setQueriesData(
+ {
+ queryKey: organizationKeys.list(),
+ exact: true,
+ },
+ (prev: any) => {
+ if (!prev) return prev
+ return [...prev, castOrganizationResponseToOrganization(data)]
+ }
+ )
+
+ await queryClient.invalidateQueries(permissionKeys.list())
+ }
+
+ await onSuccess?.(data, variables, context)
+ },
+ async onError(data, variables, context) {
+ if (onError === undefined) {
+ toast.error(`Failed to create organization: ${data.message}`)
+ } else {
+ onError(data, variables, context)
+ }
+ },
+ ...options,
+ })
+}
diff --git a/apps/studio/data/organizations/organization-link-aws-marketplace-mutation.ts b/apps/studio/data/organizations/organization-link-aws-marketplace-mutation.ts
new file mode 100644
index 00000000000..a8ac033a764
--- /dev/null
+++ b/apps/studio/data/organizations/organization-link-aws-marketplace-mutation.ts
@@ -0,0 +1,51 @@
+import { useMutation, UseMutationOptions } from '@tanstack/react-query'
+import { toast } from 'sonner'
+
+import { handleError, put } from '../fetchers'
+import type { ResponseError } from '../../types'
+
+export type OrganizationLinkAwsMarketplaceVariables = {
+ buyerId: string
+ slug: string
+}
+
+export async function linkOrganization({ buyerId, slug }: OrganizationLinkAwsMarketplaceVariables) {
+ const { data, error } = await put(`/platform/organizations/{slug}/cloud-marketplace/link`, {
+ params: { path: { slug } },
+ body: {
+ buyer_id: buyerId,
+ },
+ })
+
+ if (error) handleError(error)
+
+ return data
+}
+
+type LinkOrganizationData = Awaited<ReturnType<typeof linkOrganization>>
+
+export const useOrganizationLinkAwsMarketplaceMutation = ({
+ onSuccess,
+ onError,
+ ...options
+}: Omit<
+ UseMutationOptions<LinkOrganizationData, ResponseError, OrganizationLinkAwsMarketplaceVariables>,
+ 'mutationFn'
+> = {}) => {
+ return useMutation<LinkOrganizationData, ResponseError, OrganizationLinkAwsMarketplaceVariables>(
+ (vars) => linkOrganization(vars),
+ {
+ async onSuccess(data, variables, context) {
+ await onSuccess?.(data, variables, context)
+ },
+ async onError(data, variables, context) {
+ if (onError === undefined) {
+ toast.error(`Failed to link organization to AWS Marketplace: ${data.message}`)
+ } else {
+ onError(data, variables, context)
+ }
+ },
+ ...options,
+ }
+ )
+}
diff --git a/apps/studio/pages/aws-marketplace-onboarding.tsx b/apps/studio/pages/aws-marketplace-onboarding.tsx
new file mode 100644
index 00000000000..0faea387ebf
--- /dev/null
+++ b/apps/studio/pages/aws-marketplace-onboarding.tsx
@@ -0,0 +1,52 @@
+import { NextPageWithLayout } from '../types'
+import {
+ ScaffoldContainer,
+ ScaffoldDivider,
+ ScaffoldHeader,
+ ScaffoldTitle,
+} from '../components/layouts/Scaffold'
+import LinkAwsMarketplaceLayout from '../components/layouts/LinkAwsMarketplaceLayout'
+import { useOrganizationsQuery } from '../data/organizations/organizations-query'
+import AwsMarketplaceLinkExistingOrg from '../components/interfaces/Organization/CloudMarketplace/AwsMarketplaceLinkExistingOrg'
+import AwsMarketplaceCreateNewOrg from '../components/interfaces/Organization/CloudMarketplace/AwsMarketplaceCreateNewOrg'
+import { useCloudMarketplaceOnboardingInfoQuery } from '../components/interfaces/Organization/CloudMarketplace/cloud-marketplace-query'
+import { useRouter } from 'next/router'
+import AwsMarketplaceOnboardingPlaceholder from '../components/interfaces/Organization/CloudMarketplace/AwsMarketplaceOnboardingPlaceholder'
+
+const AwsMarketplaceOnboarding: NextPageWithLayout = () => {
+ const {
+ query: { buyer_id: buyerId },
+ } = useRouter()
+
+ const { data: organizations, isFetched: isOrganizationsFetched } = useOrganizationsQuery()
+ const { data: onboardingInfo, isLoading: isLoadingOnboardingInfo } =
+ useCloudMarketplaceOnboardingInfoQuery({
+ buyerId: buyerId as string,
+ })
+
+ return (
+ <ScaffoldContainer>
+ <ScaffoldHeader>
+ <ScaffoldTitle>AWS Marketplace Setup</ScaffoldTitle>
+ </ScaffoldHeader>
+ <ScaffoldDivider />
+ {!isOrganizationsFetched ? (
+ <AwsMarketplaceOnboardingPlaceholder />
+ ) : organizations?.length ? (
+ <AwsMarketplaceLinkExistingOrg
+ organizations={organizations}
+ onboardingInfo={onboardingInfo}
+ isLoadingOnboardingInfo={isLoadingOnboardingInfo}
+ />
+ ) : (
+ <AwsMarketplaceCreateNewOrg onboardingInfo={onboardingInfo} />
+ )}
+ </ScaffoldContainer>
+ )
+}
+
+AwsMarketplaceOnboarding.getLayout = (page) => (
+ <LinkAwsMarketplaceLayout>{page}</LinkAwsMarketplaceLayout>
+)
+
+export default AwsMarketplaceOnboarding
diff --git a/packages/api-types/types/platform.d.ts b/packages/api-types/types/platform.d.ts
index b84082af171..c5e541ff155 100644
--- a/packages/api-types/types/platform.d.ts
+++ b/packages/api-types/types/platform.d.ts
@@ -227,6 +227,23 @@ export interface paths {
patch?: never
trace?: never
}
+ '/platform/cloud-marketplace/buyers/{buyer_id}/onboarding-info': {
+ parameters: {
+ query?: never
+ header?: never
+ path?: never
+ cookie?: never
+ }
+ /** Get info needed for AWS Marketplace onboarding */
+ get: operations['ClazarController_getCloudMarketplaceOnboardingInfo']
+ put?: never
+ post?: never
+ delete?: never
+ options?: never
+ head?: never
+ patch?: never
+ trace?: never
+ }
'/platform/database/{ref}/backups': {
parameters: {
query?: never
@@ -1640,23 +1657,6 @@ export interface paths {
patch?: never
trace?: never
}
- '/platform/organizations/cloud-marketplace/check-eligibility': {
- parameters: {
- query?: never
- header?: never
- path?: never
- cookie?: never
- }
- /** Check whether given organizations are eligible for AWS billing */
- get: operations['OrganizationsController_checkCloudMarketplaceEligibility']
- put?: never
- post?: never
- delete?: never
- options?: never
- head?: never
- patch?: never
- trace?: never
- }
'/platform/organizations/confirm-subscription': {
parameters: {
query?: never
@@ -4438,11 +4438,6 @@ export interface components {
ChangeMFAEnforcementStateRequest: {
enforced: boolean
}
- CheckCloudMarketplaceEligibilityResponse: {
- is_eligible: boolean
- reasons: string[]
- slug: string
- }[]
CloneBackupsResponse: {
backups: {
id: number
@@ -4471,6 +4466,22 @@ export interface components {
/** @default 0 */
recoveryTimeTarget?: number
}
+ CloudMarketplaceOnboardingInfoResponse: {
+ aws_contract_auto_renewal: boolean
+ aws_contract_end_date: string
+ aws_contract_settings_url: string
+ aws_contract_start_date: string
+ organization_linking_eligibility: {
+ is_eligible: boolean
+ reasons: (
+ | 'ALREADY_BILLED_BY_PARTNER'
+ | 'ALREADY_BILLED_BY_PARTNER_AWS'
+ | 'OVERDUE_INVOICES'
+ )[]
+ slug: string
+ }[]
+ plan_name_selected_on_marketplace: string
+ }
ConfirmCreateSubscriptionChangeBody: {
kind?: string
name: string
@@ -9772,6 +9783,34 @@ export interface operations {
}
}
}
+ ClazarController_getCloudMarketplaceOnboardingInfo: {
+ parameters: {
+ query?: never
+ header?: never
+ path: {
+ buyer_id: string
+ }
+ cookie?: never
+ }
+ requestBody?: never
+ responses: {
+ 200: {
+ headers: {
+ [name: string]: unknown
+ }
+ content: {
+ 'application/json': components['schemas']['CloudMarketplaceOnboardingInfoResponse']
+ }
+ }
+ /** @description Failed to get info for AWS Marketplace onboarding */
+ 500: {
+ headers: {
+ [name: string]: unknown
+ }
+ content?: never
+ }
+ }
+ }
BackupsController_getBackups: {
parameters: {
query?: never
@@ -13256,7 +13295,7 @@ export interface operations {
[name: string]: unknown
}
content: {
- 'application/json': components['schemas']['CreateOrganizationResponse']
+ 'application/json': components['schemas']['OrganizationResponse']
}
}
/** @description Failed to create organization billed by AWS Marketplace */
@@ -13268,32 +13307,6 @@ export interface operations {
}
}
}
- OrganizationsController_checkCloudMarketplaceEligibility: {
- parameters: {
- query?: never
- header?: never
- path?: never
- cookie?: never
- }
- requestBody?: never
- responses: {
- 200: {
- headers: {
- [name: string]: unknown
- }
- content: {
- 'application/json': components['schemas']['CheckCloudMarketplaceEligibilityResponse']
- }
- }
- /** @description Failed to check whether organizations are eligible for AWS billing */
- 500: {
- headers: {
- [name: string]: unknown
- }
- content?: never
- }
- }
- }
OrganizationsController_confirmSubscription: {
parameters: {
query?: never