Skip to content

Commit

Permalink
Merge pull request #104 from SystemConsultantGroup/develop
Browse files Browse the repository at this point in the history
QA 배포를 위해 머지합니다.
  • Loading branch information
hynseok authored Mar 3, 2024
2 parents 9b6c880 + 2d68ea5 commit c83fd41
Show file tree
Hide file tree
Showing 14 changed files with 198 additions and 122 deletions.
2 changes: 1 addition & 1 deletion src/api/_types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const STAGE_LOOKUP_TABLE: StageLookupTable = {
};

export const STATUS_LOOKUP_TABLE: StatusLookupTable = {
UNEXAMINED: "심사 전",
UNEXAMINED: "진행중",
PASS: "합격",
FAIL: "불합격",
PENDING: "보류",
Expand Down
2 changes: 1 addition & 1 deletion src/app/student/result/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default async function StudentResultPage() {
};

const { end, after } = await checkPhase({
title: thesisInfo.stage === "MAIN" ? "본심 심사" : "예심 심사",
title: thesisInfo.stage === "MAIN" ? "본심 최종 심사" : "예심 최종 심사",
token,
});

Expand Down
26 changes: 16 additions & 10 deletions src/components/pages/AdminProfForm/AdminProfForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { RowGroup, BasicRow, TitleRow, ButtonRow } from "@/components/common/row
import { useAuth } from "@/components/common/AuthProvider/AuthProvider";
import { showNotificationError, showNotificationSuccess } from "@/components/common/Notifications";
import { DepartmentSelect } from "@/components/common/selects/DepartmentSelect";
import { User } from "@/api/_types/user";

interface Props {
professorId?: number | string;
Expand All @@ -30,6 +31,7 @@ function AdminProfForm({ professorId }: Props) {
const { login } = useAuth();
const [isPwEditing, setIsPwEditing] = useState<boolean>(false);
const [defaultDepartmentId, setDefaultDepartmentId] = useState<string | null>(null);
const [previousProf, setPreviousProf] = useState<User | undefined>();

const { onSubmit, getInputProps, setValues, isDirty, setFieldValue } =
useForm<AdminProfFormInputs>({
Expand Down Expand Up @@ -61,16 +63,16 @@ function AdminProfForm({ professorId }: Props) {
if (professorId) {
const response = await ClientAxios.get(API_ROUTES.professor.get(professorId));
const professorDetails = response.data;

setPreviousProf(professorDetails);
setValues({
loginId: professorDetails.loginId,
password: "",
name: professorDetails.name,
email: professorDetails.email,
phone: professorDetails.phone,
deptId: String(professorDetails.deptId),
deptId: String(professorDetails.department.id),
});
setDefaultDepartmentId(String(professorDetails.deptId));
setDefaultDepartmentId(String(professorDetails.department.id));
}
} catch (err) {
console.error(err);
Expand All @@ -86,13 +88,17 @@ function AdminProfForm({ professorId }: Props) {
message: "수정할 비밀번호를 입력하거나, 수정 취소 버튼을 눌러주세요.",
});
} else {
const body = {
...values,
...(!professorId || isPwEditing ? { password: values.password } : {}),
deptId: Number(values.deptId),
...(values.email ? { email: values.email } : {}),
...(values.phone ? { phone: values.phone } : {}),
};
const body = professorId
? {
...(isPwEditing ? { password: values.password } : {}),
deptId:
previousProf!.department.id === Number(values.deptId)
? undefined
: Number(values.deptId),
email: previousProf!.email === values.email ? undefined : values.email,
phone: previousProf!.phone === values.phone ? undefined : values.phone,
}
: { ...values };
if (!professorId) {
await ClientAxios.post(API_ROUTES.professor.post(), body);
showNotificationSuccess({ message: "교수 등록이 완료되었습니다." });
Expand Down
51 changes: 34 additions & 17 deletions src/components/pages/AdminStudentForm/AdminStudentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function AdminStudentForm({ studentId }: Props) {
initialValues: {
basicInfo: {
loginId: "",
password: "",
password: studentId ? undefined : "",
name: "",
email: "",
phone: "",
Expand Down Expand Up @@ -97,18 +97,34 @@ function AdminStudentForm({ studentId }: Props) {

const handleSubmit = async () => {
try {
if (isPwEditing && form.values.basicInfo.password === "") {
if (isPwEditing && form.values.basicInfo.password === undefined) {
showNotificationError({
message: "수정할 비밀번호를 입력하거나, 수정 취소 버튼을 눌러주세요.",
});
} else {
const basicInfo = {
...form.values.basicInfo,
...(!studentId || isPwEditing ? { password: form.values.basicInfo.password } : {}),
deptId: Number(form.values.basicInfo.deptId),
...(form.values.basicInfo.email ? { email: form.values.basicInfo.email } : {}),
...(form.values.basicInfo.phone ? { phone: form.values.basicInfo.phone } : {}),
};
let previous;
if (studentId) {
previous = (await ClientAxios.get(API_ROUTES.student.get(studentId))).data;
}
const basicInfo = studentId
? {
...(isPwEditing ? { password: form.values.basicInfo.password } : {}),
deptId:
previous.deptId === form.values.basicInfo.deptId
? undefined
: Number(form.values.basicInfo.deptId),
email:
previous.email === form.values.basicInfo.email
? undefined
: form.values.basicInfo.email,
phone:
previous.phone === form.values.basicInfo.phone
? undefined
: form.values.basicInfo.phone,
}
: {
...form.values.basicInfo,
};
if (headReviewer && checkReviewersLength(advisors) && checkReviewersLength(committees)) {
if (!studentId) {
/** 학생 등록 */
Expand Down Expand Up @@ -151,7 +167,7 @@ function AdminStudentForm({ studentId }: Props) {
const prevCommittees = prevReviewersRef.current?.committees;
const committeeIds = committees.map((committee) => Number(committee.profId));
const deletedCommitteeIds = prevCommittees
? prevCommittees.filter((prevAdvisor) => !advisorIds.includes(prevAdvisor))
? prevCommittees.filter((prevAdvisor) => !committeeIds.includes(prevAdvisor))
: [];
const addedCommitteeIds = prevCommittees
? committeeIds.filter((committeeId) => !prevCommittees.includes(committeeId))
Expand All @@ -171,20 +187,21 @@ function AdminStudentForm({ studentId }: Props) {
/** 지도교수, 심사위원 배정 */
const postPromises = [
...addedAdvisorIds.map((addedId) =>
ClientAxios.post(API_ROUTES.student.putReviewer(Number(studentId), addedId), {
role: "ADVISOR",
})
ClientAxios.post(
`${API_ROUTES.student.putReviewer(Number(studentId), addedId)}?role=advisor`
)
),
...addedCommitteeIds.map((addedId) =>
ClientAxios.post(API_ROUTES.student.putReviewer(Number(studentId), addedId), {
role: "COMMITTEE",
})
ClientAxios.post(
`${API_ROUTES.student.putReviewer(Number(studentId), addedId)}?role=committee`
)
),
];
await Promise.all(postPromises);

showNotificationSuccess({ message: "학생 정보 수정이 완료되었습니다." });
router.push(`/admin/students/${studentId}`);
router.refresh();
}
} else {
showNotificationError({
Expand All @@ -205,7 +222,7 @@ function AdminStudentForm({ studentId }: Props) {

return (
<>
<MainRegisterModal studentId={studentId} opened={opened} close={close} />
{studentId && <MainRegisterModal studentId={studentId} opened={opened} close={close} />}
<form onSubmit={form.onSubmit(handleSubmit)}>
<Stack gap="xl">
{studentId && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ function BasicInfoSection({ form, studentId, isPwEditing, handleIsPwEditing, ope

form.setFieldValue("basicInfo", {
loginId: studentDetails.loginId,
password: "",
password: undefined,
name: studentDetails.name,
email: studentDetails.email,
phone: studentDetails.phone,
deptId: String(studentDetails.department),
deptId: String(studentDetails.department.id),
});
setDefaultDepartmentId(String(studentDetails.department));
setDefaultDepartmentId(String(studentDetails.department.id));
}
} catch (error) {
console.error(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ClientAxios } from "@/api/ClientAxios";
import { API_ROUTES } from "@/api/apiRoute";
import { Stack, Button } from "@mantine/core";
import { RowGroup, ButtonRow } from "@/components/common/rows";
import { useEffect } from "react";
import ThesisTitleSection from "./ThesisTitleSection";
import AssignReviewerSection from "./AssignReviewerSection";
import useReviewersAssign from "../_hooks/useReviewersAssign";
Expand All @@ -18,8 +19,14 @@ interface Props {
function MainRegisterModal({ studentId, opened, close }: Props) {
const sysMainForm = useForm<AdminStudentFormInputs>({});
/** 본심 심사위원장 / 심사위원 설정*/
const { headReviewer, advisors, committees, handleReviewerCancel, handleReviewerAdd } =
useReviewersAssign();
const {
headReviewer,
advisors,
committees,
handleReviewerCancel,
handleReviewerAdd,
handleReviewersSet,
} = useReviewersAssign();

/** 본심 정보 등록하기 */
const handleSubmit = async () => {
Expand All @@ -39,6 +46,21 @@ function MainRegisterModal({ studentId, opened, close }: Props) {
}
};

useEffect(() => {
if (studentId) {
const fetchReviewer = async () => {
const response = await ClientAxios.get(API_ROUTES.student.getReviewer(Number(studentId)));
const reviewerDetails = response.data;
handleReviewersSet(
reviewerDetails.headReviewer,
reviewerDetails.advisors,
reviewerDetails.committees
);
};
fetchReviewer();
}
});

return (
<Modal
opened={opened}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type Stage = "PRELIMINARY" | "MAIN";
export interface AdminStudentFormInputs {
basicInfo: {
loginId: string;
password: string;
password?: string;
name: string;
email?: string;
phone?: string;
Expand Down
3 changes: 2 additions & 1 deletion src/components/pages/account/AdminInfoEditSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ function AdminInfoEditSection() {
password: "",
},
validate: {
password: isNotEmpty("비밀번호를 입력해주세요."),
password: (value, values) =>
isPwEditing && !values.password ? "비밀번호를 입력하거나 수정을 취소해주세요." : null,
},
});

Expand Down
66 changes: 26 additions & 40 deletions src/components/pages/account/UserInfoEditSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,19 @@ interface UserInfoEditFormInputs {
password: string;
email?: string;
phone?: string;
signFile?: File | null;
}

function UserInfoEditSection() {
const { user } = useAuth();
const { user, isLoading } = useAuth();
const [isPwEditing, setIsPwEditing] = useState(false);
const [file, setFile] = useState<File | null>(null);
const [isFileUpdated, setIsFileUpdated] = useState(false);

const {
values: formValues,
onSubmit,
getInputProps,
setFieldValue,
isDirty,
} = useForm<UserInfoEditFormInputs>({
const form = useForm<UserInfoEditFormInputs>({
initialValues: {
password: "",
email: user?.email,
phone: user?.phone,
signFile: null,
},
validate: {
password: (value, values) =>
Expand All @@ -43,34 +37,25 @@ function UserInfoEditSection() {
});

useEffect(() => {
formValues.phone = user?.phone;
formValues.email = user?.email;
}, [user]);

/**
* @todo add default file get
*/
// useEffect(() => {
// const fileResponse = await fetch(user?.signFile);
// setFile(null);
// });

const handleFileChange = (newFile: File | null) => {
setIsFileUpdated(true);
setFile(newFile);
};
if (!isLoading) {
form.values.email = user?.email;
form.values.phone = user?.phone;
form.setValues({
signFile: user?.signFile ? undefined : null,
});
}
}, [isLoading]);

const handleSubmit = async (values: UserInfoEditFormInputs) => {
try {
let fileResponse;
if (isFileUpdated && file) {
fileResponse = await uploadFile({ file, sizeLimit: 10000000 });
}
const signFileUUID = values.signFile
? (await uploadFile({ file: values.signFile! })).uuid
: undefined;
const body = {
password: isPwEditing ? values.password : undefined,
email: isDirty("email") ? values.email : undefined,
phone: isDirty("phone") ? values.phone : undefined,
signId: fileResponse ? fileResponse.uuid : undefined,
email: form.isDirty("email") ? values.email : undefined,
phone: form.isDirty("phone") ? values.phone : undefined,
signId: signFileUUID || undefined,
};
await ClientAxios.put(API_ROUTES.user.put(), body);
showNotificationSuccess({ message: "회원 정보가 수정되었습니다." });
Expand All @@ -80,20 +65,20 @@ function UserInfoEditSection() {
};

return (
<form onSubmit={onSubmit(handleSubmit)}>
<form onSubmit={form.onSubmit(handleSubmit)}>
<Stack gap={0}>
<RowGroup>
<BasicRow field="아이디">{user?.loginId}</BasicRow>
</RowGroup>
<RowGroup>
<BasicRow field="비밀번호">
<Group>
<PasswordInput {...getInputProps("password")} disabled={!isPwEditing} />
<PasswordInput {...form.getInputProps("password")} disabled={!isPwEditing} />
{isPwEditing ? (
<Group>
<Button
onClick={() => {
setFieldValue("password", "");
form.setFieldValue("password", "");
setIsPwEditing(false);
}}
color="red"
Expand All @@ -116,12 +101,12 @@ function UserInfoEditSection() {
</RowGroup>
<RowGroup>
<BasicRow field="이메일">
<TextInput {...getInputProps("email")} />
<TextInput {...form.getInputProps("email")} />
</BasicRow>
</RowGroup>
<RowGroup>
<BasicRow field="연락처">
<TextInput {...getInputProps("phone")} />
<TextInput {...form.getInputProps("phone")} />
</BasicRow>
</RowGroup>
<RowGroup>
Expand All @@ -133,8 +118,9 @@ function UserInfoEditSection() {
<RowGroup>
<FileUploadRow
field="서명 이미지"
onChange={handleFileChange}
defaultFile={file || undefined}
form={form}
formKey="signFile"
previousFile={user?.signFile}
/>
</RowGroup>
)}
Expand Down
Loading

0 comments on commit c83fd41

Please sign in to comment.