scheduled.tsx133 lines · main
| 1 | import { PermissionAction } from '@supabase/shared-types/out/constants' |
| 2 | import { useParams } from 'common' |
| 3 | import { Info } from 'lucide-react' |
| 4 | import { Admonition } from 'ui-patterns' |
| 5 | import { PageContainer } from 'ui-patterns/PageContainer' |
| 6 | import { |
| 7 | PageHeader, |
| 8 | PageHeaderMeta, |
| 9 | PageHeaderNavigationTabs, |
| 10 | PageHeaderSummary, |
| 11 | PageHeaderTitle, |
| 12 | } from 'ui-patterns/PageHeader' |
| 13 | import { PageSection, PageSectionContent } from 'ui-patterns/PageSection' |
| 14 | import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader' |
| 15 | |
| 16 | import { BackupsList } from '@/components/interfaces/Database/Backups/BackupsList' |
| 17 | import DatabaseBackupsNav from '@/components/interfaces/Database/Backups/DatabaseBackupsNav' |
| 18 | import DatabaseLayout from '@/components/layouts/DatabaseLayout/DatabaseLayout' |
| 19 | import DefaultLayout from '@/components/layouts/DefaultLayout' |
| 20 | import AlertError from '@/components/ui/AlertError' |
| 21 | import { DocsButton } from '@/components/ui/DocsButton' |
| 22 | import InformationBox from '@/components/ui/InformationBox' |
| 23 | import NoPermission from '@/components/ui/NoPermission' |
| 24 | import { useBackupsQuery } from '@/data/database/backups-query' |
| 25 | import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions' |
| 26 | import { useIsOrioleDbInAws } from '@/hooks/misc/useSelectedProject' |
| 27 | import { DOCS_URL } from '@/lib/constants' |
| 28 | import type { NextPageWithLayout } from '@/types' |
| 29 | |
| 30 | const DatabaseScheduledBackups: NextPageWithLayout = () => { |
| 31 | const { ref: projectRef } = useParams() |
| 32 | |
| 33 | const { |
| 34 | data: backups, |
| 35 | error, |
| 36 | isPending: isLoading, |
| 37 | isError, |
| 38 | isSuccess, |
| 39 | } = useBackupsQuery({ projectRef }) |
| 40 | |
| 41 | const isOrioleDbInAws = useIsOrioleDbInAws() |
| 42 | const isPitrEnabled = backups?.pitr_enabled |
| 43 | |
| 44 | const { can: canReadScheduledBackups, isSuccess: isPermissionsLoaded } = useAsyncCheckPermissions( |
| 45 | PermissionAction.READ, |
| 46 | 'back_ups' |
| 47 | ) |
| 48 | |
| 49 | return ( |
| 50 | <> |
| 51 | <PageHeader> |
| 52 | <PageHeaderMeta> |
| 53 | <PageHeaderSummary> |
| 54 | <PageHeaderTitle>Database Backups</PageHeaderTitle> |
| 55 | </PageHeaderSummary> |
| 56 | </PageHeaderMeta> |
| 57 | <PageHeaderNavigationTabs> |
| 58 | <DatabaseBackupsNav active="scheduled" /> |
| 59 | </PageHeaderNavigationTabs> |
| 60 | </PageHeader> |
| 61 | <PageContainer> |
| 62 | <PageSection> |
| 63 | <PageSectionContent> |
| 64 | {isOrioleDbInAws ? ( |
| 65 | <Admonition |
| 66 | type="default" |
| 67 | title="Database backups are not available for OrioleDB" |
| 68 | description="OrioleDB is currently in public alpha and projects created are strictly ephemeral with no database backups" |
| 69 | > |
| 70 | <DocsButton abbrev={false} className="mt-2" href={`${DOCS_URL}`} /> |
| 71 | </Admonition> |
| 72 | ) : ( |
| 73 | <div className="flex flex-col gap-y-4"> |
| 74 | {isLoading && <GenericSkeletonLoader />} |
| 75 | |
| 76 | {isError && ( |
| 77 | <AlertError error={error} subject="Failed to retrieve scheduled backups" /> |
| 78 | )} |
| 79 | |
| 80 | {isSuccess && ( |
| 81 | <> |
| 82 | {!isPitrEnabled && ( |
| 83 | <p className="text-sm text-foreground-light"> |
| 84 | Projects are backed up daily around midnight of your project’s region and |
| 85 | can be restored at any time. |
| 86 | </p> |
| 87 | )} |
| 88 | |
| 89 | {isPitrEnabled && ( |
| 90 | <InformationBox |
| 91 | hideCollapse |
| 92 | defaultVisibility |
| 93 | icon={<Info strokeWidth={2} />} |
| 94 | title="Point-In-Time-Recovery (PITR) enabled" |
| 95 | description={ |
| 96 | <div> |
| 97 | Your project uses PITR and full daily backups are no longer taken. PITR |
| 98 | lets you restore to a specific time (down to the second) within your |
| 99 | selected PITR retention period.{' '} |
| 100 | <a |
| 101 | className="text-brand transition-colors hover:text-brand-600" |
| 102 | href={`${DOCS_URL}/guides/platform/backups`} |
| 103 | > |
| 104 | Learn more |
| 105 | </a> |
| 106 | </div> |
| 107 | } |
| 108 | /> |
| 109 | )} |
| 110 | |
| 111 | {isPermissionsLoaded && !canReadScheduledBackups ? ( |
| 112 | <NoPermission resourceText="view scheduled backups" /> |
| 113 | ) : ( |
| 114 | <BackupsList /> |
| 115 | )} |
| 116 | </> |
| 117 | )} |
| 118 | </div> |
| 119 | )} |
| 120 | </PageSectionContent> |
| 121 | </PageSection> |
| 122 | </PageContainer> |
| 123 | </> |
| 124 | ) |
| 125 | } |
| 126 | |
| 127 | DatabaseScheduledBackups.getLayout = (page) => ( |
| 128 | <DefaultLayout> |
| 129 | <DatabaseLayout title="Backups">{page}</DatabaseLayout> |
| 130 | </DefaultLayout> |
| 131 | ) |
| 132 | |
| 133 | export default DatabaseScheduledBackups |