web27-Wabinar icon indicating copy to clipboard operation
web27-Wabinar copied to clipboard

Refactor/#414-B: query 중복 코드 useWorkspaceQuery 적용

Open dohun31 opened this issue 10 months ago • 4 comments

🤠 개요

  • close: #414

💫 설명

  • 같은 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 avatar Aug 18 '23 05:08 dohun31