feat(ui): add toast feedback for sync actions

- Show success toast with synced profile count
- Show info toast when no profiles to sync
- Show error toast on sync failure
This commit is contained in:
kaitranntt
2026-01-28 11:57:22 -05:00
parent 68a63a7768
commit f972a4ee80
+15 -2
View File
@@ -3,6 +3,7 @@
*/ */
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { toast } from 'sonner';
/** Sync status response */ /** Sync status response */
export interface SyncStatus { export interface SyncStatus {
@@ -144,17 +145,29 @@ export function useSyncPreview() {
} }
/** /**
* Hook to execute sync * Hook to execute sync with toast feedback
*/ */
export function useExecuteSync() { export function useExecuteSync() {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
return useMutation({ return useMutation({
mutationFn: executeSync, mutationFn: executeSync,
onSuccess: () => { onSuccess: (data) => {
// Invalidate sync-related queries after successful sync // Invalidate sync-related queries after successful sync
queryClient.invalidateQueries({ queryKey: ['cliproxy-sync-status'] }); queryClient.invalidateQueries({ queryKey: ['cliproxy-sync-status'] });
queryClient.invalidateQueries({ queryKey: ['cliproxy-sync-preview'] }); queryClient.invalidateQueries({ queryKey: ['cliproxy-sync-preview'] });
// Show success toast with synced count
if (data.syncedCount === 0) {
toast.info('No profiles to sync');
} else {
toast.success(
`Synced ${data.syncedCount} profile${data.syncedCount === 1 ? '' : 's'} to CLIProxy`
);
}
},
onError: (error: Error) => {
toast.error(`Sync failed: ${error.message}`);
}, },
}); });
} }