diff --git a/src/people/widgetViews/PhasePlannerView.tsx b/src/people/widgetViews/PhasePlannerView.tsx index e6dc4440..884b560b 100644 --- a/src/people/widgetViews/PhasePlannerView.tsx +++ b/src/people/widgetViews/PhasePlannerView.tsx @@ -193,17 +193,18 @@ const PhasePlannerView: React.FC = observer(() => { const addTicketHandler = async () => { const newTicketUuid = uuidv4(); + const latestTickets = phaseTicketStore.organizeTicketsByGroup(tickets); const initialTicketData = { uuid: newTicketUuid, feature_uuid, phase_uuid, name: '', - sequence: tickets.length + 1, + sequence: latestTickets.length + 1, dependency: [], description: '', status: 'DRAFT' as TicketStatus, version: 1, - number: tickets.length + 1 + number: latestTickets.length + 1 }; const ticketPayload = { @@ -232,7 +233,10 @@ const PhasePlannerView: React.FC = observer(() => { return; } - const reorderedTickets = Array.from(tickets); + const latestTickets = phaseTicketStore + .organizeTicketsByGroup(tickets) + .sort((a: Ticket, b: Ticket) => a.sequence - b.sequence); + const reorderedTickets = Array.from(latestTickets); const [movedTicket] = reorderedTickets.splice(source.index, 1); reorderedTickets.splice(destination.index, 0, movedTicket); @@ -244,11 +248,7 @@ const PhasePlannerView: React.FC = observer(() => { await Promise.all( reorderedTickets.map((ticket: Ticket, index: number) => { const updatedTicket = { ...ticket, sequence: index + 1 }; - return main.createUpdateTicket({ - metadata: { - source: 'websocket', - id: websocketSessionId - }, + return main.updateTicketSequence({ ticket: updatedTicket }); }) @@ -288,6 +288,7 @@ const PhasePlannerView: React.FC = observer(() => { {phaseTicketStore .organizeTicketsByGroup(tickets) + .sort((a: Ticket, b: Ticket) => a.sequence - b.sequence) .map((ticket: Ticket, index: number) => ( { + try { + if (!uiStore.meInfo) return []; + const info = uiStore.meInfo; + + const response = await fetch( + `${TribesURL}/bounties/ticket/${ticketPayload.ticket.ticket_group}/sequence`, + { + method: 'POST', + mode: 'cors', + headers: { + 'x-jwt': info.tribe_jwt, + 'Content-Type': 'application/json' + }, + body: JSON.stringify(ticketPayload) + } + ); + + if (!response.ok) { + throw new Error('Failed to create ticket'); + } + + const data = await response.json(); + console.log('data', data); + return data; + } catch (e) { + console.log('Error creating ticket', e); + return 406; + } + } + async sendTicketForReview(payload: TicketPayload): Promise { try { if (!uiStore.meInfo) return null;