Skip to content

Commit a39b429

Browse files
authored
chore: audit log entitlement (supabase#40242)
* chore: audit log entitlement * Loading state * format
1 parent 3485cd4 commit a39b429

File tree

1 file changed

+11
-6
lines changed
  • apps/studio/components/interfaces/Organization/AuditLogs

1 file changed

+11
-6
lines changed

apps/studio/components/interfaces/Organization/AuditLogs/AuditLogs.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
Button,
3333
WarningIcon,
3434
} from 'ui'
35+
import { useCheckEntitlements } from 'hooks/misc/useCheckEntitlements'
3536

3637
const logsUpgradeError = 'upgrade to Team or Enterprise Plan to access audit logs.'
3738

@@ -64,6 +65,9 @@ export const AuditLogs = () => {
6465
'notifications'
6566
)
6667

68+
const { hasAccess: hasAccessToAuditLogs, isLoading: isLoadingEntitlements } =
69+
useCheckEntitlements('security.audit_logs_days')
70+
6771
const { data, error, isLoading, isSuccess, isError, isRefetching, refetch } =
6872
useOrganizationAuditLogsQuery(
6973
{
@@ -79,7 +83,8 @@ export const AuditLogs = () => {
7983
},
8084
}
8185
)
82-
const isLogsNotAvailableBasedOnPlan = isError && error.message.endsWith(logsUpgradeError)
86+
87+
const isLogsNotAvailableBasedOnPlan = isError && !hasAccessToAuditLogs
8388
const isRangeExceededError = isError && error.message.includes('range exceeded')
8489
const showFilters = !isLoading && !isLogsNotAvailableBasedOnPlan
8590

@@ -127,10 +132,10 @@ export const AuditLogs = () => {
127132
}
128133
})
129134

130-
// This feature depends on the subscription tier of the user. Free user can view logs up to 1 day
131-
// in the past. The API limits the logs to maximum of 1 day and 5 minutes so when the page is
135+
// This feature depends on the subscription tier of the user.
136+
// The API limits the logs to maximum of 62 days and 5 minutes so when the page is
132137
// viewed for more than 5 minutes, the call parameters needs to be updated. This also works with
133-
// higher tiers (7 days of logs).The user will see a loading shimmer.
138+
// higher tiers.The user will see a loading shimmer.
134139
useEffect(() => {
135140
const duration = dayjs(dateRange.from).diff(dayjs(dateRange.to))
136141
const interval = setInterval(() => {
@@ -160,7 +165,7 @@ export const AuditLogs = () => {
160165
</AlertTitle_Shadcn_>
161166
<AlertDescription_Shadcn_ className="flex flex-row justify-between gap-3">
162167
<p>
163-
Upgrade to Team or Enterprise to view up to 28 days of Audit Logs for your
168+
Upgrade to Team or Enterprise to view up to 62 days of Audit Logs for your
164169
organization.
165170
</p>
166171
</AlertDescription_Shadcn_>
@@ -261,7 +266,7 @@ export const AuditLogs = () => {
261266
</div>
262267
)}
263268

264-
{isLoading || isLoadingPermissions ? (
269+
{isLoading || isLoadingPermissions || isLoadingEntitlements ? (
265270
<div className="space-y-2">
266271
<ShimmeringLoader />
267272
<ShimmeringLoader className="w-3/4" />

0 commit comments

Comments
 (0)