Skip to content

Commit

Permalink
fix order track status
Browse files Browse the repository at this point in the history
  • Loading branch information
sevelinCa committed Jul 25, 2024
1 parent 102bfd8 commit 59a09bd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
8 changes: 7 additions & 1 deletion src/Components/orderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ const Order: React.FC<OrderProps> = ({ orderId, orderDate, keyIndex, expectedDel
</div>
<div>
<div className="text-sm text-gray-400">Expected Delivery Date</div>
<div>{formatDate(expectedDeliveryDate)}</div>
<div> {expectedDeliveryDate
? new Date(expectedDeliveryDate).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
})
: "N/A"}</div>
</div>
<div>
<div className="text-sm text-gray-400">Status</div>
Expand Down
22 changes: 15 additions & 7 deletions src/Components/orders.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from "react";
import React, { useEffect } from "react";
import OrderTable from "./orderComponent";
import { useGetAllOrdersQuery } from "../Redux/OrderSlice";
import { useAllOrdersQuery, useGetAllOrdersQuery, useGetSellerOrderQuery } from "../Redux/OrderSlice";
import Skeleton from "react-loading-skeleton";
import 'react-loading-skeleton/dist/skeleton.css';
import useAuthUser from "react-auth-kit/hooks/useAuthUser";

interface Order {
orderId: string;
Expand All @@ -12,6 +13,7 @@ interface Order {
}

const OrderComponent = () => {
const authData:any = useAuthUser()
function getAuthCookie() {
const cookies = document.cookie.split(';');
for (let cookie of cookies) {
Expand All @@ -25,8 +27,10 @@ const OrderComponent = () => {

const token = getAuthCookie();
console.log('token ', token);
const { data: orders, isLoading, error } = useGetAllOrdersQuery({ token });

const vendorData:any = localStorage.getItem("vendorData")
const vendor = JSON.parse(vendorData)
const { data: orders, isLoading, error } = useGetSellerOrderQuery({ token,vendorId:vendor?.vendorId });
const { data: buyerOrder, isLoading:buyerLoad, error:buyerError } = useGetAllOrdersQuery({token});
const LoadingSkeleton = () => {
return (
<div className="m-10">
Expand Down Expand Up @@ -66,10 +70,14 @@ const OrderComponent = () => {
<LoadingSkeleton/>
) : error ? (
<div>Error loading orders</div>
) : !orders || orders.length === 0 ? (
<div>No orders available</div>

) : (
<OrderTable orders={orders} />
authData.role == "vendor" ? (
<OrderTable orders={orders} />

):(
<OrderTable orders={buyerOrder} />
)
)}
</div>
);
Expand Down
11 changes: 10 additions & 1 deletion src/Redux/OrderSlice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ const OrderApiSlice = apiSlice.injectEndpoints({
url: `/order/getAllOrder`,
}),
}),
getSellerOrder: builder.query({
query: ({ token,vendorId }) => ({
url: `/order/getSellerOrder/${vendorId}`,
headers: {
Authorization: `Bearer ${token}`,
},
credentials: "include",
}),
}),
}),
});

export const { useGetOrderStatusQuery, useGetOrderQuery, useUpdateOrderStatusMutation, useGetUserInfoQuery, useGetAllOrdersQuery, useAllOrdersQuery } = OrderApiSlice;
export const { useGetOrderStatusQuery, useGetOrderQuery, useUpdateOrderStatusMutation, useGetUserInfoQuery, useGetAllOrdersQuery, useAllOrdersQuery,useGetSellerOrderQuery } = OrderApiSlice;
export default OrderApiSlice;

0 comments on commit 59a09bd

Please sign in to comment.