diff --git a/apps/studio/src/features/editing-experience/components/AdminModeStateDrawer.tsx b/apps/studio/src/features/editing-experience/components/AdminModeStateDrawer.tsx index 21f43ae3c3..f285ef4f57 100644 --- a/apps/studio/src/features/editing-experience/components/AdminModeStateDrawer.tsx +++ b/apps/studio/src/features/editing-experience/components/AdminModeStateDrawer.tsx @@ -1,5 +1,12 @@ -import { useState } from "react" -import { Box, Heading, HStack, Icon, Spacer, Text } from "@chakra-ui/react" +import { + Box, + Heading, + HStack, + Icon, + Spacer, + Text, + useClipboard, +} from "@chakra-ui/react" import { Button, IconButton } from "@opengovsg/design-system-react" import { BiDollar, BiX } from "react-icons/bi" @@ -7,15 +14,9 @@ import { useEditorDrawerContext } from "~/contexts/EditorDrawerContext" export default function AdminModeStateDrawer(): JSX.Element { const { savedPageState, setDrawerState } = useEditorDrawerContext() - const [isCopiedToClipboard, setIsCopiedToClipboard] = useState(false) - - const handleCopy = async () => { - await navigator.clipboard.writeText(JSON.stringify(savedPageState, null, 2)) - setIsCopiedToClipboard(true) - setTimeout(() => { - setIsCopiedToClipboard(false) - }, 2000) - } + const { onCopy, hasCopied } = useClipboard( + JSON.stringify(savedPageState, null, 2), + ) return ( @@ -41,8 +42,8 @@ export default function AdminModeStateDrawer(): JSX.Element { - }