Skip to content

Commit

Permalink
FE: [feat] 수험자 화면 API 연결 #34
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeona01 committed Nov 19, 2024
1 parent afa394c commit 66dadb7
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/frontend/eyesee-user/src/apis/examCode.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { api } from ".";
import { apiWithoutAuth } from ".";
import { RESTYPE } from "@/types/common";
import { ExamRequest, ExamResponse } from "@/types/exam";

export const enterSession = async (
data: ExamRequest
): Promise<RESTYPE<ExamResponse>> => {
const response = await api.post(`/sessions/join`, data);
const response = await apiWithoutAuth.post(`/sessions/join`, data);
return response.data;
};
1 change: 0 additions & 1 deletion src/frontend/eyesee-user/src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ function createInstance() {
*
* @description
* 이 함수는 기본 URL만 설정된 Axios 인스턴스를 생성합니다.
* 인증 토큰이 필요하지 않은 API 요청(예: 로그인, 회원가입 등)에 사용됩니다.
*/
function createInstanceWithoutAuth() {
const instance = axios.create({
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/eyesee-user/src/apis/userInformation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { api } from ".";
import { apiWithoutAuth } from ".";
import { RESTYPE } from "@/types/common";
import { UserInfoRequest, UserInfoResponse } from "@/types/exam";

export const userInformation = async (
data: UserInfoRequest
): Promise<RESTYPE<UserInfoResponse>> => {
const response = await api.post(`/sessions/student`, data);
const response = await apiWithoutAuth.post(`/sessions/student`, data);
return response.data;
};
8 changes: 7 additions & 1 deletion src/frontend/eyesee-user/src/app/information/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import { userInformation } from "@/apis/userInformation";
import NextButton from "@/components/common/NextButton";
import SubHeader from "@/components/common/SubHeader";
import InformationSection from "@/components/information/InformationSection";
import { useExamStore } from "@/store/useExamStore";
import { UserInfoRequest } from "@/types/exam";
import { setAccessToken, setRefreshToken } from "@/utils/auth";
import { informationValidation } from "@/utils/validation";
import { useRouter } from "next/navigation";
import { useEffect, useState } from "react";

const InformationPage = () => {
const router = useRouter();
const { exam } = useExamStore();
const [isAvailable, setIsAvailable] = useState(false);
const [information, setInformation] = useState<UserInfoRequest>({
examCode: "",
// TODO: 서버 데이터 타입 통일 필요
examCode: exam.examRandomCode,
name: "",
department: "",
userNum: 0,
Expand All @@ -25,6 +29,8 @@ const InformationPage = () => {
try {
const response = await userInformation(information); // API 호출
console.log("응답 데이터:", response); // 성공 시 데이터 처리
setAccessToken(response.data.access_token);
setRefreshToken(response.data.refresh_token);
router.push("/camera");
} catch (error) {
console.error("수험 정보 입력 실패:", error); // 실패 시 에러 처리
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Information } from "@/types/information";
import { UserInfoRequest } from "@/types/exam";
import { Dispatch, SetStateAction } from "react";

type InformationSectionProps = {
information: Information;
setInformation: Dispatch<SetStateAction<Information>>;
information: UserInfoRequest;
setInformation: Dispatch<SetStateAction<UserInfoRequest>>;
};

const InformationSection = ({
information,
setInformation,
}: InformationSectionProps) => {
const handleChange = (key: keyof Information, value: string) => {
const handleChange = (key: keyof UserInfoRequest, value: string) => {
setInformation((prev) => ({
...prev,
[key]: value,
Expand Down Expand Up @@ -41,8 +41,8 @@ const InformationSection = ({
id="department"
type="text"
placeholder="학과"
value={information.major}
onChange={(e) => handleChange("major", e.target.value)}
value={information.department}
onChange={(e) => handleChange("department", e.target.value)}
className="w-full text-[#141412] text-[14px] px-3 py-3 border-b border-black"
/>
</div>
Expand All @@ -52,11 +52,11 @@ const InformationSection = ({
학번
</label>
<input
id="studentId"
id="userNum"
type="text"
placeholder="학번"
value={information.studentNumber}
onChange={(e) => handleChange("studentNumber", e.target.value)}
value={information.userNum == 0 ? "" : information.userNum}
onChange={(e) => handleChange("userNum", e.target.value)}
className="w-full text-[#141412] text-[14px] px-3 py-3 border-b border-black"
/>
</div>
Expand All @@ -66,11 +66,11 @@ const InformationSection = ({
좌석 번호
</label>
<input
id="seatNumber"
id="seatNum"
type="text"
placeholder="좌석 번호"
value={information.seatNumber}
onChange={(e) => handleChange("seatNumber", e.target.value)}
value={information.seatNum == 0 ? "" : information.seatNum}
onChange={(e) => handleChange("seatNum", e.target.value)}
className="w-full text-[#141412] text-[14px] px-3 py-3 border-b border-black"
/>
</div>
Expand Down
16 changes: 12 additions & 4 deletions src/frontend/eyesee-user/src/store/useExamStore.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { ExamResponse, InitialExamResponse } from "@/types/exam";
import { create } from "zustand";
import { persist } from "zustand/middleware";

type ExamStore = {
exam: ExamResponse;
setExam: (exam: ExamResponse) => void;
};

export const useExamStore = create<ExamStore>((set) => ({
exam: InitialExamResponse,
setExam: (exam) => set({ exam }),
}));
export const useExamStore = create(
persist<ExamStore>(
(set) => ({
exam: InitialExamResponse,
setExam: (exam) => set({ exam }),
}),
{
name: "exam-storage", // localStorage에 저장될 키 이름
}
)
);

0 comments on commit 66dadb7

Please sign in to comment.