Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added getPhaseTickets to dependency #688

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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