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 ? (