Skip to content

Commit

Permalink
⚡ :: professordetail #8
Browse files Browse the repository at this point in the history
  • Loading branch information
wjzlskxk committed Jun 30, 2024
1 parent fdbaf3e commit 7927e3a
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/components/home/matching/professorDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import Image from "next/image";
import Avartar from "src/asset/Avatar.svg";
import BestRecommandImg from "src/asset/BestRecommand.svg";
import useMatching from "@/hooks/matching/useMatching";
import { useParams } from "next/navigation";

const index = () => {
const { ...professor } = useMatching();
const { id } = useParams();
const professorDetailList = professor.getProfessorDetail();
const schoolInfo =
professorDetailList?.data.schoolName +
Expand All @@ -32,7 +34,7 @@ const index = () => {
<Image src={BestRecommandImg} alt="최다추천 이미지" width={70} height={30} />
</div>
</div>
<S.ChatButton>채팅하기</S.ChatButton>
<S.ChatButton onClick={() => professor.postMatching(1)}>채팅하기</S.ChatButton>
</S.ProffesorInfoWrap>
<S.CarrerAndReviewWrap>
<S.CarrerWrap>
Expand Down
7 changes: 5 additions & 2 deletions src/components/home/matching/professorDetail/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ export const ProfessorDetailWrap = styled.div`
width: 100%;
height: 100vh;
max-width: 1920px;
max-height: 1080px;
display: flex;
flex-direction: column;
Expand Down Expand Up @@ -81,10 +84,10 @@ export const ChatButton = styled.button`
background: ${theme.colors.new};
border-radius: 12px;
border-radius: 15px;
padding: 2%;
margin-right: 2%;
margin-right: 3%;
display: flex;
font-size: 1.6rem;
Expand Down
19 changes: 18 additions & 1 deletion src/hooks/matching/useMatching.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { useGetProfileInfo } from "@/queries/profile/query";
import { useProfessorQuery } from "src/queries/professor/professor.query";
import { usePostMatching } from "@/queries/matching/matching.query";
import { useRouter } from "next/navigation";
import dearToast from "@/libs/Swal/Swal";

const useMatching = () => {
const router = useRouter();
const getProfessorList = (page: number) => {
const [{ data: professorList }] = useProfessorQuery(page);

Expand All @@ -15,7 +19,20 @@ const useMatching = () => {
return professorDetailData;
};

return { getProfessorList, getProfessorDetail };
const postMatchingMuation = usePostMatching();

const postMatching = (subjectId: number) => {
postMatchingMuation.mutate(subjectId, {
onSuccess: () => {
router.push("/chat");
},
onError: () => {
dearToast.errorToast("알수없는 문제가 발생하였습니다.");
},
});
};

return { getProfessorList, getProfessorDetail, postMatching };
};

export default useMatching;
2 changes: 0 additions & 2 deletions src/queries/QueryKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { profile } from "console";

export const QUERY_KEYS = Object.freeze({
matching: {
matching: "/matching",
Expand Down
8 changes: 8 additions & 0 deletions src/queries/matching/matching.query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useMutation, useQueries } from "react-query";
import { QUERY_KEYS } from "../QueryKey";
import matchingRepositoryImpl from "../../repositories/matching/matchingRepositoryImpl";

export const usePostMatching = () => {
const mutation = useMutation((subjectId: number) => matchingRepositoryImpl.postMatching(subjectId));
return mutation;
};
3 changes: 3 additions & 0 deletions src/repositories/matching/matchingRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface matcingRepository {
postMatching(subjectId: number): Promise<void>;
}
10 changes: 10 additions & 0 deletions src/repositories/matching/matchingRepositoryImpl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { matcingRepository } from "./matchingRepository";
import { dearV1Axios } from "@/libs/axios/customAxios";

class MatchingRepositoryImpl implements matcingRepository {
public async postMatching(subjectId: number): Promise<void> {
await dearV1Axios.post("/matching", subjectId);
}
}

export default new MatchingRepositoryImpl();

0 comments on commit 7927e3a

Please sign in to comment.