diff --git a/client/src/components/DynamicJsonForm.tsx b/client/src/components/DynamicJsonForm.tsx index 93cde052..70303aec 100644 --- a/client/src/components/DynamicJsonForm.tsx +++ b/client/src/components/DynamicJsonForm.tsx @@ -252,28 +252,32 @@ const DynamicJsonForm = ({ }, [shouldUseJsonMode, isJsonMode]); const handleCopyJson = useCallback(() => { - try { - navigator.clipboard - .writeText(JSON.stringify(value, null, 2) ?? "[]") - .then(() => { - setCopiedJson(true); + const copyToClipboard = async () => { + try { + await navigator.clipboard.writeText( + JSON.stringify(value, null, 2) ?? "[]", + ); + setCopiedJson(true); - toast({ - title: "JSON copied", - description: - "The JSON data has been successfully copied to your clipboard.", - }); - - setTimeout(() => { - setCopiedJson(false); - }, 2000); - }) - .catch((error) => { - reportError(error); + toast({ + title: "JSON copied", + description: + "The JSON data has been successfully copied to your clipboard.", }); - } catch (error) { - reportError(error); - } + + setTimeout(() => { + setCopiedJson(false); + }, 2000); + } catch (error) { + toast({ + title: "Error", + description: `Failed to copy JSON: ${error instanceof Error ? error.message : String(error)}`, + variant: "destructive", + }); + } + }; + + copyToClipboard(); }, [toast, value]); return ( @@ -281,7 +285,12 @@ const DynamicJsonForm = ({
{isJsonMode && ( <> -