JoinOrganizationOnSignup.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { useForm } from 'react-hook-form'
  2. import {
  3. FormControl,
  4. FormField,
  5. Select,
  6. SelectContent,
  7. SelectGroup,
  8. SelectItem,
  9. SelectTrigger,
  10. SelectValue,
  11. Switch,
  12. } from 'ui'
  13. import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
  14. import { SSOConfigFormSchema } from './SSOConfig'
  15. export const JoinOrganizationOnSignup = ({
  16. form,
  17. }: {
  18. form: ReturnType<typeof useForm<SSOConfigFormSchema>>
  19. }) => {
  20. const joinOrgOnSignup = form.watch('joinOrgOnSignup')
  21. return (
  22. <div className="space-y-4">
  23. <FormField
  24. control={form.control}
  25. name="joinOrgOnSignup"
  26. render={({ field }) => (
  27. <FormItemLayout
  28. layout="flex-row-reverse"
  29. label="Automatically add users to organization on sign up"
  30. description="If disabled, users will need to be invited to the organization after signing up"
  31. >
  32. <FormControl className="flex items-center gap-2">
  33. <Switch checked={field.value} onCheckedChange={field.onChange} />
  34. </FormControl>
  35. </FormItemLayout>
  36. )}
  37. />
  38. {joinOrgOnSignup && (
  39. <FormField
  40. control={form.control}
  41. name="roleOnJoin"
  42. render={({ field }) => (
  43. <FormItemLayout
  44. label="Default role on join"
  45. description="Select a role for the user when they join the organization"
  46. layout="flex-row-reverse"
  47. className="justify-between"
  48. >
  49. <FormControl>
  50. <Select value={field.value} onValueChange={(val) => field.onChange(val)}>
  51. <SelectTrigger className="w-52">
  52. <SelectValue placeholder="Select a role" />
  53. </SelectTrigger>
  54. <SelectContent>
  55. <SelectGroup>
  56. <SelectItem value="Owner">Owner</SelectItem>
  57. <SelectItem value="Administrator">Administrator</SelectItem>
  58. <SelectItem value="Developer">Developer</SelectItem>
  59. <SelectItem value="Read-only">Read-only</SelectItem>
  60. </SelectGroup>
  61. </SelectContent>
  62. </Select>
  63. </FormControl>
  64. </FormItemLayout>
  65. )}
  66. />
  67. )}
  68. </div>
  69. )
  70. }