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 = ({
252
252
} , [ shouldUseJsonMode , isJsonMode ] ) ;
253
253
254
254
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 ) ;
260
261
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
+ } ) ;
266
267
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" ,
273
276
} ) ;
274
- } catch ( error ) {
275
- reportError ( error ) ;
276
- }
277
+ }
278
+ } ;
279
+
280
+ copyToClipboard ( ) ;
277
281
} , [ toast , value ] ) ;
278
282
279
283
return (
280
284
< div className = "space-y-4" >
281
285
< div className = "flex justify-end space-x-2" >
282
286
{ isJsonMode && (
283
287
< >
284
- < Button variant = "outline" size = "sm" onClick = { handleCopyJson } >
288
+ < Button
289
+ type = "button"
290
+ variant = "outline"
291
+ size = "sm"
292
+ onClick = { handleCopyJson }
293
+ >
285
294
{ copiedJson ? (
286
295
< CheckCheck className = "h-4 w-4 mr-2" />
287
296
) : (
You can’t perform that action at this time.
0 commit comments