fix bugs phase 2 (excel ) , download sample feature
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { navGroups } from "@/config/navGroups"
|
||||
|
||||
function normalizeTitle(title: string) {
|
||||
return title.trim().toLowerCase()
|
||||
}
|
||||
|
||||
const titleToHref = new Map<string, string>()
|
||||
|
||||
for (const group of navGroups) {
|
||||
for (const item of group.items) {
|
||||
titleToHref.set(normalizeTitle(item.title), item.href)
|
||||
|
||||
for (const subItem of item.items ?? []) {
|
||||
titleToHref.set(normalizeTitle(subItem.title), subItem.href)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getNavHrefByTitle(title: string) {
|
||||
return titleToHref.get(normalizeTitle(title))
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
"use client"
|
||||
|
||||
import Link from "next/link"
|
||||
import { FileText, FileSearch, Receipt, ShoppingCart } from "lucide-react"
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
|
||||
import type { DashboardData } from "./use-dashboard-data"
|
||||
import { getNavHrefByTitle } from "./nav-groups-links"
|
||||
|
||||
type Props = { data: DashboardData }
|
||||
|
||||
@@ -11,15 +13,15 @@ export function SalesPurchaseCards({ data }: Props) {
|
||||
const purchase = data.purchase_totals
|
||||
|
||||
const salesStats = [
|
||||
{ label: "Inspections", value: sales?.inspections ?? 0, icon: FileSearch },
|
||||
{ label: "Estimates", value: sales?.estimates ?? 0, icon: FileText },
|
||||
{ label: "Invoices", value: sales?.invoices ?? 0, icon: Receipt },
|
||||
{ label: "Inspections", value: sales?.inspections ?? 0, icon: FileSearch, href: getNavHrefByTitle("Inspections") },
|
||||
{ label: "Estimates", value: sales?.estimates ?? 0, icon: FileText, href: getNavHrefByTitle("Estimates") },
|
||||
{ label: "Invoices", value: sales?.invoices ?? 0, icon: Receipt, href: getNavHrefByTitle("Invoices") },
|
||||
]
|
||||
|
||||
const purchaseStats = [
|
||||
{ label: "Purchase Orders", value: purchase?.purchase_orders ?? 0, icon: ShoppingCart },
|
||||
{ label: "Bills", value: purchase?.bills ?? 0, icon: Receipt },
|
||||
{ label: "Expenses", value: purchase?.expenses ?? 0, icon: FileText },
|
||||
{ label: "Purchase Orders", value: purchase?.purchase_orders ?? 0, icon: ShoppingCart, href: getNavHrefByTitle("Purchase Orders") },
|
||||
{ label: "Bills", value: purchase?.bills ?? 0, icon: Receipt, href: getNavHrefByTitle("Bills") },
|
||||
{ label: "Expenses", value: purchase?.expenses ?? 0, icon: FileText, href: getNavHrefByTitle("Expenses") },
|
||||
]
|
||||
|
||||
return (
|
||||
@@ -34,16 +36,30 @@ export function SalesPurchaseCards({ data }: Props) {
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{salesStats.map((stat) => (
|
||||
<div
|
||||
key={stat.label}
|
||||
className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center"
|
||||
>
|
||||
<stat.icon className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-lg font-bold">{stat.value}</span>
|
||||
<span className="text-[11px] text-muted-foreground leading-tight">
|
||||
{stat.label}
|
||||
</span>
|
||||
</div>
|
||||
stat.href ? (
|
||||
<Link
|
||||
key={stat.label}
|
||||
href={stat.href}
|
||||
className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center transition-colors hover:bg-muted/50"
|
||||
>
|
||||
<stat.icon className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-lg font-bold">{stat.value}</span>
|
||||
<span className="text-[11px] text-muted-foreground leading-tight">
|
||||
{stat.label}
|
||||
</span>
|
||||
</Link>
|
||||
) : (
|
||||
<div
|
||||
key={stat.label}
|
||||
className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center"
|
||||
>
|
||||
<stat.icon className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-lg font-bold">{stat.value}</span>
|
||||
<span className="text-[11px] text-muted-foreground leading-tight">
|
||||
{stat.label}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
@@ -59,16 +75,30 @@ export function SalesPurchaseCards({ data }: Props) {
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
{purchaseStats.map((stat) => (
|
||||
<div
|
||||
key={stat.label}
|
||||
className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center"
|
||||
>
|
||||
<stat.icon className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-lg font-bold">{stat.value}</span>
|
||||
<span className="text-[11px] text-muted-foreground leading-tight">
|
||||
{stat.label}
|
||||
</span>
|
||||
</div>
|
||||
stat.href ? (
|
||||
<Link
|
||||
key={stat.label}
|
||||
href={stat.href}
|
||||
className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center transition-colors hover:bg-muted/50"
|
||||
>
|
||||
<stat.icon className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-lg font-bold">{stat.value}</span>
|
||||
<span className="text-[11px] text-muted-foreground leading-tight">
|
||||
{stat.label}
|
||||
</span>
|
||||
</Link>
|
||||
) : (
|
||||
<div
|
||||
key={stat.label}
|
||||
className="flex flex-col items-center gap-1 rounded-lg border p-3 text-center"
|
||||
>
|
||||
<stat.icon className="h-4 w-4 text-muted-foreground" />
|
||||
<span className="text-lg font-bold">{stat.value}</span>
|
||||
<span className="text-[11px] text-muted-foreground leading-tight">
|
||||
{stat.label}
|
||||
</span>
|
||||
</div>
|
||||
)
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { confirm } from '@/shared/components/confirm-dialog';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from '@/shared/components/ui/dropdown-menu'
|
||||
import { Button } from '@/shared/components/ui/button'
|
||||
import { toast } from 'sonner'
|
||||
import { Ellipsis, FileText, Pencil, Printer, Trash2 } from 'lucide-react';
|
||||
import { CalendarPlus, Ellipsis, FileText, Pencil, Printer, Trash2 } from 'lucide-react';
|
||||
import { useDocumentPrint } from '@/shared/hooks/use-document-print';
|
||||
import { useJobCard } from './job-card-context';
|
||||
import { useState } from 'react';
|
||||
@@ -30,6 +30,10 @@ export default function JobCardDropdown({ id }: { id: string }) {
|
||||
print("job_card", id, "print")
|
||||
}
|
||||
|
||||
const handleCreateAppointment = () => {
|
||||
router.push(`/sales/job-cards/${id}/appointments?create=1`)
|
||||
}
|
||||
|
||||
const handleConvertToInvoice = async () => {
|
||||
const confirmed = await confirm({
|
||||
title: "Convert to Invoice",
|
||||
@@ -52,7 +56,7 @@ export default function JobCardDropdown({ id }: { id: string }) {
|
||||
toast.info("An invoice already exists for this job card.")
|
||||
router.push(`/sales/invoice/${conflictId}`)
|
||||
} else {
|
||||
toast.error("Failed to convert job card to invoice")
|
||||
toast.error(err?.message || "Failed to convert job card to invoice")
|
||||
}
|
||||
} finally {
|
||||
setIsConverting(false)
|
||||
@@ -78,38 +82,52 @@ export default function JobCardDropdown({ id }: { id: string }) {
|
||||
}
|
||||
}
|
||||
return (
|
||||
|
||||
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="icon" className="self-stretch h-auto aspect-square">
|
||||
<Ellipsis className="size-4" />
|
||||
<div className="flex items-center gap-2">
|
||||
{jobCard?.status !== "draft" && (
|
||||
<Button variant="outline" onClick={handleConvertToInvoice} disabled={isConverting}>
|
||||
<FileText className="size-4" />
|
||||
{isConverting ? "Converting..." : "Convert to Invoice"}
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={handleEdit}>
|
||||
<Pencil className="size-4" />
|
||||
Edit
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={handlePrint} disabled={isPrinting}>
|
||||
<Printer className="size-4" />
|
||||
{isPrinting ? "Printing..." : "Print"}
|
||||
</DropdownMenuItem>
|
||||
{jobCard?.status !== "draft" && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
)}
|
||||
|
||||
<Button variant="outline" onClick={handleCreateAppointment}>
|
||||
<CalendarPlus className="size-4" />
|
||||
Create Appointment
|
||||
</Button>
|
||||
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="outline" size="icon" className="self-stretch h-auto aspect-square">
|
||||
<Ellipsis className="size-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem onClick={handleEdit}>
|
||||
<Pencil className="size-4" />
|
||||
Edit
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem onClick={handlePrint} disabled={isPrinting}>
|
||||
<Printer className="size-4" />
|
||||
{isPrinting ? "Printing..." : "Print"}
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={handleCreateAppointment}>
|
||||
<CalendarPlus className="size-4" />
|
||||
Create Appointment
|
||||
</DropdownMenuItem>
|
||||
{jobCard?.status !== "draft" && (
|
||||
<DropdownMenuItem onClick={handleConvertToInvoice} disabled={isConverting}>
|
||||
<FileText className="size-4" />
|
||||
{isConverting ? "Converting..." : "Convert to Invoice"}
|
||||
</DropdownMenuItem>
|
||||
</>
|
||||
)}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem variant="destructive" onClick={handleDelete}>
|
||||
<Trash2 className="size-4" />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem variant="destructive" onClick={handleDelete}>
|
||||
<Trash2 className="size-4" />
|
||||
Delete
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user