Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 지원현황/면접기록 목록페이지에서 합불상태를 조회할 수 있다. #213

Merged
merged 13 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
12 changes: 9 additions & 3 deletions frontend/components/applicant/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useQuery } from "@tanstack/react-query";
import { useSearchParams } from "next/navigation";
import { ORDER_MENU } from "@/src/constants";
import { useSearchQuery } from "@/src/hooks/useSearchQuery";
import { type ApplicantPassState } from "../../src/apis/kanban";

interface ApplicantBoardProps {
generation: string;
Expand Down Expand Up @@ -59,8 +60,10 @@ const ApplicantBoard = ({ generation }: ApplicantBoardProps) => {
"name"
)}`,
subElements: [
applicantDataFinder(value, "field1"),
applicantDataFinder(value, "field2"),
`${applicantDataFinder(value, "field1")}/${applicantDataFinder(
value,
"field2"
)}`,
`${applicantDataFinder(value, "grade")} ${applicantDataFinder(
value,
"semester"
Expand All @@ -71,11 +74,14 @@ const ApplicantBoard = ({ generation }: ApplicantBoardProps) => {
Number(applicantDataFinder(value, "uploadDate"))
).toLocaleString("ko-KR", { dateStyle: "short" }),
],
passState: `${
applicantDataFinder(value, "passState").passState
}` as ApplicantPassState,
}));

