import { PermissionAction } from '@supabase/shared-types/out/constants' import { AlertCircle, BarChart2, ChevronRight } from 'lucide-react' import Link from 'next/link' import { toast } from 'sonner' import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext' import { FormActions } from 'components/ui/Forms/FormActions' import { FormPanel } from 'components/ui/Forms/FormPanel' import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms/FormSection' import Panel from 'components/ui/Panel' import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader' import { useProjectUpdateMutation } from 'data/projects/project-update-mutation' import { useCheckPermissions } from 'hooks/misc/useCheckPermissions' import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization' import { useProjectByRef } from 'hooks/misc/useSelectedProject' import { useFlag } from 'hooks/ui/useFlag' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, CollapsibleContent_Shadcn_, CollapsibleTrigger_Shadcn_, Collapsible_Shadcn_, Form, Input, WarningIcon, } from 'ui' import PauseProjectButton from './Infrastructure/PauseProjectButton' import RestartServerButton from './Infrastructure/RestartServerButton' const General = () => { const { project } = useProjectContext() const organization = useSelectedOrganization() // Also doubles up as a feature flag to enable display of the related alert, // another dedicated flag would be redundant. const v2AnnouncementUrl = useFlag('v2AnnouncementUrl') as string const v2MaintenanceWindow = project?.v2MaintenanceWindow const v2MaintenanceDate = v2MaintenanceWindow?.start ? new Date(v2MaintenanceWindow.start).toUTCString().slice(0, 16) : undefined const v2MaintenanceStartTime = v2MaintenanceWindow?.start?.substring(11, 16) const v2MaintenanceEndTime = v2MaintenanceWindow?.end?.substring(11, 16) const parentProject = useProjectByRef(project?.parent_project_ref) const isBranch = parentProject !== undefined const formId = 'project-general-settings' const initialValues = { name: project?.name ?? '', ref: project?.ref ?? '' } const canUpdateProject = useCheckPermissions(PermissionAction.UPDATE, 'projects', { resource: { project_id: project?.id, }, }) const { mutate: updateProject, isLoading: isUpdating } = useProjectUpdateMutation() const onSubmit = async (values: any, { resetForm }: any) => { if (!project?.ref) return console.error('Ref is required') updateProject( { ref: project.ref, name: values.name.trim() }, { onSuccess: ({ name }) => { resetForm({ values: { name }, initialValues: { name } }) toast.success('Successfully saved settings') }, } ) } return (
{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 ? ( ) : (
{({ handleReset, values, initialValues }: any) => { const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues) return (
} > General settings}> ) }} )} {!isBranch && ( <>
{v2MaintenanceStartTime && v2MaintenanceEndTime && v2AnnouncementUrl !== 'https://' && ( Upcoming project restart scheduled This project will automatically restart on {v2MaintenanceDate} between{' '} {v2MaintenanceStartTime} and {v2MaintenanceEndTime} UTC, which will cause up to a few minutes of downtime. Why this time? Your project has historically had the least database queries across the previous 10 weeks during this 30 minute window. You may also manually restart this project anytime before{' '} {v2MaintenanceDate} {v2MaintenanceStartTime} UTC at a time that is convenient for you.

Find out more {' '} about our v2 platform architecture migration.
)}

Restart project

Your project will not be available for a few minutes.

Pause project

Your project will not be accessible while it is paused.

Project usage statistics have been moved

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

)} ) } export default General