Commit 8f61cc6a authored by Nurasyl's avatar Nurasyl

update

parent 24d58738
...@@ -6,6 +6,7 @@ import { NotFound } from './components/NotFound/NotFound'; ...@@ -6,6 +6,7 @@ import { NotFound } from './components/NotFound/NotFound';
import { ContactData } from './containers/ContactData/ContactData'; import { ContactData } from './containers/ContactData/ContactData';
import { Layout } from './components/Layout/Layout'; import { Layout } from './components/Layout/Layout';
import { Orders } from './containers/Orders/Orders'; import { Orders } from './containers/Orders/Orders';
import { Context } from './containers/Context';
function App() { function App() {
return ( return (
...@@ -13,7 +14,8 @@ function App() { ...@@ -13,7 +14,8 @@ function App() {
<Routes> <Routes>
<Route path='/' element={<Layout/>}> <Route path='/' element={<Layout/>}>
<Route index element={<BurgerBuilder/>}/> <Route index element={<BurgerBuilder/>}/>
<Route path='/orders' element={<Orders/>}/> <Route path='/orders' element={<Context/>}/>
<Route path='/order' element={<Context/>}/>
<Route path='/checkout' element={<Checkout/>}> <Route path='/checkout' element={<Checkout/>}>
<Route path='contactData' element={<ContactData/>}/> <Route path='contactData' element={<ContactData/>}/>
</Route> </Route>
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
padding: 10px; padding: 10px;
margin: 10px auto; margin: 10px auto;
box-sizing: border-box; box-sizing: border-box;
cursor: pointer;
} }
.OrderItem span { .OrderItem span {
text-transform: capitalize; text-transform: capitalize;
......
...@@ -4,10 +4,11 @@ import "./OrderItem.css"; ...@@ -4,10 +4,11 @@ import "./OrderItem.css";
type TProps = { type TProps = {
ingredients: Ingredients, ingredients: Ingredients,
price: number price: number,
onClick: VoidFunction
}; };
export const OrderItem = ({ingredients, price}: TProps) => { export const OrderItem = ({ingredients, price, onClick}: TProps) => {
const ings = Object.keys(ingredients).map(igName => { const ings = Object.keys(ingredients).map(igName => {
return { return {
name: igName, name: igName,
...@@ -20,7 +21,7 @@ export const OrderItem = ({ingredients, price}: TProps) => { ...@@ -20,7 +21,7 @@ export const OrderItem = ({ingredients, price}: TProps) => {
)); ));
return ( return (
<div className="OrderItem"> <div className="OrderItem" onClick={onClick}>
<p>Ingredients: {ingredientOutput}</p> <p>Ingredients: {ingredientOutput}</p>
<p>Price: <strong>{price} KZT</strong></p> <p>Price: <strong>{price} KZT</strong></p>
</div> </div>
......
import React, { useEffect } from "react";
import { useLocation } from "react-router-dom";
export const Context = () => {
const location = useLocation();
useEffect(() => {
console.log(location, 'location');
}, []);
return (
location.pathname === "/order" ?
<div>
Order Page
</div>
:
<div>
Orders Page
</div>
);
};
\ No newline at end of file
import React, {useState, useEffect, useCallback} from "react"; import React, {useState, useEffect, useCallback} from "react";
import { useNavigate } from "react-router-dom";
import axiosBurger from "@/config/axiosBurger"; import axiosBurger from "@/config/axiosBurger";
import { parseGetOrders } from "@/helpers/parseGetOrders"; import { parseGetOrders } from "@/helpers/parseGetOrders";
import { TOrder } from "@/interfaces/order"; import { TOrder } from "@/interfaces/order";
...@@ -6,6 +7,8 @@ import { OrderItem } from "@/components/Order/OrderItem/OrderItem"; ...@@ -6,6 +7,8 @@ import { OrderItem } from "@/components/Order/OrderItem/OrderItem";
import { Spinner } from "@/components/UI/Spinner/Spinner"; import { Spinner } from "@/components/UI/Spinner/Spinner";
export const Orders = () => { export const Orders = () => {
const navigate = useNavigate();
const [orders, setOrders] = useState<TOrder[]>([]); const [orders, setOrders] = useState<TOrder[]>([]);
const [isLoading, setIsLoading] = useState<boolean>(false); const [isLoading, setIsLoading] = useState<boolean>(false);
...@@ -20,12 +23,20 @@ export const Orders = () => { ...@@ -20,12 +23,20 @@ export const Orders = () => {
getOrders(); getOrders();
}, []); }, []);
const onClickHandler = (id: string) => {
navigate({
pathname: `/order`
})
};
return ( return (
<> <>
<Spinner show={isLoading}/> <Spinner show={isLoading}/>
{ {
orders.map(order => ( orders.map(order => (
<OrderItem <OrderItem
onClick={() => onClickHandler(order.id)}
key={order.id} key={order.id}
ingredients={order.ingredients} ingredients={order.ingredients}
price={order.price} price={order.price}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment