AwsMarketplaceCreateNewOrg.tsx103 lines · main
| 1 | import Link from 'next/link' |
| 2 | import { useRouter } from 'next/router' |
| 3 | import { SubmitHandler } from 'react-hook-form' |
| 4 | import { toast } from 'sonner' |
| 5 | import { Button } from 'ui' |
| 6 | |
| 7 | import AwsMarketplaceAutoRenewalWarning from './AwsMarketplaceAutoRenewalWarning' |
| 8 | import AwsMarketplaceOnboardingPlaceholder from './AwsMarketplaceOnboardingPlaceholder' |
| 9 | import { useCloudMarketplaceOnboardingInfoQuery } from './cloud-marketplace-query' |
| 10 | import NewAwsMarketplaceOrgForm, { |
| 11 | CREATE_AWS_MANAGED_ORG_FORM_ID, |
| 12 | NewMarketplaceOrgForm, |
| 13 | } from './NewAwsMarketplaceOrgForm' |
| 14 | import { |
| 15 | ScaffoldSection, |
| 16 | ScaffoldSectionContent, |
| 17 | ScaffoldSectionDetail, |
| 18 | } from '@/components/layouts/Scaffold' |
| 19 | import { useAwsManagedOrganizationCreateMutation } from '@/data/organizations/organization-create-mutation' |
| 20 | import { DOCS_URL } from '@/lib/constants' |
| 21 | |
| 22 | const AwsMarketplaceCreateNewOrg = () => { |
| 23 | const router = useRouter() |
| 24 | const { |
| 25 | query: { buyer_id: buyerId }, |
| 26 | } = router |
| 27 | |
| 28 | const { data: onboardingInfo, isPending: isLoadingOnboardingInfo } = |
| 29 | useCloudMarketplaceOnboardingInfoQuery({ |
| 30 | buyerId: buyerId as string, |
| 31 | }) |
| 32 | |
| 33 | const { mutate: createOrganization, isPending: isCreatingOrganization } = |
| 34 | useAwsManagedOrganizationCreateMutation({ |
| 35 | onSuccess: (org) => { |
| 36 | //TODO(thomas): send tracking event? |
| 37 | router.push(`/org/${org.slug}`) |
| 38 | }, |
| 39 | onError: (res) => { |
| 40 | toast.error(res.message, { |
| 41 | duration: 7_000, |
| 42 | }) |
| 43 | }, |
| 44 | }) |
| 45 | |
| 46 | const onSubmit: SubmitHandler<NewMarketplaceOrgForm> = async (values) => { |
| 47 | createOrganization({ ...values, buyerId: buyerId as string }) |
| 48 | } |
| 49 | |
| 50 | return ( |
| 51 | <> |
| 52 | {onboardingInfo && |
| 53 | !onboardingInfo.aws_contract_auto_renewal && |
| 54 | !onboardingInfo.aws_contract_is_private_offer && ( |
| 55 | <AwsMarketplaceAutoRenewalWarning |
| 56 | awsContractEndDate={onboardingInfo.aws_contract_end_date} |
| 57 | awsContractSettingsUrl={onboardingInfo.aws_contract_settings_url} |
| 58 | /> |
| 59 | )} |
| 60 | {isLoadingOnboardingInfo ? ( |
| 61 | <AwsMarketplaceOnboardingPlaceholder /> |
| 62 | ) : ( |
| 63 | <ScaffoldSection> |
| 64 | <ScaffoldSectionDetail className="text-base"> |
| 65 | <p> |
| 66 | You’ve subscribed to the Briven {onboardingInfo?.plan_name_selected_on_marketplace}{' '} |
| 67 | Plan via the AWS Marketplace. As a final step, you need to create a Briven |
| 68 | organization. That organization will be managed and billed through AWS Marketplace. |
| 69 | </p> |
| 70 | <p> |
| 71 | You can read more on billing through AWS in our {''} |
| 72 | <Link |
| 73 | href={`${DOCS_URL}/guides/platform/aws-marketplace`} |
| 74 | target="_blank" |
| 75 | className="underline" |
| 76 | > |
| 77 | Billing Docs. |
| 78 | </Link> |
| 79 | </p> |
| 80 | </ScaffoldSectionDetail> |
| 81 | <ScaffoldSectionContent className="lg:ml-10"> |
| 82 | <div className="border-l px-10 pt-10"> |
| 83 | <NewAwsMarketplaceOrgForm onSubmit={onSubmit} /> |
| 84 | |
| 85 | <div className="flex justify-end mt-10"> |
| 86 | <Button |
| 87 | form={CREATE_AWS_MANAGED_ORG_FORM_ID} |
| 88 | htmlType="submit" |
| 89 | loading={isCreatingOrganization} |
| 90 | size="medium" |
| 91 | > |
| 92 | Create organization |
| 93 | </Button> |
| 94 | </div> |
| 95 | </div> |
| 96 | </ScaffoldSectionContent> |
| 97 | </ScaffoldSection> |
| 98 | )} |
| 99 | </> |
| 100 | ) |
| 101 | } |
| 102 | |
| 103 | export default AwsMarketplaceCreateNewOrg |