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

Commit

Permalink
Merge pull request #59 from floriaaan/feature/fix-commands-lists
Browse files Browse the repository at this point in the history
Feature/fix commands lists
  • Loading branch information
Anatole-Godard authored Feb 9, 2024
2 parents 2fb82d3 + 2d31b61 commit 728890c
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
21 changes: 3 additions & 18 deletions apps/web/app/(normal)/account/orders/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@
import { Status } from "@/types/global";
import { Order } from "@/types/order";
import { ColumnDef } from "@tanstack/react-table";
import { format } from "date-fns";
import fr from "date-fns/locale/fr";
import Link from "next/link";
import { MdLink } from "react-icons/md";

export const orders_columns: ColumnDef<Order>[] = [
{
accessorFn: (order) => order.delivery.restaurant_id,
id: "restaurant_id",
id: "restaurantId",
header: "",
cell(props) {
const restaurant_id = props.getValue() as string;
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>{restaurant_id}</b> <MdLink className="h-4 w-4 shrink-0" />
Commande au <b>{restaurantId}</b> <MdLink className="h-4 w-4 shrink-0" />
</Link>
);
},
Expand Down Expand Up @@ -51,16 +48,4 @@ export const orders_columns: ColumnDef<Order>[] = [
);
},
},
{
accessorKey: "created_at",
header: "Commande passée le",
cell(props) {
return (
<span className="text-right">
Passée le{" "}
{format(new Date((props.getValue() as string).toString()), "eeee d MMMM yyyy à HH:mm", { locale: fr })}
</span>
);
},
},
];
2 changes: 1 addition & 1 deletion apps/web/app/(normal)/account/orders/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function UserOrders() {
queryFn: async () => {
const res = await fetchAPI(`/api/order/by-user/${session?.user?.id}`, session?.token);
const body = await res.json();
return body;
return body.ordersList;
},
staleTime: 1000 * 60 * 5,
enabled: isAuthenticated,
Expand Down
48 changes: 32 additions & 16 deletions apps/web/components/admin/order/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import {
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Sheet, SheetTrigger } from "@/components/ui/sheet";
import { Sheet } from "@/components/ui/sheet";
import { cn } from "@/lib/utils";
import { Order } from "@/types/order";
import { DeliveryType, Order } from "@/types/order";
import { ColumnDef } from "@tanstack/react-table";
import { MoreHorizontal } from "lucide-react";
import { MdArrowDropUp, MdCopyAll, MdEdit } from "react-icons/md";
import { MdArrowDropUp, MdCopyAll } from "react-icons/md";
import { toPrice } from "@/lib/product/toPrice";
import { format } from "date-fns";

// This type is used to define the shape of our data.
// You can use a Zod schema here if you want.
Expand All @@ -35,17 +37,17 @@ export const orders_columns: ColumnDef<Order>[] = [
);
},
cell: ({ getValue }) => {
const p = getValue() as Order["user"];
const user = getValue() as Order["user"];

return (
<span>
{p.first_name} {p.last_name}
{user.firstName} {user.lastName}
</span>
);
},
},
{
accessorKey: "delivery_type",
accessorKey: "deliveryType",
header: ({ column }) => {
return (
<button
Expand All @@ -57,6 +59,10 @@ export const orders_columns: ColumnDef<Order>[] = [
</button>
);
},
cell: ({ getValue }) => {
const deliveryType = getValue() as Order["deliveryType"];
return <span>{deliveryType === DeliveryType.DELIVERY ? "Livraison" : "Emporter"}</span>;
},
},
{
accessorKey: "payment",
Expand All @@ -76,15 +82,32 @@ export const orders_columns: ColumnDef<Order>[] = [

return (
<span>
{p.total} - {p.status}
{toPrice(p.total)} - {p.status}
</span>
);
},
},

{
accessorKey: "delivery",
header: ({ column }) => {
return (
<button
className="inline-flex items-center"
onClick={() => column.toggleSorting(column.getIsSorted() === "asc")}
>
Date
<MdArrowDropUp className={cn("ml-1 h-4 w-4", column.getIsSorted() === "asc" && "rotate-180")} />
</button>
);
},
cell: ({ getValue }) => {
const d = getValue() as Order["delivery"];
return <span>{format(new Date(d.eta), "eeee d MMMM yyyy à HH:mm")}</span>;
},
},
{
id: "actions",
cell: ({ row }) => {
cell: ({ row, getValue }) => {
const o = row.original;

return (
Expand All @@ -103,13 +126,6 @@ export const orders_columns: ColumnDef<Order>[] = [
{"Copier l'identifiant commande"}
</DropdownMenuItem>
<DropdownMenuSeparator />

<DropdownMenuItem>
<SheetTrigger className="inline-flex items-center gap-x-1">
<MdEdit className="h-4 w-4 shrink-0" />
Modifier/supprimer
</SheetTrigger>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<OrderFormSheetContent initialValues={{ ...o } as unknown as OrderCreateEditFormValues} id={o.id} />
Expand Down
8 changes: 4 additions & 4 deletions apps/web/constants/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ export const orderList: Order[] = [
deliveryType: DeliveryType.DELIVERY,
user: {
id: "user_id:1",
first_name: "John",
last_name: "Doe",
firstName: "John",
lastName: "Doe",
email: "[email protected]",
phone: "0612345678",
},
Expand Down Expand Up @@ -339,8 +339,8 @@ export const orderList: Order[] = [
deliveryType: DeliveryType.DELIVERY,
user: {
id: "user_id:1",
first_name: "John",
last_name: "Doe",
firstName: "John",
lastName: "Doe",
email: "[email protected]",
phone: "0612345678",
},
Expand Down
4 changes: 2 additions & 2 deletions apps/web/types/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Basket, BasketItem } from "@/types/basket";

export type UserMinimum = {
id: string;
first_name: string;
last_name: string;
firstName: string;
lastName: string;
email: string;
phone: string;
};
Expand Down
1 change: 0 additions & 1 deletion services/gateway/src/controller/order/order.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ orderRoutes.get("/api/order/by-user/:userId", async (req: Request, res: Response
orderService.getOrdersByUser(orderInput, async (error, response) => {
if (error) return res.status(500).send({ error });
const r = response.toObject();
console.log(r.ordersList);
const ordersList = await Promise.all(
r.ordersList.map(async (order) => {
const payment = await getPayment(order.paymentId);
Expand Down

0 comments on commit 728890c

Please sign in to comment.