Skip to content

Commit

Permalink
feat: 신청버튼 분기처리
Browse files Browse the repository at this point in the history
  • Loading branch information
rladmswo1715 committed Jun 14, 2024
1 parent ef71f88 commit 611767c
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions components/notice/NoticeDetailed/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import { calculateIncreasePercent } from "@/utils/calculateIncreasePercent";
import { postApplicant, putApplicationStatus } from "@/api/notice";
import { useRouter } from "next/router";
import getStringValue from "@/utils/getStringValue";
import { useRecoilState, useRecoilValue } from "recoil";
import { useRecoilValue } from "recoil";
import { authState, signupState } from "@/atoms/userAtom";
import { getMyApplicationList } from "@/api/user";
import { IApplicantGetApiData } from "@/types/MyShopNotice";
import { useModal } from "@/hooks/useModal";
import { profileAtom } from "@/atoms/profileAtom";
import { employerAtom } from "@/atoms/employerAtom";

const cx = classNames.bind(styles);

Expand All @@ -40,7 +42,8 @@ const NoticeDetailed = ({ shopData }: INoticeDataProps) => {
const duration = `${shopData.workhour}시간`;

const sign = useRecoilValue(signupState);
const auth = useRecoilValue(authState);
const employeeProfile = useRecoilValue(profileAtom);
const employerData = useRecoilValue(employerAtom);
const { openModal, closeModal } = useModal();

const increasePercent = calculateIncreasePercent(
Expand All @@ -49,6 +52,8 @@ const NoticeDetailed = ({ shopData }: INoticeDataProps) => {
);

const handleApplyClick = async () => {
if (!applyValidation()) return;

try {
const response = await postApplicant(shopData.shop.id, shopData.id);
if (response?.status === 201) {
Expand Down Expand Up @@ -104,6 +109,39 @@ const NoticeDetailed = ({ shopData }: INoticeDataProps) => {
}
};

const applyValidation = () => {
switch (sign.type) {
case "employee":
if (
!employeeProfile.name ||
employeeProfile.name === "" ||
!employeeProfile.address ||
employeeProfile.address === ""
) {
openModal({
modalType: "warning",
content: "내 프로필을 먼저 등록해 주세요.",
btnName: ["확인"],
});
return false;
}
break;

case "employer":
return false;

default:
openModal({
modalType: "warning",
content: "로그인을 해주세요.",
btnName: ["확인"],
});
return false;
}

return true;
};

useEffect(() => {
if (!shopData) return;

Expand Down

0 comments on commit 611767c

Please sign in to comment.