Repository: supabase/supabase
File: apps/studio/components/interfaces/Database/Triggers/TriggerSheet.tsx (TypeScript)

Code before:
  enabled_mode: 'ORIGIN',
  events: [],
}

interface TriggerSheetProps {
  selectedTrigger?: PostgresTrigger
  isDuplicatingTrigger?: boolean
  open: boolean
  onClose: () => void
}

export const TriggerSheet = ({
  selectedTrigger,
  isDuplicatingTrigger,
  open,
  onClose,
}: TriggerSheetProps) => {
  const { data: project } = useSelectedProjectQuery()

  const [isClosingPanel, setIsClosingPanel] = useState(false)
  const [showFunctionSelector, setShowFunctionSelector] = useState(false)

  const { mutate: createDatabaseTrigger, isLoading: isCreating } = useDatabaseTriggerCreateMutation(
    {
      onSuccess: (res) => {
        toast.success(`Successfully created trigger ${res.name}`)
        onClose()
      },
      onError: (error) => {
        toast.error(`Failed to create trigger: ${error.message}`)
      },
    }
  )
  const { mutate: updateDatabaseTrigger, isLoading: isUpdating } = useDatabaseTriggerUpdateMutation(
    {
      onSuccess: (res) => {
        toast.success(`Successfully updated trigger ${res.name}`)
        onClose()
      },
      onError: (error) => {
        toast.error(`Failed to update trigger: ${error.message}`)
      },
    }
  )

  const { data = [], isSuccess: isSuccessTables } = useTablesQuery({
    projectRef: project?.ref,
    connectionString: project?.connectionString,
  })
  const { data: protectedSchemas, isSuccess: isSuccessProtectedSchemas } = useProtectedSchemas()
  const isSuccess = isSuccessTables && isSuccessProtectedSchemas

Review comment (suggestion):
Not part of this PR I know, but discovered in testing that this always turns up as "Successfully created trigger undefined"

Code after:
  enabled_mode: 'ORIGIN',
  events: [],
}

interface TriggerSheetProps {
  selectedTrigger?: PostgresTrigger
  isDuplicatingTrigger?: boolean
  open: boolean
  onClose: () => void
}

export const TriggerSheet = ({
  selectedTrigger,
  isDuplicatingTrigger,
  open,
  onClose,
}: TriggerSheetProps) => {
  const { data: project } = useSelectedProjectQuery()

  const [isClosingPanel, setIsClosingPanel] = useState(false)
  const [showFunctionSelector, setShowFunctionSelector] = useState(false)

  const { mutate: createDatabaseTrigger, isLoading: isCreating } = useDatabaseTriggerCreateMutation(
    {
      onSuccess: () => {
        toast.success(`Successfully created trigger`)
        onClose()
      },
      onError: (error) => {
        toast.error(`Failed to create trigger: ${error.message}`)
      },
    }
  )
  const { mutate: updateDatabaseTrigger, isLoading: isUpdating } = useDatabaseTriggerUpdateMutation(
    {
      onSuccess: () => {
        toast.success(`Successfully updated trigger`)
        onClose()
      },
      onError: (error) => {
        toast.error(`Failed to update trigger: ${error.message}`)
      },
    }
  )

  const { data = [], isSuccess: isSuccessTables } = useTablesQuery({
    projectRef: project?.ref,
    connectionString: project?.connectionString,
  })
  const { data: protectedSchemas, isSuccess: isSuccessProtectedSchemas } = useProtectedSchemas()
  const isSuccess = isSuccessTables && isSuccessProtectedSchemas