import { useNavigate } from '@tanstack/react-router' import { useParams } from 'common' import { AlertTriangleIcon } from 'lucide-react' import { useState } from 'react' import { toast } from 'sonner' import { Button } from 'ui' import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal' import { useProjectDetailQuery, useSetProjectStatus } from '@/data/projects/project-detail-query' import { useProjectRestartMutation } from '@/data/projects/project-restart-mutation' import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { PROJECT_STATUS } from '@/lib/constants' export const UnhealthyState = () => { const navigate = useNavigate() const { ref } = useParams() const { data: project } = useSelectedProjectQuery() const { setProjectStatus } = useSetProjectStatus() const [showConfirm, setShowConfirm] = useState(false) const { can: canRestartProject } = useAsyncCheckPermissionsV2( FGA_PERMISSIONS.PROJECT.OPERATIONS_WRITE ) useProjectDetailQuery( { ref }, { // Poll until the project recovers, which will dismiss this guard automatically refetchInterval: (query) => { const data = query.state.data return data?.status === PROJECT_STATUS.ACTIVE_UNHEALTHY ? 4000 : false }, } ) const { mutate: restartProject, isPending: isRestarting } = useProjectRestartMutation({ onSuccess: () => { setProjectStatus({ ref: project?.ref ?? '', status: PROJECT_STATUS.RESTARTING }) toast.success('Restarting project...') if (ref) void navigate({ to: '/project/$ref', params: { ref } }) }, onError: (error) => { toast.error(`Failed to restart project: ${error.message}`) }, }) return ( <>
Project {project?.name} is unhealthy
Your project is experiencing health issues and is not fully operational. Restarting the project will attempt to restore normal operation.