-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: refresh button also for non-admin user (#1045)
Co-authored-by: Damian Orzepowski <[email protected]>
- Loading branch information
1 parent
5820f58
commit 23c0cd4
Showing
4 changed files
with
44 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import { useState } from 'react'; | ||
import { toast } from 'sonner'; | ||
import logger from '@/logger'; | ||
import { RefreshCw } from 'lucide-react'; | ||
import { cn } from '@/lib/utils.ts'; | ||
import { Button } from '@/components'; | ||
|
||
export const PageRefreshButton = () => { | ||
const queryClient = useQueryClient(); | ||
const [isRefreshing, setIsRefreshing] = useState(false); | ||
|
||
const onRefreshClick = async () => { | ||
setIsRefreshing(true); | ||
try { | ||
// Wait for all queries invalidation (data refetching) | ||
// and a minimum delay of 0.5sec before proceeding to make sure the UI doesn't flicker | ||
await Promise.all([queryClient.invalidateQueries(), new Promise((resolve) => setTimeout(resolve, 500))]); | ||
toast.success('Data refreshed'); | ||
} catch { | ||
logger.error('Failed to refresh'); | ||
toast.error('Failed to refresh'); | ||
} finally { | ||
setIsRefreshing(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<Button variant="ghost" className="ml-auto" disabled={isRefreshing} onClick={onRefreshClick}> | ||
<RefreshCw className={cn('h-4 w-4 mr-2', isRefreshing && 'animate-spin')} /> | ||
Refresh | ||
</Button> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './PageRefreshButton.tsx'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters