From b61141f0b3a18473b322a8a34bcc210e02171045 Mon Sep 17 00:00:00 2001 From: sujikim Date: Mon, 14 Aug 2023 18:15:32 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=EB=B6=88=ED=95=84=EC=9A=94=ED=95=9C?= =?UTF-8?q?=20=ED=83=80=EC=9E=85=EC=B2=B4=ED=81=AC=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/date.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/util/date.ts b/src/util/date.ts index 42267704..f9d73be0 100644 --- a/src/util/date.ts +++ b/src/util/date.ts @@ -1,11 +1,8 @@ -import { isNumber, isString } from "./typeCheck"; /* 기본적인 날짜표시 형식 20yy-mm-dd */ - const dateReg = /^(20\d{2})-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])$/; export const isFormattedDate = (string: string) => RegExp(dateReg).test(string); export const dateFormat = (string: string) => { - if (isFormattedDate(string)) return string; return string?.slice(0, 10)?.replace(".", "-") || ""; }; @@ -23,7 +20,6 @@ export const splitDate = (string: string) => /* string 형식의 날짜 비교 */ export const dateLessThan = (date: string, now = nowDate) => { - if (!isString(date) || !isString(now)) return undefined; return dateFormat(date) < now; }; @@ -44,7 +40,6 @@ export const isExpiredDate = (expireDateString: string) => { }; export const addDay = (num: number, date = nowDate) => { - if (!isString(date) || !isNumber(num)) return date; const splited = splitDate(dateFormat(date)); if (!splited) return date; const [year, month, day] = splited; From 66e64b64e0b5bcc625dc8dbcf1a099455fc74575 Mon Sep 17 00:00:00 2001 From: sujikim Date: Mon, 14 Aug 2023 18:17:29 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix:=20addDay=20=EB=82=A0=EC=A7=9C=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/date.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util/date.ts b/src/util/date.ts index f9d73be0..32eefbfc 100644 --- a/src/util/date.ts +++ b/src/util/date.ts @@ -40,9 +40,7 @@ export const isExpiredDate = (expireDateString: string) => { }; export const addDay = (num: number, date = nowDate) => { - const splited = splitDate(dateFormat(date)); - if (!splited) return date; - const [year, month, day] = splited; - const dateObj = new Date(year, month - 1, day); + if (!isFormattedDate(date)) return date; + const dateObj = new Date(date); return dateFormat(addDayDateObject(dateObj, num).toISOString()); }; From eb7810464b2dfd2567a1aada2585dcee8df41c77 Mon Sep 17 00:00:00 2001 From: sujikim Date: Mon, 14 Aug 2023 18:32:44 +0900 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20string=20=ED=98=95=ED=83=9C?= =?UTF-8?q?=EC=9D=98=20=EB=82=A0=EC=A7=9C=20=EB=B9=84=EA=B5=90=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20compareDate=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/util/date.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/util/date.ts b/src/util/date.ts index 32eefbfc..26d6c454 100644 --- a/src/util/date.ts +++ b/src/util/date.ts @@ -19,8 +19,16 @@ export const splitDate = (string: string) => ?.map(v => parseInt(v)) || []; /* string 형식의 날짜 비교 */ +export const compareDate = ( + date1: string, + date2 = nowDate, + compare: (date1: string, date2: string) => boolean, +) => { + return compare(dateFormat(date1), dateFormat(date2)); +}; + export const dateLessThan = (date: string, now = nowDate) => { - return dateFormat(date) < now; + return compareDate(date, now, (date1, date2) => date1 < date2); }; /* 날짜 및 시간 계산 */ From b5dd738782d3ff7538fbf415edf61d0e6d423628 Mon Sep 17 00:00:00 2001 From: sujikim Date: Mon, 14 Aug 2023 18:33:55 +0900 Subject: [PATCH 4/4] =?UTF-8?q?refactor:=20=EB=8C=80=EC=B6=9C=EC=A0=9C?= =?UTF-8?q?=ED=95=9C=EC=9D=BC=20=EA=B3=84=EC=82=B0=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=EB=B0=8F=20=ED=86=B5=ED=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/mypage/Mypage.tsx | 37 ++----------------- .../userManagement/UserBriefInfo.tsx | 35 ++---------------- src/util/date.ts | 22 +++++++++++ 3 files changed, 29 insertions(+), 65 deletions(-) diff --git a/src/component/mypage/Mypage.tsx b/src/component/mypage/Mypage.tsx index d3002b5a..7a1fcb8f 100644 --- a/src/component/mypage/Mypage.tsx +++ b/src/component/mypage/Mypage.tsx @@ -4,6 +4,7 @@ import { myPageTabList } from "../../constant/tablist"; import { useTabFocus } from "../../hook/useTabFocus"; import { useNewDialog } from "../../hook/useNewDialog"; import { useGetUsersSearchId } from "../../api/users/useGetUsersSearchId"; +import { lendingRestriction } from "../../util/date"; import MyRent from "./MyRentInfo/MyRent"; import MyReservation from "./MyReservation"; import MyReview from "./MyReview"; @@ -65,35 +66,6 @@ const Mypage = () => { }; }, []); - const concatDate = (day: Date) => { - if (!userInfo) return ""; - let overDueDate = ""; - day.setDate(day.getDate() + userInfo.overDueDay); - overDueDate += day.getFullYear(); - overDueDate += "-"; - overDueDate += - day.getMonth() + 1 >= 10 - ? day.getMonth() + 1 - : "0".concat(`${day.getMonth() + 1}}`); - overDueDate += "-"; - overDueDate += - day.getDate() >= 10 ? day.getDate() : "0".concat(`${day.getDate()}`); - return overDueDate; - }; - - const getOverDueDate = () => { - if ( - !userInfo || - (userInfo && - (!userInfo.penaltyEndDate || - new Date(userInfo.penaltyEndDate).setHours(0, 0, 0, 0) < - new Date().setHours(0, 0, 0, 0))) - ) { - return concatDate(new Date()); - } - return concatDate(new Date(userInfo.penaltyEndDate)); - }; - return ( <> {deviceMode === "desktop" && ( @@ -170,11 +142,8 @@ const Mypage = () => { 대출제한 - {userInfo.overDueDay || - (userInfo.penaltyEndDate && - new Date(userInfo.penaltyEndDate).setHours(0, 0, 0, 0) >= - new Date().setHours(0, 0, 0, 0)) - ? `${getOverDueDate()} 까지` + {lendingRestriction(userInfo).isRestricted + ? `${lendingRestriction(userInfo).restrictionDate} 까지` : "-"} 정보수정 diff --git a/src/component/userManagement/UserBriefInfo.tsx b/src/component/userManagement/UserBriefInfo.tsx index 7205cb1b..50664cc7 100644 --- a/src/component/userManagement/UserBriefInfo.tsx +++ b/src/component/userManagement/UserBriefInfo.tsx @@ -1,8 +1,9 @@ +import { User } from "../../type"; +import { lendingRestriction } from "../../util/date"; import Image from "../utils/Image"; import UserUsage from "../../asset/img/book-arrow-right.svg"; import UserEdit from "../../asset/img/edit.svg"; import "../../asset/css/UserBriefInfo.css"; -import { User } from "../../type"; const roles = ["미인증", "일반", "사서", "운영진"]; const USAGE = 1; @@ -26,30 +27,7 @@ const UserBriefInfo = ({ user, line, setModal, setSelectedUser }: Props) => { setModal(EDIT); }; - const concatDate = (day: Date) => { - let overDueDate = ""; - - day.setDate(day.getDate() + user.overDueDay); - overDueDate += day.getFullYear(); - overDueDate += "-"; - overDueDate += day.getMonth() + 1 < 10 ? "0" : ""; - overDueDate += day.getMonth() + 1; - overDueDate += "-"; - overDueDate += day.getDate() < 10 ? "0" : ""; - overDueDate += day.getDate(); - return overDueDate; - }; - - const getOverDueDate = () => { - if ( - !user.penaltyEndDate || - new Date(user.penaltyEndDate).setHours(0, 0, 0, 0) < - new Date().setHours(0, 0, 0, 0) - ) { - return concatDate(nowDay); - } - return concatDate(new Date(user.penaltyEndDate)); - }; + const { isRestricted, restrictionDate } = lendingRestriction(user); return (
@@ -68,12 +46,7 @@ const UserBriefInfo = ({ user, line, setModal, setSelectedUser }: Props) => { )}
{user.email}
- {user.overDueDay || - (user.penaltyEndDate && - new Date(user.penaltyEndDate).setHours(0, 0, 0, 0) >= - new Date().setHours(0, 0, 0, 0)) - ? getOverDueDate() - : "-"} + {isRestricted ? restrictionDate : "-"}
{user.nickname ? (