diff --git a/src/components/common/TicketEditor/TicketEditor.tsx b/src/components/common/TicketEditor/TicketEditor.tsx index fc4a2133..511e0f37 100644 --- a/src/components/common/TicketEditor/TicketEditor.tsx +++ b/src/components/common/TicketEditor/TicketEditor.tsx @@ -12,6 +12,7 @@ import { } from '@elastic/eui'; import { renderMarkdown } from 'people/utils/RenderMarkdown.tsx'; import styled from 'styled-components'; +import history from 'config/history.ts'; import { phaseTicketStore } from '../../../store/phase'; import { ActionButton, @@ -92,6 +93,7 @@ const TicketEditor = observer( const [isCopying, setIsCopying] = useState(false); const [activeMode, setActiveMode] = useState<'preview' | 'edit'>('edit'); const { main } = useStores(); + const [isCreatingBounty, setIsCreatingBounty] = useState(false); const ui = uiStore; const groupTickets = useMemo( @@ -277,6 +279,43 @@ const TicketEditor = observer( setIsCopying(false); } }; + + const handleCreateBounty = async () => { + if (isCreatingBounty) return; + + setIsCreatingBounty(true); + try { + const data = await main.createBountyFromTicket(ticketData.uuid); + + if (data?.success) { + setToasts([ + { + id: `${Date.now()}-bounty-success`, + title: 'Bounty Created', + color: 'success', + text: 'Bounty created successfully!' + } + ]); + + history.push(`/bounty/${data.bounty_id}`); + } else { + throw new Error('Failed to create bounty'); + } + } catch (error) { + console.error('Error creating bounty:', error); + setToasts([ + { + id: `${Date.now()}-bounty-error`, + title: 'Error', + color: 'danger', + text: 'Failed to create bounty' + } + ]); + } finally { + setIsCreatingBounty(false); + } + }; + return ( @@ -372,6 +411,14 @@ const TicketEditor = observer( > Update + + {isCreatingBounty ? 'Creating Bounty...' : 'Create Bounty'} + {swwfLink && ( { + try { + const info = uiStore.meInfo; + if (!info) return null; + + const response = await fetch(`${TribesURL}/bounties/ticket/${ticketUuid}/bounty`, { + method: 'POST', + mode: 'cors', + headers: { + 'x-jwt': info.tribe_jwt, + 'Content-Type': 'application/json' + } + }); + + if (!response.ok) { + throw new Error('Failed to create bounty'); + } + + return response.json(); + } catch (error) { + console.error('Error creating bounty:', error); + return null; + } + } } export const mainStore = new MainStore();