Skip to content

Commit

Permalink
Merge pull request #688 from stakwork/fix/get_tickets_by_phase_uuid
Browse files Browse the repository at this point in the history
fix: added getPhaseTickets to dependency
  • Loading branch information
tobi-bams authored Dec 2, 2024
2 parents 159cc9e + 8149874 commit 39ef5ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/people/widgetViews/PhasePlannerView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,34 @@ const PhasePlannerView: React.FC = () => {
return data;
}, [feature_uuid, phase_uuid, main]);

const getPhaseTickets = useCallback(async () => {
if (!feature_uuid || !phase_uuid) return;
const data = await main.getTicketDataByPhase(feature_uuid, phase_uuid);

return data;
}, [feature_uuid, phase_uuid, main]);

useEffect(() => {
const fetchData = async () => {
try {
const feature = await getFeatureData();
const phase = await getPhaseData();
const phaseTickets = await getPhaseTickets();

if (!feature || !phase) {
if (!feature || !phase || !Array.isArray(phaseTickets)) {
history.push('/');
} else {
const parsedTicketData: TicketData[] = [];
for (let i = 0; i < phaseTickets.length; i++) {
const ticket = phaseTickets[i];
if (ticket.UUID) {
ticket.uuid = ticket.UUID;
}
parsedTicketData.push({ ...ticket });
}
setFeatureData(feature);
setPhaseData(phase);
setTicketData(parsedTicketData);
}
} catch (error) {
console.error('Error fetching data:', error);
Expand All @@ -81,7 +98,7 @@ const PhasePlannerView: React.FC = () => {
};

fetchData();
}, [getFeatureData, getPhaseData, history]);
}, [getFeatureData, getPhaseData, history, getPhaseTickets]);

const handleClose = () => {
history.push(`/feature/${feature_uuid}`);
Expand Down
24 changes: 24 additions & 0 deletions src/store/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3598,6 +3598,30 @@ export class MainStore {
}
}

async getTicketDataByPhase(feature_uuid: string, phase_uuid: string): Promise<Phase | undefined> {
try {
if (!uiStore.meInfo) return undefined;
const info = uiStore.meInfo;

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

return r.json();
} catch (e) {
console.error('getFeaturePhaseByUUID', e);
return undefined;
}
}

async createOrUpdatePhase(phase: Phase): Promise<any> {
try {
if (!uiStore.meInfo) return [];
Expand Down

0 comments on commit 39ef5ad

Please sign in to comment.