Skip to content

Commit

Permalink
feat: 토스트 메시지 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Leejha committed Oct 4, 2023
1 parent 0cf58e3 commit 3d5ae24
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,14 @@ function UserInfoEditContainer() {
variant="primary"
width="100%"
height="56px"
onClick={() => {
onClick={() =>
updateUserInfo({
nickname,
alcoholLimit,
mbti,
imageUrl,
});
router.push(Path.MY_PAGE);
}}
})
}
>
완료
</CompleteButton>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { uploadImageAPI } from "lib/apis/common";
import { deleteUserAPI, updateUserInfoAPI } from "lib/apis/my";
import Path from "lib/Path";
import { queryKeys } from "lib/queryKeys";
import { useRouter } from "next/navigation";
import { toast } from "react-toastify";

type UpdateUserInfoRequest = Exclude<Parameters<typeof updateUserInfoAPI>[0], undefined>;

Expand Down Expand Up @@ -39,9 +42,12 @@ export default function useEditProfileService() {
queryClient.setQueryData(getQueryKey, (prev: any) => ({ ...prev, mbti: value }));
};

const router = useRouter();

const { mutate: updateUserInfo } = useMutation(
(newUserInfo: UpdateUserInfoRequest) => updateUserInfoAPI(newUserInfo),
{
onSuccess: () => router.push(Path.MY_PAGE),
onError: () => {
/**
* @TODO 서버 메시지와 연동
Expand All @@ -51,7 +57,12 @@ export default function useEditProfileService() {
},
);

const { mutate: deleteUser } = useMutation(() => deleteUserAPI());
const { mutate: deleteUser } = useMutation(() => deleteUserAPI(), {
onSuccess: () => {
toast("회원 탈퇴가 완료되었습니다.");
router.push(Path.MAIN_PAGE);
},
});

return {
onUploadImage,
Expand Down
16 changes: 11 additions & 5 deletions apps/jurumarble/src/app/register/contexts/RegisterProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ export const RegisterProvider = ({ children }: PropsWithChildren) => {
: 1;

const onNextStep = () => {
if (Number(yearOfBirth) > 2004) {
toast.error("2004년 이후 출생자는 가입이 불가능합니다.");
setYearOfBirth("");
return;
} else if (999 < Number(yearOfBirth) && Number(yearOfBirth) < 1900) {
toast.error("출생년도를 다시 한번 확인해주세요.");
setYearOfBirth("");
return;
}

currentStepIndex < stepList.length
? setStep(stepList[currentStepIndex])
: onToggleWarningModal();
Expand Down Expand Up @@ -141,11 +151,7 @@ export const RegisterProvider = ({ children }: PropsWithChildren) => {
} else if (step === "STEP2") {
return gender === null;
} else if (step === "STEP3") {
/**
* @TODO 토스트 메시지가 두번씩 뜨는 이슈
*/
Number(yearOfBirth) > 2004 && toast.error("2004년 이후 출생자는 가입이 불가능합니다.");
return yearOfBirth === "" || yearOfBirth?.length !== 4 || Number(yearOfBirth) > 2004;
return yearOfBirth === "" || yearOfBirth?.length !== 4;
} else if (step === "STEP4") {
return Object.values(MBTI).some((value) => value === null);
}
Expand Down

0 comments on commit 3d5ae24

Please sign in to comment.