Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Feature/dev 60 ] 로그인 또는 회원가입 mock API 연결 #128

Merged
merged 5 commits into from
Jul 31, 2024

Conversation

soomin9106
Copy link
Collaborator

🔥 Related Issues

https://linear.app/fewletter/issue/DEV-60/%EB%A1%9C%EA%B7%B8%EC%9D%B8-%EB%98%90%EB%8A%94-%ED%9A%8C%EC%9B%90%EA%B0%80%EC%9E%85-mock-api-%EC%97%B0%EA%B2%B0

✅ PR Point

  • /api/v1/members (로그인 또는 회원가입 버튼 클릭 시 인증 이메일 보내는 API -> 그 결과를 리턴함) 을 mocking 하고 custom hook 구현
  • 이메일 전송 성공 시, 전송 성공 페이지로 이동 => 실패 시, toast 출력
export const useEmailForm = () => {
  const { toast } = useToast();
  const router = useRouter()

  const form = useForm<EmailSubscribeFormData>({
    resolver: zodResolver(emailSubscribeSchema),
    defaultValues: {
      email: "",
    },
    mode: "onSubmit",
  });

  const { mutate: memberSave } = useMutation({
    ...memberSaveOptions()
  });

  const onSubmit = (values: EmailSubscribeFormData) => {
    try {
      memberSave(values, {
        onSuccess: (response: ApiResponse<memberSaveResponse>) => {
          console.log('res', response);

          if (response.data?.data?.sendAuth) {
            // redirect to validation page
            router.push(`/auth/validation?email=${values.email}`)
          } else {
            toast({
              title: SIGNUP_PROGRESS.EMAIL_SEND_FAIL,
            });
          }
        },
        onError: () => {  
          toast({
            title: SIGNUP_PROGRESS.EMAIL_SEND_FAIL,
          });
        },
      });
    } catch (error) {
      console.error("catch error", error);

      toast({
        title: LOGIN_STATUS.FAILED,
      });
    }
  };

  return {
    form,
    onSubmit,
  };
};

👀 스크린샷 / GIF / 링크

2024-07-29.11.21.40.mov

@soomin9106
Copy link
Collaborator Author

test code 는 mutation 포함해서 작성 중임다!!

Copy link
Collaborator

@Happhee Happhee left a comment

Choose a reason for hiding this comment

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

고생많았어요..!

근데 ㅠ.ㅠ 어째...순서가 또 뒤바뀌고 있는것가타욥 ㅠㅠㅠ테스크코드를 먼저짜는게 맞는것같습니다아 !!!!!

@@ -23,7 +23,7 @@ export const metadata: Metadata = {
},
};

export const runtime = "edge"; // TBD: 개발환경과 분리
// export const runtime = "edge"; // TBD: 개발환경과 분리
Copy link
Collaborator

Choose a reason for hiding this comment

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

오우 얘는 develop으로 가면 안될것같아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

아아 얘 확인했습니다!

router.push(`/auth/validation?email=${values.email}`)
} else {
toast({
title: SIGNUP_PROGRESS.EMAIL_SEND_FAIL,
Copy link
Collaborator

Choose a reason for hiding this comment

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

혹시 onError에서 처리하지 않고, onSuccess 내부에서 data의 여부로 실패를 판단한 이유가 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

아 이 부분은 sendAuth 가 이메일이 전송이 되었는지 안되었는지를 따지는 필드인데, 아예 백엔드 자체에서 이메일 전송에 실패했을 경우도 있어서 저렇게 처리 했습니다!! onError 인 경우하고는 또 다른 경우인 것 같아용!! 이메일을 전송 못했을 때 sendAuth 가 false 로 올 수도 있습니당!!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

근데 이메일 전송 실패 사유를 정확하게 파악은 못하는 상황이라 toast title 은 SIGNUP_PROGRESS.EMAIL_SEND_FAIL 로 onError 일 때와 같습니다!!
참고: https://www.figma.com/design/nfHptFfTa7zPwklplA6v4F?node-id=1014-977#890519000

Copy link
Collaborator

Choose a reason for hiding this comment

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

@soomin9106 아 네네 이해했습니다. 혹시 그러면 저희가 요청자체를 실패하는 경우는 없는걸까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이메일 검증 과정이 있어서 클라 쪽에서의 요청 실패는 없을 듯 합니당!!
조금 더 케이스 봐보고 보완할게요!

@soomin9106
Copy link
Collaborator Author

맞아요 ㅠㅠ mutation 부분을 어떻게 하면 좋을까 하다 테코 작성을 미뤘습니다.. ㅋㅋㅋ ㅠㅠ
담 PR 부터는 테코부터 써보겠슴다

@soomin9106
Copy link
Collaborator Author

테코 추가했습니다!
2d0f08a

Copy link
Collaborator

@Happhee Happhee left a comment

Choose a reason for hiding this comment

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

테스트 코드까지 검증하시느라 고생하셨습니다!

Comment on lines 65 to 68
const user = userEvent.setup();

renderWithClient();

Copy link
Collaborator

Choose a reason for hiding this comment

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

이부분은 beforeEach 메소드 앞에 사용해서 정의해주면 반복해서 작성할 필요없는것같습니다..!

@soomin9106 soomin9106 merged commit e030fbd into develop Jul 31, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants