DataPrivacyForm.tsx51 lines · main
| 1 | import { PermissionAction } from '@supabase/shared-types/out/constants' |
| 2 | import { useEffect } from 'react' |
| 3 | import { Card, CardContent, CardFooter, Form } from 'ui' |
| 4 | |
| 5 | import { AIOptInLevelSelector } from './AIOptInLevelSelector' |
| 6 | import { FormActions } from '@/components/ui/Forms/FormActions' |
| 7 | import { useAIOptInForm } from '@/hooks/forms/useAIOptInForm' |
| 8 | import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions' |
| 9 | |
| 10 | export const DataPrivacyForm = () => { |
| 11 | const { form, onSubmit, isUpdating, currentOptInLevel } = useAIOptInForm() |
| 12 | const { can: canUpdateOrganization } = useAsyncCheckPermissions( |
| 13 | PermissionAction.UPDATE, |
| 14 | 'organizations' |
| 15 | ) |
| 16 | |
| 17 | const permissionsHelperText = !canUpdateOrganization |
| 18 | ? "You need additional permissions to manage this organization's settings" |
| 19 | : undefined |
| 20 | |
| 21 | useEffect(() => { |
| 22 | form.reset({ aiOptInLevel: currentOptInLevel }) |
| 23 | }, [currentOptInLevel, form]) |
| 24 | |
| 25 | return ( |
| 26 | <Form {...form}> |
| 27 | <form id="org-privacy-form" onSubmit={form.handleSubmit(onSubmit)}> |
| 28 | <Card> |
| 29 | <CardContent className="pt-6"> |
| 30 | <AIOptInLevelSelector |
| 31 | control={form.control} |
| 32 | disabled={!canUpdateOrganization || isUpdating} |
| 33 | layout="flex-row-reverse" |
| 34 | label="Briven Assistant Opt-in Level" |
| 35 | /> |
| 36 | </CardContent> |
| 37 | <CardFooter className="flex justify-end p-4 md:px-8"> |
| 38 | <FormActions |
| 39 | form="org-privacy-form" |
| 40 | isSubmitting={isUpdating} |
| 41 | hasChanges={form.formState.isDirty} |
| 42 | handleReset={() => form.reset()} |
| 43 | helper={permissionsHelperText} |
| 44 | disabled={!canUpdateOrganization} |
| 45 | /> |
| 46 | </CardFooter> |
| 47 | </Card> |
| 48 | </form> |
| 49 | </Form> |
| 50 | ) |
| 51 | } |