import { Button } from "@/src/components/ui/button"; import { api } from "@/src/utils/api"; import { useState } from "react"; import { Popover, PopoverContent, PopoverTrigger, } from "@/src/components/ui/popover"; import { Input } from "@/src/components/ui/input"; import { Label } from "@/src/components/ui/label"; import { RotateCcw } from "lucide-react"; import { toast } from "sonner"; export function RetryBackgroundMigration({ backgroundMigrationName, isRetryable, }: { backgroundMigrationName: string; isRetryable: boolean; }) { const utils = api.useUtils(); const [isOpen, setIsOpen] = useState(false); const [adminApiKey, setAdminApiKey] = useState(""); const [isLoading, setIsLoading] = useState(false); const mutRetryBackgroundMigration = api.backgroundMigrations.retry.useMutation({ onSuccess: () => { void utils.backgroundMigrations.invalidate(); toast.success("Migration scheduled for retry"); setIsOpen(false); setAdminApiKey(""); }, onError: (error) => { toast.error(error?.message || "Failed to retry migration"); }, onSettled: () => { setIsLoading(false); }, }); const handleRetry = async () => { if (!adminApiKey.trim()) { toast.error("Admin API key is required"); return; } setIsLoading(true); try { await mutRetryBackgroundMigration.mutateAsync({ name: backgroundMigrationName, adminApiKey: "Bearer " + adminApiKey.trim(), }); } catch (_e) { // Error handled in onError } }; return ( setIsOpen((prev) => !prev)}>

Retry Background Migration

This action schedules the migration for retry. Restart the worker containers to re-initiate the migration.

setAdminApiKey(e.target.value)} className="mt-1" disabled={isLoading} autoComplete="off" inputMode="text" name="admin-api-key" />

Required for security. This key must match your ADMIN_API_KEY environment variable{" ("} Docs {")."}

); }