From 9842a6278a71c9f5515bd24584b3a43b67be3a97 Mon Sep 17 00:00:00 2001 From: Francisco Veiras <74626997+francisco-svg761@users.noreply.github.com> Date: Sun, 6 Jul 2025 12:08:20 -0300 Subject: [PATCH] fix: Copy JSON button form submission --- client/src/components/DynamicJsonForm.tsx | 51 +++++++++++++---------- 1 file changed, 30 insertions(+), 21 deletions(-) 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 && ( <> -