import { zodResolver } from '@hookform/resolvers/zod' import { PermissionAction } from '@supabase/shared-types/out/constants' import { BarChart2 } from 'lucide-react' import Link from 'next/link' import { useForm } from 'react-hook-form' import { toast } from 'sonner' import * as z from 'zod' import { useProjectUpdateMutation } from 'data/projects/project-update-mutation' import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions' import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled' import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization' import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, Card, CardContent, CardFooter, FormControl_Shadcn_, FormField_Shadcn_, FormMessage_Shadcn_, Form_Shadcn_, Input_Shadcn_, WarningIcon, } from 'ui' import { Input } from 'ui-patterns/DataInputs/Input' import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout' import { PageSection, PageSectionContent, PageSectionDescription, PageSectionMeta, PageSectionSummary, PageSectionTitle, } from 'ui-patterns/PageSection' import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader' import PauseProjectButton from './Infrastructure/PauseProjectButton' import RestartServerButton from './Infrastructure/RestartServerButton' export const General = () => { const { data: project } = useSelectedProjectQuery() const { data: organization } = useSelectedOrganizationQuery() const isBranch = Boolean(project?.parent_project_ref) const { projectSettingsRestartProject } = useIsFeatureEnabled([ 'project_settings:restart_project', ]) const { can: canUpdateProject } = useAsyncCheckPermissions(PermissionAction.UPDATE, 'projects', { resource: { project_id: project?.id, }, }) const { mutate: updateProject, isPending: isUpdating } = useProjectUpdateMutation() const formSchema = z.object({ name: z.string().trim().min(3, 'Project name must be at least 3 characters long'), }) const defaultValues = { name: project?.name ?? '' } const form = useForm>({ resolver: zodResolver(formSchema), defaultValues, values: defaultValues, mode: 'onSubmit', reValidateMode: 'onBlur', }) const onSubmit = async (values: z.infer) => { if (!project?.ref) return console.error('Ref is required') updateProject( { ref: project.ref, name: values.name.trim() }, { onSuccess: ({ name }) => { form.reset({ name }) toast.success('Successfully saved settings') }, } ) } return ( <> General settings {isBranch && ( You are currently on a preview branch of your project Certain settings are not available while you're on a preview branch. To adjust your project settings, you may return to your{' '} main branch . )} {project === undefined ? ( ) : (
( )} /> {form.formState.isDirty && ( )}
)}
Project availability Restart or pause your project when performing maintenance.

{projectSettingsRestartProject ? 'Restart project' : 'Restart database'}

Your project will not be available for a few minutes.

Pause project

Your project will not be accessible while it is paused.

{!isBranch && ( Project usage Usage statistics now live under your organization settings.

Project usage statistics have been moved

You may view your project's usage under your organization's settings

{!!organization && !!project && ( )}
)} ) }