Files
28e4473953 Update account/me page components (#41193)
* update account me page

* copy

* Update apps/studio/components/interfaces/Account/Preferences/ProfileInformation.tsx

Co-authored-by: Francesco Sansalvadore <f.sansalvadore@gmail.com>

* Update apps/studio/components/interfaces/Account/Preferences/ProfileInformation.tsx

Co-authored-by: Francesco Sansalvadore <f.sansalvadore@gmail.com>

* Update apps/studio/components/interfaces/Account/Preferences/ProfileInformation.tsx

Co-authored-by: Francesco Sansalvadore <f.sansalvadore@gmail.com>

* fixes

* fix sizes

* Smol fix

---------

Co-authored-by: Francesco Sansalvadore <f.sansalvadore@gmail.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-12-12 17:32:38 +08:00

106 lines
3.3 KiB
TypeScript

import { zodResolver } from '@hookform/resolvers/zod'
import { useForm } from 'react-hook-form'
import * as z from 'zod'
import { LOCAL_STORAGE_KEYS } from 'common'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { Card, CardContent, FormControl_Shadcn_, FormField_Shadcn_, Form_Shadcn_, Switch } from 'ui'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import {
PageSection,
PageSectionContent,
PageSectionDescription,
PageSectionMeta,
PageSectionSummary,
PageSectionTitle,
} from 'ui-patterns/PageSection'
const InlineEditorSchema = z.object({
inlineEditorEnabled: z.boolean(),
})
export const useIsInlineEditorEnabled = () => {
const [inlineEditorEnabled] = useLocalStorageQuery(
LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR,
false
)
return inlineEditorEnabled ?? false
}
export const InlineEditorSettings = () => {
const [inlineEditorEnabled, setInlineEditorEnabled] = useLocalStorageQuery(
LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR,
false
)
const { data: org } = useSelectedOrganizationQuery()
const { mutate: sendEvent } = useSendEventMutation()
const form = useForm<z.infer<typeof InlineEditorSchema>>({
resolver: zodResolver(InlineEditorSchema),
values: {
inlineEditorEnabled: inlineEditorEnabled ?? false,
},
})
const handleToggle = (value: boolean) => {
setInlineEditorEnabled(value)
form.setValue('inlineEditorEnabled', value)
sendEvent({
action: 'inline_editor_setting_clicked',
properties: {
enabled: value,
},
groups: {
organization: org?.slug,
},
})
}
return (
<PageSection>
<PageSectionMeta>
<PageSectionSummary>
<PageSectionTitle id="inline-editor">Dashboard</PageSectionTitle>
<PageSectionDescription>
Choose your preferred experience when editing policies, triggers, and functions.
</PageSectionDescription>
</PageSectionSummary>
</PageSectionMeta>
<PageSectionContent>
<Form_Shadcn_ {...form}>
<Card>
<CardContent>
<FormField_Shadcn_
control={form.control}
name="inlineEditorEnabled"
render={({ field }) => (
<FormItemLayout
layout="flex-row-reverse"
label="Edit entities in SQL"
description="When enabled, view and edit policies, triggers, and functions directly in the SQL editor instead of a more beginner-friendly UI panel. Ideal for those comfortable with SQL."
>
<FormControl_Shadcn_>
<Switch
checked={field.value}
onCheckedChange={(value) => {
field.onChange(value)
handleToggle(value)
}}
/>
</FormControl_Shadcn_>
</FormItemLayout>
)}
/>
</CardContent>
</Card>
</Form_Shadcn_>
</PageSectionContent>
</PageSection>
)
}