From f9b588c4542c04c1a8a43d0d1facaadba738d586 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Wed, 18 Dec 2024 16:58:38 +0500 Subject: [PATCH] feat(TicketEditor): Enhance Copy Button functionality --- .../common/TicketEditor/TicketEditor.tsx | 44 ++++++++++++++++++- src/people/widgetViews/workspace/style.ts | 26 +++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/components/common/TicketEditor/TicketEditor.tsx b/src/components/common/TicketEditor/TicketEditor.tsx index ed69d39c..40563fda 100644 --- a/src/components/common/TicketEditor/TicketEditor.tsx +++ b/src/components/common/TicketEditor/TicketEditor.tsx @@ -10,7 +10,11 @@ import { EuiBadge } from '@elastic/eui'; import { phaseTicketStore } from '../../../store/phase'; -import { ActionButton, TicketButtonGroup } from '../../../people/widgetViews/workspace/style'; +import { + ActionButton, + CopyButtonGroup, + TicketButtonGroup +} from '../../../people/widgetViews/workspace/style'; import { TicketContainer, TicketHeader, @@ -49,6 +53,7 @@ const TicketEditor = observer( ); const [selectedVersion, setSelectedVersion] = useState(latestTicket?.version as number); const [versionTicketData, setVersionTicketData] = useState(latestTicket as Ticket); + const [isCopying, setIsCopying] = useState(false); const { main } = useStores(); const groupTickets = useMemo( @@ -207,6 +212,33 @@ const TicketEditor = observer( } } }; + const handleCopy = async () => { + if (isCopying) return; + + setIsCopying(true); + try { + await navigator.clipboard.writeText(versionTicketData.description); + setToasts([ + { + id: `${Date.now()}-copy-success`, + title: 'Hive', + color: 'success', + text: 'Description copied to clipboard!' + } + ]); + } catch (err) { + setToasts([ + { + id: `${Date.now()}-copy-error`, + title: 'Hive', + color: 'danger', + text: 'Failed to copy description' + } + ]); + } finally { + setIsCopying(false); + } + }; return ( @@ -238,6 +270,16 @@ const TicketEditor = observer( Version {selectedVersion} + + + Copy + +