Skip to content

Commit

Permalink
Merge pull request stakwork#681 from aliraza556/ticket-editor-load-ex…
Browse files Browse the repository at this point in the history
…isting-data

🔄 Ticket Editor: Load & Display Existing Ticket Data on Refresh
  • Loading branch information
humansinstitute authored Dec 2, 2024
2 parents d6d6f36 + 8ca45ab commit ca4f605
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/common/TicketEditor/TicketEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { useStores } from 'store';
import { ActionButton, TicketButtonGroup } from '../../../people/widgetViews/workspace/style';
import { TicketContainer, TicketHeader, TicketTextArea } from '../../../pages/tickets/style';
Expand All @@ -23,6 +23,21 @@ const TicketEditor = ({ ticketData }: TicketEditorProps) => {
const [description, setDescription] = useState('');
const { main } = useStores();

useEffect(() => {
const fetchTicketDetails = async () => {
try {
const ticket = await main.getTicketDetails(ticketData.uuid);
if (ticket) {
setDescription(ticket.description || '');
}
} catch (error) {
console.error('Error fetching ticket details:', error);
}
};

fetchTicketDetails();
}, [ticketData.uuid, main]);

const handleUpdate = async () => {
const updateTicketData = {
uuid: ticketData.uuid,
Expand Down
26 changes: 26 additions & 0 deletions src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3727,6 +3727,32 @@ export class MainStore {
}
}

async getTicketDetails(uuid: string): Promise<any> {
try {
if (!uiStore.meInfo) return null;
const info = uiStore.meInfo;

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

if (!response.ok) {
throw new Error('Failed to fetch ticket details');
}

const data = await response.json();
return data;
} catch (error) {
console.error('Error fetching ticket details:', error);
return null;
}
}

async createConnectionCodes(users_number: number): Promise<number> {
try {
if (!uiStore.meInfo) return 406;
Expand Down

0 comments on commit ca4f605

Please sign in to comment.