Skip to content

Commit

Permalink
fix: fix fetch sprint error
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneMoroz committed Sep 27, 2024
1 parent 14d5f26 commit c2120b1
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export const getDashboardData = async (
.map((sprint) =>
fetchMeeting({
sprintNumber: sprint.number,
meetingId: sprint.teamMeetings[0]?.id,
meetingId: sprint.teamMeetings[0],
}),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import ErrorComponent from "@/components/Error";
function getMeeting(sprints: Sprint[], sprintNumber: number) {
const sprint = sprints.find((sprint) => sprint.number === sprintNumber);

if (sprint?.teamMeetings && sprint?.teamMeetings.length > 0)
return sprint.teamMeetings[0];
if (sprint?.teamMeetingsData && sprint?.teamMeetingsData.length > 0)
return sprint.teamMeetingsData[0];
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function ProgressStepper({

function handleClick(sprintNumber: number) {
const meetingId = sprints.find((sprint) => sprint.number === sprintNumber)!
.teamMeetings[0]?.id;
.teamMeetings[0];

if (meetingId) {
router.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export default async function RedirectToCurrentSprintWrapper({
const teamId = Number(params.teamId);

let currentSprintNumber: number;
let currentMeetingId: number;

const [user, error] = await getUser();

Expand Down Expand Up @@ -110,13 +109,11 @@ export default async function RedirectToCurrentSprintWrapper({
);
}
const { teamMeetings, number } = getCurrentSprint(res!.sprints) as Sprint;

currentSprintNumber = number;
currentMeetingId = teamMeetings[0]?.id;

if (currentMeetingId) {
redirect(
`/my-voyage/${teamId}/sprints/${currentSprintNumber}/meeting/${currentMeetingId}`,
);
if (teamMeetings.length !== 0) {
redirect(`/my-voyage/${teamId}/sprints/${currentSprintNumber}/meeting/4`);
} else {
redirect(`/my-voyage/${teamId}/sprints/${currentSprintNumber}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default async function SprintWrapper({ params }: SprintWrapperProps) {

const correspondingMeetingId = voyageData.sprints.find(
(sprint) => sprint.number === sprintNumber,
)?.teamMeetings[0]?.id;
)?.teamMeetings[0];

if (meetingId === correspondingMeetingId) {
const [res, error] = await fetchMeeting({ sprintNumber, meetingId });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,13 @@ export default function AgendaTopicForm() {

useEffect(() => {
if (sprintNumber && agendaId) {
const topic = sprints
.find((sprint) => sprint.number === sprintNumber)
?.teamMeetings[0].agendas?.find((topic) => topic.id === agendaId);
const sprint = sprints.find((sprint) => sprint.number === sprintNumber);

const topic =
sprint?.teamMeetingsData &&
sprint.teamMeetingsData[0].agendas?.find(
(topic) => topic.id === agendaId,
);

setTopicData(topic);
setEditMode(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@ export default function MeetingForm() {
useEffect(() => {
if (params.meetingId) {
const meeting = sprints.find(
(sprint) => sprint.teamMeetings[0]?.id === +params.meetingId,
)?.teamMeetings[0];
(sprint) =>
sprint.teamMeetingsData &&
sprint.teamMeetingsData[0].id === +params.meetingId,
);

setMeetingData(meeting as Meeting);
setEditMode(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ export default function Notes() {
} = useSprint();

useEffect(() => {
setData(sprints[sprintNumber - 1].teamMeetings[0].notes);
const sprint = sprints[sprintNumber - 1];
if (sprint.teamMeetingsData && sprint.teamMeetingsData.length) {
setData(sprint.teamMeetingsData[0].notes);
}
}, [sprints, sprintNumber]);

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ export default function Planning() {
} = useSprint();

useEffect(() => {
setData(
sprints[sprintNumber - 1].teamMeetings[0].formResponseMeeting?.find(
(form) => form.form.id === Number(Forms.planning),
),
);
const sprint = sprints[sprintNumber - 1];
if (sprint.teamMeetingsData && sprint.teamMeetingsData.length) {
setData(
sprint.teamMeetingsData[0].formResponseMeeting?.find(
(form) => form.form.id === Number(Forms.planning),
),
);
}
}, [sprints, sprintNumber]);

const goal = data?.responseGroup.responses.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,14 @@ export default function Review() {
} = useSprint();

useEffect(() => {
setData(
sprints[sprintNumber - 1].teamMeetings[0].formResponseMeeting?.find(
(form) => form.form.id === Number(Forms.review),
),
);
const sprint = sprints[sprintNumber - 1];
if (sprint.teamMeetingsData && sprint.teamMeetingsData.length) {
setData(
sprint.teamMeetingsData[0].formResponseMeeting?.find(
(form) => form.form.id === Number(Forms.review),
),
);
}
}, [sprints, sprintNumber]);

const what_right = data?.responseGroup.responses.find(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export interface SprintsResponse {
number: number;
startDate: string;
endDate: string;
teamMeetings: { id: number }[];
teamMeetings: number[];
}[];
}

Expand Down
12 changes: 4 additions & 8 deletions src/store/features/sprint/sprintSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export interface Sprint {
number: number;
startDate: string;
endDate: string;
teamMeetings: Meeting[];
teamMeetings: number[];
teamMeetingsData?: Meeting[];
}

export interface Voyage {
Expand Down Expand Up @@ -89,16 +90,11 @@ export const sprintSlice = createSlice({

const updatedSprints = state.voyage.sprints.map((sprint) => {
if (sprint.id === sprintId) {
const updatedMeetings = sprint.teamMeetings.map((meeting) => {
if (meeting.id === action.payload.id) {
return action.payload;
}
return meeting;
});
return { ...sprint, teamMeetings: updatedMeetings };
return { ...sprint, teamMeetingsData: [action.payload] };
}
return sprint;
});

state.voyage.sprints = updatedSprints;
state.loading = true;
},
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getCurrentSprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type Sprint } from "@/store/features/sprint/sprintSlice";

export const currentDate =
process.env.NODE_ENV === "development"
? new Date(2024, 5, 10, 12)
? new Date(2024, 5, 1, 12)
: new Date();

export function getCurrentSprint(sprints: Sprint[]) {
Expand Down

0 comments on commit c2120b1

Please sign in to comment.