From b816af3020fb0d670a1d505430573de867ebaf0c Mon Sep 17 00:00:00 2001 From: Aya <90342033+Aya-X@users.noreply.github.com> Date: Mon, 3 Oct 2022 13:48:02 +0800 Subject: [PATCH] refactor: Update MenuItemOption to ModalContent --- src/components/MenuModalContent.jsx | 105 ++++++++++++++++++++++++++-- 1 file changed, 101 insertions(+), 4 deletions(-) diff --git a/src/components/MenuModalContent.jsx b/src/components/MenuModalContent.jsx index 7e4dacb..799707b 100644 --- a/src/components/MenuModalContent.jsx +++ b/src/components/MenuModalContent.jsx @@ -10,6 +10,95 @@ import apiHelper from '../utils/helpers'; import useInput from '../hooks/useInput'; import useCounter from '../hooks/useCounter'; +function MenuOptionList({ itemId, onClickItem }) { + // const { itemId } = useParams(); + // #TODO: WIP + const [optionData, setOptionData] = useState(null); + const [itemData, setItemData] = useState(null); + + useEffect(() => { + let isFetch = false; + + apiHelper.getMenuItem(itemId).then((res) => { + console.log(res); + + if (res?.data?.Status) { + console.log('getMenuItem:::', res?.data); + + const { Data, DetailList } = res.data; + console.log(DetailList[0]); + console.log(Data.ProductName); + + if (!isFetch) { + setOptionData(DetailList); + setItemData(Data); + } + /* end of IF(!isFetch) */ + } + /* end of IF(!Status) */ + }); + + return () => { + isFetch = true; + }; + }, [itemId]); + + if (!optionData || !itemData) { + return ( +

+ {itemId} + LOADING... +

+ ); + } + + return ( + <> +
+
+

{itemData.ProductName}

+ +

{`${itemData.Price} 元`}

+
+ +

商品選項

+ + +
+ {/* */} + + ); +} +/* end of MenuOptionList */ + +MenuOptionList.propTypes = { + itemId: PropTypes.oneOfType([ + PropTypes.object, + PropTypes.string, + PropTypes.number, + ]).isRequired, +}; + function MenuModalContent({ item, shopId }) { const navigate = useNavigate(); @@ -24,6 +113,13 @@ function MenuModalContent({ item, shopId }) { const thisMsg = useInput(''); + const onClickItem = (optionItemId) => { + console.log('optionItemId:::', optionItemId); + console.log('shopId:::', shopId); + return setClickOptionId(optionItemId); + }; + /* end of onClickItem() */ + return (
@@ -56,7 +152,6 @@ function MenuModalContent({ item, shopId }) {
       
 
       {/* Modal-Body */}
-
       
{ProductName ? (
@@ -69,10 +164,12 @@ function MenuModalContent({ item, shopId }) { )} {Id ? ( -

商品選項

+ <> +

商品選項

+ {/* // #TODO: WIP */} + + ) : ( - // #TODO: WIP - <>