'use client'; import { useState } from 'react'; import { api } from '~/trpc/react'; export function ResyncButton() { const [isResyncing, setIsResyncing] = useState(false); const [lastSync, setLastSync] = useState(null); const [syncMessage, setSyncMessage] = useState(null); const resyncMutation = api.scripts.resyncScripts.useMutation({ onSuccess: (data) => { setIsResyncing(false); setLastSync(new Date()); if (data.success) { setSyncMessage(data.message ?? 'Scripts synced successfully'); // Reload the page after successful sync setTimeout(() => { window.location.reload(); }, 2000); // Wait 2 seconds to show the success message } else { setSyncMessage(data.error ?? 'Failed to sync scripts'); // Clear message after 3 seconds for errors setTimeout(() => setSyncMessage(null), 3000); } }, onError: (error) => { setIsResyncing(false); setSyncMessage(`Error: ${error.message}`); setTimeout(() => setSyncMessage(null), 3000); }, }); const handleResync = async () => { setIsResyncing(true); setSyncMessage(null); resyncMutation.mutate(); }; return (
Sync scripts with ProxmoxVE repo
{lastSync && (
Last sync: {lastSync.toLocaleTimeString()}
)}
{syncMessage && (
{syncMessage}
)}
); }