Skip to content
This repository has been archived by the owner on Jul 8, 2024. It is now read-only.

Commit

Permalink
Add useLocation hook and RestaurantCell component
Browse files Browse the repository at this point in the history
  • Loading branch information
floriaaan committed Feb 9, 2024
1 parent 5afb756 commit 3dc82df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
20 changes: 14 additions & 6 deletions apps/web/app/(normal)/account/orders/columns.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use client";

import { useLocation } from "@/hooks";
import { Status } from "@/types/global";
import { Order } from "@/types/order";
import { ColumnDef } from "@tanstack/react-table";
Expand All @@ -8,16 +9,12 @@ import { MdLink } from "react-icons/md";

export const orders_columns: ColumnDef<Order>[] = [
{
id: "restaurantId",
id: "",
header: "",
cell(props) {
const restaurantId = props.getValue() as string;
const { id } = props.row.original;
return (
<Link href={`/account/orders/${id}`} className="inline-flex items-center gap-1 hover:underline">
Commande au <b>{restaurantId}</b> <MdLink className="h-4 w-4 shrink-0" />
</Link>
);
return <RestaurantCell restaurantId={restaurantId} id={id} />;
},
},
{
Expand Down Expand Up @@ -49,3 +46,14 @@ export const orders_columns: ColumnDef<Order>[] = [
},
},
];

const RestaurantCell = ({ restaurantId, id }: { restaurantId: Order["restaurantId"]; id: Order["id"] }) => {
const { restaurants } = useLocation();
const restaurant = restaurants.find((r) => r.id === restaurantId);

return (
<Link href={`/account/orders/${id}`} className="inline-flex items-center gap-1 hover:underline">
Commande au <b>{restaurant?.name || restaurantId}</b> <MdLink className="h-4 w-4 shrink-0" />
</Link>
);
};
3 changes: 2 additions & 1 deletion apps/web/app/(normal)/checkout/callback/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function CheckoutCallbackPage({ params }: PageProps) {
const { user, session } = useAuth();
const { isAuthenticated } = useBasket();

const { data: order } = useQuery<Order>({
const { data: order, isLoading } = useQuery<Order>({
// eslint-disable-next-line @tanstack/query/exhaustive-deps
queryKey: ["order", "payment", paymentId],
queryFn: async () => {
Expand All @@ -46,6 +46,7 @@ export default function CheckoutCallbackPage({ params }: PageProps) {
}
};

if (isLoading) return <LargeComponentLoader />;
if (!(isAuthenticated && user && session?.token)) return <NotLogged />;
return (
<>
Expand Down

0 comments on commit 3dc82df

Please sign in to comment.