From b89925c61c04b1c070e56124fe593d2c1fc345e0 Mon Sep 17 00:00:00 2001
From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com>
Date: Thu, 7 Mar 2024 02:01:23 +0100
Subject: [PATCH] Feat: Copy project slug button
---
.../ProjectNameChangeSection/CopyButton.tsx | 51 +++++++++++++++++++
1 file changed, 51 insertions(+)
create mode 100644 frontend/src/views/Settings/ProjectSettingsPage/components/ProjectNameChangeSection/CopyButton.tsx
diff --git a/frontend/src/views/Settings/ProjectSettingsPage/components/ProjectNameChangeSection/CopyButton.tsx b/frontend/src/views/Settings/ProjectSettingsPage/components/ProjectNameChangeSection/CopyButton.tsx
new file mode 100644
index 000000000..4add9df76
--- /dev/null
+++ b/frontend/src/views/Settings/ProjectSettingsPage/components/ProjectNameChangeSection/CopyButton.tsx
@@ -0,0 +1,51 @@
+import { useCallback } from "react";
+import { faCheck, faCopy } from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
+
+import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
+import { Button } from "@app/components/v2";
+import { useToggle } from "@app/hooks";
+
+type Props = {
+ value: string;
+ hoverText: string;
+ children: React.ReactNode;
+};
+
+export const CopyButton = ({ value, children, hoverText }: Props) => {
+ const [isProjectIdCopied, setIsProjectIdCopied] = useToggle(false);
+ const { createNotification } = useNotificationContext();
+
+ const copyToClipboard = useCallback(() => {
+ if (isProjectIdCopied) {
+ return;
+ }
+
+ setIsProjectIdCopied.on();
+ navigator.clipboard.writeText(value);
+
+ createNotification({
+ text: "Copied Project ID to clipboard",
+ type: "success"
+ });
+
+ const timer = setTimeout(() => setIsProjectIdCopied.off(), 2000);
+
+ // eslint-disable-next-line consistent-return
+ return () => clearTimeout(timer);
+ }, [isProjectIdCopied]);
+
+ return (
+ }
+ onClick={copyToClipboard}
+ >
+ {children}
+
+ {hoverText}
+
+
+ );
+};