담벼락프로젝트_코드리팩토링[0]

BBAKJUN·2021년 11월 26일
0

코드리팩토링

목록 보기
1/1
post-thumbnail
const handelSubmit = () => {
  await userAPI.signIn({
      email,password
    }).then((res) => {
      res.data.isSuccess // 로그인 성공 true of false ???
        ? (
          swalAlert(res.data.message,"",'success',{
            buttons: false,
            timer: 1000,
          }).then(() => {
            userAPI.detail(res.data.jwt)
              .then((response) => {
                if(response.data.isSuccess) SubmitForm(response.data.result[0],res.data.jwt)
              }).catch((error) => {
              swalAlert(error.message,"", "error", {
                buttons: false,
                timer: 1000,
              })
            })
          }).catch((err) => {
            console.log(err)
          })
        )
        : (
          swalAlert(res.data.message,"","error")
        )
    })
}

이랬던 코드를

 const SignIn = async () => {
    return userAPI.signIn({
      email, password
    })
  }
  const getUserDetail = async (jwt) => {
    return userAPI.detail(jwt)
  }
  const handleSubmit = () => {
    SignIn().then((signInRes) => {
      signInRes.data.isSuccess
        ? swalAlert(signInRes.data.message,"","success",{buttons:false,timer:1000}).then(() => {
            getUserDetail(signInRes.data.jwt).then((getUserDetailRes) => {
              getUserDetailRes.data.isSuccess
                ? SubmitForm(getUserDetailRes.data.result[0],signInRes.data.jwt)
                : null
            }).catch((err) => {
              swalAlert(err.message,"","error",{buttons:false,timer:1000})
            })
          })
        :swalAlert(signInRes.data.message,'message','error')
    })
  }

이렇게 바꾸었는데 괜찮은건가 잘 모르겠다....
일단 맥주를 마시며 코드썼으니깐 내일 다시 일어나서 보는거로해보자!!!!

profile
함께 일하고 싶은 환경을 만들어가는 프론트엔드 개발자 박준형입니다.

0개의 댓글