'use client'; import { useState, useTransition } from 'react'; import { Button } from '@/components/ui/button'; import { RefreshCw } from 'lucide-react'; import { triggerPolicySync } from '@/lib/actions/policySettings'; import { toast } from 'sonner'; export function SyncButton() { const [isPending, startTransition] = useTransition(); const [lastJobId, setLastJobId] = useState(null); const handleSync = () => { startTransition(async () => { try { const result = await triggerPolicySync(); if (result.success && result.jobId) { setLastJobId(result.jobId); toast.success(result.message ?? `Sync queued (Job #${result.jobId})`); } else { toast.error(result.error ?? 'Failed to trigger sync'); } } catch (error) { toast.error('An unexpected error occurred'); } }); }; return (
{lastJobId && ( Last job: #{lastJobId} )}
); }