Skip to content

Commit

Permalink
feat: show transaction history in admin
Browse files Browse the repository at this point in the history
  • Loading branch information
nisrinasalm committed Dec 10, 2024
1 parent 056b28a commit dea390f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/TransactionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function index(Request $request)

$category = Category::all();

$transaction = Transaction::with(['cart_product.product.category'])
$transaction = Transaction::with(['cart_product.user', 'cart_product.product.category'])
->whereHas('cart_product.product.category', function ($query) use ($categoryIds) {
if (!empty($categoryIds)) {
$query->whereIn('category_id', $categoryIds);
Expand Down
4 changes: 2 additions & 2 deletions resources/js/Layouts/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function Navbar() {
Cart
</NavLink>
)}{" "}
{auth.user !== null && auth.user.role === "user" && (
{auth.user !== null && (
<NavLink
href={route("transaction.index")}
active={route().current("transaction.index")}
Expand Down Expand Up @@ -168,7 +168,7 @@ export default function Navbar() {
Cart
</ResponsiveNavLink>
)}
{auth.user !== null && auth.user.role === "user" && (
{auth.user !== null && (
<ResponsiveNavLink
href={route("transaction.index")}
active={route().current("transaction.index")}
Expand Down
22 changes: 21 additions & 1 deletion resources/js/Pages/Transaction/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { cn, numberToCurrency } from "@/Lib/utils";
import { CartType } from "@/types/entities/cart";
import { CategoryType } from "@/types/entities/category";
import { TransactionType } from "@/types/entities/transaction";
import { Head } from "@inertiajs/react";
import { Head, usePage } from "@inertiajs/react";
import { router } from "@inertiajs/react";
import { format, formatDate } from "date-fns";
import { Search, XCircle } from "lucide-react";
Expand Down Expand Up @@ -114,6 +114,16 @@ export default function TransactionIndex({
}
}, [filterQuery.category, filterDate]);

const { auth } = usePage().props as unknown as {
auth: {
user: {
name: string;
email: string;
role: string;
} | null;
};
};

return (
<AuthenticatedLayout>
<Head title="Order List" />
Expand Down Expand Up @@ -182,6 +192,16 @@ export default function TransactionIndex({
<Typography variant="s3" className="text-typo-secondary">
TR/{format(new Date(t.created_at), "yyyyMMdd")}/{t.id}
</Typography>
{auth.user?.role === "admin" && (
<>
<Typography variant="s3" className="text-typo-tertiary">
|
</Typography>
<Typography variant="s3" className="text-typo-secondary">
{t.cart_product[0].user.name}
</Typography>
</>
)}
</div>
<div className="flex flex-col gap-4 w-full">
<ProductItems
Expand Down
4 changes: 4 additions & 0 deletions resources/js/types/entities/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ export type CartType = {
product_id: string;
quantity: number;
product: ProductType;
user: {
id: string;
name: string;
};
};

0 comments on commit dea390f

Please sign in to comment.