@@ -7,33 +7,42 @@ import { useCallback, useState } from 'react'
77import { Tooltip } from './Tooltip'
88import { useSuccessTooltip } from './useSuccessTooltip'
99
10- import { Button } from '@/app/_components'
10+ import { Alert , Button } from '@/app/_components'
1111
1212interface Props {
1313 text : string
1414}
1515
1616export const CopyToClipboardButton : FC < Props > = ( { text } ) => {
1717 const [ isLoading , setIsLoading ] = useState ( false )
18+ const [ error , setError ] = useState < string | null > ( null )
1819 const [ showTooltip , setShowTooltip ] = useSuccessTooltip ( )
1920
2021 const handleClick = useCallback ( ( ) => {
22+ setError ( null )
2123 setIsLoading ( true )
2224 navigator . clipboard
2325 . writeText ( text )
24- . then ( ( ) => setShowTooltip ( true ) )
25- . catch ( ( _e ) => {
26- /* エラー処理 */
26+ . then ( ( ) => {
27+ setShowTooltip ( true )
28+ setIsLoading ( false )
29+ } )
30+ . catch ( ( e ) => {
31+ console . error ( 'Failed to copy to clipboard' , e )
32+ setError ( 'Failed to copy to clipboard. Please check your browser permissions.' )
33+ setIsLoading ( false )
2734 } )
28- setIsLoading ( false )
2935 } , [ text , setShowTooltip ] )
3036
3137 return (
32- < span className = "relative" >
33- < Tooltip show = { showTooltip } />
34- < Button isLoading = { isLoading } onClick = { handleClick } variant = "secondary" >
35- Copy to Clipboard
36- </ Button >
37- </ span >
38+ < div className = "space-y-2" >
39+ { error && < Alert > { error } </ Alert > }
40+ < span className = "relative" >
41+ < Tooltip show = { showTooltip } />
42+ < Button isLoading = { isLoading } onClick = { handleClick } variant = "secondary" >
43+ Copy to Clipboard
44+ </ Button >
45+ </ span >
46+ </ div >
3847 )
3948}
0 commit comments