clean code
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import { Card, Col, Image, Row } from "antd";
|
||||
import PresentIcon from "components/Icons/cart/PresentIcon";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link, useParams } from "react-router-dom";
|
||||
import { useGetRestaurantDetailsQuery } from "redux/api/others";
|
||||
import { ACCESS_TOKEN } from "utils/constants";
|
||||
import { colors } from "ThemeConstants.ts";
|
||||
import ProText from "../ProText";
|
||||
@@ -12,7 +10,7 @@ import { useAppSelector } from "redux/hooks";
|
||||
const LoyaltyCard = () => {
|
||||
const { t } = useTranslation();
|
||||
const { subdomain } = useParams();
|
||||
const { data: restaurant } = useGetRestaurantDetailsQuery(subdomain);
|
||||
const { restaurant } = useAppSelector((state) => state.order);
|
||||
const { isRTL } = useAppSelector((state) => state.locale);
|
||||
const token = localStorage.getItem(ACCESS_TOKEN);
|
||||
const loyaltyStamps = restaurant?.loyalty_stamps ?? 0;
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
import { Loader } from "components/Loader/Loader";
|
||||
import { Navigate, useParams } from "react-router-dom";
|
||||
import { useAppSelector } from "redux/hooks";
|
||||
|
||||
export const PrivateRoute = ({
|
||||
children,
|
||||
}: // permission,
|
||||
{
|
||||
children: JSX.Element;
|
||||
permission?: string;
|
||||
}) => {
|
||||
const { token, loading } = useAppSelector((state) => state.auth);
|
||||
const { subdomain } = useParams();
|
||||
|
||||
// const { data: user, isLoading: loadingUser } = useGetSignedUserInfoQuery();
|
||||
|
||||
// useEffect(() => {
|
||||
// if (user) dispatch(setUser(user));
|
||||
// }, [dispatch, user]);
|
||||
|
||||
if (loading) {
|
||||
return <Loader />;
|
||||
}
|
||||
|
||||
// let newPermissions: any[] = [];
|
||||
// // aggregate the rules from multi
|
||||
// user?.roles?.forEach(
|
||||
// (r) => (newPermissions = [...newPermissions, ...r.permissions])
|
||||
// );
|
||||
|
||||
// const userHasRequiredPermission = permission
|
||||
// ? !!newPermissions.find((p) => p.name === permission)
|
||||
// : true;
|
||||
|
||||
console.log(token);
|
||||
|
||||
|
||||
if (!token) {
|
||||
return <Navigate to={`/${subdomain}/login`} />;
|
||||
}
|
||||
|
||||
// if (token && !userHasRequiredPermission) {
|
||||
// return <AccessDenied />; // build your won access denied page (sth like 404)
|
||||
// }
|
||||
|
||||
return children;
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export function useDetectBarcode() {
|
||||
const [barcode, setBarcode] = useState<string>("");
|
||||
const [lastBarcode, setLastBarcode] = useState<string>("");
|
||||
|
||||
useEffect(() => {
|
||||
let interval: any;
|
||||
|
||||
const handleKeydown = (evt: any) => {
|
||||
if (interval) clearInterval(interval);
|
||||
|
||||
if (evt.code === "Enter") {
|
||||
if (barcode) handleBarcode(barcode);
|
||||
setBarcode("");
|
||||
return;
|
||||
}
|
||||
|
||||
if (evt.key !== "Shift") setBarcode((prev) => prev + evt.key);
|
||||
|
||||
interval = setInterval(() => setBarcode(""), 20);
|
||||
};
|
||||
|
||||
// Adding the event listener when the component mounts
|
||||
document.addEventListener("keydown", handleKeydown);
|
||||
|
||||
// Cleanup the event listener when the component unmounts
|
||||
return () => {
|
||||
document.removeEventListener("keydown", handleKeydown);
|
||||
if (interval) clearInterval(interval);
|
||||
};
|
||||
}, [barcode]);
|
||||
|
||||
const handleBarcode = (scannedBarcode: string) => {
|
||||
setLastBarcode(scannedBarcode);
|
||||
};
|
||||
|
||||
return lastBarcode;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
import { useRef, useState, useCallback } from "react";
|
||||
|
||||
type Props = { isEnabled: boolean; swipeAction: () => void };
|
||||
|
||||
export default function useSwipeUp({ isEnabled, swipeAction }: Props) {
|
||||
// Swipe detection
|
||||
const startYRef = useRef(0);
|
||||
const [isSwiping, setIsSwiping] = useState(false);
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
// Touch event handlers for swipe detection
|
||||
const handleTouchStart = useCallback(
|
||||
(e: React.TouchEvent) => {
|
||||
if (!isEnabled) return;
|
||||
startYRef.current = e.touches[0].clientY;
|
||||
setIsSwiping(true);
|
||||
},
|
||||
[isEnabled],
|
||||
);
|
||||
|
||||
/*
|
||||
const handleTouchMove = useCallback(
|
||||
(e: React.TouchEvent) => {
|
||||
if (!isSwiping) return;
|
||||
},
|
||||
[isSwiping],
|
||||
);
|
||||
*/
|
||||
|
||||
const handleTouchEnd = useCallback(
|
||||
(e: React.TouchEvent) => {
|
||||
if (!isSwiping || !isEnabled) return;
|
||||
|
||||
const endY = e.changedTouches[0].clientY;
|
||||
const deltaY = startYRef.current - endY;
|
||||
const threshold = 70; // Threshold to detect a swipe up
|
||||
|
||||
if (deltaY > threshold) {
|
||||
// Swipe up detected
|
||||
swipeAction();
|
||||
}
|
||||
|
||||
setIsSwiping(false);
|
||||
},
|
||||
[isSwiping, isEnabled],
|
||||
);
|
||||
|
||||
return {
|
||||
containerRef,
|
||||
handleTouchStart,
|
||||
handleTouchEnd,
|
||||
};
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
import { useAppSelector } from "redux/hooks";
|
||||
|
||||
export function useTranslations() {
|
||||
const { isRTL } = useAppSelector((state) => state.locale);
|
||||
const nameProp = isRTL ? "arabic_name" : "name";
|
||||
return [nameProp] as const ;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Layout } from 'antd';
|
||||
|
||||
const { Footer } = Layout;
|
||||
|
||||
type FooterNavProps = React.HTMLAttributes<HTMLDivElement>;
|
||||
|
||||
const FooterNav = ({ ...others }: FooterNavProps) => {
|
||||
return (
|
||||
<Footer {...others}>AntD Dashboard © 2023 Created by Design Sparx</Footer>
|
||||
);
|
||||
};
|
||||
|
||||
export default FooterNav;
|
||||
@@ -1,70 +0,0 @@
|
||||
import { BugFilled } from "@ant-design/icons";
|
||||
import { MenuProps } from "antd";
|
||||
import { PATHS } from "utils/constants";
|
||||
|
||||
// import WarehouseIcon from "components/Icons/WarehouseIcon";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
export default function useSidebarItems() {
|
||||
type MenuItem = Required<MenuProps>["items"][number] & {
|
||||
permission: string;
|
||||
children?: MenuItem[];
|
||||
};
|
||||
const { t } = useTranslation();
|
||||
// const [isAuth] = useAuth();
|
||||
const getItem = (
|
||||
label: React.ReactNode,
|
||||
key: React.Key,
|
||||
permission?: string,
|
||||
icon?: React.ReactNode,
|
||||
children?: MenuItem[],
|
||||
type?: "group"
|
||||
): MenuItem => {
|
||||
return {
|
||||
key,
|
||||
icon,
|
||||
children,
|
||||
label,
|
||||
type,
|
||||
permission,
|
||||
} as MenuItem;
|
||||
};
|
||||
|
||||
// Recursive function to filter items based on permissions
|
||||
const getGrantedItems = (items: any[]): MenuItem[] => {
|
||||
return items
|
||||
.filter(() => true)// Filter out items without permission
|
||||
.map((item: any) => {
|
||||
if (item.children) {
|
||||
// Recursively filter children
|
||||
return {
|
||||
...item,
|
||||
children: getGrantedItems(item.children),
|
||||
};
|
||||
}
|
||||
return item;
|
||||
});
|
||||
};
|
||||
|
||||
const items: MenuProps["items"] = [
|
||||
getItem(
|
||||
t("menu"),
|
||||
PATHS.menu,
|
||||
undefined,
|
||||
<div style={{ marginTop: 10 }}>
|
||||
<Link style={{}} to={PATHS.menu}>
|
||||
<BugFilled className="icon-container pos-icon" />
|
||||
</Link>
|
||||
</div>
|
||||
),
|
||||
];
|
||||
|
||||
// if we have a menu with empty children after applying "getGrantedItems"
|
||||
// we going to remove it
|
||||
const grantedItems = getGrantedItems(items).filter(
|
||||
(i) => (i.children && i.children.length !== 0) || !i.children
|
||||
);
|
||||
|
||||
return grantedItems;
|
||||
}
|
||||
@@ -33,7 +33,6 @@ export default function CartMobileTabletLayout({
|
||||
const { items, orderType } = useAppSelector(selectCart);
|
||||
const { isRTL } = useAppSelector((state) => state.locale);
|
||||
const { subdomain } = useParams();
|
||||
const { pickup_type } = useAppSelector((state) => state.order.restaurant);
|
||||
const { isMobile, isTablet } = useBreakPoint();
|
||||
const getResponsiveClass = () => (isTablet ? "tablet" : "mobile");
|
||||
const navigate = useNavigate();
|
||||
|
||||
@@ -206,7 +206,7 @@ function MenuPage() {
|
||||
border: "none",
|
||||
}}
|
||||
onClick={() => {
|
||||
if (table) callWaiter({
|
||||
if (table) callWaiter({
|
||||
table_id: table,
|
||||
call_reason: "call_waiter",
|
||||
}).unwrap().then(() => {
|
||||
|
||||
@@ -10,16 +10,13 @@ import styles from "./restaurant.module.css";
|
||||
import RestaurantServices from "./RestaurantServices";
|
||||
|
||||
// Import the Client Component for localStorage handling
|
||||
import Ads1 from "components/Ads/Ads1";
|
||||
import { OrderDetailsBottomSheet } from "components/CustomBottomSheet/orderDetailsSheet/OrderDetailsBottomSheet.tsx";
|
||||
import { Loader } from "components/Loader/Loader";
|
||||
import {
|
||||
CART_STORAGE_KEYS,
|
||||
updateOrderType,
|
||||
} from "features/order/orderSlice.ts";
|
||||
import useBreakPoint from "hooks/useBreakPoint";
|
||||
import { useRestaurant } from "hooks/useRestaurant";
|
||||
import useSwipeUp from "hooks/useSwipeUp";
|
||||
import { OrderType } from "pages/checkout/hooks/types.ts";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Grid } from "antd";
|
||||
import { Loader } from "components/Loader/Loader";
|
||||
import { PrivateRoute } from "components/privateRoute/PrivateRoute";
|
||||
import { PublicRoute } from "components/publicRoute/PublicRoute";
|
||||
import { AppLayout } from "layouts";
|
||||
import HeaderMenuDrawer from "layouts/app/HeaderMenuDrawer";
|
||||
@@ -9,7 +8,7 @@ import CardDetailsPage from "pages/CardDetails/CardDetails";
|
||||
import CartPage from "pages/cart/page";
|
||||
import CheckoutPage from "pages/checkout/page";
|
||||
import EGiftCardsPage from "pages/EGiftCards/EGiftCards";
|
||||
import { Error400Page, ErrorPage } from "pages/errors";
|
||||
import { ErrorPage } from "pages/errors";
|
||||
import LoginPage from "pages/login/page";
|
||||
import MenuPage from "pages/menu/page";
|
||||
import OrderDetails from "pages/order/components/OrderDetails";
|
||||
@@ -123,9 +122,9 @@ export const router = createHashRouter([
|
||||
element: (
|
||||
<PageWrapper
|
||||
children={
|
||||
<PrivateRoute>
|
||||
<PublicRoute>
|
||||
<OrdersPage />
|
||||
</PrivateRoute>
|
||||
</PublicRoute>
|
||||
}
|
||||
/>
|
||||
),
|
||||
@@ -195,20 +194,6 @@ export const router = createHashRouter([
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: "errors",
|
||||
errorElement: <ErrorPage />,
|
||||
children: [
|
||||
{
|
||||
path: "400",
|
||||
element: (
|
||||
<PrivateRoute>
|
||||
<Error400Page />
|
||||
</PrivateRoute>
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user