Files
supabase/apps/studio/components/interfaces/Integrations/Webhooks/OverviewTab.tsx
Joshen Lim e48c909b31 Chore/deprecate use query state with select part 04 (#42747)
## Context

Related to FE-2461

More refactoring to clean up usage of `useQueryStateWithSelect`, in the
following pages
- Auth OAuth Apps
- Cron Jobs
- Vaults Secrets Management
- Database Hooks
- Wrappers

## To test

In each of those pages, verify that
- [ ] Clicking the "new" cta updates the URL params, and refreshing
should re-open the sheet
- [ ] Editing an existing item should update URL params, and refreshing
should re-open the sheet with the right item
- Verify that if the URL param has the wrong id, page should not open
the sheet, show a toast, and reset the URL param
- [ ] Deleting an existing item should update URL params, and refreshing
should re-open the sheet with the right item
- Verify that if the URL param has the wrong id, page should not open
the sheet, show a toast, and reset the URL param

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Added "item not found" toasts and clearer feedback after
create/update/delete actions; prevent opening create flows when server
features are disabled.

* **Style**
* Standardized button labels, sizes and modal/dialog spacing; refined
table column widths and inline code formatting for readability.

* **Refactor**
* Simplified UI state flows across OAuth Apps, Hooks/Webhooks, Cron
Jobs, Vault Secrets, and Wrappers to use consistent URL-driven
interactions and centralized modals.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-02-13 16:18:28 +08:00

96 lines
2.9 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { useParams } from 'common'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import NoPermission from 'components/ui/NoPermission'
import { useHooksEnableMutation } from 'data/database/hooks-enable-mutation'
import { useSchemasQuery } from 'data/database/schemas-query'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { toast } from 'sonner'
import { Admonition } from 'ui-patterns'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import { IntegrationOverviewTab } from '../Integration/IntegrationOverviewTab'
export const WebhooksOverviewTab = () => {
const { ref: projectRef } = useParams()
const { data: project } = useSelectedProjectQuery()
const {
data: schemas,
isSuccess: isSchemasLoaded,
refetch,
} = useSchemasQuery({
projectRef: project?.ref,
connectionString: project?.connectionString,
})
const isHooksEnabled = schemas?.some((schema) => schema.name === 'supabase_functions')
const { can: canReadWebhooks, isLoading: isLoadingPermissions } = useAsyncCheckPermissions(
PermissionAction.TENANT_SQL_ADMIN_READ,
'triggers'
)
const { mutate: enableHooks, isPending: isEnablingHooks } = useHooksEnableMutation({
onSuccess: async () => {
await refetch()
toast.success('Successfully enabled webhooks')
},
})
const enableHooksForProject = async () => {
if (!projectRef) return console.error('Project ref is required')
enableHooks({ ref: projectRef })
}
if (!isSchemasLoaded || isLoadingPermissions) {
return (
<div className="p-10">
<GenericSkeletonLoader />
</div>
)
}
if (!canReadWebhooks) {
return (
<div className="p-10">
<NoPermission isFullPage resourceText="view database webhooks" />
</div>
)
}
return (
<IntegrationOverviewTab
actions={
isSchemasLoaded && isHooksEnabled ? null : (
<Admonition
showIcon={false}
type="default"
title="Enable database webhooks on your project"
>
<p>
Database Webhooks can be used to trigger serverless functions or send requests to an
HTTP endpoint
</p>
<ButtonTooltip
className="mt-2 w-fit"
onClick={() => enableHooksForProject()}
disabled={isEnablingHooks}
tooltip={{
content: {
side: 'bottom',
text: !canReadWebhooks
? 'You need additional permissions to enable webhooks'
: undefined,
},
}}
>
Enable webhooks
</ButtonTooltip>
</Admonition>
)
}
/>
)
}