diff --git a/packages/web/src/components/Chat/Header/SideMenu.tsx b/packages/web/src/components/Chat/Header/SideMenu.tsx index cfdafcf09..8e591877d 100644 --- a/packages/web/src/components/Chat/Header/SideMenu.tsx +++ b/packages/web/src/components/Chat/Header/SideMenu.tsx @@ -1,6 +1,7 @@ -import { memo, useCallback, useState } from "react"; +import { memo, useCallback, useEffect, useState } from "react"; import useIsTimeOver from "@/hooks/useIsTimeOver"; +import { useAxios } from "@/hooks/useTaxiAPI"; import DottedLine from "@/components/DottedLine"; import { @@ -26,6 +27,7 @@ import LogoutOutlinedIcon from "@mui/icons-material/LogoutOutlined"; import PeopleAltRoundedIcon from "@mui/icons-material/PeopleAltRounded"; import ReportGmailerrorredRoundedIcon from "@mui/icons-material/ReportGmailerrorredRounded"; import ShareRoundedIcon from "@mui/icons-material/ShareRounded"; +import WalletRoundedIcon from "@mui/icons-material/WalletRounded"; type SideMenuButtonProps = { type: "share" | "report" | "taxi"; @@ -72,6 +74,8 @@ const SideMenuButton = ({ type, onClick }: SideMenuButtonProps) => { }; const SideMenu = ({ roomInfo, isOpen, setIsOpen }: SideMenuProps) => { + const axios = useAxios(); + const setAlert = useSetRecoilState(alertAtom); const [isOpenShare, setIsOpenShare] = useState(false); const [isOpenCallTaxi, setIsOpenCallTaxi] = useState(false); @@ -90,6 +94,24 @@ const SideMenu = ({ roomInfo, isOpen, setIsOpen }: SideMenuProps) => { const onClickCallTaxi = useCallback(() => setIsOpenCallTaxi(true), []); const onClickReport = useCallback(() => setIsOpenReport(true), []); + const [taxiFare, setTaxiFare] = useState(0); + const getTaxiFare = async () => { + await axios({ + url: "/fare/getTaxiFare", + method: "get", + params: { + from: roomInfo.from._id.toString(), + to: roomInfo.to._id.toString(), + time: roomInfo.time, + }, + onSuccess: (data) => setTaxiFare(data.fare), + onError: (status) => {}, + }); + }; + + useEffect(() => { + getTaxiFare(); + }, []); const isAlone = roomInfo.part.length === 1; const styleBackground = { @@ -191,6 +213,15 @@ const SideMenu = ({ roomInfo, isOpen, setIsOpen }: SideMenuProps) => { +
+
+ +
+ 예상 택시비 : {taxiFare.toLocaleString("ko-KR")}원 +
+
+
+ diff --git a/packages/web/src/components/ModalPopup/Body/BodyRoomSelection.tsx b/packages/web/src/components/ModalPopup/Body/BodyRoomSelection.tsx index a9122a532..0a18e6de1 100644 --- a/packages/web/src/components/ModalPopup/Body/BodyRoomSelection.tsx +++ b/packages/web/src/components/ModalPopup/Body/BodyRoomSelection.tsx @@ -1,4 +1,4 @@ -import { useCallback, useMemo, useRef } from "react"; +import { useCallback, useMemo, useEffect, useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { useHistory } from "react-router-dom"; @@ -157,6 +157,25 @@ const BodyRoomSelection = ({ roomInfo }: BodyRoomSelectionProps) => { onCall.current = false; }, [roomInfo?._id, history]); + const [taxiFare, setTaxiFare] = useState(0); + const getTaxiFare = async () => { + await axios({ + url: "/fare/getTaxiFare", + method: "get", + params: { + from: roomInfo.from._id.toString(), + to: roomInfo.to._id.toString(), + time: roomInfo.time, + }, + onSuccess: (data) => setTaxiFare(data.fare), + onError: (status) => {}, + }); + }; + + useEffect(() => { + getTaxiFare(); + }, []); + const stylePlace = { width: "100%", display: "flex", @@ -217,6 +236,22 @@ const BodyRoomSelection = ({ roomInfo }: BodyRoomSelectionProps) => { + +
+

{`${taxiFare.toLocaleString("ko-KR")}원 / ${ + roomInfo?.part?.length + + (isAlreadyPart || isDepart || isRoomFull ? 0 : 1) + }명`}

+

+   + {`= 인당 ${Math.floor( + taxiFare / + (roomInfo?.part?.length + + (isAlreadyPart || isDepart || isRoomFull ? 0 : 1)) + ).toLocaleString("ko-KR")}원`} +

+
+
{isLogin || isRoomFull || isDepart ? (