import axios from "axios"; import React, { useContext, useEffect, useReducer } from "react"; import { Helmet } from "react-helmet-async"; import { useNavigate } from "react-router-dom"; import LoadingBox from "../components/LoadingBox"; import MessageBox from "../components/MessageBox"; import { getError } from "../components/utils"; import { Store } from "../Store"; import Button from "react-bootstrap/Button"; import CheckIcon from "@mui/icons-material/Check"; import ClearIcon from "@mui/icons-material/Clear"; const reducer = (state, action) => { switch (action.type) { case "FETCH_REQUEST": return { ...state, loading: true }; case "FETCH_SUCCESS": return { ...state, orders: action.payload, loading: false }; case "FETCH_FAIL": return { ...state, loading: false, error: action.payload }; default: return state; } }; function OrderHistoryScreen() { const { state } = useContext(Store); const { userInfo } = state; const navigate = useNavigate(); const [{ loading, error, orders }, dispatch] = useReducer(reducer, { loading: true, error: "", }); useEffect(() => { const fetchData = async () => { dispatch({ type: "FETCH_REQUEST" }); try { const { data } = await axios.get("/api/orders/mine", { headers: { Authorization: `Bearer ${userInfo.token}` }, }); dispatch({ type: "FETCH_SUCCESS", payload: data }); } catch (error) { dispatch({ type: "FETCH_FAIL", payload: getError(error) }); } }; fetchData(); }, [userInfo]); return (
Историја на нарачки

Историја на нарачки

{loading ? ( ) : error ? ( {error} ) : ( {orders.map((order) => ( ))}
ID Дата Вкупно Статус Акции
{order._id.substring(0, 7)} {order.createdAt.substring(0, 10)} {order.totalPrice.toFixed(2)} {order.isDelivered ? ( ) : ( )}
)}
); } export default OrderHistoryScreen;