Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type ProfileFormData = z.infer<typeof profileSchema>;

interface UseModifyUserHookformReturn {
methods: ReturnType<typeof useForm<ProfileFormData>>;
myInfo?: Partial<MyInfoResponse>;
myInfo?: MyInfoResponse;
onSubmit: (data: ProfileFormData) => void;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { MyInfoResponse } from "@/apis/MyPage";

export interface ModifyProfileReadOnlyFields {
homeUniversityName: string;
attendedUniversity: string;
}

export const resolveModifyProfileReadOnlyFields = (myInfo: MyInfoResponse): ModifyProfileReadOnlyFields => {
const isMentorProfile = myInfo.role === "MENTOR" || myInfo.role === "ADMIN";

return {
homeUniversityName: myInfo.homeUniversityName ?? "",
attendedUniversity: isMentorProfile ? myInfo.attendedUniversity : "",
};
};
13 changes: 6 additions & 7 deletions apps/web/src/app/my/modify/_ui/ModifyContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import { FormProvider } from "react-hook-form";
import CloudSpinnerPage from "@/components/ui/CloudSpinnerPage";
import { UserRole } from "@/types/mentor";
import useModifyUserHookform from "./_hooks/useModifyUserHookform";
import { resolveModifyProfileReadOnlyFields } from "./_lib/profileFields";
import ImageInputFiled from "./_ui/ImageInputFiled";
import InputField from "./_ui/InputFiled";
import ReadOnlyField from "./_ui/ReadOnlyField";

const ModifyContent = () => {
const { methods, myInfo, onSubmit } = useModifyUserHookform();

const defaultUniversity: string =
(myInfo?.role === UserRole.MENTOR || myInfo?.role === UserRole.ADMIN) && myInfo.attendedUniversity
? myInfo.attendedUniversity
: "인하대학교";

const {
handleSubmit,
formState: { isValid, isDirty },
Expand All @@ -26,6 +22,9 @@ const ModifyContent = () => {
if (!myInfo) {
return <CloudSpinnerPage />;
}

const { homeUniversityName, attendedUniversity } = resolveModifyProfileReadOnlyFields(myInfo);

return (
<FormProvider {...methods}>
<div className="px-5 py-6">
Expand All @@ -39,10 +38,10 @@ const ModifyContent = () => {
<InputField name="nickname" label="닉네임" placeholder="닉네임을 입력해주세요" />

{/* 출신학교 - 읽기 전용 */}
<ReadOnlyField label="출신학교" value={defaultUniversity} placeholder="서울대학교" />
<ReadOnlyField label="출신학교" value={homeUniversityName} placeholder="등록된 출신학교가 없습니다" />

{/* 수학 학교 - 읽기 전용 */}
<ReadOnlyField label="수학 학교" value="컴퓨터공학과" placeholder="전공" />
<ReadOnlyField label="수학 학교" value={attendedUniversity} placeholder="등록된 수학 학교가 없습니다" />

{/* 사용자 유형 - 읽기 전용 */}
<ReadOnlyField
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/types/myInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface BaseUserInfo {
email: string;
likedPostCount: number;
likedMentorCount: number;
homeUniversityName: string | null;
homeUniversityName?: string | null;
}

export interface MyInfo {
Expand Down
Loading