Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Use page and form components general settings (#41192)

Saxon Fletchere98ba379b8f7
diff --git a/apps/studio/components/interfaces/Settings/General/ComplianceConfig/ProjectComplianceMode.tsx b/apps/studio/components/interfaces/Settings/General/ComplianceConfig/ProjectComplianceMode.tsx
index c073eca684a..628c7b13423 100644
--- a/apps/studio/components/interfaces/Settings/General/ComplianceConfig/ProjectComplianceMode.tsx
+++ b/apps/studio/components/interfaces/Settings/General/ComplianceConfig/ProjectComplianceMode.tsx
@@ -6,16 +6,21 @@ import { toast } from 'sonner'
import { useParams } from 'common'
import AlertError from 'components/ui/AlertError'
import { DocsButton } from 'components/ui/DocsButton'
-import { FormHeader } from 'components/ui/Forms/FormHeader'
-import { FormPanel } from 'components/ui/Forms/FormPanel'
-import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms/FormSection'
import { InlineLink } from 'components/ui/InlineLink'
import { useComplianceConfigUpdateMutation } from 'data/config/project-compliance-config-mutation'
import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { DOCS_URL } from 'lib/constants'
-import { Switch, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
+import { Card, CardContent, Switch, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
+import {
+ PageSection,
+ PageSectionContent,
+ PageSectionDescription,
+ PageSectionMeta,
+ PageSectionSummary,
+ PageSectionTitle,
+} from 'ui-patterns/PageSection'
export const ComplianceConfig = () => {
const { ref } = useParams()
@@ -61,36 +66,30 @@ export const ComplianceConfig = () => {
}, [isLoading])
return (
- <div id="compliance-configuration">
- <div className="flex items-center justify-between mb-6">
- <FormHeader
- className="mb-0"
- title="High Compliance Configuration"
- description="For projects storing and processing sensitive data (HIPAA)"
- />
- <DocsButton href={`${DOCS_URL}/guides/platform/hipaa-projects`} />
- </div>
- <FormPanel>
- <FormSection
- header={
- <FormSectionLabel
- className="lg:col-span-9"
- description={
- <p className="text-sm text-foreground-light">
- Enable security warnings in the{' '}
- <InlineLink href={`/project/${ref}/advisors/security`}>
- Security Advisor
- </InlineLink>{' '}
- to enforce requirements for managing sensitive data
- </p>
- }
- >
- Apply additional compliance controls to project
- </FormSectionLabel>
- }
- >
- <FormSectionContent loading={false} className="lg:!col-span-3">
- <div className="flex items-center justify-end mt-2.5 space-x-2">
+ <PageSection id="compliance-configuration">
+ <PageSectionMeta>
+ <div className="flex flex-col gap-3 @lg:flex-row @lg:items-center @lg:justify-between">
+ <PageSectionSummary>
+ <PageSectionTitle>High Compliance Configuration</PageSectionTitle>
+ <PageSectionDescription>
+ For projects storing and processing sensitive data (HIPAA).
+ </PageSectionDescription>
+ </PageSectionSummary>
+ <DocsButton href={`${DOCS_URL}/guides/platform/hipaa-projects`} />
+ </div>
+ </PageSectionMeta>
+ <PageSectionContent>
+ <Card>
+ <CardContent className="flex flex-col gap-4 @lg:flex-row @lg:items-center @lg:justify-between">
+ <div className="space-y-2 max-w-2xl">
+ <p className="text-sm">Apply additional compliance controls to project</p>
+ <p className="text-sm text-foreground-light">
+ Enable security warnings in the{' '}
+ <InlineLink href={`/project/${ref}/advisors/security`}>Security Advisor</InlineLink>{' '}
+ to enforce requirements for managing sensitive data.
+ </p>
+ </div>
+ <div className="flex items-center justify-end space-x-2">
{(isLoading || isSubmitting) && (
<Loader2 className="animate-spin" strokeWidth={1.5} size={16} />
)}
@@ -119,9 +118,9 @@ export const ComplianceConfig = () => {
</Tooltip>
)}
</div>
- </FormSectionContent>
- </FormSection>
- </FormPanel>
- </div>
+ </CardContent>
+ </Card>
+ </PageSectionContent>
+ </PageSection>
)
}
diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
index 39068ee77ae..b4b55d01884 100644
--- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
+++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
@@ -3,9 +3,7 @@ import { AlertCircle } from 'lucide-react'
import { SupportCategories } from '@supabase/shared-types/out/constants'
import { useFlag, useParams } from 'common'
import { SupportLink } from 'components/interfaces/Support/SupportLink'
-import { FormHeader } from 'components/ui/Forms/FormHeader'
import { InlineLinkClassName } from 'components/ui/InlineLink'
-import Panel from 'components/ui/Panel'
import { UpgradeToPro } from 'components/ui/UpgradeToPro'
import {
useCustomDomainsQuery,
@@ -13,6 +11,15 @@ import {
} from 'data/custom-domains/custom-domains-query'
import { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
+import { Card, CardContent } from 'ui'
+import {
+ PageSection,
+ PageSectionContent,
+ PageSectionDescription,
+ PageSectionMeta,
+ PageSectionSummary,
+ PageSectionTitle,
+} from 'ui-patterns/PageSection'
import CustomDomainActivate from './CustomDomainActivate'
import CustomDomainDelete from './CustomDomainDelete'
import CustomDomainVerify from './CustomDomainVerify'
@@ -54,87 +61,101 @@ export const CustomDomainConfig = () => {
const { status } = customDomainData || {}
return (
- <section id="custom-domains">
- <FormHeader title="Custom Domains" description="Present a branded experience to your users" />
- {isLoadingAddons ? (
- <Panel>
- <Panel.Content className="space-y-6">
- <CustomDomainsShimmerLoader />
- </Panel.Content>
- </Panel>
- ) : !hasCustomDomainAddon ? (
- <UpgradeToPro
- primaryText={
- customDomainsDisabledDueToQuota
- ? 'New custom domains are temporarily disabled'
- : 'Custom domains are a Pro Plan add-on'
- }
- secondaryText={
- customDomainsDisabledDueToQuota
- ? 'We are working with our upstream DNS provider before we are able to sign up new custom domains. Please check back in a few hours.'
- : plan === 'free'
- ? 'Paid Plans come with free vanity subdomains or Custom Domains for an additional $10/month per domain.'
- : 'To configure a custom domain for your project, please enable the add-on. Each Custom Domain costs $10 per month.'
- }
- addon="customDomain"
- source="customDomain"
- featureProposition="enable custom domains"
- disabled={customDomainsDisabledDueToQuota}
- />
- ) : isCustomDomainsLoading ? (
- <Panel>
- <Panel.Content className="space-y-6">
- <CustomDomainsShimmerLoader />
- </Panel.Content>
- </Panel>
- ) : isError ? (
- <Panel>
- <Panel.Content className="space-y-6">
- <div className="flex items-center justify-center space-x-2 py-8">
- <AlertCircle size={16} strokeWidth={1.5} />
- <p className="text-sm text-foreground-light">
- Failed to retrieve custom domain configuration. Please try again later or{' '}
- <SupportLink
- queryParams={{ projectRef: ref, category: SupportCategories.SALES_ENQUIRY }}
- className={InlineLinkClassName}
- >
- contact support
- </SupportLink>
- .
- </p>
- </div>
- </Panel.Content>
- </Panel>
- ) : status === '0_no_hostname_configured' ? (
- <CustomDomainsConfigureHostname />
- ) : (
- <Panel>
- {isSuccess ? (
- <div className="flex flex-col">
- {(status === '1_not_started' ||
- status === '2_initiated' ||
- status === '3_challenge_verified') && <CustomDomainVerify />}
+ <PageSection id="custom-domains">
+ <PageSectionMeta>
+ <PageSectionSummary>
+ <PageSectionTitle>Custom Domains</PageSectionTitle>
+ <PageSectionDescription>
+ Present a branded experience to your users.
+ </PageSectionDescription>
+ </PageSectionSummary>
+ </PageSectionMeta>
+ <PageSectionContent>
+ {isLoadingAddons ? (
+ <Card>
+ <CardContent className="space-y-6">
+ <CustomDomainsShimmerLoader />
+ </CardContent>
+ </Card>
+ ) : !hasCustomDomainAddon ? (
+ <UpgradeToPro
+ primaryText={
+ customDomainsDisabledDueToQuota
+ ? 'New custom domains are temporarily disabled'
+ : 'Custom domains are a Pro Plan add-on'
+ }
+ secondaryText={
+ customDomainsDisabledDueToQuota
+ ? 'We are working with our upstream DNS provider before we are able to sign up new custom domains. Please check back in a few hours.'
+ : plan === 'free'
+ ? 'Paid Plans come with free vanity subdomains or Custom Domains for an additional $10/month per domain.'
+ : 'To configure a custom domain for your project, please enable the add-on. Each Custom Domain costs $10 per month.'
+ }
+ addon="customDomain"
+ source="customDomain"
+ featureProposition="enable custom domains"
+ disabled={customDomainsDisabledDueToQuota}
+ />
+ ) : isCustomDomainsLoading ? (
+ <Card>
+ <CardContent className="space-y-6">
+ <CustomDomainsShimmerLoader />
+ </CardContent>
+ </Card>
+ ) : isError ? (
+ <Card>
+ <CardContent className="space-y-6">
+ <div className="flex items-center justify-center space-x-2 py-8">
+ <AlertCircle size={16} strokeWidth={1.5} />
+ <p className="text-sm text-foreground-light">
+ Failed to retrieve custom domain configuration. Please try again later or{' '}
+ <SupportLink
+ queryParams={{ projectRef: ref, category: SupportCategories.SALES_ENQUIRY }}
+ className={InlineLinkClassName}
+ >
+ contact support
+ </SupportLink>
+ .
+ </p>
+ </div>
+ </CardContent>
+ </Card>
+ ) : status === '0_no_hostname_configured' ? (
+ <CustomDomainsConfigureHostname />
+ ) : (
+ <Card>
+ <CardContent className="p-0">
+ {isSuccess ? (
+ <div className="flex flex-col">
+ {(status === '1_not_started' ||
+ status === '2_initiated' ||
+ status === '3_challenge_verified') && <CustomDomainVerify />}
- {customDomainData.status === '4_origin_setup_completed' && (
- <CustomDomainActivate
- projectRef={ref}
- customDomain={customDomainData.customDomain}
- />
- )}
+ {customDomainData.status === '4_origin_setup_completed' && (
+ <CustomDomainActivate
+ projectRef={ref}
+ customDomain={customDomainData.customDomain}
+ />
+ )}
- {customDomainData.status === '5_services_reconfigured' && (
- <CustomDomainDelete projectRef={ref} customDomain={customDomainData.customDomain} />
+ {customDomainData.status === '5_services_reconfigured' && (
+ <CustomDomainDelete
+ projectRef={ref}
+ customDomain={customDomainData.customDomain}
+ />
+ )}
+ </div>
+ ) : (
+ <CustomDomainConfigFallthrough
+ fetchStatus={customDomainStatus}
+ data={customDomainData}
+ />
)}
- </div>
- ) : (
- <CustomDomainConfigFallthrough
- fetchStatus={customDomainStatus}
- data={customDomainData}
- />
- )}
- </Panel>
- )}
- </section>
+ </CardContent>
+ </Card>
+ )}
+ </PageSectionContent>
+ </PageSection>
)
}
diff --git a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx
index 7106ee78bcc..cd0ad8a982d 100644
--- a/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx
+++ b/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainsConfigureHostname.tsx
@@ -1,21 +1,33 @@
+import { zodResolver } from '@hookform/resolvers/zod'
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import * as yup from 'yup'
+import { useForm } from 'react-hook-form'
+import { z } from 'zod'
import { useParams } from 'common'
import { DocsButton } from 'components/ui/DocsButton'
-import { FormActions } from 'components/ui/Forms/FormActions'
-import { FormPanel } from 'components/ui/Forms/FormPanel'
-import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms/FormSection'
import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { useCheckCNAMERecordMutation } from 'data/custom-domains/check-cname-mutation'
import { useCustomDomainCreateMutation } from 'data/custom-domains/custom-domains-create-mutation'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { DOCS_URL } from 'lib/constants'
-import { Form, Input } from 'ui'
+import {
+ Button,
+ Card,
+ CardContent,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+ FormControl_Shadcn_,
+ FormField_Shadcn_,
+ FormMessage_Shadcn_,
+ Form_Shadcn_,
+ Input_Shadcn_,
+} from 'ui'
+import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
-const schema = yup.object({
- domain: yup.string().required('A value for your custom domain is required'),
+const schema = z.object({
+ domain: z.string().trim().min(1, 'A value for your custom domain is required'),
})
const CustomDomainsConfigureHostname = () => {
@@ -26,7 +38,6 @@ const CustomDomainsConfigureHostname = () => {
const { mutate: createCustomDomain, isPending: isCreating } = useCustomDomainCreateMutation()
const { data: settings } = useProjectSettingsV2Query({ projectRef: ref })
- const FORM_ID = 'custom-domains-form'
const endpoint = settings?.app_config?.endpoint
const { can: canConfigureCustomDomain } = useAsyncCheckPermissions(
PermissionAction.UPDATE,
@@ -38,88 +49,109 @@ const CustomDomainsConfigureHostname = () => {
}
)
- const onCreateCustomDomain = async (values: yup.InferType<typeof schema>) => {
+ const form = useForm<z.infer<typeof schema>>({
+ resolver: zodResolver(schema),
+ defaultValues: {
+ domain: '',
+ },
+ mode: 'onSubmit',
+ reValidateMode: 'onBlur',
+ })
+
+ const onCreateCustomDomain = async (values: z.infer<typeof schema>) => {
if (!ref) return console.error('Project ref is required')
checkCNAMERecord(
- { domain: values.domain },
+ { domain: values.domain.trim() },
{
onSuccess: () => {
- createCustomDomain({ projectRef: ref, customDomain: values.domain })
+ createCustomDomain({ projectRef: ref, customDomain: values.domain.trim() })
},
}
)
}
+ const domain = form.watch('domain')
+ const isSubmitting = isCheckingRecord || isCreating
+
return (
- <Form
- id={FORM_ID}
- initialValues={{ domain: '' }}
- validationSchema={schema}
- onSubmit={onCreateCustomDomain}
- >
- {({ handleReset, values, initialValues }: any) => {
- const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)
+ <Form_Shadcn_ {...form}>
+ <form onSubmit={form.handleSubmit(onCreateCustomDomain)}>
+ <Card>
+ <CardHeader className="flex flex-row items-center justify-between space-y-0 gap-4">
+ <CardTitle>Add a custom domain</CardTitle>
+ <DocsButton href={`${DOCS_URL}/guides/platform/custom-domains`} />
+ </CardHeader>
+ <CardContent>
+ <div className="space-y-4">
+ <FormField_Shadcn_
+ control={form.control}
+ name="domain"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Custom domain"
+ description="Enter the subdomain you want to use."
+ className="[&>div]:md:w-1/2"
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_
+ {...field}
+ placeholder="subdomain.example.com"
+ disabled={!canConfigureCustomDomain || isSubmitting}
+ autoComplete="off"
+ />
+ </FormControl_Shadcn_>
+ <FormMessage_Shadcn_ />
+ </FormItemLayout>
+ )}
+ />
+ </div>
+ </CardContent>
+ <CardContent>
+ <h4 className="text-sm mb-1">Configure a CNAME record</h4>
+ <p className="text-sm text-foreground-light">
+ Set up a CNAME record for{' '}
+ {domain ? <code className="text-code-inline">{domain}</code> : 'your custom domain'}{' '}
+ resolving to{' '}
+ {endpoint ? (
+ <code className="text-code-inline">{endpoint}</code>
+ ) : (
+ "your project's API URL"
+ )}{' '}
+ with as low a TTL as possible. If you're using Cloudflare as your DNS provider,
+ disable the proxy option.
+ </p>
+ </CardContent>
- return (
- <>
- <FormPanel
- disabled={!canConfigureCustomDomain}
- footer={
- <div className="flex py-4 px-[var(--card-padding-x)]">
- <FormActions
- form={FORM_ID}
- isSubmitting={isCheckingRecord || isCreating}
- submitText="Add"
- hasChanges={hasChanges}
- handleReset={handleReset}
- disabled={!true}
- helper={
- !canConfigureCustomDomain ? (
- "You need additional permissions to update your project's custom domain settings"
- ) : (
- <DocsButton href={`${DOCS_URL}/guides/platform/custom-domains`} />
- )
- }
- />
- </div>
- }
+ <CardFooter className="justify-end space-x-2">
+ {form.formState.isDirty && (
+ <Button
+ type="default"
+ disabled={isSubmitting}
+ onClick={() => form.reset({ domain: '' })}
+ >
+ Cancel
+ </Button>
+ )}
+ <Button
+ type="primary"
+ htmlType="submit"
+ loading={isSubmitting}
+ disabled={!form.formState.isDirty || isSubmitting || !canConfigureCustomDomain}
>
- <FormSection header={<FormSectionLabel>Add a custom domain</FormSectionLabel>}>
- <FormSectionContent loading={false}>
- <Input
- id="domain"
- disabled={!canConfigureCustomDomain || isCheckingRecord || isCreating}
- className="w-full"
- type="text"
- name="domain"
- placeholder="subdomain.example.com"
- />
- </FormSectionContent>
- </FormSection>
- <FormSection header={<FormSectionLabel>Configure a CNAME record</FormSectionLabel>}>
- <p className="col-span-12 text-sm lg:col-span-7 leading-6">
- Set up a CNAME record for{' '}
- {values.domain ? (
- <code className="text-code-inline">{values.domain}</code>
- ) : (
- 'your custom domain'
- )}{' '}
- resolving to{' '}
- {endpoint ? (
- <code className="text-code-inline">{endpoint}</code>
- ) : (
- "your project's API URL"
- )}{' '}
- with as low a TTL as possible. If you're using Cloudflare as your DNS provider,
- disable the proxy option.
- </p>
- </FormSection>
- </FormPanel>
- </>
- )
- }}
- </Form>
+ Add
+ </Button>
+ </CardFooter>
+ </Card>
+
+ {!canConfigureCustomDomain && (
+ <p className="text-xs text-foreground-light">
+ You need additional permissions to update your project's custom domain settings.
+ </p>
+ )}
+ </form>
+ </Form_Shadcn_>
)
}
diff --git a/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectPanel.tsx b/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectPanel.tsx
index 2e4d2f5cdf8..61bb43b3e43 100644
--- a/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectPanel.tsx
+++ b/apps/studio/components/interfaces/Settings/General/DeleteProjectPanel/DeleteProjectPanel.tsx
@@ -1,7 +1,14 @@
-import { FormHeader } from 'components/ui/Forms/FormHeader'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
-import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_, CriticalIcon } from 'ui'
+import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, CriticalIcon } from 'ui'
+import {
+ PageSection,
+ PageSectionContent,
+ PageSectionDescription,
+ PageSectionMeta,
+ PageSectionSummary,
+ PageSectionTitle,
+} from 'ui-patterns/PageSection'
import { DeleteProjectButton } from './DeleteProjectButton'
export const DeleteProjectPanel = () => {
@@ -20,17 +27,26 @@ export const DeleteProjectPanel = () => {
: 'Make sure you have made a backup if you want to keep your data.'
return (
- <section id="delete-project">
- <FormHeader title="Delete Project" description="" />
+ <PageSection id="delete-project">
+ <PageSectionMeta>
+ <PageSectionSummary>
+ <PageSectionTitle>Delete Project</PageSectionTitle>
+ <PageSectionDescription>
+ Permanently remove your project and its database.
+ </PageSectionDescription>
+ </PageSectionSummary>
+ </PageSectionMeta>
- <Alert_Shadcn_ variant="destructive">
- <CriticalIcon />
- <AlertTitle_Shadcn_>{title}</AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_>{description}</AlertDescription_Shadcn_>
- <div className="mt-2">
- <DeleteProjectButton />
- </div>
- </Alert_Shadcn_>
- </section>
+ <PageSectionContent>
+ <Alert_Shadcn_ variant="destructive">
+ <CriticalIcon />
+ <AlertTitle_Shadcn_>{title}</AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>{description}</AlertDescription_Shadcn_>
+ <div className="mt-2">
+ <DeleteProjectButton />
+ </div>
+ </Alert_Shadcn_>
+ </PageSectionContent>
+ </PageSection>
)
}
diff --git a/apps/studio/components/interfaces/Settings/General/General.tsx b/apps/studio/components/interfaces/Settings/General/General.tsx
index 8b70571f408..5b65d5ca151 100644
--- a/apps/studio/components/interfaces/Settings/General/General.tsx
+++ b/apps/studio/components/interfaces/Settings/General/General.tsx
@@ -1,15 +1,12 @@
+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 { useState } from 'react'
+import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
+import * as z from 'zod'
-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 { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { useProjectUpdateMutation } from 'data/projects/project-update-mutation'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
@@ -20,10 +17,26 @@ import {
AlertTitle_Shadcn_,
Alert_Shadcn_,
Button,
- Form,
- Input,
+ 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 PauseProjectButton from './Infrastructure/PauseProjectButton'
import RestartServerButton from './Infrastructure/RestartServerButton'
@@ -31,17 +44,12 @@ export const General = () => {
const { data: project } = useSelectedProjectQuery()
const { data: organization } = useSelectedOrganizationQuery()
- // [Joshen] Need to refactor to use RHF so we don't need manual error handlers like this
- const [nameError, setNameError] = useState<string>()
-
const isBranch = Boolean(project?.parent_project_ref)
const { projectSettingsRestartProject } = useIsFeatureEnabled([
'project_settings:restart_project',
])
- const formId = 'project-general-settings'
- const initialValues = { name: project?.name ?? '', ref: project?.ref ?? '' }
const { can: canUpdateProject } = useAsyncCheckPermissions(PermissionAction.UPDATE, 'projects', {
resource: {
project_id: project?.id,
@@ -50,19 +58,27 @@ export const General = () => {
const { mutate: updateProject, isPending: isUpdating } = useProjectUpdateMutation()
- const onSubmit = async (values: any, { resetForm }: any) => {
- if (!project?.ref) return console.error('Ref is required')
+ const formSchema = z.object({
+ name: z.string().trim().min(3, 'Project name must be at least 3 characters long'),
+ })
- if (values.name.length < 3) {
- setNameError('Project name must be at least 3 characters long')
- return
- }
+ const defaultValues = { name: project?.name ?? '' }
+ const form = useForm<z.infer<typeof formSchema>>({
+ resolver: zodResolver(formSchema),
+ defaultValues,
+ values: defaultValues,
+ mode: 'onSubmit',
+ reValidateMode: 'onBlur',
+ })
+
+ const onSubmit = async (values: z.infer<typeof formSchema>) => {
+ if (!project?.ref) return console.error('Ref is required')
updateProject(
{ ref: project.ref, name: values.name.trim() },
{
onSuccess: ({ name }) => {
- resetForm({ values: { name }, initialValues: { name } })
+ form.reset({ name })
toast.success('Successfully saved settings')
},
}
@@ -70,132 +86,187 @@ export const General = () => {
}
return (
- <div>
- {isBranch && (
- <Alert_Shadcn_ variant="default" className="mb-6">
- <WarningIcon />
- <AlertTitle_Shadcn_>
- You are currently on a preview branch of your project
- </AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_>
- Certain settings are not available while you're on a preview branch. To adjust your
- project settings, you may return to your{' '}
- <Link
- href={`/project/${project?.parent_project_ref}/settings/general`}
- className="text-brand"
- >
- main branch
- </Link>
- .
- </AlertDescription_Shadcn_>
- </Alert_Shadcn_>
- )}
+ <>
+ <PageSection>
+ <PageSectionMeta>
+ <PageSectionSummary>
+ <PageSectionTitle>General settings</PageSectionTitle>
+ </PageSectionSummary>
+ </PageSectionMeta>
+ <PageSectionContent>
+ {isBranch && (
+ <Alert_Shadcn_ variant="default">
+ <WarningIcon />
+ <AlertTitle_Shadcn_>
+ You are currently on a preview branch of your project
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ Certain settings are not available while you're on a preview branch. To adjust your
+ project settings, you may return to your{' '}
+ <Link
+ href={`/project/${project?.parent_project_ref}/settings/general`}
+ className="text-brand"
+ >
+ main branch
+ </Link>
+ .
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )}
- {project === undefined ? (
- <GenericSkeletonLoader />
- ) : (
- <Form id={formId} initialValues={initialValues} onSubmit={onSubmit}>
- {({ handleReset, values, initialValues }: any) => {
- const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues)
- return (
- <FormPanel
- disabled={!canUpdateProject}
- footer={
- <div className="flex py-4 px-[var(--card-padding-x)]">
- <FormActions
- form={formId}
- isSubmitting={isUpdating}
- hasChanges={hasChanges}
- handleReset={() => {
- handleReset()
- setNameError(undefined)
- }}
- helper={
- !canUpdateProject
- ? "You need additional permissions to manage this project's settings"
- : undefined
- }
- />
- </div>
- }
- >
- <FormSection header={<FormSectionLabel>General settings</FormSectionLabel>}>
- <FormSectionContent loading={false}>
- <Input
- id="name"
- size="small"
- label="Project name"
- disabled={isBranch || !canUpdateProject}
- onChange={() => setNameError(undefined)}
- error={nameError}
+ {project === undefined ? (
+ <GenericSkeletonLoader />
+ ) : (
+ <Form_Shadcn_ {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)}>
+ <Card>
+ <CardContent>
+ <FormField_Shadcn_
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Project name"
+ description="Displayed throughout the dashboard."
+ className="[&>div]:md:w-1/2"
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_
+ {...field}
+ disabled={isBranch || !canUpdateProject}
+ autoComplete="off"
+ />
+ </FormControl_Shadcn_>
+ <FormMessage_Shadcn_ />
+ </FormItemLayout>
+ )}
/>
- <Input copy disabled id="ref" size="small" label="Project ID" />
- </FormSectionContent>
- </FormSection>
- </FormPanel>
- )
- }}
- </Form>
- )}
- <div className="mt-6" id="restart-project">
- <FormPanel>
- <div className="flex flex-col py-4 px-[var(--card-padding-x)]">
- <div className="flex flex-col @lg:flex-row @lg:justify-between @lg:items-center gap-4">
- <div>
- <p className="text-sm">
- {projectSettingsRestartProject ? 'Restart project' : 'Restart database'}
- </p>
- <div className="max-w-[420px]">
- <p className="text-sm text-foreground-light">
- Your project will not be available for a few minutes.
- </p>
- </div>
- </div>
- <RestartServerButton />
- </div>
- </div>
- <div
- className="flex w-full flex-col @lg:flex-row @lg:justify-between @lg:items-center gap-4 px-[var(--card-padding-x)] py-4"
- id="pause-project"
- >
- <div>
- <p className="text-sm">Pause project</p>
- <div className="max-w-[420px]">
- <p className="text-sm text-foreground-light">
- Your project will not be accessible while it is paused.
- </p>
- </div>
- </div>
- <PauseProjectButton />
- </div>
- </FormPanel>
- </div>
- {!isBranch && (
- <div className="mt-6">
- <Panel>
- <Panel.Content>
+ </CardContent>
+ <CardContent>
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Project ID"
+ description="Reference used in APIs and URLs."
+ className="[&>div]:md:w-1/2 [&>div>div]:md:w-full"
+ >
+ <FormControl_Shadcn_>
+ <Input copy readOnly size="small" value={project?.ref ?? ''} />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ </CardContent>
+ <CardFooter className="justify-end space-x-2">
+ {form.formState.isDirty && (
+ <Button
+ type="default"
+ htmlType="button"
+ disabled={isUpdating}
+ onClick={() => form.reset({ name: project?.name ?? '' })}
+ >
+ Cancel
+ </Button>
+ )}
+ <Button
+ type="primary"
+ htmlType="submit"
+ disabled={
+ !form.formState.isDirty || isUpdating || !canUpdateProject || isBranch
+ }
+ loading={isUpdating}
+ >
+ Save changes
+ </Button>
+ </CardFooter>
+ </Card>
+ </form>
+ </Form_Shadcn_>
+ )}
+ </PageSectionContent>
+ </PageSection>
+
+ <PageSection id="restart-project">
+ <PageSectionMeta>
+ <PageSectionSummary>
+ <PageSectionTitle>Project availability</PageSectionTitle>
+ <PageSectionDescription>
+ Restart or pause your project when performing maintenance.
+ </PageSectionDescription>
+ </PageSectionSummary>
+ </PageSectionMeta>
+ <PageSectionContent>
+ <Card>
+ <CardContent>
<div className="flex flex-col @lg:flex-row @lg:justify-between @lg:items-center gap-4">
- <div className="flex space-x-4">
- <BarChart2 strokeWidth={2} />
- <div>
- <p className="text-sm">Project usage statistics have been moved</p>
- <p className="text-foreground-light text-sm">
- You may view your project's usage under your organization's settings
+ <div>
+ <p className="text-sm">
+ {projectSettingsRestartProject ? 'Restart project' : 'Restart database'}
+ </p>
+ <div className="max-w-[420px]">
+ <p className="text-sm text-foreground-light">
+ Your project will not be available for a few minutes.
</p>
</div>
</div>
+ <RestartServerButton />
+ </div>
+ </CardContent>
+ <CardContent>
+ <div
+ className="flex w-full flex-col @lg:flex-row @lg:justify-between @lg:items-center gap-4"
+ id="pause-project"
+ >
<div>
- <Button asChild type="default">
- <Link href={`/org/${organization?.slug}/usage?projectRef=${project?.ref}`}>
- View project usage
- </Link>
- </Button>
+ <p className="text-sm">Pause project</p>
+ <div className="max-w-[420px]">
+ <p className="text-sm text-foreground-light">
+ Your project will not be accessible while it is paused.
+ </p>
+ </div>
</div>
+ <PauseProjectButton />
</div>
- </Panel.Content>
- </Panel>
- </div>
+ </CardContent>
+ </Card>
+ </PageSectionContent>
+ </PageSection>
+
+ {!isBranch && (
+ <PageSection>
+ <PageSectionMeta>
+ <PageSectionSummary>
+ <PageSectionTitle>Project usage</PageSectionTitle>
+ <PageSectionDescription>
+ Usage statistics now live under your organization settings.
+ </PageSectionDescription>
+ </PageSectionSummary>
+ </PageSectionMeta>
+ <PageSectionContent>
+ <Card>
+ <CardContent>
+ <div className="flex flex-col @lg:flex-row @lg:justify-between @lg:items-center gap-4">
+ <div className="flex space-x-4">
+ <BarChart2 strokeWidth={2} />
+ <div>
+ <p className="text-sm">Project usage statistics have been moved</p>
+ <p className="text-foreground-light text-sm">
+ You may view your project's usage under your organization's settings
+ </p>
+ </div>
+ </div>
+
+ {!!organization && !!project && (
+ <Button asChild type="default">
+ <Link href={`/org/${organization.slug}/usage?projectRef=${project.ref}`}>
+ View project usage
+ </Link>
+ </Button>
+ )}
+ </div>
+ </CardContent>
+ </Card>
+ </PageSectionContent>
+ </PageSection>
)}
- </div>
+ </>
)
}
diff --git a/apps/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectPanel.tsx b/apps/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectPanel.tsx
index 093c1d9e3dc..b713be37c48 100644
--- a/apps/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectPanel.tsx
+++ b/apps/studio/components/interfaces/Settings/General/TransferProjectPanel/TransferProjectPanel.tsx
@@ -1,9 +1,16 @@
import { Truck } from 'lucide-react'
-import { FormHeader } from 'components/ui/Forms/FormHeader'
-import Panel from 'components/ui/Panel'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { TransferProjectButton } from './TransferProjectButton'
+import { Card, CardContent } from 'ui'
+import {
+ PageSection,
+ PageSectionContent,
+ PageSectionDescription,
+ PageSectionMeta,
+ PageSectionSummary,
+ PageSectionTitle,
+} from 'ui-patterns/PageSection'
export const TransferProjectPanel = () => {
const { data: project } = useSelectedProjectQuery()
@@ -11,30 +18,36 @@ export const TransferProjectPanel = () => {
if (project === undefined) return null
return (
- <section id="transfer-project">
- <FormHeader
- title="Transfer Project"
- description="Transfer your project to a different organization."
- />
- <Panel>
- <Panel.Content>
- <div className="flex flex-col @lg:flex-row @lg:justify-between @lg:items-center gap-4">
- <div className="flex space-x-4">
- <Truck className="mt-1" />
- <div className="space-y-1 xl:max-w-lg">
- <p className="text-sm">Transfer project to another organization</p>
- <p className="text-sm text-foreground-light">
- To transfer projects, the owner must be a member of both the source and target
- organizations.
- </p>
+ <PageSection id="transfer-project">
+ <PageSectionMeta>
+ <PageSectionSummary>
+ <PageSectionTitle>Transfer Project</PageSectionTitle>
+ <PageSectionDescription>
+ Transfer your project to a different organization.
+ </PageSectionDescription>
+ </PageSectionSummary>
+ </PageSectionMeta>
+ <PageSectionContent>
+ <Card>
+ <CardContent>
+ <div className="flex flex-col @lg:flex-row @lg:justify-between @lg:items-center gap-4">
+ <div className="flex space-x-4">
+ <Truck className="mt-1" />
+ <div className="space-y-1 xl:max-w-lg">
+ <p className="text-sm">Transfer project to another organization</p>
+ <p className="text-sm text-foreground-light">
+ To transfer projects, the owner must be a member of both the source and target
+ organizations.
+ </p>
+ </div>
+ </div>
+ <div>
+ <TransferProjectButton />
</div>
</div>
- <div>
- <TransferProjectButton />
- </div>
- </div>
- </Panel.Content>
- </Panel>
- </section>
+ </CardContent>
+ </Card>
+ </PageSectionContent>
+ </PageSection>
)
}
diff --git a/apps/studio/pages/project/[ref]/settings/general.tsx b/apps/studio/pages/project/[ref]/settings/general.tsx
index 2bcf27c0244..d99669a9f29 100644
--- a/apps/studio/pages/project/[ref]/settings/general.tsx
+++ b/apps/studio/pages/project/[ref]/settings/general.tsx
@@ -7,7 +7,6 @@ import { General } from 'components/interfaces/Settings/General/General'
import { TransferProjectPanel } from 'components/interfaces/Settings/General/TransferProjectPanel/TransferProjectPanel'
import DefaultLayout from 'components/layouts/DefaultLayout'
import SettingsLayout from 'components/layouts/ProjectSettingsLayout/SettingsLayout'
-import { ScaffoldContainer, ScaffoldHeader, ScaffoldTitle } from 'components/layouts/Scaffold'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
@@ -15,6 +14,14 @@ import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { useRouter } from 'next/router'
import { useEffect } from 'react'
import type { NextPageWithLayout } from 'types'
+import { PageContainer } from 'ui-patterns/PageContainer'
+import {
+ PageHeader,
+ PageHeaderDescription,
+ PageHeaderMeta,
+ PageHeaderSummary,
+ PageHeaderTitle,
+} from 'ui-patterns/PageHeader'
const ProjectSettings: NextPageWithLayout = () => {
const { data: project } = useSelectedProjectQuery()
@@ -36,12 +43,17 @@ const ProjectSettings: NextPageWithLayout = () => {
return (
<>
- <ScaffoldContainer>
- <ScaffoldHeader>
- <ScaffoldTitle>Project Settings</ScaffoldTitle>
- </ScaffoldHeader>
- </ScaffoldContainer>
- <ScaffoldContainer className="flex flex-col gap-10" bottomPadding>
+ <PageHeader size="small">
+ <PageHeaderMeta>
+ <PageHeaderSummary>
+ <PageHeaderTitle>Project Settings</PageHeaderTitle>
+ <PageHeaderDescription>
+ Configure general options, domains, transfers, and project lifecycle.
+ </PageHeaderDescription>
+ </PageHeaderSummary>
+ </PageHeaderMeta>
+ </PageHeader>
+ <PageContainer size="small">
<General />
{/* this is only settable on compliance orgs, currently that means HIPAA orgs */}
@@ -49,7 +61,7 @@ const ProjectSettings: NextPageWithLayout = () => {
{projectSettingsCustomDomains && <CustomDomainConfig />}
{!isBranch && projectTransferEnabled && <TransferProjectPanel />}
{!isBranch && <DeleteProjectPanel />}
- </ScaffoldContainer>
+ </PageContainer>
</>
)
}