File tree Expand file tree Collapse file tree 1 file changed +29
-20
lines changed
Expand file tree Collapse file tree 1 file changed +29
-20
lines changed Original file line number Diff line number Diff line change @@ -252,36 +252,45 @@ const DynamicJsonForm = ({
252252 } , [ shouldUseJsonMode , isJsonMode ] ) ;
253253
254254 const handleCopyJson = useCallback ( ( ) => {
255- try {
256- navigator . clipboard
257- . writeText ( JSON . stringify ( value , null , 2 ) ?? "[]" )
258- . then ( ( ) => {
259- setCopiedJson ( true ) ;
255+ const copyToClipboard = async ( ) => {
256+ try {
257+ await navigator . clipboard . writeText (
258+ JSON . stringify ( value , null , 2 ) ?? "[]" ,
259+ ) ;
260+ setCopiedJson ( true ) ;
260261
261- toast ( {
262- title : "JSON copied" ,
263- description :
264- "The JSON data has been successfully copied to your clipboard." ,
265- } ) ;
262+ toast ( {
263+ title : "JSON copied" ,
264+ description :
265+ "The JSON data has been successfully copied to your clipboard." ,
266+ } ) ;
266267
267- setTimeout ( ( ) => {
268- setCopiedJson ( false ) ;
269- } , 2000 ) ;
270- } )
271- . catch ( ( error ) => {
272- reportError ( error ) ;
268+ setTimeout ( ( ) => {
269+ setCopiedJson ( false ) ;
270+ } , 2000 ) ;
271+ } catch ( error ) {
272+ toast ( {
273+ title : "Error" ,
274+ description : `Failed to copy JSON: ${ error instanceof Error ? error . message : String ( error ) } ` ,
275+ variant : "destructive" ,
273276 } ) ;
274- } catch ( error ) {
275- reportError ( error ) ;
276- }
277+ }
278+ } ;
279+
280+ copyToClipboard ( ) ;
277281 } , [ toast , value ] ) ;
278282
279283 return (
280284 < div className = "space-y-4" >
281285 < div className = "flex justify-end space-x-2" >
282286 { isJsonMode && (
283287 < >
284- < Button variant = "outline" size = "sm" onClick = { handleCopyJson } >
288+ < Button
289+ type = "button"
290+ variant = "outline"
291+ size = "sm"
292+ onClick = { handleCopyJson }
293+ >
285294 { copiedJson ? (
286295 < CheckCheck className = "h-4 w-4 mr-2" />
287296 ) : (
You can’t perform that action at this time.
0 commit comments