Skip to content

Commit

Permalink
Merge branch 'dev' into feature/tech-stack-functionality-p2
Browse files Browse the repository at this point in the history
  • Loading branch information
MattRueter committed Jun 26, 2024
2 parents 758b276 + b08b52d commit 523657b
Show file tree
Hide file tree
Showing 21 changed files with 337 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/app/(auth)/authService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ async function asyncSignIn(
);

if (!res.ok) {
throw new Error(res.statusText);
throw new Error(`Status code: ${res.status}, Message: ${res.statusText}`);
}

const accessToken = res.headers.getSetCookie()[0].split("access_token=")[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import VoyageSupport from "@/app/(main)/dashboard/components/shared/VoyageSuppor
import EmptySprintProvider from "@/app/(main)/my-voyage/[teamId]/sprints/providers/EmptySprintProvider";
import { getUser } from "@/utils/getUser";
import type { Sprint, Voyage } from "@/store/features/sprint/sprintSlice";
import { type ErrorType } from "@/utils/error";
import ErrorComponent from "@/components/Error";

interface VoyageDashboardProps {
teamId?: string;
Expand All @@ -37,6 +39,8 @@ async function VoyageDashboard({ teamId }: VoyageDashboardProps) {
let meetingsData: EventList[] = [];
let voyageNumber: number | null = null;
let voyageData: Voyage = {} as Voyage;
let errorMessage: string | undefined;
let errorType: ErrorType | undefined;

if (teamId !== undefined) {
const data = await getDashboardData(user, error, Number(teamId));
Expand All @@ -45,6 +49,12 @@ async function VoyageDashboard({ teamId }: VoyageDashboardProps) {
meetingsData = data.meetingsData;
voyageNumber = data.voyageNumber;
voyageData = data.voyageData;
errorMessage = data.errorMessage;
errorType = data.errorType;
}

if (errorMessage && errorType) {
return <ErrorComponent errorType={errorType} message={errorMessage} />;
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { User } from "@/store/features/user/userSlice";
import { fetchMeeting } from "@/app/(main)/my-voyage/[teamId]/sprints/components/SprintWrapper";
import type { AppError } from "@/types/types";
import convertStringToDate from "@/utils/convertStringToDate";
import { ErrorType } from "@/utils/error";

interface GetDashboardDataResponse {
currentSprintNumber: number | null;
Expand All @@ -16,6 +17,7 @@ interface GetDashboardDataResponse {
voyageNumber: number | null;
voyageData: Voyage;
errorMessage?: string;
errorType?: ErrorType;
}

export type EventList = {
Expand All @@ -33,6 +35,8 @@ export const getDashboardData = async (
let sprintsData: Sprint[] = [];
let voyageNumber: number | null = null;
let voyageData: Voyage = {} as Voyage;
let errorMessage: string | undefined;
let errorType: ErrorType | undefined;

const { errorResponse, data } = await getCurrentVoyageData({
user,
Expand All @@ -51,14 +55,24 @@ export const getDashboardData = async (
voyageNumber: null,
voyageData: {} as Voyage,
errorMessage: errorResponse,
errorType: ErrorType.FETCH_VOYAGE_DATA,
};
}

if (data) {
const [res, error] = data;

if (error) {
throw new Error(`Error: ${error.message}`);
return {
currentSprintNumber: null,
sprintsData: [],
user: null,
meetingsData: [],
voyageNumber: null,
voyageData: {} as Voyage,
errorMessage: error.message,
errorType: ErrorType.FETCH_SPRINT,
};
}

sprintsData = res!.sprints;
Expand All @@ -79,16 +93,18 @@ export const getDashboardData = async (
sprint: number;
}[] = [];

const fetchMeetingsPromises = sprintsData.map((sprint) =>
fetchMeeting({
sprintNumber: sprint.number,
meetingId: sprint.teamMeetings[0]?.id,
}),
);
const fetchMeetingsPromises = sprintsData
.filter((sprint) => sprint.teamMeetings.length)
.map((sprint) =>
fetchMeeting({
sprintNumber: sprint.number,
meetingId: sprint.teamMeetings[0]?.id,
}),
);

const fetchMeetingsResults = await Promise.all(fetchMeetingsPromises);

fetchMeetingsResults.forEach(([res]) => {
fetchMeetingsResults.forEach(([res, error]) => {
if (res) {
const { title, dateTime, meetingLink, sprint } = res;
const parsedDate = convertStringToDate(dateTime, user?.timezone ?? "");
Expand All @@ -100,7 +116,8 @@ export const getDashboardData = async (
sprint: sprint.number,
});
} else if (error) {
return `Error: ${error.message}`;
errorMessage = error.message;
errorType = ErrorType.FETCH_MEETING;
}
});

Expand All @@ -111,5 +128,7 @@ export const getDashboardData = async (
meetingsData,
voyageNumber,
voyageData,
errorType,
errorMessage,
};
};
23 changes: 23 additions & 0 deletions src/app/(main)/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use client";

import { useEffect } from "react";
import ErrorComponent from "@/components/Error";

export default function Error({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
useEffect(() => {
// Log the error to an error reporting service
}, [error]);

return (
<ErrorComponent
message="Something went wrong. Please contact support"
reset={reset}
/>
);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { redirect } from "next/navigation";

import DirectoryProvider from "./DirectoryProvider";
import TeamMember from "./TeamMember";
import { type TeamDirectory } from "@/store/features/directory/directorySlice";

import Banner from "@/components/banner/Banner";
import ErrorComponent from "@/components/Error";

import { type TeamDirectory } from "@/store/features/directory/directorySlice";

import { getAccessToken } from "@/utils/getCookie";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { GET } from "@/utils/requests";
Expand All @@ -12,6 +17,7 @@ import { getUser } from "@/utils/getUser";
import { getTimezone } from "@/utils/getTimezone";
import VoyagePageBannerContainer from "@/components/banner/VoyagePageBannerContainer";
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import { ErrorType } from "@/utils/error";

interface FetchTeamDirectoryProps {
teamId: number;
Expand Down Expand Up @@ -86,14 +92,24 @@ export default async function DirectoryComponentWrapper({
});

if (errorResponse) {
return errorResponse;
return (
<ErrorComponent
errorType={ErrorType.FETCH_VOYAGE_DATA}
message={errorResponse}
/>
);
}

if (data) {
const [res, error] = data;

if (error) {
return `Error: ${error.message}`;
return (
<ErrorComponent
errorType={ErrorType.FETCH_TEAM_DIRECTORY}
message={error.message}
/>
);
}

teamDirectory = res!;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import { redirect } from "next/navigation";

import FeaturesProvider from "./FeaturesProvider";
import FeaturesContainer from "./FeaturesContainer";
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import { getUser } from "@/utils/getUser";
import { getAccessToken } from "@/utils/getCookie";
import VoyagePageBannerContainer from "@/components/banner/VoyagePageBannerContainer";
import Banner from "@/components/banner/Banner";
import ErrorComponent from "@/components/Error";

import {
type Features,
type FeaturesList,
} from "@/store/features/features/featuresSlice";

import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import { getUser } from "@/utils/getUser";
import { getAccessToken } from "@/utils/getCookie";
import { GET } from "@/utils/requests";
import { CacheTag } from "@/utils/cacheTag";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import VoyagePageBannerContainer from "@/components/banner/VoyagePageBannerContainer";
import Banner from "@/components/banner/Banner";
import { ErrorType } from "@/utils/error";

function transformData(features: Features[]): FeaturesList[] {
const transformedData: FeaturesList[] = [
Expand Down Expand Up @@ -117,14 +122,24 @@ export default async function FeaturesComponentWrapper({
});

if (errorResponse) {
return errorResponse;
return (
<ErrorComponent
errorType={ErrorType.FETCH_VOYAGE_DATA}
message={errorResponse}
/>
);
}

if (data) {
const [res, error] = data;

if (error) {
return `Error: ${error.message}`;
return (
<ErrorComponent
errorType={ErrorType.FETCH_FEATURES}
message={error.message}
/>
);
}

features = res!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import VoteCard from "./VoteCard";
import { type FetchIdeationsProps } from "@/app/(main)/my-voyage/[teamId]/ideation/ideationService";
import Banner from "@/components/banner/Banner";
import VoyagePageBannerContainer from "@/components/banner/VoyagePageBannerContainer";
import ErrorComponent from "@/components/Error";

import { type IdeationData } from "@/store/features/ideation/ideationSlice";
import { CacheTag } from "@/utils/cacheTag";
import { getAccessToken } from "@/utils/getCookie";
Expand All @@ -16,6 +18,7 @@ import { getUser } from "@/utils/getUser";
import { handleAsync, type AsyncActionResponse } from "@/utils/handleAsync";
import { GET } from "@/utils/requests";
import routePaths from "@/utils/routePaths";
import { ErrorType } from "@/utils/error";

// import { ideation } from "./fixtures/ideation";

Expand Down Expand Up @@ -62,14 +65,24 @@ export default async function IdeationComponentWrapper({
});

if (errorResponse) {
return errorResponse;
return (
<ErrorComponent
errorType={ErrorType.FETCH_VOYAGE_DATA}
message={errorResponse}
/>
);
}

if (data) {
const [res, error] = data;

if (error) {
return `Error: ${error.message}`;
return (
<ErrorComponent
errorType={ErrorType.FETCH_IDEATIONS}
message={error.message}
/>
);
}

projectIdeas = res!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
getSprintCheckinIsStatus,
getVoyageProjectStatus,
} from "@/utils/getFormStatus";
import { ErrorType } from "@/utils/error";
import ErrorComponent from "@/components/Error";

function getMeeting(sprints: Sprint[], sprintNumber: number) {
const sprint = sprints.find((sprint) => sprint.number === sprintNumber);
Expand Down Expand Up @@ -52,14 +54,24 @@ export default async function EmptySprintWrapper({
});

if (errorResponse) {
return errorResponse;
return (
<ErrorComponent
errorType={ErrorType.FETCH_VOYAGE_DATA}
message={errorResponse}
/>
);
}

if (data) {
const [res, error] = data;

if (error) {
return `Error: ${error.message}`;
return (
<ErrorComponent
errorType={ErrorType.FETCH_SPRINT}
message={error.message}
/>
);
}
voyageData = res!;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { type Sprint } from "@/store/features/sprint/sprintSlice";
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import routePaths from "@/utils/routePaths";
import { ErrorType } from "@/utils/error";
import ErrorComponent from "@/components/Error";

export async function fetchSprints({
teamId,
Expand Down Expand Up @@ -56,14 +58,24 @@ export default async function RedirectToCurrentSprintWrapper({
});

if (errorResponse) {
return errorResponse;
return (
<ErrorComponent
errorType={ErrorType.FETCH_VOYAGE_DATA}
message={errorResponse}
/>
);
}

if (data) {
const [res, error] = data;

if (error) {
return `Error: ${error.message}`;
return (
<ErrorComponent
errorType={ErrorType.FETCH_SPRINT}
message={error.message}
/>
);
}
const { teamMeetings, number } = getCurrentSprint(res!.sprints) as Sprint;
currentSprintNumber = number;
Expand Down
Loading

0 comments on commit 523657b

Please sign in to comment.