Skip to content

Commit

Permalink
fix: migrate routes to app folder
Browse files Browse the repository at this point in the history
sell is not working but the others are displaying
  • Loading branch information
Zalk0 committed Nov 27, 2023
1 parent 337c659 commit 6177ba9
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 190 deletions.
File renamed without changes.
33 changes: 17 additions & 16 deletions src/routes/items.tsx → src/app/items/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import React, { useState } from 'react';

import './items.scss';
import Navbar from '../components/navbar';
import Switch from '../components/switch';
import { useSelector } from 'react-redux';
import { Category as CategoryType, IBuyable, State } from '../types';
import FontAwesome from 'react-fontawesome';
import { formatPrice } from '@/utils/format';
import { toggleAvailable } from '@/utils/items';
"use client";
import React, { useState } from "react";
import "../page.scss";
import "./page.scss";
import Navbar from "../../components/navbar";
import Switch from "../../components/switch";
import { useSelector } from "react-redux";
import { Category as CategoryType, IBuyable, State } from "../../types";
import FontAwesome from "react-fontawesome";
import { formatPrice } from "@/utils/format";
import { toggleAvailable } from "@/utils/items";

const Item = ({ item }: { item: IBuyable }) => {
return (
<div
className={'supplements' in item ? 'item' : 'item supplement'}
onClick={() => toggleAvailable('supplements' in item ? item.id : `S${item.id}`)}>
className={"supplements" in item ? "item" : "item supplement"}
onClick={() => toggleAvailable("supplements" in item ? item.id : `S${item.id}`)}>
<div className="left-side">
<Switch on={item.available} />
<span>{item.name}</span>
Expand All @@ -31,15 +32,15 @@ const Category = ({ category }: { category: CategoryType }) => {
return (
<div className="category">
<div className="title" onClick={() => setOpen(!isOpen)}>
<FontAwesome name={`chevron-right ${isOpen ? 'open' : ''}`} className="icon" />
<FontAwesome name={`chevron-right ${isOpen ? "open" : ""}`} className="icon" />
{category.name}
</div>
{isOpen && (
<div className="items">
{category.items.map((item, itemIndex) =>
[item, ...item.supplements].map((entry, entryIndex) => (
<Item item={entry} key={`${itemIndex}-${entryIndex}`} />
)),
))
)}
</div>
)}
Expand All @@ -52,7 +53,7 @@ export const itemsAvailable = (categories: Array<CategoryType>) =>
return acc + curr.items.filter((item) => item.available).length;
}, 0);

const Items = () => {
const Page = () => {
const categories = useSelector((state: State) => state.categories);

return (
Expand All @@ -70,4 +71,4 @@ const Items = () => {
);
};

export default Items;
export default Page;
36 changes: 18 additions & 18 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import StoreProvider from '@/store';
import React from 'react';
import { Flip, ToastContainer } from 'react-toastify';
import '../../public/fontawesome/css/all.min.css';
import StoreProvider from "@/store";
import React from "react";
import { Flip, ToastContainer } from "react-toastify";
import "../../public/fontawesome/css/all.min.css";

export const metadata = {
charset: 'utf-8',
title: 'TurboBouffe',
charset: "utf-8",
title: "TurboBouffe",
description: "Site de gestion de la bouffe de l'UA",
icons: {
icon: '/favicon.ico',
apple: '/logo192.png',
icon: "/favicon.ico",
apple: "/logo192.png"
},
themeColor: '#fb560c',
manifest: '/manifest.json',
themeColor: "#fb560c",
manifest: "/manifest.json",
viewport: {
width: 'device-width',
initialScale: 1,
},
width: "device-width",
initialScale: 1
}
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="fr">
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<StoreProvider>{children}</StoreProvider>
<ToastContainer autoClose={3000} transition={Flip} hideProgressBar={true} pauseOnHover={true} />
</body>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<StoreProvider>{children}</StoreProvider>
<ToastContainer autoClose={3000} transition={Flip} hideProgressBar={true} pauseOnHover={true} />
</body>
</html>
);
}
File renamed without changes.
35 changes: 18 additions & 17 deletions src/routes/login.tsx → src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import React, { ReactNode, useState } from 'react';

import './login.scss';
import { useDispatch } from 'react-redux';
import { tryLogin } from '@/reducers/login';
import FontAwesome from 'react-fontawesome';
import { Action } from '@/types';

