From 8aa077f4b88b2ae4943e8994853d082e90442be0 Mon Sep 17 00:00:00 2001 From: Dan Ko Date: Tue, 1 Oct 2024 01:28:07 -0400 Subject: [PATCH] refactor types --- src/app/(auth)/AuthProvider.tsx | 2 +- src/app/(auth)/authService.ts | 2 +- .../components/voyage-dashboard/getDashboardData.ts | 3 ++- .../directory/components/DirectoryComponentWrapper.tsx | 2 +- .../my-voyage/[teamId]/directory/directoryService.ts | 2 +- .../features/components/FeaturesComponentWrapper.tsx | 2 +- .../(main)/my-voyage/[teamId]/features/featuresService.ts | 2 +- .../my-voyage/[teamId]/ideation/adapters/ideationSA.ts | 2 +- .../ideation/components/IdeationComponentWrapper.tsx | 2 +- .../sprints/components/RedirectToCurrentSprintWrapper.tsx | 2 +- .../[teamId]/sprints/components/SprintWrapper.tsx | 2 +- .../[teamId]/sprints/components/WeeklyCheckInWrapper.tsx | 2 +- .../(main)/my-voyage/[teamId]/sprints/sprintsService.ts | 2 +- .../my-voyage/[teamId]/tech-stack/techStackService.ts | 2 +- .../[teamId]/voyage-resources/resourcesService.ts | 2 +- src/hooks/useServerAction.ts | 2 +- src/modules/shared/types.ts | 6 ------ src/store/features/modal/modalSlice.ts | 2 +- src/types/types.ts | 3 +++ src/utils/getCurrentVoyageData.ts | 3 ++- src/utils/getCurrentVoyageTeam.ts | 2 +- src/utils/getUser.ts | 2 +- src/utils/handleAsync.ts | 8 ++++---- 23 files changed, 29 insertions(+), 30 deletions(-) delete mode 100644 src/modules/shared/types.ts diff --git a/src/app/(auth)/AuthProvider.tsx b/src/app/(auth)/AuthProvider.tsx index e34395fd1..f5b51f2a2 100644 --- a/src/app/(auth)/AuthProvider.tsx +++ b/src/app/(auth)/AuthProvider.tsx @@ -5,7 +5,7 @@ import { formatInTimeZone } from "date-fns-tz"; import { clientSignIn, clientSignOut } from "@/store/features/auth/authSlice"; import { useAppDispatch } from "@/store/hooks"; import { type User, getUserState } from "@/store/features/user/userSlice"; -import { type AppError } from "@/modules/shared/types"; +import { type AppError } from "@/types/types"; import { currentDate } from "@/utils/getCurrentSprint"; interface AuthProviderProps { diff --git a/src/app/(auth)/authService.ts b/src/app/(auth)/authService.ts index d5d12121f..24df5341b 100644 --- a/src/app/(auth)/authService.ts +++ b/src/app/(auth)/authService.ts @@ -2,7 +2,7 @@ import { cookies } from "next/headers"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { getAccessToken, getRefreshToken } from "@/utils/getCookie"; import { POST, UNAUTHPOST } from "@/utils/requests"; diff --git a/src/app/(main)/dashboard/components/voyage-dashboard/getDashboardData.ts b/src/app/(main)/dashboard/components/voyage-dashboard/getDashboardData.ts index 30f0cfdab..ecbe3e859 100644 --- a/src/app/(main)/dashboard/components/voyage-dashboard/getDashboardData.ts +++ b/src/app/(main)/dashboard/components/voyage-dashboard/getDashboardData.ts @@ -2,7 +2,8 @@ import { fetchSprints } from "@/myVoyage/sprints/components/RedirectToCurrentSpr import { fetchMeeting } from "@/myVoyage/sprints/components/SprintWrapper"; import type { User } from "@/store/features/user/userSlice"; import type { Sprint, Voyage } from "@/store/features/sprint/sprintSlice"; -import type { AppError, AsyncActionResponse } from "@/modules/shared/types"; +import { type AppError } from "@/types/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { getCurrentSprint } from "@/utils/getCurrentSprint"; import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData"; import { fetchResources } from "@/app/(main)/my-voyage/[teamId]/voyage-resources/components/ResourcesComponentWrapper"; diff --git a/src/app/(main)/my-voyage/[teamId]/directory/components/DirectoryComponentWrapper.tsx b/src/app/(main)/my-voyage/[teamId]/directory/components/DirectoryComponentWrapper.tsx index a83604e55..0139b856d 100644 --- a/src/app/(main)/my-voyage/[teamId]/directory/components/DirectoryComponentWrapper.tsx +++ b/src/app/(main)/my-voyage/[teamId]/directory/components/DirectoryComponentWrapper.tsx @@ -10,7 +10,7 @@ import { type TeamDirectory } from "@/store/features/directory/directorySlice"; import { getAccessToken } from "@/utils/getCookie"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { GET } from "@/utils/requests"; import { CacheTag } from "@/utils/cacheTag"; import { type User } from "@/store/features/user/userSlice"; diff --git a/src/app/(main)/my-voyage/[teamId]/directory/directoryService.ts b/src/app/(main)/my-voyage/[teamId]/directory/directoryService.ts index 1910d21cb..eaf9dc43d 100644 --- a/src/app/(main)/my-voyage/[teamId]/directory/directoryService.ts +++ b/src/app/(main)/my-voyage/[teamId]/directory/directoryService.ts @@ -3,7 +3,7 @@ import { revalidateTag } from "next/cache"; import { getAccessToken } from "@/utils/getCookie"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { PATCH } from "@/utils/requests"; import { CacheTag } from "@/utils/cacheTag"; diff --git a/src/app/(main)/my-voyage/[teamId]/features/components/FeaturesComponentWrapper.tsx b/src/app/(main)/my-voyage/[teamId]/features/components/FeaturesComponentWrapper.tsx index 10a6212d5..ca81309b8 100644 --- a/src/app/(main)/my-voyage/[teamId]/features/components/FeaturesComponentWrapper.tsx +++ b/src/app/(main)/my-voyage/[teamId]/features/components/FeaturesComponentWrapper.tsx @@ -17,7 +17,7 @@ import { getAccessToken } from "@/utils/getCookie"; import { GET } from "@/utils/requests"; import { CacheTag } from "@/utils/cacheTag"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { ErrorType } from "@/utils/error"; function transformData(features: Features[]): FeaturesList[] { diff --git a/src/app/(main)/my-voyage/[teamId]/features/featuresService.ts b/src/app/(main)/my-voyage/[teamId]/features/featuresService.ts index 47361c620..3597c1b47 100644 --- a/src/app/(main)/my-voyage/[teamId]/features/featuresService.ts +++ b/src/app/(main)/my-voyage/[teamId]/features/featuresService.ts @@ -5,7 +5,7 @@ import { type Features } from "@/store/features/features/featuresSlice"; import { CacheTag } from "@/utils/cacheTag"; import { getAccessToken } from "@/utils/getCookie"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { DELETE, PATCH, POST } from "@/utils/requests"; interface SaveOrderProps { diff --git a/src/app/(main)/my-voyage/[teamId]/ideation/adapters/ideationSA.ts b/src/app/(main)/my-voyage/[teamId]/ideation/adapters/ideationSA.ts index 008f3e20d..9ff0741f4 100644 --- a/src/app/(main)/my-voyage/[teamId]/ideation/adapters/ideationSA.ts +++ b/src/app/(main)/my-voyage/[teamId]/ideation/adapters/ideationSA.ts @@ -5,7 +5,7 @@ import { IdeationClientAdapter } from "./ideationClientAdapter"; import { getAccessToken } from "@/utils/getCookie"; import { DELETE, PATCH, POST } from "@/utils/requests"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { CacheTag } from "@/utils/cacheTag"; import { type AddIdeationResponseDto } from "@/modules/ideation/application/dtos/response.dto"; import { type AddIdeationUsecaseDto } from "@/modules/ideation/application/dtos/addIdeationUsecaseDto"; diff --git a/src/app/(main)/my-voyage/[teamId]/ideation/components/IdeationComponentWrapper.tsx b/src/app/(main)/my-voyage/[teamId]/ideation/components/IdeationComponentWrapper.tsx index 413d1f779..277dd5b65 100644 --- a/src/app/(main)/my-voyage/[teamId]/ideation/components/IdeationComponentWrapper.tsx +++ b/src/app/(main)/my-voyage/[teamId]/ideation/components/IdeationComponentWrapper.tsx @@ -16,7 +16,7 @@ import { getAccessToken } from "@/utils/getCookie"; import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData"; import { getUser } from "@/utils/getUser"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { GET } from "@/utils/requests"; import routePaths from "@/utils/routePaths"; import { ErrorType } from "@/utils/error"; diff --git a/src/app/(main)/my-voyage/[teamId]/sprints/components/RedirectToCurrentSprintWrapper.tsx b/src/app/(main)/my-voyage/[teamId]/sprints/components/RedirectToCurrentSprintWrapper.tsx index 7357515ab..96a6acab9 100644 --- a/src/app/(main)/my-voyage/[teamId]/sprints/components/RedirectToCurrentSprintWrapper.tsx +++ b/src/app/(main)/my-voyage/[teamId]/sprints/components/RedirectToCurrentSprintWrapper.tsx @@ -17,7 +17,7 @@ import { getCurrentSprint } from "@/utils/getCurrentSprint"; import { GET } from "@/utils/requests"; import { CacheTag } from "@/utils/cacheTag"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { type Sprint } from "@/store/features/sprint/sprintSlice"; import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData"; import routePaths from "@/utils/routePaths"; diff --git a/src/app/(main)/my-voyage/[teamId]/sprints/components/SprintWrapper.tsx b/src/app/(main)/my-voyage/[teamId]/sprints/components/SprintWrapper.tsx index 6923111ac..f22bfe474 100644 --- a/src/app/(main)/my-voyage/[teamId]/sprints/components/SprintWrapper.tsx +++ b/src/app/(main)/my-voyage/[teamId]/sprints/components/SprintWrapper.tsx @@ -26,7 +26,7 @@ import { import { getCurrentSprint } from "@/utils/getCurrentSprint"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { GET } from "@/utils/requests"; import { getAccessToken } from "@/utils/getCookie"; import { getUser } from "@/utils/getUser"; diff --git a/src/app/(main)/my-voyage/[teamId]/sprints/components/WeeklyCheckInWrapper.tsx b/src/app/(main)/my-voyage/[teamId]/sprints/components/WeeklyCheckInWrapper.tsx index 0367de0a7..2e30a26fe 100644 --- a/src/app/(main)/my-voyage/[teamId]/sprints/components/WeeklyCheckInWrapper.tsx +++ b/src/app/(main)/my-voyage/[teamId]/sprints/components/WeeklyCheckInWrapper.tsx @@ -10,7 +10,7 @@ import { getUser } from "@/utils/getUser"; import { GET } from "@/utils/requests"; import { CacheTag } from "@/utils/cacheTag"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData"; import routePaths from "@/utils/routePaths"; import { Forms } from "@/utils/form/formsEnums"; diff --git a/src/app/(main)/my-voyage/[teamId]/sprints/sprintsService.ts b/src/app/(main)/my-voyage/[teamId]/sprints/sprintsService.ts index 0d4b5a3a6..275d8e9aa 100644 --- a/src/app/(main)/my-voyage/[teamId]/sprints/sprintsService.ts +++ b/src/app/(main)/my-voyage/[teamId]/sprints/sprintsService.ts @@ -4,7 +4,7 @@ import { revalidateTag } from "next/cache"; import { getAccessToken } from "@/utils/getCookie"; import { DELETE, PATCH, POST } from "@/utils/requests"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { CacheTag } from "@/utils/cacheTag"; import { getSprintCache } from "@/utils/getSprintCache"; diff --git a/src/app/(main)/my-voyage/[teamId]/tech-stack/techStackService.ts b/src/app/(main)/my-voyage/[teamId]/tech-stack/techStackService.ts index 63d2924e6..9f8963d42 100644 --- a/src/app/(main)/my-voyage/[teamId]/tech-stack/techStackService.ts +++ b/src/app/(main)/my-voyage/[teamId]/tech-stack/techStackService.ts @@ -5,7 +5,7 @@ import type { Category } from "./finalize/types"; import { CacheTag } from "@/utils/cacheTag"; import { getAccessToken } from "@/utils/getCookie"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { DELETE, PATCH, POST } from "@/utils/requests"; import { type TechStackItem } from "@/store/features/techStack/techStackSlice"; diff --git a/src/app/(main)/my-voyage/[teamId]/voyage-resources/resourcesService.ts b/src/app/(main)/my-voyage/[teamId]/voyage-resources/resourcesService.ts index 2bce5661a..6b7aa428b 100644 --- a/src/app/(main)/my-voyage/[teamId]/voyage-resources/resourcesService.ts +++ b/src/app/(main)/my-voyage/[teamId]/voyage-resources/resourcesService.ts @@ -4,7 +4,7 @@ import { revalidateTag } from "next/cache"; import { getAccessToken } from "@/utils/getCookie"; import { POST, DELETE } from "@/utils/requests"; import { handleAsync } from "@/utils/handleAsync"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { CacheTag } from "@/utils/cacheTag"; interface ResourceProps { diff --git a/src/hooks/useServerAction.ts b/src/hooks/useServerAction.ts index 71fd5ddba..0427b8c9e 100644 --- a/src/hooks/useServerAction.ts +++ b/src/hooks/useServerAction.ts @@ -1,7 +1,7 @@ "use client"; import { useCallback, useState } from "react"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; type ActionType = (arg: X) => Promise>; diff --git a/src/modules/shared/types.ts b/src/modules/shared/types.ts deleted file mode 100644 index 587476253..000000000 --- a/src/modules/shared/types.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface AppError { - message: string; -} - -export type AsyncFunction = () => Promise; -export type AsyncActionResponse = [X | null, AppError | null]; diff --git a/src/store/features/modal/modalSlice.ts b/src/store/features/modal/modalSlice.ts index 65c4fbd8a..282efceaf 100644 --- a/src/store/features/modal/modalSlice.ts +++ b/src/store/features/modal/modalSlice.ts @@ -14,7 +14,7 @@ import { type DeleteFeatureProps, type deleteFeature, } from "@/myVoyage/features/featuresService"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { type DeleteAgendaTopicProps, type DeleteAgendaTopicResponse, diff --git a/src/types/types.ts b/src/types/types.ts index 077b0ae33..cf150593d 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -1 +1,4 @@ // only put global types here +export interface AppError { + message: string; +} diff --git a/src/utils/getCurrentVoyageData.ts b/src/utils/getCurrentVoyageData.ts index 02de6ee3c..c70a2a77a 100644 --- a/src/utils/getCurrentVoyageData.ts +++ b/src/utils/getCurrentVoyageData.ts @@ -1,5 +1,6 @@ import { getCurrentVoyageTeam } from "./getCurrentVoyageTeam"; -import type { AsyncActionResponse, AppError } from "@/modules/shared/types"; +import { type AppError } from "@/types/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { type User } from "@/store/features/user/userSlice"; interface GetCurrentVoyageDataProps { diff --git a/src/utils/getCurrentVoyageTeam.ts b/src/utils/getCurrentVoyageTeam.ts index 466a6bd79..3f98c7ac8 100644 --- a/src/utils/getCurrentVoyageTeam.ts +++ b/src/utils/getCurrentVoyageTeam.ts @@ -1,4 +1,4 @@ -import { type AppError } from "@/modules/shared/types"; +import { type AppError } from "@/types/types"; import { type User, type VoyageTeamMember, diff --git a/src/utils/getUser.ts b/src/utils/getUser.ts index 8865369be..84e5c7b7f 100644 --- a/src/utils/getUser.ts +++ b/src/utils/getUser.ts @@ -1,7 +1,7 @@ import { getAccessToken } from "./getCookie"; import { handleAsync } from "./handleAsync"; import { GET } from "./requests"; -import { type AsyncActionResponse } from "@/modules/shared/types"; +import { type AsyncActionResponse } from "@/utils/handleAsync"; import { type User } from "@/store/features/user/userSlice"; export function getUser(): Promise> { diff --git a/src/utils/handleAsync.ts b/src/utils/handleAsync.ts index 3ca6f810c..3bf8ffbd6 100644 --- a/src/utils/handleAsync.ts +++ b/src/utils/handleAsync.ts @@ -1,7 +1,7 @@ -import { - type AsyncActionResponse, - type AsyncFunction, -} from "@/modules/shared/types"; +import { type AppError } from "@/types/types"; + +export type AsyncFunction = () => Promise; +export type AsyncActionResponse = [X | null, AppError | null]; export async function handleAsync( asyncFn: AsyncFunction,