Skip to content

Conversation

dohun31
Copy link
Member

@dohun31 dohun31 commented Aug 18, 2023

🤠 개요

💫 설명

  • 같은 query 로직이 흩어져 있을 때 이런 문제가 발생할 수 있어요!

    • queryKey를 잘못 쓸 수 있음
    • queryFn을 잘못 쓸 수 있음
  • 따라서 해당 로직을 useWorkspaceQuery 훅에서 관리해 똑같은 동작을 보장해요.


🌜 고민거리 (Optional)

Q. 테스트코드 써볼까요?

  • 지금은 정말 간단한 리팩토링이어서 괜찮은데 client/src/pages/Workspace/index.tsx같이 로직이 좀 있는 걸 고치려면 테스트 코드가 있어야 할 것 같아요.
    • 가령 이 코드 같은 경우에 각 case에 맞게 잘 navigate되는지 테스트코드 작성해두고 리팩토링 진행하면 좋을 것 같아요.
    const loadWorkspaces = async () => {
      if (!user) {
        navigate('/');
        return;
      }
    
      const { id: userId } = user;
    
      const { workspaces: userWorkspaces } = await getWorkspaces({
        id: userId,
      });
    
      setIsLoaded(true);
      setWorkspaces(userWorkspaces);
    
      if (!userWorkspaces.length) {
        navigate('/workspace');
        return;
      }
    
      if (params['*']?.length) return;
    
      const defaultWorkspace = userWorkspaces[0];
      const { id: workspaceId } = defaultWorkspace;
    
      navigate(`/workspace/${workspaceId}`);
    };

📷 스크린샷 (Optional)

@dohun31 dohun31 added 🐥 Frontend 프론트엔드 작업 🛠️ Refactor 리팩토링 작업 labels Aug 18, 2023
@dohun31 dohun31 requested a review from se030 August 18, 2023 05:48
@dohun31 dohun31 self-assigned this Aug 18, 2023
@dohun31 dohun31 changed the title Refactor/#414-B: query 중복 코드 useWorkspacQuery 적용 Refactor/#414-B: query 중복 코드 useWorkspaceQuery 적용 Aug 18, 2023
Copy link
Collaborator

@se030 se030 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L super good TM ^^

@se030
Copy link
Collaborator

se030 commented Aug 18, 2023

고민거리에 써주신 내용은 E2E 테스트를 말씀하시는거겠죠?

@dohun31
Copy link
Member Author

dohun31 commented Aug 18, 2023

고민거리에 써주신 내용은 E2E 테스트를 말씀하시는거겠죠?

@se030 네네네!

@wcho21
Copy link
Member

wcho21 commented Sep 12, 2023

Wow

@se030 se030 requested a review from wcho21 September 12, 2023 13:29
@dohun31
Copy link
Member Author

dohun31 commented Sep 13, 2023

@wcho21 원희님 리뷰 부탁드려요 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐥 Frontend 프론트엔드 작업 🛠️ Refactor 리팩토링 작업
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor: workspace 관련 중복 query 훅으로 분리
3 participants