mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-20 22:20:03 +00:00
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:
@@ -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}`);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user