Compare commits
58 Commits
6e16d4f2c8
...
feat/disca
| Author | SHA1 | Date | |
|---|---|---|---|
| 830883c6b7 | |||
| 68829dc72b | |||
| 9d7f956c3b | |||
| 0026824f84 | |||
| a18eb64dac | |||
| 6c71d8f8a7 | |||
| 0e2172366b | |||
| 56180f8d18 | |||
| 5269b29aac | |||
| 9fe7109faf | |||
| 9720546455 | |||
| 8727963c54 | |||
| 0e8108b875 | |||
| 87dde1c8d1 | |||
| a376558b2f | |||
| 4fe93460d9 | |||
| cbfb6e040b | |||
| 7a82e17bbb | |||
| 23186ffd29 | |||
| fb9a654aea | |||
| d88978a830 | |||
| ba9731de86 | |||
| c0f3a718ef | |||
| 14220445ad | |||
| 79272c7abc | |||
| 26e15360f7 | |||
| b6a0f04f1e | |||
| 9cf4f0e795 | |||
| fdcfc3a8db | |||
| 278b9591d7 | |||
| 02adbb4c10 | |||
| 53fe4e11fe | |||
| 2eb58856af | |||
| c73ba0a01f | |||
| 1a94ff80e6 | |||
| b1174c8825 | |||
| d4a7a7c139 | |||
| 57b33bd061 | |||
| 81df3a9973 | |||
| 09ce57c9e0 | |||
| ea684fc9fe | |||
| ec77696157 | |||
| adff2e2c41 | |||
| 3e5dbd5893 | |||
| 11f95c4727 | |||
| e805cdee09 | |||
| 57461a05f2 | |||
| 8a080cb051 | |||
| 063f963fd4 | |||
| 1f8ca87bd0 | |||
| 8665762ba2 | |||
| 81a53b692d | |||
| 82050372c6 | |||
| 2fc01f74e2 | |||
| 67237982c8 | |||
| c1c81687d8 | |||
| 81b68fdb61 | |||
| 5439a5ff45 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -44,6 +44,7 @@ Thumbs.db
|
|||||||
|
|
||||||
# TypeScript
|
# TypeScript
|
||||||
*.tsbuildinfo
|
*.tsbuildinfo
|
||||||
|
next-env.d.ts
|
||||||
|
|
||||||
# Test / coverage
|
# Test / coverage
|
||||||
coverage/
|
coverage/
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
{
|
{
|
||||||
"$schema": "https://ui.shadcn.com/schema.json",
|
"$schema": "https://ui.shadcn.com/schema.json",
|
||||||
"style": "new-york",
|
"style": "radix-vega",
|
||||||
"rsc": true,
|
"rsc": true,
|
||||||
"tsx": true,
|
"tsx": true,
|
||||||
"tailwind": {
|
"tailwind": {
|
||||||
"config": "",
|
"config": "",
|
||||||
"css": "src/app/globals.css",
|
"css": "src/app/globals.css",
|
||||||
"baseColor": "slate",
|
"baseColor": "neutral",
|
||||||
"cssVariables": true,
|
"cssVariables": true,
|
||||||
"prefix": ""
|
"prefix": ""
|
||||||
},
|
},
|
||||||
"iconLibrary": "lucide",
|
"iconLibrary": "lucide",
|
||||||
|
"rtl": false,
|
||||||
"aliases": {
|
"aliases": {
|
||||||
"components": "@/components",
|
"components": "@/components",
|
||||||
"utils": "@/lib/utils",
|
"utils": "@/lib/utils",
|
||||||
@@ -18,5 +19,7 @@
|
|||||||
"lib": "@/lib",
|
"lib": "@/lib",
|
||||||
"hooks": "@/hooks"
|
"hooks": "@/hooks"
|
||||||
},
|
},
|
||||||
|
"menuColor": "default",
|
||||||
|
"menuAccent": "subtle",
|
||||||
"registries": {}
|
"registries": {}
|
||||||
}
|
}
|
||||||
|
|||||||
6
next-env.d.ts
vendored
6
next-env.d.ts
vendored
@@ -1,6 +0,0 @@
|
|||||||
/// <reference types="next" />
|
|
||||||
/// <reference types="next/image-types/global" />
|
|
||||||
import "./.next/types/routes.d.ts";
|
|
||||||
|
|
||||||
// NOTE: This file should not be edited
|
|
||||||
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
|
|
||||||
3467
package-lock.json
generated
3467
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
11
package.json
11
package.json
@@ -27,26 +27,35 @@
|
|||||||
"@tanstack/react-query-devtools": "^5.101.0",
|
"@tanstack/react-query-devtools": "^5.101.0",
|
||||||
"@tanstack/react-table": "^8.21.3",
|
"@tanstack/react-table": "^8.21.3",
|
||||||
"@tanstack/react-virtual": "^3.14.3",
|
"@tanstack/react-virtual": "^3.14.3",
|
||||||
|
"@vidstack/react": "^1.15.6",
|
||||||
"axios": "^1.13.6",
|
"axios": "^1.13.6",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
"date-fns": "^4.4.0",
|
||||||
|
"leaflet": "^1.9.4",
|
||||||
"libphonenumber-js": "^1.13.7",
|
"libphonenumber-js": "^1.13.7",
|
||||||
|
"lightgallery": "^2.9.0",
|
||||||
"lucide-react": "^0.548.0",
|
"lucide-react": "^0.548.0",
|
||||||
"motion": "^12.38.0",
|
"motion": "^12.38.0",
|
||||||
"next": "16.0.10",
|
"next": "16.0.10",
|
||||||
"next-themes": "^0.4.6",
|
"next-themes": "^0.4.6",
|
||||||
"radix-ui": "^1.6.0",
|
"radix-ui": "^1.6.0",
|
||||||
"react": "19.2.0",
|
"react": "19.2.0",
|
||||||
|
"react-day-picker": "^10.0.1",
|
||||||
"react-dom": "19.2.0",
|
"react-dom": "19.2.0",
|
||||||
"react-hook-form": "^7.79.0",
|
"react-hook-form": "^7.79.0",
|
||||||
"recharts": "2.15.4",
|
"react-leaflet": "^5.0.0",
|
||||||
|
"recharts": "^3.8.0",
|
||||||
|
"shadcn": "^4.13.0",
|
||||||
"sonner": "^1.7.4",
|
"sonner": "^1.7.4",
|
||||||
"tailwind-merge": "^3.3.1",
|
"tailwind-merge": "^3.3.1",
|
||||||
|
"vaul": "^1.1.2",
|
||||||
"zod": "^4.4.3",
|
"zod": "^4.4.3",
|
||||||
"zustand": "^5.0.14"
|
"zustand": "^5.0.14"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@tailwindcss/postcss": "^4.1.9",
|
"@tailwindcss/postcss": "^4.1.9",
|
||||||
|
"@types/leaflet": "^1.9.21",
|
||||||
"@types/node": "^22",
|
"@types/node": "^22",
|
||||||
"@types/react": "^19",
|
"@types/react": "^19",
|
||||||
"@types/react-dom": "^19",
|
"@types/react-dom": "^19",
|
||||||
|
|||||||
BIN
public/logo.png
Normal file
BIN
public/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 278 KiB |
@@ -31,7 +31,7 @@ function ForgotPasswordContent() {
|
|||||||
<div className="flex h-screen flex-1 items-center justify-center border-l border-border p-6 md:w-[60%]">
|
<div className="flex h-screen flex-1 items-center justify-center border-l border-border p-6 md:w-[60%]">
|
||||||
<section className="w-full max-w-sm space-y-7">
|
<section className="w-full max-w-sm space-y-7">
|
||||||
<header className="space-y-2 text-center md:text-left">
|
<header className="space-y-2 text-center md:text-left">
|
||||||
<p className="text-muted-foreground">VisionRoad</p>
|
<p className="text-muted-foreground">RoadMonitor</p>
|
||||||
<h1>{displayInfo.title}</h1>
|
<h1>{displayInfo.title}</h1>
|
||||||
<p className="text-muted-foreground">{displayInfo.description}</p>
|
<p className="text-muted-foreground">{displayInfo.description}</p>
|
||||||
</header>
|
</header>
|
||||||
@@ -60,7 +60,11 @@ function ForgotPasswordContent() {
|
|||||||
className="w-full"
|
className="w-full"
|
||||||
disabled={isLoading || !canSubmit}
|
disabled={isLoading || !canSubmit}
|
||||||
>
|
>
|
||||||
{isLoading ? <Loader2 className="size-4 animate-spin" /> : <Send />}
|
{isLoading ? (
|
||||||
|
<Loader2 className="size-4 animate-spin" />
|
||||||
|
) : (
|
||||||
|
<Send />
|
||||||
|
)}
|
||||||
{displayInfo.buttonLabel}
|
{displayInfo.buttonLabel}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export default function LoginPage() {
|
|||||||
<section className="w-full max-w-sm space-y-7">
|
<section className="w-full max-w-sm space-y-7">
|
||||||
<header className="space-y-2 text-center md:text-left">
|
<header className="space-y-2 text-center md:text-left">
|
||||||
<p className="text-sm font-medium text-muted-foreground">
|
<p className="text-sm font-medium text-muted-foreground">
|
||||||
VisionRoad
|
RoadMonitor
|
||||||
</p>
|
</p>
|
||||||
<h1 className="text-2xl font-semibold tracking-tight">Sign in</h1>
|
<h1 className="text-2xl font-semibold tracking-tight">Sign in</h1>
|
||||||
<p className="text-sm text-muted-foreground">
|
<p className="text-sm text-muted-foreground">
|
||||||
|
|||||||
@@ -27,13 +27,13 @@ function ResetPasswordContent() {
|
|||||||
<div className="flex h-screen flex-1 items-center justify-center border-l border-border p-6 md:w-[60%]">
|
<div className="flex h-screen flex-1 items-center justify-center border-l border-border p-6 md:w-[60%]">
|
||||||
<section className="w-full max-w-sm space-y-7">
|
<section className="w-full max-w-sm space-y-7">
|
||||||
<header className="space-y-2 text-center md:text-left">
|
<header className="space-y-2 text-center md:text-left">
|
||||||
<p className="text-muted-foreground">VisionRoad</p>
|
<p className="text-muted-foreground">RoadMonitor</p>
|
||||||
<h1>{displayInfo.title}</h1>
|
<h1>{displayInfo.title}</h1>
|
||||||
<p className="text-muted-foreground">{displayInfo.description}</p>
|
<p className="text-muted-foreground">{displayInfo.description}</p>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{!hasToken ? (
|
{!hasToken ? (
|
||||||
<div className="rounded-md border border-destructive/30 bg-destructive/5 p-4 text-destructive">
|
<div className="rounded-lg border border-destructive/30 bg-destructive/5 p-4 text-destructive">
|
||||||
Password reset token is missing.
|
Password reset token is missing.
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
@@ -69,7 +69,9 @@ function ResetPasswordContent() {
|
|||||||
className="w-full"
|
className="w-full"
|
||||||
disabled={isLoading || !canSubmit}
|
disabled={isLoading || !canSubmit}
|
||||||
>
|
>
|
||||||
{isLoading ? <Loader2 className="size-4 animate-spin" /> : null}
|
{isLoading ? (
|
||||||
|
<Loader2 className="size-4 animate-spin" />
|
||||||
|
) : null}
|
||||||
{displayInfo.buttonLabel}
|
{displayInfo.buttonLabel}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
27
src/app/(modules)/_components/module-shell-header.tsx
Normal file
27
src/app/(modules)/_components/module-shell-header.tsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { BreadcrumbBasic } from '@/components/app-breadcrumb';
|
||||||
|
import { ModeToggle } from '@/components/mode-toogle';
|
||||||
|
import { Separator } from '@/components/ui/separator';
|
||||||
|
import { SidebarTrigger, useSidebar } from '@/components/ui/sidebar';
|
||||||
|
|
||||||
|
export function ModuleShellHeader() {
|
||||||
|
const { isMobile } = useSidebar();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="sticky top-0 z-50 flex h-14 items-center justify-between gap-4 border-b border-border bg-background/95 px-6 backdrop-blur supports-backdrop-filter:bg-background/80">
|
||||||
|
<div className="flex min-w-0 items-center gap-3">
|
||||||
|
{isMobile ? (
|
||||||
|
<>
|
||||||
|
<SidebarTrigger className="shrink-0 bg-background/80 text-muted-foreground shadow-xs backdrop-blur-sm" />
|
||||||
|
<Separator orientation="vertical" className="h-4 shrink-0" />
|
||||||
|
</>
|
||||||
|
) : null}
|
||||||
|
<div className="min-w-0">
|
||||||
|
<BreadcrumbBasic />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<ModeToggle />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -13,6 +13,7 @@ import { FormField, PhoneInput } from '@/components/form';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
@@ -71,12 +72,12 @@ export function ClientSheet({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="flex max-h-[calc(100vh-2rem)] flex-col gap-0 p-0 sm:max-w-3xl">
|
<DialogContent className="sm:max-w-3xl">
|
||||||
<DialogHeader className="shrink-0 border-b px-6 py-4 pr-12">
|
<DialogHeader>
|
||||||
<DialogTitle className="text-lg leading-none font-semibold tracking-tight">
|
<DialogTitle>
|
||||||
{clientId ? 'Edit Client' : 'Create Client'}
|
{clientId ? 'Edit Client' : 'Create Client'}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogDescription className="text-sm">
|
<DialogDescription>
|
||||||
Manage company and primary contact details.
|
Manage company and primary contact details.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
@@ -86,7 +87,7 @@ export function ClientSheet({
|
|||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
className="flex min-h-0 flex-1 flex-col"
|
className="flex min-h-0 flex-1 flex-col"
|
||||||
>
|
>
|
||||||
<div className="max-h-[58vh] space-y-5 overflow-y-auto px-6 py-4">
|
<DialogBody className="space-y-5">
|
||||||
<div className="grid gap-4 md:grid-cols-2">
|
<div className="grid gap-4 md:grid-cols-2">
|
||||||
<FormField
|
<FormField
|
||||||
id="client-first-name"
|
id="client-first-name"
|
||||||
@@ -240,9 +241,9 @@ export function ClientSheet({
|
|||||||
/>
|
/>
|
||||||
</FormField>
|
</FormField>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</DialogBody>
|
||||||
|
|
||||||
<DialogFooter className="shrink-0 border-t px-6 py-4">
|
<DialogFooter>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import { BreadcrumbBasic } from '@/components/app-breadcrumb';
|
|
||||||
import { AppSidebar } from '@/components/app-sidebar';
|
import { AppSidebar } from '@/components/app-sidebar';
|
||||||
import { ModeToggle } from '@/components/mode-toogle';
|
import { SidebarProvider } from '@/components/ui/sidebar';
|
||||||
import { SidebarProvider, SidebarTrigger } from '@/components/ui/sidebar';
|
|
||||||
import { Separator } from '@/components/ui/separator';
|
|
||||||
import { AuthGuard } from '@/guards';
|
import { AuthGuard } from '@/guards';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { ModuleShellHeader } from './_components/module-shell-header';
|
||||||
|
|
||||||
const ModulesLayout = ({
|
const ModulesLayout = ({
|
||||||
children,
|
children,
|
||||||
@@ -15,16 +13,11 @@ const ModulesLayout = ({
|
|||||||
<AuthGuard>
|
<AuthGuard>
|
||||||
<SidebarProvider>
|
<SidebarProvider>
|
||||||
<AppSidebar />
|
<AppSidebar />
|
||||||
<main className="flex flex-1 flex-col w-full h-screen overflow-hidden">
|
<main className="flex flex-1 h-screen w-full flex-col overflow-hidden">
|
||||||
<div className="flex-1 overflow-auto">
|
<div className="scroll-stable flex-1 overflow-auto">
|
||||||
<div className="max-w-380 mx-auto w-full flex flex-col min-h-full">
|
<div className="mx-auto flex min-h-full w-full max-w-380 flex-col">
|
||||||
<div className="flex gap-3 items-center sticky top-0 bg-background z-50 py-3 px-6 border-b border-border">
|
<ModuleShellHeader />
|
||||||
<SidebarTrigger />
|
<div className="flex-1 p-6">{children}</div>
|
||||||
<ModeToggle />
|
|
||||||
<Separator orientation="vertical" className="mx-2 h-4" />
|
|
||||||
<BreadcrumbBasic />
|
|
||||||
</div>
|
|
||||||
<div className="p-6 flex-1">{children}</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { ProjectSelect } from '@/components/lookups/ProjectSelect';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
@@ -62,14 +63,14 @@ export function PackageDialog({
|
|||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent
|
<DialogContent
|
||||||
className="flex max-h-[calc(100vh-2rem)] flex-col gap-0 p-0 sm:max-w-2xl"
|
className="sm:max-w-2xl"
|
||||||
onOpenAutoFocus={(event) => event.preventDefault()}
|
onOpenAutoFocus={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
<DialogHeader className="shrink-0 border-b px-6 py-4 pr-12">
|
<DialogHeader>
|
||||||
<DialogTitle className="text-lg leading-none font-semibold tracking-tight">
|
<DialogTitle>
|
||||||
{packageId ? 'Edit Package' : 'Create Package'}
|
{packageId ? 'Edit Package' : 'Create Package'}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogDescription className="text-sm">
|
<DialogDescription>
|
||||||
Manage package details and optional chainage range.
|
Manage package details and optional chainage range.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
@@ -79,7 +80,7 @@ export function PackageDialog({
|
|||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
className="flex min-h-0 flex-1 flex-col"
|
className="flex min-h-0 flex-1 flex-col"
|
||||||
>
|
>
|
||||||
<div className="max-h-[58vh] space-y-6 overflow-y-auto px-6 py-4">
|
<DialogBody className="space-y-6">
|
||||||
<section className="space-y-4">
|
<section className="space-y-4">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<h3 className="text-sm font-semibold">Basic details</h3>
|
<h3 className="text-sm font-semibold">Basic details</h3>
|
||||||
@@ -173,9 +174,9 @@ export function PackageDialog({
|
|||||||
</FormField>
|
</FormField>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</DialogBody>
|
||||||
|
|
||||||
<DialogFooter className="shrink-0 border-t px-6 py-4">
|
<DialogFooter>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
@@ -4,6 +4,16 @@ import { useCallback, useState } from 'react';
|
|||||||
import { Package as PackageIcon, Plus } from 'lucide-react';
|
import { Package as PackageIcon, Plus } from 'lucide-react';
|
||||||
|
|
||||||
import { PageHeader } from '@/components/page-header';
|
import { PageHeader } from '@/components/page-header';
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from '@/components/ui/alert-dialog';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import type { Package } from '@/types';
|
import type { Package } from '@/types';
|
||||||
|
|
||||||
@@ -20,6 +30,7 @@ import {
|
|||||||
|
|
||||||
export default function PackagePage() {
|
export default function PackagePage() {
|
||||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||||
|
const [packageToDelete, setPackageToDelete] = useState<Package | null>(null);
|
||||||
const { skip, setSkip, limit, setLimit } = usePackageFilters();
|
const { skip, setSkip, limit, setLimit } = usePackageFilters();
|
||||||
const packagesQuery = usePackagesQuery({ skip, limit });
|
const packagesQuery = usePackagesQuery({ skip, limit });
|
||||||
const projectsQuery = useProjectOptionsQuery();
|
const projectsQuery = useProjectOptionsQuery();
|
||||||
@@ -67,14 +78,25 @@ export default function PackagePage() {
|
|||||||
|
|
||||||
const deletePackage = useCallback(
|
const deletePackage = useCallback(
|
||||||
(pkg: Package) => {
|
(pkg: Package) => {
|
||||||
if (!confirm(`Are you sure you want to delete package "${pkg.name}"?`)) {
|
setPackageToDelete(pkg);
|
||||||
return;
|
|
||||||
}
|
|
||||||
deletePackageMutation.mutate(pkg);
|
|
||||||
},
|
},
|
||||||
[deletePackageMutation],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleDeleteDialogOpenChange = useCallback((open: boolean) => {
|
||||||
|
if (!open) {
|
||||||
|
setPackageToDelete(null);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const confirmDeletePackage = useCallback(() => {
|
||||||
|
if (!packageToDelete) return;
|
||||||
|
|
||||||
|
deletePackageMutation.mutate(packageToDelete, {
|
||||||
|
onSettled: () => setPackageToDelete(null),
|
||||||
|
});
|
||||||
|
}, [deletePackageMutation, packageToDelete]);
|
||||||
|
|
||||||
const projects = projectsQuery.data?.items ?? [];
|
const projects = projectsQuery.data?.items ?? [];
|
||||||
const packages = packagesQuery.data?.items ?? [];
|
const packages = packagesQuery.data?.items ?? [];
|
||||||
const total = packagesQuery.data?.totalItems ?? 0;
|
const total = packagesQuery.data?.totalItems ?? 0;
|
||||||
@@ -122,6 +144,36 @@ export default function PackagePage() {
|
|||||||
canSubmit={canSubmit}
|
canSubmit={canSubmit}
|
||||||
isSaving={isSaving}
|
isSaving={isSaving}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<AlertDialog
|
||||||
|
open={Boolean(packageToDelete)}
|
||||||
|
onOpenChange={handleDeleteDialogOpenChange}
|
||||||
|
>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Delete package?</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This will permanently delete{' '}
|
||||||
|
<span className="font-medium text-foreground">
|
||||||
|
{packageToDelete?.name}
|
||||||
|
</span>
|
||||||
|
. This action cannot be undone.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={deletePackageMutation.isPending}>
|
||||||
|
Cancel
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
variant="destructive"
|
||||||
|
disabled={deletePackageMutation.isPending}
|
||||||
|
onClick={confirmDeletePackage}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ export function PlanSheet({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||||
<SheetContent className="w-full gap-0 p-0 sm:max-w-3xl">
|
<SheetContent className="w-full! gap-0 p-0 sm:max-w-3xl! lg:max-w-4xl!">
|
||||||
<SheetHeader className="shrink-0 border-b px-6 py-4 pr-12">
|
<SheetHeader className="shrink-0 border-b px-6 py-4 pr-12">
|
||||||
<SheetTitle className="text-lg leading-none font-semibold tracking-tight">
|
<SheetTitle className="text-lg leading-none font-semibold tracking-tight">
|
||||||
{planId ? 'Edit Plan' : 'Create Plan'}
|
{planId ? 'Edit Plan' : 'Create Plan'}
|
||||||
@@ -77,7 +77,11 @@ export function PlanSheet({
|
|||||||
</SheetDescription>
|
</SheetDescription>
|
||||||
</SheetHeader>
|
</SheetHeader>
|
||||||
|
|
||||||
<form noValidate onSubmit={onSubmit} className="flex min-h-0 flex-1 flex-col">
|
<form
|
||||||
|
noValidate
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
className="flex min-h-0 flex-1 flex-col"
|
||||||
|
>
|
||||||
<div className="flex-1 space-y-5 overflow-y-auto px-6 py-4">
|
<div className="flex-1 space-y-5 overflow-y-auto px-6 py-4">
|
||||||
<div className="grid gap-4 md:grid-cols-2">
|
<div className="grid gap-4 md:grid-cols-2">
|
||||||
<FormField
|
<FormField
|
||||||
@@ -242,7 +246,7 @@ export function PlanSheet({
|
|||||||
<label className="flex items-center gap-2">
|
<label className="flex items-center gap-2">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="size-4 rounded border-border accent-primary"
|
className="size-4 rounded-lg border-border accent-primary"
|
||||||
{...register('is_active')}
|
{...register('is_active')}
|
||||||
/>
|
/>
|
||||||
Active
|
Active
|
||||||
@@ -250,7 +254,7 @@ export function PlanSheet({
|
|||||||
<label className="flex items-center gap-2">
|
<label className="flex items-center gap-2">
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
className="size-4 rounded border-border accent-primary"
|
className="size-4 rounded-lg border-border accent-primary"
|
||||||
{...register('is_custom')}
|
{...register('is_custom')}
|
||||||
/>
|
/>
|
||||||
Custom plan
|
Custom plan
|
||||||
@@ -269,7 +273,7 @@ export function PlanSheet({
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
{isPermissionsLoading ? (
|
{isPermissionsLoading ? (
|
||||||
<div className="rounded-md border p-6 text-muted-foreground">
|
<div className="rounded-lg border p-6 text-muted-foreground">
|
||||||
Loading permissions...
|
Loading permissions...
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { FormField } from '@/components/form';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
@@ -54,14 +55,14 @@ export function ProjectDialog({
|
|||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent
|
<DialogContent
|
||||||
className="flex max-h-[calc(100vh-2rem)] flex-col gap-0 p-0 sm:max-w-2xl"
|
className="sm:max-w-2xl"
|
||||||
onOpenAutoFocus={(event) => event.preventDefault()}
|
onOpenAutoFocus={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
<DialogHeader className="shrink-0 border-b px-6 py-4 pr-12">
|
<DialogHeader>
|
||||||
<DialogTitle className="text-lg leading-none font-semibold tracking-tight">
|
<DialogTitle>
|
||||||
{projectId ? 'Edit Project' : 'Create Project'}
|
{projectId ? 'Edit Project' : 'Create Project'}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogDescription className="text-sm">
|
<DialogDescription>
|
||||||
Manage road project identity and optional coordinate boundaries.
|
Manage road project identity and optional coordinate boundaries.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
@@ -71,7 +72,7 @@ export function ProjectDialog({
|
|||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
className="flex min-h-0 flex-1 flex-col"
|
className="flex min-h-0 flex-1 flex-col"
|
||||||
>
|
>
|
||||||
<div className="max-h-[58vh] space-y-6 overflow-y-auto px-6 py-4">
|
<DialogBody className="space-y-6">
|
||||||
<section className="space-y-4">
|
<section className="space-y-4">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<h3 className="text-sm font-semibold">Basic details</h3>
|
<h3 className="text-sm font-semibold">Basic details</h3>
|
||||||
@@ -192,9 +193,9 @@ export function ProjectDialog({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</DialogBody>
|
||||||
|
|
||||||
<DialogFooter className="shrink-0 border-t px-6 py-4">
|
<DialogFooter>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
@@ -4,6 +4,16 @@ import { useCallback, useState } from 'react';
|
|||||||
import { Layers, Plus } from 'lucide-react';
|
import { Layers, Plus } from 'lucide-react';
|
||||||
|
|
||||||
import { PageHeader } from '@/components/page-header';
|
import { PageHeader } from '@/components/page-header';
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from '@/components/ui/alert-dialog';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import type { Project } from '@/types';
|
import type { Project } from '@/types';
|
||||||
|
|
||||||
@@ -19,6 +29,7 @@ import {
|
|||||||
|
|
||||||
export default function ProjectPage() {
|
export default function ProjectPage() {
|
||||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||||
|
const [projectToDelete, setProjectToDelete] = useState<Project | null>(null);
|
||||||
const { skip, setSkip, limit, setLimit } = useProjectFilters();
|
const { skip, setSkip, limit, setLimit } = useProjectFilters();
|
||||||
const projectsQuery = useProjectsQuery({ skip, limit });
|
const projectsQuery = useProjectsQuery({ skip, limit });
|
||||||
const deleteProjectMutation = useDeleteProjectMutation();
|
const deleteProjectMutation = useDeleteProjectMutation();
|
||||||
@@ -63,16 +74,25 @@ export default function ProjectPage() {
|
|||||||
|
|
||||||
const deleteProject = useCallback(
|
const deleteProject = useCallback(
|
||||||
(project: Project) => {
|
(project: Project) => {
|
||||||
if (
|
setProjectToDelete(project);
|
||||||
!confirm(`Are you sure you want to delete project "${project.name}"?`)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
deleteProjectMutation.mutate(project);
|
|
||||||
},
|
},
|
||||||
[deleteProjectMutation],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleDeleteDialogOpenChange = useCallback((open: boolean) => {
|
||||||
|
if (!open) {
|
||||||
|
setProjectToDelete(null);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const confirmDeleteProject = useCallback(() => {
|
||||||
|
if (!projectToDelete) return;
|
||||||
|
|
||||||
|
deleteProjectMutation.mutate(projectToDelete, {
|
||||||
|
onSettled: () => setProjectToDelete(null),
|
||||||
|
});
|
||||||
|
}, [deleteProjectMutation, projectToDelete]);
|
||||||
|
|
||||||
const columns = useProjectColumns();
|
const columns = useProjectColumns();
|
||||||
const projects = projectsQuery.data?.items ?? [];
|
const projects = projectsQuery.data?.items ?? [];
|
||||||
const total = projectsQuery.data?.totalItems ?? 0;
|
const total = projectsQuery.data?.totalItems ?? 0;
|
||||||
@@ -117,6 +137,36 @@ export default function ProjectPage() {
|
|||||||
canSubmit={canSubmit}
|
canSubmit={canSubmit}
|
||||||
isSaving={isSaving}
|
isSaving={isSaving}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<AlertDialog
|
||||||
|
open={Boolean(projectToDelete)}
|
||||||
|
onOpenChange={handleDeleteDialogOpenChange}
|
||||||
|
>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Delete project?</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This will permanently delete{' '}
|
||||||
|
<span className="font-medium text-foreground">
|
||||||
|
{projectToDelete?.name}
|
||||||
|
</span>
|
||||||
|
. This action cannot be undone.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={deleteProjectMutation.isPending}>
|
||||||
|
Cancel
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
variant="destructive"
|
||||||
|
disabled={deleteProjectMutation.isPending}
|
||||||
|
onClick={confirmDeleteProject}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,108 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
|
|
||||||
|
function StatSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-center rounded-lg border border-muted bg-muted/30 p-4 text-center">
|
||||||
|
<Skeleton className="mb-2 size-9 rounded-lg" />
|
||||||
|
<Skeleton className="h-6 w-12" />
|
||||||
|
<Skeleton className="mt-2 h-3 w-20" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function DetectionLogSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border bg-card p-3">
|
||||||
|
<div className="flex gap-3">
|
||||||
|
<Skeleton className="size-20 shrink-0 rounded-lg" />
|
||||||
|
<div className="min-w-0 flex-1 space-y-2">
|
||||||
|
<div className="flex items-start justify-between gap-3">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-5 w-28" />
|
||||||
|
<Skeleton className="h-3 w-20" />
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-3 w-12" />
|
||||||
|
<Skeleton className="h-3 w-10" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-3 w-32" />
|
||||||
|
<Skeleton className="h-3 w-44" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function VideoResultsSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="space-y-8">
|
||||||
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
<div className="flex min-w-0 items-start gap-3">
|
||||||
|
<Skeleton className="size-10 rounded-lg" />
|
||||||
|
<div className="min-w-0 space-y-2">
|
||||||
|
<Skeleton className="h-7 w-60 max-w-full" />
|
||||||
|
<Skeleton className="h-3 w-80 max-w-full" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-8 w-20" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section className="overflow-hidden rounded-lg border bg-card">
|
||||||
|
<div className="border-b p-6 pb-4">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
|
<Skeleton className="size-10 rounded-lg" />
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-5 w-44" />
|
||||||
|
<Skeleton className="h-3 w-64" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="p-6">
|
||||||
|
<div className="grid grid-cols-1 gap-6 lg:grid-cols-3">
|
||||||
|
<div className="space-y-6 lg:col-span-2">
|
||||||
|
<Skeleton className="aspect-video w-full rounded-lg border" />
|
||||||
|
|
||||||
|
<section className="overflow-hidden rounded-lg border bg-card/80">
|
||||||
|
<div className="flex flex-col gap-3 border-b px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-4 w-48" />
|
||||||
|
<Skeleton className="h-3 w-72 max-w-full" />
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-8 w-48" />
|
||||||
|
</div>
|
||||||
|
<div className="grid grid-cols-1 gap-2 p-3 sm:grid-cols-3">
|
||||||
|
{Array.from({ length: 3 }).map((_, index) => (
|
||||||
|
<Skeleton key={index} className="h-16 w-full rounded-lg" />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<Skeleton className="h-5 w-36" />
|
||||||
|
</div>
|
||||||
|
<div className="h-107.5 rounded-lg border bg-muted/20 p-4">
|
||||||
|
<div className="space-y-3">
|
||||||
|
{Array.from({ length: 5 }).map((_, index) => (
|
||||||
|
<DetectionLogSkeleton key={index} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-6 grid grid-cols-2 gap-3 md:grid-cols-5">
|
||||||
|
{Array.from({ length: 5 }).map((_, index) => (
|
||||||
|
<StatSkeleton key={index} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,25 +1,12 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useMemo } from 'react';
|
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
import { ArrowLeft, Loader2, TrendingUp } from 'lucide-react';
|
import { ArrowLeft, TrendingUp } from 'lucide-react';
|
||||||
import VideoPlayerSection from '@/components/videoPlayerSection';
|
import VideoPlayerSection from '@/components/videoPlayerSection';
|
||||||
import { PageHeader } from '@/components/page-header';
|
import { PageHeader } from '@/components/page-header';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { CompletedVideoResult, DetectionType } from '@/types';
|
|
||||||
import { getDetectionModeConfig } from '@/constants/detectionModeConfig';
|
|
||||||
import { useVideoResultsQuery } from '../hooks/useVideoResults';
|
import { useVideoResultsQuery } from '../hooks/useVideoResults';
|
||||||
|
import { VideoResultsSkeleton } from './components/VideoResultsSkeleton';
|
||||||
const inferDetectionType = (data: CompletedVideoResult): DetectionType => {
|
|
||||||
if (data.detection_mode) return data.detection_mode as DetectionType;
|
|
||||||
|
|
||||||
const signboards = data.summary?.unique_signboards || 0;
|
|
||||||
const potholes = data.summary?.unique_potholes || 0;
|
|
||||||
|
|
||||||
if (signboards > 0 && potholes > 0) return 'pot-sign-detection';
|
|
||||||
if (signboards > 0) return 'sign-board-detection';
|
|
||||||
return 'pothole-detection';
|
|
||||||
};
|
|
||||||
|
|
||||||
export default function VideoResultsPage() {
|
export default function VideoResultsPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@@ -32,34 +19,19 @@ export default function VideoResultsPage() {
|
|||||||
error: queryError,
|
error: queryError,
|
||||||
} = useVideoResultsQuery(videoId);
|
} = useVideoResultsQuery(videoId);
|
||||||
|
|
||||||
const detectionType = useMemo<DetectionType>(
|
|
||||||
() =>
|
|
||||||
detectionData ? inferDetectionType(detectionData) : 'pothole-detection',
|
|
||||||
[detectionData],
|
|
||||||
);
|
|
||||||
|
|
||||||
const error = isError
|
const error = isError
|
||||||
? queryError instanceof Error
|
? queryError instanceof Error
|
||||||
? queryError.message
|
? queryError.message
|
||||||
: 'Failed to load results'
|
: 'Failed to load results'
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
const getTitle = () => {
|
|
||||||
const config = getDetectionModeConfig(detectionType);
|
|
||||||
return `${config.label} Results`;
|
|
||||||
};
|
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return <VideoResultsSkeleton />;
|
||||||
<div className="min-h-[60vh] flex items-center justify-center">
|
|
||||||
<Loader2 className="h-8 w-8 animate-spin text-primary" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return (
|
return (
|
||||||
<div className="min-h-[60vh] flex items-center justify-center">
|
<div className="flex min-h-[60vh] items-center justify-center">
|
||||||
<p className="text-sm text-destructive">{error}</p>
|
<p className="text-sm text-destructive">{error}</p>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
@@ -68,7 +40,7 @@ export default function VideoResultsPage() {
|
|||||||
return (
|
return (
|
||||||
<div className="space-y-8">
|
<div className="space-y-8">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title={getTitle()}
|
title="Detection Results"
|
||||||
description={`Video ID: ${videoId}`}
|
description={`Video ID: ${videoId}`}
|
||||||
icon={TrendingUp}
|
icon={TrendingUp}
|
||||||
actions={
|
actions={
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
|
|||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
import { videoService } from '@/services/api';
|
import { videoService } from '@/services/api';
|
||||||
|
import type { VideoAnnotationFramesParams } from '@/types';
|
||||||
|
|
||||||
import { videoKeys } from '../queries/videoKeys';
|
import { videoKeys } from '../queries/videoKeys';
|
||||||
|
|
||||||
@@ -18,6 +19,20 @@ export function useVideoResultsQuery(videoId: string | undefined) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useVideoAnnotationFramesQuery(
|
||||||
|
videoId: string | undefined,
|
||||||
|
params: VideoAnnotationFramesParams,
|
||||||
|
) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: videoKeys.annotationFrames(videoId ?? '', params),
|
||||||
|
queryFn: () =>
|
||||||
|
videoService.getVideoAnnotationFrames(videoId as string, params),
|
||||||
|
enabled: Boolean(videoId),
|
||||||
|
staleTime: 1000 * 60 * 5,
|
||||||
|
gcTime: 1000 * 60 * 30,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download the annotated video through the authenticated axios client and
|
* Download the annotated video through the authenticated axios client and
|
||||||
* expose a local object URL that the native `<video>` element can play.
|
* expose a local object URL that the native `<video>` element can play.
|
||||||
@@ -26,10 +41,10 @@ export function useVideoResultsQuery(videoId: string | undefined) {
|
|||||||
* directly is what fixes the 401. The browser cannot attach the Bearer token to
|
* directly is what fixes the 401. The browser cannot attach the Bearer token to
|
||||||
* a media request, but axios can.
|
* a media request, but axios can.
|
||||||
*/
|
*/
|
||||||
export function useAnnotatedVideoQuery(url: string | undefined) {
|
export function useProtectedVideoQuery(url: string | undefined) {
|
||||||
const query = useQuery({
|
const query = useQuery({
|
||||||
queryKey: videoKeys.annotatedVideo(url ?? ''),
|
queryKey: videoKeys.annotatedVideo(url ?? ''),
|
||||||
queryFn: () => videoService.getAnnotatedVideo(url as string),
|
queryFn: () => videoService.getProtectedVideo(url as string),
|
||||||
enabled: Boolean(url),
|
enabled: Boolean(url),
|
||||||
staleTime: Infinity,
|
staleTime: Infinity,
|
||||||
gcTime: 1000 * 60 * 30,
|
gcTime: 1000 * 60 * 30,
|
||||||
@@ -59,3 +74,5 @@ export function useAnnotatedVideoQuery(url: string | undefined) {
|
|||||||
refetch: query.refetch,
|
refetch: query.refetch,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const useAnnotatedVideoQuery = useProtectedVideoQuery;
|
||||||
|
|||||||
@@ -2,6 +2,10 @@ export const videoKeys = {
|
|||||||
all: ['videos'] as const,
|
all: ['videos'] as const,
|
||||||
results: () => [...videoKeys.all, 'results'] as const,
|
results: () => [...videoKeys.all, 'results'] as const,
|
||||||
result: (videoId: string) => [...videoKeys.results(), videoId] as const,
|
result: (videoId: string) => [...videoKeys.results(), videoId] as const,
|
||||||
|
annotationFrames: (
|
||||||
|
videoId: string,
|
||||||
|
params: { start_time_ms: number; end_time_ms: number },
|
||||||
|
) => [...videoKeys.result(videoId), 'annotation-frames', params] as const,
|
||||||
annotatedVideos: () => [...videoKeys.all, 'annotated'] as const,
|
annotatedVideos: () => [...videoKeys.all, 'annotated'] as const,
|
||||||
annotatedVideo: (url: string) =>
|
annotatedVideo: (url: string) =>
|
||||||
[...videoKeys.annotatedVideos(), url] as const,
|
[...videoKeys.annotatedVideos(), url] as const,
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export function RoleSheet({
|
|||||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||||
<SheetContent
|
<SheetContent
|
||||||
side="right"
|
side="right"
|
||||||
className="flex h-full flex-col gap-0 p-0 sm:max-w-3xl lg:max-w-2xl"
|
className="flex h-full w-full! flex-col gap-0 p-0 sm:max-w-3xl!"
|
||||||
>
|
>
|
||||||
<SheetHeader className="shrink-0 border-b px-6 py-4 pr-12">
|
<SheetHeader className="shrink-0 border-b px-6 py-4 pr-12">
|
||||||
<SheetTitle className="text-lg leading-none font-semibold tracking-tight">
|
<SheetTitle className="text-lg leading-none font-semibold tracking-tight">
|
||||||
@@ -73,7 +73,11 @@ export function RoleSheet({
|
|||||||
</SheetDescription>
|
</SheetDescription>
|
||||||
</SheetHeader>
|
</SheetHeader>
|
||||||
|
|
||||||
<form noValidate onSubmit={onSubmit} className="flex min-h-0 flex-1 flex-col">
|
<form
|
||||||
|
noValidate
|
||||||
|
onSubmit={onSubmit}
|
||||||
|
className="flex min-h-0 flex-1 flex-col"
|
||||||
|
>
|
||||||
<div className="flex-1 space-y-5 overflow-y-auto px-6 py-4">
|
<div className="flex-1 space-y-5 overflow-y-auto px-6 py-4">
|
||||||
<div className="grid gap-4 md:grid-cols-2">
|
<div className="grid gap-4 md:grid-cols-2">
|
||||||
<FormField
|
<FormField
|
||||||
@@ -125,7 +129,7 @@ export function RoleSheet({
|
|||||||
}
|
}
|
||||||
>
|
>
|
||||||
{isPermissionsLoading ? (
|
{isPermissionsLoading ? (
|
||||||
<div className="rounded-md border p-6 text-muted-foreground">
|
<div className="rounded-lg border p-6 text-muted-foreground">
|
||||||
Loading permissions...
|
Loading permissions...
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { ProjectSelect } from '@/components/lookups/ProjectSelect';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
@@ -71,14 +72,14 @@ export function SegmentDialog({
|
|||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent
|
<DialogContent
|
||||||
className="flex max-h-[calc(100vh-2rem)] flex-col gap-0 p-0 sm:max-w-2xl"
|
className="sm:max-w-2xl"
|
||||||
onOpenAutoFocus={(event) => event.preventDefault()}
|
onOpenAutoFocus={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
<DialogHeader className="shrink-0 border-b px-6 py-4 pr-12">
|
<DialogHeader>
|
||||||
<DialogTitle className="text-lg leading-none font-semibold tracking-tight">
|
<DialogTitle>
|
||||||
{segmentId ? 'Edit Segment' : 'Create Segment'}
|
{segmentId ? 'Edit Segment' : 'Create Segment'}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogDescription className="text-sm">
|
<DialogDescription>
|
||||||
Manage segment binding, chainage values, direction, and coordinates.
|
Manage segment binding, chainage values, direction, and coordinates.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
@@ -88,7 +89,7 @@ export function SegmentDialog({
|
|||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
className="flex min-h-0 flex-1 flex-col"
|
className="flex min-h-0 flex-1 flex-col"
|
||||||
>
|
>
|
||||||
<div className="max-h-[58vh] space-y-6 overflow-y-auto px-6 py-4">
|
<DialogBody className="space-y-6">
|
||||||
<section className="space-y-4">
|
<section className="space-y-4">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<h3 className="text-sm font-semibold">Basic details</h3>
|
<h3 className="text-sm font-semibold">Basic details</h3>
|
||||||
@@ -300,9 +301,9 @@ export function SegmentDialog({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</DialogBody>
|
||||||
|
|
||||||
<DialogFooter className="shrink-0 border-t px-6 py-4">
|
<DialogFooter>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
@@ -4,6 +4,16 @@ import { useCallback, useState } from 'react';
|
|||||||
import { Milestone, Plus } from 'lucide-react';
|
import { Milestone, Plus } from 'lucide-react';
|
||||||
|
|
||||||
import { PageHeader } from '@/components/page-header';
|
import { PageHeader } from '@/components/page-header';
|
||||||
|
import {
|
||||||
|
AlertDialog,
|
||||||
|
AlertDialogAction,
|
||||||
|
AlertDialogCancel,
|
||||||
|
AlertDialogContent,
|
||||||
|
AlertDialogDescription,
|
||||||
|
AlertDialogFooter,
|
||||||
|
AlertDialogHeader,
|
||||||
|
AlertDialogTitle,
|
||||||
|
} from '@/components/ui/alert-dialog';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import type { Chainage } from '@/types';
|
import type { Chainage } from '@/types';
|
||||||
|
|
||||||
@@ -21,6 +31,7 @@ import {
|
|||||||
|
|
||||||
export default function SegmentPage() {
|
export default function SegmentPage() {
|
||||||
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
const [isDialogOpen, setIsDialogOpen] = useState(false);
|
||||||
|
const [segmentToDelete, setSegmentToDelete] = useState<Chainage | null>(null);
|
||||||
const { skip, setSkip, limit, setLimit } = useSegmentFilters();
|
const { skip, setSkip, limit, setLimit } = useSegmentFilters();
|
||||||
const segmentsQuery = useSegmentsQuery({ skip, limit });
|
const segmentsQuery = useSegmentsQuery({ skip, limit });
|
||||||
const projectsQuery = useProjectOptionsQuery();
|
const projectsQuery = useProjectOptionsQuery();
|
||||||
@@ -75,18 +86,25 @@ export default function SegmentPage() {
|
|||||||
|
|
||||||
const deleteSegment = useCallback(
|
const deleteSegment = useCallback(
|
||||||
(segment: Chainage) => {
|
(segment: Chainage) => {
|
||||||
if (
|
setSegmentToDelete(segment);
|
||||||
!confirm(
|
|
||||||
`Are you sure you want to delete segment "${segment.segment_name}"?`,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
deleteSegmentMutation.mutate(segment);
|
|
||||||
},
|
},
|
||||||
[deleteSegmentMutation],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const handleDeleteDialogOpenChange = useCallback((open: boolean) => {
|
||||||
|
if (!open) {
|
||||||
|
setSegmentToDelete(null);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const confirmDeleteSegment = useCallback(() => {
|
||||||
|
if (!segmentToDelete) return;
|
||||||
|
|
||||||
|
deleteSegmentMutation.mutate(segmentToDelete, {
|
||||||
|
onSettled: () => setSegmentToDelete(null),
|
||||||
|
});
|
||||||
|
}, [deleteSegmentMutation, segmentToDelete]);
|
||||||
|
|
||||||
const projects = projectsQuery.data?.items ?? [];
|
const projects = projectsQuery.data?.items ?? [];
|
||||||
const allPackages = allPackagesQuery.data?.items ?? [];
|
const allPackages = allPackagesQuery.data?.items ?? [];
|
||||||
const segments = segmentsQuery.data?.items ?? [];
|
const segments = segmentsQuery.data?.items ?? [];
|
||||||
@@ -139,6 +157,36 @@ export default function SegmentPage() {
|
|||||||
canSubmit={canSubmit}
|
canSubmit={canSubmit}
|
||||||
isSaving={isSaving}
|
isSaving={isSaving}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<AlertDialog
|
||||||
|
open={Boolean(segmentToDelete)}
|
||||||
|
onOpenChange={handleDeleteDialogOpenChange}
|
||||||
|
>
|
||||||
|
<AlertDialogContent>
|
||||||
|
<AlertDialogHeader>
|
||||||
|
<AlertDialogTitle>Delete segment?</AlertDialogTitle>
|
||||||
|
<AlertDialogDescription>
|
||||||
|
This will permanently delete{' '}
|
||||||
|
<span className="font-medium text-foreground">
|
||||||
|
{segmentToDelete?.segment_name}
|
||||||
|
</span>
|
||||||
|
. This action cannot be undone.
|
||||||
|
</AlertDialogDescription>
|
||||||
|
</AlertDialogHeader>
|
||||||
|
<AlertDialogFooter>
|
||||||
|
<AlertDialogCancel disabled={deleteSegmentMutation.isPending}>
|
||||||
|
Cancel
|
||||||
|
</AlertDialogCancel>
|
||||||
|
<AlertDialogAction
|
||||||
|
variant="destructive"
|
||||||
|
disabled={deleteSegmentMutation.isPending}
|
||||||
|
onClick={confirmDeleteSegment}
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</AlertDialogAction>
|
||||||
|
</AlertDialogFooter>
|
||||||
|
</AlertDialogContent>
|
||||||
|
</AlertDialog>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import { FormField, PhoneInput, SelectPopover } from '@/components/form';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
@@ -98,12 +99,12 @@ export function TenantSheet({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="flex max-h-[calc(100vh-2rem)] flex-col gap-0 p-0 sm:max-w-3xl">
|
<DialogContent className="sm:max-w-3xl">
|
||||||
<DialogHeader className="shrink-0 border-b px-6 py-4 pr-12">
|
<DialogHeader>
|
||||||
<DialogTitle className="text-lg leading-none font-semibold tracking-tight">
|
<DialogTitle>
|
||||||
{tenantId ? 'Edit Tenant' : 'Create Tenant'}
|
{tenantId ? 'Edit Tenant' : 'Create Tenant'}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogDescription className="text-sm">
|
<DialogDescription>
|
||||||
Bind a client and subscription plan, then invite the tenant
|
Bind a client and subscription plan, then invite the tenant
|
||||||
administrator.
|
administrator.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
@@ -114,7 +115,7 @@ export function TenantSheet({
|
|||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
className="flex min-h-0 flex-1 flex-col"
|
className="flex min-h-0 flex-1 flex-col"
|
||||||
>
|
>
|
||||||
<div className="max-h-[50vh] space-y-5 overflow-y-auto px-6 py-4">
|
<DialogBody className="space-y-5">
|
||||||
<div className="space-y-1">
|
<div className="space-y-1">
|
||||||
<p>Basic Information</p>
|
<p>Basic Information</p>
|
||||||
<p className="text-muted-foreground">
|
<p className="text-muted-foreground">
|
||||||
@@ -227,7 +228,7 @@ export function TenantSheet({
|
|||||||
id="tenant-description"
|
id="tenant-description"
|
||||||
placeholder="North zone operations"
|
placeholder="North zone operations"
|
||||||
{...register('description')}
|
{...register('description')}
|
||||||
className="min-h-20 w-full rounded-md border border-input bg-background px-3 py-2 outline-none focus-visible:border-ring"
|
className="min-h-20 w-full rounded-lg border border-input bg-background px-3 py-2 outline-none focus-visible:border-ring"
|
||||||
/>
|
/>
|
||||||
</FormField>
|
</FormField>
|
||||||
</div>
|
</div>
|
||||||
@@ -314,7 +315,7 @@ export function TenantSheet({
|
|||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
) : adminEmail ? (
|
) : adminEmail ? (
|
||||||
<div className="rounded-md border bg-muted/40 p-4 text-muted-foreground">
|
<div className="rounded-lg border bg-muted/40 p-4 text-muted-foreground">
|
||||||
Admin invitation details cannot be changed after tenant
|
Admin invitation details cannot be changed after tenant
|
||||||
creation.
|
creation.
|
||||||
<p className="mt-1 text-foreground">
|
<p className="mt-1 text-foreground">
|
||||||
@@ -322,9 +323,9 @@ export function TenantSheet({
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</DialogBody>
|
||||||
|
|
||||||
<DialogFooter className="shrink-0 border-t px-6 py-4">
|
<DialogFooter>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
@@ -0,0 +1,161 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState, type FormEvent } from 'react';
|
||||||
|
import { Loader2, Trash2 } from 'lucide-react';
|
||||||
|
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from '@/components/ui/dialog';
|
||||||
|
import { Label } from '@/components/ui/label';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectItem,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from '@/components/ui/select';
|
||||||
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
import type { DetectionDiscardReason, DiscardDetectionPayload } from '@/types';
|
||||||
|
|
||||||
|
const DISCARD_REASON_OPTIONS: Array<{
|
||||||
|
value: DetectionDiscardReason;
|
||||||
|
label: string;
|
||||||
|
}> = [
|
||||||
|
{ value: 'not_a_defect', label: 'Not a defect' },
|
||||||
|
{ value: 'wrong_class', label: 'Wrong classification' },
|
||||||
|
{ value: 'duplicate', label: 'Duplicate detection' },
|
||||||
|
{ value: 'poor_image_quality', label: 'Poor image quality' },
|
||||||
|
{ value: 'incorrect_location', label: 'Incorrect location' },
|
||||||
|
{ value: 'already_repaired', label: 'Already repaired' },
|
||||||
|
{ value: 'other', label: 'Other' },
|
||||||
|
];
|
||||||
|
|
||||||
|
interface DetectionDiscardDialogProps {
|
||||||
|
open: boolean;
|
||||||
|
detectionLabel: string;
|
||||||
|
isPending: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
onSubmit: (payload: DiscardDetectionPayload) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function DetectionDiscardDialog({
|
||||||
|
open,
|
||||||
|
detectionLabel,
|
||||||
|
isPending,
|
||||||
|
onOpenChange,
|
||||||
|
onSubmit,
|
||||||
|
}: DetectionDiscardDialogProps) {
|
||||||
|
const [reason, setReason] = useState<DetectionDiscardReason | ''>('');
|
||||||
|
const [comment, setComment] = useState('');
|
||||||
|
|
||||||
|
const resetForm = () => {
|
||||||
|
setReason('');
|
||||||
|
setComment('');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleOpenChange = (nextOpen: boolean) => {
|
||||||
|
if (isPending) return;
|
||||||
|
|
||||||
|
if (!nextOpen) resetForm();
|
||||||
|
onOpenChange(nextOpen);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
|
||||||
|
event.preventDefault();
|
||||||
|
if (!reason || isPending) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await onSubmit({
|
||||||
|
reason,
|
||||||
|
comment: comment.trim() || undefined,
|
||||||
|
});
|
||||||
|
resetForm();
|
||||||
|
} catch {
|
||||||
|
// The mutation displays the request error and keeps the dialog open.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
|
<DialogContent showCloseButton={!isPending}>
|
||||||
|
<form className="flex min-h-0 flex-1 flex-col" onSubmit={handleSubmit}>
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Discard detection</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Remove {detectionLabel} from this ticket and record why the AI
|
||||||
|
result is incorrect.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<DialogBody className="space-y-5">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="discard-reason">Reason</Label>
|
||||||
|
<Select
|
||||||
|
value={reason}
|
||||||
|
onValueChange={(value) =>
|
||||||
|
setReason(value as DetectionDiscardReason)
|
||||||
|
}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
<SelectTrigger id="discard-reason" className="w-full">
|
||||||
|
<SelectValue placeholder="Select a reason" />
|
||||||
|
</SelectTrigger>
|
||||||
|
<SelectContent>
|
||||||
|
{DISCARD_REASON_OPTIONS.map((option) => (
|
||||||
|
<SelectItem key={option.value} value={option.value}>
|
||||||
|
{option.label}
|
||||||
|
</SelectItem>
|
||||||
|
))}
|
||||||
|
</SelectContent>
|
||||||
|
</Select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<div className="flex items-center justify-between gap-3">
|
||||||
|
<Label htmlFor="discard-comment">Comment</Label>
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
|
Optional | {comment.length}/500
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<Textarea
|
||||||
|
id="discard-comment"
|
||||||
|
value={comment}
|
||||||
|
onChange={(event) => setComment(event.target.value)}
|
||||||
|
placeholder="Add details that can help improve future detections"
|
||||||
|
rows={4}
|
||||||
|
maxLength={500}
|
||||||
|
disabled={isPending}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</DialogBody>
|
||||||
|
|
||||||
|
<DialogFooter>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => handleOpenChange(false)}
|
||||||
|
disabled={isPending}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
variant="destructive"
|
||||||
|
disabled={!reason || isPending}
|
||||||
|
>
|
||||||
|
{isPending ? <Loader2 className="animate-spin" /> : <Trash2 />}
|
||||||
|
{isPending ? 'Discarding' : 'Discard detection'}
|
||||||
|
</Button>
|
||||||
|
</DialogFooter>
|
||||||
|
</form>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
import { Card, CardContent, CardHeader } from '@/components/ui/card';
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
|
import { Timeline, TimelineItem } from '@/components/ui/timeline';
|
||||||
|
|
||||||
|
function TimelineEntrySkeleton({
|
||||||
|
index,
|
||||||
|
isLast,
|
||||||
|
}: {
|
||||||
|
index: number;
|
||||||
|
isLast: boolean;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<TimelineItem
|
||||||
|
layout="left"
|
||||||
|
isLast={isLast}
|
||||||
|
opposite={
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="ml-auto h-4 w-16" />
|
||||||
|
<Skeleton className="ml-auto h-3 w-12" />
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
marker={<Skeleton className="size-4 rounded-full" />}
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={
|
||||||
|
index === 0
|
||||||
|
? 'rounded-lg border border-dashed border-primary/25 bg-primary/5 px-4 py-3.5'
|
||||||
|
: 'rounded-lg border bg-card p-4'
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{index === 0 ? <Skeleton className="h-5 w-28 rounded-lg" /> : null}
|
||||||
|
<Skeleton className={index === 0 ? 'mt-3 h-4 w-44' : 'h-4 w-44'} />
|
||||||
|
{index === 0 ? (
|
||||||
|
<Skeleton className="mt-2 h-3 w-full max-w-md" />
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="mt-3 flex items-center gap-3">
|
||||||
|
<Skeleton className="size-9 rounded-full" />
|
||||||
|
<div className="min-w-0 flex-1 space-y-2">
|
||||||
|
<Skeleton className="h-4 w-36" />
|
||||||
|
<Skeleton className="h-3 w-48 max-w-full" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Skeleton className="mt-3 h-16 w-full rounded-lg" />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</TimelineItem>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TicketClassContentSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="space-y-4" aria-label="Loading defect class details">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Skeleton className="size-5 rounded-lg" />
|
||||||
|
<Skeleton className="h-5 w-56 max-w-full" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<Timeline>
|
||||||
|
{Array.from({ length: 3 }).map((_, index) => (
|
||||||
|
<TimelineEntrySkeleton
|
||||||
|
key={index}
|
||||||
|
index={index}
|
||||||
|
isLast={index === 2}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Timeline>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TicketClassActionsSkeleton() {
|
||||||
|
return (
|
||||||
|
<Card aria-label="Loading defect class actions">
|
||||||
|
<CardHeader>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Skeleton className="size-4 rounded-lg" />
|
||||||
|
<Skeleton className="h-5 w-32" />
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
<Skeleton className="h-10 w-full" />
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-4 w-12" />
|
||||||
|
<Skeleton className="h-20 w-full" />
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-10 w-full" />
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,318 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
import { AlertTriangle, ChevronLeft, ChevronRight, Trash2 } from 'lucide-react';
|
||||||
|
|
||||||
|
import DetectionLocationMap from '@/components/map/detectionLocationMap';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
|
import AnnotatedDetectionImage from '@/components/video/annotatedDetectionImage';
|
||||||
|
import { getDefectVisual } from '@/constants/defectVisualConfig';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
import {
|
||||||
|
useDiscardDetectionMutation,
|
||||||
|
useTicketClassDetectionsQuery,
|
||||||
|
} from '../../hooks/useTicketQueries';
|
||||||
|
import { DetectionDiscardDialog } from './DetectionDiscardDialog';
|
||||||
|
|
||||||
|
interface TicketClassDetectionPreviewProps {
|
||||||
|
ticketId: string;
|
||||||
|
videoId?: string | null;
|
||||||
|
defectClassName: string;
|
||||||
|
displayName: string;
|
||||||
|
totalCount?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DetectionMetadataBar({
|
||||||
|
items,
|
||||||
|
}: {
|
||||||
|
items: { label: string; value: string | number }[];
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg bg-muted/40 px-4 py-4">
|
||||||
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-3 sm:divide-x sm:divide-border/70">
|
||||||
|
{items.map((item, index) => (
|
||||||
|
<div
|
||||||
|
key={item.label}
|
||||||
|
className={cn(
|
||||||
|
'space-y-1',
|
||||||
|
index === 0 && 'sm:pr-4',
|
||||||
|
index === 1 && 'sm:px-4',
|
||||||
|
index === 2 && 'sm:pl-4',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<p className="text-xs text-muted-foreground">{item.label}</p>
|
||||||
|
<div className="text-sm font-semibold text-foreground">
|
||||||
|
{item.value}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function TicketClassDetectionPreviewSkeleton() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="grid grid-cols-1 gap-4 xl:grid-cols-2">
|
||||||
|
<div className="min-w-0 space-y-2">
|
||||||
|
<Skeleton className="h-3 w-24" />
|
||||||
|
<Skeleton className="aspect-video w-full rounded-lg" />
|
||||||
|
</div>
|
||||||
|
<div className="min-w-0 space-y-2">
|
||||||
|
<Skeleton className="h-3 w-28" />
|
||||||
|
<Skeleton
|
||||||
|
className="w-full rounded-lg"
|
||||||
|
style={{ aspectRatio: '16 / 9' }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="rounded-lg bg-muted/40 px-4 py-4">
|
||||||
|
<div className="grid grid-cols-1 gap-4 sm:grid-cols-3 sm:divide-x sm:divide-border/70">
|
||||||
|
{Array.from({ length: 3 }).map((_, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className={cn(
|
||||||
|
'space-y-1',
|
||||||
|
index === 0 && 'sm:pr-4',
|
||||||
|
index === 1 && 'sm:px-4',
|
||||||
|
index === 2 && 'sm:pl-4',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Skeleton className="h-3 w-16" />
|
||||||
|
<Skeleton className="h-4 w-20" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TicketClassDetectionPreview({
|
||||||
|
ticketId,
|
||||||
|
videoId,
|
||||||
|
defectClassName,
|
||||||
|
displayName,
|
||||||
|
totalCount,
|
||||||
|
}: TicketClassDetectionPreviewProps) {
|
||||||
|
const [currentIndex, setCurrentIndex] = useState(0);
|
||||||
|
const [isDiscardDialogOpen, setIsDiscardDialogOpen] = useState(false);
|
||||||
|
const visual = getDefectVisual(defectClassName);
|
||||||
|
const IssueIcon = visual.icon;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setCurrentIndex(0);
|
||||||
|
}, [defectClassName]);
|
||||||
|
|
||||||
|
const queryParams = useMemo(
|
||||||
|
() => ({
|
||||||
|
class_name: defectClassName,
|
||||||
|
skip: currentIndex,
|
||||||
|
limit: 1,
|
||||||
|
sort: 'timestamp_asc',
|
||||||
|
}),
|
||||||
|
[currentIndex, defectClassName],
|
||||||
|
);
|
||||||
|
|
||||||
|
const detectionsQuery = useTicketClassDetectionsQuery(
|
||||||
|
videoId ?? undefined,
|
||||||
|
queryParams,
|
||||||
|
);
|
||||||
|
const discardMutation = useDiscardDetectionMutation(
|
||||||
|
ticketId,
|
||||||
|
videoId ?? undefined,
|
||||||
|
defectClassName,
|
||||||
|
);
|
||||||
|
const detectionResult = detectionsQuery.data;
|
||||||
|
const activeDetection = detectionResult?.items[0];
|
||||||
|
const detectionCount = detectionResult?.total ?? totalCount ?? 0;
|
||||||
|
const mediaAspectRatio =
|
||||||
|
detectionResult &&
|
||||||
|
detectionResult.video_width > 0 &&
|
||||||
|
detectionResult.video_height > 0
|
||||||
|
? `${detectionResult.video_width} / ${detectionResult.video_height}`
|
||||||
|
: '16 / 9';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (detectionCount === 0 && currentIndex !== 0) {
|
||||||
|
setCurrentIndex(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (detectionCount > 0 && currentIndex > detectionCount - 1) {
|
||||||
|
setCurrentIndex(detectionCount - 1);
|
||||||
|
}
|
||||||
|
}, [currentIndex, detectionCount]);
|
||||||
|
|
||||||
|
const isNavigationDisabled =
|
||||||
|
detectionCount === 0 || detectionsQuery.isLoading;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
||||||
|
<div className="flex min-w-0 items-center gap-3">
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
'flex size-10 shrink-0 self-start items-center justify-center rounded-lg',
|
||||||
|
visual.cardClassName,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<IssueIcon className={cn('size-5', visual.colorClassName)} />
|
||||||
|
</span>
|
||||||
|
<div className="min-w-0 space-y-1">
|
||||||
|
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
||||||
|
<h3>{displayName}</h3>
|
||||||
|
<Badge
|
||||||
|
variant="secondary"
|
||||||
|
className={cn(
|
||||||
|
'rounded-lg',
|
||||||
|
visual.cardClassName,
|
||||||
|
visual.colorClassName,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{detectionCount} Detections
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
<p className="text-muted-foreground">
|
||||||
|
Review detections in ascending timestamp order.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2 self-start sm:self-auto">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
onClick={() =>
|
||||||
|
setCurrentIndex((index) =>
|
||||||
|
detectionCount === 0
|
||||||
|
? 0
|
||||||
|
: (index - 1 + detectionCount) % detectionCount,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
disabled={isNavigationDisabled}
|
||||||
|
aria-label="Previous detection"
|
||||||
|
>
|
||||||
|
<ChevronLeft className="size-4" />
|
||||||
|
</Button>
|
||||||
|
<div className="min-w-16 text-center text-sm font-medium text-foreground">
|
||||||
|
{detectionCount === 0
|
||||||
|
? '0 of 0'
|
||||||
|
: `${currentIndex + 1} of ${detectionCount}`}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
onClick={() =>
|
||||||
|
setCurrentIndex((index) =>
|
||||||
|
detectionCount === 0 ? 0 : (index + 1) % detectionCount,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
disabled={isNavigationDisabled}
|
||||||
|
aria-label="Next detection"
|
||||||
|
>
|
||||||
|
<ChevronRight className="size-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{detectionsQuery.isLoading && !detectionsQuery.data ? (
|
||||||
|
<TicketClassDetectionPreviewSkeleton />
|
||||||
|
) : detectionsQuery.isError ? (
|
||||||
|
<div className="rounded-lg border border-dashed border-destructive/40 bg-destructive/5 px-4 py-8 text-center">
|
||||||
|
<div className="flex flex-col items-center gap-2">
|
||||||
|
<AlertTriangle className="size-6 text-destructive" />
|
||||||
|
<p className="text-sm font-medium text-destructive">
|
||||||
|
Failed to load detection preview.
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
onClick={() => void detectionsQuery.refetch()}
|
||||||
|
>
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : !activeDetection || !detectionResult ? (
|
||||||
|
<div className="rounded-lg border border-dashed bg-muted/20 px-4 py-10 text-center text-sm text-muted-foreground">
|
||||||
|
No detections are available for this issue.
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="grid grid-cols-1 items-start gap-4 xl:grid-cols-2">
|
||||||
|
<div className="min-w-0 space-y-2">
|
||||||
|
<p className="text-muted-foreground">Detection Image</p>
|
||||||
|
<div className="overflow-hidden rounded-lg">
|
||||||
|
<AnnotatedDetectionImage
|
||||||
|
detection={activeDetection}
|
||||||
|
videoWidth={detectionResult.video_width}
|
||||||
|
videoHeight={detectionResult.video_height}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DetectionLocationMap
|
||||||
|
className="min-w-0"
|
||||||
|
latitude={activeDetection.location.latitude}
|
||||||
|
longitude={activeDetection.location.longitude}
|
||||||
|
label={`${displayName} - Frame ${activeDetection.frame.number}`}
|
||||||
|
title="Location on Map"
|
||||||
|
variant="plain"
|
||||||
|
aspectRatio={mediaAspectRatio}
|
||||||
|
showCoordinates={false}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DetectionMetadataBar
|
||||||
|
items={[
|
||||||
|
{
|
||||||
|
label: 'Confidence',
|
||||||
|
value: `${Math.round(activeDetection.detection.confidence * 100)}%`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Frame',
|
||||||
|
value: activeDetection.frame.number,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Timestamp',
|
||||||
|
value: `${activeDetection.frame.timestamp_seconds}s`,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="flex justify-end">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="destructive"
|
||||||
|
onClick={() => setIsDiscardDialogOpen(true)}
|
||||||
|
>
|
||||||
|
<Trash2 />
|
||||||
|
Discard detection
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<DetectionDiscardDialog
|
||||||
|
open={isDiscardDialogOpen}
|
||||||
|
detectionLabel={activeDetection.detection.display_name}
|
||||||
|
isPending={discardMutation.isPending}
|
||||||
|
onOpenChange={setIsDiscardDialogOpen}
|
||||||
|
onSubmit={async (payload) => {
|
||||||
|
await discardMutation.mutateAsync({
|
||||||
|
detectionId: activeDetection.detection.id,
|
||||||
|
payload,
|
||||||
|
});
|
||||||
|
setIsDiscardDialogOpen(false);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,164 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
|
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import { Component, ListChecks } from 'lucide-react';
|
||||||
|
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Card, CardContent } from '@/components/ui/card';
|
||||||
|
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||||
|
import { DEFECT_CLASS_STATUS_CONFIG } from '@/constants/defectClassStatus';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import type { TicketOverviewDetail } from '@/types';
|
||||||
|
|
||||||
|
import { useTicketDefectClassesQuery } from '../../hooks/useTicketQueries';
|
||||||
|
import { TicketClassDetectionPreview } from './TicketClassDetectionPreview';
|
||||||
|
|
||||||
|
interface TicketDefectClassTabsProps {
|
||||||
|
ticketId: string;
|
||||||
|
ticket?: TicketOverviewDetail;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TicketDefectClassTabs({
|
||||||
|
ticketId,
|
||||||
|
ticket,
|
||||||
|
}: TicketDefectClassTabsProps) {
|
||||||
|
const router = useRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const defectClassParam = searchParams.get('defect_class');
|
||||||
|
const defectClassesQuery = useTicketDefectClassesQuery(ticketId);
|
||||||
|
const defectClasses = useMemo(
|
||||||
|
() => defectClassesQuery.data?.defect_classes ?? [],
|
||||||
|
[defectClassesQuery.data?.defect_classes],
|
||||||
|
);
|
||||||
|
const [selectedClass, setSelectedClass] = useState<string>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!defectClasses.length) return;
|
||||||
|
|
||||||
|
const hasUrlClass = defectClasses.some(
|
||||||
|
(item) => item.class_name === defectClassParam,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (hasUrlClass) {
|
||||||
|
setSelectedClass(defectClassParam ?? undefined);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstClass = defectClasses[0].class_name;
|
||||||
|
const nextParams = new URLSearchParams(searchParams.toString());
|
||||||
|
nextParams.set('defect_class', firstClass);
|
||||||
|
setSelectedClass(firstClass);
|
||||||
|
router.replace(`${pathname}?${nextParams.toString()}`, { scroll: false });
|
||||||
|
}, [defectClassParam, defectClasses, pathname, router, searchParams]);
|
||||||
|
|
||||||
|
const handleClassChange = (className: string) => {
|
||||||
|
const nextParams = new URLSearchParams(searchParams.toString());
|
||||||
|
|
||||||
|
nextParams.set('defect_class', className);
|
||||||
|
setSelectedClass(className);
|
||||||
|
router.replace(`${pathname}?${nextParams.toString()}`, { scroll: false });
|
||||||
|
};
|
||||||
|
const selectedIssue = ticket?.ai_result.detections_by_class.find(
|
||||||
|
(item) => item.class_name === selectedClass,
|
||||||
|
);
|
||||||
|
const selectedClassItem = defectClasses.find(
|
||||||
|
(item) => item.class_name === selectedClass,
|
||||||
|
);
|
||||||
|
const previewDisplayName =
|
||||||
|
selectedIssue?.display_name ??
|
||||||
|
selectedClassItem?.display_name ??
|
||||||
|
selectedClass ??
|
||||||
|
'Detection';
|
||||||
|
const previewVideoId = ticket?.video_id ?? defectClassesQuery.data?.video_id;
|
||||||
|
|
||||||
|
if (defectClassesQuery.isLoading) {
|
||||||
|
return (
|
||||||
|
<Card className="w-full rounded-lg">
|
||||||
|
<CardContent className="space-y-4 p-5">
|
||||||
|
<div className="h-5 w-24 animate-pulse rounded-lg bg-muted" />
|
||||||
|
<div className="flex flex-col gap-2">
|
||||||
|
{Array.from({ length: 3 }).map((_, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="h-11 w-full animate-pulse rounded-lg bg-muted"
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (defectClassesQuery.isError || !defectClasses.length || !selectedClass) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Tabs
|
||||||
|
value={selectedClass}
|
||||||
|
onValueChange={handleClassChange}
|
||||||
|
orientation="vertical"
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
|
<Card className="w-full">
|
||||||
|
<CardContent className="grid gap-0 p-0 lg:grid-cols-[minmax(220px,280px)_1fr] lg:divide-x lg:divide-border">
|
||||||
|
<div className="space-y-4 px-5">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<ListChecks className="size-5 shrink-0 text-primary" />
|
||||||
|
<h2 className="text-base font-semibold">Detected Issues</h2>
|
||||||
|
<Badge
|
||||||
|
variant="secondary"
|
||||||
|
className="min-w-5 min-h-5 justify-center rounded-full"
|
||||||
|
>
|
||||||
|
{defectClasses.length}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<TabsList className="flex h-auto w-full flex-col items-stretch gap-2 bg-transparent p-0">
|
||||||
|
{defectClasses.map((item) => {
|
||||||
|
const statusConfig =
|
||||||
|
DEFECT_CLASS_STATUS_CONFIG[item.assignment_status];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TabsTrigger
|
||||||
|
key={item.class_name}
|
||||||
|
value={item.class_name}
|
||||||
|
className={cn(
|
||||||
|
'group h-auto w-full flex-none items-center justify-between! gap-2 rounded-lg border bg-muted/30 px-3 py-2.5 text-sm text-muted-foreground shadow-none after:hidden',
|
||||||
|
'data-[state=active]:bg-muted data-[state=active]:text-foreground',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<span className="min-w-0 truncate text-left font-medium">
|
||||||
|
{item.display_name}
|
||||||
|
</span>
|
||||||
|
<Badge
|
||||||
|
className={cn(
|
||||||
|
'shrink-0 rounded-full',
|
||||||
|
statusConfig.badgeClassName,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Component className="size-3" />
|
||||||
|
{statusConfig.label}
|
||||||
|
</Badge>
|
||||||
|
</TabsTrigger>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</TabsList>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="min-w-0 px-5">
|
||||||
|
<TicketClassDetectionPreview
|
||||||
|
ticketId={ticketId}
|
||||||
|
videoId={previewVideoId}
|
||||||
|
defectClassName={selectedClass}
|
||||||
|
displayName={previewDisplayName}
|
||||||
|
totalCount={selectedIssue?.count}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</Tabs>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -4,43 +4,26 @@ import { ArrowLeft } from 'lucide-react';
|
|||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { SparkleButton } from '@/components/ui/sparkle-button';
|
import type { TicketOverviewDetail } from '@/types';
|
||||||
import { PERMISSIONS } from '@/constants/permissions';
|
|
||||||
import { PermissionGuard } from '@/guards';
|
|
||||||
import type { TicketDetail } from '@/types';
|
|
||||||
|
|
||||||
import { TicketStatusBadge } from '../../components/TicketStatusBadge';
|
export function TicketDetailHeader({
|
||||||
|
ticket,
|
||||||
export function TicketDetailHeader({ ticket }: { ticket: TicketDetail }) {
|
}: {
|
||||||
|
ticket: TicketOverviewDetail;
|
||||||
|
}) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const ticketLabel = ticket.ticket_name || ticket.id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
|
||||||
<div className="min-w-0 space-y-1">
|
<div className="min-w-0 space-y-1">
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
<h1 className="text-2xl font-semibold tracking-tight">Ticket Detail</h1>
|
||||||
<h1 className="text-2xl font-semibold tracking-tight">
|
<p className="text-xs ">Ticket: {ticketLabel}</p>
|
||||||
Ticket Detail
|
|
||||||
</h1>
|
|
||||||
<TicketStatusBadge status={ticket.status} />
|
|
||||||
</div>
|
|
||||||
<p className="text-xs ">Ticket ID: {ticket.id}</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex shrink-0 items-center gap-2">
|
<div className="flex shrink-0 items-center gap-2">
|
||||||
{ticket.video_id ? (
|
|
||||||
<PermissionGuard permissions={PERMISSIONS.TICKET.ASSIGN}>
|
|
||||||
<SparkleButton
|
|
||||||
className="h-10 min-w-36 px-5"
|
|
||||||
onClick={() => router.push(`/results/${ticket.video_id}`)}
|
|
||||||
>
|
|
||||||
View Analysis
|
|
||||||
</SparkleButton>
|
|
||||||
</PermissionGuard>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="secondary"
|
||||||
size="sm"
|
|
||||||
onClick={() => router.push('/ticket')}
|
onClick={() => router.push('/ticket')}
|
||||||
>
|
>
|
||||||
<ArrowLeft className="size-4" />
|
<ArrowLeft className="size-4" />
|
||||||
|
|||||||
@@ -2,89 +2,84 @@
|
|||||||
|
|
||||||
import { History, MessageSquareText } from 'lucide-react';
|
import { History, MessageSquareText } from 'lucide-react';
|
||||||
|
|
||||||
|
import { PersonInfo } from '@/components/person-avatar';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Timeline, TimelineItem } from '@/components/ui/timeline';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import type { TicketDetail, TicketHistoryItem, TicketStatus } from '@/types';
|
import type { TicketDetail, TicketHistoryItem, TicketHistorySource } from '@/types';
|
||||||
import { formatDate } from '@/utils/date';
|
import { formatTimelineDateTime } from '@/utils/date';
|
||||||
|
import { getPersonLabel } from '@/utils/person';
|
||||||
|
|
||||||
import { formatTicketStatus } from '../../components/TicketStatusBadge';
|
function TimelineDate({ value }: { value: string }) {
|
||||||
|
const { date, time } = formatTimelineDateTime(value);
|
||||||
function getActorLabel(item: TicketHistoryItem) {
|
|
||||||
return item.actor?.name || item.actor?.email || 'System';
|
|
||||||
}
|
|
||||||
|
|
||||||
function getLifecycleTitle(status: TicketStatus) {
|
|
||||||
const titles: Record<TicketStatus, string> = {
|
|
||||||
processing: 'Incident Ticket Created',
|
|
||||||
unassigned: 'Awaiting Assignment',
|
|
||||||
assigned: 'Dispatched to Maintenance',
|
|
||||||
under_review: 'Maintenance Finalized',
|
|
||||||
closed: 'Ticket Closed',
|
|
||||||
};
|
|
||||||
|
|
||||||
return titles[status] ?? formatTicketStatus(status);
|
|
||||||
}
|
|
||||||
|
|
||||||
function HistoryEntry({
|
|
||||||
item,
|
|
||||||
isLast,
|
|
||||||
}: {
|
|
||||||
item: TicketHistoryItem;
|
|
||||||
isLast: boolean;
|
|
||||||
}) {
|
|
||||||
const isClosed = item.to_status === 'closed';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="relative flex gap-4 pb-8 last:pb-0">
|
<time dateTime={value} className="block tabular-nums">
|
||||||
{!isLast ? (
|
<span className="block text-sm font-semibold text-foreground">{date}</span>
|
||||||
<span
|
<span className="block text-xs text-muted-foreground">{time}</span>
|
||||||
aria-hidden
|
</time>
|
||||||
className="absolute top-6 left-[11px] h-[calc(100%-10px)] w-px bg-border"
|
);
|
||||||
/>
|
}
|
||||||
) : null}
|
|
||||||
|
|
||||||
<span
|
function HistoryNote({ item }: { item: TicketHistoryItem }) {
|
||||||
aria-hidden
|
const noteText = item.note?.text?.trim();
|
||||||
className={cn(
|
if (!noteText) return null;
|
||||||
'relative z-10 mt-0.5 flex size-6 shrink-0 items-center justify-center rounded-full border-2 bg-background',
|
|
||||||
isClosed
|
|
||||||
? 'border-primary bg-primary text-primary-foreground'
|
|
||||||
: 'border-primary/60',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
className={cn(
|
|
||||||
'size-2 rounded-full bg-primary',
|
|
||||||
isClosed &&
|
|
||||||
'h-1.5 w-2.5 rotate-[-45deg] rounded-none border-b-2 border-l-2 border-current bg-transparent',
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<div className="min-w-0 flex-1 space-y-2">
|
return (
|
||||||
<div className="flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
<div className="mt-3 rounded-lg border border-amber-300/80 bg-amber-50/90 px-3 py-2.5 dark:border-amber-500/30 dark:bg-amber-500/10">
|
||||||
<h3 className="text-sm font-semibold text-foreground">
|
<div className="flex items-center gap-1.5 text-xs font-medium text-amber-900 dark:text-amber-200">
|
||||||
{getLifecycleTitle(item.to_status)}
|
<MessageSquareText className="size-3.5 shrink-0 text-amber-700 dark:text-amber-300" />
|
||||||
</h3>
|
<span>
|
||||||
<time
|
Note by {getPersonLabel(item.note?.author ?? item.actor)}
|
||||||
dateTime={item.created_at}
|
</span>
|
||||||
className="text-xs font-semibold text-muted-foreground tabular-nums"
|
|
||||||
>
|
|
||||||
{formatDate(item.created_at)}
|
|
||||||
</time>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p className="text-xs font-medium text-muted-foreground">
|
|
||||||
Updated By{' '}
|
|
||||||
<span className="text-foreground/90">{getActorLabel(item)}</span>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
{item.note ? (
|
|
||||||
<div className="flex gap-2 rounded-md border border-border bg-background px-3 py-2 text-sm leading-relaxed text-foreground">
|
|
||||||
<MessageSquareText className="mt-0.5 size-4 shrink-0 text-primary" />
|
|
||||||
<p>{item.note}</p>
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
</div>
|
</div>
|
||||||
|
<p className="mt-1.5 text-sm leading-relaxed text-amber-950/80 dark:text-amber-100/90">
|
||||||
|
{noteText}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSourceLabel(source: TicketHistorySource) {
|
||||||
|
return source === 'system' ? 'System Generated' : 'User Action';
|
||||||
|
}
|
||||||
|
|
||||||
|
function SystemHistoryEntry({ item }: { item: TicketHistoryItem }) {
|
||||||
|
const noteText = item.note?.text?.trim();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-dashed border-primary/25 bg-primary/5 px-4 py-3.5">
|
||||||
|
<Badge
|
||||||
|
|
||||||
|
className="rounded-lg px-2.5 py-0.5 text-[10px] font-semibold tracking-wider uppercase"
|
||||||
|
>
|
||||||
|
{getSourceLabel(item.source)}
|
||||||
|
</Badge>
|
||||||
|
<h3 className="mt-2 text-sm font-semibold text-foreground">{item.title}</h3>
|
||||||
|
{noteText ? (
|
||||||
|
<p className="mt-1 text-sm leading-relaxed text-muted-foreground">
|
||||||
|
{noteText}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function UserHistoryEntry({ item }: { item: TicketHistoryItem }) {
|
||||||
|
const noteText = item.note?.text?.trim();
|
||||||
|
const isAssigned = item.event_type === 'assigned';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border bg-card p-4">
|
||||||
|
<h3 className="mb-3 text-sm font-semibold text-foreground">{item.title}</h3>
|
||||||
|
<PersonInfo person={item.actor} />
|
||||||
|
{isAssigned && item.target_user ? (
|
||||||
|
<div className="mt-3 space-y-1">
|
||||||
|
<p className="text-xs text-muted-foreground">Assigned to</p>
|
||||||
|
<PersonInfo person={item.target_user} />
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{noteText ? <HistoryNote item={item} /> : null}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -93,24 +88,41 @@ export function TicketHistoryCard({ ticket }: { ticket: TicketDetail }) {
|
|||||||
const history = ticket.history ?? [];
|
const history = ticket.history ?? [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="rounded-xl border bg-card p-5">
|
<div className="space-y-4">
|
||||||
<div className="mb-5 flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<History className="size-5 text-primary" />
|
<History className="size-5 text-primary" />
|
||||||
<h2 className="text-base font-semibold text-foreground">
|
<h2 className="text-base font-semibold">Audit & Lifecycle Timeline</h2>
|
||||||
Audit & Lifecycle Timeline
|
|
||||||
</h2>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{history.length ? (
|
{history.length ? (
|
||||||
<div className={cn('pl-0.5')}>
|
<Timeline>
|
||||||
{history.map((item, index) => (
|
{history.map((item, index) => (
|
||||||
<HistoryEntry
|
<TimelineItem
|
||||||
key={item.id}
|
key={item.id}
|
||||||
item={item}
|
layout="left"
|
||||||
isLast={index === history.length - 1}
|
isLast={index === history.length - 1}
|
||||||
/>
|
opposite={<TimelineDate value={item.created_at} />}
|
||||||
|
marker={
|
||||||
|
<span className="flex size-4 items-center justify-center rounded-full border bg-background shadow-xs">
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
'size-1.5 rounded-full',
|
||||||
|
item.source === 'system'
|
||||||
|
? 'bg-muted-foreground'
|
||||||
|
: 'bg-primary',
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{item.source === 'system' ? (
|
||||||
|
<SystemHistoryEntry item={item} />
|
||||||
|
) : (
|
||||||
|
<UserHistoryEntry item={item} />
|
||||||
|
)}
|
||||||
|
</TimelineItem>
|
||||||
))}
|
))}
|
||||||
</div>
|
</Timeline>
|
||||||
) : (
|
) : (
|
||||||
<div className="rounded-lg border border-dashed border-border/80 bg-muted/10 px-4 py-8 text-center">
|
<div className="rounded-lg border border-dashed border-border/80 bg-muted/10 px-4 py-8 text-center">
|
||||||
<p className="text-sm font-medium text-muted-foreground">
|
<p className="text-sm font-medium text-muted-foreground">
|
||||||
@@ -118,6 +130,6 @@ export function TicketHistoryCard({ ticket }: { ticket: TicketDetail }) {
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</section>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useRef } from 'react';
|
||||||
|
import type { MediaPlayerInstance } from '@vidstack/react';
|
||||||
|
|
||||||
|
import { useProtectedVideoQuery } from '@/app/(modules)/results/hooks/useVideoResults';
|
||||||
|
import AnnotatedVideoPlayer from '@/components/video/annotatedVideoPlayer';
|
||||||
|
import { useVideoAnnotationPlayback } from '@/components/video/useVideoAnnotationPlayback';
|
||||||
|
import type { TicketOverviewDetail } from '@/types';
|
||||||
|
|
||||||
|
type TicketInlineAnalysisVideoProps = {
|
||||||
|
ticket: TicketOverviewDetail;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function TicketInlineAnalysisVideo({
|
||||||
|
ticket,
|
||||||
|
}: TicketInlineAnalysisVideoProps) {
|
||||||
|
const videoRef = useRef<MediaPlayerInstance | null>(null);
|
||||||
|
const videoId = ticket.video_id ?? ticket.video?.id ?? undefined;
|
||||||
|
const sourceUrl = ticket.video?.url ?? undefined;
|
||||||
|
const fps = ticket.video_metadata?.fps ?? 0;
|
||||||
|
const videoWidth = ticket.video_metadata?.resolution.width ?? 0;
|
||||||
|
const videoHeight = ticket.video_metadata?.resolution.height ?? 0;
|
||||||
|
const {
|
||||||
|
visibleDetections,
|
||||||
|
handleSeeked,
|
||||||
|
handleTimeUpdate,
|
||||||
|
handleVideoFrame,
|
||||||
|
} = useVideoAnnotationPlayback({
|
||||||
|
videoId,
|
||||||
|
logs: [],
|
||||||
|
fps,
|
||||||
|
videoRef,
|
||||||
|
});
|
||||||
|
const {
|
||||||
|
videoUrl,
|
||||||
|
isLoading: isVideoLoading,
|
||||||
|
isError: isVideoError,
|
||||||
|
refetch: refetchVideo,
|
||||||
|
} = useProtectedVideoQuery(sourceUrl);
|
||||||
|
|
||||||
|
if (!videoId || !sourceUrl) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-dashed bg-muted/20 px-4 py-8 text-sm text-muted-foreground">
|
||||||
|
Analysis video is unavailable for this ticket.
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-2">
|
||||||
|
<AnnotatedVideoPlayer
|
||||||
|
videoRef={videoRef}
|
||||||
|
logs={[]}
|
||||||
|
visibleDetections={visibleDetections}
|
||||||
|
videoWidth={videoWidth}
|
||||||
|
videoHeight={videoHeight}
|
||||||
|
videoUrl={videoUrl}
|
||||||
|
isLoading={isVideoLoading}
|
||||||
|
isError={isVideoError}
|
||||||
|
onRetry={() => void refetchVideo()}
|
||||||
|
onTimeUpdate={handleTimeUpdate}
|
||||||
|
onVideoFrame={handleVideoFrame}
|
||||||
|
onSeeked={handleSeeked}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,32 +1,42 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import type { TicketActor, TicketDetail } from '@/types';
|
import {
|
||||||
import { formatDate } from '@/utils/date';
|
Activity,
|
||||||
|
CalendarDays,
|
||||||
|
Clock3,
|
||||||
|
Gauge,
|
||||||
|
MapPin,
|
||||||
|
Monitor,
|
||||||
|
UserRound,
|
||||||
|
Play
|
||||||
|
} from 'lucide-react';
|
||||||
|
import { useState } from 'react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
TicketStatusBadge,
|
Card,
|
||||||
} from '../../components/TicketStatusBadge';
|
CardAction,
|
||||||
|
CardContent,
|
||||||
|
CardHeader,
|
||||||
|
CardTitle,
|
||||||
|
} from '@/components/ui/card';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from '@/components/ui/dialog';
|
||||||
|
import { getDefectVisual } from '@/constants/defectVisualConfig';
|
||||||
|
import { PERMISSIONS } from '@/constants/permissions';
|
||||||
|
import { PermissionGuard } from '@/guards';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import type { TicketOverviewDetail } from '@/types';
|
||||||
|
import { formatDate } from '@/utils/date';
|
||||||
|
import { TicketInlineAnalysisVideo } from './TicketInlineAnalysisVideo';
|
||||||
|
|
||||||
function formatCreatedDate(value: string | null | undefined) {
|
type IconComponent = React.ComponentType<{ className?: string }>;
|
||||||
if (!value) return '-';
|
|
||||||
return new Intl.DateTimeFormat('en-IN', { dateStyle: 'medium' }).format(
|
|
||||||
new Date(value),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getInitials(person: TicketActor | null | undefined) {
|
|
||||||
const source = person?.name || person?.email || '?';
|
|
||||||
return source
|
|
||||||
.split(/[\s@._-]+/)
|
|
||||||
.filter(Boolean)
|
|
||||||
.slice(0, 2)
|
|
||||||
.map((part) => part.charAt(0).toUpperCase())
|
|
||||||
.join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPersonLabel(person: TicketActor | null | undefined) {
|
|
||||||
return person?.name || person?.email || '-';
|
|
||||||
}
|
|
||||||
|
|
||||||
function MetaLabel({ children }: { children: React.ReactNode }) {
|
function MetaLabel({ children }: { children: React.ReactNode }) {
|
||||||
return (
|
return (
|
||||||
@@ -40,29 +50,6 @@ function MetaValue({ children }: { children: React.ReactNode }) {
|
|||||||
return <p className="text-sm font-semibold text-foreground">{children}</p>;
|
return <p className="text-sm font-semibold text-foreground">{children}</p>;
|
||||||
}
|
}
|
||||||
|
|
||||||
function PersonMetaValue({
|
|
||||||
person,
|
|
||||||
accentClassName = 'bg-primary/15 text-primary',
|
|
||||||
}: {
|
|
||||||
person: TicketActor | null | undefined;
|
|
||||||
accentClassName?: string;
|
|
||||||
}) {
|
|
||||||
if (!person) {
|
|
||||||
return <MetaValue>-</MetaValue>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="flex min-w-0 items-center gap-2">
|
|
||||||
<span
|
|
||||||
className={`flex size-5 shrink-0 items-center justify-center rounded-full text-[10px] font-bold ${accentClassName}`}
|
|
||||||
>
|
|
||||||
{getInitials(person)}
|
|
||||||
</span>
|
|
||||||
<p className="truncate text-sm font-medium">{getPersonLabel(person)}</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function OverviewField({
|
function OverviewField({
|
||||||
label,
|
label,
|
||||||
children,
|
children,
|
||||||
@@ -71,68 +58,193 @@ function OverviewField({
|
|||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-1">
|
<div className="min-w-0 space-y-1">
|
||||||
<MetaLabel>{label}</MetaLabel>
|
<MetaLabel>{label}</MetaLabel>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TicketOverviewCard({ ticket }: { ticket: TicketDetail }) {
|
function SummaryCard({
|
||||||
const detectionCount = ticket.ai_result?.detection_count;
|
label,
|
||||||
|
value,
|
||||||
|
colorClassName,
|
||||||
|
cardClassName,
|
||||||
|
}: {
|
||||||
|
label: string;
|
||||||
|
value: number;
|
||||||
|
colorClassName: string;
|
||||||
|
cardClassName: string;
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<section className="overflow-hidden rounded-xl border bg-card">
|
<div
|
||||||
<div className="border-b px-4 py-2.5">
|
className={cn(
|
||||||
<h2 className="text-xs font-medium ">
|
'rounded-lg bg-muted/40 p-4 hover:scale-105 transition-transform ease-in-out',
|
||||||
Overview
|
cardClassName,
|
||||||
</h2>
|
)}
|
||||||
</div>
|
>
|
||||||
|
<p className={cn('text-2xl font-bold tracking-tight', colorClassName)}>
|
||||||
<div className="grid grid-cols-2 gap-x-4 gap-y-6 p-4 md:grid-cols-4">
|
{value}
|
||||||
<OverviewField label="Detection Count">
|
</p>
|
||||||
<MetaValue>
|
<p className="mt-2 truncate text-xs font-semibold text-foreground">
|
||||||
{detectionCount != null ? `${detectionCount} Occurrences` : '-'}
|
{label}
|
||||||
</MetaValue>
|
</p>
|
||||||
</OverviewField>
|
<p className="mt-0.5 text-[11px] text-muted-foreground">Detected</p>
|
||||||
|
</div>
|
||||||
<OverviewField label="Chainage">
|
);
|
||||||
<MetaValue>{ticket.chainage_id || '-'}</MetaValue>
|
}
|
||||||
</OverviewField>
|
|
||||||
|
function VideoMetric({
|
||||||
<OverviewField label="Uploaded By">
|
icon: Icon,
|
||||||
<PersonMetaValue person={ticket.uploader} />
|
label,
|
||||||
</OverviewField>
|
}: {
|
||||||
|
icon: IconComponent;
|
||||||
<OverviewField label="Created Date">
|
label: string;
|
||||||
<MetaValue>{formatCreatedDate(ticket.timestamps.created_at)}</MetaValue>
|
}) {
|
||||||
</OverviewField>
|
return (
|
||||||
|
<div className="flex items-center justify-center gap-2 font-medium">
|
||||||
<OverviewField label="Assigned To">
|
<Icon className="size-4 text-muted-foreground" />
|
||||||
<PersonMetaValue
|
<span>{label}</span>
|
||||||
person={ticket.worker}
|
</div>
|
||||||
accentClassName="bg-secondary text-secondary-foreground"
|
);
|
||||||
/>
|
}
|
||||||
</OverviewField>
|
|
||||||
|
export function TicketOverviewCard({
|
||||||
<OverviewField label="Reviewer">
|
ticket,
|
||||||
<PersonMetaValue
|
}: {
|
||||||
person={ticket.reviewer}
|
ticket: TicketOverviewDetail;
|
||||||
accentClassName="bg-primary/20 text-primary"
|
}) {
|
||||||
/>
|
const [isAnalysisOpen, setIsAnalysisOpen] = useState(false);
|
||||||
</OverviewField>
|
const videoMetadata = ticket.video_metadata;
|
||||||
|
const duration =
|
||||||
<OverviewField label="Assigned At">
|
typeof videoMetadata?.duration_seconds === 'number'
|
||||||
<MetaValue>{formatDate(ticket.worker?.assigned_at)}</MetaValue>
|
? `${Math.floor(videoMetadata.duration_seconds / 60)}:${Math.floor(
|
||||||
</OverviewField>
|
videoMetadata.duration_seconds % 60,
|
||||||
|
)
|
||||||
</div>
|
.toString()
|
||||||
|
.padStart(2, '0')}`
|
||||||
{ticket.ai_result?.completed_at ? (
|
: null;
|
||||||
<div className="border-t px-4 py-3 text-xs text-muted-foreground">
|
const chainageName =
|
||||||
AI analysis completed {formatDate(ticket.ai_result.completed_at)}
|
ticket.location?.chainage?.name || ticket.chainage_name || null;
|
||||||
</div>
|
const packageName = ticket.location?.package?.name || null;
|
||||||
) : null}
|
const locationLabel =
|
||||||
</section>
|
[chainageName, packageName].filter(Boolean).join(', ') || null;
|
||||||
|
const uploadedOn =
|
||||||
|
ticket.timestamps?.created_at || ticket.ai_result.completed_at || null;
|
||||||
|
const uploaderName = ticket.uploader?.name || null;
|
||||||
|
const analysisVideoId = ticket.video_id || ticket.video?.id || null;
|
||||||
|
const videoName = ticket.video?.name || null;
|
||||||
|
const analysisTitle = videoName || ticket.ticket_name || 'Analysis Video';
|
||||||
|
const hasVideoMetrics = Boolean(
|
||||||
|
videoMetadata?.fps || duration || videoMetadata?.resolution?.label,
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-5">
|
||||||
|
{uploadedOn || uploaderName || locationLabel ? (
|
||||||
|
<Card>
|
||||||
|
<CardContent className="grid gap-4 py-4 sm:grid-cols-3 sm:divide-x">
|
||||||
|
{uploadedOn ? (
|
||||||
|
<div className="flex items-center gap-3 sm:pr-4">
|
||||||
|
<CalendarDays className="size-5 shrink-0 text-muted-foreground" />
|
||||||
|
<OverviewField label="Uploaded On">
|
||||||
|
<MetaValue>{formatDate(uploadedOn)}</MetaValue>
|
||||||
|
</OverviewField>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{uploaderName ? (
|
||||||
|
<div className="flex items-center gap-3 sm:px-4">
|
||||||
|
<UserRound className="size-5 shrink-0 text-muted-foreground" />
|
||||||
|
<OverviewField label="Uploaded By">
|
||||||
|
<MetaValue>{uploaderName}</MetaValue>
|
||||||
|
</OverviewField>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
{locationLabel ? (
|
||||||
|
<div className="flex items-center gap-3 sm:pl-4">
|
||||||
|
<MapPin className="size-5 shrink-0 text-muted-foreground" />
|
||||||
|
<OverviewField label="Location">
|
||||||
|
<MetaValue>{locationLabel}</MetaValue>
|
||||||
|
</OverviewField>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center gap-2">
|
||||||
|
<Activity className="size-5 text-primary" />
|
||||||
|
AI Detection Summary
|
||||||
|
</CardTitle>
|
||||||
|
{analysisVideoId ? (
|
||||||
|
<CardAction>
|
||||||
|
<PermissionGuard permissions={PERMISSIONS.TICKET.ASSIGN}>
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
onClick={() => setIsAnalysisOpen(true)}
|
||||||
|
>
|
||||||
|
<Play className="mr-2 size-4" />
|
||||||
|
View Video
|
||||||
|
</Button>
|
||||||
|
</PermissionGuard>
|
||||||
|
</CardAction>
|
||||||
|
) : null}
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<div className="grid grid-cols-2 gap-3 lg:grid-cols-3 xl:grid-cols-6">
|
||||||
|
<SummaryCard
|
||||||
|
label="Total Detections"
|
||||||
|
value={ticket.ai_result.detection_count}
|
||||||
|
colorClassName="text-violet-600"
|
||||||
|
cardClassName="bg-violet-500/8"
|
||||||
|
/>
|
||||||
|
{ticket.ai_result.detections_by_class.map((item) => {
|
||||||
|
const visual = getDefectVisual(item.class_name);
|
||||||
|
return (
|
||||||
|
<SummaryCard
|
||||||
|
key={item.class_name}
|
||||||
|
label={item.display_name}
|
||||||
|
value={item.count}
|
||||||
|
colorClassName={visual.colorClassName}
|
||||||
|
cardClassName={visual.cardClassName}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
{hasVideoMetrics ? (
|
||||||
|
<div className="grid gap-3 rounded-lg bg-muted/35 px-4 py-3 text-sm sm:grid-cols-3">
|
||||||
|
{videoMetadata?.fps ? (
|
||||||
|
<VideoMetric icon={Gauge} label={`${videoMetadata.fps} FPS`} />
|
||||||
|
) : null}
|
||||||
|
{duration ? (
|
||||||
|
<VideoMetric icon={Clock3} label={`${duration} Duration`} />
|
||||||
|
) : null}
|
||||||
|
{videoMetadata?.resolution?.label ? (
|
||||||
|
<VideoMetric
|
||||||
|
icon={Monitor}
|
||||||
|
label={`${videoMetadata.resolution.label} Resolution`}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Dialog open={isAnalysisOpen} onOpenChange={setIsAnalysisOpen}>
|
||||||
|
<DialogContent className="sm:max-w-5xl">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>{analysisTitle}</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Video analysis with annotation overlay
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
<DialogBody>
|
||||||
|
<TicketInlineAnalysisVideo ticket={ticket} />
|
||||||
|
</DialogBody>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
import {
|
||||||
|
Card,
|
||||||
|
CardAction,
|
||||||
|
CardContent,
|
||||||
|
CardHeader,
|
||||||
|
} from '@/components/ui/card';
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
|
|
||||||
|
function OverviewMetaSkeletonField({ className }: { className?: string }) {
|
||||||
|
return (
|
||||||
|
<div className={`flex items-center gap-3 ${className ?? ''}`}>
|
||||||
|
<Skeleton className="size-5 shrink-0 rounded-lg" />
|
||||||
|
<div className="min-w-0 space-y-2">
|
||||||
|
<Skeleton className="h-3 w-24" />
|
||||||
|
<Skeleton className="h-4 w-32 max-w-full" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SummarySkeletonCard() {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg bg-muted/40 p-4">
|
||||||
|
<Skeleton className="h-7 w-10" />
|
||||||
|
<Skeleton className="mt-3 h-3 w-24 max-w-full" />
|
||||||
|
<Skeleton className="mt-2 h-3 w-16" />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TicketOverviewHeaderSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between">
|
||||||
|
<div className="min-w-0 space-y-2">
|
||||||
|
<Skeleton className="h-8 w-40" />
|
||||||
|
<Skeleton className="h-3 w-36 max-w-full" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex shrink-0 items-center gap-2">
|
||||||
|
<Skeleton className="h-8 w-28" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TicketOverviewCardSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="space-y-5" aria-label="Loading ticket overview">
|
||||||
|
<Card>
|
||||||
|
<CardContent className="grid gap-4 py-4 sm:grid-cols-3 sm:divide-x">
|
||||||
|
<OverviewMetaSkeletonField className="sm:pr-4" />
|
||||||
|
<OverviewMetaSkeletonField className="sm:px-4" />
|
||||||
|
<OverviewMetaSkeletonField className="sm:pl-4" />
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Skeleton className="size-5 rounded-lg" />
|
||||||
|
<Skeleton className="h-5 w-40" />
|
||||||
|
</div>
|
||||||
|
<CardAction>
|
||||||
|
<Skeleton className="h-9 w-28" />
|
||||||
|
</CardAction>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<div className="grid grid-cols-2 gap-3 lg:grid-cols-3 xl:grid-cols-6">
|
||||||
|
{Array.from({ length: 6 }).map((_, index) => (
|
||||||
|
<SummarySkeletonCard key={index} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid gap-3 rounded-lg bg-muted/35 px-4 py-3 sm:grid-cols-3">
|
||||||
|
{Array.from({ length: 3 }).map((_, index) => (
|
||||||
|
<div
|
||||||
|
key={index}
|
||||||
|
className="flex items-center justify-center gap-2"
|
||||||
|
>
|
||||||
|
<Skeleton className="size-4 rounded-lg" />
|
||||||
|
<Skeleton className="h-4 w-24" />
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { ImageIcon } from 'lucide-react';
|
|
||||||
|
|
||||||
import type { TicketDetail } from '@/types';
|
|
||||||
|
|
||||||
import { RepairProofImagesGrid } from './repair-report/RepairProofImagesGrid';
|
|
||||||
import { RepairReportPanel } from './repair-report/RepairReportPanel';
|
|
||||||
import { RepairVideoComparison } from './repair-report/RepairVideoComparison';
|
|
||||||
|
|
||||||
export function TicketRepairReportCard({ ticket }: { ticket: TicketDetail }) {
|
|
||||||
const repair = ticket.repair;
|
|
||||||
|
|
||||||
if (!repair) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<section className="space-y-5">
|
|
||||||
<RepairReportPanel ticket={ticket} />
|
|
||||||
|
|
||||||
<RepairVideoComparison ticket={ticket} />
|
|
||||||
|
|
||||||
<div className="space-y-3">
|
|
||||||
<h3 className="flex items-center gap-2 text-base font-semibold">
|
|
||||||
<ImageIcon className="size-5 text-primary" />
|
|
||||||
Repair Images
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<RepairProofImagesGrid
|
|
||||||
imageUrls={repair?.proof_image_urls ?? []}
|
|
||||||
submittedAt={repair?.submitted_at ?? null}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -3,69 +3,84 @@
|
|||||||
import { PERMISSIONS } from '@/constants/permissions';
|
import { PERMISSIONS } from '@/constants/permissions';
|
||||||
import { PermissionGuard } from '@/guards';
|
import { PermissionGuard } from '@/guards';
|
||||||
import type { TicketDetail } from '@/types';
|
import type { TicketDetail } from '@/types';
|
||||||
import type { TicketDetailLiveState } from '../../hooks/useTicketDetailEvents';
|
|
||||||
|
|
||||||
|
import { AssignedContractorAction } from './actions/AssignedContractorAction';
|
||||||
import { AssignTicketAction } from './actions/AssignTicketAction';
|
import { AssignTicketAction } from './actions/AssignTicketAction';
|
||||||
import { ClosedTicketAction } from './actions/ClosedTicketAction';
|
import { ClosedTicketAction } from './actions/ClosedTicketAction';
|
||||||
import { NoTicketAction } from './actions/NoTicketAction';
|
import { NoTicketAction } from './actions/NoTicketAction';
|
||||||
import { ProcessingTicketAction } from './actions/ProcessingTicketAction';
|
import { ReviewExtensionRequestAction } from './actions/ReviewExtensionRequestAction';
|
||||||
import { ReviewRepairAction } from './actions/ReviewRepairAction';
|
import { ReviewRepairAction } from './actions/ReviewRepairAction';
|
||||||
|
import { SubmittedRepairProofAction } from './actions/SubmittedRepairProofAction';
|
||||||
import { SubmitRepairAction } from './actions/SubmitRepairAction';
|
import { SubmitRepairAction } from './actions/SubmitRepairAction';
|
||||||
|
|
||||||
interface TicketStatusActionsProps {
|
interface TicketStatusActionsProps {
|
||||||
ticket: TicketDetail;
|
ticket: TicketDetail;
|
||||||
liveState: TicketDetailLiveState;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TicketStatusActions({
|
function getTicketAction(ticket: TicketDetail) {
|
||||||
ticket,
|
if (ticket.assignment_status === 'unassigned') {
|
||||||
liveState,
|
|
||||||
}: TicketStatusActionsProps) {
|
|
||||||
if (ticket.status === 'processing') {
|
|
||||||
return (
|
|
||||||
<ProcessingTicketAction
|
|
||||||
progress={liveState.progress}
|
|
||||||
errorMessage={liveState.errorMessage}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ticket.status === 'unassigned') {
|
|
||||||
return (
|
return (
|
||||||
<PermissionGuard
|
<PermissionGuard
|
||||||
permissions={PERMISSIONS.TICKET.ASSIGN}
|
permissions={PERMISSIONS.TICKET.ASSIGN}
|
||||||
fallback={<NoTicketAction status={ticket.status} />}
|
fallback={<NoTicketAction />}
|
||||||
>
|
>
|
||||||
<AssignTicketAction ticket={ticket} />
|
<AssignTicketAction ticket={ticket} />
|
||||||
</PermissionGuard>
|
</PermissionGuard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ticket.status === 'assigned') {
|
if (ticket.assignment_status === 'assigned') {
|
||||||
return (
|
return (
|
||||||
<PermissionGuard
|
<PermissionGuard
|
||||||
permissions={PERMISSIONS.TICKET.WORK}
|
permissions={PERMISSIONS.TICKET.ASSIGN}
|
||||||
fallback={<NoTicketAction status={ticket.status} />}
|
fallback={
|
||||||
|
<PermissionGuard
|
||||||
|
permissions={PERMISSIONS.TICKET.WORK}
|
||||||
|
fallback={<NoTicketAction />}
|
||||||
|
>
|
||||||
|
<SubmitRepairAction ticket={ticket} />
|
||||||
|
</PermissionGuard>
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<SubmitRepairAction ticket={ticket} />
|
<>
|
||||||
|
<AssignedContractorAction ticket={ticket} />
|
||||||
|
<ReviewExtensionRequestAction ticket={ticket} />
|
||||||
|
</>
|
||||||
</PermissionGuard>
|
</PermissionGuard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ticket.status === 'under_review') {
|
if (ticket.assignment_status === 'under_review') {
|
||||||
return (
|
return (
|
||||||
<PermissionGuard
|
<PermissionGuard
|
||||||
permissions={PERMISSIONS.TICKET.REVIEW}
|
permissions={PERMISSIONS.TICKET.REVIEW}
|
||||||
fallback={<NoTicketAction status={ticket.status} />}
|
fallback={<NoTicketAction />}
|
||||||
>
|
>
|
||||||
<ReviewRepairAction ticket={ticket} />
|
<ReviewRepairAction ticket={ticket} />
|
||||||
</PermissionGuard>
|
</PermissionGuard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ticket.status === 'closed') {
|
if (
|
||||||
|
ticket.assignment_status === 'approved' ||
|
||||||
|
ticket.assignment_status === 'rejected'
|
||||||
|
) {
|
||||||
return <ClosedTicketAction ticket={ticket} />;
|
return <ClosedTicketAction ticket={ticket} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <NoTicketAction status={ticket.status} />;
|
return <NoTicketAction />;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TicketStatusActions({ ticket }: TicketStatusActionsProps) {
|
||||||
|
const action = getTicketAction(ticket);
|
||||||
|
const submittedProof = ticket.repair?.submitted_at ? (
|
||||||
|
<SubmittedRepairProofAction ticket={ticket} />
|
||||||
|
) : null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-3">
|
||||||
|
{submittedProof}
|
||||||
|
{action}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +1,109 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
import { Send, UserPlus } from 'lucide-react';
|
import { Users, Mail, Phone, Send, ShieldCheck } from 'lucide-react';
|
||||||
|
|
||||||
|
import { DatePickerSimple } from '@/components/form/DatePickerSimple';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import { AssignableWorkerSelect } from '@/components/lookups/AssignableWorkerSelect';
|
import { AssignableWorkerSelect } from '@/components/lookups/AssignableWorkerSelect';
|
||||||
import type { TicketDetail } from '@/types';
|
import type { AssignableTicketUser, TicketDetail } from '@/types';
|
||||||
|
|
||||||
import { useAssignTicketMutation } from '../../../hooks/useTicketQueries';
|
import { useAssignTicketMutation } from '../../../hooks/useTicketQueries';
|
||||||
import { TicketActionCard } from './TicketActionCard';
|
import { TicketActionCard } from './TicketActionCard';
|
||||||
|
|
||||||
export function AssignTicketAction({ ticket }: { ticket: TicketDetail }) {
|
export function AssignTicketAction({ ticket }: { ticket: TicketDetail }) {
|
||||||
const [selectedUserId, setSelectedUserId] = useState('');
|
const [selectedUserId, setSelectedUserId] = useState('');
|
||||||
|
const [selectedContractor, setSelectedContractor] =
|
||||||
|
useState<AssignableTicketUser | null>(null);
|
||||||
|
const [dueDate, setDueDate] = useState<Date>();
|
||||||
const [assignNote, setAssignNote] = useState('');
|
const [assignNote, setAssignNote] = useState('');
|
||||||
|
|
||||||
const assignMutation = useAssignTicketMutation(ticket.id);
|
const assignMutation = useAssignTicketMutation(ticket.id);
|
||||||
|
const today = useMemo(() => {
|
||||||
|
const date = new Date();
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
return date;
|
||||||
|
}, []);
|
||||||
|
const maxDueMonth = useMemo(
|
||||||
|
() => new Date(today.getFullYear() + 20, 11),
|
||||||
|
[today],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TicketActionCard icon={UserPlus} title="Assign Ticket">
|
<TicketActionCard icon={Users} title="Assign to Contractor">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label>Worker</Label>
|
<Label>Contractor *</Label>
|
||||||
<AssignableWorkerSelect
|
<AssignableWorkerSelect
|
||||||
value={selectedUserId}
|
value={selectedUserId}
|
||||||
onValueChange={setSelectedUserId}
|
onValueChange={(userId, user) => {
|
||||||
|
setSelectedUserId(userId);
|
||||||
|
setSelectedContractor(user);
|
||||||
|
}}
|
||||||
disabled={assignMutation.isPending}
|
disabled={assignMutation.isPending}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
{selectedContractor ? (
|
||||||
|
<div className="space-y-2 rounded-lg border bg-muted/30 p-3">
|
||||||
|
<p className="text-sm font-medium">Contractor Details</p>
|
||||||
|
{selectedContractor.phone_number ? (
|
||||||
|
<p className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||||
|
<Phone className="size-4 shrink-0" />
|
||||||
|
{selectedContractor.phone_number}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
<p className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||||
|
<Mail className="size-4 shrink-0" />
|
||||||
|
<span className="truncate">{selectedContractor.email}</span>
|
||||||
|
</p>
|
||||||
|
<p className="flex items-center gap-2 text-sm text-muted-foreground">
|
||||||
|
<ShieldCheck className="size-4 shrink-0" />
|
||||||
|
{selectedContractor.role.name}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label>Note</Label>
|
<Label htmlFor="assign-due-date">
|
||||||
|
Due Date <span className="text-destructive">*</span>
|
||||||
|
</Label>
|
||||||
|
<DatePickerSimple
|
||||||
|
id="assign-due-date"
|
||||||
|
value={dueDate}
|
||||||
|
onChange={setDueDate}
|
||||||
|
showLabel={false}
|
||||||
|
placeholder="Select due date"
|
||||||
|
disabled={assignMutation.isPending}
|
||||||
|
className="w-full"
|
||||||
|
startMonth={today}
|
||||||
|
endMonth={maxDueMonth}
|
||||||
|
disabledDates={{ before: today }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>Assignment Note (Optional)</Label>
|
||||||
<Textarea
|
<Textarea
|
||||||
value={assignNote}
|
value={assignNote}
|
||||||
onChange={(event) => setAssignNote(event.target.value)}
|
onChange={(event) => setAssignNote(event.target.value)}
|
||||||
placeholder="Please inspect and repair"
|
placeholder="Add any instructions or notes for the contractor..."
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Button
|
<Button
|
||||||
disabled={!selectedUserId || assignMutation.isPending}
|
disabled={!selectedUserId || !dueDate || assignMutation.isPending}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (!selectedUserId) return;
|
if (!selectedUserId || !dueDate) return;
|
||||||
assignMutation.mutate({
|
assignMutation.mutate({
|
||||||
assigned_to_user_id: Number(selectedUserId),
|
assigned_to_user_id: Number(selectedUserId),
|
||||||
|
defect_class: ticket.defect_class,
|
||||||
|
due_at: dueDate.toISOString(),
|
||||||
note: assignNote || undefined,
|
note: assignNote || undefined,
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
>
|
>
|
||||||
<Send />
|
<Send />
|
||||||
Assign
|
Assign Ticket
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</TicketActionCard>
|
</TicketActionCard>
|
||||||
|
|||||||
@@ -0,0 +1,61 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { CalendarClock, UserCheck } from 'lucide-react';
|
||||||
|
|
||||||
|
import { PersonInfo } from '@/components/person-avatar';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import type { TicketDetail } from '@/types';
|
||||||
|
import { formatDate } from '@/utils/date';
|
||||||
|
|
||||||
|
import { TicketActionCard } from './TicketActionCard';
|
||||||
|
|
||||||
|
function AssignmentField({ label, value }: { label: string; value: string }) {
|
||||||
|
return (
|
||||||
|
<div className="min-w-0 space-y-1">
|
||||||
|
<p className="text-xs text-muted-foreground">{label}</p>
|
||||||
|
<p className="truncate text-sm font-medium text-foreground">{value}</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function AssignedContractorAction({ ticket }: { ticket: TicketDetail }) {
|
||||||
|
const worker = ticket.worker;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TicketActionCard icon={UserCheck} title="Assigned Contractor">
|
||||||
|
{worker ? (
|
||||||
|
<div className="space-y-5">
|
||||||
|
<div className="flex items-center justify-between gap-3">
|
||||||
|
<PersonInfo person={worker} size="lg" />
|
||||||
|
<Badge>
|
||||||
|
Assigned
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-x-4 gap-y-5 border-t pt-4">
|
||||||
|
<AssignmentField label="Role" value={worker.role?.name ?? '-'} />
|
||||||
|
<AssignmentField
|
||||||
|
label="Assigned By"
|
||||||
|
value={worker.assigned_by_name ?? '-'}
|
||||||
|
/>
|
||||||
|
<AssignmentField
|
||||||
|
label="Assigned On"
|
||||||
|
value={formatDate(worker.assigned_at)}
|
||||||
|
/>
|
||||||
|
<div className="min-w-0 space-y-1">
|
||||||
|
<p className="text-xs text-muted-foreground">Due Date</p>
|
||||||
|
<p className="flex items-center gap-1.5 text-sm font-medium text-foreground">
|
||||||
|
<CalendarClock className="size-4 shrink-0 text-muted-foreground" />
|
||||||
|
<span className="truncate">{formatDate(worker.due_at)}</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Assignment details are not available.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
|
</TicketActionCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import { Lock, MessageSquare } from 'lucide-react';
|
import { Lock, MessageSquare } from 'lucide-react';
|
||||||
|
|
||||||
import { Avatar, AvatarFallback } from '@/components/ui/avatar';
|
import { PersonInfo } from '@/components/person-avatar';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
@@ -14,34 +14,18 @@ import {
|
|||||||
} from '@/components/ui/card';
|
} from '@/components/ui/card';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import type { TicketDetail } from '@/types';
|
import type { TicketDetail } from '@/types';
|
||||||
|
import { formatDateOnly } from '@/utils/date';
|
||||||
function getInitials(name?: string | null, email?: string | null) {
|
|
||||||
const source = name || email || '?';
|
|
||||||
return source
|
|
||||||
.split(/[\s@._-]+/)
|
|
||||||
.filter(Boolean)
|
|
||||||
.slice(0, 2)
|
|
||||||
.map((part) => part.charAt(0).toUpperCase())
|
|
||||||
.join('');
|
|
||||||
}
|
|
||||||
|
|
||||||
function getPersonLabel(person: TicketDetail['reviewer']) {
|
|
||||||
return person?.name || person?.email || 'Unknown';
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatReviewDate(value: string | null | undefined) {
|
|
||||||
if (!value) return '-';
|
|
||||||
return new Intl.DateTimeFormat('en-IN', { dateStyle: 'medium' }).format(
|
|
||||||
new Date(value),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function getClosedAt(ticket: TicketDetail) {
|
function getClosedAt(ticket: TicketDetail) {
|
||||||
const closedEntry = ticket.history?.find(
|
const approvedEntry = [...(ticket.history ?? [])]
|
||||||
(item) => item.to_status === 'closed',
|
.reverse()
|
||||||
);
|
.find(
|
||||||
|
(item) =>
|
||||||
|
item.event_type === 'repair_approved' ||
|
||||||
|
item.to_class_status === 'approved',
|
||||||
|
);
|
||||||
return (
|
return (
|
||||||
closedEntry?.created_at ??
|
approvedEntry?.created_at ??
|
||||||
ticket.reviewer?.reviewed_at ??
|
ticket.reviewer?.reviewed_at ??
|
||||||
ticket.timestamps.updated_at
|
ticket.timestamps.updated_at
|
||||||
);
|
);
|
||||||
@@ -98,38 +82,22 @@ export function ClosedTicketAction({ ticket }: { ticket: TicketDetail }) {
|
|||||||
const reviewedAt = reviewer?.reviewed_at ?? getClosedAt(ticket);
|
const reviewedAt = reviewer?.reviewed_at ?? getClosedAt(ticket);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card className="relative overflow-hidden border bg-card/80">
|
<Card>
|
||||||
<CardHeader className="relative pb-4">
|
<CardHeader>
|
||||||
<CardTitle className="text-lg">Resolution Details</CardTitle>
|
<CardTitle className="text-lg">Resolution Details</CardTitle>
|
||||||
<CardDescription>Review record for {ticket.id}</CardDescription>
|
<CardDescription>Review record for {ticket.ticket_name}</CardDescription>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|
||||||
<CardContent className="relative space-y-5">
|
<CardContent className="space-y-5">
|
||||||
<div className="space-y-4 rounded-xl border bg-muted/20 p-4">
|
<div className="space-y-4 rounded-lg border bg-muted/20 p-4">
|
||||||
<MetaField
|
<MetaField
|
||||||
label="Reviewed By"
|
label="Reviewed By"
|
||||||
value={
|
value={<PersonInfo person={reviewer} size="lg" />}
|
||||||
<div className="flex min-w-0 items-center gap-3">
|
|
||||||
<Avatar className="size-10 border border-primary/30">
|
|
||||||
<AvatarFallback className="bg-primary/15 text-sm text-primary">
|
|
||||||
{getInitials(reviewer?.name, reviewer?.email)}
|
|
||||||
</AvatarFallback>
|
|
||||||
</Avatar>
|
|
||||||
<div className="min-w-0">
|
|
||||||
<p className="truncate">{getPersonLabel(reviewer)}</p>
|
|
||||||
{reviewer?.email ? (
|
|
||||||
<p className="mt-0.5 truncate text-xs font-medium text-muted-foreground">
|
|
||||||
{reviewer.email}
|
|
||||||
</p>
|
|
||||||
) : null}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<MetaField
|
<MetaField
|
||||||
label="Reviewed Date"
|
label="Reviewed Date"
|
||||||
value={formatReviewDate(reviewedAt)}
|
value={formatDateOnly(reviewedAt)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -1,37 +1,15 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { CircleOff, Clock } from 'lucide-react';
|
import { CircleOff } from 'lucide-react';
|
||||||
|
|
||||||
import type { TicketStatus } from '@/types';
|
|
||||||
|
|
||||||
import { TicketActionCard } from './TicketActionCard';
|
import { TicketActionCard } from './TicketActionCard';
|
||||||
|
|
||||||
const statusConfig: Record<
|
export function NoTicketAction() {
|
||||||
'processing',
|
|
||||||
{ icon: typeof Clock; title: string; message: string }
|
|
||||||
> = {
|
|
||||||
processing: {
|
|
||||||
icon: Clock,
|
|
||||||
title: 'Processing',
|
|
||||||
message: 'This ticket is still being processed. Check back shortly.',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export function NoTicketAction({ status }: { status: TicketStatus }) {
|
|
||||||
const config =
|
|
||||||
status === 'processing'
|
|
||||||
? statusConfig[status]
|
|
||||||
: {
|
|
||||||
icon: CircleOff,
|
|
||||||
title: 'No Actions',
|
|
||||||
message: 'No action available for this ticket.',
|
|
||||||
};
|
|
||||||
|
|
||||||
const Icon = config.icon;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TicketActionCard icon={Icon} title={config.title}>
|
<TicketActionCard icon={CircleOff} title="No Actions">
|
||||||
<p className="text-sm text-muted-foreground">{config.message}</p>
|
<p className="text-sm text-muted-foreground">
|
||||||
|
No action available for this ticket.
|
||||||
|
</p>
|
||||||
</TicketActionCard>
|
</TicketActionCard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,54 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { AlertCircle, Loader2 } from 'lucide-react';
|
|
||||||
|
|
||||||
import { Progress } from '@/components/ui/progress';
|
|
||||||
import type { TicketProcessingProgress } from '../../../hooks/useTicketDetailEvents';
|
|
||||||
|
|
||||||
import { TicketActionCard } from './TicketActionCard';
|
|
||||||
|
|
||||||
interface ProcessingTicketActionProps {
|
|
||||||
progress: TicketProcessingProgress | null;
|
|
||||||
errorMessage: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getProgressMessage(progress: TicketProcessingProgress | null) {
|
|
||||||
if (!progress) return 'Waiting for analysis updates.';
|
|
||||||
if (progress.progress >= 95) {
|
|
||||||
return progress.message ?? 'Rendering annotated video...';
|
|
||||||
}
|
|
||||||
return progress.message ?? 'Processing video.';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ProcessingTicketAction({
|
|
||||||
progress,
|
|
||||||
errorMessage,
|
|
||||||
}: ProcessingTicketActionProps) {
|
|
||||||
const progressValue = progress ? progress.progress : 0;
|
|
||||||
const hasProgress = Boolean(progress);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TicketActionCard icon={Loader2} title="Analyzing Video">
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<div className="flex items-center justify-between gap-3 text-sm">
|
|
||||||
<span className="font-medium text-foreground">
|
|
||||||
{getProgressMessage(progress)}
|
|
||||||
</span>
|
|
||||||
<span className="shrink-0 text-muted-foreground">
|
|
||||||
{hasProgress ? `${Math.round(progressValue)}%` : '--'}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<Progress value={hasProgress ? progressValue : 0} />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{errorMessage && (
|
|
||||||
<div className="flex gap-2 rounded-md border border-destructive/25 bg-destructive/10 p-3 text-sm text-destructive">
|
|
||||||
<AlertCircle className="mt-0.5 size-4 shrink-0" />
|
|
||||||
<span>{errorMessage}</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</TicketActionCard>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,16 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
||||||
import { ImageIcon, Loader2, Send, Video, X } from 'lucide-react';
|
import {
|
||||||
|
Camera,
|
||||||
|
ImageIcon,
|
||||||
|
Loader2,
|
||||||
|
Play,
|
||||||
|
Plus,
|
||||||
|
Send,
|
||||||
|
Video,
|
||||||
|
X,
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Label } from '@/components/ui/label';
|
import { Label } from '@/components/ui/label';
|
||||||
@@ -10,139 +19,208 @@ import { cn } from '@/lib/utils';
|
|||||||
|
|
||||||
import { useSubmitRepairUploadMutation } from '../../../hooks/useTicketQueries';
|
import { useSubmitRepairUploadMutation } from '../../../hooks/useTicketQueries';
|
||||||
|
|
||||||
const MAX_IMAGES = 5;
|
const MAX_IMAGES = 30;
|
||||||
|
const MAX_NOTES = 500;
|
||||||
|
|
||||||
function RequiredMark() {
|
function RequiredMark() {
|
||||||
return <span className="text-destructive">*</span>;
|
return <span className="text-destructive">*</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MediaDropzoneProps {
|
function formatVideoDuration(seconds: number) {
|
||||||
|
const totalSeconds = Math.floor(seconds);
|
||||||
|
const minutes = Math.floor(totalSeconds / 60);
|
||||||
|
const remainingSeconds = totalSeconds % 60;
|
||||||
|
return `${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MediaSectionHeaderProps {
|
||||||
icon: ReactNode;
|
icon: ReactNode;
|
||||||
label: string;
|
title: string;
|
||||||
accept: string;
|
addLabel: string;
|
||||||
file: File | null;
|
onAdd: () => void;
|
||||||
onFileChange: (file: File | null) => void;
|
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function MediaDropzone({
|
function MediaSectionHeader({
|
||||||
icon,
|
icon,
|
||||||
label,
|
title,
|
||||||
accept,
|
addLabel,
|
||||||
file,
|
onAdd,
|
||||||
onFileChange,
|
|
||||||
disabled = false,
|
disabled = false,
|
||||||
}: MediaDropzoneProps) {
|
}: MediaSectionHeaderProps) {
|
||||||
const inputRef = useRef<HTMLInputElement | null>(null);
|
return (
|
||||||
|
<div className="flex items-center justify-between gap-3">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="text-primary">{icon}</span>
|
||||||
|
<span className="text-sm font-semibold">{title}</span>
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
size="sm"
|
||||||
|
disabled={disabled}
|
||||||
|
onClick={onAdd}
|
||||||
|
className="shrink-0"
|
||||||
|
>
|
||||||
|
<Plus className="size-3.5" />
|
||||||
|
{addLabel}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function MediaHint({ children }: { children: ReactNode }) {
|
||||||
|
return (
|
||||||
|
<p className="rounded-lg bg-muted/50 px-3 py-2 text-xs text-muted-foreground">
|
||||||
|
{children}
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface EmptyMediaPlaceholderProps {
|
||||||
|
icon: ReactNode;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
className?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
onClick: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EmptyMediaPlaceholder({
|
||||||
|
icon,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
className,
|
||||||
|
disabled = false,
|
||||||
|
onClick,
|
||||||
|
}: EmptyMediaPlaceholderProps) {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
onClick={() => inputRef.current?.click()}
|
onClick={onClick}
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex w-full items-center gap-3 rounded-lg border border-dashed px-4 py-3 text-left transition-colors',
|
'flex w-full min-w-0 cursor-pointer flex-col items-center justify-center gap-2 rounded-lg border border-dashed border-border/80 bg-muted/15 px-4 py-6 text-center transition-colors',
|
||||||
'hover:border-primary/50 hover:bg-muted/30',
|
'hover:border-primary/40 hover:bg-primary/5',
|
||||||
disabled && 'pointer-events-none opacity-60',
|
disabled && 'cursor-not-allowed opacity-60',
|
||||||
file && 'border-primary/40 bg-muted/20',
|
className,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<input
|
<span className="flex size-10 items-center justify-center rounded-full bg-primary/10 text-primary">
|
||||||
ref={inputRef}
|
|
||||||
type="file"
|
|
||||||
accept={accept}
|
|
||||||
className="hidden"
|
|
||||||
disabled={disabled}
|
|
||||||
onChange={(event) => {
|
|
||||||
onFileChange(event.target.files?.[0] ?? null);
|
|
||||||
event.target.value = '';
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<span className="flex size-9 shrink-0 items-center justify-center rounded-md bg-primary/10 text-primary">
|
|
||||||
{icon}
|
{icon}
|
||||||
</span>
|
</span>
|
||||||
<span className="min-w-0 flex-1">
|
<span className="text-sm font-medium text-foreground">{title}</span>
|
||||||
<span className="block truncate text-sm font-medium">
|
<span className="max-w-xs text-xs text-muted-foreground">
|
||||||
{file ? file.name : label}
|
{description}
|
||||||
</span>
|
|
||||||
{file ? (
|
|
||||||
<span className="text-xs text-muted-foreground">
|
|
||||||
Click to replace
|
|
||||||
</span>
|
|
||||||
) : null}
|
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ImageSlotProps {
|
interface ImageThumbnailProps {
|
||||||
file: File | null;
|
file: File;
|
||||||
previewUrl: string | null;
|
previewUrl: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
onAdd: () => void;
|
|
||||||
onRemove: () => void;
|
onRemove: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ImageSlot({
|
function ImageThumbnail({
|
||||||
file,
|
file,
|
||||||
previewUrl,
|
previewUrl,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
onAdd,
|
|
||||||
onRemove,
|
onRemove,
|
||||||
}: ImageSlotProps) {
|
}: ImageThumbnailProps) {
|
||||||
if (file && previewUrl) {
|
|
||||||
return (
|
|
||||||
<div className="group relative aspect-square overflow-hidden rounded-lg border bg-muted/30">
|
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
||||||
<img
|
|
||||||
src={previewUrl}
|
|
||||||
alt={file.name}
|
|
||||||
className="size-full object-cover"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
disabled={disabled}
|
|
||||||
onClick={onRemove}
|
|
||||||
className="absolute top-1 right-1 flex size-5 items-center justify-center rounded-full bg-background/90 text-foreground opacity-0 shadow-sm transition-opacity group-hover:opacity-100 disabled:pointer-events-none"
|
|
||||||
aria-label={`Remove ${file.name}`}
|
|
||||||
>
|
|
||||||
<X className="size-3" />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<button
|
<div className="group relative size-20 shrink-0 overflow-hidden rounded-lg border bg-muted/30">
|
||||||
type="button"
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
disabled={disabled}
|
<img
|
||||||
onClick={onAdd}
|
src={previewUrl}
|
||||||
className={cn(
|
alt={file.name}
|
||||||
'flex aspect-square items-center justify-center rounded-lg border border-dashed bg-muted/20 text-muted-foreground transition-colors',
|
className="size-full object-cover"
|
||||||
'hover:border-primary/50 hover:bg-muted/40 hover:text-primary',
|
/>
|
||||||
disabled && 'pointer-events-none opacity-60',
|
<button
|
||||||
)}
|
type="button"
|
||||||
aria-label="Add image"
|
disabled={disabled}
|
||||||
>
|
onClick={onRemove}
|
||||||
<ImageIcon className="size-4" />
|
className="absolute top-1 right-1 flex size-5 cursor-pointer items-center justify-center rounded-full bg-foreground/80 text-background shadow-sm transition-opacity disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
</button>
|
aria-label={`Remove ${file.name}`}
|
||||||
|
>
|
||||||
|
<X className="size-3" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface VideoThumbnailProps {
|
||||||
|
file: File;
|
||||||
|
previewUrl: string;
|
||||||
|
duration: string | null;
|
||||||
|
disabled?: boolean;
|
||||||
|
onRemove: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
function VideoThumbnail({
|
||||||
|
file,
|
||||||
|
previewUrl,
|
||||||
|
duration,
|
||||||
|
disabled = false,
|
||||||
|
onRemove,
|
||||||
|
}: VideoThumbnailProps) {
|
||||||
|
return (
|
||||||
|
<div className="group relative h-20 w-36 shrink-0 overflow-hidden rounded-lg border bg-muted/30">
|
||||||
|
<video
|
||||||
|
src={previewUrl}
|
||||||
|
className="size-full object-cover"
|
||||||
|
muted
|
||||||
|
playsInline
|
||||||
|
preload="metadata"
|
||||||
|
aria-label={file.name}
|
||||||
|
/>
|
||||||
|
<div className="pointer-events-none absolute inset-0 flex items-center justify-center bg-black/20">
|
||||||
|
<span className="flex size-8 items-center justify-center rounded-full bg-background/90 text-foreground shadow-sm">
|
||||||
|
<Play className="size-3.5 fill-current" />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
{duration ? (
|
||||||
|
<span className="pointer-events-none absolute bottom-1.5 right-1.5 rounded-lg bg-black/75 px-1.5 py-0.5 text-[10px] font-medium text-white">
|
||||||
|
{duration}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={disabled}
|
||||||
|
onClick={onRemove}
|
||||||
|
className="absolute top-1 right-1 flex size-5 cursor-pointer items-center justify-center rounded-full bg-foreground/80 text-background shadow-sm transition-opacity disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
aria-label={`Remove ${file.name}`}
|
||||||
|
>
|
||||||
|
<X className="size-3" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RepairEvidenceFormProps {
|
interface RepairEvidenceFormProps {
|
||||||
ticketId: string;
|
ticketId: string;
|
||||||
|
defectClass: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RepairEvidenceForm({ ticketId }: RepairEvidenceFormProps) {
|
export function RepairEvidenceForm({
|
||||||
|
ticketId,
|
||||||
|
defectClass,
|
||||||
|
}: RepairEvidenceFormProps) {
|
||||||
const imageInputRef = useRef<HTMLInputElement | null>(null);
|
const imageInputRef = useRef<HTMLInputElement | null>(null);
|
||||||
|
const videoInputRef = useRef<HTMLInputElement | null>(null);
|
||||||
const [notes, setNotes] = useState('');
|
const [notes, setNotes] = useState('');
|
||||||
const [videoFile, setVideoFile] = useState<File | null>(null);
|
const [videoFile, setVideoFile] = useState<File | null>(null);
|
||||||
|
const [videoPreview, setVideoPreview] = useState<string | null>(null);
|
||||||
|
const [videoDuration, setVideoDuration] = useState<string | null>(null);
|
||||||
const [imageFiles, setImageFiles] = useState<File[]>([]);
|
const [imageFiles, setImageFiles] = useState<File[]>([]);
|
||||||
const [imagePreviews, setImagePreviews] = useState<string[]>([]);
|
const [imagePreviews, setImagePreviews] = useState<string[]>([]);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const submitRepairUploadMutation = useSubmitRepairUploadMutation(ticketId);
|
const submitRepairUploadMutation = useSubmitRepairUploadMutation(ticketId);
|
||||||
const isSubmitting = submitRepairUploadMutation.isPending;
|
const isSubmitting = submitRepairUploadMutation.isPending;
|
||||||
const canSubmit = Boolean(notes.trim() && videoFile);
|
const canSubmit = Boolean(notes.trim() && videoFile);
|
||||||
|
const canAddMoreImages = imageFiles.length < MAX_IMAGES;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const urls = imageFiles.map((file) => URL.createObjectURL(file));
|
const urls = imageFiles.map((file) => URL.createObjectURL(file));
|
||||||
@@ -152,6 +230,32 @@ export function RepairEvidenceForm({ ticketId }: RepairEvidenceFormProps) {
|
|||||||
};
|
};
|
||||||
}, [imageFiles]);
|
}, [imageFiles]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!videoFile) {
|
||||||
|
setVideoPreview(null);
|
||||||
|
setVideoDuration(null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const url = URL.createObjectURL(videoFile);
|
||||||
|
setVideoPreview(url);
|
||||||
|
setVideoDuration(null);
|
||||||
|
|
||||||
|
let cancelled = false;
|
||||||
|
const video = document.createElement('video');
|
||||||
|
video.preload = 'metadata';
|
||||||
|
video.onloadedmetadata = () => {
|
||||||
|
if (cancelled || !Number.isFinite(video.duration)) return;
|
||||||
|
setVideoDuration(formatVideoDuration(video.duration));
|
||||||
|
};
|
||||||
|
video.src = url;
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
};
|
||||||
|
}, [videoFile]);
|
||||||
|
|
||||||
const addImages = (files: FileList | null) => {
|
const addImages = (files: FileList | null) => {
|
||||||
if (!files?.length) return;
|
if (!files?.length) return;
|
||||||
|
|
||||||
@@ -173,6 +277,16 @@ export function RepairEvidenceForm({ ticketId }: RepairEvidenceFormProps) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const selectVideo = (files: FileList | null) => {
|
||||||
|
setVideoFile(files?.[0] ?? null);
|
||||||
|
setError(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
const removeVideo = () => {
|
||||||
|
setVideoFile(null);
|
||||||
|
setError(null);
|
||||||
|
};
|
||||||
|
|
||||||
const removeImage = (index: number) => {
|
const removeImage = (index: number) => {
|
||||||
setImageFiles((current) =>
|
setImageFiles((current) =>
|
||||||
current.filter((_, itemIndex) => itemIndex !== index),
|
current.filter((_, itemIndex) => itemIndex !== index),
|
||||||
@@ -182,13 +296,14 @@ export function RepairEvidenceForm({ ticketId }: RepairEvidenceFormProps) {
|
|||||||
|
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
if (!notes.trim() || !videoFile) {
|
if (!notes.trim() || !videoFile) {
|
||||||
setError('Repair notes and video are required.');
|
setError('Repair notes and a video are required.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setError(null);
|
setError(null);
|
||||||
try {
|
try {
|
||||||
await submitRepairUploadMutation.mutateAsync({
|
await submitRepairUploadMutation.mutateAsync({
|
||||||
|
defect_class: defectClass,
|
||||||
notes: notes.trim(),
|
notes: notes.trim(),
|
||||||
video: videoFile,
|
video: videoFile,
|
||||||
images: imageFiles,
|
images: imageFiles,
|
||||||
@@ -201,83 +316,148 @@ export function RepairEvidenceForm({ ticketId }: RepairEvidenceFormProps) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const imageSlots = Array.from({ length: MAX_IMAGES }, (_, index) => ({
|
const openImagePicker = () => {
|
||||||
file: imageFiles[index] ?? null,
|
if (!isSubmitting && canAddMoreImages) {
|
||||||
previewUrl: imagePreviews[index] ?? null,
|
imageInputRef.current?.click();
|
||||||
}));
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const openVideoPicker = () => {
|
||||||
|
if (!isSubmitting) {
|
||||||
|
videoInputRef.current?.click();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-5">
|
<div className="space-y-5">
|
||||||
|
<div className="flex gap-3 rounded-lg border border-primary/15 bg-primary/5 p-4">
|
||||||
|
<Camera className="mt-0.5 size-5 shrink-0 text-primary" />
|
||||||
|
<div className="space-y-1">
|
||||||
|
<p className="text-sm font-semibold">Instructions</p>
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Upload clear photos and one video of the repaired area and provide
|
||||||
|
relevant details.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input
|
||||||
|
ref={imageInputRef}
|
||||||
|
type="file"
|
||||||
|
accept="image/jpeg,image/png,image/*"
|
||||||
|
multiple
|
||||||
|
className="hidden"
|
||||||
|
disabled={isSubmitting || !canAddMoreImages}
|
||||||
|
onChange={(event) => {
|
||||||
|
addImages(event.target.files);
|
||||||
|
event.target.value = '';
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
ref={videoInputRef}
|
||||||
|
type="file"
|
||||||
|
accept="video/mp4,video/quicktime,video/x-msvideo,video/*"
|
||||||
|
className="hidden"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
onChange={(event) => {
|
||||||
|
selectVideo(event.target.files);
|
||||||
|
event.target.value = '';
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<section className="space-y-3">
|
||||||
|
<MediaSectionHeader
|
||||||
|
icon={<Camera className="size-4" />}
|
||||||
|
title="Photos"
|
||||||
|
addLabel="Add Photos"
|
||||||
|
onAdd={openImagePicker}
|
||||||
|
disabled={isSubmitting || !canAddMoreImages}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="overflow-x-auto pb-1 [-ms-overflow-style:none] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
|
||||||
|
{imageFiles.length === 0 ? (
|
||||||
|
<EmptyMediaPlaceholder
|
||||||
|
icon={<ImageIcon className="size-5" />}
|
||||||
|
title="No photos added yet"
|
||||||
|
description="Tap to upload repair photos"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
onClick={openImagePicker}
|
||||||
|
className="min-h-26"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<div className="flex min-w-min gap-3">
|
||||||
|
{imageFiles.map((file, index) => (
|
||||||
|
<ImageThumbnail
|
||||||
|
key={`${file.name}-${file.lastModified}-${index}`}
|
||||||
|
file={file}
|
||||||
|
previewUrl={imagePreviews[index]}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
onRemove={() => removeImage(index)}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<MediaHint>
|
||||||
|
You can upload up to {MAX_IMAGES} images (JPG, PNG)
|
||||||
|
</MediaHint>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="space-y-3">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<Video className="size-4 text-primary" />
|
||||||
|
<span className="text-sm font-semibold">Video</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
{!videoFile || !videoPreview ? (
|
||||||
|
<EmptyMediaPlaceholder
|
||||||
|
icon={<Video className="size-5" />}
|
||||||
|
title="No video added yet"
|
||||||
|
description="Tap to upload a repair video"
|
||||||
|
disabled={isSubmitting}
|
||||||
|
onClick={openVideoPicker}
|
||||||
|
className="min-h-[104px]"
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
|
<VideoThumbnail
|
||||||
|
file={videoFile}
|
||||||
|
previewUrl={videoPreview}
|
||||||
|
duration={videoDuration}
|
||||||
|
disabled={isSubmitting}
|
||||||
|
onRemove={removeVideo}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<MediaHint>You can upload one video (MP4, MOV, AVI)</MediaHint>
|
||||||
|
</section>
|
||||||
|
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<Label htmlFor="repair-notes">
|
<Label htmlFor="repair-notes">
|
||||||
Repair Notes <RequiredMark />
|
Repair Notes <RequiredMark />
|
||||||
</Label>
|
</Label>
|
||||||
<Textarea
|
<div className="relative">
|
||||||
id="repair-notes"
|
<Textarea
|
||||||
value={notes}
|
id="repair-notes"
|
||||||
onChange={(event) => {
|
value={notes}
|
||||||
setNotes(event.target.value);
|
onChange={(event) => {
|
||||||
setError(null);
|
setNotes(event.target.value.slice(0, MAX_NOTES));
|
||||||
}}
|
|
||||||
placeholder="Describe the repair work performed..."
|
|
||||||
disabled={isSubmitting}
|
|
||||||
className="min-h-24 resize-none"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-3">
|
|
||||||
<Label className="text-muted-foreground">Media Upload</Label>
|
|
||||||
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label className="text-sm font-normal">
|
|
||||||
Repair Video <RequiredMark />
|
|
||||||
</Label>
|
|
||||||
<MediaDropzone
|
|
||||||
icon={<Video className="size-4" />}
|
|
||||||
label="Upload Repair Video (MP4, max 50MB)"
|
|
||||||
accept="video/mp4,video/*"
|
|
||||||
file={videoFile}
|
|
||||||
onFileChange={(file) => {
|
|
||||||
setVideoFile(file);
|
|
||||||
setError(null);
|
setError(null);
|
||||||
}}
|
}}
|
||||||
|
placeholder="Describe the repair work completed, materials used, and any additional observations."
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
|
className="min-h-28 resize-none pb-8"
|
||||||
/>
|
/>
|
||||||
</div>
|
<span className="pointer-events-none absolute bottom-2 right-3 text-xs text-muted-foreground">
|
||||||
|
{notes.length} / {MAX_NOTES}
|
||||||
<div className="space-y-2">
|
</span>
|
||||||
<Label className="text-sm font-normal">
|
|
||||||
Upload Images (Max {MAX_IMAGES})
|
|
||||||
</Label>
|
|
||||||
<input
|
|
||||||
ref={imageInputRef}
|
|
||||||
type="file"
|
|
||||||
accept="image/*"
|
|
||||||
multiple
|
|
||||||
className="hidden"
|
|
||||||
disabled={isSubmitting || imageFiles.length >= MAX_IMAGES}
|
|
||||||
onChange={(event) => {
|
|
||||||
addImages(event.target.files);
|
|
||||||
event.target.value = '';
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<div className="grid grid-cols-5 gap-2">
|
|
||||||
{imageSlots.map((slot, index) => (
|
|
||||||
<ImageSlot
|
|
||||||
key={index}
|
|
||||||
file={slot.file}
|
|
||||||
previewUrl={slot.previewUrl}
|
|
||||||
disabled={isSubmitting || (!slot.file && imageFiles.length >= MAX_IMAGES)}
|
|
||||||
onAdd={() => imageInputRef.current?.click()}
|
|
||||||
onRemove={() => removeImage(index)}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{error ? (
|
{error ? (
|
||||||
<div className="rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
<div className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
|
|||||||
@@ -0,0 +1,157 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useMemo, useState } from 'react';
|
||||||
|
import { Clock3, Loader2, Send } from 'lucide-react';
|
||||||
|
|
||||||
|
import { DatePicker } from '@/components/form/DatePicker';
|
||||||
|
import { DatePickerSimple } from '@/components/form/DatePickerSimple';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Label } from '@/components/ui/label';
|
||||||
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
import type { TicketDetail } from '@/types';
|
||||||
|
|
||||||
|
import { useRequestTicketExtensionMutation } from '../../../hooks/useTicketQueries';
|
||||||
|
|
||||||
|
const MAX_REASON_LENGTH = 300;
|
||||||
|
|
||||||
|
interface RequestExtensionFormProps {
|
||||||
|
ticket: TicketDetail;
|
||||||
|
onCancel: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RequestExtensionForm({
|
||||||
|
ticket,
|
||||||
|
onCancel,
|
||||||
|
}: RequestExtensionFormProps) {
|
||||||
|
const currentDueAt = ticket.worker?.due_at;
|
||||||
|
const currentDueDate = useMemo(
|
||||||
|
() => (currentDueAt ? new Date(currentDueAt) : undefined),
|
||||||
|
[currentDueAt],
|
||||||
|
);
|
||||||
|
const earliestRequestedDate = useMemo(() => {
|
||||||
|
const date = currentDueDate ? new Date(currentDueDate) : new Date();
|
||||||
|
date.setHours(0, 0, 0, 0);
|
||||||
|
if (currentDueDate) date.setDate(date.getDate() + 1);
|
||||||
|
return date;
|
||||||
|
}, [currentDueDate]);
|
||||||
|
const latestRequestedMonth = useMemo(
|
||||||
|
() => new Date(earliestRequestedDate.getFullYear() + 20, 11),
|
||||||
|
[earliestRequestedDate],
|
||||||
|
);
|
||||||
|
const [requestedDueDate, setRequestedDueDate] = useState<Date>();
|
||||||
|
const [reason, setReason] = useState('');
|
||||||
|
const assignmentId = ticket.worker?.assignment_id;
|
||||||
|
const requestExtensionMutation = useRequestTicketExtensionMutation(
|
||||||
|
ticket.id,
|
||||||
|
assignmentId,
|
||||||
|
ticket.defect_class,
|
||||||
|
);
|
||||||
|
const isPending = requestExtensionMutation.isPending;
|
||||||
|
const isRequestedDateValid = Boolean(
|
||||||
|
requestedDueDate &&
|
||||||
|
(!currentDueDate || requestedDueDate.getTime() > currentDueDate.getTime()),
|
||||||
|
);
|
||||||
|
const canSubmit =
|
||||||
|
Boolean(assignmentId) &&
|
||||||
|
isRequestedDateValid &&
|
||||||
|
Boolean(reason.trim()) &&
|
||||||
|
!isPending;
|
||||||
|
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
if (!requestedDueDate || !canSubmit) return;
|
||||||
|
|
||||||
|
await requestExtensionMutation.mutateAsync({
|
||||||
|
requested_due_at: requestedDueDate.toISOString(),
|
||||||
|
reason: reason.trim(),
|
||||||
|
});
|
||||||
|
setRequestedDueDate(undefined);
|
||||||
|
setReason('');
|
||||||
|
onCancel();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-5">
|
||||||
|
<div className="flex gap-3 rounded-lg border border-primary/15 bg-primary/5 p-4">
|
||||||
|
<Clock3 className="mt-0.5 size-5 shrink-0 text-primary" />
|
||||||
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Request more time to complete the repair. Your manager will review the
|
||||||
|
request.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>Current Due Date</Label>
|
||||||
|
<DatePicker
|
||||||
|
value={currentDueDate}
|
||||||
|
showTimeZone={false}
|
||||||
|
placeholder="No due date available"
|
||||||
|
disabled
|
||||||
|
className="w-full"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>
|
||||||
|
Requested Due Date <span className="text-destructive">*</span>
|
||||||
|
</Label>
|
||||||
|
<DatePickerSimple
|
||||||
|
id="requested-due-date"
|
||||||
|
value={requestedDueDate}
|
||||||
|
onChange={setRequestedDueDate}
|
||||||
|
showLabel={false}
|
||||||
|
placeholder="Select requested due date"
|
||||||
|
disabled={isPending}
|
||||||
|
className="w-full"
|
||||||
|
startMonth={earliestRequestedDate}
|
||||||
|
endMonth={latestRequestedMonth}
|
||||||
|
disabledDates={{ before: earliestRequestedDate }}
|
||||||
|
/>
|
||||||
|
{requestedDueDate && !isRequestedDateValid ? (
|
||||||
|
<p className="text-xs text-destructive">
|
||||||
|
Requested date must be after the current due date.
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="extension-reason">
|
||||||
|
Reason for Extension <span className="text-destructive">*</span>
|
||||||
|
</Label>
|
||||||
|
<div className="relative">
|
||||||
|
<Textarea
|
||||||
|
id="extension-reason"
|
||||||
|
value={reason}
|
||||||
|
onChange={(event) =>
|
||||||
|
setReason(event.target.value.slice(0, MAX_REASON_LENGTH))
|
||||||
|
}
|
||||||
|
placeholder="Explain why additional time is required to complete the repair."
|
||||||
|
disabled={isPending}
|
||||||
|
className="min-h-28 resize-none pb-8"
|
||||||
|
/>
|
||||||
|
<span className="pointer-events-none absolute right-3 bottom-2 text-xs text-muted-foreground">
|
||||||
|
{reason.length} / {MAX_REASON_LENGTH}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
This request will be sent to your manager for approval.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-3">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
disabled={isPending}
|
||||||
|
onClick={onCancel}
|
||||||
|
>
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
<Button type="button" disabled={!canSubmit} onClick={handleSubmit}>
|
||||||
|
{isPending ? <Loader2 className="animate-spin" /> : <Send />}
|
||||||
|
{isPending ? 'Submitting...' : 'Submit Request'}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,231 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
|
import {
|
||||||
|
ArrowRight,
|
||||||
|
CalendarClock,
|
||||||
|
Check,
|
||||||
|
Clock3,
|
||||||
|
Loader2,
|
||||||
|
X,
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Label } from '@/components/ui/label';
|
||||||
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
import type {
|
||||||
|
TicketDetail,
|
||||||
|
TicketExtensionRequest,
|
||||||
|
TicketExtensionRequestsResponse,
|
||||||
|
} from '@/types';
|
||||||
|
import { formatDate } from '@/utils/date';
|
||||||
|
|
||||||
|
import {
|
||||||
|
useReviewTicketExtensionMutation,
|
||||||
|
useTicketExtensionRequestQuery,
|
||||||
|
} from '../../../hooks/useTicketQueries';
|
||||||
|
import { TicketActionCard } from './TicketActionCard';
|
||||||
|
|
||||||
|
const MAX_NOTE_LENGTH = 300;
|
||||||
|
|
||||||
|
function getPendingRequest(response: TicketExtensionRequestsResponse) {
|
||||||
|
return response.items
|
||||||
|
.filter((request) => request.status === 'pending')
|
||||||
|
.reduce<TicketExtensionRequest | null>((latest, request) => {
|
||||||
|
if (!latest) return request;
|
||||||
|
return new Date(request.requested_at) > new Date(latest.requested_at)
|
||||||
|
? request
|
||||||
|
: latest;
|
||||||
|
}, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExtensionDays(request: TicketExtensionRequest) {
|
||||||
|
const difference =
|
||||||
|
new Date(request.requested_due_at).getTime() -
|
||||||
|
new Date(request.current_due_at).getTime();
|
||||||
|
return Math.max(0, Math.ceil(difference / (24 * 60 * 60 * 1000)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function Requester({ request }: { request: TicketExtensionRequest }) {
|
||||||
|
const name = request.requested_by?.name ?? 'Assigned worker';
|
||||||
|
const initials = name
|
||||||
|
.split(/\s+/)
|
||||||
|
.slice(0, 2)
|
||||||
|
.map((part) => part[0]?.toUpperCase())
|
||||||
|
.join('');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="grid grid-cols-2 gap-3 rounded-lg bg-muted/40 p-3">
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span className="flex size-8 shrink-0 items-center justify-center rounded-full bg-primary/15 text-xs font-semibold text-primary">
|
||||||
|
{initials || 'W'}
|
||||||
|
</span>
|
||||||
|
<div className="min-w-0">
|
||||||
|
<p className="text-[11px] text-muted-foreground">Requested By</p>
|
||||||
|
<p className="truncate text-sm font-medium">{name}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p className="text-[11px] text-muted-foreground">Requested On</p>
|
||||||
|
<p className="text-sm font-medium">
|
||||||
|
{formatDate(request.requested_at)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ExtensionReviewForm({
|
||||||
|
ticket,
|
||||||
|
request,
|
||||||
|
}: {
|
||||||
|
ticket: TicketDetail;
|
||||||
|
request: TicketExtensionRequest;
|
||||||
|
}) {
|
||||||
|
const [note, setNote] = useState('');
|
||||||
|
const [selectedAction, setSelectedAction] = useState<
|
||||||
|
'approve' | 'reject' | null
|
||||||
|
>(null);
|
||||||
|
const assignmentId = ticket.worker?.assignment_id as number;
|
||||||
|
const reviewMutation = useReviewTicketExtensionMutation(
|
||||||
|
ticket.id,
|
||||||
|
assignmentId,
|
||||||
|
ticket.defect_class,
|
||||||
|
);
|
||||||
|
const extensionDays = getExtensionDays(request);
|
||||||
|
|
||||||
|
const submitDecision = async (action: 'approve' | 'reject') => {
|
||||||
|
setSelectedAction(action);
|
||||||
|
try {
|
||||||
|
await reviewMutation.mutateAsync({ action, note: note.trim() });
|
||||||
|
} finally {
|
||||||
|
setSelectedAction(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TicketActionCard icon={CalendarClock} title="Extension Request Details">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<Requester request={request} />
|
||||||
|
|
||||||
|
<section className="space-y-2">
|
||||||
|
<p className="text-xs font-semibold">Request Summary</p>
|
||||||
|
<div className="grid grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] items-start gap-3 rounded-lg border p-3">
|
||||||
|
<div>
|
||||||
|
<p className="text-[11px] text-muted-foreground">
|
||||||
|
Current Due Date
|
||||||
|
</p>
|
||||||
|
<p className="text-xs font-medium">
|
||||||
|
{formatDate(request.current_due_at)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<ArrowRight className="mt-6 size-4 text-muted-foreground" />
|
||||||
|
<div>
|
||||||
|
<p className="text-[11px] text-muted-foreground">
|
||||||
|
Requested Due Date
|
||||||
|
</p>
|
||||||
|
<p className="text-xs font-medium">
|
||||||
|
{formatDate(request.requested_due_at)}
|
||||||
|
</p>
|
||||||
|
{extensionDays > 0 ? (
|
||||||
|
<span className="mt-1 inline-flex rounded-full bg-emerald-100 px-2 py-0.5 text-[10px] font-semibold text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-300">
|
||||||
|
+{extensionDays} {extensionDays === 1 ? 'Day' : 'Days'}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="rounded-lg border p-3">
|
||||||
|
<p className="text-[11px] text-muted-foreground">Reason</p>
|
||||||
|
<p className="mt-1 text-sm leading-relaxed">{request.reason}</p>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="extension-manager-note">
|
||||||
|
Add Manager Comments{' '}
|
||||||
|
<span className="text-muted-foreground">(Optional)</span>
|
||||||
|
</Label>
|
||||||
|
<div className="relative">
|
||||||
|
<Textarea
|
||||||
|
id="extension-manager-note"
|
||||||
|
value={note}
|
||||||
|
onChange={(event) =>
|
||||||
|
setNote(event.target.value.slice(0, MAX_NOTE_LENGTH))
|
||||||
|
}
|
||||||
|
placeholder="Add a note explaining your decision..."
|
||||||
|
disabled={reviewMutation.isPending}
|
||||||
|
className="min-h-24 resize-none pb-8"
|
||||||
|
/>
|
||||||
|
<span className="pointer-events-none absolute right-3 bottom-2 text-xs text-muted-foreground">
|
||||||
|
{note.length} / {MAX_NOTE_LENGTH}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-2 gap-3">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
className="border-destructive/40 text-destructive hover:bg-destructive/5 hover:text-destructive"
|
||||||
|
disabled={reviewMutation.isPending}
|
||||||
|
onClick={() => submitDecision('reject')}
|
||||||
|
>
|
||||||
|
{selectedAction === 'reject' ? (
|
||||||
|
<Loader2 className="animate-spin" />
|
||||||
|
) : (
|
||||||
|
<X />
|
||||||
|
)}
|
||||||
|
Reject Request
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
disabled={reviewMutation.isPending}
|
||||||
|
onClick={() => submitDecision('approve')}
|
||||||
|
>
|
||||||
|
{selectedAction === 'approve' ? (
|
||||||
|
<Loader2 className="animate-spin" />
|
||||||
|
) : (
|
||||||
|
<Check />
|
||||||
|
)}
|
||||||
|
Approve Extension
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</TicketActionCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ReviewExtensionRequestAction({
|
||||||
|
ticket,
|
||||||
|
}: {
|
||||||
|
ticket: TicketDetail;
|
||||||
|
}) {
|
||||||
|
const assignmentId = ticket.worker?.assignment_id;
|
||||||
|
const extensionRequestQuery = useTicketExtensionRequestQuery(
|
||||||
|
ticket.id,
|
||||||
|
assignmentId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!assignmentId || extensionRequestQuery.isError) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extensionRequestQuery.isLoading) {
|
||||||
|
return (
|
||||||
|
<TicketActionCard icon={Clock3} title="Extension Request">
|
||||||
|
<div className="flex items-center justify-center py-8 text-muted-foreground">
|
||||||
|
<Loader2 className="mr-2 size-4 animate-spin" />
|
||||||
|
<span className="text-sm">Checking for requests...</span>
|
||||||
|
</div>
|
||||||
|
</TicketActionCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const pendingRequest = extensionRequestQuery.data
|
||||||
|
? getPendingRequest(extensionRequestQuery.data)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (!pendingRequest) return null;
|
||||||
|
|
||||||
|
return <ExtensionReviewForm ticket={ticket} request={pendingRequest} />;
|
||||||
|
}
|
||||||
@@ -32,9 +32,11 @@ export function ReviewRepairAction({ ticket }: { ticket: TicketDetail }) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-2 gap-2">
|
<div className="grid grid-cols-2 gap-2">
|
||||||
<Button
|
<Button
|
||||||
|
variant={'secondary'}
|
||||||
disabled={!reviewComment || reviewRepairMutation.isPending}
|
disabled={!reviewComment || reviewRepairMutation.isPending}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
reviewRepairMutation.mutate({
|
reviewRepairMutation.mutate({
|
||||||
|
defect_class: ticket.defect_class,
|
||||||
action: 'approve',
|
action: 'approve',
|
||||||
comment: reviewComment,
|
comment: reviewComment,
|
||||||
})
|
})
|
||||||
@@ -48,6 +50,7 @@ export function ReviewRepairAction({ ticket }: { ticket: TicketDetail }) {
|
|||||||
disabled={!reviewComment || reviewRepairMutation.isPending}
|
disabled={!reviewComment || reviewRepairMutation.isPending}
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
reviewRepairMutation.mutate({
|
reviewRepairMutation.mutate({
|
||||||
|
defect_class: ticket.defect_class,
|
||||||
action: 'reject',
|
action: 'reject',
|
||||||
comment: reviewComment,
|
comment: reviewComment,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,16 +1,52 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
import { Wrench } from 'lucide-react';
|
import { Wrench } from 'lucide-react';
|
||||||
|
|
||||||
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
||||||
import type { TicketDetail } from '@/types';
|
import type { TicketDetail } from '@/types';
|
||||||
|
|
||||||
import { RepairEvidenceForm } from './RepairEvidenceForm';
|
import { RepairEvidenceForm } from './RepairEvidenceForm';
|
||||||
|
import { TicketExtensionRequestPanel } from './TicketExtensionRequestPanel';
|
||||||
import { TicketActionCard } from './TicketActionCard';
|
import { TicketActionCard } from './TicketActionCard';
|
||||||
|
|
||||||
|
type RepairActionTab = 'repair-proof' | 'request-extension';
|
||||||
|
|
||||||
export function SubmitRepairAction({ ticket }: { ticket: TicketDetail }) {
|
export function SubmitRepairAction({ ticket }: { ticket: TicketDetail }) {
|
||||||
|
const [activeTab, setActiveTab] = useState<RepairActionTab>('repair-proof');
|
||||||
|
|
||||||
|
if (ticket.repair?.submitted_at) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TicketActionCard icon={Wrench} title="Submit Repair Evidence">
|
<TicketActionCard icon={Wrench} title="Repair Proof">
|
||||||
<RepairEvidenceForm ticketId={ticket.id} />
|
<Tabs
|
||||||
|
value={activeTab}
|
||||||
|
onValueChange={(value) => setActiveTab(value as RepairActionTab)}
|
||||||
|
className="gap-5"
|
||||||
|
>
|
||||||
|
<TabsList variant="line" className="grid h-auto w-full grid-cols-2 p-0">
|
||||||
|
<TabsTrigger value="repair-proof" className="pb-3">
|
||||||
|
Upload Repair Proof
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="request-extension" className="pb-3">
|
||||||
|
Request Extension
|
||||||
|
</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
<TabsContent value="repair-proof">
|
||||||
|
<RepairEvidenceForm
|
||||||
|
ticketId={ticket.id}
|
||||||
|
defectClass={ticket.defect_class}
|
||||||
|
/>
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="request-extension">
|
||||||
|
<TicketExtensionRequestPanel
|
||||||
|
ticket={ticket}
|
||||||
|
onCancelRequest={() => setActiveTab('repair-proof')}
|
||||||
|
/>
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
</TicketActionCard>
|
</TicketActionCard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
export { RepairProofSummary as SubmittedRepairProofAction } from '../repair/RepairProofSummary';
|
||||||
@@ -3,23 +3,26 @@
|
|||||||
import type { LucideIcon } from 'lucide-react';
|
import type { LucideIcon } from 'lucide-react';
|
||||||
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
interface TicketActionCardProps {
|
interface TicketActionCardProps {
|
||||||
icon: LucideIcon;
|
icon: LucideIcon;
|
||||||
|
iconClassName?: string;
|
||||||
title: string;
|
title: string;
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TicketActionCard({
|
export function TicketActionCard({
|
||||||
icon: Icon,
|
icon: Icon,
|
||||||
|
iconClassName,
|
||||||
title,
|
title,
|
||||||
children,
|
children,
|
||||||
}: TicketActionCardProps) {
|
}: TicketActionCardProps) {
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
<CardHeader className="pb-4">
|
<CardHeader>
|
||||||
<CardTitle className="flex items-center gap-2 text-base">
|
<CardTitle className="flex items-center gap-2 text-base">
|
||||||
<Icon className="size-4 text-primary" />
|
<Icon className={cn('text-primary', iconClassName)} />
|
||||||
{title}
|
{title}
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
|||||||
@@ -0,0 +1,248 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import {
|
||||||
|
AlertCircle,
|
||||||
|
CalendarDays,
|
||||||
|
CheckCircle2,
|
||||||
|
Clock3,
|
||||||
|
History,
|
||||||
|
Loader2,
|
||||||
|
RotateCcw,
|
||||||
|
XCircle,
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import type {
|
||||||
|
TicketDetail,
|
||||||
|
TicketExtensionRequest,
|
||||||
|
TicketExtensionRequestsResponse,
|
||||||
|
} from '@/types';
|
||||||
|
import { formatDate } from '@/utils/date';
|
||||||
|
|
||||||
|
import { useTicketExtensionRequestQuery } from '../../../hooks/useTicketQueries';
|
||||||
|
import { RequestExtensionForm } from './RequestExtensionForm';
|
||||||
|
|
||||||
|
interface TicketExtensionRequestPanelProps {
|
||||||
|
ticket: TicketDetail;
|
||||||
|
onCancelRequest: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DetailRowProps {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
children?: React.ReactNode;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function DetailRow({ label, value, children, className }: DetailRowProps) {
|
||||||
|
return (
|
||||||
|
<div className={cn('space-y-1 px-3 py-2.5', className)}>
|
||||||
|
<p className="text-[11px] font-medium text-muted-foreground">{label}</p>
|
||||||
|
<div className="flex items-center justify-between gap-3">
|
||||||
|
<p className="text-sm font-medium">{value}</p>
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusConfig = {
|
||||||
|
pending: {
|
||||||
|
title: 'Request Pending',
|
||||||
|
description: 'Your extension request is waiting for manager approval.',
|
||||||
|
icon: Clock3,
|
||||||
|
className:
|
||||||
|
'border-amber-200 bg-amber-50 text-amber-700 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-300',
|
||||||
|
},
|
||||||
|
approved: {
|
||||||
|
title: 'Request Approved',
|
||||||
|
description: 'Your extension request has been approved by the manager.',
|
||||||
|
icon: CheckCircle2,
|
||||||
|
className:
|
||||||
|
'border-emerald-200 bg-emerald-50 text-emerald-700 dark:border-emerald-900/60 dark:bg-emerald-950/30 dark:text-emerald-300',
|
||||||
|
},
|
||||||
|
rejected: {
|
||||||
|
title: 'Request Rejected',
|
||||||
|
description: 'Your extension request has been rejected by the manager.',
|
||||||
|
icon: AlertCircle,
|
||||||
|
className:
|
||||||
|
'border-red-200 bg-red-50 text-red-700 dark:border-red-900/60 dark:bg-red-950/30 dark:text-red-300',
|
||||||
|
},
|
||||||
|
cancelled: {
|
||||||
|
title: 'Request Cancelled',
|
||||||
|
description: 'This extension request was cancelled.',
|
||||||
|
icon: XCircle,
|
||||||
|
className: 'border-border bg-muted/50 text-muted-foreground',
|
||||||
|
},
|
||||||
|
} satisfies Record<
|
||||||
|
TicketExtensionRequest['status'],
|
||||||
|
{
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
icon: typeof Clock3;
|
||||||
|
className: string;
|
||||||
|
}
|
||||||
|
>;
|
||||||
|
|
||||||
|
function getLatestRequest(response: TicketExtensionRequestsResponse) {
|
||||||
|
return response.items.reduce<TicketExtensionRequest | null>(
|
||||||
|
(latest, item) => {
|
||||||
|
if (!latest) return item;
|
||||||
|
return new Date(item.requested_at) > new Date(latest.requested_at)
|
||||||
|
? item
|
||||||
|
: latest;
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExtensionDays(request: TicketExtensionRequest) {
|
||||||
|
const difference =
|
||||||
|
new Date(request.requested_due_at).getTime() -
|
||||||
|
new Date(request.current_due_at).getTime();
|
||||||
|
return Math.max(0, Math.ceil(difference / (24 * 60 * 60 * 1000)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function ExtensionRequestDetails({
|
||||||
|
request,
|
||||||
|
}: {
|
||||||
|
request: TicketExtensionRequest;
|
||||||
|
}) {
|
||||||
|
const config = statusConfig[request.status];
|
||||||
|
const StatusIcon = config.icon;
|
||||||
|
const extensionDays = getExtensionDays(request);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div className={cn('flex gap-3 rounded-lg border p-4', config.className)}>
|
||||||
|
<StatusIcon className="mt-0.5 size-5 shrink-0" />
|
||||||
|
<div className="space-y-1">
|
||||||
|
<p className="text-sm font-semibold">{config.title}</p>
|
||||||
|
<p className="text-xs leading-relaxed">{config.description}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section className="space-y-2">
|
||||||
|
<p className="text-xs font-semibold">Request Details</p>
|
||||||
|
<div className="divide-y overflow-hidden rounded-lg border">
|
||||||
|
<DetailRow
|
||||||
|
label="Requested On"
|
||||||
|
value={formatDate(request.requested_at)}
|
||||||
|
/>
|
||||||
|
<DetailRow
|
||||||
|
label="Requested Due Date"
|
||||||
|
value={formatDate(request.requested_due_at)}
|
||||||
|
>
|
||||||
|
{extensionDays > 0 ? (
|
||||||
|
<span className="shrink-0 rounded-full bg-primary/10 px-2 py-0.5 text-[10px] font-semibold text-primary">
|
||||||
|
+{extensionDays} {extensionDays === 1 ? 'Day' : 'Days'}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</DetailRow>
|
||||||
|
<DetailRow label="Reason for Extension" value={request.reason} />
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
{request.resolved_at || request.resolved_by ? (
|
||||||
|
<section className="space-y-2">
|
||||||
|
<p className="text-xs font-semibold">Manager Response</p>
|
||||||
|
<div className="divide-y overflow-hidden rounded-lg border">
|
||||||
|
{request.resolved_at ? (
|
||||||
|
<DetailRow
|
||||||
|
label="Responded On"
|
||||||
|
value={formatDate(request.resolved_at)}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
{request.resolved_by ? (
|
||||||
|
<DetailRow
|
||||||
|
label="Resolved By"
|
||||||
|
value={`${request.resolved_by.name} · ${request.resolved_by.role.name}`}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
{request.status === 'approved' ? (
|
||||||
|
<DetailRow
|
||||||
|
label="Approved Due Date"
|
||||||
|
value={formatDate(request.requested_due_at)}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<section className="space-y-2">
|
||||||
|
<p className="text-xs font-semibold">Original Due Date</p>
|
||||||
|
<div className="rounded-lg border">
|
||||||
|
<DetailRow
|
||||||
|
label="Original schedule"
|
||||||
|
value={formatDate(request.current_due_at)}
|
||||||
|
>
|
||||||
|
<CalendarDays className="size-4 text-muted-foreground" />
|
||||||
|
</DetailRow>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<Button type="button" variant="outline" className="w-full">
|
||||||
|
<History />
|
||||||
|
View Approval History
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TicketExtensionRequestPanel({
|
||||||
|
ticket,
|
||||||
|
onCancelRequest,
|
||||||
|
}: TicketExtensionRequestPanelProps) {
|
||||||
|
const assignmentId = ticket.worker?.assignment_id;
|
||||||
|
const extensionRequestQuery = useTicketExtensionRequestQuery(
|
||||||
|
ticket.id,
|
||||||
|
assignmentId,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!assignmentId) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-dashed p-4 text-sm text-muted-foreground">
|
||||||
|
No active assignment is available for this ticket.
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extensionRequestQuery.isLoading) {
|
||||||
|
return (
|
||||||
|
<div className="flex min-h-40 items-center justify-center text-muted-foreground">
|
||||||
|
<Loader2 className="size-5 animate-spin" />
|
||||||
|
<span className="ml-2 text-sm">Loading extension request...</span>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extensionRequestQuery.isError) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-3 rounded-lg border border-destructive/30 bg-destructive/5 p-4">
|
||||||
|
<p className="text-sm text-destructive">
|
||||||
|
Extension request details could not be loaded.
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
size="sm"
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => extensionRequestQuery.refetch()}
|
||||||
|
>
|
||||||
|
<RotateCcw />
|
||||||
|
Try Again
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const latestRequest = extensionRequestQuery.data
|
||||||
|
? getLatestRequest(extensionRequestQuery.data)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (!latestRequest) {
|
||||||
|
return <RequestExtensionForm ticket={ticket} onCancel={onCancelRequest} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
return <ExtensionRequestDetails request={latestRequest} />;
|
||||||
|
}
|
||||||
@@ -1,121 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { ImageIcon } from 'lucide-react';
|
|
||||||
|
|
||||||
import { Skeleton } from '@/components/ui/skeleton';
|
|
||||||
import { useProtectedMediaObjectUrl } from '@/hooks/useProtectedMedia';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
import { formatRepairDate, ReportSurface } from './repairReportUtils';
|
|
||||||
|
|
||||||
const MAX_MEDIA_SLOTS = 5;
|
|
||||||
|
|
||||||
const imageBadgeStyles = [
|
|
||||||
'bg-primary/90 text-primary-foreground',
|
|
||||||
'bg-secondary text-secondary-foreground',
|
|
||||||
'bg-accent text-accent-foreground',
|
|
||||||
'bg-muted text-muted-foreground',
|
|
||||||
'bg-primary/70 text-primary-foreground',
|
|
||||||
] as const;
|
|
||||||
|
|
||||||
export function RepairProofImagesGrid({
|
|
||||||
imageUrls,
|
|
||||||
submittedAt,
|
|
||||||
layout = 'row',
|
|
||||||
}: {
|
|
||||||
imageUrls: string[];
|
|
||||||
submittedAt: string | null;
|
|
||||||
layout?: 'row' | 'sidebar';
|
|
||||||
}) {
|
|
||||||
const imageSlots = Array.from(
|
|
||||||
{ length: MAX_MEDIA_SLOTS },
|
|
||||||
(_, index) => imageUrls[index] ?? null,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'grid gap-3',
|
|
||||||
layout === 'sidebar'
|
|
||||||
? 'grid-cols-2 auto-rows-fr'
|
|
||||||
: 'grid-cols-2 sm:grid-cols-3 lg:grid-cols-5',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{imageSlots.map((url, index) => (
|
|
||||||
<RepairProofImageSlot
|
|
||||||
key={index}
|
|
||||||
url={url}
|
|
||||||
index={index}
|
|
||||||
submittedAt={submittedAt}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function RepairProofImageSlot({
|
|
||||||
url,
|
|
||||||
index,
|
|
||||||
submittedAt,
|
|
||||||
}: {
|
|
||||||
url: string | null;
|
|
||||||
index: number;
|
|
||||||
submittedAt: string | null;
|
|
||||||
}) {
|
|
||||||
const { objectUrl, isLoading, isError } = useProtectedMediaObjectUrl(url);
|
|
||||||
|
|
||||||
if (!url) {
|
|
||||||
return (
|
|
||||||
<ReportSurface className="space-y-2 p-2">
|
|
||||||
<div className="flex aspect-4/3 items-center justify-center rounded-lg border border-dashed border-border/70 bg-muted/10 text-muted-foreground/70">
|
|
||||||
<ImageIcon className="size-4" />
|
|
||||||
</div>
|
|
||||||
<p className="truncate px-1 text-[11px] text-muted-foreground/70">
|
|
||||||
No image added
|
|
||||||
</p>
|
|
||||||
</ReportSurface>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isLoading) {
|
|
||||||
return (
|
|
||||||
<ReportSurface className="space-y-2 p-2">
|
|
||||||
<Skeleton className="aspect-4/3 w-full rounded-lg" />
|
|
||||||
<Skeleton className="h-3 w-16" />
|
|
||||||
</ReportSurface>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isError || !objectUrl) {
|
|
||||||
return (
|
|
||||||
<ReportSurface className="space-y-2 p-2">
|
|
||||||
<div className="flex aspect-4/3 items-center justify-center rounded-lg border border-dashed bg-muted/10 text-xs text-muted-foreground">
|
|
||||||
Unavailable
|
|
||||||
</div>
|
|
||||||
<p className="truncate px-1 text-[11px] text-muted-foreground">
|
|
||||||
Image {index + 1}
|
|
||||||
</p>
|
|
||||||
</ReportSurface>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ReportSurface className="space-y-2 p-2">
|
|
||||||
<a
|
|
||||||
href={objectUrl}
|
|
||||||
target="_blank"
|
|
||||||
rel="noreferrer"
|
|
||||||
className="group relative block overflow-hidden rounded-lg border bg-muted/20"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src={objectUrl}
|
|
||||||
alt={`Repair proof ${index + 1}`}
|
|
||||||
className="aspect-4/3 w-full object-cover transition-transform group-hover:scale-[1.02]"
|
|
||||||
/>
|
|
||||||
</a>
|
|
||||||
<p className="truncate px-1 text-[11px] text-muted-foreground">
|
|
||||||
{submittedAt ? formatRepairDate(submittedAt) : `Image ${index + 1}`}
|
|
||||||
</p>
|
|
||||||
</ReportSurface>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { FileText, MessageSquareQuote, BadgeCheck } from 'lucide-react';
|
|
||||||
|
|
||||||
import type { TicketDetail } from '@/types';
|
|
||||||
|
|
||||||
import {
|
|
||||||
EmptyPanel,
|
|
||||||
formatRepairDate,
|
|
||||||
getPersonLabel,
|
|
||||||
} from './repairReportUtils';
|
|
||||||
|
|
||||||
function MetaLabel({ children }: { children: React.ReactNode }) {
|
|
||||||
return (
|
|
||||||
<p className="text-xs font-medium tracking-wide text-muted-foreground">
|
|
||||||
{children}
|
|
||||||
</p>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ReportField({
|
|
||||||
label,
|
|
||||||
value,
|
|
||||||
}: {
|
|
||||||
label: string;
|
|
||||||
value: string | null | undefined;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div className="space-y-1">
|
|
||||||
<MetaLabel>{label}</MetaLabel>
|
|
||||||
<p className="text-sm font-semibold text-foreground">{value || '-'}</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function RepairReportPanel({ ticket }: { ticket: TicketDetail }) {
|
|
||||||
const repair = ticket.repair;
|
|
||||||
|
|
||||||
if (!repair) {
|
|
||||||
return (
|
|
||||||
<section className="space-y-4 rounded-xl border bg-card p-4 lg:p-6">
|
|
||||||
<div className="flex items-center gap-2 border-b border-border pb-4">
|
|
||||||
<FileText className="size-5 text-primary" />
|
|
||||||
<h3 className="text-lg font-semibold">Repair Report</h3>
|
|
||||||
</div>
|
|
||||||
<EmptyPanel
|
|
||||||
icon={MessageSquareQuote}
|
|
||||||
title="No repair report submitted yet"
|
|
||||||
description="Repair details will appear here once the assigned worker submits evidence."
|
|
||||||
className="py-10"
|
|
||||||
/>
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<section className="space-y-4 rounded-xl border bg-card p-4 lg:p-6">
|
|
||||||
<div className="flex flex-col gap-2 border-b border-border pb-4 sm:flex-row sm:items-center sm:justify-between">
|
|
||||||
<h3 className="flex items-center gap-2 text-lg font-semibold">
|
|
||||||
<FileText className="size-5 text-primary" />
|
|
||||||
Repair Report
|
|
||||||
</h3>
|
|
||||||
{repair.submitted_at ? (
|
|
||||||
<span className="text-xs text-muted-foreground italic">
|
|
||||||
Completed {formatRepairDate(repair.submitted_at)}
|
|
||||||
</span>
|
|
||||||
) : null}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2">
|
|
||||||
<ReportField label="Technician" value={getPersonLabel(ticket.worker)} />
|
|
||||||
<ReportField
|
|
||||||
label="Submitted At"
|
|
||||||
value={
|
|
||||||
repair.submitted_at ? formatRepairDate(repair.submitted_at) : null
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="space-y-2 pt-1">
|
|
||||||
<MetaLabel>Repair Summary</MetaLabel>
|
|
||||||
{repair.notes?.trim() ? (
|
|
||||||
<>
|
|
||||||
<div className="rounded-lg border bg-muted/15 px-4 py-3">
|
|
||||||
<p className="text-sm leading-relaxed text-foreground/90">
|
|
||||||
{repair.notes}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
{/* <div className="flex items-center gap-2 text-xs text-muted-foreground">
|
|
||||||
<BadgeCheck className="size-3.5 text-primary" />
|
|
||||||
<span>Self-certified by {getPersonLabel(ticket.worker)}</span>
|
|
||||||
</div> */}
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<EmptyPanel
|
|
||||||
icon={MessageSquareQuote}
|
|
||||||
title="No repair notes added yet"
|
|
||||||
className="py-6"
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { ShieldCheck } from 'lucide-react';
|
|
||||||
|
|
||||||
import { ProtectedVideoPlayer } from '@/components/media/ProtectedVideoPlayer';
|
|
||||||
import type { TicketDetail } from '@/types';
|
|
||||||
|
|
||||||
export function RepairVideoComparison({ ticket }: { ticket: TicketDetail }) {
|
|
||||||
const originalVideoUrl = ticket.video?.url ?? null;
|
|
||||||
const repairVideoUrl = ticket.repair?.proof_video_url ?? null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<section className="space-y-4">
|
|
||||||
<h3 className="flex items-center gap-2 text-base font-semibold">
|
|
||||||
<ShieldCheck className="size-5 text-primary" />
|
|
||||||
Repair Verification
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<div className="grid grid-cols-1 gap-4 lg:grid-cols-2">
|
|
||||||
<ComparisonVideoItem
|
|
||||||
tooltip={ticket.video?.name ?? 'Original inspection video'}
|
|
||||||
videoLabel="Before"
|
|
||||||
videoUrl={originalVideoUrl}
|
|
||||||
meta="AI detection video"
|
|
||||||
emptyTitle="No original video available"
|
|
||||||
emptyDescription="The source inspection video is not attached to this ticket."
|
|
||||||
/>
|
|
||||||
<ComparisonVideoItem
|
|
||||||
tooltip="Worker repair evidence video"
|
|
||||||
videoLabel="After"
|
|
||||||
videoUrl={repairVideoUrl}
|
|
||||||
meta="Worker evidence video"
|
|
||||||
emptyTitle={
|
|
||||||
ticket.repair
|
|
||||||
? 'No repair video uploaded'
|
|
||||||
: 'No evidence submitted yet'
|
|
||||||
}
|
|
||||||
emptyDescription={
|
|
||||||
ticket.repair
|
|
||||||
? 'The assigned worker has not uploaded a repair video yet.'
|
|
||||||
: 'Repair video will appear here once evidence is submitted.'
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ComparisonVideoItem({
|
|
||||||
tooltip,
|
|
||||||
videoLabel,
|
|
||||||
videoUrl,
|
|
||||||
meta,
|
|
||||||
emptyTitle,
|
|
||||||
emptyDescription,
|
|
||||||
}: {
|
|
||||||
tooltip: string;
|
|
||||||
videoLabel: string;
|
|
||||||
videoUrl: string | null;
|
|
||||||
meta: string;
|
|
||||||
emptyTitle: string;
|
|
||||||
emptyDescription: string;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div title={tooltip}>
|
|
||||||
<ProtectedVideoPlayer
|
|
||||||
url={videoUrl}
|
|
||||||
label={videoLabel}
|
|
||||||
meta={meta}
|
|
||||||
emptyTitle={emptyTitle}
|
|
||||||
emptyDescription={emptyDescription}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import type { LucideIcon } from 'lucide-react';
|
|
||||||
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
import type { TicketActor } from '@/types';
|
|
||||||
|
|
||||||
export function formatRepairDate(value: string | null | undefined) {
|
|
||||||
if (!value) return '-';
|
|
||||||
return new Intl.DateTimeFormat('en-IN', {
|
|
||||||
dateStyle: 'medium',
|
|
||||||
timeStyle: 'short',
|
|
||||||
}).format(new Date(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
export function getPersonLabel(person: TicketActor | null | undefined) {
|
|
||||||
return person?.name || person?.email || 'Unknown';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function SectionLabel({ children }: { children: React.ReactNode }) {
|
|
||||||
return (
|
|
||||||
<p className="text-[11px] font-semibold tracking-[0.12em] text-foreground uppercase">
|
|
||||||
{children}
|
|
||||||
</p>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ReportSurface({
|
|
||||||
children,
|
|
||||||
className,
|
|
||||||
}: {
|
|
||||||
children: React.ReactNode;
|
|
||||||
className?: string;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div className={cn('rounded-xl border bg-card p-4', className)}>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function EmptyPanel({
|
|
||||||
icon: Icon,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
className,
|
|
||||||
}: {
|
|
||||||
icon: LucideIcon;
|
|
||||||
title: string;
|
|
||||||
description?: string;
|
|
||||||
className?: string;
|
|
||||||
}) {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'flex flex-col items-center justify-center rounded-lg border border-dashed border-border/80 bg-muted/10 px-4 py-8 text-center',
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Icon className="mb-3 size-6 text-muted-foreground" />
|
|
||||||
<p className="text-sm font-medium text-muted-foreground">{title}</p>
|
|
||||||
{description ? (
|
|
||||||
<p className="mt-1 max-w-xs text-xs text-muted-foreground/80">
|
|
||||||
{description}
|
|
||||||
</p>
|
|
||||||
) : null}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useMemo } from 'react';
|
||||||
|
import { useQueries } from '@tanstack/react-query';
|
||||||
|
import LightGallery from 'lightgallery/react';
|
||||||
|
import lgThumbnail from 'lightgallery/plugins/thumbnail';
|
||||||
|
import lgZoom from 'lightgallery/plugins/zoom';
|
||||||
|
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
|
import { protectedMediaService } from '@/services/api';
|
||||||
|
|
||||||
|
interface RepairProofGalleryProps {
|
||||||
|
imageUrls: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const MAX_VISIBLE_IMAGES = 8;
|
||||||
|
|
||||||
|
export function RepairProofGallery({ imageUrls }: RepairProofGalleryProps) {
|
||||||
|
const queries = useQueries({
|
||||||
|
queries: imageUrls.map((url) => ({
|
||||||
|
queryKey: ['protected-media', 'v2', url],
|
||||||
|
queryFn: () => protectedMediaService.getBlob(url),
|
||||||
|
staleTime: Infinity,
|
||||||
|
gcTime: 1000 * 60 * 30,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
|
||||||
|
const blobs = queries.map((query) => query.data);
|
||||||
|
const objectUrls = useMemo(
|
||||||
|
() => blobs.map((blob) => (blob ? URL.createObjectURL(blob) : null)),
|
||||||
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
|
[...blobs],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(
|
||||||
|
() => () => {
|
||||||
|
objectUrls.forEach((url) => {
|
||||||
|
if (url) URL.revokeObjectURL(url);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[objectUrls],
|
||||||
|
);
|
||||||
|
|
||||||
|
if (queries.some((query) => query.isLoading)) {
|
||||||
|
return (
|
||||||
|
<div className="grid grid-cols-4 gap-1 overflow-hidden rounded-lg">
|
||||||
|
{imageUrls.slice(0, MAX_VISIBLE_IMAGES).map((url, index) => (
|
||||||
|
<Skeleton
|
||||||
|
key={`${url}-${index}`}
|
||||||
|
className="aspect-square rounded-lg"
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const images = objectUrls.flatMap((url, index) =>
|
||||||
|
url ? [{ url, originalIndex: index }] : [],
|
||||||
|
);
|
||||||
|
const visibleCount = Math.min(MAX_VISIBLE_IMAGES, images.length);
|
||||||
|
const overflowCount = images.length - visibleCount;
|
||||||
|
|
||||||
|
if (images.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="rounded-lg border border-dashed py-8 text-center text-sm text-muted-foreground">
|
||||||
|
Repair images are unavailable.
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<LightGallery
|
||||||
|
elementClassNames="grid grid-cols-4 gap-1 overflow-hidden rounded-lg"
|
||||||
|
mode="lg-fade"
|
||||||
|
speed={400}
|
||||||
|
plugins={[lgThumbnail, lgZoom]}
|
||||||
|
thumbnail
|
||||||
|
download={false}
|
||||||
|
mobileSettings={{ controls: true, showCloseIcon: true, download: false }}
|
||||||
|
>
|
||||||
|
{images.map(({ url, originalIndex }, index) => {
|
||||||
|
const isVisible = index < visibleCount;
|
||||||
|
const isOverflowTile = overflowCount > 0 && index === visibleCount - 1;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
key={imageUrls[originalIndex]}
|
||||||
|
data-src={url}
|
||||||
|
data-sub-html={`<p>Repair evidence ${originalIndex + 1}</p>`}
|
||||||
|
className={isVisible ? 'group relative aspect-square' : 'hidden'}
|
||||||
|
aria-label={
|
||||||
|
isOverflowTile
|
||||||
|
? `View all ${images.length} repair images`
|
||||||
|
: `View repair image ${originalIndex + 1} of ${images.length}`
|
||||||
|
}
|
||||||
|
>
|
||||||
|
{/* Blob URLs cannot be handled by next/image. */}
|
||||||
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
|
<img
|
||||||
|
src={url}
|
||||||
|
alt={`Repair evidence ${originalIndex + 1}`}
|
||||||
|
className="size-full object-cover transition duration-300 group-hover:scale-[1.03] group-hover:brightness-90"
|
||||||
|
/>
|
||||||
|
{isOverflowTile ? (
|
||||||
|
<span className="absolute inset-0 flex items-center justify-center bg-black/55 text-xl font-semibold text-white transition-colors group-hover:bg-black/65">
|
||||||
|
+{overflowCount}
|
||||||
|
</span>
|
||||||
|
) : null}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</LightGallery>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
import { CheckCircle2, HardHat, Wrench, ToolCase } from 'lucide-react';
|
||||||
|
|
||||||
|
import { ProtectedVideoPlayer } from '@/components/media/ProtectedVideoPlayer';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import type { TicketDetail } from '@/types';
|
||||||
|
|
||||||
|
import { formatDate } from '@/utils/date';
|
||||||
|
import { RepairProofGallery } from './RepairProofGallery';
|
||||||
|
|
||||||
|
function SubmittedBanner({
|
||||||
|
submittedAt,
|
||||||
|
submitterName,
|
||||||
|
}: {
|
||||||
|
submittedAt: string;
|
||||||
|
submitterName: string;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-start gap-3 rounded-lg border border-emerald-200 bg-emerald-50 px-3 py-3 dark:border-emerald-900/60 dark:bg-emerald-950/30">
|
||||||
|
<CheckCircle2 className="mt-0.5 size-5 shrink-0 text-emerald-600 dark:text-emerald-400" />
|
||||||
|
<div className="min-w-0 space-y-0.5">
|
||||||
|
<p className="text-sm font-semibold text-emerald-800 dark:text-emerald-200">
|
||||||
|
Repair Submitted
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-emerald-700/80 dark:text-emerald-300/80">
|
||||||
|
{formatDate(submittedAt)} by {submitterName}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ImageGallery({
|
||||||
|
imageUrls,
|
||||||
|
hasVideo,
|
||||||
|
}: {
|
||||||
|
imageUrls: string[];
|
||||||
|
hasVideo: boolean;
|
||||||
|
}) {
|
||||||
|
if (imageUrls.length === 0) {
|
||||||
|
return hasVideo ? null : (
|
||||||
|
<div className="flex items-center gap-2 rounded-lg border border-dashed px-3 py-4 text-sm text-muted-foreground">
|
||||||
|
<HardHat className="size-4 shrink-0" />
|
||||||
|
No media attached
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return <RepairProofGallery imageUrls={imageUrls} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Notes({ notes }: { notes: string | null | undefined }) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<p className="text-xs font-semibold text-foreground">Repair Notes</p>
|
||||||
|
<p className="text-sm leading-relaxed text-muted-foreground">
|
||||||
|
{notes?.trim() || 'No repair notes provided.'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RepairProofSummary({ ticket }: { ticket: TicketDetail }) {
|
||||||
|
const repair = ticket.repair;
|
||||||
|
|
||||||
|
if (!repair?.submitted_at) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitterName = ticket.worker?.name?.trim() || 'Assigned worker';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader>
|
||||||
|
<CardTitle className="flex items-center gap-2 text-base">
|
||||||
|
<ToolCase className="text-primary" />
|
||||||
|
Repair Proof
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<SubmittedBanner
|
||||||
|
submittedAt={repair.submitted_at}
|
||||||
|
submitterName={submitterName}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ProtectedVideoPlayer
|
||||||
|
url={repair.proof_video_url}
|
||||||
|
meta="Contractor evidence video"
|
||||||
|
emptyTitle="No repair video uploaded"
|
||||||
|
emptyDescription="The assigned worker has not uploaded a repair video."
|
||||||
|
className="rounded-lg"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<ImageGallery
|
||||||
|
imageUrls={repair.proof_image_urls}
|
||||||
|
hasVideo={Boolean(repair.proof_video_url)}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Notes notes={repair.notes} />
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,40 +1,47 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
import { useParams, useRouter, useSearchParams } from 'next/navigation';
|
||||||
import { ArrowLeft, Loader2 } from 'lucide-react';
|
import { ArrowLeft } from 'lucide-react';
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
import { TicketDetailHeader } from './components/TicketDetailHeader';
|
import { TicketDetailHeader } from './components/TicketDetailHeader';
|
||||||
|
import {
|
||||||
|
TicketOverviewCardSkeleton,
|
||||||
|
TicketOverviewHeaderSkeleton,
|
||||||
|
} from './components/TicketOverviewSkeleton';
|
||||||
|
import {
|
||||||
|
TicketClassActionsSkeleton,
|
||||||
|
TicketClassContentSkeleton,
|
||||||
|
} from './components/TicketClassDetailSkeleton';
|
||||||
|
|
||||||
import { TicketHistoryCard } from './components/TicketHistoryCard';
|
import { TicketHistoryCard } from './components/TicketHistoryCard';
|
||||||
import { TicketOverviewCard } from './components/TicketOverviewCard';
|
import { TicketOverviewCard } from './components/TicketOverviewCard';
|
||||||
import { TicketRepairReportCard } from './components/TicketRepairReportCard';
|
|
||||||
import { TicketStatusActions } from './components/TicketStatusActions';
|
import { TicketStatusActions } from './components/TicketStatusActions';
|
||||||
|
import { TicketDefectClassTabs } from './components/TicketDefectClassTabs';
|
||||||
import { useTicketDetailEvents } from '../hooks/useTicketDetailEvents';
|
import { useTicketDetailEvents } from '../hooks/useTicketDetailEvents';
|
||||||
import { useTicketDetailQuery } from '../hooks/useTicketQueries';
|
import {
|
||||||
|
useTicketClassDetailQuery,
|
||||||
|
useTicketOverviewQuery,
|
||||||
|
} from '../hooks/useTicketQueries';
|
||||||
|
|
||||||
export default function TicketDetailPage() {
|
export default function TicketDetailPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
const { ticketId } = useParams() as { ticketId: string };
|
const { ticketId } = useParams() as { ticketId: string };
|
||||||
|
const defectClass = searchParams.get('defect_class') ?? undefined;
|
||||||
|
|
||||||
const ticketQuery = useTicketDetailQuery(ticketId);
|
const overviewQuery = useTicketOverviewQuery(ticketId);
|
||||||
const ticket = ticketQuery.data;
|
const classDetailQuery = useTicketClassDetailQuery(ticketId, defectClass);
|
||||||
|
const overview = overviewQuery.data;
|
||||||
const liveState = useTicketDetailEvents(
|
const classDetail = classDetailQuery.data;
|
||||||
ticketId,
|
const isClassDetailLoading = Boolean(
|
||||||
Boolean(ticketId && ticket && ticket.status !== 'closed'),
|
defectClass && classDetailQuery.isLoading,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (ticketQuery.isLoading) {
|
useTicketDetailEvents(ticketId, defectClass, Boolean(ticketId));
|
||||||
return (
|
|
||||||
<div className="flex min-h-[60vh] items-center justify-center">
|
|
||||||
<Loader2 className="size-8 animate-spin text-primary" />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ticketQuery.isError || !ticket) {
|
if (overviewQuery.isError) {
|
||||||
return (
|
return (
|
||||||
<div className="flex min-h-[60vh] flex-col items-center justify-center gap-3">
|
<div className="flex min-h-[60vh] flex-col items-center justify-center gap-3">
|
||||||
<p className="text-sm text-destructive">Failed to load ticket.</p>
|
<p className="text-sm text-destructive">Failed to load ticket.</p>
|
||||||
@@ -52,17 +59,31 @@ export default function TicketDetailPage() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="relative z-10 space-y-5">
|
<main className="relative z-10 space-y-5">
|
||||||
<TicketDetailHeader ticket={ticket} />
|
{overview ? (
|
||||||
|
<TicketDetailHeader ticket={overview} />
|
||||||
|
) : (
|
||||||
|
<TicketOverviewHeaderSkeleton />
|
||||||
|
)}
|
||||||
|
|
||||||
<div className="grid gap-5 xl:grid-cols-[minmax(0,7fr)_minmax(0,3fr)]">
|
<div className="grid gap-5 xl:grid-cols-[minmax(0,7fr)_minmax(0,3fr)]">
|
||||||
<div className="space-y-5">
|
<div className="space-y-5">
|
||||||
<TicketOverviewCard ticket={ticket} />
|
{overview ? (
|
||||||
<TicketRepairReportCard ticket={ticket} />
|
<TicketOverviewCard ticket={overview} />
|
||||||
<TicketHistoryCard ticket={ticket} />
|
) : (
|
||||||
|
<TicketOverviewCardSkeleton />
|
||||||
|
)}
|
||||||
|
<TicketDefectClassTabs ticketId={ticketId} ticket={overview} />
|
||||||
|
{isClassDetailLoading ? <TicketClassContentSkeleton /> : null}
|
||||||
|
{!isClassDetailLoading && classDetail ? (
|
||||||
|
<TicketHistoryCard ticket={classDetail} />
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div className="space-y-3 self-start">
|
||||||
<TicketStatusActions ticket={ticket} liveState={liveState} />
|
{isClassDetailLoading ? <TicketClassActionsSkeleton /> : null}
|
||||||
|
{!isClassDetailLoading && classDetail ? (
|
||||||
|
<TicketStatusActions ticket={classDetail} />
|
||||||
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -5,26 +5,19 @@ import type { ColumnDef } from '@tanstack/react-table';
|
|||||||
|
|
||||||
import type { TicketListItem } from '@/types';
|
import type { TicketListItem } from '@/types';
|
||||||
|
|
||||||
import { TicketStatusBadge } from './TicketStatusBadge';
|
|
||||||
import { formatDate } from '@/utils/date';
|
import { formatDate } from '@/utils/date';
|
||||||
|
|
||||||
export function useTicketColumns(): ColumnDef<TicketListItem>[] {
|
export function useTicketColumns(): ColumnDef<TicketListItem>[] {
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
accessorKey: 'id',
|
accessorKey: 'ticket_name',
|
||||||
header: 'Ticket',
|
header: 'Ticket',
|
||||||
size: 180,
|
size: 180,
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<span className="font-medium">{row.original.id}</span>
|
<span className="font-medium">{row.original.ticket_name}</span>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
accessorKey: 'status',
|
|
||||||
header: 'Status',
|
|
||||||
size: 150,
|
|
||||||
cell: ({ row }) => <TicketStatusBadge status={row.original.status} />,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
accessorKey: 'chainage_name',
|
accessorKey: 'chainage_name',
|
||||||
header: 'Segment',
|
header: 'Segment',
|
||||||
@@ -37,16 +30,21 @@ export function useTicketColumns(): ColumnDef<TicketListItem>[] {
|
|||||||
size: 120,
|
size: 120,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'assigned_to_name',
|
id: 'created_by',
|
||||||
header: 'Assigned To',
|
|
||||||
size: 220,
|
|
||||||
cell: ({ row }) => row.original.assigned_to_name || 'N/A',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'created_by_name',
|
|
||||||
header: 'Uploaded By',
|
header: 'Uploaded By',
|
||||||
size: 220,
|
size: 220,
|
||||||
cell: ({ row }) => row.original.created_by_name || 'N/A',
|
cell: ({ row }) => (
|
||||||
|
<div>
|
||||||
|
<p className="font-medium">
|
||||||
|
{row.original.created_by_name || 'N/A'}
|
||||||
|
</p>
|
||||||
|
{row.original.created_by_email ? (
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{row.original.created_by_email}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'updated_at',
|
accessorKey: 'updated_at',
|
||||||
|
|||||||
@@ -1,60 +1,19 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { SegmentSelect } from '@/components/lookups/SegmentSelect';
|
import { SegmentSelect } from '@/components/lookups/SegmentSelect';
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from '@/components/ui/select';
|
|
||||||
import type { TicketStatus } from '@/types';
|
|
||||||
|
|
||||||
import { formatTicketStatus } from './TicketStatusBadge';
|
|
||||||
|
|
||||||
const ticketStatuses: TicketStatus[] = [
|
|
||||||
'processing',
|
|
||||||
'unassigned',
|
|
||||||
'assigned',
|
|
||||||
'under_review',
|
|
||||||
'closed',
|
|
||||||
];
|
|
||||||
|
|
||||||
interface TicketFiltersProps {
|
interface TicketFiltersProps {
|
||||||
status: TicketStatus | 'all';
|
|
||||||
segmentId: string;
|
segmentId: string;
|
||||||
onStatusChange: (status: TicketStatus | 'all') => void;
|
|
||||||
onSegmentChange: (segmentId: string) => void;
|
onSegmentChange: (segmentId: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function TicketFilters({
|
export function TicketFilters({
|
||||||
status,
|
|
||||||
segmentId,
|
segmentId,
|
||||||
onStatusChange,
|
|
||||||
onSegmentChange,
|
onSegmentChange,
|
||||||
}: TicketFiltersProps) {
|
}: TicketFiltersProps) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-2 sm:flex-row sm:items-center">
|
<div className="w-full sm:w-64">
|
||||||
<Select
|
<SegmentSelect value={segmentId} onValueChange={onSegmentChange} />
|
||||||
value={status}
|
|
||||||
onValueChange={(value) => onStatusChange(value as TicketStatus | 'all')}
|
|
||||||
>
|
|
||||||
<SelectTrigger className="w-full sm:w-48">
|
|
||||||
<SelectValue placeholder="Status" />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
<SelectItem value="all">All statuses</SelectItem>
|
|
||||||
{ticketStatuses.map((item) => (
|
|
||||||
<SelectItem key={item} value={item}>
|
|
||||||
{formatTicketStatus(item)}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
|
|
||||||
<div className="w-full sm:w-64">
|
|
||||||
<SegmentSelect value={segmentId} onValueChange={onSegmentChange} />
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import { cn } from '@/lib/utils';
|
|||||||
import type { TicketStatus } from '@/types';
|
import type { TicketStatus } from '@/types';
|
||||||
|
|
||||||
const statusClasses: Record<TicketStatus, string> = {
|
const statusClasses: Record<TicketStatus, string> = {
|
||||||
processing: 'bg-sky-100 text-sky-700 border-sky-200',
|
|
||||||
unassigned: 'bg-amber-100 text-amber-800 border-amber-200',
|
unassigned: 'bg-amber-100 text-amber-800 border-amber-200',
|
||||||
assigned: 'bg-indigo-100 text-indigo-700 border-indigo-200',
|
assigned: 'bg-indigo-100 text-indigo-700 border-indigo-200',
|
||||||
under_review: 'bg-violet-100 text-violet-700 border-violet-200',
|
under_review: 'bg-violet-100 text-violet-700 border-violet-200',
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import type { ReactNode } from 'react';
|
import type { ReactNode } from 'react';
|
||||||
import type { ColumnDef } from '@tanstack/react-table';
|
import type { ColumnDef } from '@tanstack/react-table';
|
||||||
import { Eye } from 'lucide-react';
|
|
||||||
|
|
||||||
import { DataTable } from '@/components/data-table';
|
import { DataTable } from '@/components/data-table';
|
||||||
import type { TicketListItem } from '@/types';
|
import type { TicketListItem } from '@/types';
|
||||||
@@ -40,14 +39,7 @@ export function TicketTable({
|
|||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
toolbar={toolbar}
|
toolbar={toolbar}
|
||||||
emptyTitle="No tickets found."
|
emptyTitle="No tickets found."
|
||||||
emptyDescription="Ticket rows will appear after video processing creates them."
|
emptyDescription="Tickets will appear when road issues are detected."
|
||||||
actions={[
|
|
||||||
{
|
|
||||||
label: 'View',
|
|
||||||
icon: <Eye className="size-4" />,
|
|
||||||
onClick: onView,
|
|
||||||
},
|
|
||||||
]}
|
|
||||||
pagination={{
|
pagination={{
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
@@ -56,7 +48,6 @@ export function TicketTable({
|
|||||||
onLimitChange,
|
onLimitChange,
|
||||||
}}
|
}}
|
||||||
onRowClick={onView}
|
onRowClick={onView}
|
||||||
actionsSticky
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ function shouldCountCreatedTicket(
|
|||||||
event: TicketTableStatusEvent,
|
event: TicketTableStatusEvent,
|
||||||
params?: TicketListParams,
|
params?: TicketListParams,
|
||||||
) {
|
) {
|
||||||
if (params?.status && event.status !== params.status) return false;
|
|
||||||
if (params?.chainage_id && event.chainage_id !== params.chainage_id) {
|
if (params?.chainage_id && event.chainage_id !== params.chainage_id) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -86,7 +85,7 @@ function buildTicketListItem(
|
|||||||
): TicketListItem | null {
|
): TicketListItem | null {
|
||||||
if (
|
if (
|
||||||
!event.id ||
|
!event.id ||
|
||||||
!event.status ||
|
!event.ticket_name ||
|
||||||
event.detection_count === undefined ||
|
event.detection_count === undefined ||
|
||||||
!event.updated_at
|
!event.updated_at
|
||||||
) {
|
) {
|
||||||
@@ -95,12 +94,13 @@ function buildTicketListItem(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
id: event.id,
|
id: event.id,
|
||||||
|
ticket_name: event.ticket_name,
|
||||||
chainage_id: event.chainage_id ?? null,
|
chainage_id: event.chainage_id ?? null,
|
||||||
chainage_name: event.chainage_name ?? null,
|
chainage_name: event.chainage_name ?? null,
|
||||||
status: event.status,
|
default_defect_class: event.default_defect_class ?? null,
|
||||||
assigned_to_name: event.assigned_to_name ?? null,
|
|
||||||
detection_count: event.detection_count,
|
detection_count: event.detection_count,
|
||||||
created_by_name: event.created_by_name ?? null,
|
created_by_name: event.created_by_name ?? null,
|
||||||
|
created_by_email: event.created_by_email ?? null,
|
||||||
created_at: event.created_at ?? event.updated_at,
|
created_at: event.created_at ?? event.updated_at,
|
||||||
updated_at: event.updated_at,
|
updated_at: event.updated_at,
|
||||||
};
|
};
|
||||||
@@ -112,12 +112,14 @@ function mergeTicketListItem(
|
|||||||
): TicketListItem {
|
): TicketListItem {
|
||||||
return {
|
return {
|
||||||
...current,
|
...current,
|
||||||
|
ticket_name: event.ticket_name ?? current.ticket_name,
|
||||||
chainage_id: event.chainage_id ?? current.chainage_id,
|
chainage_id: event.chainage_id ?? current.chainage_id,
|
||||||
chainage_name: event.chainage_name ?? current.chainage_name,
|
chainage_name: event.chainage_name ?? current.chainage_name,
|
||||||
status: event.status ?? current.status,
|
default_defect_class:
|
||||||
assigned_to_name: event.assigned_to_name ?? current.assigned_to_name,
|
event.default_defect_class ?? current.default_defect_class,
|
||||||
detection_count: event.detection_count ?? current.detection_count,
|
detection_count: event.detection_count ?? current.detection_count,
|
||||||
created_by_name: event.created_by_name ?? current.created_by_name,
|
created_by_name: event.created_by_name ?? current.created_by_name,
|
||||||
|
created_by_email: event.created_by_email ?? current.created_by_email,
|
||||||
created_at: event.created_at ?? current.created_at,
|
created_at: event.created_at ?? current.created_at,
|
||||||
updated_at: event.updated_at ?? current.updated_at,
|
updated_at: event.updated_at ?? current.updated_at,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,29 +1,15 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
import { API_ROUTES } from '@/constants/apiRoutes';
|
import { API_ROUTES } from '@/constants/apiRoutes';
|
||||||
import { useSseWithToken } from '@/hooks/sse/useSseWithToken';
|
import { useSseWithToken } from '@/hooks/sse/useSseWithToken';
|
||||||
import { ticketService } from '@/services/api';
|
import { ticketService } from '@/services/api';
|
||||||
import type {
|
import type { TicketDetailStatusEvent } from '@/types';
|
||||||
TicketDetailStatusEvent,
|
|
||||||
TicketProgressEvent,
|
|
||||||
TicketStreamErrorEvent,
|
|
||||||
} from '@/types';
|
|
||||||
|
|
||||||
import { ticketKeys } from '../queries/ticketKeys';
|
import { ticketKeys } from '../queries/ticketKeys';
|
||||||
|
|
||||||
export interface TicketProcessingProgress {
|
|
||||||
progress: number;
|
|
||||||
message: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface TicketDetailLiveState {
|
|
||||||
progress: TicketProcessingProgress | null;
|
|
||||||
errorMessage: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const TICKET_DETAIL_RECONNECT_EVENTS = ['error'] as const;
|
const TICKET_DETAIL_RECONNECT_EVENTS = ['error'] as const;
|
||||||
|
|
||||||
function isHeartbeatEvent(event: { type?: string } | null | undefined) {
|
function isHeartbeatEvent(event: { type?: string } | null | undefined) {
|
||||||
@@ -32,18 +18,28 @@ function isHeartbeatEvent(event: { type?: string } | null | undefined) {
|
|||||||
|
|
||||||
export function useTicketDetailEvents(
|
export function useTicketDetailEvents(
|
||||||
ticketId: string | undefined,
|
ticketId: string | undefined,
|
||||||
|
defectClass: string | undefined,
|
||||||
enabled = true,
|
enabled = true,
|
||||||
): TicketDetailLiveState {
|
): void {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [progress, setProgress] = useState<TicketProcessingProgress | null>(
|
const defectClassRef = useRef(defectClass);
|
||||||
null,
|
|
||||||
);
|
useEffect(() => {
|
||||||
const [errorMessage, setErrorMessage] = useState<string | null>(null);
|
defectClassRef.current = defectClass;
|
||||||
|
}, [defectClass]);
|
||||||
|
|
||||||
const refetchTicket = useCallback(() => {
|
const refetchTicket = useCallback(() => {
|
||||||
if (!ticketId) return;
|
if (!ticketId) return;
|
||||||
|
|
||||||
queryClient.refetchQueries({ queryKey: ticketKeys.detail(ticketId) });
|
queryClient.refetchQueries({ queryKey: ticketKeys.overview(ticketId) });
|
||||||
|
if (defectClassRef.current) {
|
||||||
|
queryClient.refetchQueries({
|
||||||
|
queryKey: ticketKeys.classDetail(ticketId, defectClassRef.current),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.defectClasses(ticketId),
|
||||||
|
});
|
||||||
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
||||||
}, [queryClient, ticketId]);
|
}, [queryClient, ticketId]);
|
||||||
|
|
||||||
@@ -64,56 +60,17 @@ export function useTicketDetailEvents(
|
|||||||
if (isHeartbeatEvent(event)) return;
|
if (isHeartbeatEvent(event)) return;
|
||||||
refetchTicket();
|
refetchTicket();
|
||||||
},
|
},
|
||||||
progress: (event: TicketProgressEvent) => {
|
error: () => undefined,
|
||||||
setErrorMessage(null);
|
|
||||||
setProgress({
|
|
||||||
progress: event.progress,
|
|
||||||
message: event.message,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
complete: (event: TicketProgressEvent) => {
|
|
||||||
setErrorMessage(null);
|
|
||||||
setProgress({
|
|
||||||
progress: 100,
|
|
||||||
message: event.message,
|
|
||||||
});
|
|
||||||
refetchTicket();
|
|
||||||
},
|
|
||||||
error: (event: TicketStreamErrorEvent) => {
|
|
||||||
setErrorMessage(
|
|
||||||
event.message ?? 'Live ticket updates disconnected. Reconnecting...',
|
|
||||||
);
|
|
||||||
},
|
|
||||||
heartbeat: () => undefined,
|
heartbeat: () => undefined,
|
||||||
}),
|
}),
|
||||||
[refetchTicket],
|
[refetchTicket],
|
||||||
);
|
);
|
||||||
|
|
||||||
const shouldStop = useCallback(
|
|
||||||
(eventName: keyof typeof events, event: unknown) =>
|
|
||||||
eventName === 'ticket_status' &&
|
|
||||||
(event as TicketDetailStatusEvent).status === 'closed',
|
|
||||||
[],
|
|
||||||
);
|
|
||||||
|
|
||||||
const onConnectionError = useCallback(() => {
|
|
||||||
setErrorMessage('Live ticket updates disconnected. Reconnecting...');
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setProgress(null);
|
|
||||||
setErrorMessage(null);
|
|
||||||
}, [ticketId]);
|
|
||||||
|
|
||||||
useSseWithToken({
|
useSseWithToken({
|
||||||
enabled: Boolean(enabled && ticketId),
|
enabled: Boolean(enabled && ticketId),
|
||||||
getToken,
|
getToken,
|
||||||
getPath,
|
getPath,
|
||||||
events,
|
events,
|
||||||
reconnectOnEvents: TICKET_DETAIL_RECONNECT_EVENTS,
|
reconnectOnEvents: TICKET_DETAIL_RECONNECT_EVENTS,
|
||||||
shouldStop,
|
|
||||||
onConnectionError,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return { progress, errorMessage };
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,19 @@ import { useMemo } from 'react';
|
|||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
import { ticketService } from '@/services/api';
|
import { detectionService, ticketService, videoService } from '@/services/api';
|
||||||
import type {
|
import type {
|
||||||
AssignTicketPayload,
|
AssignTicketPayload,
|
||||||
|
CloseTicketPayload,
|
||||||
|
DiscardDetectionPayload,
|
||||||
|
RequestTicketExtensionPayload,
|
||||||
|
ReviewTicketExtensionPayload,
|
||||||
ReviewRepairPayload,
|
ReviewRepairPayload,
|
||||||
SubmitRepairPayload,
|
SubmitRepairPayload,
|
||||||
SubmitRepairUploadPayload,
|
SubmitRepairUploadPayload,
|
||||||
TicketDetail,
|
TicketDetail,
|
||||||
TicketListParams,
|
TicketListParams,
|
||||||
TicketStatus,
|
VideoDetectionsParams,
|
||||||
} from '@/types';
|
} from '@/types';
|
||||||
|
|
||||||
import { ticketKeys } from '../queries/ticketKeys';
|
import { ticketKeys } from '../queries/ticketKeys';
|
||||||
@@ -22,29 +26,26 @@ const TICKET_TABLE_REFRESH_MS = 5 * 60 * 1000;
|
|||||||
interface UseTicketsQueryParams {
|
interface UseTicketsQueryParams {
|
||||||
skip: number;
|
skip: number;
|
||||||
limit: number;
|
limit: number;
|
||||||
status?: TicketStatus | 'all';
|
|
||||||
chainageId?: string;
|
chainageId?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildTicketListParams({
|
function buildTicketListParams({
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
status,
|
|
||||||
chainageId,
|
chainageId,
|
||||||
}: UseTicketsQueryParams): TicketListParams {
|
}: UseTicketsQueryParams): TicketListParams {
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
status: status === 'all' ? undefined : status,
|
|
||||||
chainage_id: chainageId || undefined,
|
chainage_id: chainageId || undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTicketsQuery(params: UseTicketsQueryParams) {
|
export function useTicketsQuery(params: UseTicketsQueryParams) {
|
||||||
const { skip, limit, status, chainageId } = params;
|
const { skip, limit, chainageId } = params;
|
||||||
const listParams = useMemo(
|
const listParams = useMemo(
|
||||||
() => buildTicketListParams({ skip, limit, status, chainageId }),
|
() => buildTicketListParams({ skip, limit, chainageId }),
|
||||||
[chainageId, limit, skip, status],
|
[chainageId, limit, skip],
|
||||||
);
|
);
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
@@ -55,14 +56,123 @@ export function useTicketsQuery(params: UseTicketsQueryParams) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTicketDetailQuery(ticketId: string | undefined) {
|
export function useTicketOverviewQuery(ticketId: string | undefined) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ticketKeys.detail(ticketId ?? ''),
|
queryKey: ticketKeys.overview(ticketId ?? ''),
|
||||||
queryFn: () => ticketService.getTicketDetail(ticketId as string),
|
queryFn: () => ticketService.getTicketOverview(ticketId as string),
|
||||||
enabled: Boolean(ticketId),
|
enabled: Boolean(ticketId),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useTicketClassDetailQuery(
|
||||||
|
ticketId: string | undefined,
|
||||||
|
defectClass: string | undefined,
|
||||||
|
) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ticketKeys.classDetail(ticketId ?? '', defectClass ?? ''),
|
||||||
|
queryFn: () =>
|
||||||
|
ticketService.getTicketClassDetail(
|
||||||
|
ticketId as string,
|
||||||
|
defectClass as string,
|
||||||
|
),
|
||||||
|
enabled: Boolean(ticketId && defectClass),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useTicketDefectClassesQuery(ticketId: string | undefined) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ticketKeys.defectClasses(ticketId ?? ''),
|
||||||
|
queryFn: () => ticketService.getTicketDefectClasses(ticketId as string),
|
||||||
|
enabled: Boolean(ticketId),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useTicketClassDetectionsQuery(
|
||||||
|
videoId: string | undefined,
|
||||||
|
params: VideoDetectionsParams,
|
||||||
|
) {
|
||||||
|
const queryParams = useMemo(
|
||||||
|
() => ({
|
||||||
|
skip: params.skip ?? 0,
|
||||||
|
limit: params.limit ?? 1,
|
||||||
|
class_name: params.class_name,
|
||||||
|
min_confidence: params.min_confidence,
|
||||||
|
sort: params.sort ?? 'timestamp_asc',
|
||||||
|
search: params.search,
|
||||||
|
}),
|
||||||
|
[
|
||||||
|
params.class_name,
|
||||||
|
params.limit,
|
||||||
|
params.min_confidence,
|
||||||
|
params.search,
|
||||||
|
params.skip,
|
||||||
|
params.sort,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ticketKeys.classDetections(videoId ?? '', queryParams),
|
||||||
|
queryFn: () =>
|
||||||
|
videoService.getVideoDetections(videoId as string, queryParams),
|
||||||
|
enabled: Boolean(videoId && queryParams.class_name),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useDiscardDetectionMutation(
|
||||||
|
ticketId: string,
|
||||||
|
videoId: string | undefined,
|
||||||
|
defectClass: string,
|
||||||
|
) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({
|
||||||
|
detectionId,
|
||||||
|
payload,
|
||||||
|
}: {
|
||||||
|
detectionId: number;
|
||||||
|
payload: DiscardDetectionPayload;
|
||||||
|
}) => detectionService.discardDetection(detectionId, payload),
|
||||||
|
onSuccess: async () => {
|
||||||
|
toast.success('Detection discarded');
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
videoId
|
||||||
|
? queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.classDetectionLists(videoId),
|
||||||
|
})
|
||||||
|
: Promise.resolve(),
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.overview(ticketId),
|
||||||
|
}),
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.classDetail(ticketId, defectClass),
|
||||||
|
}),
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.defectClasses(ticketId),
|
||||||
|
}),
|
||||||
|
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() }),
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
onError: () => toast.error('Failed to discard detection'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useTicketExtensionRequestQuery(
|
||||||
|
ticketId: string | undefined,
|
||||||
|
assignmentId: number | undefined,
|
||||||
|
) {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ticketKeys.extensionRequest(ticketId ?? '', assignmentId),
|
||||||
|
queryFn: () =>
|
||||||
|
ticketService.getTicketExtensionRequest(
|
||||||
|
ticketId as string,
|
||||||
|
assignmentId as number,
|
||||||
|
),
|
||||||
|
enabled: Boolean(ticketId && assignmentId),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function useAssignableTicketUsersQuery(enabled: boolean) {
|
export function useAssignableTicketUsersQuery(enabled: boolean) {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ticketKeys.assignableUsers(),
|
queryKey: ticketKeys.assignableUsers(),
|
||||||
@@ -90,10 +200,10 @@ export function useAssignTicketMutation(ticketId: string) {
|
|||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload: AssignTicketPayload) =>
|
mutationFn: (payload: AssignTicketPayload) =>
|
||||||
ticketService.assignTicket(ticketId, payload),
|
ticketService.assignTicket(ticketId, payload),
|
||||||
onSuccess: (ticket) => {
|
onSuccess: (ticket, payload) => {
|
||||||
toast.success('Ticket assigned');
|
toast.success('Ticket assigned');
|
||||||
queryClient.setQueryData<TicketDetail>(
|
queryClient.setQueryData<TicketDetail>(
|
||||||
ticketKeys.detail(ticketId),
|
ticketKeys.classDetail(ticketId, payload.defect_class),
|
||||||
(current) => mergeTicketDetailResponse(current, ticket),
|
(current) => mergeTicketDetailResponse(current, ticket),
|
||||||
);
|
);
|
||||||
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
||||||
@@ -102,23 +212,6 @@ export function useAssignTicketMutation(ticketId: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useStartTicketMutation(ticketId: string) {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
return useMutation({
|
|
||||||
mutationFn: () => ticketService.startTicket(ticketId),
|
|
||||||
onSuccess: (ticket) => {
|
|
||||||
toast.success('Ticket started');
|
|
||||||
queryClient.setQueryData<TicketDetail>(
|
|
||||||
ticketKeys.detail(ticketId),
|
|
||||||
(current) => mergeTicketDetailResponse(current, ticket),
|
|
||||||
);
|
|
||||||
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
|
||||||
},
|
|
||||||
onError: () => toast.error('Failed to start ticket'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useSubmitRepairMutation(ticketId: string) {
|
export function useSubmitRepairMutation(ticketId: string) {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
@@ -128,7 +221,7 @@ export function useSubmitRepairMutation(ticketId: string) {
|
|||||||
onSuccess: (ticket) => {
|
onSuccess: (ticket) => {
|
||||||
toast.success('Repair submitted');
|
toast.success('Repair submitted');
|
||||||
queryClient.setQueryData<TicketDetail>(
|
queryClient.setQueryData<TicketDetail>(
|
||||||
ticketKeys.detail(ticketId),
|
ticketKeys.classDetail(ticketId, ticket.defect_class),
|
||||||
(current) => mergeTicketDetailResponse(current, ticket),
|
(current) => mergeTicketDetailResponse(current, ticket),
|
||||||
);
|
);
|
||||||
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
||||||
@@ -143,10 +236,10 @@ export function useSubmitRepairUploadMutation(ticketId: string) {
|
|||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: (payload: SubmitRepairUploadPayload) =>
|
mutationFn: (payload: SubmitRepairUploadPayload) =>
|
||||||
ticketService.submitRepairUpload(ticketId, payload),
|
ticketService.submitRepairUpload(ticketId, payload),
|
||||||
onSuccess: (ticket) => {
|
onSuccess: (ticket, payload) => {
|
||||||
toast.success('Repair evidence uploaded');
|
toast.success('Repair evidence uploaded');
|
||||||
queryClient.setQueryData<TicketDetail>(
|
queryClient.setQueryData<TicketDetail>(
|
||||||
ticketKeys.detail(ticketId),
|
ticketKeys.classDetail(ticketId, payload.defect_class),
|
||||||
(current) => mergeTicketDetailResponse(current, ticket),
|
(current) => mergeTicketDetailResponse(current, ticket),
|
||||||
);
|
);
|
||||||
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
||||||
@@ -155,6 +248,64 @@ export function useSubmitRepairUploadMutation(ticketId: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useRequestTicketExtensionMutation(
|
||||||
|
ticketId: string,
|
||||||
|
assignmentId: number | undefined,
|
||||||
|
defectClass: string,
|
||||||
|
) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (payload: RequestTicketExtensionPayload) => {
|
||||||
|
if (assignmentId === undefined) {
|
||||||
|
throw new Error('No active assignment is available for this ticket.');
|
||||||
|
}
|
||||||
|
return ticketService.requestTicketExtension(
|
||||||
|
ticketId,
|
||||||
|
assignmentId,
|
||||||
|
payload,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
toast.success('Extension request submitted');
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.extensionRequest(ticketId, assignmentId),
|
||||||
|
});
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.classDetail(ticketId, defectClass),
|
||||||
|
});
|
||||||
|
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
||||||
|
},
|
||||||
|
onError: () => toast.error('Failed to request an extension'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export function useReviewTicketExtensionMutation(
|
||||||
|
ticketId: string,
|
||||||
|
assignmentId: number,
|
||||||
|
defectClass: string,
|
||||||
|
) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (payload: ReviewTicketExtensionPayload) =>
|
||||||
|
ticketService.reviewTicketExtension(ticketId, assignmentId, payload),
|
||||||
|
onSuccess: (_response, payload) => {
|
||||||
|
toast.success(
|
||||||
|
payload.action === 'approve'
|
||||||
|
? 'Extension request approved'
|
||||||
|
: 'Extension request rejected',
|
||||||
|
);
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.extensionRequest(ticketId, assignmentId),
|
||||||
|
});
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.classDetail(ticketId, defectClass),
|
||||||
|
});
|
||||||
|
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
||||||
|
},
|
||||||
|
onError: () => toast.error('Failed to review extension request'),
|
||||||
|
});
|
||||||
|
}
|
||||||
export function useReviewRepairMutation(ticketId: string) {
|
export function useReviewRepairMutation(ticketId: string) {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
@@ -166,7 +317,7 @@ export function useReviewRepairMutation(ticketId: string) {
|
|||||||
payload.action === 'approve' ? 'Repair approved' : 'Repair rejected',
|
payload.action === 'approve' ? 'Repair approved' : 'Repair rejected',
|
||||||
);
|
);
|
||||||
queryClient.setQueryData<TicketDetail>(
|
queryClient.setQueryData<TicketDetail>(
|
||||||
ticketKeys.detail(ticketId),
|
ticketKeys.classDetail(ticketId, payload.defect_class),
|
||||||
(current) => mergeTicketDetailResponse(current, ticket),
|
(current) => mergeTicketDetailResponse(current, ticket),
|
||||||
);
|
);
|
||||||
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
||||||
@@ -179,11 +330,12 @@ export function useCloseTicketMutation(ticketId: string) {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation({
|
return useMutation({
|
||||||
mutationFn: () => ticketService.closeTicket(ticketId),
|
mutationFn: (payload: CloseTicketPayload) =>
|
||||||
onSuccess: (ticket) => {
|
ticketService.closeTicket(ticketId, payload),
|
||||||
|
onSuccess: (ticket, payload) => {
|
||||||
toast.success('Ticket closed');
|
toast.success('Ticket closed');
|
||||||
queryClient.setQueryData<TicketDetail>(
|
queryClient.setQueryData<TicketDetail>(
|
||||||
ticketKeys.detail(ticketId),
|
ticketKeys.classDetail(ticketId, payload.defect_class),
|
||||||
(current) => mergeTicketDetailResponse(current, ticket),
|
(current) => mergeTicketDetailResponse(current, ticket),
|
||||||
);
|
);
|
||||||
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { useCallback, useMemo, useState } from 'react';
|
|||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { PageHeader } from '@/components/page-header';
|
import { PageHeader } from '@/components/page-header';
|
||||||
import { Ticket } from 'lucide-react';
|
import { Ticket } from 'lucide-react';
|
||||||
import type { TicketListItem, TicketStatus } from '@/types';
|
import type { TicketListItem } from '@/types';
|
||||||
|
|
||||||
import { TicketFilters } from './components/TicketFilters';
|
import { TicketFilters } from './components/TicketFilters';
|
||||||
import { TicketTable } from './components/TicketTable';
|
import { TicketTable } from './components/TicketTable';
|
||||||
@@ -16,7 +16,6 @@ export default function TicketPage() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [skip, setSkip] = useState(0);
|
const [skip, setSkip] = useState(0);
|
||||||
const [limit, setLimit] = useState(10);
|
const [limit, setLimit] = useState(10);
|
||||||
const [status, setStatus] = useState<TicketStatus | 'all'>('all');
|
|
||||||
const [segmentId, setSegmentId] = useState('');
|
const [segmentId, setSegmentId] = useState('');
|
||||||
|
|
||||||
useTenantTicketTableEvents();
|
useTenantTicketTableEvents();
|
||||||
@@ -24,7 +23,6 @@ export default function TicketPage() {
|
|||||||
const ticketsQuery = useTicketsQuery({
|
const ticketsQuery = useTicketsQuery({
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
status,
|
|
||||||
chainageId: segmentId,
|
chainageId: segmentId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -32,11 +30,6 @@ export default function TicketPage() {
|
|||||||
const tickets = ticketsQuery.data?.items ?? [];
|
const tickets = ticketsQuery.data?.items ?? [];
|
||||||
const total = ticketsQuery.data?.total ?? 0;
|
const total = ticketsQuery.data?.total ?? 0;
|
||||||
|
|
||||||
const handleStatusChange = useCallback((nextStatus: TicketStatus | 'all') => {
|
|
||||||
setStatus(nextStatus);
|
|
||||||
setSkip(0);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleSegmentChange = useCallback((nextSegmentId: string) => {
|
const handleSegmentChange = useCallback((nextSegmentId: string) => {
|
||||||
setSegmentId(nextSegmentId);
|
setSegmentId(nextSegmentId);
|
||||||
setSkip(0);
|
setSkip(0);
|
||||||
@@ -44,7 +37,11 @@ export default function TicketPage() {
|
|||||||
|
|
||||||
const handleView = useCallback(
|
const handleView = useCallback(
|
||||||
(ticket: TicketListItem) => {
|
(ticket: TicketListItem) => {
|
||||||
router.push(`/ticket/${ticket.id}`);
|
const defectClassQuery = ticket.default_defect_class
|
||||||
|
? `?defect_class=${encodeURIComponent(ticket.default_defect_class)}`
|
||||||
|
: '';
|
||||||
|
|
||||||
|
router.push(`/ticket/${ticket.id}${defectClassQuery}`);
|
||||||
},
|
},
|
||||||
[router],
|
[router],
|
||||||
);
|
);
|
||||||
@@ -52,13 +49,11 @@ export default function TicketPage() {
|
|||||||
const toolbar = useMemo(
|
const toolbar = useMemo(
|
||||||
() => (
|
() => (
|
||||||
<TicketFilters
|
<TicketFilters
|
||||||
status={status}
|
|
||||||
segmentId={segmentId}
|
segmentId={segmentId}
|
||||||
onStatusChange={handleStatusChange}
|
|
||||||
onSegmentChange={handleSegmentChange}
|
onSegmentChange={handleSegmentChange}
|
||||||
/>
|
/>
|
||||||
),
|
),
|
||||||
[handleSegmentChange, handleStatusChange, segmentId, status],
|
[handleSegmentChange, segmentId],
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,10 +1,27 @@
|
|||||||
import type { TicketListParams } from '@/types';
|
import type { TicketListParams, VideoDetectionsParams } from '@/types';
|
||||||
|
|
||||||
export const ticketKeys = {
|
export const ticketKeys = {
|
||||||
all: ['tickets'] as const,
|
all: ['tickets'] as const,
|
||||||
lists: () => [...ticketKeys.all, 'list'] as const,
|
lists: () => [...ticketKeys.all, 'list'] as const,
|
||||||
list: (params: TicketListParams) => [...ticketKeys.lists(), params] as const,
|
list: (params: TicketListParams) => [...ticketKeys.lists(), params] as const,
|
||||||
details: () => [...ticketKeys.all, 'detail'] as const,
|
details: () => [...ticketKeys.all, 'detail'] as const,
|
||||||
detail: (ticketId: string) => [...ticketKeys.details(), ticketId] as const,
|
overview: (ticketId: string) =>
|
||||||
|
[...ticketKeys.details(), ticketId, 'overview'] as const,
|
||||||
|
classDetail: (ticketId: string, defectClass: string) =>
|
||||||
|
[...ticketKeys.details(), ticketId, 'class', defectClass] as const,
|
||||||
|
classDetectionLists: (videoId: string) =>
|
||||||
|
[...ticketKeys.details(), 'video', videoId, 'detections'] as const,
|
||||||
|
classDetections: (videoId: string, params: VideoDetectionsParams) =>
|
||||||
|
[...ticketKeys.classDetectionLists(videoId), params] as const,
|
||||||
|
defectClasses: (ticketId: string) =>
|
||||||
|
[...ticketKeys.details(), ticketId, 'defect-classes'] as const,
|
||||||
|
extensionRequest: (ticketId: string, assignmentId: number | undefined) =>
|
||||||
|
[
|
||||||
|
...ticketKeys.details(),
|
||||||
|
ticketId,
|
||||||
|
'assignments',
|
||||||
|
assignmentId,
|
||||||
|
'extension-request',
|
||||||
|
] as const,
|
||||||
assignableUsers: () => [...ticketKeys.all, 'assignable-users'] as const,
|
assignableUsers: () => [...ticketKeys.all, 'assignable-users'] as const,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,79 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from '@/components/ui/select';
|
|
||||||
|
|
||||||
const pageSizes = [10, 20, 40, 50, 100];
|
|
||||||
|
|
||||||
interface CardPaginationProps {
|
|
||||||
skip: number;
|
|
||||||
limit: number;
|
|
||||||
total: number;
|
|
||||||
count: number;
|
|
||||||
onPageChange: (skip: number) => void;
|
|
||||||
onLimitChange: (limit: number) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function CardPagination({
|
|
||||||
skip,
|
|
||||||
limit,
|
|
||||||
total,
|
|
||||||
count,
|
|
||||||
onPageChange,
|
|
||||||
onLimitChange,
|
|
||||||
}: CardPaginationProps) {
|
|
||||||
return (
|
|
||||||
<div className="flex flex-col gap-3 text-sm text-muted-foreground md:flex-row md:items-center md:justify-between">
|
|
||||||
<div className="flex flex-wrap items-center gap-3">
|
|
||||||
<span>Showing {count} of {total}</span>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span>Rows per page</span>
|
|
||||||
<Select
|
|
||||||
value={String(limit)}
|
|
||||||
onValueChange={(value) => onLimitChange(Number(value))}
|
|
||||||
>
|
|
||||||
<SelectTrigger className="h-8 w-18 bg-background">
|
|
||||||
<SelectValue />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{pageSizes.map((size) => (
|
|
||||||
<SelectItem key={size} value={String(size)}>
|
|
||||||
{size}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
disabled={skip === 0}
|
|
||||||
onClick={() => onPageChange(Math.max(0, skip - limit))}
|
|
||||||
>
|
|
||||||
<ChevronLeft className="size-4" />
|
|
||||||
Previous
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="sm"
|
|
||||||
disabled={skip + limit >= total}
|
|
||||||
onClick={() => onPageChange(skip + limit)}
|
|
||||||
>
|
|
||||||
Next
|
|
||||||
<ChevronRight className="size-4" />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -6,6 +6,7 @@ import { Loader2, Play } from 'lucide-react';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
@@ -89,19 +90,17 @@ export function CreateUploadDialog({
|
|||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={handleOpenChange}>
|
<Dialog open={open} onOpenChange={handleOpenChange}>
|
||||||
<DialogContent
|
<DialogContent
|
||||||
className="flex max-h-[calc(100vh-2rem)] flex-col gap-0 p-0 sm:max-w-5xl"
|
className="sm:max-w-5xl"
|
||||||
onOpenAutoFocus={(event) => event.preventDefault()}
|
onOpenAutoFocus={(event) => event.preventDefault()}
|
||||||
>
|
>
|
||||||
<DialogHeader className="shrink-0 border-b px-6 py-4 pr-12">
|
<DialogHeader>
|
||||||
<DialogTitle className="text-lg leading-none font-semibold tracking-tight">
|
<DialogTitle>Upload Video</DialogTitle>
|
||||||
Upload Video
|
|
||||||
</DialogTitle>
|
|
||||||
<DialogDescription>
|
<DialogDescription>
|
||||||
Configure location and upload road inspection data.
|
Configure location and upload road inspection data.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<div className="min-h-0 flex-1 space-y-5 overflow-y-auto px-6 py-4">
|
<DialogBody className="space-y-5">
|
||||||
<LocationSection
|
<LocationSection
|
||||||
value={session}
|
value={session}
|
||||||
onChange={setSession}
|
onChange={setSession}
|
||||||
@@ -130,13 +129,13 @@ export function CreateUploadDialog({
|
|||||||
portalContainer={dropdownPortalRef}
|
portalContainer={dropdownPortalRef}
|
||||||
/>
|
/>
|
||||||
{error ? (
|
{error ? (
|
||||||
<div className="rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
<div className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
||||||
{error}
|
{error}
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</DialogBody>
|
||||||
|
|
||||||
<DialogFooter className="shrink-0 border-t px-6 py-4">
|
<DialogFooter>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { Loader2 } from 'lucide-react';
|
|
||||||
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { useAnnotatedVideoQuery } from '@/app/(modules)/results/hooks/useVideoResults';
|
|
||||||
import type { UploadVideo } from '@/types';
|
|
||||||
|
|
||||||
interface ProcessedVideoDialogProps {
|
|
||||||
upload: UploadVideo | null;
|
|
||||||
open: boolean;
|
|
||||||
onOpenChange: (open: boolean) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ProcessedVideoDialog({
|
|
||||||
upload,
|
|
||||||
open,
|
|
||||||
onOpenChange,
|
|
||||||
}: ProcessedVideoDialogProps) {
|
|
||||||
const { videoUrl, isLoading, isError } = useAnnotatedVideoQuery(
|
|
||||||
open ? upload?.processed_video_url ?? undefined : undefined,
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
||||||
<DialogContent className="sm:max-w-4xl">
|
|
||||||
<DialogHeader>
|
|
||||||
<DialogTitle>{upload?.filename ?? 'Processed Video'}</DialogTitle>
|
|
||||||
<DialogDescription>Processed video preview</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<div className="flex aspect-video items-center justify-center overflow-hidden rounded-md border bg-muted/30">
|
|
||||||
{isLoading ? (
|
|
||||||
<Loader2 className="size-6 animate-spin text-primary" />
|
|
||||||
) : isError || !videoUrl ? (
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
Processed video is not available.
|
|
||||||
</p>
|
|
||||||
) : (
|
|
||||||
<video src={videoUrl} controls className="h-full w-full" />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,27 +1,37 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Eye, MoreVertical, PlayCircle } from 'lucide-react';
|
import { useRouter } from 'next/navigation';
|
||||||
|
import {
|
||||||
|
Download,
|
||||||
|
Eye,
|
||||||
|
MoreVertical,
|
||||||
|
PlayCircle,
|
||||||
|
RotateCcw,
|
||||||
|
Ticket,
|
||||||
|
Trash2,
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
DropdownMenuItem,
|
DropdownMenuItem,
|
||||||
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from '@/components/ui/dropdown-menu';
|
} from '@/components/ui/dropdown-menu';
|
||||||
import type { UploadVideo } from '@/types';
|
import type { UploadListItem } from '@/types';
|
||||||
|
|
||||||
interface UploadActionsMenuProps {
|
interface UploadActionsMenuProps {
|
||||||
upload: UploadVideo;
|
upload: UploadListItem;
|
||||||
onViewDetails: (upload: UploadVideo) => void;
|
onViewVideo: (upload: UploadListItem) => void;
|
||||||
onViewProcessedVideo: (upload: UploadVideo) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function UploadActionsMenu({
|
export function UploadActionsMenu({
|
||||||
upload,
|
upload,
|
||||||
onViewDetails,
|
onViewVideo,
|
||||||
onViewProcessedVideo,
|
|
||||||
}: UploadActionsMenuProps) {
|
}: UploadActionsMenuProps) {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
@@ -37,16 +47,38 @@ export function UploadActionsMenu({
|
|||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
<DropdownMenuItem onClick={() => onViewDetails(upload)}>
|
{upload.raw_video_url ? (
|
||||||
<Eye className="size-4" />
|
<DropdownMenuItem
|
||||||
View Details
|
onClick={(event) => {
|
||||||
</DropdownMenuItem>
|
event.stopPropagation();
|
||||||
{upload.processed_video_url ? (
|
onViewVideo(upload);
|
||||||
<DropdownMenuItem onClick={() => onViewProcessedVideo(upload)}>
|
}}
|
||||||
|
>
|
||||||
<PlayCircle className="size-4" />
|
<PlayCircle className="size-4" />
|
||||||
View Processed Video
|
View Video
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
) : null}
|
) : null}
|
||||||
|
<DropdownMenuItem>
|
||||||
|
<Eye /> View Details
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem>
|
||||||
|
<RotateCcw /> Retry Analysis
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
disabled={!upload.ticket_id}
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
if (upload.ticket_id) {
|
||||||
|
router.push(`/ticket/${upload.ticket_id}`);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Ticket /> Open Ticket
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
<DropdownMenuItem variant="destructive">
|
||||||
|
<Trash2 /> Delete
|
||||||
|
</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,107 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { FileVideo } from 'lucide-react';
|
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Card, CardContent } from '@/components/ui/card';
|
|
||||||
import type { UploadVideo } from '@/types';
|
|
||||||
|
|
||||||
import { CardPagination } from './CardPagination';
|
|
||||||
import { UploadActionsMenu } from './UploadActionsMenu';
|
|
||||||
import { UploadThumbnail } from './UploadThumbnail';
|
|
||||||
import { formatUploadedAt } from './uploadUtils';
|
|
||||||
|
|
||||||
interface UploadCardGridProps {
|
|
||||||
uploads: UploadVideo[];
|
|
||||||
isLoading: boolean;
|
|
||||||
skip: number;
|
|
||||||
limit: number;
|
|
||||||
total: number;
|
|
||||||
onPageChange: (skip: number) => void;
|
|
||||||
onLimitChange: (limit: number) => void;
|
|
||||||
onUploadNew: () => void;
|
|
||||||
onOpenUpload: (upload: UploadVideo) => void;
|
|
||||||
onViewDetails: (upload: UploadVideo) => void;
|
|
||||||
onViewProcessedVideo: (upload: UploadVideo) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function UploadCardGrid({
|
|
||||||
uploads,
|
|
||||||
isLoading,
|
|
||||||
skip,
|
|
||||||
limit,
|
|
||||||
total,
|
|
||||||
onPageChange,
|
|
||||||
onLimitChange,
|
|
||||||
onUploadNew,
|
|
||||||
onOpenUpload,
|
|
||||||
onViewDetails,
|
|
||||||
onViewProcessedVideo,
|
|
||||||
}: UploadCardGridProps) {
|
|
||||||
const skeletonItems = Array.from({ length: Math.min(limit, 20) });
|
|
||||||
|
|
||||||
if (!isLoading && uploads.length === 0) {
|
|
||||||
return (
|
|
||||||
<Card>
|
|
||||||
<CardContent className="flex min-h-80 flex-col items-center justify-center gap-3 text-center">
|
|
||||||
<div className="flex size-12 items-center justify-center rounded-md border bg-muted/40">
|
|
||||||
<FileVideo className="size-6 text-muted-foreground" />
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<h2 className="text-base">No uploads found</h2>
|
|
||||||
<p className="text-sm text-muted-foreground">
|
|
||||||
Upload your first road inspection video.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<Button onClick={onUploadNew}>Upload New</Button>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<section className="space-y-4">
|
|
||||||
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4 2xl:grid-cols-5">
|
|
||||||
{isLoading
|
|
||||||
? skeletonItems.map((_, index) => (
|
|
||||||
<Card key={index} className="h-62 animate-pulse bg-muted/30" />
|
|
||||||
))
|
|
||||||
: uploads.map((upload) => (
|
|
||||||
<Card
|
|
||||||
key={upload.video_id}
|
|
||||||
className="cursor-pointer overflow-hidden transition-colors hover:bg-muted/30"
|
|
||||||
onClick={() => onOpenUpload(upload)}
|
|
||||||
>
|
|
||||||
<CardContent className="space-y-3 p-3">
|
|
||||||
<UploadThumbnail upload={upload} />
|
|
||||||
<div className="flex items-start gap-2">
|
|
||||||
<div className="min-w-0 flex-1">
|
|
||||||
<p className="truncate text-sm font-medium">
|
|
||||||
{upload.filename}
|
|
||||||
</p>
|
|
||||||
<p className="text-xs text-muted-foreground">
|
|
||||||
Uploaded {formatUploadedAt(upload.uploaded_at)}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<UploadActionsMenu
|
|
||||||
upload={upload}
|
|
||||||
onViewDetails={onViewDetails}
|
|
||||||
onViewProcessedVideo={onViewProcessedVideo}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</CardContent>
|
|
||||||
</Card>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<CardPagination
|
|
||||||
skip={skip}
|
|
||||||
limit={limit}
|
|
||||||
total={total}
|
|
||||||
count={uploads.length}
|
|
||||||
onPageChange={onPageChange}
|
|
||||||
onLimitChange={onLimitChange}
|
|
||||||
/>
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,77 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useMemo } from 'react';
|
|
||||||
import type { ColumnDef } from '@tanstack/react-table';
|
|
||||||
|
|
||||||
import { UploadActionsMenu } from './UploadActionsMenu';
|
|
||||||
import { UploadThumbnail } from './UploadThumbnail';
|
|
||||||
import { formatUploadedAt, getUploadStatus } from './uploadUtils';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import type { UploadVideo } from '@/types';
|
|
||||||
|
|
||||||
interface UseUploadColumnsProps {
|
|
||||||
onViewDetails: (upload: UploadVideo) => void;
|
|
||||||
onViewProcessedVideo: (upload: UploadVideo) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useUploadColumns({
|
|
||||||
onViewDetails,
|
|
||||||
onViewProcessedVideo,
|
|
||||||
}: UseUploadColumnsProps) {
|
|
||||||
return useMemo<ColumnDef<UploadVideo>[]>(
|
|
||||||
() => [
|
|
||||||
{
|
|
||||||
id: 'thumbnail',
|
|
||||||
header: 'Thumbnail',
|
|
||||||
size: 140,
|
|
||||||
minSize: 120,
|
|
||||||
enableSorting: false,
|
|
||||||
meta: { disableTruncate: true },
|
|
||||||
cell: ({ row }) => (
|
|
||||||
<UploadThumbnail upload={row.original} className="w-28" />
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'filename',
|
|
||||||
header: 'Filename',
|
|
||||||
cell: ({ row }) => (
|
|
||||||
<span className="font-medium">{row.original.filename}</span>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'status',
|
|
||||||
header: 'Status',
|
|
||||||
size: 130,
|
|
||||||
cell: ({ row }) => (
|
|
||||||
<Badge className="rounded-full">
|
|
||||||
{getUploadStatus(row.original)}
|
|
||||||
</Badge>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
accessorKey: 'uploaded_at',
|
|
||||||
header: 'Uploaded At',
|
|
||||||
cell: ({ row }) => formatUploadedAt(row.original.uploaded_at),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 'actions',
|
|
||||||
header: () => <span className="sr-only">Actions</span>,
|
|
||||||
size: 56,
|
|
||||||
minSize: 56,
|
|
||||||
enableSorting: false,
|
|
||||||
enableHiding: false,
|
|
||||||
meta: { disableTruncate: true },
|
|
||||||
cell: ({ row }) => (
|
|
||||||
<div className="flex justify-center">
|
|
||||||
<UploadActionsMenu
|
|
||||||
upload={row.original}
|
|
||||||
onViewDetails={onViewDetails}
|
|
||||||
onViewProcessedVideo={onViewProcessedVideo}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
],
|
|
||||||
[onViewDetails, onViewProcessedVideo],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,79 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import {
|
|
||||||
Dialog,
|
|
||||||
DialogContent,
|
|
||||||
DialogDescription,
|
|
||||||
DialogHeader,
|
|
||||||
DialogTitle,
|
|
||||||
} from '@/components/ui/dialog';
|
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import {
|
|
||||||
Tooltip,
|
|
||||||
TooltipContent,
|
|
||||||
TooltipProvider,
|
|
||||||
TooltipTrigger,
|
|
||||||
} from '@/components/ui/tooltip';
|
|
||||||
import type { UploadVideo } from '@/types';
|
|
||||||
|
|
||||||
import { formatUploadedAt, getUploadStatus } from './uploadUtils';
|
|
||||||
|
|
||||||
interface UploadDetailsDialogProps {
|
|
||||||
upload: UploadVideo | null;
|
|
||||||
open: boolean;
|
|
||||||
onOpenChange: (open: boolean) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function UploadDetailsDialog({
|
|
||||||
upload,
|
|
||||||
open,
|
|
||||||
onOpenChange,
|
|
||||||
}: UploadDetailsDialogProps) {
|
|
||||||
const title = upload?.filename ?? 'Upload Details';
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
|
||||||
<DialogContent className="sm:max-w-lg">
|
|
||||||
<DialogHeader className="min-w-0 pr-8">
|
|
||||||
<DialogTitle className="min-w-0 max-w-full overflow-hidden text-left">
|
|
||||||
{upload?.filename ? (
|
|
||||||
<TooltipProvider delayDuration={200}>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<span
|
|
||||||
className="block w-full overflow-hidden text-ellipsis whitespace-nowrap"
|
|
||||||
title={title}
|
|
||||||
>
|
|
||||||
{title}
|
|
||||||
</span>
|
|
||||||
</TooltipTrigger>
|
|
||||||
<TooltipContent className="max-w-80 break-all">
|
|
||||||
{title}
|
|
||||||
</TooltipContent>
|
|
||||||
</Tooltip>
|
|
||||||
</TooltipProvider>
|
|
||||||
) : (
|
|
||||||
title
|
|
||||||
)}
|
|
||||||
</DialogTitle>
|
|
||||||
<DialogDescription>Uploaded video details</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
{upload ? (
|
|
||||||
<dl className="grid grid-cols-[120px_1fr] gap-x-4 gap-y-3 text-sm">
|
|
||||||
<dt className="text-muted-foreground">Status</dt>
|
|
||||||
<dd>
|
|
||||||
<Badge className="rounded-full">{getUploadStatus(upload)}</Badge>
|
|
||||||
</dd>
|
|
||||||
<dt className="text-muted-foreground">Uploaded At</dt>
|
|
||||||
<dd>{formatUploadedAt(upload.uploaded_at)}</dd>
|
|
||||||
<dt className="text-muted-foreground">Uploaded By</dt>
|
|
||||||
<dd>{upload.uploaded_by_email ?? '-'}</dd>
|
|
||||||
<dt className="text-muted-foreground">Video ID</dt>
|
|
||||||
<dd className="break-all font-mono text-xs">{upload.video_id}</dd>
|
|
||||||
</dl>
|
|
||||||
) : null}
|
|
||||||
</DialogContent>
|
|
||||||
</Dialog>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -56,7 +56,7 @@ export function UploadFileDropzone({
|
|||||||
handleFiles(event.dataTransfer.files);
|
handleFiles(event.dataTransfer.files);
|
||||||
}}
|
}}
|
||||||
className={cn(
|
className={cn(
|
||||||
'group flex min-h-32 cursor-pointer flex-col justify-between rounded-md border border-dashed bg-card/60 p-4 transition-colors',
|
'group flex min-h-32 cursor-pointer flex-col justify-between rounded-lg border border-dashed bg-card/60 p-4 transition-colors',
|
||||||
'hover:border-primary/60 hover:bg-secondary/40',
|
'hover:border-primary/60 hover:bg-secondary/40',
|
||||||
isDragging && 'border-primary bg-secondary/60',
|
isDragging && 'border-primary bg-secondary/60',
|
||||||
disabled && 'pointer-events-none cursor-not-allowed opacity-60',
|
disabled && 'pointer-events-none cursor-not-allowed opacity-60',
|
||||||
@@ -72,7 +72,7 @@ export function UploadFileDropzone({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="space-y-3">
|
<div className="space-y-3">
|
||||||
<div className="flex size-9 items-center justify-center rounded-md border bg-background">
|
<div className="flex size-9 items-center justify-center rounded-lg border bg-background">
|
||||||
<UploadCloud className="size-4 text-muted-foreground" />
|
<UploadCloud className="size-4 text-muted-foreground" />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
156
src/app/(modules)/upload/components/UploadListColumns.tsx
Normal file
156
src/app/(modules)/upload/components/UploadListColumns.tsx
Normal file
@@ -0,0 +1,156 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useMemo } from 'react';
|
||||||
|
import type { ColumnDef } from '@tanstack/react-table';
|
||||||
|
import { Video } from 'lucide-react';
|
||||||
|
|
||||||
|
import { ENV_CONSTANT } from '@/constants/secrect.constant';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import type { UploadListItem } from '@/types';
|
||||||
|
import { formatDate } from '@/utils/date';
|
||||||
|
|
||||||
|
import { UploadActionsMenu } from './UploadActionsMenu';
|
||||||
|
import { UploadResultCell } from './UploadResultCell';
|
||||||
|
import { UploadStatusBadge } from './UploadStatusBadge';
|
||||||
|
|
||||||
|
function resolveThumbnailUrl(value: string | null) {
|
||||||
|
if (!value) return null;
|
||||||
|
if (/^https?:\/\//i.test(value)) return value;
|
||||||
|
|
||||||
|
const baseUrl = ENV_CONSTANT.BASE_API_URL?.replace(/\/$/, '');
|
||||||
|
const path = value.startsWith('/') ? value : `/${value}`;
|
||||||
|
return baseUrl ? `${baseUrl}${path}` : path;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUploadListColumns(
|
||||||
|
onViewVideo: (upload: UploadListItem) => void,
|
||||||
|
): ColumnDef<UploadListItem>[] {
|
||||||
|
return useMemo(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
id: 'thumbnail',
|
||||||
|
header: 'Thumbnail',
|
||||||
|
size: 104,
|
||||||
|
minSize: 96,
|
||||||
|
enableSorting: false,
|
||||||
|
meta: { disableTruncate: true },
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const thumbnail = resolveThumbnailUrl(row.original.thumbnail);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className="flex aspect-video w-20 items-center justify-center overflow-hidden rounded-lg border bg-muted bg-cover bg-center"
|
||||||
|
style={
|
||||||
|
thumbnail
|
||||||
|
? { backgroundImage: `url("${thumbnail}")` }
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
|
role={thumbnail ? 'img' : undefined}
|
||||||
|
aria-label={thumbnail ? 'Upload thumbnail' : undefined}
|
||||||
|
>
|
||||||
|
{!thumbnail ? (
|
||||||
|
<Video className="size-5 text-muted-foreground" />
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'uploaded_by',
|
||||||
|
header: 'Uploader',
|
||||||
|
size: 190,
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div>
|
||||||
|
<p className="font-medium">
|
||||||
|
{row.original.uploaded_by.name ?? '—'}
|
||||||
|
</p>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{row.original.uploaded_by.email ?? '—'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'project',
|
||||||
|
header: 'Project',
|
||||||
|
size: 165,
|
||||||
|
cell: ({ row }) => row.original.project ?? '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'package',
|
||||||
|
header: 'Package',
|
||||||
|
size: 110,
|
||||||
|
cell: ({ row }) => row.original.package ?? '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'segment',
|
||||||
|
header: 'Segment',
|
||||||
|
size: 140,
|
||||||
|
cell: ({ row }) => row.original.segment ?? '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'chainage',
|
||||||
|
header: 'Chainage',
|
||||||
|
size: 155,
|
||||||
|
cell: ({ row }) => row.original.chainage ?? '—',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'uploaded_at',
|
||||||
|
header: 'Uploaded At',
|
||||||
|
size: 175,
|
||||||
|
cell: ({ row }) => formatDate(row.original.uploaded_at),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
accessorKey: 'is_uploaded',
|
||||||
|
header: 'Upload Status',
|
||||||
|
size: 125,
|
||||||
|
meta: { disableTruncate: true },
|
||||||
|
cell: ({ row }) =>
|
||||||
|
row.original.is_uploaded ? (
|
||||||
|
<Badge className="bg-emerald-500/15 text-emerald-600 dark:text-emerald-400">
|
||||||
|
Uploaded
|
||||||
|
</Badge>
|
||||||
|
) : (
|
||||||
|
<span className="text-muted-foreground">—</span>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'status',
|
||||||
|
header: 'Analysis Status',
|
||||||
|
size: 145,
|
||||||
|
meta: { disableTruncate: true },
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<UploadStatusBadge
|
||||||
|
status={row.original.status}
|
||||||
|
progress={row.original.progress}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'result',
|
||||||
|
header: 'Result',
|
||||||
|
size: 170,
|
||||||
|
meta: { disableTruncate: true },
|
||||||
|
cell: ({ row }) => <UploadResultCell item={row.original} />,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'actions',
|
||||||
|
header: () => <span className="sr-only">Actions</span>,
|
||||||
|
size: 64,
|
||||||
|
minSize: 64,
|
||||||
|
enableSorting: false,
|
||||||
|
enableHiding: false,
|
||||||
|
meta: { disableTruncate: true },
|
||||||
|
cell: ({ row }) => (
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<UploadActionsMenu
|
||||||
|
upload={row.original}
|
||||||
|
onViewVideo={onViewVideo}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
[onViewVideo],
|
||||||
|
);
|
||||||
|
}
|
||||||
46
src/app/(modules)/upload/components/UploadResultCell.tsx
Normal file
46
src/app/(modules)/upload/components/UploadResultCell.tsx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { CircleMinus, CircleX, TicketCheck } from 'lucide-react';
|
||||||
|
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import type { UploadListItem } from '@/types';
|
||||||
|
|
||||||
|
export function UploadResultCell({ item }: { item: UploadListItem }) {
|
||||||
|
if (item.result === 'ticket_created') {
|
||||||
|
return (
|
||||||
|
<div className="space-y-1">
|
||||||
|
<Badge className="bg-violet-500/15 text-violet-600 dark:text-violet-400">
|
||||||
|
<TicketCheck /> Ticket Created
|
||||||
|
</Badge>
|
||||||
|
<p className="text-xs font-medium">
|
||||||
|
{item.ticket_name ?? item.ticket_id}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.result === 'analysis_failed') {
|
||||||
|
return (
|
||||||
|
<div className="space-y-1 text-red-600 dark:text-red-400">
|
||||||
|
<div className="flex items-center gap-1.5 text-xs font-medium">
|
||||||
|
<CircleX className="size-3.5" /> Analysis Failed
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{item.error_message ?? 'Processing failed'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.result === 'no_defects_found') {
|
||||||
|
return (
|
||||||
|
<div className="space-y-1">
|
||||||
|
<div className="flex items-center gap-1.5 text-xs font-medium text-amber-500">
|
||||||
|
<CircleMinus className="size-3.5" /> No Defects Found
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-muted-foreground">
|
||||||
|
{item.total_detections ?? 0} issues detected
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return <span className="text-muted-foreground">—</span>;
|
||||||
|
}
|
||||||
65
src/app/(modules)/upload/components/UploadStatusBadge.tsx
Normal file
65
src/app/(modules)/upload/components/UploadStatusBadge.tsx
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import { CheckCircle2, Clock3, LoaderCircle, XCircle } from 'lucide-react';
|
||||||
|
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Progress } from '@/components/ui/progress';
|
||||||
|
import type { UploadStatus } from '@/types';
|
||||||
|
|
||||||
|
interface UploadStatusBadgeProps {
|
||||||
|
status: UploadStatus;
|
||||||
|
progress: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const statusConfig = {
|
||||||
|
queued: {
|
||||||
|
label: 'Queued',
|
||||||
|
icon: Clock3,
|
||||||
|
className: 'bg-zinc-500/15 text-zinc-500 dark:text-zinc-300',
|
||||||
|
},
|
||||||
|
processing: {
|
||||||
|
label: 'Processing',
|
||||||
|
icon: LoaderCircle,
|
||||||
|
className: 'bg-blue-500/15 text-blue-600 dark:text-blue-400',
|
||||||
|
},
|
||||||
|
completed: {
|
||||||
|
label: 'Completed',
|
||||||
|
icon: CheckCircle2,
|
||||||
|
className: 'bg-emerald-500/15 text-emerald-600 dark:text-emerald-400',
|
||||||
|
},
|
||||||
|
failed: {
|
||||||
|
label: 'Failed',
|
||||||
|
icon: XCircle,
|
||||||
|
className: 'bg-red-500/15 text-red-600 dark:text-red-400',
|
||||||
|
},
|
||||||
|
} satisfies Record<
|
||||||
|
UploadStatus,
|
||||||
|
{ label: string; icon: typeof Clock3; className: string }
|
||||||
|
>;
|
||||||
|
|
||||||
|
export function UploadStatusBadge({
|
||||||
|
status,
|
||||||
|
progress,
|
||||||
|
}: UploadStatusBadgeProps) {
|
||||||
|
const config = statusConfig[status];
|
||||||
|
const Icon = config.icon;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Badge variant="secondary" className={config.className}>
|
||||||
|
<Icon
|
||||||
|
className={status === 'processing' ? 'animate-spin' : undefined}
|
||||||
|
/>
|
||||||
|
{config.label}
|
||||||
|
</Badge>
|
||||||
|
{status === 'processing' ? (
|
||||||
|
<div className="w-24 space-y-1">
|
||||||
|
<span className="text-xs text-muted-foreground">
|
||||||
|
{progress}% complete
|
||||||
|
</span>
|
||||||
|
<Progress value={progress} className="h-1.5" />
|
||||||
|
</div>
|
||||||
|
) : status === 'completed' ? (
|
||||||
|
<p className="text-xs text-muted-foreground">100%</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -3,18 +3,17 @@
|
|||||||
import type { ColumnDef } from '@tanstack/react-table';
|
import type { ColumnDef } from '@tanstack/react-table';
|
||||||
|
|
||||||
import { DataTable } from '@/components/data-table';
|
import { DataTable } from '@/components/data-table';
|
||||||
import type { UploadVideo } from '@/types';
|
import type { UploadListItem } from '@/types';
|
||||||
|
|
||||||
interface UploadTableProps {
|
interface UploadTableProps {
|
||||||
columns: ColumnDef<UploadVideo>[];
|
columns: ColumnDef<UploadListItem>[];
|
||||||
uploads: UploadVideo[];
|
uploads: UploadListItem[];
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
skip: number;
|
skip: number;
|
||||||
limit: number;
|
limit: number;
|
||||||
total: number;
|
total: number;
|
||||||
onPageChange: (skip: number) => void;
|
onPageChange: (skip: number) => void;
|
||||||
onLimitChange: (limit: number) => void;
|
onLimitChange: (limit: number) => void;
|
||||||
onRowClick: (upload: UploadVideo) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function UploadTable({
|
export function UploadTable({
|
||||||
@@ -26,7 +25,6 @@ export function UploadTable({
|
|||||||
total,
|
total,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onLimitChange,
|
onLimitChange,
|
||||||
onRowClick,
|
|
||||||
}: UploadTableProps) {
|
}: UploadTableProps) {
|
||||||
return (
|
return (
|
||||||
<DataTable
|
<DataTable
|
||||||
@@ -42,7 +40,6 @@ export function UploadTable({
|
|||||||
onPageChange,
|
onPageChange,
|
||||||
onLimitChange,
|
onLimitChange,
|
||||||
}}
|
}}
|
||||||
onRowClick={onRowClick}
|
|
||||||
enableColumnControls={false}
|
enableColumnControls={false}
|
||||||
minColumnSize={120}
|
minColumnSize={120}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,33 +0,0 @@
|
|||||||
import { ImageIcon } from 'lucide-react';
|
|
||||||
|
|
||||||
import type { UploadVideo } from '@/types';
|
|
||||||
|
|
||||||
import { resolveMediaUrl } from './uploadUtils';
|
|
||||||
|
|
||||||
interface UploadThumbnailProps {
|
|
||||||
upload: UploadVideo;
|
|
||||||
className?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function UploadThumbnail({ upload, className }: UploadThumbnailProps) {
|
|
||||||
const thumbnailUrl = resolveMediaUrl(upload.thumbnail);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className={className}>
|
|
||||||
<div className="aspect-video overflow-hidden rounded-md border bg-muted/40">
|
|
||||||
{thumbnailUrl ? (
|
|
||||||
<img
|
|
||||||
src={thumbnailUrl}
|
|
||||||
alt={upload.filename}
|
|
||||||
loading="lazy"
|
|
||||||
className="h-full w-full object-cover"
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<div className="flex h-full w-full items-center justify-center text-muted-foreground">
|
|
||||||
<ImageIcon className="size-8" />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
41
src/app/(modules)/upload/components/VideoPreviewDialog.tsx
Normal file
41
src/app/(modules)/upload/components/VideoPreviewDialog.tsx
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { ProtectedVideoPlayer } from '@/components/media/ProtectedVideoPlayer';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
|
DialogContent,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from '@/components/ui/dialog';
|
||||||
|
import type { UploadListItem } from '@/types';
|
||||||
|
|
||||||
|
interface VideoPreviewDialogProps {
|
||||||
|
upload: UploadListItem | null;
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function VideoPreviewDialog({
|
||||||
|
upload,
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
}: VideoPreviewDialogProps) {
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-5xl">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Video Preview</DialogTitle>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<DialogBody>
|
||||||
|
<ProtectedVideoPlayer
|
||||||
|
url={open ? upload?.raw_video_url : undefined}
|
||||||
|
className="rounded-lg"
|
||||||
|
unavailableTitle="Video preview unavailable"
|
||||||
|
/>
|
||||||
|
</DialogBody>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { Grid2X2, Table2 } from 'lucide-react';
|
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
import type { UploadViewMode } from '../hooks/useUploadFilters';
|
|
||||||
|
|
||||||
interface ViewSwitcherProps {
|
|
||||||
value: UploadViewMode;
|
|
||||||
onValueChange: (value: UploadViewMode) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function ViewSwitcher({ value, onValueChange }: ViewSwitcherProps) {
|
|
||||||
const items: Array<{
|
|
||||||
value: UploadViewMode;
|
|
||||||
label: string;
|
|
||||||
icon: React.ReactNode;
|
|
||||||
}> = [
|
|
||||||
{ value: 'card', label: 'Card View', icon: <Grid2X2 className="size-4" /> },
|
|
||||||
{ value: 'table', label: 'Table View', icon: <Table2 className="size-4" /> },
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="inline-flex rounded-md border bg-card p-1">
|
|
||||||
{items.map((item) => (
|
|
||||||
<Button
|
|
||||||
key={item.value}
|
|
||||||
type="button"
|
|
||||||
variant="ghost"
|
|
||||||
size="sm"
|
|
||||||
onClick={() => onValueChange(item.value)}
|
|
||||||
className={cn(
|
|
||||||
'gap-2',
|
|
||||||
value === item.value && 'bg-secondary text-foreground',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{item.icon}
|
|
||||||
{item.label}
|
|
||||||
</Button>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
import { ENV_CONSTANT } from '@/constants/secrect.constant';
|
|
||||||
import type { UploadVideo } from '@/types';
|
|
||||||
|
|
||||||
export function getUploadStatus(upload: UploadVideo) {
|
|
||||||
return upload.status?.status || 'unknown';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function formatUploadedAt(value: string) {
|
|
||||||
const date = new Date(value);
|
|
||||||
if (Number.isNaN(date.getTime())) return '-';
|
|
||||||
|
|
||||||
return new Intl.DateTimeFormat('en-IN', {
|
|
||||||
day: '2-digit',
|
|
||||||
month: 'short',
|
|
||||||
year: 'numeric',
|
|
||||||
hour: 'numeric',
|
|
||||||
minute: '2-digit',
|
|
||||||
}).format(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function resolveMediaUrl(url?: string | null) {
|
|
||||||
if (!url) return null;
|
|
||||||
if (/^https?:\/\//i.test(url)) return url;
|
|
||||||
|
|
||||||
const baseUrl = ENV_CONSTANT.BASE_API_URL?.replace(/\/$/, '');
|
|
||||||
const path = url.startsWith('/') ? url : `/${url}`;
|
|
||||||
return baseUrl ? `${baseUrl}${path}` : path;
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -2,14 +2,11 @@
|
|||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
export type UploadViewMode = 'card' | 'table';
|
|
||||||
|
|
||||||
const DEFAULT_LIMIT = 20;
|
const DEFAULT_LIMIT = 20;
|
||||||
|
|
||||||
export function useUploadFilters() {
|
export function useUploadFilters() {
|
||||||
const [skip, setSkip] = useState(0);
|
const [skip, setSkip] = useState(0);
|
||||||
const [limit, setLimitValue] = useState(DEFAULT_LIMIT);
|
const [limit, setLimitValue] = useState(DEFAULT_LIMIT);
|
||||||
const [viewMode, setViewMode] = useState<UploadViewMode>('card');
|
|
||||||
|
|
||||||
const setLimit = (nextLimit: number) => {
|
const setLimit = (nextLimit: number) => {
|
||||||
setLimitValue(nextLimit);
|
setLimitValue(nextLimit);
|
||||||
@@ -21,7 +18,5 @@ export function useUploadFilters() {
|
|||||||
setSkip,
|
setSkip,
|
||||||
limit,
|
limit,
|
||||||
setLimit,
|
setLimit,
|
||||||
viewMode,
|
|
||||||
setViewMode,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
112
src/app/(modules)/upload/hooks/useUploadListEvents.ts
Normal file
112
src/app/(modules)/upload/hooks/useUploadListEvents.ts
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useCallback, useMemo, useRef } from 'react';
|
||||||
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import { API_ROUTES } from '@/constants/apiRoutes';
|
||||||
|
import { useSseWithToken } from '@/hooks/sse/useSseWithToken';
|
||||||
|
import { videoService } from '@/services/api';
|
||||||
|
import type {
|
||||||
|
PaginationParams,
|
||||||
|
UploadListResponse,
|
||||||
|
UploadStatusEvent,
|
||||||
|
} from '@/types';
|
||||||
|
|
||||||
|
import { uploadKeys } from './useUploadQueries';
|
||||||
|
|
||||||
|
function getUploadListParams(queryKey: readonly unknown[]) {
|
||||||
|
const params = queryKey[2];
|
||||||
|
|
||||||
|
if (!params || typeof params !== 'object' || Array.isArray(params)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return params as PaginationParams;
|
||||||
|
}
|
||||||
|
|
||||||
|
function patchUploadList(
|
||||||
|
current: UploadListResponse | undefined,
|
||||||
|
event: UploadStatusEvent,
|
||||||
|
params?: PaginationParams,
|
||||||
|
) {
|
||||||
|
if (!current) return current;
|
||||||
|
|
||||||
|
const existingIndex = current.items.findIndex(
|
||||||
|
(upload) => upload.id === event.item.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (existingIndex >= 0) {
|
||||||
|
return {
|
||||||
|
...current,
|
||||||
|
items: current.items.map((upload) =>
|
||||||
|
upload.id === event.item.id ? event.item : upload,
|
||||||
|
),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.kind !== 'created') return current;
|
||||||
|
|
||||||
|
const nextTotal = current.total + 1;
|
||||||
|
if ((params?.skip ?? 0) !== 0) {
|
||||||
|
return { ...current, total: nextTotal };
|
||||||
|
}
|
||||||
|
|
||||||
|
const pageLimit = params?.limit ?? current.items.length + 1;
|
||||||
|
return {
|
||||||
|
items: [event.item, ...current.items].slice(0, pageLimit),
|
||||||
|
total: nextTotal,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUploadListEvents(enabled = true) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const hasInvalidatedAfterConnectionErrorRef = useRef(false);
|
||||||
|
|
||||||
|
const events = useMemo(
|
||||||
|
() => ({
|
||||||
|
upload_status: (event: UploadStatusEvent) => {
|
||||||
|
queryClient
|
||||||
|
.getQueryCache()
|
||||||
|
.findAll({ queryKey: uploadKeys.lists() })
|
||||||
|
.forEach((query) => {
|
||||||
|
queryClient.setQueryData<UploadListResponse>(
|
||||||
|
query.queryKey,
|
||||||
|
(current) =>
|
||||||
|
patchUploadList(
|
||||||
|
current,
|
||||||
|
event,
|
||||||
|
getUploadListParams(query.queryKey),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
heartbeat: () => undefined,
|
||||||
|
}),
|
||||||
|
[queryClient],
|
||||||
|
);
|
||||||
|
|
||||||
|
const getPath = useCallback(
|
||||||
|
(token: string) => API_ROUTES.VIDEOS.UPLOAD_EVENTS(token),
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
const onConnectionError = useCallback(() => {
|
||||||
|
if (hasInvalidatedAfterConnectionErrorRef.current) return;
|
||||||
|
|
||||||
|
hasInvalidatedAfterConnectionErrorRef.current = true;
|
||||||
|
queryClient.invalidateQueries({ queryKey: uploadKeys.lists() });
|
||||||
|
}, [queryClient]);
|
||||||
|
|
||||||
|
const onConnectionOpen = useCallback(() => {
|
||||||
|
hasInvalidatedAfterConnectionErrorRef.current = false;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useSseWithToken({
|
||||||
|
enabled,
|
||||||
|
getToken: videoService.createUploadEventsToken,
|
||||||
|
getPath,
|
||||||
|
events,
|
||||||
|
onConnectionError,
|
||||||
|
onConnectionOpen,
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ export const uploadKeys = {
|
|||||||
list: (params: PaginationParams) => [...uploadKeys.lists(), params] as const,
|
list: (params: PaginationParams) => [...uploadKeys.lists(), params] as const,
|
||||||
};
|
};
|
||||||
|
|
||||||
interface UseMyUploadsQueryParams {
|
interface UseUploadsQueryParams {
|
||||||
skip: number;
|
skip: number;
|
||||||
limit: number;
|
limit: number;
|
||||||
}
|
}
|
||||||
@@ -21,14 +21,14 @@ interface UseMyUploadsQueryParams {
|
|||||||
function buildUploadListParams({
|
function buildUploadListParams({
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
}: UseMyUploadsQueryParams): PaginationParams {
|
}: UseUploadsQueryParams): PaginationParams {
|
||||||
return {
|
return {
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useMyUploadsQuery(params: UseMyUploadsQueryParams) {
|
export function useUploadsQuery(params: UseUploadsQueryParams) {
|
||||||
const { skip, limit } = params;
|
const { skip, limit } = params;
|
||||||
const listParams = useMemo(
|
const listParams = useMemo(
|
||||||
() => buildUploadListParams({ skip, limit }),
|
() => buildUploadListParams({ skip, limit }),
|
||||||
@@ -37,7 +37,7 @@ export function useMyUploadsQuery(params: UseMyUploadsQueryParams) {
|
|||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: uploadKeys.list(listParams),
|
queryKey: uploadKeys.list(listParams),
|
||||||
queryFn: () => videoService.getMyUploads(listParams),
|
queryFn: () => videoService.getUploads(listParams),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,66 +1,39 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useCallback, useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { Plus, UploadCloud } from 'lucide-react';
|
import { Plus, UploadCloud } from 'lucide-react';
|
||||||
|
|
||||||
import { PageHeader } from '@/components/page-header';
|
import { PageHeader } from '@/components/page-header';
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import type { UploadVideo } from '@/types';
|
import type { UploadListItem } from '@/types';
|
||||||
|
|
||||||
import { CreateUploadDialog } from './components/CreateUploadDialog';
|
import { CreateUploadDialog } from './components/CreateUploadDialog';
|
||||||
import { ProcessedVideoDialog } from './components/ProcessedVideoDialog';
|
import { useUploadListColumns } from './components/UploadListColumns';
|
||||||
import { UploadCardGrid } from './components/UploadCardGrid';
|
|
||||||
import { useUploadColumns } from './components/UploadColumns';
|
|
||||||
import { UploadDetailsDialog } from './components/UploadDetailsDialog';
|
|
||||||
import { UploadTable } from './components/UploadTable';
|
import { UploadTable } from './components/UploadTable';
|
||||||
import { ViewSwitcher } from './components/ViewSwitcher';
|
import { VideoPreviewDialog } from './components/VideoPreviewDialog';
|
||||||
import { useUploadFilters } from './hooks/useUploadFilters';
|
import { useUploadFilters } from './hooks/useUploadFilters';
|
||||||
import { useMyUploadsQuery } from './hooks/useUploadQueries';
|
import { useUploadListEvents } from './hooks/useUploadListEvents';
|
||||||
|
import { useUploadsQuery } from './hooks/useUploadQueries';
|
||||||
|
|
||||||
export default function UploadPage() {
|
export default function UploadPage() {
|
||||||
const { skip, setSkip, limit, setLimit, viewMode, setViewMode } =
|
const { skip, setSkip, limit, setLimit } = useUploadFilters();
|
||||||
useUploadFilters();
|
const uploadsQuery = useUploadsQuery({ skip, limit });
|
||||||
const uploadsQuery = useMyUploadsQuery({ skip, limit });
|
useUploadListEvents();
|
||||||
const [isCreateOpen, setIsCreateOpen] = useState(false);
|
const [isCreateOpen, setIsCreateOpen] = useState(false);
|
||||||
const [detailsUpload, setDetailsUpload] = useState<UploadVideo | null>(null);
|
const [videoUpload, setVideoUpload] = useState<UploadListItem | null>(null);
|
||||||
const [processedUpload, setProcessedUpload] = useState<UploadVideo | null>(
|
|
||||||
null,
|
|
||||||
);
|
|
||||||
|
|
||||||
const uploads = uploadsQuery.data?.items ?? [];
|
const uploads = uploadsQuery.data?.items ?? [];
|
||||||
const total = uploadsQuery.data?.total ?? 0;
|
const total = uploadsQuery.data?.total ?? 0;
|
||||||
const isLoading = uploadsQuery.isLoading;
|
const isLoading = uploadsQuery.isLoading;
|
||||||
|
|
||||||
const handleViewDetails = useCallback((upload: UploadVideo) => {
|
const columns = useUploadListColumns(setVideoUpload);
|
||||||
setDetailsUpload(upload);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleViewProcessedVideo = useCallback((upload: UploadVideo) => {
|
|
||||||
setProcessedUpload(upload);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleOpenUpload = useCallback(
|
|
||||||
(upload: UploadVideo) => {
|
|
||||||
if (upload.processed_video_url) {
|
|
||||||
handleViewProcessedVideo(upload);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
handleViewDetails(upload);
|
|
||||||
},
|
|
||||||
[handleViewDetails, handleViewProcessedVideo],
|
|
||||||
);
|
|
||||||
|
|
||||||
const columns = useUploadColumns({
|
|
||||||
onViewDetails: handleViewDetails,
|
|
||||||
onViewProcessedVideo: handleViewProcessedVideo,
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<main className="space-y-5">
|
<main className="space-y-5">
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title="My Uploads"
|
title="Uploads"
|
||||||
description="View and manage uploaded road inspection videos."
|
description="Track uploaded road inspection videos, processing progress, and results."
|
||||||
icon={UploadCloud}
|
icon={UploadCloud}
|
||||||
actions={
|
actions={
|
||||||
<Button onClick={() => setIsCreateOpen(true)} size="sm">
|
<Button onClick={() => setIsCreateOpen(true)} size="sm">
|
||||||
@@ -70,52 +43,24 @@ export default function UploadPage() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className="flex justify-end">
|
<UploadTable
|
||||||
<ViewSwitcher value={viewMode} onValueChange={setViewMode} />
|
columns={columns}
|
||||||
</div>
|
uploads={uploads}
|
||||||
|
isLoading={isLoading}
|
||||||
{viewMode === 'card' ? (
|
skip={skip}
|
||||||
<UploadCardGrid
|
limit={limit}
|
||||||
uploads={uploads}
|
total={total}
|
||||||
isLoading={isLoading}
|
onPageChange={setSkip}
|
||||||
skip={skip}
|
onLimitChange={setLimit}
|
||||||
limit={limit}
|
/>
|
||||||
total={total}
|
|
||||||
onPageChange={setSkip}
|
|
||||||
onLimitChange={setLimit}
|
|
||||||
onUploadNew={() => setIsCreateOpen(true)}
|
|
||||||
onOpenUpload={handleOpenUpload}
|
|
||||||
onViewDetails={handleViewDetails}
|
|
||||||
onViewProcessedVideo={handleViewProcessedVideo}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<UploadTable
|
|
||||||
columns={columns}
|
|
||||||
uploads={uploads}
|
|
||||||
isLoading={isLoading}
|
|
||||||
skip={skip}
|
|
||||||
limit={limit}
|
|
||||||
total={total}
|
|
||||||
onPageChange={setSkip}
|
|
||||||
onLimitChange={setLimit}
|
|
||||||
onRowClick={handleOpenUpload}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<CreateUploadDialog open={isCreateOpen} onOpenChange={setIsCreateOpen} />
|
<CreateUploadDialog open={isCreateOpen} onOpenChange={setIsCreateOpen} />
|
||||||
<UploadDetailsDialog
|
<VideoPreviewDialog
|
||||||
upload={detailsUpload}
|
upload={videoUpload}
|
||||||
open={Boolean(detailsUpload)}
|
open={Boolean(videoUpload)}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) setDetailsUpload(null);
|
if (!open) setVideoUpload(null);
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<ProcessedVideoDialog
|
|
||||||
upload={processedUpload}
|
|
||||||
open={Boolean(processedUpload)}
|
|
||||||
onOpenChange={(open) => {
|
|
||||||
if (!open) setProcessedUpload(null);
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { RoleSelect } from '@/components/lookups/RoleSelect';
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
DialogContent,
|
DialogContent,
|
||||||
DialogDescription,
|
DialogDescription,
|
||||||
DialogFooter,
|
DialogFooter,
|
||||||
@@ -67,13 +68,13 @@ export function UserSheet({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
<DialogContent className="flex max-h-[calc(100vh-2rem)] flex-col gap-0 p-0 sm:max-w-xl">
|
<DialogContent className="sm:max-w-xl">
|
||||||
<DialogHeader className="shrink-0 border-b px-6 py-4 pr-12">
|
<DialogHeader>
|
||||||
<DialogTitle className="text-lg leading-none font-semibold tracking-tight">
|
<DialogTitle>
|
||||||
{userId ? 'Edit User' : 'Create User'}
|
{userId ? 'Edit User' : 'Create User'}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
|
|
||||||
<DialogDescription className="text-sm">
|
<DialogDescription>
|
||||||
Assign user details and a role.
|
Assign user details and a role.
|
||||||
</DialogDescription>
|
</DialogDescription>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
@@ -83,7 +84,7 @@ export function UserSheet({
|
|||||||
onSubmit={onSubmit}
|
onSubmit={onSubmit}
|
||||||
className="flex min-h-0 flex-1 flex-col"
|
className="flex min-h-0 flex-1 flex-col"
|
||||||
>
|
>
|
||||||
<div className="max-h-[50vh] space-y-5 overflow-y-auto px-6 py-4">
|
<DialogBody className="space-y-5">
|
||||||
<div className="grid gap-4 md:grid-cols-2">
|
<div className="grid gap-4 md:grid-cols-2">
|
||||||
<FormField
|
<FormField
|
||||||
id="first-name"
|
id="first-name"
|
||||||
@@ -169,12 +170,12 @@ export function UserSheet({
|
|||||||
type="hidden"
|
type="hidden"
|
||||||
{...register('role_id')}
|
{...register('role_id')}
|
||||||
value={roleId}
|
value={roleId}
|
||||||
readOnly
|
readOnly
|
||||||
/>
|
/>
|
||||||
</FormField>
|
</FormField>
|
||||||
</div>
|
</DialogBody>
|
||||||
|
|
||||||
<DialogFooter className="shrink-0 border-t px-6 py-4">
|
<DialogFooter>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 3.7 KiB |
@@ -1,84 +1,86 @@
|
|||||||
@import 'tailwindcss';
|
@import 'tailwindcss';
|
||||||
@import 'tw-animate-css';
|
@import 'tw-animate-css';
|
||||||
@import './typography.css';
|
@import './typography.css';
|
||||||
|
@import "tw-animate-css";
|
||||||
|
@import "shadcn/tailwind.css";
|
||||||
|
|
||||||
@custom-variant dark (&:is(.dark *));
|
@custom-variant dark (&:is(.dark *));
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--radius: 0.65rem;
|
--radius: 0.225rem;
|
||||||
--background: oklch(1 0 0);
|
|
||||||
--foreground: oklch(0.141 0.005 285.823);
|
|
||||||
--card: oklch(1 0 0);
|
--card: oklch(1 0 0);
|
||||||
--card-foreground: oklch(0.141 0.005 285.823);
|
--card-foreground: oklch(0.145 0 0);
|
||||||
--popover: oklch(1 0 0);
|
--popover: oklch(1 0 0);
|
||||||
--popover-foreground: oklch(0.141 0.005 285.823);
|
--popover-foreground: oklch(0.145 0 0);
|
||||||
--primary: oklch(0.541 0.281 293.009);
|
--primary: oklch(0.457 0.24 277.023);
|
||||||
--primary-foreground: oklch(0.969 0.016 293.756);
|
--primary-foreground: oklch(0.962 0.018 272.314);
|
||||||
--secondary: oklch(0.967 0.001 286.375);
|
--secondary: oklch(0.967 0.001 286.375);
|
||||||
--secondary-foreground: oklch(0.21 0.006 285.885);
|
--secondary-foreground: oklch(0.21 0.006 285.885);
|
||||||
--muted: oklch(0.967 0.001 286.375);
|
--muted: oklch(0.97 0 0);
|
||||||
--muted-foreground: oklch(0.552 0.016 285.938);
|
--muted-foreground: oklch(0.556 0 0);
|
||||||
--accent: oklch(0.967 0.001 286.375);
|
--accent: oklch(0.97 0 0);
|
||||||
--accent-foreground: oklch(0.21 0.006 285.885);
|
--accent-foreground: oklch(0.205 0 0);
|
||||||
--destructive: oklch(0.577 0.245 27.325);
|
--destructive: oklch(0.577 0.245 27.325);
|
||||||
--border: oklch(0.92 0.004 286.32);
|
--border: oklch(0.922 0 0);
|
||||||
--input: oklch(0.92 0.004 286.32);
|
--input: oklch(0.922 0 0);
|
||||||
--ring: oklch(0.702 0.183 293.541);
|
--ring: oklch(0.708 0 0);
|
||||||
--chart-1: oklch(0.65 0.18 25); /* Soft Red/Rose - High Priority */
|
--chart-1: oklch(0.785 0.115 274.713); /* Soft Red/Rose - High Priority */
|
||||||
--chart-2: oklch(0.78 0.12 75); /* Warm Amber - Distinct */
|
--chart-2: oklch(0.585 0.233 277.117); /* Warm Amber - Distinct */
|
||||||
--chart-3: oklch(0.68 0.12 245); /* Azure Blue - Cool Professional */
|
--chart-3: oklch(0.511 0.262 276.966); /* Azure Blue - Cool Professional */
|
||||||
--chart-4: oklch(0.75 0.1 165); /* Mint Teal - Balanced */
|
--chart-4: oklch(0.457 0.24 277.023); /* Mint Teal - Balanced */
|
||||||
--chart-5: oklch(0.85 0.08 195); /* Soft Cyan - Subdued */
|
--chart-5: oklch(0.398 0.195 277.366); /* Soft Cyan - Subdued */
|
||||||
--chart-6: oklch(0.62 0.22 295); /* Deep Violet - Theme Primary */
|
--chart-6: oklch(0.62 0.22 295); /* Deep Violet - Theme Primary */
|
||||||
--chart-8: oklch(0.58 0.2 335); /* Cool Magenta - Distant Accent */
|
--chart-8: oklch(0.58 0.2 335); /* Cool Magenta - Distant Accent */
|
||||||
--sidebar: oklch(0.985 0 0);
|
--sidebar: oklch(0.985 0 0);
|
||||||
--sidebar-foreground: oklch(0.141 0.005 285.823);
|
--sidebar-foreground: oklch(0.145 0 0);
|
||||||
--sidebar-primary: oklch(0.541 0.281 293.009);
|
--sidebar-primary: oklch(0.511 0.262 276.966);
|
||||||
--sidebar-primary-foreground: oklch(0.969 0.016 293.756);
|
--sidebar-primary-foreground: oklch(0.962 0.018 272.314);
|
||||||
--sidebar-accent: oklch(0.967 0.001 286.375);
|
--sidebar-accent: oklch(0.97 0 0);
|
||||||
--sidebar-accent-foreground: oklch(0.21 0.006 285.885);
|
--sidebar-accent-foreground: oklch(0.205 0 0);
|
||||||
--sidebar-border: oklch(0.92 0.004 286.32);
|
--sidebar-border: oklch(0.922 0 0);
|
||||||
--sidebar-ring: oklch(0.702 0.183 293.541);
|
--sidebar-ring: oklch(0.708 0 0);
|
||||||
|
--background: oklch(1 0 0);
|
||||||
|
--foreground: oklch(0.145 0 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
--background: oklch(0.141 0.005 285.823);
|
--background: oklch(0.145 0 0);
|
||||||
--foreground: oklch(0.985 0 0);
|
--foreground: oklch(0.985 0 0);
|
||||||
--card: oklch(0.21 0.006 285.885);
|
--card: oklch(0.205 0 0);
|
||||||
--card-foreground: oklch(0.985 0 0);
|
--card-foreground: oklch(0.985 0 0);
|
||||||
--popover: oklch(0.21 0.006 285.885);
|
--popover: oklch(0.205 0 0);
|
||||||
--popover-foreground: oklch(0.985 0 0);
|
--popover-foreground: oklch(0.985 0 0);
|
||||||
--primary: oklch(0.606 0.25 292.717);
|
--primary: oklch(0.398 0.195 277.366);
|
||||||
--primary-foreground: oklch(0.969 0.016 293.756);
|
--primary-foreground: oklch(0.962 0.018 272.314);
|
||||||
--secondary: oklch(0.274 0.006 286.033);
|
--secondary: oklch(0.274 0.006 286.033);
|
||||||
--secondary-foreground: oklch(0.985 0 0);
|
--secondary-foreground: oklch(0.985 0 0);
|
||||||
--muted: oklch(0.274 0.006 286.033);
|
--muted: oklch(0.269 0 0);
|
||||||
--muted-foreground: oklch(0.705 0.015 286.067);
|
--muted-foreground: oklch(0.708 0 0);
|
||||||
--accent: oklch(0.274 0.006 286.033);
|
--accent: oklch(0.269 0 0);
|
||||||
--accent-foreground: oklch(0.985 0 0);
|
--accent-foreground: oklch(0.985 0 0);
|
||||||
--destructive: oklch(0.704 0.191 22.216);
|
--destructive: oklch(0.704 0.191 22.216);
|
||||||
--border: oklch(1 0 0 / 10%);
|
--border: oklch(1 0 0 / 10%);
|
||||||
--input: oklch(1 0 0 / 15%);
|
--input: oklch(1 0 0 / 15%);
|
||||||
--ring: oklch(0.38 0.189 293.745);
|
--ring: oklch(0.556 0 0);
|
||||||
--chart-1: oklch(0.7 0.16 25);
|
--chart-1: oklch(0.785 0.115 274.713);
|
||||||
--chart-2: oklch(0.82 0.14 75);
|
--chart-2: oklch(0.585 0.233 277.117);
|
||||||
--chart-3: oklch(0.72 0.14 245);
|
--chart-3: oklch(0.511 0.262 276.966);
|
||||||
--chart-4: oklch(0.78 0.12 165);
|
--chart-4: oklch(0.457 0.24 277.023);
|
||||||
--chart-5: oklch(0.88 0.1 195);
|
--chart-5: oklch(0.398 0.195 277.366);
|
||||||
--chart-6: oklch(0.65 0.24 295);
|
--chart-6: oklch(0.65 0.24 295);
|
||||||
--chart-8: oklch(0.62 0.22 335);
|
--chart-8: oklch(0.62 0.22 335);
|
||||||
--sidebar: oklch(0.21 0.006 285.885);
|
--sidebar: oklch(0.205 0 0);
|
||||||
--sidebar-foreground: oklch(0.985 0 0);
|
--sidebar-foreground: oklch(0.985 0 0);
|
||||||
--sidebar-primary: oklch(0.606 0.25 292.717);
|
--sidebar-primary: oklch(0.585 0.233 277.117);
|
||||||
--sidebar-primary-foreground: oklch(0.969 0.016 293.756);
|
--sidebar-primary-foreground: oklch(0.962 0.018 272.314);
|
||||||
--sidebar-accent: oklch(0.274 0.006 286.033);
|
--sidebar-accent: oklch(0.269 0 0);
|
||||||
--sidebar-accent-foreground: oklch(0.985 0 0);
|
--sidebar-accent-foreground: oklch(0.985 0 0);
|
||||||
--sidebar-border: oklch(1 0 0 / 10%);
|
--sidebar-border: oklch(1 0 0 / 10%);
|
||||||
--sidebar-ring: oklch(0.38 0.189 293.745);
|
--sidebar-ring: oklch(0.556 0 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@theme inline {
|
@theme inline {
|
||||||
--font-sans: 'Poppins', 'Poppins Fallback', system-ui, sans-serif;
|
--font-sans: var(--font-sans);
|
||||||
--font-mono: 'Geist Mono', 'Geist Mono Fallback', monospace;
|
--font-mono: 'Geist Mono', 'Geist Mono Fallback', monospace;
|
||||||
--color-background: var(--background);
|
--color-background: var(--background);
|
||||||
--color-foreground: var(--foreground);
|
--color-foreground: var(--foreground);
|
||||||
@@ -119,14 +121,47 @@
|
|||||||
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
|
||||||
--color-sidebar-border: var(--sidebar-border);
|
--color-sidebar-border: var(--sidebar-border);
|
||||||
--color-sidebar-ring: var(--sidebar-ring);
|
--color-sidebar-ring: var(--sidebar-ring);
|
||||||
|
--font-heading: var(--font-sans);
|
||||||
|
--radius-2xl: calc(var(--radius) * 1.8);
|
||||||
|
--radius-3xl: calc(var(--radius) * 2.2);
|
||||||
|
--radius-4xl: calc(var(--radius) * 2.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
@layer base {
|
@layer base {
|
||||||
|
html:has(body[data-scroll-locked]) {
|
||||||
|
scrollbar-gutter: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@supports not (scrollbar-gutter: stable) {
|
||||||
|
.scroll-stable {
|
||||||
|
overflow-y: scroll;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
@apply border-border outline-none;
|
@apply outline-none border-border outline-ring/50;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@apply bg-background text-foreground;
|
@apply bg-background text-foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.scroll-stable {
|
||||||
|
scrollbar-gutter: stable;
|
||||||
|
}
|
||||||
|
html {
|
||||||
|
@apply font-sans;
|
||||||
|
}
|
||||||
|
button:not(:disabled), [role="button"]:not(:disabled) {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.detection-video-player .vds-slider-preview {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.detection-video-player
|
||||||
|
.vds-slider-preview:has(.vds-slider-thumbnail img[src^='blob:']) {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
import type { Metadata } from 'next';
|
import type { Metadata } from 'next';
|
||||||
import { Geist_Mono, Poppins } from 'next/font/google';
|
import { Geist_Mono, Poppins, Inter } from 'next/font/google';
|
||||||
|
import '@vidstack/react/player/styles/default/theme.css';
|
||||||
|
import '@vidstack/react/player/styles/default/layouts/video.css';
|
||||||
|
import 'leaflet/dist/leaflet.css';
|
||||||
|
import 'lightgallery/css/lightgallery.css';
|
||||||
|
import 'lightgallery/css/lg-thumbnail.css';
|
||||||
|
import 'lightgallery/css/lg-zoom.css';
|
||||||
import './globals.css';
|
import './globals.css';
|
||||||
import { ThemeProvider } from '@/providers/ThemeProvider';
|
import { ThemeProvider } from '@/providers/ThemeProvider';
|
||||||
import AppInitializer from '@/providers/AppInitializer';
|
import AppInitializer from '@/providers/AppInitializer';
|
||||||
import QueryProvider from '@/providers/QueryProvider';
|
import QueryProvider from '@/providers/QueryProvider';
|
||||||
import { Toaster } from '@/components/ui/sonner';
|
import { Toaster } from '@/components/ui/sonner';
|
||||||
|
import { TooltipProvider } from '@/components/ui/tooltip';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
const inter = Inter({subsets:['latin'],variable:'--font-sans'});
|
||||||
|
|
||||||
const poppins = Poppins({
|
const poppins = Poppins({
|
||||||
variable: '--font-poppins',
|
variable: '--font-poppins',
|
||||||
@@ -19,8 +29,8 @@ const geistMono = Geist_Mono({
|
|||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: {
|
title: {
|
||||||
default: 'VisionRoad',
|
default: 'RoadMonitor',
|
||||||
template: '%s | VisionRoad',
|
template: '%s | RoadMonitor',
|
||||||
},
|
},
|
||||||
description: 'Road infrastructure monitoring and pothole detection platform',
|
description: 'Road infrastructure monitoring and pothole detection platform',
|
||||||
};
|
};
|
||||||
@@ -31,7 +41,11 @@ export default function RootLayout({
|
|||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}>) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<html lang="en" suppressHydrationWarning>
|
<html
|
||||||
|
lang="en"
|
||||||
|
suppressHydrationWarning
|
||||||
|
className={cn('font-sans', "font-sans", inter.variable)}
|
||||||
|
>
|
||||||
<head>
|
<head>
|
||||||
<link rel="stylesheet" href="/flags/flags.css" />
|
<link rel="stylesheet" href="/flags/flags.css" />
|
||||||
</head>
|
</head>
|
||||||
@@ -44,8 +58,10 @@ export default function RootLayout({
|
|||||||
>
|
>
|
||||||
<QueryProvider>
|
<QueryProvider>
|
||||||
<AppInitializer>
|
<AppInitializer>
|
||||||
{children}
|
<TooltipProvider delayDuration={0}>
|
||||||
<Toaster position="top-center" />
|
{children}
|
||||||
|
<Toaster position="top-center" />
|
||||||
|
</TooltipProvider>
|
||||||
</AppInitializer>
|
</AppInitializer>
|
||||||
</QueryProvider>
|
</QueryProvider>
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
|
|||||||
57
src/components/LogoWrapper.tsx
Normal file
57
src/components/LogoWrapper.tsx
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import Image from 'next/image';
|
||||||
|
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
|
const sizeClasses = {
|
||||||
|
sm: 'size-8 rounded-lg border-2 p-0.5',
|
||||||
|
md: 'size-12 rounded-lg border-2 p-1.5',
|
||||||
|
lg: 'size-28 rounded-lg border-[5px] p-3',
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const variantClasses = {
|
||||||
|
default: 'border-white bg-primary shadow-md',
|
||||||
|
solid: 'border-white bg-primary',
|
||||||
|
glass: 'border-primary-foreground bg-primary/85 shadow-md',
|
||||||
|
sidebar: 'border-0 bg-primary',
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
type LogoWrapperProps = {
|
||||||
|
alt?: string;
|
||||||
|
className?: string;
|
||||||
|
imageClassName?: string;
|
||||||
|
priority?: boolean;
|
||||||
|
size?: keyof typeof sizeClasses;
|
||||||
|
variant?: keyof typeof variantClasses;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function LogoWrapper({
|
||||||
|
alt = 'RoadMonitor logo',
|
||||||
|
className,
|
||||||
|
imageClassName,
|
||||||
|
priority = false,
|
||||||
|
size = 'md',
|
||||||
|
variant = 'default',
|
||||||
|
}: LogoWrapperProps) {
|
||||||
|
return (
|
||||||
|
<span
|
||||||
|
className={cn(
|
||||||
|
'inline-flex shrink-0 items-center justify-center',
|
||||||
|
sizeClasses[size],
|
||||||
|
variantClasses[variant],
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<Image
|
||||||
|
src="/logo.png"
|
||||||
|
alt={alt}
|
||||||
|
width={112}
|
||||||
|
height={112}
|
||||||
|
className={cn(
|
||||||
|
'size-full object-contain brightness-0 invert',
|
||||||
|
imageClassName,
|
||||||
|
)}
|
||||||
|
priority={priority}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
}
|
||||||
66
src/components/annotation/boundingBoxOverlay.tsx
Normal file
66
src/components/annotation/boundingBoxOverlay.tsx
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import { getDefectVisual } from '@/constants/defectVisualConfig';
|
||||||
|
import type { BoundingBoxOverlayItem } from '@/types';
|
||||||
|
|
||||||
|
interface BoundingBoxOverlayProps {
|
||||||
|
detections: BoundingBoxOverlayItem[];
|
||||||
|
videoWidth: number;
|
||||||
|
videoHeight: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function BoundingBoxOverlay({
|
||||||
|
detections,
|
||||||
|
videoWidth,
|
||||||
|
videoHeight,
|
||||||
|
}: BoundingBoxOverlayProps) {
|
||||||
|
if (videoWidth <= 0 || videoHeight <= 0 || detections.length === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
className="pointer-events-none absolute inset-0 z-[2] size-full"
|
||||||
|
viewBox={`0 0 ${videoWidth} ${videoHeight}`}
|
||||||
|
preserveAspectRatio="xMidYMid meet"
|
||||||
|
>
|
||||||
|
{detections.map((detection) => {
|
||||||
|
const { bounding_box: box } = detection;
|
||||||
|
const color = getDefectVisual(detection.class_name).boundingBoxColor;
|
||||||
|
const label = `${detection.display_name} ${(detection.confidence * 100).toFixed(0)}%`;
|
||||||
|
const labelY = Math.max(box.y1 - 34, 0);
|
||||||
|
const labelWidth = Math.max(150, label.length * 17);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<g key={detection.id}>
|
||||||
|
<rect
|
||||||
|
x={box.x1}
|
||||||
|
y={box.y1}
|
||||||
|
width={box.x2 - box.x1}
|
||||||
|
height={box.y2 - box.y1}
|
||||||
|
fill="none"
|
||||||
|
stroke={color}
|
||||||
|
strokeWidth="4"
|
||||||
|
vectorEffect="non-scaling-stroke"
|
||||||
|
/>
|
||||||
|
<rect
|
||||||
|
x={box.x1}
|
||||||
|
y={labelY}
|
||||||
|
width={labelWidth}
|
||||||
|
height="34"
|
||||||
|
fill={color}
|
||||||
|
/>
|
||||||
|
<text
|
||||||
|
x={box.x1 + 8}
|
||||||
|
y={labelY + 23}
|
||||||
|
fill="white"
|
||||||
|
fontSize="20"
|
||||||
|
fontWeight="600"
|
||||||
|
>
|
||||||
|
{label}
|
||||||
|
</text>
|
||||||
|
</g>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</svg>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import Link from 'next/link';
|
||||||
import { usePathname } from 'next/navigation';
|
import { usePathname } from 'next/navigation';
|
||||||
import {
|
import {
|
||||||
Breadcrumb,
|
Breadcrumb,
|
||||||
@@ -27,7 +28,9 @@ export function BreadcrumbBasic() {
|
|||||||
<Breadcrumb>
|
<Breadcrumb>
|
||||||
<BreadcrumbList>
|
<BreadcrumbList>
|
||||||
<BreadcrumbItem>
|
<BreadcrumbItem>
|
||||||
<BreadcrumbLink href="/">Home</BreadcrumbLink>
|
<BreadcrumbLink asChild>
|
||||||
|
<Link href="/">Home</Link>
|
||||||
|
</BreadcrumbLink>
|
||||||
</BreadcrumbItem>
|
</BreadcrumbItem>
|
||||||
{segments.length > 0 && <BreadcrumbSeparator />}
|
{segments.length > 0 && <BreadcrumbSeparator />}
|
||||||
|
|
||||||
@@ -44,8 +47,8 @@ export function BreadcrumbBasic() {
|
|||||||
{isLast ? (
|
{isLast ? (
|
||||||
<BreadcrumbPage>{formatSegment(segment)}</BreadcrumbPage>
|
<BreadcrumbPage>{formatSegment(segment)}</BreadcrumbPage>
|
||||||
) : (
|
) : (
|
||||||
<BreadcrumbLink href={href}>
|
<BreadcrumbLink asChild>
|
||||||
{formatSegment(segment)}
|
<Link href={href}>{formatSegment(segment)}</Link>
|
||||||
</BreadcrumbLink>
|
</BreadcrumbLink>
|
||||||
)}
|
)}
|
||||||
</BreadcrumbItem>
|
</BreadcrumbItem>
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { ChevronRight, Package } from 'lucide-react';
|
import { ChevronRight } from 'lucide-react';
|
||||||
|
import { LogoWrapper } from '@/components/LogoWrapper';
|
||||||
import { NavUser } from '@/components/nav-user';
|
import { NavUser } from '@/components/nav-user';
|
||||||
import {
|
import {
|
||||||
filterMenuItems,
|
filterMenuItems,
|
||||||
@@ -17,24 +18,36 @@ import {
|
|||||||
Sidebar,
|
Sidebar,
|
||||||
SidebarContent,
|
SidebarContent,
|
||||||
SidebarFooter,
|
SidebarFooter,
|
||||||
|
SidebarGroup,
|
||||||
SidebarHeader,
|
SidebarHeader,
|
||||||
SidebarRail,
|
|
||||||
SidebarMenu,
|
SidebarMenu,
|
||||||
SidebarMenuItem,
|
|
||||||
SidebarMenuButton,
|
SidebarMenuButton,
|
||||||
|
SidebarMenuItem,
|
||||||
SidebarMenuSub,
|
SidebarMenuSub,
|
||||||
SidebarMenuSubButton,
|
SidebarMenuSubButton,
|
||||||
SidebarMenuSubItem,
|
SidebarMenuSubItem,
|
||||||
SidebarGroup,
|
SidebarRail,
|
||||||
SidebarGroupLabel,
|
SidebarTrigger,
|
||||||
|
useSidebar,
|
||||||
} from '@/components/ui/sidebar';
|
} from '@/components/ui/sidebar';
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from '@/components/ui/tooltip';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { usePathname } from 'next/navigation';
|
import { usePathname } from 'next/navigation';
|
||||||
import { useAppStore } from '@/store/app.store';
|
import { useAppStore } from '@/store/app.store';
|
||||||
|
|
||||||
|
function isRouteActive(pathname: string, path?: string) {
|
||||||
|
if (!path) return false;
|
||||||
|
return pathname === path || pathname.startsWith(`${path}/`);
|
||||||
|
}
|
||||||
|
|
||||||
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const { hasPermission } = usePermissions();
|
const { hasPermission } = usePermissions();
|
||||||
|
const { isMobile } = useSidebar();
|
||||||
const authUser = useAppStore((state) => state.user);
|
const authUser = useAppStore((state) => state.user);
|
||||||
const navItems = filterMenuItems(menuItems, hasPermission);
|
const navItems = filterMenuItems(menuItems, hasPermission);
|
||||||
const user = {
|
const user = {
|
||||||
@@ -47,19 +60,21 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Sidebar collapsible="icon" {...props}>
|
<Sidebar collapsible="icon" {...props}>
|
||||||
<SidebarHeader>
|
<SidebarHeader className="border-b border-sidebar-border px-3 py-3 group-data-[collapsible=icon]:items-center group-data-[collapsible=icon]:border-b-0 group-data-[collapsible=icon]:px-2">
|
||||||
<div className="flex items-center gap-2 py-2">
|
<div className="flex h-8 w-full items-center gap-3 group-data-[collapsible=icon]:w-8 group-data-[collapsible=icon]:justify-center">
|
||||||
<div className="flex aspect-square size-8 items-center justify-center rounded-lg bg-primary text-primary-foreground">
|
<SidebarBrandControl isMobile={isMobile} />
|
||||||
<Package className="size-4" />
|
|
||||||
</div>
|
|
||||||
<div className="grid flex-1 text-left text-sm leading-tight group-data-[collapsible=icon]:hidden">
|
<div className="grid flex-1 text-left text-sm leading-tight group-data-[collapsible=icon]:hidden">
|
||||||
<span className="truncate font-semibold">Vision Road</span>
|
<span className="truncate font-semibold">RoadMonitor</span>
|
||||||
<span className="truncate text-xs">Analytics Platform</span>
|
<span className="truncate text-xs">Road Intelligence</span>
|
||||||
</div>
|
</div>
|
||||||
|
<SidebarTrigger
|
||||||
|
className="ml-auto shrink-0 bg-sidebar/80 text-sidebar-foreground/80 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:hidden"
|
||||||
|
aria-label={isMobile ? 'Close menu' : 'Hide menu'}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</SidebarHeader>
|
</SidebarHeader>
|
||||||
<SidebarContent>
|
<SidebarContent className="px-2 py-3">
|
||||||
<SidebarGroup>
|
<SidebarGroup className="p-0">
|
||||||
<SidebarMenu>
|
<SidebarMenu>
|
||||||
{navItems.map((item) => (
|
{navItems.map((item) => (
|
||||||
<SidebarNavItem
|
<SidebarNavItem
|
||||||
@@ -71,7 +86,7 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
|||||||
</SidebarMenu>
|
</SidebarMenu>
|
||||||
</SidebarGroup>
|
</SidebarGroup>
|
||||||
</SidebarContent>
|
</SidebarContent>
|
||||||
<SidebarFooter>
|
<SidebarFooter className="border-t border-sidebar-border px-3 py-3">
|
||||||
<NavUser user={user} />
|
<NavUser user={user} />
|
||||||
</SidebarFooter>
|
</SidebarFooter>
|
||||||
<SidebarRail />
|
<SidebarRail />
|
||||||
@@ -79,6 +94,27 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function SidebarBrandControl({ isMobile }: { isMobile: boolean }) {
|
||||||
|
return (
|
||||||
|
<div className="group/sidebar-brand relative flex size-8 shrink-0 items-center justify-center">
|
||||||
|
<LogoWrapper
|
||||||
|
size="sm"
|
||||||
|
variant="sidebar"
|
||||||
|
className="transition-opacity duration-150 group-data-[collapsible=icon]:group-hover/sidebar-brand:opacity-0 group-data-[collapsible=icon]:group-focus-within/sidebar-brand:opacity-0"
|
||||||
|
/>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<SidebarTrigger
|
||||||
|
className="pointer-events-none absolute inset-0 bg-sidebar text-sidebar-foreground/80 opacity-0 shadow-none hover:bg-sidebar-accent hover:text-sidebar-accent-foreground group-data-[collapsible=icon]:pointer-events-auto group-data-[collapsible=icon]:group-hover/sidebar-brand:opacity-100 group-data-[collapsible=icon]:group-focus-within/sidebar-brand:opacity-100"
|
||||||
|
aria-label={isMobile ? 'Close menu' : 'Open menu'}
|
||||||
|
/>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent side="right">Open menu</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function SidebarNavItem({
|
function SidebarNavItem({
|
||||||
item,
|
item,
|
||||||
pathname,
|
pathname,
|
||||||
@@ -86,16 +122,23 @@ function SidebarNavItem({
|
|||||||
item: MenuItem;
|
item: MenuItem;
|
||||||
pathname: string;
|
pathname: string;
|
||||||
}) {
|
}) {
|
||||||
const isActive = item.path ? pathname === item.path : false;
|
const isActive = isRouteActive(pathname, item.path);
|
||||||
const isChildActive =
|
const isChildActive =
|
||||||
item.children?.some((child) => child.path === pathname) ?? false;
|
item.children?.some((child) => isRouteActive(pathname, child.path)) ??
|
||||||
|
false;
|
||||||
const hasChildren = Boolean(item.children?.length);
|
const hasChildren = Boolean(item.children?.length);
|
||||||
|
const [open, setOpen] = React.useState(isChildActive);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
if (isChildActive) setOpen(true);
|
||||||
|
}, [isChildActive]);
|
||||||
|
|
||||||
if (hasChildren) {
|
if (hasChildren) {
|
||||||
return (
|
return (
|
||||||
<Collapsible
|
<Collapsible
|
||||||
asChild
|
asChild
|
||||||
defaultOpen={isChildActive}
|
open={open}
|
||||||
|
onOpenChange={setOpen}
|
||||||
className="group/collapsible"
|
className="group/collapsible"
|
||||||
>
|
>
|
||||||
<SidebarMenuItem>
|
<SidebarMenuItem>
|
||||||
@@ -113,7 +156,7 @@ function SidebarNavItem({
|
|||||||
{child.path ? (
|
{child.path ? (
|
||||||
<SidebarMenuSubButton
|
<SidebarMenuSubButton
|
||||||
asChild
|
asChild
|
||||||
isActive={pathname === child.path}
|
isActive={isRouteActive(pathname, child.path)}
|
||||||
>
|
>
|
||||||
<Link href={child.path}>
|
<Link href={child.path}>
|
||||||
<child.icon />
|
<child.icon />
|
||||||
|
|||||||
@@ -14,11 +14,9 @@ import {
|
|||||||
ComboboxTrigger,
|
ComboboxTrigger,
|
||||||
ComboboxValue,
|
ComboboxValue,
|
||||||
} from '@/components/ui/combobox';
|
} from '@/components/ui/combobox';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
import type {
|
import type { AsyncSelectOption, AsyncSelectProps } from './AsyncSelect.types';
|
||||||
AsyncSelectOption,
|
|
||||||
AsyncSelectProps,
|
|
||||||
} from './AsyncSelect.types';
|
|
||||||
import { VirtualSelectList } from './VirtualSelectList';
|
import { VirtualSelectList } from './VirtualSelectList';
|
||||||
|
|
||||||
type VirtualizerHandle = Virtualizer<HTMLDivElement, Element>;
|
type VirtualizerHandle = Virtualizer<HTMLDivElement, Element>;
|
||||||
@@ -30,6 +28,8 @@ export function AsyncSelect({
|
|||||||
searchPlaceholder = 'Search...',
|
searchPlaceholder = 'Search...',
|
||||||
emptyMessage = 'No items found.',
|
emptyMessage = 'No items found.',
|
||||||
disabled = false,
|
disabled = false,
|
||||||
|
triggerClassName,
|
||||||
|
renderSelectedOption,
|
||||||
portalContainer,
|
portalContainer,
|
||||||
}: AsyncSelectProps) {
|
}: AsyncSelectProps) {
|
||||||
const [open, setOpen] = useState(false);
|
const [open, setOpen] = useState(false);
|
||||||
@@ -125,7 +125,10 @@ export function AsyncSelect({
|
|||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
variant="outline"
|
variant="outline"
|
||||||
className="w-full justify-between font-normal"
|
className={cn(
|
||||||
|
'w-full justify-between font-normal',
|
||||||
|
triggerClassName,
|
||||||
|
)}
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
>
|
>
|
||||||
{isLoading && !selectedOption ? (
|
{isLoading && !selectedOption ? (
|
||||||
@@ -134,14 +137,20 @@ export function AsyncSelect({
|
|||||||
Loading...
|
Loading...
|
||||||
</span>
|
</span>
|
||||||
) : (
|
) : (
|
||||||
<ComboboxValue placeholder={triggerPlaceholder} />
|
<>
|
||||||
|
{selectedOption && renderSelectedOption ? (
|
||||||
|
renderSelectedOption(selectedOption)
|
||||||
|
) : (
|
||||||
|
<ComboboxValue placeholder={triggerPlaceholder} />
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<ComboboxContent
|
<ComboboxContent
|
||||||
container={portalContainer}
|
container={portalContainer}
|
||||||
className="min-w-[var(--anchor-width)]"
|
className="min-w-(--anchor-width)"
|
||||||
>
|
>
|
||||||
<div className="border-b p-2">
|
<div className="border-b p-2">
|
||||||
<ComboboxInput
|
<ComboboxInput
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import type { RefObject } from 'react';
|
import type { ReactNode, RefObject } from 'react';
|
||||||
|
|
||||||
export type AsyncSelectOption = {
|
export type AsyncSelectOption = {
|
||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
data?: unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PaginatedResult<T> = {
|
export type PaginatedResult<T> = {
|
||||||
@@ -47,5 +48,7 @@ export interface AsyncSelectProps {
|
|||||||
searchPlaceholder?: string;
|
searchPlaceholder?: string;
|
||||||
emptyMessage?: string;
|
emptyMessage?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
triggerClassName?: string;
|
||||||
|
renderSelectedOption?: (option: AsyncSelectOption) => ReactNode;
|
||||||
portalContainer?: RefObject<HTMLDivElement | null>;
|
portalContainer?: RefObject<HTMLDivElement | null>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { LogoWrapper } from '@/components/LogoWrapper';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
|
||||||
const BOKEH_ORBS = [
|
const BOKEH_ORBS = [
|
||||||
@@ -80,6 +81,30 @@ export function AuthBackground({ className }: AuthBackgroundProps) {
|
|||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
|
<div className="absolute inset-x-10 top-1/2 -translate-y-1/2 text-center text-primary-foreground">
|
||||||
|
<div className="mb-9 inline-flex items-center gap-5 text-left">
|
||||||
|
<LogoWrapper
|
||||||
|
alt=""
|
||||||
|
className="size-28 rounded-lg border-[5px] p-4"
|
||||||
|
priority
|
||||||
|
variant="glass"
|
||||||
|
/>
|
||||||
|
<span className="min-w-0">
|
||||||
|
<span className="block text-5xl font-semibold leading-none tracking-normal">
|
||||||
|
Road
|
||||||
|
</span>
|
||||||
|
<span className="block text-5xl font-semibold leading-none tracking-normal">
|
||||||
|
Monitor
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p className="mx-auto max-w-md text-base leading-7 text-primary-foreground/82">
|
||||||
|
Map, monitor, and repair road issues with data-driven surface
|
||||||
|
intelligence.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Table } from '@tanstack/react-table';
|
import { Table } from '@tanstack/react-table';
|
||||||
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
import {
|
||||||
|
ChevronLeft,
|
||||||
|
ChevronRight,
|
||||||
|
ChevronsLeft,
|
||||||
|
ChevronsRight,
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
@@ -25,26 +30,33 @@ export function TableFooter<TData>({
|
|||||||
pageSize?: number;
|
pageSize?: number;
|
||||||
onPageSizeChange?: (pageSize: number) => void;
|
onPageSizeChange?: (pageSize: number) => void;
|
||||||
}) {
|
}) {
|
||||||
const rows = table.getRowModel().rows.length;
|
|
||||||
const currentPageSize = pageSize ?? table.getState().pagination.pageSize;
|
const currentPageSize = pageSize ?? table.getState().pagination.pageSize;
|
||||||
|
const selectedRowCount = Object.keys(table.getState().rowSelection).length;
|
||||||
|
const pageIndex = table.getState().pagination.pageIndex;
|
||||||
|
const rawPageCount = table.getPageCount();
|
||||||
|
const pageCount = Math.max(
|
||||||
|
1,
|
||||||
|
Number.isFinite(rawPageCount) && rawPageCount > 0 ? rawPageCount : 1,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-3 text-sm text-muted-foreground sm:flex-row sm:items-center sm:justify-between">
|
<div className="flex flex-col gap-3 px-4 text-sm text-muted-foreground sm:flex-row sm:items-center sm:justify-between">
|
||||||
<div className="flex flex-wrap items-center gap-3">
|
<div>
|
||||||
<span>
|
{selectedRowCount} of {totalItems} row(s) selected.
|
||||||
Showing {rows} of {totalItems}
|
</div>
|
||||||
</span>
|
|
||||||
|
<div className="flex flex-wrap items-center gap-4 sm:justify-end">
|
||||||
{onPageSizeChange ? (
|
{onPageSizeChange ? (
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2 text-foreground">
|
||||||
<span>Rows per page</span>
|
<span className="font-medium">Rows per page</span>
|
||||||
<Select
|
<Select
|
||||||
value={String(currentPageSize)}
|
value={String(currentPageSize)}
|
||||||
onValueChange={(value) => onPageSizeChange(Number(value))}
|
onValueChange={(value) => table.setPageSize(Number(value))}
|
||||||
>
|
>
|
||||||
<SelectTrigger className="h-8 w-18 bg-background">
|
<SelectTrigger className="h-8 w-20 border-border bg-background shadow-none">
|
||||||
<SelectValue />
|
<SelectValue />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent align="end">
|
||||||
{PAGE_SIZE_OPTIONS.map((size) => (
|
{PAGE_SIZE_OPTIONS.map((size) => (
|
||||||
<SelectItem key={size} value={String(size)}>
|
<SelectItem key={size} value={String(size)}>
|
||||||
{size}
|
{size}
|
||||||
@@ -54,26 +66,57 @@ export function TableFooter<TData>({
|
|||||||
</Select>
|
</Select>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
|
||||||
<div className="flex gap-2">
|
<div className="min-w-24 text-foreground font-medium">
|
||||||
<Button
|
Page {pageIndex + 1} of {pageCount}
|
||||||
variant="outline"
|
</div>
|
||||||
size="sm"
|
|
||||||
onClick={() => table.previousPage()}
|
<div className="flex items-center gap-2">
|
||||||
disabled={!table.getCanPreviousPage()}
|
<Button
|
||||||
>
|
type="button"
|
||||||
<ChevronLeft className="size-4" />
|
variant="outline"
|
||||||
Previous
|
size="icon-sm"
|
||||||
</Button>
|
className="size-8 shadow-none"
|
||||||
<Button
|
onClick={() => table.setPageIndex(0)}
|
||||||
variant="outline"
|
disabled={!table.getCanPreviousPage()}
|
||||||
size="sm"
|
aria-label="Go to first page"
|
||||||
onClick={() => table.nextPage()}
|
>
|
||||||
disabled={!table.getCanNextPage()}
|
<ChevronsLeft className="size-4" />
|
||||||
>
|
</Button>
|
||||||
Next
|
<Button
|
||||||
<ChevronRight className="size-4" />
|
type="button"
|
||||||
</Button>
|
variant="outline"
|
||||||
|
size="icon-sm"
|
||||||
|
className="size-8 shadow-none"
|
||||||
|
onClick={() => table.previousPage()}
|
||||||
|
disabled={!table.getCanPreviousPage()}
|
||||||
|
aria-label="Go to previous page"
|
||||||
|
>
|
||||||
|
<ChevronLeft className="size-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="icon-sm"
|
||||||
|
className="size-8 shadow-none"
|
||||||
|
onClick={() => table.nextPage()}
|
||||||
|
disabled={!table.getCanNextPage()}
|
||||||
|
aria-label="Go to next page"
|
||||||
|
>
|
||||||
|
<ChevronRight className="size-4" />
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="icon-sm"
|
||||||
|
className="size-8 shadow-none"
|
||||||
|
onClick={() => table.setPageIndex(pageCount - 1)}
|
||||||
|
disabled={!table.getCanNextPage()}
|
||||||
|
aria-label="Go to last page"
|
||||||
|
>
|
||||||
|
<ChevronsRight className="size-4" />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -21,26 +21,35 @@ const TopHeader = ({
|
|||||||
tableTools,
|
tableTools,
|
||||||
}: TopHeaderProps) => {
|
}: TopHeaderProps) => {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-3">
|
||||||
{(title || onAddNew) && (
|
{(title || onAddNew) && (
|
||||||
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
<div className="flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between">
|
||||||
<div>
|
<div className="min-w-0">
|
||||||
{title ? <h2>{title}</h2> : null}
|
{title ? <h2 className="text-lg font-semibold">{title}</h2> : null}
|
||||||
<p className="text-muted-foreground">Total {itemCount ?? 0}</p>
|
<p className="text-sm text-muted-foreground">
|
||||||
|
Total {itemCount ?? 0}
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{onAddNew ? (
|
{onAddNew ? (
|
||||||
<Button onClick={onAddNew}>
|
<Button onClick={onAddNew} size="sm" className="w-fit">
|
||||||
<Plus className="mr-2 size-4" />
|
<Plus className="size-4" />
|
||||||
{addButtonText}
|
{addButtonText}
|
||||||
</Button>
|
</Button>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{(toolbar || tableTools) && (
|
{(toolbar || tableTools) && (
|
||||||
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
<div className="flex flex-col gap-3 md:flex-row md:items-center md:justify-between">
|
||||||
<div className="min-w-0 flex-1">{toolbar}</div>
|
{toolbar ? (
|
||||||
|
<div className="min-w-0 flex-1 **:data-[slot=input-group]:border-border [&_[data-slot=input-group]]:bg-background [&_[data-slot=input-group]]:shadow-none [&_[data-slot=select-trigger]]:border-border [&_[data-slot=select-trigger]]:bg-background [&_[data-slot=select-trigger]]:shadow-none">
|
||||||
|
{toolbar}
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
{tableTools ? (
|
{tableTools ? (
|
||||||
<div className="flex shrink-0 justify-end">{tableTools}</div>
|
<div className="flex shrink-0 justify-end **:data-[slot=button]:shadow-none">
|
||||||
|
{tableTools}
|
||||||
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import { getPinnedColumnStyles } from './columnStyles';
|
|||||||
|
|
||||||
const TableHeader = <TData, _>({ table }: { table: Table<TData> }) => {
|
const TableHeader = <TData, _>({ table }: { table: Table<TData> }) => {
|
||||||
return (
|
return (
|
||||||
<ShadTableHeader className="sticky top-0 z-20 bg-card">
|
<ShadTableHeader className="sticky top-0 z-20 bg-muted/70 backdrop-blur supports-backdrop-filter:bg-muted/60">
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
<TableRow key={headerGroup.id}>
|
<TableRow key={headerGroup.id}>
|
||||||
{headerGroup.headers.map((header) => {
|
{headerGroup.headers.map((header) => {
|
||||||
@@ -39,9 +39,9 @@ const TableHeader = <TData, _>({ table }: { table: Table<TData> }) => {
|
|||||||
canSort ? header.column.getToggleSortingHandler() : undefined
|
canSort ? header.column.getToggleSortingHandler() : undefined
|
||||||
}
|
}
|
||||||
className={cn(
|
className={cn(
|
||||||
'h-10 max-w-0 overflow-hidden border-b border-border bg-card px-2 text-foreground transition-colors',
|
'h-11 max-w-0 overflow-hidden border-b border-border bg-muted/70 px-4 text-sm font-semibold text-foreground transition-colors',
|
||||||
canSort && 'cursor-pointer select-none hover:bg-muted/60',
|
canSort && 'cursor-pointer select-none hover:bg-muted',
|
||||||
sortDirection && 'bg-muted/70',
|
sortDirection && 'bg-muted',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{header.isPlaceholder ? null : (
|
{header.isPlaceholder ? null : (
|
||||||
@@ -70,7 +70,7 @@ const TableHeader = <TData, _>({ table }: { table: Table<TData> }) => {
|
|||||||
onMouseDown={header.getResizeHandler()}
|
onMouseDown={header.getResizeHandler()}
|
||||||
onTouchStart={header.getResizeHandler()}
|
onTouchStart={header.getResizeHandler()}
|
||||||
className={cn(
|
className={cn(
|
||||||
'absolute -right-2 top-0 h-full w-1 cursor-col-resize touch-none select-none rounded bg-border opacity-0 transition-opacity hover:opacity-100',
|
'absolute -right-2 top-0 h-full w-1 cursor-col-resize touch-none select-none rounded-lg bg-border opacity-0 transition-opacity hover:opacity-100',
|
||||||
header.column.getIsResizing() && 'opacity-100',
|
header.column.getIsResizing() && 'opacity-100',
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -23,14 +23,20 @@ export function TableSearchInput({
|
|||||||
className,
|
className,
|
||||||
}: TableSearchInputProps) {
|
}: TableSearchInputProps) {
|
||||||
return (
|
return (
|
||||||
<InputGroup className={cn('md:max-w-xs', className)}>
|
<InputGroup
|
||||||
|
className={cn(
|
||||||
|
'h-9 border-border bg-background shadow-none md:max-w-xs',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
<InputGroupAddon>
|
<InputGroupAddon>
|
||||||
<Search />
|
<Search className="size-4" />
|
||||||
</InputGroupAddon>
|
</InputGroupAddon>
|
||||||
<InputGroupInput
|
<InputGroupInput
|
||||||
value={value}
|
value={value}
|
||||||
onChange={(event) => onChange(event.target.value)}
|
onChange={(event) => onChange(event.target.value)}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
|
className="placeholder:text-muted-foreground/70"
|
||||||
/>
|
/>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
);
|
);
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user