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
11 changes: 7 additions & 4 deletions src/lib/buildProcessSteps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { ActionButton } from "@/components/photoManage/ActionButton";
import { RecipientInfoCard } from "@/components/photoManage/RecipientInfoCard";
import { formatEstimatedTime, formatShippedDate } from "@/utils/dateFormat";
import { getEarlyFinishedHours } from "@/utils/getEarlyFinishedHours";
import { getEarlyFinishedTime } from "@/utils/getEarlyFinishedTime";
import ProcessStepSubContent from "@/components/photoManage/ProcessStepSubContent";

type BuildStepsArgs = {
Expand Down Expand Up @@ -48,7 +48,7 @@ export function buildProcessSteps({
};

const earlyHours = workData.print
Copy link
Contributor

Choose a reason for hiding this comment

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

SHOULD: 함수명에 맞게 이것도 바꾸면 좋을 거 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

완료

? getEarlyFinishedHours(
? getEarlyFinishedTime(
workData.print.estimatedAt,
workData.print.completedAt,
)
Expand Down Expand Up @@ -129,11 +129,14 @@ export function buildProcessSteps({
workData.print?.status === "COMPLETED"
) {
const content = `작업 완료 시간: ${formatEstimatedTime(workData.print.completedAt)}`;
const subcontent = `예상 작업 시간보다 ${earlyHours}시간 빨리 완료되었어요!`;
return (
<ProcessStepSubContent
content={content}
subcontent={subcontent}
subcontent={
earlyHours !== -1
? `예상 작업 시간보다 ${earlyHours} 빨리 완료되었어요!`
: undefined
}
Comment on lines +135 to +139
Copy link
Contributor

Choose a reason for hiding this comment

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

high

현재 조건 earlyHours !== -1getEarlyFinishedTime 함수가 반환하는 문자열 "-1"을 올바르게 처리하지 못하여 버그를 유발할 수 있습니다. 예를 들어, 작업이 예상보다 늦게 끝나면 earlyHours는 문자열 "-1"이 되고, "-1" !== -1true이므로 "예상 작업 시간보다 -1 빨리 완료되었어요!"라는 잘못된 메시지가 표시됩니다. 또한, 유효하지 않은 날짜에 대해 빈 문자열("")이 반환될 때도 의도치 않은 메시지가 보일 수 있습니다. earlyHours가 유효한 시간 문자열일 때만 메시지를 표시하도록 조건을 수정해야 합니다.

Suggested change
subcontent={
earlyHours !== -1
? `예상 작업 시간보다 ${earlyHours} 빨리 완료되었어요!`
: undefined
}
subcontent={
(earlyHours !== -1 && earlyHours !== "" && earlyHours !== "-1")
? `예상 작업 시간보다 ${earlyHours} 빨리 완료되었어요!`
: undefined
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

완료

icon={<ClockIcon className="h-3 w-3" />}
/>
);
Expand Down
16 changes: 0 additions & 16 deletions src/utils/getEarlyFinishedHours.ts

This file was deleted.

34 changes: 34 additions & 0 deletions src/utils/getEarlyFinishedTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export function getEarlyFinishedTime(
estimatedAt: string | null,
completedAt: string | null,
): string {
if (!estimatedAt || !completedAt) return "";

const estimated = new Date(estimatedAt).getTime();
const completed = new Date(completedAt).getTime();

const diffMs = estimated - completed;

// 일찍 끝나지 않았으면
if (diffMs <= 0) return "-1";
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

조금 더 일관성 있고 사용하기 쉬운 API를 위해, 일찍 끝나지 않은 경우에 매직 스트링 "-1"을 반환하는 대신 빈 문자열("")을 반환하는 것을 고려해보세요. 이렇게 하면 이 함수를 사용하는 쪽에서 """-1"을 모두 확인해야 하는 번거로움을 줄일 수 있고, falsy 값 체크만으로 간단하게 로직을 처리할 수 있습니다.

Suggested change
if (diffMs <= 0) return "-1";
if (diffMs <= 0) return "";


const totalMinutes = Math.floor(diffMs / (1000 * 60));

const minutesInHour = 60;
const minutesInDay = 60 * 24;

// 1시간 미만 → 분
if (totalMinutes < minutesInHour) {
return `${totalMinutes}분`;
}

// 1일 미만 → 시간
if (totalMinutes < minutesInDay) {
const hours = Math.floor(totalMinutes / minutesInHour);
return `${hours}시간`;
}

// 1일 이상 → 일
const days = Math.floor(totalMinutes / minutesInDay);
return `${days}일`;
}