Skip to content

Commit

Permalink
fix merge conflict and fix issue with DI
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan-Y-Ko committed Oct 17, 2024
2 parents 4b89a51 + 522aceb commit 330a0c4
Show file tree
Hide file tree
Showing 43 changed files with 417 additions and 66 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@heroicons/react": "^2.0.18",
"@hookform/resolvers": "^3.3.1",
"@reduxjs/toolkit": "^1.9.5",
"axios": "^1.7.7",
"class-variance-authority": "^0.7.0",
"date-fns": "^3.6.0",
"date-fns-tz": "^3.1.3",
Expand All @@ -33,7 +34,9 @@
"react-hook-form": "^7.46.2",
"react-redux": "^8.1.2",
"redux-persist": "^6.0.0",
"reflect-metadata": "^0.2.2",
"tailwind-merge": "^2.0.0",
"tsyringe": "^4.8.0",
"zod": "^3.22.2"
},
"devDependencies": {
Expand Down
18 changes: 18 additions & 0 deletions src/app/(auth)/_adapters/authClientAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { inject, injectable } from "tsyringe";
import { type LoginRequestDto } from "@/modules/auth/application/dtos/request.dto";
import { type LoginResponseDto } from "@/modules/auth/application/dtos/response.dto";
import { LoginUsecase } from "@/modules/auth/application/usecases/loginUsecase";
import { type AuthClientPort } from "@/modules/auth/ports/primary/authClientPort";
import { TYPES } from "@/di/types";

@injectable()
export class AuthClientAdapter implements AuthClientPort {
constructor(
@inject(TYPES.LoginUsecase)
private readonly loginUsecase: LoginUsecase,
) {}

async login({ email, password }: LoginRequestDto): Promise<LoginResponseDto> {
return await this.loginUsecase.execute({ email, password });
}
}
3 changes: 2 additions & 1 deletion src/app/(auth)/authService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"use server";

import { cookies } from "next/headers";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { getAccessToken, getRefreshToken } from "@/utils/getCookie";
import { POST, UNAUTHPOST } from "@/utils/requests";

Expand Down
1 change: 1 addition & 0 deletions src/app/(auth)/sign-in/components/SignInContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import "reflect-metadata";
import { useState } from "react";
import ResetPasswordContainer from "./ResetPasswordContainer";
import SignInBlock from "./SignInBlock";
Expand Down
37 changes: 9 additions & 28 deletions src/app/(auth)/sign-in/components/SignInFormContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ import Link from "next/link";
import { useRouter } from "next/navigation";
import { type SubmitHandler, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { serverSignIn } from "@/app/(auth)/authService";

import Button from "@/components/Button";
import TextInput from "@/components/inputs/TextInput";
import { validateTextInput } from "@/utils/form/validateInput";
import { clientSignIn } from "@/store/features/auth/authSlice";
import { onOpenModal } from "@/store/features/modal/modalSlice";
import { useAppDispatch } from "@/store/hooks";
import routePaths from "@/utils/routePaths";

import useServerAction from "@/hooks/useServerAction";
import Spinner from "@/components/Spinner";
import { type AuthClientAdapter } from "@/app/(auth)/_adapters/authClientAdapter";
import { TYPES } from "@/di/types";
import { resolve } from "@/di/resolver";

const validationSchema = z.object({
email: validateTextInput({
Expand Down Expand Up @@ -42,15 +39,9 @@ function SignInFormContainer({
const router = useRouter();
const dispatch = useAppDispatch();

const {
runAction: serverSignInAction,
isLoading: serverSignInLoading,
setIsLoading: setServerSignInLoading,
} = useServerAction(serverSignIn);

const {
register,
formState: { errors, isDirty, isValid },
formState: { errors },
handleSubmit,
} = useForm<ValidationSchema>({
mode: "onTouched",
Expand All @@ -59,25 +50,15 @@ function SignInFormContainer({

const onSubmit: SubmitHandler<ValidationSchema> = async (data) => {
const { email, password } = data;
const [res, error] = await serverSignInAction({ email, password });
const authAdapter = resolve<AuthClientAdapter>(TYPES.AuthClientAdapter);

if (res) {
dispatch(clientSignIn());
router.replace(routePaths.dashboardPage());
}
await authAdapter.login({ email, password });

if (error) {
dispatch(
onOpenModal({ type: "error", content: { message: error.message } }),
);
setServerSignInLoading(false);
}
dispatch(clientSignIn());
router.replace(routePaths.dashboardPage());
};

function renderButtonContent() {
if (serverSignInLoading) {
return <Spinner />;
}
return "Sign In";
}

Expand Down Expand Up @@ -113,7 +94,7 @@ function SignInFormContainer({
<Button
type="submit"
title="submit"
disabled={!isDirty || !isValid || serverSignInLoading}
// disabled={!isDirty || !isValid || serverSignInLoading}
>
{renderButtonContent()}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } from "@/types/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";
Expand All @@ -13,7 +14,6 @@ import { type FeaturesList } from "@/store/features/features/featuresSlice";
import { type IdeationData } from "@/store/features/ideation/ideationSlice";
import { type TechStackData } from "@/store/features/techStack/techStackSlice";
import { type ResourceData } from "@/store/features/resources/resourcesSlice";
import type { AsyncActionResponse } from "@/utils/handleAsync";
import { ErrorType } from "@/utils/error";

interface GetDashboardDataResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ 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 { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { GET } from "@/utils/requests";
import { CacheTag } from "@/utils/cacheTag";
import { type User } from "@/store/features/user/userSlice";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { revalidateTag } from "next/cache";
import { getAccessToken } from "@/utils/getCookie";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { PATCH } from "@/utils/requests";
import { CacheTag } from "@/utils/cacheTag";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ 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 { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { ErrorType } from "@/utils/error";

function transformData(features: Features[]): FeaturesList[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { revalidateTag } from "next/cache";
import { type Features } from "@/store/features/features/featuresSlice";
import { CacheTag } from "@/utils/cacheTag";
import { getAccessToken } from "@/utils/getCookie";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { DELETE, PATCH, POST } from "@/utils/requests";

interface SaveOrderProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import FinalizedIdeationCard from "./FinalizedIdeationCard";
import IdeationContainer from "./IdeationContainer";
import IdeationProvider from "./IdeationProvider";
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";
Expand All @@ -15,10 +14,12 @@ import { CacheTag } from "@/utils/cacheTag";
import { getAccessToken } from "@/utils/getCookie";
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import { getUser } from "@/utils/getUser";
import { handleAsync, type AsyncActionResponse } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { GET } from "@/utils/requests";
import routePaths from "@/utils/routePaths";
import { ErrorType } from "@/utils/error";
import { type FetchIdeationsProps } from "@/app/(main)/my-voyage/[teamId]/ideation/ideationService";

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ import { validateTextInput } from "@/utils/form/validateInput";
import { useAppDispatch, useIdeation } from "@/store/hooks";
import { type IdeationData } from "@/store/features/ideation/ideationSlice";
import Spinner from "@/components/Spinner";
import {
editIdeation,
type EditIdeationProps,
addIdeation,
deleteIdeation,
} from "@/app/(main)/my-voyage/[teamId]/ideation/ideationService";
import useServerAction from "@/hooks/useServerAction";
import { persistor } from "@/store/store";
import { onOpenModal } from "@/store/features/modal/modalSlice";
import routePaths from "@/utils/routePaths";
import {
addIdeation,
deleteIdeation,
editIdeation,
type EditIdeationProps,
} from "@/app/(main)/my-voyage/[teamId]/ideation/ideationService";

const validationSchema = z.object({
title: validateTextInput({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { useAppDispatch, useIdeation, useModal, useUser } from "@/store/hooks";
import Spinner from "@/components/Spinner";
import { cn } from "@/lib/utils";
import useServerAction from "@/hooks/useServerAction";
import { onOpenModal } from "@/store/features/modal/modalSlice";
import AvatarGroup from "@/components/avatar/AvatarGroup";
import Avatar from "@/components/avatar/Avatar";
import {
addIdeationVote,
removeIdeationVote,
} from "@/app/(main)/my-voyage/[teamId]/ideation/ideationService";
import { onOpenModal } from "@/store/features/modal/modalSlice";
import AvatarGroup from "@/components/avatar/AvatarGroup";
import Avatar from "@/components/avatar/Avatar";
import Tooltip from "@/components/Tooltip";

interface VoteCardProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { useParams, useRouter } from "next/navigation";
import { type FinalizedIdeation } from "./FinalizeIdeationList";
import useServerAction from "@/hooks/useServerAction";
import Button from "@/components/Button";
import { finalizeIdeation } from "@/myVoyage/ideation/ideationService";
import routePaths from "@/utils/routePaths";
import { useAppDispatch } from "@/store/hooks";
import { onOpenModal } from "@/store/features/modal/modalSlice";
import Spinner from "@/components/Spinner";
import { finalizeIdeation } from "@/app/(main)/my-voyage/[teamId]/ideation/ideationService";

interface ConfirmationButtonProps {
finalizedIdeation: FinalizedIdeation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { getUser } from "@/utils/getUser";
import { getCurrentSprint } from "@/utils/getCurrentSprint";
import { GET } from "@/utils/requests";
import { CacheTag } from "@/utils/cacheTag";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { type Sprint } from "@/store/features/sprint/sprintSlice";
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import routePaths from "@/utils/routePaths";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
} from "@/store/features/sprint/sprintSlice";

import { getCurrentSprint } from "@/utils/getCurrentSprint";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { GET } from "@/utils/requests";
import { getAccessToken } from "@/utils/getCookie";
import { getUser } from "@/utils/getUser";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { getAccessToken } from "@/utils/getCookie";
import { getUser } from "@/utils/getUser";
import { GET } from "@/utils/requests";
import { CacheTag } from "@/utils/cacheTag";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { getCurrentVoyageData } from "@/utils/getCurrentVoyageData";
import routePaths from "@/utils/routePaths";
import { Forms, UserRole } from "@/utils/form/formsEnums";
Expand Down
3 changes: 2 additions & 1 deletion src/app/(main)/my-voyage/[teamId]/sprints/sprintsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import { revalidateTag } from "next/cache";
import { getAccessToken } from "@/utils/getCookie";
import { DELETE, PATCH, POST } from "@/utils/requests";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { CacheTag } from "@/utils/cacheTag";
import { getSprintCache } from "@/utils/getSprintCache";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { revalidateTag } from "next/cache";
import type { Category } from "./finalize/types";
import { CacheTag } from "@/utils/cacheTag";
import { getAccessToken } from "@/utils/getCookie";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { DELETE, PATCH, POST } from "@/utils/requests";
import { type TechStackItem } from "@/store/features/techStack/techStackSlice";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import { revalidateTag } from "next/cache";
import { getAccessToken } from "@/utils/getCookie";
import { POST, DELETE } from "@/utils/requests";
import { type AsyncActionResponse, handleAsync } from "@/utils/handleAsync";
import { handleAsync } from "@/utils/handleAsync";
import { type AsyncActionResponse } from "@/utils/handleAsync";
import { CacheTag } from "@/utils/cacheTag";

interface ResourceProps {
Expand Down
2 changes: 2 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "reflect-metadata";
import "@/di/config";
import "./globals.css";
import type { Metadata } from "next";
import { Inter } from "next/font/google";
Expand Down
13 changes: 13 additions & 0 deletions src/di/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { container } from "tsyringe";
import { TYPES } from "./types";
import { AuthApiAdapter } from "@/modules/auth/adapters/secondary/authApiAdapter";
import { AxiosAdapter } from "@/modules/restApi/adapters/secondary/AxiosAdapter";
import { AuthClientAdapter } from "@/app/(auth)/_adapters/authClientAdapter";
import { LoginUsecase } from "@/modules/auth/application/usecases/loginUsecase";

container.register(TYPES.RestApiPort, { useClass: AxiosAdapter });
container.register(TYPES.AuthApiPort, { useClass: AuthApiAdapter });
container.register(TYPES.LoginUsecase, { useClass: LoginUsecase });
container.register(TYPES.AuthClientAdapter, { useClass: AuthClientAdapter });

export default container;
6 changes: 6 additions & 0 deletions src/di/resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { InjectionToken } from "tsyringe";

import container from "./config";

export const resolve = <T>(token: InjectionToken<T>): T =>
container.resolve(token);
14 changes: 14 additions & 0 deletions src/di/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const TYPES = {
/* Ports */
RestApiPort: Symbol.for("RestApiPort"),
AuthClientPort: Symbol.for("AuthClientPort"),
AuthApiPort: Symbol.for("AuthApiPort"),

/* Adapters */
AxiosAdapter: Symbol.for("AxiosAdapter"),
AuthClientAdapter: Symbol.for("AuthClientAdapter"),
AuthApiAdapter: Symbol.for("AuthApiAdapter"),

/* UseCases */
LoginUsecase: Symbol.for("LoginUsecase"),
};
18 changes: 18 additions & 0 deletions src/hooks/useInjection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import "reflect-metadata";

import { useMemo } from "react";

import { injectables } from "@/di/injectables";

const useInjection = () => {
const injection = useMemo(
() => ({
...injectables,
}),
[],
);

return injection;
};

export default useInjection;
Loading

0 comments on commit 330a0c4

Please sign in to comment.