From 161ac76c90aaa7e1e9175e8f283c2e139e77d562 Mon Sep 17 00:00:00 2001 From: tsaichiehhuang Date: Wed, 23 Aug 2023 12:01:14 +0800 Subject: [PATCH 1/8] =?UTF-8?q?fix:=E5=85=88=E8=A8=82=E9=A4=90=E5=8F=88?= =?UTF-8?q?=E5=8E=BB=E8=A8=82=E4=BD=8D=E6=99=82=EF=BC=8C=E6=9C=83=E8=B7=B3?= =?UTF-8?q?=E5=87=BA=E6=8F=90=E7=A4=BA=E6=A1=86=E6=98=AF=E5=90=A6=E6=94=B9?= =?UTF-8?q?=E7=82=BA=E5=85=A7=E7=94=A8=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/Alert/Alert.module.scss | 4 ++++ frontend/src/pages/Booking/BookingInfoInput.js | 7 +++++-- frontend/src/pages/Booking/OrderPosition.js | 6 +++--- frontend/src/pages/Booking/[id].jsx | 17 +++++++++++++++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/Alert/Alert.module.scss b/frontend/src/components/Alert/Alert.module.scss index 2f424f2..be02661 100644 --- a/frontend/src/components/Alert/Alert.module.scss +++ b/frontend/src/components/Alert/Alert.module.scss @@ -34,6 +34,10 @@ font-style: normal; font-weight: 700; line-height: normal; + width: 80%; + display: flex; + align-items: center; + justify-content: center; } .context { color: var(--unnamed, #959595); diff --git a/frontend/src/pages/Booking/BookingInfoInput.js b/frontend/src/pages/Booking/BookingInfoInput.js index df155ca..9bb0dc1 100644 --- a/frontend/src/pages/Booking/BookingInfoInput.js +++ b/frontend/src/pages/Booking/BookingInfoInput.js @@ -8,8 +8,7 @@ import Cookies from 'js-cookie' const BookingInfoInput = ({ isOrderPosition, makeReservation, - setPhone, - phone + setIsChangeAlert }) => { const router = useRouter() const { id } = router.query @@ -26,6 +25,10 @@ const BookingInfoInput = ({ .matches(/^(09)\d{8}$/, '手機格式不正確') }) const handleSubmit = async (values) => { + setTimeout(() => { + setIsChangeAlert(true) + }, 1000) + const requestBody = { restaurantId: parseInt(id), headcount: parseInt(values.headcount), diff --git a/frontend/src/pages/Booking/OrderPosition.js b/frontend/src/pages/Booking/OrderPosition.js index 9053ba9..33f428f 100644 --- a/frontend/src/pages/Booking/OrderPosition.js +++ b/frontend/src/pages/Booking/OrderPosition.js @@ -11,7 +11,8 @@ const OrderPosition = ({ phone, setPhone, setIsWaitingCancelAlert, - setIsCancelAlert + setIsCancelAlert, + setIsChangeAlert }) => { const [isOrderPosition, setIsOrderPosition] = useState(false) @@ -168,8 +169,7 @@ const OrderPosition = ({ ) : ( diff --git a/frontend/src/pages/Booking/[id].jsx b/frontend/src/pages/Booking/[id].jsx index 1a7d786..d752c07 100644 --- a/frontend/src/pages/Booking/[id].jsx +++ b/frontend/src/pages/Booking/[id].jsx @@ -24,6 +24,8 @@ export default function Booking() { const [isEatHere, setIsEatHere] = useState(false) const [isCancelAlert, setIsCancelAlert] = useState(false) const [isWaitingCancelAlert, setIsWaitingCancelAlert] = useState(false) + const [isChangeAlert, setIsChangeAlert] = useState(false) + const phone = Cookies.get('phone') const restaurantId = parseInt(Cookies.get('restaurantsId')) const { cancleReservation, cancleBooking } = useCancel({ @@ -89,6 +91,17 @@ export default function Booking() { status='ok' /> )} + {isChangeAlert && ( + + )} {isCancelAlert && ( )} + {isWaitingCancelAlert && ( {chooseOrderPosition ? ( ) : (
From 724b20ce7ca785b8db2cfed684559d617791ef60 Mon Sep 17 00:00:00 2001 From: tsaichiehhuang Date: Wed, 23 Aug 2023 13:02:28 +0800 Subject: [PATCH 2/8] =?UTF-8?q?fix:order=20search=E5=A4=96=E5=B8=B6?= =?UTF-8?q?=E5=8F=AF=E5=8F=96=E6=B6=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/hook/useCancel.js | 39 ++++++++++++++++++++++++-- frontend/src/pages/Home/Restaurant.jsx | 19 ++++++++++--- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/frontend/src/hook/useCancel.js b/frontend/src/hook/useCancel.js index 4b91ccd..fdab743 100644 --- a/frontend/src/hook/useCancel.js +++ b/frontend/src/hook/useCancel.js @@ -1,6 +1,6 @@ import Cookies from 'js-cookie' -const useCancel = ({ phone, restaurantId }) => { +const useCancel = ({ phone, restaurantId, orderId }) => { // const restaurantId = parseInt(Cookies.get('restaurantsId')) // const phone = Cookies.get('phone') @@ -75,7 +75,42 @@ const useCancel = ({ phone, restaurantId }) => { } } - return { cancleReservation, cancleBooking } + async function cancleToGo() { + //外帶 + try { + const response = await fetch( + `https://107.22.142.48/api/1.0/orders/${orderId}/cancel`, + { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + phone: phone + }) + } + ) + if (!response.ok) { + throw new Error('Network response was not ok') + } + if (response.ok) { + // Cookies.remove('reservationId') + // Cookies.remove('isReserved') + // Cookies.remove('isEatHere') + // Cookies.remove('userGender') + // Cookies.remove('userName') + // Cookies.remove('phone') + // Cookies.remove('tableId') + setTimeout(() => { + window.location.reload() + }, 100) + } + console.log('取消外帶 response: ', response.json()) + } catch (error) { + console.error('Error fetching data:', error) + } + } + return { cancleReservation, cancleBooking, cancleToGo } } export default useCancel diff --git a/frontend/src/pages/Home/Restaurant.jsx b/frontend/src/pages/Home/Restaurant.jsx index 1dabb31..36bbe31 100644 --- a/frontend/src/pages/Home/Restaurant.jsx +++ b/frontend/src/pages/Home/Restaurant.jsx @@ -97,9 +97,10 @@ function getTags(order) { } export default function Restaurant({ type, restaurant, order, phone }) { - const { cancleReservation, cancleBooking } = useCancel({ + const { cancleReservation, cancleBooking, cancleToGo } = useCancel({ phone, - restaurantId: order?.restaurantId + restaurantId: order?.restaurantId, + orderId: order?.orderId }) return (
) )} @@ -160,7 +162,7 @@ function RestaurantInfo({ restaurant }) { ) } -function OrderHistory({ order, cancleReservation, cancleBooking }) { +function OrderHistory({ order, cancleReservation, cancleBooking, cancleToGo }) { const [isCancelAlert, setIsCancelAlert] = useState(false) const handleCancel = () => { if ( @@ -177,6 +179,14 @@ function OrderHistory({ order, cancleReservation, cancleBooking }) { ) { // 候位 cancleReservation() + } else if ( + order.tableId === null && + order.reservationId === null && + order.status === null && + order.orderId !== null + ) { + // 外帶 + cancleToGo() } } @@ -190,10 +200,11 @@ function OrderHistory({ order, cancleReservation, cancleBooking }) { context='真的要取消?' status='option' yes='保留' - no='取消訂位' + no='取消' onClickHandle={handleCancel} /> )} +
Date: Wed, 23 Aug 2023 13:30:27 +0800 Subject: [PATCH 3/8] =?UTF-8?q?style:=E6=89=80=E6=9C=89=E5=AD=97=E9=AB=94?= =?UTF-8?q?=E6=94=B9=E6=88=90Noto=20Sans=20TC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Alert/Alert.module.scss | 2 -- .../src/pages/Booking/Booking.module.scss | 21 +++++-------------- .../src/pages/Booking/BookingInfoInput.js | 6 +++--- frontend/src/pages/Cart/Cart.module.scss | 5 ----- frontend/src/pages/Home/Home.module.scss | 3 +-- .../src/pages/Product/Product.module.scss | 6 +----- frontend/src/styles/globals.css | 6 +++--- 7 files changed, 13 insertions(+), 36 deletions(-) diff --git a/frontend/src/components/Alert/Alert.module.scss b/frontend/src/components/Alert/Alert.module.scss index be02661..294548f 100644 --- a/frontend/src/components/Alert/Alert.module.scss +++ b/frontend/src/components/Alert/Alert.module.scss @@ -29,7 +29,6 @@ } .title { color: #000; - font-family: Inter; font-size: 18px; font-style: normal; font-weight: 700; @@ -41,7 +40,6 @@ } .context { color: var(--unnamed, #959595); - font-family: Inter; font-size: 16px; font-style: normal; font-weight: 400; diff --git a/frontend/src/pages/Booking/Booking.module.scss b/frontend/src/pages/Booking/Booking.module.scss index a1d0490..384b365 100644 --- a/frontend/src/pages/Booking/Booking.module.scss +++ b/frontend/src/pages/Booking/Booking.module.scss @@ -37,16 +37,13 @@ color: black; font-size: 24px; font-weight: 700; - font-family: 'Inter'; } .storeAddress { font-size: 14px; font-weight: 400; - font-family: 'Inter'; } .storePhone { color: var(--unnamed, #f58873); - font-family: 'Inter'; font-size: 12px; font-style: normal; font-weight: 400; @@ -61,7 +58,6 @@ height: 37px; width: 50%; color: #000; - font-family: 'Inter'; font-size: 16px; font-style: normal; font-weight: 500; @@ -91,7 +87,6 @@ } .inputTitle { color: #000; - font-family: 'Inter'; font-size: 16px; font-style: normal; font-weight: 400; @@ -113,11 +108,8 @@ } .errorMessage { bottom: 0; - // position: absolute; - // z-index: 2; display: grid; color: red; - font-family: 'Alkatra', sans-serif; font-size: 0.8rem; line-height: 1rem; margin-top: 5px; @@ -128,7 +120,6 @@ width: 309px; height: 53px; color: #000; - font-family: 'Inter'; font-size: 20px; letter-spacing: 2px; border-radius: 10px; @@ -140,7 +131,6 @@ width: 309px; height: 53px; color: #000; - font-family: 'Inter'; font-size: 20px; letter-spacing: 2px; border-radius: 10px; @@ -149,7 +139,6 @@ } .orderButtonRemind { color: $DarkGrey; - font-family: Inter; font-size: 10px; font-style: normal; font-weight: 400; @@ -159,7 +148,7 @@ // 我要訂餐 .storeIntro { white-space: pre-line; - font-family: 'Jaldi'; + font-size: 16px; } @@ -217,8 +206,8 @@ } .kindsTitle { width: 100%; - font-size: 20px; - font-weight: 700; + font-size: 22px; + font-weight: 600; border-bottom: 1px solid $lightGrey; padding-bottom: 10px; } @@ -233,11 +222,11 @@ padding-bottom: 10px; } .productName { - font-weight: 600; + font-weight: 500; + font-size: 18px; } .productIntro { color: $DarkGrey; - font-size: 16px; } .productChosenQuantity { diff --git a/frontend/src/pages/Booking/BookingInfoInput.js b/frontend/src/pages/Booking/BookingInfoInput.js index 9bb0dc1..90f86fe 100644 --- a/frontend/src/pages/Booking/BookingInfoInput.js +++ b/frontend/src/pages/Booking/BookingInfoInput.js @@ -25,9 +25,9 @@ const BookingInfoInput = ({ .matches(/^(09)\d{8}$/, '手機格式不正確') }) const handleSubmit = async (values) => { - setTimeout(() => { - setIsChangeAlert(true) - }, 1000) + // setTimeout(() => { + // setIsChangeAlert(true) + // }, 1000) const requestBody = { restaurantId: parseInt(id), diff --git a/frontend/src/pages/Cart/Cart.module.scss b/frontend/src/pages/Cart/Cart.module.scss index b656840..87fbc14 100644 --- a/frontend/src/pages/Cart/Cart.module.scss +++ b/frontend/src/pages/Cart/Cart.module.scss @@ -152,7 +152,6 @@ } .inputTitle { color: #000; - font-family: 'Inter'; font-size: 16px; font-style: normal; font-weight: 400; @@ -178,7 +177,6 @@ // z-index: 2; display: grid; color: red; - font-family: 'Alkatra', sans-serif; font-size: 0.8rem; line-height: 1rem; margin-top: 5px; @@ -189,7 +187,6 @@ width: 309px; height: 53px; color: #000; - font-family: 'Inter'; font-size: 20px; letter-spacing: 2px; border-radius: 10px; @@ -201,7 +198,6 @@ width: 309px; height: 53px; color: #000; - font-family: 'Inter'; font-size: 20px; letter-spacing: 2px; border-radius: 10px; @@ -209,7 +205,6 @@ } .orderButtonRemind { color: $DarkGrey; - font-family: Inter; font-size: 10px; font-style: normal; font-weight: 400; diff --git a/frontend/src/pages/Home/Home.module.scss b/frontend/src/pages/Home/Home.module.scss index 20e7b17..4257ae9 100644 --- a/frontend/src/pages/Home/Home.module.scss +++ b/frontend/src/pages/Home/Home.module.scss @@ -356,7 +356,7 @@ width: 85%; font-size: 16px; font-weight: 700; - font-family: 'Inter'; + margin-top: 1.5rem; border-bottom: 5px $mainYellow solid; padding-bottom: 20px; @@ -569,6 +569,5 @@ .noOrder { color: $mainRed; font-weight: 700; - font-family: 'Inter'; padding: 20px 0px; } diff --git a/frontend/src/pages/Product/Product.module.scss b/frontend/src/pages/Product/Product.module.scss index cdb3b4b..4d43d47 100644 --- a/frontend/src/pages/Product/Product.module.scss +++ b/frontend/src/pages/Product/Product.module.scss @@ -66,17 +66,14 @@ .storeName { color: black; font-size: 24px; - font-weight: 700; - font-family: 'Inter'; + font-weight: 600; } .storeAddress { font-size: 14px; font-weight: 400; - font-family: 'Inter'; } .storePhone { color: var(--unnamed, #f58873); - font-family: 'Inter'; font-size: 12px; font-style: normal; font-weight: 400; @@ -90,7 +87,6 @@ height: 37px; width: 50%; color: #000; - font-family: 'Inter'; font-size: 16px; font-style: normal; font-weight: 500; diff --git a/frontend/src/styles/globals.css b/frontend/src/styles/globals.css index 1f30312..4ef97dd 100644 --- a/frontend/src/styles/globals.css +++ b/frontend/src/styles/globals.css @@ -1,9 +1,9 @@ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap'); - +@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC&display=swap'); body { background: white; display: flex; align-items: center; justify-content: center; - font-family: 'Inter'; -} \ No newline at end of file + font-family: 'Noto Sans TC', sans-serif, 'Inter'; +} From f9239eff11aa92ca3d3606eaebc82f3fdd0bd7a4 Mon Sep 17 00:00:00 2001 From: yihsuan Date: Wed, 23 Aug 2023 13:46:38 +0800 Subject: [PATCH 4/8] feat:change orderstauts while takeout is switch to eat in, fix: search table/reservation in certain restaurant --- backend/controller/reservation/orderToIn.js | 51 +++++++++++ backend/controller/reservation/reserve.js | 27 +++--- backend/index.js | 8 ++ backend/model/reserveModel.js | 95 ++++++++++++++++++++- 4 files changed, 164 insertions(+), 17 deletions(-) create mode 100644 backend/controller/reservation/orderToIn.js diff --git a/backend/controller/reservation/orderToIn.js b/backend/controller/reservation/orderToIn.js new file mode 100644 index 0000000..c25f733 --- /dev/null +++ b/backend/controller/reservation/orderToIn.js @@ -0,0 +1,51 @@ + +import { hasOrder, changeOrdertoIn, changeOrdertoWait } from '../../model/reserveModel.js'; + +function ReqIsNumber(s) { + return parseFloat(s).toString() !== "NaN"; +} + +export async function changeOrderStatus(req, res) { + try { + const { restaurantId, tableId, reservationId, phone } = req.body; + console.log(restaurantId) + console.log(tableId) + console.log(reservationId) + console.log(phone) + + if (!restaurantId || !phone || !phone.startsWith('09') || !ReqIsNumber(restaurantId)) { + return res.status(400).json({ error: 'Wrong format in request body.' }); + } + const phoneNum = parseInt(phone, 10); + const isOrdered = await hasOrder(restaurantId,phoneNum); + + if (!isOrdered) { + return res.status(404).json({ + error: 'Phone not found in orderList.', + }); + } + + + if (tableId !== null) { + const orderstatusIn = await changeOrdertoIn(restaurantId, phoneNum, tableId) + console.log(orderstatusIn); + if(orderstatusIn === null ){ + return res.status(404).json({ error: 'No data found' }); + } + return res.status(200).json({ data: {orderId:orderstatusIn} }) + } + + if (reservationId !== null) { + const orderstatusWait = await changeOrdertoWait(restaurantId, phoneNum, reservationId) + console.log(orderstatusWait); + if(orderstatusWait === null ){ + return res.status(404).json({ error: 'No data found' }); + } + return res.status(200).json({ data: {orderId:orderstatusWait} }) + } + + } catch (error) { + console.error('Error in tableCancel:', error); + return res.status(500).json({ error: 'Internal server error' }); + } +} \ No newline at end of file diff --git a/backend/controller/reservation/reserve.js b/backend/controller/reservation/reserve.js index 553f0d6..2787a03 100644 --- a/backend/controller/reservation/reserve.js +++ b/backend/controller/reservation/reserve.js @@ -4,14 +4,13 @@ import {insertReservation} from '../../model/reserveModel.js'; import {updateTableVacancy} from '../../model/reserveModel.js'; import {checkExistingReservation} from '../../model/reserveModel.js'; import {getWaitCount} from '../../model/reserveModel.js'; - +import {hasOrder} from '../../model/reserveModel.js'; export async function reservationReserve(req, res) { try { const { restaurantId, headcount, name, gender, phone } = req.body; - // Check if request body is missing if (!restaurantId || !headcount || !name || !gender || !phone||!phone.startsWith('09')) { return res.status(400).json({ error: 'Missing request body fields.' }); } @@ -19,44 +18,46 @@ export async function reservationReserve(req, res) { const phoneNum = parseInt(phone, 10); - const isTable = await checkExistingTable(phoneNum); + const isTable = await checkExistingTable(restaurantId, phoneNum); if (isTable) { console.log("you alreayd have a seat, you can't reserve again!"); - return res.status(400).json({ error: 'You already have an existing seat.' }); + return res.status(400).json({ error: 'You already have an existing seat in this restaurant.' }); } console.log("you don't have a seat!, I will check if you have a reservation"); - const isReserve = await checkExistingReservation(phoneNum); + const isReserve = await checkExistingReservation(restaurantId,phoneNum); if (isReserve) { - console.log("you already have a reservation in this restaurant"); - return res.status(400).json({ error: 'You already have an reservation.' }); + return res.status(400).json({ error: 'You already have an reservation in this restaurant.' }); } - console.log("you don't have a reservation in this restaurant"); - + const isVacancy = await hasVacancy(restaurantId, headcount); console.log(`isVancy is ${isVacancy}`); console.log(`!isVancy is ${!isVacancy}`); if (isVacancy) { console.log("there is vancancy") const updateTableId = await updateTableVacancy(phoneNum,headcount); - console.log("Good, you already have a seat"); - + console.log("Good, you already have a seat in this restaurant"); + + const isOrdered = await hasOrder(restaurantId,phoneNum); + return res.status(200).json({data:{ "tableId": updateTableId, "reservationId":null, "reservationCount": null, + "order" : isOrdered }}); } console.log("there is no vancancy") + const isOrdered = await hasOrder(restaurantId,phoneNum); - const inserReservationId = await insertReservation(phone, headcount, restaurantId); const reserveCount = await getWaitCount(restaurantId); - console.log(`Sorry, you need to wait a while...${reserveCount}`); + console.log(`Sorry, you need to wait a while...for${reserveCount}`); return res.status(200).json({data:{ "tableId": null, "reservationId": inserReservationId, "reservationCount": reserveCount, + "order" : isOrdered }}); } catch (error) { diff --git a/backend/index.js b/backend/index.js index 175a019..1e4b082 100644 --- a/backend/index.js +++ b/backend/index.js @@ -9,6 +9,7 @@ import { restaurantList } from './controller/restaurant/list.js'; import { restaurantProfile } from './controller/restaurant/profile.js'; import { reservationReserve } from './controller/reservation/reserve.js'; import { reservationPending } from './controller/reservation/pending.js'; +import { changeOrderStatus } from './controller/reservation/orderToIn.js'; import { reservationCancel } from './controller/reservation/reserveCancel.js'; import { restaurantVacancy } from './controller/restaurant/vacancy.js'; import { menuSearch } from './controller/menu/search.js'; @@ -23,6 +24,9 @@ import { orderCheckout } from './controller/order/checkout.js'; + + + /************************* * global config *************************/ @@ -80,6 +84,10 @@ app.post(`/api/${process.env.apiVer}/orders/request`, orderRequest); app.get(`/api/${process.env.apiVer}/orders/pending`, orderPending); app.get(`/api/${process.env.apiVer}/orders/detail`, orderDetail); app.get(`/api/${process.env.apiVer}/orders/order`, OrderSummary); +app.post(`/api/${process.env.apiVer}/reservations/orderstatus`, changeOrderStatus); + + + diff --git a/backend/model/reserveModel.js b/backend/model/reserveModel.js index acbfc22..9c09a15 100644 --- a/backend/model/reserveModel.js +++ b/backend/model/reserveModel.js @@ -1,9 +1,9 @@ import { pool } from './util.js'; -export async function checkExistingTable(phone) { +export async function checkExistingTable(restaurantId,phone) { try { - const [rows] = await pool.query('SELECT * FROM tableList WHERE phone = ?', [phone]); + const [rows] = await pool.query('SELECT * FROM tableList WHERE restaurantId=? AND phone = ?', [restaurantId,phone]); console.log('Query result:', rows); return rows.length > 0; } catch (error) { @@ -12,9 +12,9 @@ export async function checkExistingTable(phone) { } } - export async function checkExistingReservation(phone) { + export async function checkExistingReservation(restaurantId,phone) { try { - const [rows] = await pool.query('SELECT * FROM Reservation WHERE phone = ?', [phone]); + const [rows] = await pool.query('SELECT * FROM Reservation WHERE restaurantId=? AND phone = ?', [restaurantId,phone]); console.log('checkExistingReservation result:', rows); return rows.length > 0; } catch (error) { @@ -78,3 +78,90 @@ export async function getWaitCount(restaurantId) { throw error; } } + + + export async function hasOrder(restaurantId,phoneNum) { + try { + const [res] = await pool.query( + 'SELECT id FROM OrderList WHERE restaurantId = ? AND phone = ? AND reservationId IS NULL AND tableId IS NULL', + [restaurantId, phoneNum] + ); + console.log(`result of return ${res.length}`); + return res.length > 0; + } catch (error) { + console.error('Error in checkhasOrder:', error); + throw error; + } + } + + export async function changeOrdertoIn(restaurantId, phoneNum, tableId) { + const connection = await pool.getConnection(); + + try { + await connection.beginTransaction(); + + const [orderRows] = await connection.query( + 'SELECT id FROM OrderList WHERE restaurantId = ? AND phone = ? AND reservationId IS NULL AND tableId IS NULL', + [restaurantId, phoneNum] + ); + + if (orderRows.length > 0) { + const orderId = orderRows[0].id; + + await connection.query( + 'UPDATE OrderList SET tableId = ? WHERE id = ?', + [tableId, orderId] + ); + await connection.commit(); + return orderId; + } + await connection.commit(); + return null; + + } catch (error) { + await connection.rollback(); + console.error('Error in changeOrdertoIn:', error); + throw error; + } finally { + connection.release(); + } + } + + + + export async function changeOrdertoWait(restaurantId, phoneNum, reservationId) { + const connection = await pool.getConnection(); + + try { + await connection.beginTransaction(); + + const [orderRows] = await connection.query( + 'SELECT id FROM OrderList WHERE restaurantId = ? AND phone = ? AND reservationId IS NULL AND tableId IS NULL', + + [restaurantId, phoneNum] + ); + + if (orderRows.length > 0) { + const orderId = orderRows[0].id; + + await connection.query( + 'UPDATE OrderList SET reservationId = ? WHERE id = ?', + [reservationId, orderId] + ); + await connection.commit(); + return orderId; + } + + await connection.commit(); + return null; + + } catch (error) { + await connection.rollback(); + console.error('Error in changeOrdertoWait:', error); + throw error; + } finally { + connection.release(); + } + } + + \ No newline at end of file From 8db71e02d96630c24c62c6879efc6fdddab33e2c Mon Sep 17 00:00:00 2001 From: tsaichiehhuang Date: Wed, 23 Aug 2023 13:47:21 +0800 Subject: [PATCH 5/8] =?UTF-8?q?style:=E5=AD=97=E9=AB=94=E6=94=B9=E5=AE=8C?= =?UTF-8?q?=E5=BE=8Cfont-weight=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/pages/Home/Home.module.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/pages/Home/Home.module.scss b/frontend/src/pages/Home/Home.module.scss index 4257ae9..b8b6248 100644 --- a/frontend/src/pages/Home/Home.module.scss +++ b/frontend/src/pages/Home/Home.module.scss @@ -169,7 +169,7 @@ .text { font-size: 12px; - font-weight: 700; + font-weight: 600; color: #fff; } } @@ -472,7 +472,7 @@ position: absolute; left: 45px; font-size: 12px; - font-weight: 700; + font-weight: 500; color: #fff; z-index: 999; } From e335846bc4d1b790c639270fb8588597b11ba02e Mon Sep 17 00:00:00 2001 From: tsaichiehhuang Date: Wed, 23 Aug 2023 14:23:12 +0800 Subject: [PATCH 6/8] =?UTF-8?q?fix:=E8=A8=82=E4=BD=8D=E5=BE=8C=EF=BC=8C?= =?UTF-8?q?=E5=A4=96=E5=B8=B6=E5=8F=AF=E4=BB=A5=E6=94=B9=E6=88=90=E5=85=A7?= =?UTF-8?q?=E7=94=A8(=E4=B8=B2oderstatus=20API)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/Alert/Alert.module.scss | 1 + frontend/src/hook/useCancel.js | 6 ++-- frontend/src/hook/useOrderStatus.js | 36 +++++++++++++++++++ frontend/src/hook/useReservation.js | 7 +++- .../src/pages/Booking/BookingInfoInput.js | 4 --- frontend/src/pages/Booking/[id].jsx | 23 +++++++++--- 6 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 frontend/src/hook/useOrderStatus.js diff --git a/frontend/src/components/Alert/Alert.module.scss b/frontend/src/components/Alert/Alert.module.scss index 294548f..58666ce 100644 --- a/frontend/src/components/Alert/Alert.module.scss +++ b/frontend/src/components/Alert/Alert.module.scss @@ -13,6 +13,7 @@ justify-content: center; align-items: center; gap: 10px; + padding: 10px 0; } .overlay { position: absolute; diff --git a/frontend/src/hook/useCancel.js b/frontend/src/hook/useCancel.js index fdab743..312a512 100644 --- a/frontend/src/hook/useCancel.js +++ b/frontend/src/hook/useCancel.js @@ -31,7 +31,7 @@ const useCancel = ({ phone, restaurantId, orderId }) => { Cookies.remove('tableId') setTimeout(() => { window.location.reload() - }, 100) + }, 50) } if (!response.ok) { throw new Error('Network response was not ok') @@ -67,7 +67,7 @@ const useCancel = ({ phone, restaurantId, orderId }) => { Cookies.remove('tableId') setTimeout(() => { window.location.reload() - }, 100) + }, 50) } console.log('取消訂位 response: ', response.json()) } catch (error) { @@ -103,7 +103,7 @@ const useCancel = ({ phone, restaurantId, orderId }) => { // Cookies.remove('tableId') setTimeout(() => { window.location.reload() - }, 100) + }, 50) } console.log('取消外帶 response: ', response.json()) } catch (error) { diff --git a/frontend/src/hook/useOrderStatus.js b/frontend/src/hook/useOrderStatus.js new file mode 100644 index 0000000..b903fba --- /dev/null +++ b/frontend/src/hook/useOrderStatus.js @@ -0,0 +1,36 @@ +import { useState, useEffect } from 'react' +import Cookies from 'js-cookie' + +const useOrderStatus = () => { + const [reservationInfo, setReservationInfo] = useState(null) + + const OrderChange = async (requestBody) => { + try { + const response = await fetch( + `https://107.22.142.48/api/1.0/reservations/orderstatus`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(requestBody) + } + ) + + if (response.ok) { + const data = await response.json() + setTimeout(() => { + window.location.reload() + }, 50) + } + } catch (error) { + console.error(error) + } + } + return { + reservationInfo, + OrderChange + } +} + +export default useOrderStatus diff --git a/frontend/src/hook/useReservation.js b/frontend/src/hook/useReservation.js index 739491e..aab645a 100644 --- a/frontend/src/hook/useReservation.js +++ b/frontend/src/hook/useReservation.js @@ -1,7 +1,7 @@ import { useState, useEffect } from 'react' import Cookies from 'js-cookie' -const useReservation = () => { +const useReservation = ({ setIsChangeAlert }) => { const [reservationInfo, setReservationInfo] = useState(null) const [reservationError, setReservationError] = useState(null) const [isAlert, setIsAlert] = useState(false) @@ -42,6 +42,11 @@ const useReservation = () => { Cookies.set('userGender', requestBody.gender) Cookies.set('phone', requestBody.phone) } + if (data.data.order === true) { + setTimeout(() => { + setIsChangeAlert(true) + }, 1000) + } } else { setReservationError(data.error) if (reservationError === 'You already have an reservation.') { diff --git a/frontend/src/pages/Booking/BookingInfoInput.js b/frontend/src/pages/Booking/BookingInfoInput.js index 90f86fe..8db630d 100644 --- a/frontend/src/pages/Booking/BookingInfoInput.js +++ b/frontend/src/pages/Booking/BookingInfoInput.js @@ -25,10 +25,6 @@ const BookingInfoInput = ({ .matches(/^(09)\d{8}$/, '手機格式不正確') }) const handleSubmit = async (values) => { - // setTimeout(() => { - // setIsChangeAlert(true) - // }, 1000) - const requestBody = { restaurantId: parseInt(id), headcount: parseInt(values.headcount), diff --git a/frontend/src/pages/Booking/[id].jsx b/frontend/src/pages/Booking/[id].jsx index d752c07..939a49f 100644 --- a/frontend/src/pages/Booking/[id].jsx +++ b/frontend/src/pages/Booking/[id].jsx @@ -11,27 +11,29 @@ import Alert from '@/components/Alert' import useMenu from '@/hook/useMenu' import useRestaurantProfile from '@/hook/useRestaurantProfile' import useCancel from '@/hook/useCancel' +import useOrderStatus from '@/hook/useOrderStatus' export default function Booking() { const router = useRouter() const { id } = router.query Cookies.set('restaurantsId', id) const [chooseOrderPosition, setChooseOrderPosition] = useState(true) //訂位or訂餐 - const { makeReservation, isAlert, setIsAlert, reservationType } = - useReservation() + const { menuInfo } = useMenu(id) const { profileData, isLoading } = useRestaurantProfile(id) const [isEatHere, setIsEatHere] = useState(false) const [isCancelAlert, setIsCancelAlert] = useState(false) const [isWaitingCancelAlert, setIsWaitingCancelAlert] = useState(false) const [isChangeAlert, setIsChangeAlert] = useState(false) - + const { makeReservation, isAlert, setIsAlert, reservationType } = + useReservation({ setIsChangeAlert }) const phone = Cookies.get('phone') const restaurantId = parseInt(Cookies.get('restaurantsId')) const { cancleReservation, cancleBooking } = useCancel({ phone, restaurantId }) + const { OrderChange } = useOrderStatus() useEffect(() => { if (Cookies.get('isReserved')) { if (Cookies.get('isReserved').includes(id)) { @@ -49,7 +51,18 @@ export default function Booking() { setChooseOrderPosition(false) } }, []) - + const handleOrderChange = async () => { + const phone = Cookies.get('phone') + const tableId = parseInt(Cookies.get('tableId')) + const reservationId = parseInt(Cookies.get('reservationId')) + const requestBody = { + restaurantId: parseInt(id), + phone: phone, + tableId: tableId, + reservationId: reservationId + } + await OrderChange(requestBody) + } return ( {isLoading ? ( @@ -99,7 +112,7 @@ export default function Booking() { status='option' yes='保持外帶' no='改成內用' - // onClickHandle={cancleBooking} + onClickHandle={handleOrderChange} /> )} {isCancelAlert && ( From 841e4616c1370944419b6431420254338dc00bf1 Mon Sep 17 00:00:00 2001 From: Zobyyy Date: Wed, 23 Aug 2023 14:23:27 +0800 Subject: [PATCH 7/8] style(checkout page): adjust order list border style to border-box --- .../src/pages/Checkout/Checkout.module.scss | 27 +++++++++++++++++-- frontend/src/pages/Checkout/OrderDetail.jsx | 2 +- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/Checkout/Checkout.module.scss b/frontend/src/pages/Checkout/Checkout.module.scss index f4b8a4f..93650da 100644 --- a/frontend/src/pages/Checkout/Checkout.module.scss +++ b/frontend/src/pages/Checkout/Checkout.module.scss @@ -83,15 +83,26 @@ align-items: center; overflow-y: auto; + &::-webkit-scrollbar { + width: 1px; + } + &::-webkit-scrollbar-track-piece { + background: transparent; + } + &::-webkit-scrollbar-button { + background: transparent; + } + .order { - width: 30rem; - height: 7rem; + width: 32rem; + height: 8rem; background-color: #fff; border: 1px solid $Grey; border-radius: 20px; display: flex; align-items: center; padding: 0px 1.5rem; + box-sizing: border-box; cursor: pointer; .block { @@ -163,6 +174,18 @@ height: 55%; overflow: auto; + &::-webkit-scrollbar { + width: 1px; + } + + &::-webkit-scrollbar-track-piece { + background: transparent; + } + + &::-webkit-scrollbar-button { + background: transparent; + } + .detailItem { border-bottom: 1px solid $Grey; width: 100%; diff --git a/frontend/src/pages/Checkout/OrderDetail.jsx b/frontend/src/pages/Checkout/OrderDetail.jsx index f818302..8c8649e 100644 --- a/frontend/src/pages/Checkout/OrderDetail.jsx +++ b/frontend/src/pages/Checkout/OrderDetail.jsx @@ -32,7 +32,7 @@ export default function OrderDetail() {

總金額

NT${detail?.total}

- +
) } From ab9e6affd9c8e739f11865cdabc46d2029319d16 Mon Sep 17 00:00:00 2001 From: Zobyyy Date: Wed, 23 Aug 2023 14:25:47 +0800 Subject: [PATCH 8/8] style(checkout page): order list style --- frontend/src/pages/Checkout/Checkout.module.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/Checkout/Checkout.module.scss b/frontend/src/pages/Checkout/Checkout.module.scss index 93650da..d094d96 100644 --- a/frontend/src/pages/Checkout/Checkout.module.scss +++ b/frontend/src/pages/Checkout/Checkout.module.scss @@ -94,7 +94,7 @@ } .order { - width: 32rem; + width: 32.5rem; height: 8rem; background-color: #fff; border: 1px solid $Grey;