const Login = () => {
"use client";
import React, { ReactNode, useState } from "react";
import "../page.scss";
import "./page.scss";
import { useDispatch } from "react-redux";
import { tryLogin } from "@/reducers/login";
import FontAwesome from "react-fontawesome";
import { Action } from "@/types";

const Page = () => {
const digits = [
['1', '2', '3'],
['4', '5', '6'],
['7', '8', '9'],
[<FontAwesome key="backspace" name="backspace" />, '0', <FontAwesome key="check" name="check" />],
["1", "2", "3"],
["4", "5", "6"],
["7", "8", "9"],
[<FontAwesome key="backspace" name="backspace" />, "0", <FontAwesome key="check" name="check" />]
];

const dispatch = useDispatch();
const [pin, setPin] = useState('');
const [pin, setPin] = useState("");

const onClick = async (digit: string | ReactNode) => {
switch (digit) {
Expand All @@ -25,7 +26,7 @@ const Login = () => {

case digits[3][2]:
dispatch(tryLogin(pin) as unknown as Action);
setPin('');
setPin("");
break;

default:
Expand All @@ -39,7 +40,7 @@ const Login = () => {
<span className="title" onClick={() => window.location.reload()}>
TurboBouffe
</span>
<div className="field">{pin.replace(/./g, '•')}</div>
<div className="field">{pin.replace(/./g, "•")}</div>
<div className="digits">
{digits.map((digitsRow, index) => (
<div className="digits-row" key={index}>
Expand All @@ -56,4 +57,4 @@ const Login = () => {
);
};

export default Login;
export default Page;
31 changes: 31 additions & 0 deletions src/app/page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,34 @@ body {
width: 0; /* Remove scrollbar space */
background: transparent; /* Optional: just make scrollbar invisible */
}
.logout {
padding-right: 14px;
}

#index {
display: flex;
flex-direction: row;
justify-content: center;
flex-wrap: wrap;
align-items: stretch;
height: calc(100% - 50px);
font-size: 3em;

div {
height: calc(33% - 20px - 4px);
width: calc(50% - 20px - 4px - 20px);
display: flex;
justify-content: center;
align-items: center;
background-color: var(--primary);
margin: 10px;

.fa {
margin-right: 15px;
}

&:hover {
filter: brightness(0.9);
}
}
}
24 changes: 12 additions & 12 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use client';
import React from 'react';
import 'react-toastify/dist/ReactToastify.css';
import 'moment/locale/fr';
import './page.scss';
import moment from 'moment';
import { useDispatch } from 'react-redux';
import Navbar from '@/components/navbar';
import FontAwesome from 'react-fontawesome';
import { logout } from '@/reducers/login';
import { Action } from 'redux';
"use client";
import React from "react";
import "react-toastify/dist/ReactToastify.css";
import "moment/locale/fr";
import "./page.scss";
import moment from "moment";
import { useDispatch } from "react-redux";
import Navbar from "@/components/navbar";
import FontAwesome from "react-fontawesome";
import { logout } from "@/reducers/login";
import { Action } from "redux";

moment.locale('fr');
moment.locale("fr");

const App = () => {
const dispatch = useDispatch();
Expand Down
File renamed without changes.
54 changes: 27 additions & 27 deletions src/routes/preparation.tsx → src/app/preparation/page.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import React, { useEffect, useState } from 'react';
"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";

import './preparation.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 { useLocation } from 'react-router';
import queryString from 'query-string';
import Modal from '../components/modals/modal';
import Loader from '../components/loader';
import Separator from '../components/UI/separator';

const Preparation = () => {
const location = useLocation();
const queryParams = queryString.parse(location.search);
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 (queryParams.only) {
if (searchParams.has("only")) {
orders = orders.filter((order) =>
order.orderItems.some((orderItem) => orderItem.item.category.key === queryParams.only),
order.orderItems.some((orderItem) => orderItem.item.category.key == searchParams.get("only"))
);
}

Expand Down Expand Up @@ -58,7 +57,8 @@ const Preparation = () => {
setDowngradeMode(false);
await downgradeOrder(order);
}
} catch (e) {}
} catch (e) {
}
setLoading(null);
setConfirmOrder(null);
}
Expand All @@ -79,7 +79,7 @@ const Preparation = () => {
<li key={index}>
{orderItem.item.name}
<div className="options">
{orderItem.supplements.map((orderSuppl) => orderSuppl.supplement.name).join(', ')}
{orderItem.supplements.map((orderSuppl) => orderSuppl.supplement.name).join(", ")}
</div>
</li>
))}
Expand All @@ -89,7 +89,7 @@ const Preparation = () => {
<Loader />
</div>
) : (
<div className={`next ${downgradeMode ? 'downgrade' : ''}`} onClick={() => editOrder(order)}>
<div className={`next ${downgradeMode ? "downgrade" : ""}`} onClick={() => editOrder(order)}>
<FontAwesome name="arrow-right" />
</div>
)}
Expand All @@ -104,8 +104,8 @@ const Preparation = () => {
<Navbar back="/">
<div
onClick={() => setDowngradeMode(!downgradeMode)}
className={`preparation-mode-button ${downgradeMode ? 'downgrade' : ''}`}>
{!downgradeMode ? 'Aller en arrière' : 'Aller en avant'}
className={`preparation-mode-button ${downgradeMode ? "downgrade" : ""}`}>
{!downgradeMode ? "Aller en arrière" : "Aller en avant"}
</div>
</Navbar>
<div id="preparation">
Expand All @@ -132,20 +132,20 @@ const Preparation = () => {
)}
<div className="actions">
<div className="button cancel" onClick={() => setConfirmOrder(null)}>
{loading ? <Loader /> : 'Annuler'}
{loading ? <Loader /> : "Annuler"}
</div>
<div
className="button confirm"
onClick={async () => {
await editOrder(confirmOrder, true);
setConfirmOrder(null);
}}>
{loading ? <Loader /> : 'Confirmer'}
{loading ? <Loader /> : "Confirmer"}
</div>
</div>
</Modal>
</>
);
};

export default Preparation;
export default Page;
File renamed without changes.
Loading

0 comments on commit 6177ba9

Please sign in to comment.