diff --git a/src/app/page.scss b/src/app/page.scss index 5468265..02adcaa 100644 --- a/src/app/page.scss +++ b/src/app/page.scss @@ -77,7 +77,7 @@ body { flex-direction: column; justify-content: center; align-items: center; - row-gap: 5vh; + row-gap: 5%; background-color: var(--primary); margin: 0px 10px; border-radius: .2em; diff --git a/src/app/page.tsx b/src/app/page.tsx index 2673054..52c7f0a 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -16,6 +16,7 @@ const App = () => { const dispatch = useDispatch(); const router = useRouter(); const login = useSelector((state: State) => state.login); + console.log(login) return ( <> @@ -62,26 +63,35 @@ const App = () => { } - { ['admin','tv','seller'].includes(login.key) && -
-

Administration / Affichage :

-
- { ['admin','seller'].includes(login.key) && -
router.push('/sell')}> - Vente -
- } - { login.key === 'admin' && -
router.push('/items')}> - Gestion -
- } -
router.push('/tv')}> - TV +
+ { ['admin','seller','preparator','tv'].includes(login.key) && + <> +

Autres controles :

+
+ { ['admin','seller'].includes(login.key) && +
router.push('/sell')}> + Vente +
+ } + { login.key === 'admin' && +
router.push('/items')}> + Gestion +
+ } + { ['admin','preparator'].includes(login.key) && +
router.push('/service')}> + Service +
+ } + { ['admin','tv'].includes(login.key) && +
router.push('/tv')}> + TV +
+ }
-
-
- } + + } +
); diff --git a/src/app/preparation/page.scss b/src/app/preparation/page.scss index 4107716..10d2b77 100644 --- a/src/app/preparation/page.scss +++ b/src/app/preparation/page.scss @@ -103,6 +103,11 @@ transition: transform 0.5s ease-in, opacity 0.5s ease-in; } + &.disabled { + visibility: hidden; + background-color: var(--warning-dark); + } + &.downgrade { background-color: var(--warning-dark); diff --git a/src/app/preparation/page.tsx b/src/app/preparation/page.tsx index ba521a9..6bcd89e 100644 --- a/src/app/preparation/page.tsx +++ b/src/app/preparation/page.tsx @@ -69,7 +69,7 @@ const Page = () => { const displayOrders = (orders: Array) => { - const tenMinutesAgo: moment.Moment = moment().subtract(10, 'minutes'); + const tenMinutesAgo: moment.Moment = moment().subtract(1, 'minutes'); const twentyMinutesAgo: moment.Moment = moment().subtract(20, 'minutes'); type itemQuantity = { @@ -122,7 +122,7 @@ const Page = () => { ) : ( -
editOrder(order)}> +
editOrder(order)}>
)} @@ -131,14 +131,9 @@ const Page = () => { {separate_by === 'item' && items.map((item) => (
- {/* x {item.quantity} */} x {item.quantity} - {/* {moment(order.createdAt).fromNow(true)} */}
    - {/*
  • - {item.name} -
  • */} {item.name}
diff --git a/src/app/service/page.scss b/src/app/service/page.scss new file mode 100644 index 0000000..73ebe18 --- /dev/null +++ b/src/app/service/page.scss @@ -0,0 +1,161 @@ +.preparation-mode-button { + padding: 0 10px; + width: 210px; + text-align: left; + height: 100%; + line-height: 50px; + + &.downgrade { + background-color: var(--warning-dark); + } +} + +#preparation { + display: flex; + height: calc(100% - 50px); + justify-content: space-between; + background-color: var(--primary); + + .status.service { + margin: auto; + width: 100%; + height: calc(100% - 20px); + padding: 10px 14px 0; + overflow-x: hidden; + overflow-y: auto; + scrollbar-color: var(--primary-light) transparent; + scrollbar-width: auto; + + .title { + font-size: 1.5em; + line-height: 60px; + } + + // Removes the visuals clicks for pending (because you can't downgrade a pending order) + &.pending .orders .order .next.downgrade { + background-color: var(--danger-dark); + } + } + + .status .orders.service { + width: calc(100% - 10px); + display: grid; + grid-template-columns: 50% 50%; + column-gap: 10px; + } + + .status .orders .order { + background: var(--primary-light); + padding-left: 10px; + position: relative; + display: flex; + justify-content: space-between; + align-items: center; + margin-bottom: 5px; + + .titles { + display: flex; + flex-direction: column; + margin: 5px 0; + width: 20%; + + .place, + .quantity { + font-size: 1.75em; + } + + .place { + margin-bottom: 10px; + } + } + + .items { + text-align: left; + margin-right: auto; + + .options { + font-style: italic; + } + } + + &.timewarning:before { + content: ""; + position: absolute; + left: 0; + top: 0; + width: 10px; + height: 100%; + } + + &.orange:before { + background-color: var(--toastify-color-warning); + } + + &.red:before { + background-color: var(--toastify-color-error); + } + + .next { + background-color: var(--success); + width: 20%; + font-size: 2em; + position: relative; + align-self: stretch; + display: flex; + flex-direction: column; + justify-content: center; + transition: background-color 0.5s ease-in; + + .fa { + transition: transform 0.5s ease-in, opacity 0.5s ease-in; + } + + &.downgrade { + background-color: var(--warning-dark); + + .fa { + transform: rotateZ(180deg); + } + } + + &:before { + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + } + + &:hover { + filter: brightness(0.9); + } + } + } +} + +.preparation-modal { + .actions { + display: flex; + flex-flow: row nowrap; + justify-content: center; + + .button { + display: inline-block; + padding: 40px 100px; + margin: 0 20px; + + color: #fff; + + &.cancel { + background: var(--danger); + } + + &.confirm { + background: var(--success); + } + + &:hover { + filter: brightness(0.9); + } + } + } +} diff --git a/src/app/service/page.tsx b/src/app/service/page.tsx new file mode 100644 index 0000000..e6fcb66 --- /dev/null +++ b/src/app/service/page.tsx @@ -0,0 +1,145 @@ +"use client"; +import React, { useEffect, useState } from "react"; +import "../page.scss"; +import "./page.scss"; +import Navbar from "../../components/navbar"; +import moment from "moment"; +import FontAwesome from "react-fontawesome"; +import { useSelector } from "react-redux"; +import { Order, State, Status } from "@/types"; +import { downgradeOrder, upgradeOrder } from "@/utils/orders"; +import Modal from "../../components/modals/modal"; +import Loader from "../../components/loader"; +import Separator from "../../components/UI/separator"; +import { useSearchParams } from "next/navigation"; + +const Page = () => { + const searchParams = useSearchParams(); + let orders = useSelector((state: State) => state.orders); + + // Renvoie les commandes contenant au moins un item dans la catégory du paramètre + if (searchParams.has("only")) { + orders = orders.filter((order) => + order.orderItems.some((orderItem) => orderItem.item.category.key == searchParams.get("only")) + ); + } + + // used only to refresh the component every minute + const [tictac, setTicTac] = useState(false); + const [loading, setLoading] = useState(null); + const [confirmOrder, setConfirmOrder] = useState(null); + const [downgradeMode, setDowngradeMode] = useState(false); + + // used only to refresh the component every minute to refresh the duration on the + useEffect(() => { + const interval = setInterval(() => { + setTicTac(!tictac); + }, 1000 * 60); + + return () => clearInterval(interval); + }); + + const editOrder = async (order: Order, confirmed = false) => { + // If ready to be confirmed + if (order.status === Status.READY && !confirmed && !downgradeMode) { + setConfirmOrder(order); + } + // If ready to be cancelled + else if (order.status === Status.PENDING && !confirmed && downgradeMode) { + setConfirmOrder(order); + } else { + if (!loading) { + setLoading(order); + try { + if (!downgradeMode) { + await upgradeOrder(order); + } else { + setDowngradeMode(false); + await downgradeOrder(order); + } + } catch (e) { + } + setLoading(null); + setConfirmOrder(null); + } + } + }; + + const displayOrders = (orders: Array) => { + + const tenMinutesAgo: moment.Moment = moment().subtract(10, 'minutes'); + const twentyMinutesAgo: moment.Moment = moment().subtract(20, 'minutes'); + + return ( +
+ {orders.map((order) => ( +
+
+ {order.place} + {moment(order.createdAt).fromNow(true)} +
+
    + {order.orderItems.map((orderItem, index) => ( +
  • + {orderItem.item.name} +
    + {orderItem.supplements.map((orderSuppl) => orderSuppl.supplement.name).join(", ")} +
    +
  • + ))} +
+ {loading && loading.id === order.id ? ( +
+ +
+ ) : ( +
editOrder(order)}> + +
+ )} +
+ ))} +
+ ); + }; + + return ( + <> + +
setDowngradeMode(!downgradeMode)} + className={`preparation-mode-button ${downgradeMode ? "downgrade" : ""}`}> + {!downgradeMode ? "Retour cuisine" : "Servir"} +
+
+
+
+ A servir + {displayOrders(orders.filter((order) => order.status === Status.READY))} +
+
+ + {downgradeMode ? ( +

Annuler la commande {confirmOrder && confirmOrder.place} ?

+ ) : ( +

La commande {confirmOrder && confirmOrder.place} a-t-elle bien été livrée ?

+ )} +
+
setConfirmOrder(null)}> + {loading ? : "Annuler"} +
+
{ + await editOrder(confirmOrder, true); + setConfirmOrder(null); + }}> + {loading ? : "Confirmer"} +
+
+
+ + ); +}; + +export default Page;