diff --git a/src/components/common/TicketEditor/TicketEditor.tsx b/src/components/common/TicketEditor/TicketEditor.tsx index c5b9701e..8555c8b6 100644 --- a/src/components/common/TicketEditor/TicketEditor.tsx +++ b/src/components/common/TicketEditor/TicketEditor.tsx @@ -1,8 +1,8 @@ import React, { useState } from 'react'; import { useStores } from 'store'; import { ActionButton, TicketButtonGroup } from '../../../people/widgetViews/workspace/style'; - import { TicketContainer, TicketHeader, TicketTextArea } from '../../../pages/tickets/style'; +import { TicketStatus } from '../../../store/interface'; interface TicketEditorProps { ticketData: { @@ -32,19 +32,35 @@ const TicketEditor = ({ ticketData }: TicketEditorProps) => { sequence: ticketData.sequence, dependency: [], description: description, - status: 'DRAFT', + status: 'DRAFT' as TicketStatus, version: ticketData.version + 1 }; try { await main.createUpdateTicket(updateTicketData); } catch (error) { - console.error('Error registering ticket:', error); + console.error('Error updating ticket:', error); } }; - const handleTicketBuilder = () => { - console.log('Ticket Builder clicked'); + const handleTicketBuilder = async () => { + try { + const ticketForReview = { + ...ticketData, + description: description || ticketData.description, + status: 'DRAFT' as TicketStatus + }; + + const response = await main.sendTicketForReview(ticketForReview); + + if (response) { + console.log('Ticket sent for review successfully'); + } else { + throw new Error('Failed to send ticket for review'); + } + } catch (error) { + console.error('Error in ticket builder:', error); + } }; return ( diff --git a/src/store/main.ts b/src/store/main.ts index a4ad401a..5a0f3238 100644 --- a/src/store/main.ts +++ b/src/store/main.ts @@ -45,7 +45,8 @@ import { CreateFeatureInput, FeatureStory, UpdateFeatureStoryInput, - CreateFeatureStoryInput + CreateFeatureStoryInput, + TicketStatus } from './interface'; function makeTorSaveURL(host: string, key: string) { @@ -3690,6 +3691,45 @@ export class MainStore { } } + async sendTicketForReview(ticket: { + uuid: string; + feature_uuid: string; + phase_uuid: string; + name: string; + sequence: number; + dependency: string[]; + description: string; + status: TicketStatus; + version: number; + }): Promise { + try { + if (!uiStore.meInfo) return null; + const info = uiStore.meInfo; + + const response = await fetch(`${TribesURL}/bounty/ticket/review/send`, { + method: 'POST', + mode: 'cors', + headers: { + 'x-jwt': info.tribe_jwt, + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + ticket + }) + }); + + if (!response.ok) { + throw new Error('Failed to send ticket for review'); + } + + const data = await response.json(); + return data; + } catch (error) { + console.error('Error sending ticket for review:', error); + return null; + } + } + async createConnectionCodes(users_number: number): Promise { try { if (!uiStore.meInfo) return 406;