-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
150 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
"use client"; | ||
|
||
import { Button } from "@/components/ui/button"; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger, | ||
} from "@/components/ui/dropdown-menu"; | ||
import { | ||
Table, | ||
TableBody, | ||
TableCell, | ||
TableHead, | ||
TableHeader, | ||
TableRow, | ||
} from "@/components/ui/table"; | ||
import { api } from "@/lib/api"; | ||
import type { server } from "@/lib/server"; | ||
import { cn, rupiahFormatter } from "@/lib/utils"; | ||
import { IoEllipsisVerticalSharp } from "react-icons/io5"; | ||
|
||
export default function OrderTable({ | ||
initialData, | ||
}: { | ||
initialData: Awaited<ReturnType<typeof server.admin.getOrders.query>>; | ||
}) { | ||
const { data } = api.admin.getOrders.useQuery(undefined, { | ||
initialData, | ||
}); | ||
return ( | ||
<Table> | ||
<TableHeader> | ||
<TableRow> | ||
<TableHead className="w-[100px]">Order</TableHead> | ||
<TableHead className="min-w-[150px]">Customer</TableHead> | ||
<TableHead className="hidden md:table-cell">Date</TableHead> | ||
<TableHead className="hidden sm:table-cell">Product</TableHead> | ||
<TableHead className="hidden text-right sm:table-cell"> | ||
Total | ||
</TableHead> | ||
<TableHead className="w-12">Status</TableHead> | ||
<TableHead className="text-right">Actions</TableHead> | ||
</TableRow> | ||
</TableHeader> | ||
<TableBody> | ||
{data.map((order) => ( | ||
<TableRow key={order.id}> | ||
<TableCell className="line-clamp-1 font-medium"> | ||
{order.id} | ||
</TableCell> | ||
<TableCell>{order.buyer.name}</TableCell> | ||
<TableCell className="hidden md:table-cell"> | ||
{new Date(order.createdAt).toLocaleDateString()} | ||
</TableCell> | ||
<TableCell className="hidden sm:table-cell"> | ||
{order.products.name} | ||
</TableCell> | ||
<TableCell className="hidden text-right sm:table-cell"> | ||
{rupiahFormatter(order.totalPrice)} | ||
</TableCell> | ||
<TableCell className="whitespace-nowrap uppercase"> | ||
<span | ||
className={cn( | ||
"mr-2 inline-block h-2 w-2 rounded-full", | ||
order.status === "done" | ||
? "bg-green-500" | ||
: order.status === "cancelled" | ||
? "bg-red-500" | ||
: "bg-yellow-500", | ||
)} | ||
/> | ||
{order.status} | ||
</TableCell> | ||
<TableCell className="text-right"> | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button size="icon" variant="ghost"> | ||
<IoEllipsisVerticalSharp /> | ||
<span className="sr-only">Actions</span> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align="end"> | ||
<DropdownMenuItem>View order</DropdownMenuItem> | ||
<DropdownMenuItem>Customer details</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
</TableCell> | ||
</TableRow> | ||
))} | ||
</TableBody> | ||
</Table> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import { clsx } from "clsx" | ||
import type {ClassValue} from "clsx"; | ||
import { twMerge } from "tailwind-merge" | ||
import { clsx } from "clsx"; | ||
import type { ClassValue } from "clsx"; | ||
import { twMerge } from "tailwind-merge"; | ||
|
||
export function cn(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)) | ||
return twMerge(clsx(inputs)); | ||
} | ||
|
||
export function rupiahFormatter(value?: number): string { | ||
if (!value) return ""; | ||
|
||
return new Intl.NumberFormat("id-ID", { | ||
style: "currency", | ||
currency: "IDR", | ||
minimumFractionDigits: 0, | ||
}).format(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { alias } from "drizzle-orm/mysql-core"; | ||
|
||
import { eq, sql } from "@vivat/db"; | ||
import { addresses } from "@vivat/db/schema/addresses"; | ||
import { orders } from "@vivat/db/schema/orders"; | ||
import { products } from "@vivat/db/schema/products"; | ||
import { users } from "@vivat/db/schema/users"; | ||
|
||
import { adminProcedure, createTRPCRouter } from "../trpc"; | ||
|
||
export const adminRouter = createTRPCRouter({ | ||
getOrders: adminProcedure.query(async ({ ctx }) => { | ||
const seller = alias(users, "seller"); | ||
|
||
return await ctx.db | ||
.select({ | ||
createdAt: orders.createdAt, | ||
id: orders.id, | ||
status: orders.status, | ||
products, | ||
buyer: users, | ||
seller, | ||
totalPrice: orders.totalPrice, | ||
}) | ||
.from(orders) | ||
.innerJoin(addresses, eq(orders.addressId, addresses.id)) | ||
.innerJoin(users, eq(addresses.userId, users.id)) | ||
.innerJoin(products, eq(orders.productId, products.id)) | ||
.innerJoin(seller, eq(products.sellerId, seller.id)) | ||
.orderBy(sql`(CASE ${orders.status} WHEN 'payment' THEN 0 ELSE 1 END), ${orders.createdAt} DESC`) | ||
}), | ||
}); |
This file was deleted.
Oops, something went wrong.