import { PermissionAction } from '@supabase/shared-types/out/constants' import { useEffect } from 'react' import { toast } from 'sonner' import { object, string } from 'yup' import { useParams } from 'common' import { FormActions } from 'components/ui/Forms/FormActions' import { FormHeader } from 'components/ui/Forms/FormHeader' import { FormPanel } from 'components/ui/Forms/FormPanel' import { FormSection, FormSectionContent } from 'components/ui/Forms/FormSection' import { useAuthConfigQuery } from 'data/auth/auth-config-query' import { useAuthConfigUpdateMutation } from 'data/auth/auth-config-update-mutation' import { useCheckPermissions } from 'hooks/misc/useCheckPermissions' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Form, Input } from 'ui' import { AlertCircle } from 'lucide-react' const schema = object({ SITE_URL: string().required('Must have a Site URL'), }) const SiteUrl = () => { const { ref: projectRef } = useParams() const { data: authConfig, error: authConfigError, isLoading, isError, isSuccess, } = useAuthConfigQuery({ projectRef }) const { mutate: updateAuthConfig, isLoading: isUpdatingConfig } = useAuthConfigUpdateMutation() const formId = 'auth-config-general-form' const canUpdateConfig = useCheckPermissions(PermissionAction.UPDATE, 'custom_config_gotrue') const INITIAL_VALUES = { SITE_URL: authConfig?.SITE_URL } const onSubmit = (values: any, { resetForm }: any) => { const payload = { ...values } updateAuthConfig( { projectRef: projectRef!, config: payload }, { onError: () => { toast.error('Failed to update settings') }, onSuccess: () => { toast.success('Successfully updated settings') resetForm({ values: values, initialValues: values }) }, } ) } if (isError) { return ( Failed to retrieve auth configuration {authConfigError.message} ) } return (
{({ handleReset, resetForm, values, initialValues }: any) => { const hasChanges = JSON.stringify(values) !== JSON.stringify(initialValues) // Form is reset once remote data is loaded in store // eslint-disable-next-line react-hooks/rules-of-hooks useEffect(() => { if (isSuccess) { resetForm({ values: INITIAL_VALUES, initialValues: INITIAL_VALUES }) } }, [isSuccess]) return ( <> } > ) }} ) } export default SiteUrl