NewAwsMarketplaceOrgForm.tsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import { zodResolver } from '@hookform/resolvers/zod'
  2. import { useForm } from 'react-hook-form'
  3. import {
  4. Form,
  5. FormControl,
  6. FormField,
  7. Input,
  8. Label,
  9. Select,
  10. SelectContent,
  11. SelectItem,
  12. SelectTrigger,
  13. SelectValue,
  14. } from 'ui'
  15. import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
  16. import { z } from 'zod'
  17. const ORG_KIND_TYPES = {
  18. PERSONAL: 'Personal',
  19. EDUCATIONAL: 'Educational',
  20. STARTUP: 'Startup',
  21. AGENCY: 'Agency',
  22. COMPANY: 'Company',
  23. UNDISCLOSED: 'N/A',
  24. }
  25. const ORG_KIND_DEFAULT = 'PERSONAL'
  26. const ORG_SIZE_TYPES = {
  27. '1': '1 - 10',
  28. '10': '10 - 49',
  29. '50': '50 - 99',
  30. '100': '100 - 299',
  31. '300': 'More than 300',
  32. }
  33. interface Props {
  34. onSubmit: (values: NewMarketplaceOrgForm) => void
  35. }
  36. export const CREATE_AWS_MANAGED_ORG_FORM_ID = 'create-aws-managed-org-form'
  37. const FormSchema = z.object({
  38. name: z.string().trim().min(1, 'Please provide an organization name'),
  39. kind: z.string(),
  40. size: z.string().optional(),
  41. })
  42. export type NewMarketplaceOrgForm = z.infer<typeof FormSchema>
  43. const NewAwsMarketplaceOrgForm = ({ onSubmit }: Props) => {
  44. const form = useForm<NewMarketplaceOrgForm>({
  45. resolver: zodResolver(FormSchema as any),
  46. defaultValues: {
  47. name: '',
  48. kind: ORG_KIND_DEFAULT,
  49. },
  50. })
  51. const kind = form.watch('kind')
  52. return (
  53. <Form {...form}>
  54. <form id={CREATE_AWS_MANAGED_ORG_FORM_ID} onSubmit={form.handleSubmit(onSubmit)}>
  55. <div className="flex flex-col gap-4">
  56. <FormField
  57. control={form.control}
  58. name="name"
  59. render={({ field }) => (
  60. <FormItemLayout label="Name" layout="horizontal">
  61. <FormControl>
  62. <>
  63. <Input {...field} placeholder="Organization name" />
  64. <div className="mt-1">
  65. <Label
  66. htmlFor="name"
  67. className="text-foreground-lighter leading-normal text-sm"
  68. >
  69. What's the name of your company or team?
  70. </Label>
  71. </div>
  72. </>
  73. </FormControl>
  74. </FormItemLayout>
  75. )}
  76. />
  77. <FormField
  78. control={form.control}
  79. name="kind"
  80. render={({ field }) => (
  81. <FormItemLayout label="Type" layout="horizontal">
  82. <FormControl>
  83. <>
  84. <Select value={field.value} onValueChange={field.onChange}>
  85. <SelectTrigger>
  86. <SelectValue />
  87. </SelectTrigger>
  88. <SelectContent>
  89. {Object.entries(ORG_KIND_TYPES).map(([k, v]) => (
  90. <SelectItem key={k} value={k}>
  91. {v}
  92. </SelectItem>
  93. ))}
  94. </SelectContent>
  95. </Select>
  96. <div className="mt-1">
  97. <Label
  98. htmlFor="kind"
  99. className="text-foreground-lighter leading-normal text-sm"
  100. >
  101. What would best describe your organization?
  102. </Label>
  103. </div>
  104. </>
  105. </FormControl>
  106. </FormItemLayout>
  107. )}
  108. />
  109. {kind == 'COMPANY' && (
  110. <FormField
  111. control={form.control}
  112. name="size"
  113. render={({ field }) => (
  114. <FormItemLayout label="Company size" layout="horizontal">
  115. <FormControl>
  116. <>
  117. <Select value={field.value} onValueChange={field.onChange}>
  118. <SelectTrigger>
  119. <SelectValue placeholder="How many people are in your company?" />
  120. </SelectTrigger>
  121. <SelectContent>
  122. {Object.entries(ORG_SIZE_TYPES).map(([k, v]) => (
  123. <SelectItem key={k} value={k}>
  124. {v}
  125. </SelectItem>
  126. ))}
  127. </SelectContent>
  128. </Select>
  129. <div className="mt-1">
  130. <Label
  131. htmlFor="size"
  132. className="text-foreground-lighter leading-normal text-sm"
  133. >
  134. How many people are in your company?
  135. </Label>
  136. </div>
  137. </>
  138. </FormControl>
  139. </FormItemLayout>
  140. )}
  141. />
  142. )}
  143. </div>
  144. </form>
  145. </Form>
  146. )
  147. }
  148. export default NewAwsMarketplaceOrgForm