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

[Bug/#394] CSV 버그 수정 #395

Merged
merged 1 commit into from
Sep 13, 2024
Merged
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
10 changes: 7 additions & 3 deletions src/pages/ticketholderlist/TicketHolderList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const headers = [
{ label: "예매상태", key: "bookingStatus" },
];

const CSVDataArr: CSVDataType[] = [];

const TicketHolderList = () => {
const [CSVDataArr, setCSVDataArr] = useState<CSVDataType[]>([]);

const { performanceId } = useParams();
const [reservedCount, setReservedCount] = useState(0);

Expand Down Expand Up @@ -93,20 +93,24 @@ const TicketHolderList = () => {
setInitBookingStatuses(immutableBookingStatuses);

//전체 데이터를 기반으로 csv 추출 데이터 구축
const tempCSVDataArr: CSVDataType[] = [];

data.bookingList.map((item) => {
const date = item.createdAt.split("T")[0];
const time = item.createdAt.split("T")[1].slice(0, 5);
const formattedDate = date?.replace(/-/g, ".");
const formattedCreateTime = `${formattedDate} ${time}`;

CSVDataArr.push({
tempCSVDataArr.push({
createdAt: formattedCreateTime,
scheduleNumber: `${convertingNumber(item.scheduleNumber)}회차`,
bookerName: item.bookerName,
purchaseTicketCount: `${item.purchaseTicketCount}매`,
bookerPhoneNumber: item.bookerPhoneNumber,
bookingStatus: convertingBookingStatus(item.bookingStatus),
});

setCSVDataArr(tempCSVDataArr);
});
}
Comment on lines +96 to 115
Copy link
Member

Choose a reason for hiding this comment

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

p1
지금 코드 보면 tempCSVDataArr에 데이터를 추가하고, 반복문 안에서 계속 불필요하게 setCSVDataArr를 호출하고 있어!
tempCSVDataArr에 데이터를 모두 넣고, 반복문이 끝난 후에 한 번만 호출해도 될 것 같아!
이렇게 상태를 한 번에 업데이트하면 불필요한 상태 변경이 없어도 되서 무결성도 유지하면서, 성능도 더 괜찮을 것 같아!

아래 코드를 실행시켜 본 건 아닌데! 이런 식으로 하면 좋을 듯!

const tempCSVDataArr: CSVDataType[] = data.bookingList.map((item) => {
  const date = item.createdAt.split("T")[0];
  const time = item.createdAt.split("T")[1].slice(0, 5);
  const formattedDate = date?.replace(/-/g, ".");
  const formattedCreateTime = `${formattedDate} ${time}`;

  return {
    createdAt: formattedCreateTime,
    scheduleNumber: `${convertingNumber(item.scheduleNumber)}회차`,
    bookerName: item.bookerName,
    purchaseTicketCount: `${item.purchaseTicketCount}매`,
    bookerPhoneNumber: item.bookerPhoneNumber,
    bookingStatus: convertingBookingStatus(item.bookingStatus),
  };
});

setCSVDataArr(tempCSVDataArr);

Copy link
Contributor

Choose a reason for hiding this comment

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

와웅........ 좋은 방법인 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오 코드를 졸면서 짰나.. 좋은 지적 고마워 !!
바로 반영할게 👍

}, [data]);
Expand Down
Loading