DashboardSettingsToggles.tsx 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // @ts-nocheck
  2. import { zodResolver } from '@hookform/resolvers/zod'
  3. import { useForm } from 'react-hook-form'
  4. import { toast } from 'sonner'
  5. import { Card, Form } from 'ui'
  6. import * as z from 'zod'
  7. import { DashboardToggle } from './DashboardToggle'
  8. import { useIsInlineEditorSetting, useIsQueueOperationsSetting } from './useDashboardSettings'
  9. import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
  10. import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
  11. const DashboardSettingsSchema = z.object({
  12. inlineEditorEnabled: z.boolean(),
  13. queueOperationsEnabled: z.boolean(),
  14. })
  15. export const DashboardSettingsToggles = () => {
  16. const { inlineEditorEnabled, setInlineEditorEnabled } = useIsInlineEditorSetting()
  17. const { isQueueOperationsEnabled, setIsQueueOperationsEnabled } = useIsQueueOperationsSetting()
  18. const { data: org } = useSelectedOrganizationQuery()
  19. const { mutate: sendEvent } = useSendEventMutation()
  20. const form = useForm<z.infer<typeof DashboardSettingsSchema>>({
  21. resolver: zodResolver(DashboardSettingsSchema as any),
  22. values: {
  23. inlineEditorEnabled: inlineEditorEnabled ?? false,
  24. queueOperationsEnabled: isQueueOperationsEnabled ?? false,
  25. },
  26. })
  27. const handleInlineEditorToggle = (value: boolean) => {
  28. setInlineEditorEnabled(value)
  29. form.setValue('inlineEditorEnabled', value)
  30. sendEvent({
  31. action: 'inline_editor_setting_clicked',
  32. properties: { enabled: value },
  33. groups: { organization: org?.slug },
  34. })
  35. toast(
  36. `${value ? 'Editing entities will now be via the SQL Editor' : 'Editing entities will now be via a guided UI panel'}`
  37. )
  38. }
  39. const handleQueueOperationsToggle = (value: boolean) => {
  40. setIsQueueOperationsEnabled(value)
  41. form.setValue('queueOperationsEnabled', value)
  42. sendEvent({
  43. action: 'queue_operations_setting_clicked',
  44. properties: { enabled: value },
  45. groups: { organization: org?.slug },
  46. })
  47. toast(
  48. `${value ? 'Table edits in the Table Editor will now be queued' : 'Table edits in the Table Editor will now be saved immediately'}`
  49. )
  50. }
  51. return (
  52. <Form {...form}>
  53. <Card>
  54. <DashboardToggle
  55. form={form}
  56. name="inlineEditorEnabled"
  57. label="Edit entities in SQL"
  58. description="Edit policies, triggers, and functions in the SQL editor instead of the guided UI."
  59. onToggle={handleInlineEditorToggle}
  60. />
  61. <DashboardToggle
  62. form={form}
  63. name="queueOperationsEnabled"
  64. label="Queue table operations"
  65. description="Review and batch table edits in Table Editor before saving them to your database."
  66. onToggle={handleQueueOperationsToggle}
  67. isLast
  68. />
  69. </Card>
  70. </Form>
  71. )
  72. }