fix: Copy JSON button form submission
This commit is contained in:
parent
b08aa68236
commit
9842a6278a
1 changed files with 29 additions and 20 deletions
|
|
@ -252,10 +252,11 @@ const DynamicJsonForm = ({
|
||||||
}, [shouldUseJsonMode, isJsonMode]);
|
}, [shouldUseJsonMode, isJsonMode]);
|
||||||
|
|
||||||
const handleCopyJson = useCallback(() => {
|
const handleCopyJson = useCallback(() => {
|
||||||
|
const copyToClipboard = async () => {
|
||||||
try {
|
try {
|
||||||
navigator.clipboard
|
await navigator.clipboard.writeText(
|
||||||
.writeText(JSON.stringify(value, null, 2) ?? "[]")
|
JSON.stringify(value, null, 2) ?? "[]",
|
||||||
.then(() => {
|
);
|
||||||
setCopiedJson(true);
|
setCopiedJson(true);
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
|
|
@ -267,13 +268,16 @@ const DynamicJsonForm = ({
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setCopiedJson(false);
|
setCopiedJson(false);
|
||||||
}, 2000);
|
}, 2000);
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
reportError(error);
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
reportError(error);
|
toast({
|
||||||
|
title: "Error",
|
||||||
|
description: `Failed to copy JSON: ${error instanceof Error ? error.message : String(error)}`,
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
copyToClipboard();
|
||||||
}, [toast, value]);
|
}, [toast, value]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
@ -281,7 +285,12 @@ const DynamicJsonForm = ({
|
||||||
<div className="flex justify-end space-x-2">
|
<div className="flex justify-end space-x-2">
|
||||||
{isJsonMode && (
|
{isJsonMode && (
|
||||||
<>
|
<>
|
||||||
<Button variant="outline" size="sm" onClick={handleCopyJson}>
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={handleCopyJson}
|
||||||
|
>
|
||||||
{copiedJson ? (
|
{copiedJson ? (
|
||||||
<CheckCheck className="h-4 w-4 mr-2" />
|
<CheckCheck className="h-4 w-4 mr-2" />
|
||||||
) : (
|
) : (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue