NewAwsMarketplaceOrgModal.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {
  2. Dialog,
  3. DialogContent,
  4. DialogDescription,
  5. DialogFooter,
  6. DialogHeader,
  7. DialogSection,
  8. DialogSectionSeparator,
  9. DialogTitle,
  10. } from '@ui/components/shadcn/ui/dialog'
  11. import { SubmitHandler } from 'react-hook-form'
  12. import { toast } from 'sonner'
  13. import { Button } from 'ui'
  14. import NewAwsMarketplaceOrgForm, {
  15. CREATE_AWS_MANAGED_ORG_FORM_ID,
  16. NewMarketplaceOrgForm,
  17. } from './NewAwsMarketplaceOrgForm'
  18. import { useAwsManagedOrganizationCreateMutation } from '@/data/organizations/organization-create-mutation'
  19. interface Props {
  20. buyerId: string
  21. visible: boolean
  22. onSuccess: (newlyCreatedOrgSlug: string) => void
  23. onClose: () => void
  24. }
  25. const NewAwsMarketplaceOrgModal = ({ buyerId, visible, onSuccess, onClose }: Props) => {
  26. const { mutate: createOrganization, isPending: isCreatingOrganization } =
  27. useAwsManagedOrganizationCreateMutation({
  28. onSuccess: (org) => {
  29. //TODO(thomas): send tracking event?
  30. onSuccess(org.slug)
  31. },
  32. onError: (res) => {
  33. toast.error(res.message, {
  34. duration: 7_000,
  35. })
  36. },
  37. })
  38. const onSubmit: SubmitHandler<NewMarketplaceOrgForm> = async (values) => {
  39. createOrganization({ ...values, buyerId })
  40. }
  41. return (
  42. <Dialog
  43. open={visible}
  44. onOpenChange={(open) => {
  45. if (!open) onClose()
  46. }}
  47. >
  48. <DialogContent
  49. onOpenAutoFocus={(event) => event.preventDefault()}
  50. size="xlarge"
  51. onEscapeKeyDown={(e) => (isCreatingOrganization ? e.preventDefault() : onClose())}
  52. onPointerDownOutside={(e) => (isCreatingOrganization ? e.preventDefault() : onClose())}
  53. className="p-2"
  54. >
  55. <DialogHeader>
  56. <DialogTitle>Create a new organization</DialogTitle>
  57. <DialogDescription>
  58. A new organization will be created and linked to your AWS Marketplace subscription
  59. </DialogDescription>
  60. </DialogHeader>
  61. <DialogSectionSeparator />
  62. <DialogSection>
  63. <NewAwsMarketplaceOrgForm onSubmit={onSubmit}></NewAwsMarketplaceOrgForm>
  64. </DialogSection>
  65. <DialogFooter>
  66. <Button
  67. form={CREATE_AWS_MANAGED_ORG_FORM_ID}
  68. htmlType="submit"
  69. loading={isCreatingOrganization}
  70. size="medium"
  71. >
  72. Create and link organization
  73. </Button>
  74. </DialogFooter>
  75. </DialogContent>
  76. </Dialog>
  77. )
  78. }
  79. export default NewAwsMarketplaceOrgModal