Skip to content

Commit

Permalink
Merge pull request stakwork#709 from saithsab877/feat-ticket-websocke…
Browse files Browse the repository at this point in the history
…t-metadata

Feature: Add Websocket Metadata Support for Ticket Operations
  • Loading branch information
humansinstitute authored Dec 5, 2024
2 parents 9ffb963 + 9902803 commit c5543c1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 23 deletions.
27 changes: 17 additions & 10 deletions src/components/common/TicketEditor/TicketEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,28 @@ const TicketEditor = ({ ticketData, websocketSessionId }: TicketEditorProps) =>
};

const handleUpdate = async () => {
const updateTicketData = {
...ticketData,
name,
description,
status: 'DRAFT' as TicketStatus,
version: ticketData.version + 1
};

try {
const response = await main.createUpdateTicket(updateTicketData);
const ticketPayload = {
metadata: {
source: 'websocket',
id: websocketSessionId
},
ticket: {
...ticketData,
name,
description,
status: 'DRAFT' as TicketStatus,
version: ticketData.version + 1
}
};

const response = await main.createUpdateTicket(ticketPayload);

if (response === 406 || !response) {
throw new Error('Failed to update ticket');
}
phaseTicketStore.updateTicket(ticketData.uuid, updateTicketData);

phaseTicketStore.updateTicket(ticketData.uuid, ticketPayload.ticket);
addUpdateSuccessToast();
} catch (error) {
console.error('Error updating ticket:', error);
Expand Down
10 changes: 9 additions & 1 deletion src/people/widgetViews/PhasePlannerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,16 @@ const PhasePlannerView: React.FC = () => {
version: 1
};

const ticketPayload = {
metadata: {
source: 'websocket',
id: websocketSessionId
},
ticket: initialTicketData
};

try {
await main.createUpdateTicket(initialTicketData);
await main.createUpdateTicket(ticketPayload);
phaseTicketStore.addTicket(initialTicketData as Ticket);
setTicketData((prevTickets: TicketData[]) => [
...prevTickets,
Expand Down
30 changes: 18 additions & 12 deletions src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3675,29 +3675,35 @@ export class MainStore {
}
}

async createUpdateTicket(initialTicketData: {
uuid: string;
feature_uuid: string;
phase_uuid: string;
name: string;
sequence: number;
dependency: string[];
description: string;
status: string;
version: number;
async createUpdateTicket(ticketPayload: {
metadata: {
source: string;
id: string;
};
ticket: {
uuid: string;
feature_uuid: string;
phase_uuid: string;
name: string;
sequence: number;
dependency: string[];
description: string;
status: string;
version: number;
};
}): Promise<any> {
try {
if (!uiStore.meInfo) return [];
const info = uiStore.meInfo;

const response = await fetch(`${TribesURL}/bounties/ticket/${initialTicketData.uuid}`, {
const response = await fetch(`${TribesURL}/bounties/ticket/${ticketPayload.ticket.uuid}`, {
method: 'POST',
mode: 'cors',
headers: {
'x-jwt': info.tribe_jwt,
'Content-Type': 'application/json'
},
body: JSON.stringify(initialTicketData)
body: JSON.stringify(ticketPayload)
});

if (!response.ok) {
Expand Down

0 comments on commit c5543c1

Please sign in to comment.