Skip to content

Commit

Permalink
Merge pull request #195 from SystemConsultantGroup/develop
Browse files Browse the repository at this point in the history
수정사항 반영을 위해 머지합니다.
  • Loading branch information
hynseok authored Nov 1, 2024
2 parents b2135e3 + 84481db commit 15a619a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/app/admin/students/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ interface Props {
}

export default async function StudentRegisterPage({ params: { id } }: Props) {
await AuthSSR({ userType: "ADMIN" });
const auth = await AuthSSR({ userType: "ADMIN" });

return (
<>
<PageHeader title="학생 현황 및 수정" />
<Section>
<AdminStudentForm studentId={id} />
<AdminStudentForm studentId={id} token={auth.token} />
</Section>
</>
);
Expand Down
35 changes: 29 additions & 6 deletions src/components/pages/AdminStudentForm/AdminStudentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import MainRegisterModal from "./_sections/MainRegisterModal";

interface Props {
studentId?: string | number;
token?: string;
}

function AdminStudentForm({ studentId }: Props) {
function AdminStudentForm({ studentId, token }: Props) {
const router = useRouter();
const { login, isLoading, user } = useAuth();
const [isPwEditing, setIsPwEditing] = useState<boolean>(false);
Expand All @@ -41,6 +42,7 @@ function AdminStudentForm({ studentId }: Props) {
handleReviewersSet,
} = useReviewersAssign();
const [isPhd, setIsPhd] = useState<boolean>(false);
const [phdLoading, setPhdLoading] = useState<boolean>(true);

const form = useForm<AdminStudentFormInputs>({
initialValues: {
Expand Down Expand Up @@ -283,7 +285,7 @@ function AdminStudentForm({ studentId }: Props) {
showNotificationSuccess({ message: "학생 등록이 완료되었습니다." });
router.push("/admin/students");
} else {
await ClientAxios.post(API_ROUTES.student.put(studentId), basicInfo);
await ClientAxios.put(API_ROUTES.student.put(studentId), basicInfo);
showNotificationSuccess({ message: "학생 정보 수정이 완료되었습니다." });
router.push(`/admin/students/${studentId}`);
router.refresh();
Expand All @@ -304,7 +306,23 @@ function AdminStudentForm({ studentId }: Props) {
}
}, [isLoading]);

useEffect(() => {}, [isPhd]);
useEffect(() => {
const fetchPhd = async () => {
if (studentId && token) {
const { data } = await ClientAxios.get(API_ROUTES.student.get(studentId), {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (data.type === "PHD") {
setIsPhd(true);
}
setPhdLoading(false);
}
};
fetchPhd();
}, [studentId, token]);

return (
<>
<Modal
Expand All @@ -329,7 +347,7 @@ function AdminStudentForm({ studentId }: Props) {
</Group>
</Stack>
</Modal>
{studentId && (
{studentId && !isPhd && !phdLoading && (
<MainRegisterModal studentId={studentId} opened={opened} close={close} token={isAdmin} />
)}
<form onSubmit={isPhd ? form.onSubmit(handlePhd) : form.onSubmit(handleSubmit)}>
Expand Down Expand Up @@ -369,8 +387,9 @@ function AdminStudentForm({ studentId }: Props) {
open={open}
token={isAdmin}
isPhd={isPhd}
phdLoading={phdLoading}
/>
{!isPhd && (
{!isPhd && !phdLoading ? (
<AssignReviewerSection
studentId={studentId}
headReviewer={headReviewer}
Expand All @@ -380,9 +399,13 @@ function AdminStudentForm({ studentId }: Props) {
onChangeReviewerCancle={handleReviewerCancel}
onChangeReviewersSet={handleReviewersSet}
token={isAdmin}
isPhd={isPhd}
phdLoading={phdLoading}
/>
) : (
<></>
)}
{!isPhd ? (
{!isPhd && !phdLoading ? (
studentId ? (
<ThesisInfoSection studentId={studentId} token={isAdmin} />
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ interface Props {
_advisors: Professor[],
_committees: Professor[]
) => void;

isPhd: boolean;
phdLoading: boolean;
}

interface SelectedReviewer {
Expand All @@ -49,6 +52,8 @@ function AssignReviewerSection({
committees,
studentId,
token = false,
isPhd,
phdLoading,
}: Props) {
/** 교수 목록, 학과 목록 조회 */
const {
Expand Down Expand Up @@ -144,7 +149,7 @@ function AssignReviewerSection({
};

const fetchReviewer = async () => {
if (studentId && onChangeReviewersSet && token) {
if (studentId && onChangeReviewersSet && token && !isPhd && !phdLoading) {
const response = await ClientAxios.get(API_ROUTES.student.getReviewer(Number(studentId)));
const reviewerDetails = response.data;
onChangeReviewersSet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface Props {
open: () => void;
token?: boolean;
isPhd?: boolean;
phdLoading?: boolean;
}

function BasicInfoSection({
Expand All @@ -28,6 +29,7 @@ function BasicInfoSection({
open,
token,
isPhd,
phdLoading,
}: Props) {
const [phase, setPhase] = useState<Phase>();
const [defaultDepartmentId, setDefaultDepartmentId] = useState<string | null>(null);
Expand All @@ -42,9 +44,11 @@ function BasicInfoSection({
const studentDetails = response.data;

// 시스템 정보 조회
const sysResponse = await ClientAxios.get(API_ROUTES.student.getSystem(studentId));
const sysDetails = sysResponse.data;
setPhase(sysDetails.phase);
if (!isPhd && !phdLoading) {
const sysResponse = await ClientAxios.get(API_ROUTES.student.getSystem(studentId));
const sysDetails = sysResponse.data;
setPhase(sysDetails.phase);
}

form.setFieldValue("basicInfo", {
loginId: studentDetails.loginId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ function MainRegisterModal({ studentId, opened, close, token }: Props) {
onChangeReviewerCancle={handleReviewerCancel}
onChangeReviewersSet={handleReviewersSet}
token={token}
isPhd={false}
phdLoading={false}
/>
<ThesisTitleSection form={sysMainForm} />
<RowGroup>
Expand Down

0 comments on commit 15a619a

Please sign in to comment.