Skip to content

Commit

Permalink
Merge pull request stakwork#675 from Shoaibdev7/ticket-builder-review…
Browse files Browse the repository at this point in the history
…-endpoint

onClick of "Ticket Builder" post data to bounty/ticket/review/send
  • Loading branch information
humansinstitute authored Nov 29, 2024
2 parents 471cb72 + b4e72b9 commit b88e6ff
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 6 deletions.
26 changes: 21 additions & 5 deletions src/components/common/TicketEditor/TicketEditor.tsx
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down Expand Up @@ -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 (
Expand Down
42 changes: 41 additions & 1 deletion src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import {
CreateFeatureInput,
FeatureStory,
UpdateFeatureStoryInput,
CreateFeatureStoryInput
CreateFeatureStoryInput,
TicketStatus
} from './interface';

function makeTorSaveURL(host: string, key: string) {
Expand Down Expand Up @@ -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<any> {
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<number> {
try {
if (!uiStore.meInfo) return 406;
Expand Down

0 comments on commit b88e6ff

Please sign in to comment.