return (
<Board
wapperClassname="divide-x"
wrapperClassname="divide-x"
boardData={createSearchData(true) ?? boardData}
onClick={onClick}
>
Expand Down
82 changes: 20 additions & 62 deletions frontend/components/common/board/Board.tsx
Original file line number Diff line number Diff line change
@@ -1,92 +1,50 @@
"use client";

import { PropsWithChildren, useState } from "react";
import BoardCell from "./BoardCell.component";
import Modal from "react-modal";
import Image from "next/image";
import CloseImage from "/public/icons/ellipsis.multiply.svg";
import { cn } from "@/src/utils/cn";
import Txt from "../Txt.component";
import { type PropsWithChildren } from "react";
import useModalState from "../../../src/hooks/useModalState";
import BoardModal from "./BoardModal";
import BoardTable from "./BoardTable";
import { type ApplicantPassState } from "../../../src/apis/kanban";

interface BoardData {
export interface BoardData {
id: string;
title: string;
subElements: string[];
time?: Date;
passState?: ApplicantPassState;
}

interface BoardProps extends PropsWithChildren {
onClick?: (id: string) => void;
wapperClassname?: string;
wrapperClassname?: string;
boardData: BoardData[];
}

const Board = ({
children,
onClick,
wapperClassname,
wrapperClassname,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapperClassName으로 작성하는게 좋아보입니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오타 제보 감사용 .

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boardData,
}: BoardProps) => {
const [isOpen, setIsOpen] = useState(false);
const { isOpen, openModal, closeModal } = useModalState();

const openModel = (id: string) => {
setIsOpen(true);
const handleModalOpen = (id: string) => () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오...! 커링으로 작성한 것은 처음 보네요..!
저는 이렇게 사용해본 경험이 없어서 그런데, 해당 로직을 이런 형식으로사용했을 때 얻을 수 있는 장점이 무엇이 있나요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

일단은 현재 커링을 쓴 이유는 컴포넌트를 분리함에 따라 이벤트 핸들러를 넘겨줘야 하는데,
기존 코드를 유지하기 위해 사용하였습니다.

마찬가지로 특정 이벤트 핸들러를 상위 컴포넌트에서 전달해주는데 각 요소 별로 전달해야할 값들이 있을 때 유용하다고 생각합니다^^

말이 장황할 수 있는데 현재 PR 코드 보시는 느낌 그대로라고 생각하시면 될 거 같습니다 !

openModal();
onClick && onClick(id);
};
const closeModel = () => setIsOpen(false);

return (
<section className="flex flex-col">
{boardData.length === 0 ? (
<Txt>검색결과가 없습니다.</Txt>
) : (
<>
{boardData.map((item) => (
<BoardCell
key={item.id}
title={item.title}
subElements={item.subElements}
onClick={() => openModel(item.id)}
/>
))}
</>
)}
<Modal
style={{
content: {
width: "calc(100% - 12rem)",
zIndex: "9999",
height: "calc(100%)",
margin: "3rem 6rem 0 6rem",
minWidth: "1280px",
boxShadow: "0px 0px 6px 1px rgba(0, 0, 0, 0.14)",
border: "none",
position: "relative",
inset: "0",
padding: "2.5rem 3rem",
},
overlay: {
padding: "0",
position: "absolute",
},
}}
<>
<BoardTable boardRows={boardData} handleModalOpen={handleModalOpen} />
<BoardModal
isOpen={isOpen}
onRequestClose={closeModel}
onRequestClose={closeModal}
ariaHideApp={false}
wrapperClassname={wrapperClassname}
>
<button className="absolute z-10" onClick={closeModel}>
<Image src={CloseImage} alt="close" />
</button>
<div
className={cn(
"flex pt-8 absolute h-[calc(100%-6rem)] w-[calc(100%-6rem)]",
wapperClassname
)}
>
{children}
</div>
</Modal>
</section>
{children}
</BoardModal>
</>
);
};

Expand Down
12 changes: 11 additions & 1 deletion frontend/components/common/board/BoardCell.component.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import { type ApplicantPassState } from "../../../src/apis/kanban";
import PassStateLabel from "../../passState/PassStateLabel";
import Txt from "../Txt.component";

export interface BoardCellProps {
title: string;
subElements: string[];
passState?: ApplicantPassState;
score?: string;
onClick?: () => void;
}

const BoardCell = ({ title, subElements, score, onClick }: BoardCellProps) => {
const BoardCell = ({
title,
subElements,
score,
passState,
onClick,
}: BoardCellProps) => {
return (
<button className="flex border-t py-4 justify-between" onClick={onClick}>
<Txt typography="h6" className="flex-[2_0_0] text-left truncate">
{title}
</Txt>
{passState && <PassStateLabel passState={passState} />}
<div className="flex gap-20 flex-[2_0_0] text-center truncate">
{subElements.map((subElement, index) => (
<Txt
Expand Down
52 changes: 52 additions & 0 deletions frontend/components/common/board/BoardModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import Modal from "react-modal";
import CloseImage from "/public/icons/ellipsis.multiply.svg";
import Image from "next/image";
import { cn } from "@/src/utils/cn";

const modalStyle = {
content: {
width: "calc(100% - 12rem)",
zIndex: "9999",
height: "calc(100%)",
margin: "3rem 6rem 0 6rem",
minWidth: "1280px",
boxShadow: "0px 0px 6px 1px rgba(0, 0, 0, 0.14)",
border: "none",
position: "relative",
inset: "0",
padding: "2.5rem 3rem",
},
overlay: {
padding: "0",
position: "absolute",
},
} as const;

interface BoardModalProps extends Modal.Props {
wrapperClassname?: string;
}

const BoardModal = ({
wrapperClassname,
style,
children,
...props
}: BoardModalProps) => {
return (
<Modal style={{ ...modalStyle, ...style }} {...props}>
<button className="absolute z-10" onClick={props.onRequestClose}>
<Image src={CloseImage} alt="close" />
</button>
<div
className={cn(
"flex pt-8 absolute h-[calc(100%-6rem)] w-[calc(100%-6rem)]",
wrapperClassname
)}
>
{children}
</div>
</Modal>
);
};

export default BoardModal;
31 changes: 31 additions & 0 deletions frontend/components/common/board/BoardTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import Txt from "../Txt.component";
import { BoardData } from "./Board";
import BoardCell from "./BoardCell.component";

interface BoardTableProps {
boardRows: BoardData[];
handleModalOpen: (id: string) => () => void;
}
const BoardTable = ({ boardRows, handleModalOpen }: BoardTableProps) => {
return (
<section className="flex flex-col">
{boardRows.length === 0 ? (
<Txt>검색결과가 없습니다.</Txt>
) : (
<>
{boardRows.map(({ id, title, subElements, passState }) => (
<BoardCell
key={id}
title={title}
subElements={subElements}
passState={passState}
onClick={handleModalOpen(id)}
/>
))}
</>
)}
</section>
);
};

export default BoardTable;
29 changes: 18 additions & 11 deletions frontend/components/interview/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import { useAtom } from "jotai";
import { interViewApplicantIdState } from "@/src/stores/interview/Interview.atom";
import { useSearchParams } from "next/navigation";
import { getInterviewRecordByPageWithOrder } from "@/src/apis/interview";
import { ORDER_MENU } from "@/src/constants";
import { CHARACTERS, ORDER_MENU } from "@/src/constants";
import { useSearchQuery } from "@/src/hooks/useSearchQuery";
import { removeAll } from "@/src/functions/replacer";

interface InterviewBoardProps {
generation: string;
Expand All @@ -34,7 +35,7 @@ const InterviewBoard = ({ generation }: InterviewBoardProps) => {
});
};

const { data, isLoading } = useQuery({
const { data, status } = useQuery({
queryKey: ["allInterviewRecord", pageIndex, order, generation],
queryFn: () =>
getInterviewRecordByPageWithOrder({
Expand All @@ -44,29 +45,35 @@ const InterviewBoard = ({ generation }: InterviewBoardProps) => {
}),
});

if (!data || isLoading) {
if (status === "loading") {
return <div>loading...</div>;
}

const { records } = data;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

구조 분해를 하나의 데이터만 하는 것은 좋은 코드가 아니여서 이렇게 하신건가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

음, 꼭 그런건 아니구요
굳이 사용할 필요가 없어보여서 사용하지 않았습니다!

if (status === "error") {
return <div>에러가 발생하였습니다. 잠시 후 다시 시도해보세요.</div>;
}
2yunseong marked this conversation as resolved.
Show resolved Hide resolved

const boardData = records.map((value) => {
const boardData = data.records.map((value) => {
return {
id: value.applicantId,
title: value.name,
subElements: [
value.field1.split('"').join(""),
value.field2.split('"').join(""),
`${value.grade.split('"').join("")} ${value.semester
.split('"')
.join("")}`,
removeAll(value.field1, CHARACTERS.DOUBLE_QUOTE).concat(
CHARACTERS.SLASH,
removeAll(value.field2, CHARACTERS.DOUBLE_QUOTE)
),
2yunseong marked this conversation as resolved.
Show resolved Hide resolved
removeAll(value.grade, CHARACTERS.DOUBLE_QUOTE).concat(
CHARACTERS.SPACE,
removeAll(value.semester, CHARACTERS.DOUBLE_QUOTE)
),
],
passState: value.state.passState,
};
});

return (
<Board
wapperClassname="divide-x"
wrapperClassname="divide-x"
boardData={createSearchData() ?? boardData}
onClick={(id) => onClick(id)}
>
Expand Down
27 changes: 27 additions & 0 deletions frontend/components/passState/PassStateLabel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ApplicantPassState } from "../../src/apis/kanban";
import { getApplicantPassState } from "../../src/functions/formatter";
import Txt from "../common/Txt.component";

interface PassStateLabelProps {
passState: ApplicantPassState;
}

// TODO: if you want more reusable component, it's should get addtional prop that custom css style.
const PassStateLabel = ({ passState }: PassStateLabelProps) => {
2yunseong marked this conversation as resolved.
Show resolved Hide resolved
return (
<Txt
className="w-full flex-1 last:text-right truncate"
color={
passState === "non-passed"
? "red"
: passState === "final-passed"
? "blue"
: "black"
}
>
{getApplicantPassState(passState)}
</Txt>
);
};

export default PassStateLabel;
5 changes: 5 additions & 0 deletions frontend/src/apis/interview/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { https } from "@/src/functions/axios";
import { PageInfo } from "../applicant";
import { type ApplicantPassState } from "../kanban";

export interface RecordsRes {
applicantId: string;
Expand All @@ -12,6 +13,10 @@ export interface RecordsRes {
grade: string;
semester: string;
modifiedAt: string;
// TODO: 더 범용적이고 재사용 가능하게 타입 선언이 필요함.
state: {
passState: ApplicantPassState;
};
}

interface RecordsByPageRes {
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,9 @@ export const needValidatePath = [
];

export const MAX_TEXT_LENGTH = 1000;

export const CHARACTERS = {
DOUBLE_QUOTE: '"',
SLASH: "/",
SPACE: " ",
};
3 changes: 3 additions & 0 deletions frontend/src/functions/replacer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ export const replacer = (value: string, type: ReplacerType) => {

export const replaceTwoString = (original: number, by: string = "0") =>
original.toString().padStart(2, by);

export const removeAll = (str: string, pattern: string | RegExp) =>
str.replaceAll(pattern, "");
Loading