import { useParams } from 'common' import { Database, Storage } from 'icons' import { ChevronDown, Download, ExternalLink } from 'lucide-react' import { useEffect, useState } from 'react' import { toast } from 'sonner' import { Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, } from 'ui' import { Admonition, TimestampInfo } from 'ui-patterns' import { DropdownMenuItemTooltip } from '@/components/ui/DropdownMenuItemTooltip' import { InlineLink } from '@/components/ui/InlineLink' import { useBackupDownloadMutation } from '@/data/database/backup-download-mutation' import { useProjectPauseStatusQuery } from '@/data/projects/project-pause-status-query' import { useStorageArchiveCreateMutation } from '@/data/storage/storage-archive-create-mutation' import { useStorageArchiveQuery } from '@/data/storage/storage-archive-query' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { DOCS_URL, PROJECT_STATUS } from '@/lib/constants' export const PauseDisabledState = () => { const { ref } = useParams() const { data: project } = useSelectedProjectQuery() const [toastId, setToastId] = useState() const [refetchInterval, setRefetchInterval] = useState(false) const dbVersion = project?.dbVersion?.replace('briven-postgres-', '') const { data: pauseStatus } = useProjectPauseStatusQuery( { ref }, { enabled: project?.status === PROJECT_STATUS.INACTIVE } ) const latestBackup = pauseStatus?.latest_downloadable_backup_id const { data: storageArchive, isSuccess: isStorageArchiveSuccess } = useStorageArchiveQuery( { projectRef: ref }, { refetchInterval, refetchOnWindowFocus: false, } ) useEffect(() => { if (!isStorageArchiveSuccess) return if (storageArchive.fileUrl && refetchInterval !== false) { toast.success('Downloading storage objects', { id: toastId }) setToastId(undefined) setRefetchInterval(false) downloadStorageArchive(storageArchive.fileUrl) } }, [isStorageArchiveSuccess, storageArchive, refetchInterval]) const storageArchiveUrl = storageArchive?.fileUrl const { mutate: downloadBackup } = useBackupDownloadMutation({ onSuccess: (res) => { const { fileUrl } = res // Trigger browser download by create,trigger and remove tempLink const tempLink = document.createElement('a') tempLink.href = fileUrl document.body.appendChild(tempLink) tempLink.click() document.body.removeChild(tempLink) }, }) const { mutate: createStorageArchive } = useStorageArchiveCreateMutation({ onSuccess: () => { const toastId = toast.loading( 'Retrieving storage archive. This may take a few minutes depending on the size of your storage objects.' ) setToastId(toastId) setRefetchInterval(5000) }, }) const onSelectDownloadBackup = () => { if (ref === undefined) return console.error('Project ref is required') if (!latestBackup) return toast.error('No backups available for download') const toastId = toast.loading('Fetching database backup') downloadBackup( { ref, backup: { id: latestBackup, }, }, { onSuccess: () => { toast.success('Downloading database backup', { id: toastId }) }, } ) } const downloadStorageArchive = (url: string) => { const tempLink = document.createElement('a') tempLink.href = url document.body.appendChild(tempLink) tempLink.click() document.body.removeChild(tempLink) } const onSelectDownloadStorageArchive = () => { if (!storageArchiveUrl) { createStorageArchive({ projectRef: ref }) } else { toast.success('Downloading storage objects') downloadStorageArchive(storageArchiveUrl) } } return ( <>

This project has been paused for over{' '} {pauseStatus?.max_days_till_restore_disabled ?? 90} days {' '} and cannot be restored through the dashboard. However, your data remains intact and can be downloaded as a backup.

{!!pauseStatus?.last_paused_on && (

Project last paused on{' '}

)}

Recovery options:

  • Restore the backup to a new Briven project
  • Restore the backup on your local machine

Export your data

Download backups for your database and storage objects

onSelectDownloadBackup()} tooltip={{ content: { side: 'right', text: 'No backups available, please reach out via support for assistance', }, }} > Database backup (PG: {dbVersion}) onSelectDownloadStorageArchive()}> Storage objects {/* [Joshen] Once storage object download is supported, can just use the below component */} {/* onSelectDownloadStorageArchive()}> Download storage objects */}
) }