Compare commits
10 Commits
830883c6b7
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
| 224361f144 | |||
| 77b6755d05 | |||
| 2f25fd49be | |||
| 3891500cf2 | |||
| 062e89fcba | |||
| 725c256791 | |||
| 5d3dac0b21 | |||
| e077467bce | |||
| e94da54aa9 | |||
| 76c87811d8 |
@@ -1,2 +1,2 @@
|
|||||||
# Backend API base URL (no trailing slash)
|
# Server-only backend origin. Do not expose this as a NEXT_PUBLIC variable.
|
||||||
NEXT_PUBLIC_API_URL=http://localhost:8000/api/v1
|
BACKEND_ORIGIN=http://localhost:8000
|
||||||
|
|||||||
@@ -1,7 +1,21 @@
|
|||||||
import type { NextConfig } from 'next';
|
import type { NextConfig } from 'next';
|
||||||
|
|
||||||
|
const backendOrigin = process.env.BACKEND_ORIGIN?.replace(/\/+$/, '');
|
||||||
|
|
||||||
|
if (!backendOrigin) {
|
||||||
|
throw new Error('BACKEND_ORIGIN is required');
|
||||||
|
}
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
reactStrictMode: false,
|
reactStrictMode: false,
|
||||||
|
async rewrites() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
source: '/:namespace(api|biz)/:path*',
|
||||||
|
destination: `${backendOrigin}/:namespace/:path*`,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export default nextConfig;
|
export default nextConfig;
|
||||||
|
|||||||
5
public/color_logo.svg
Normal file
5
public/color_logo.svg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<svg width="81" height="58" viewBox="0 0 81 58" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M13.5332 0.0605059C16.6649 -0.107743 21.7192 0.126367 25.0234 0.14449L47.7461 0.166951L63.0156 0.155232C65.667 0.142338 69.1473 -0.0926585 71.7178 0.265584C76.9286 0.992005 80.2385 5.82745 80.2812 10.7988C80.3549 19.3927 80.2813 27.8445 80.25 36.373L80.2373 44.5009C80.2302 48.9661 80.5911 51.3666 77.3691 54.8593L77.2021 55.0253C73.9898 58.1924 70.8296 57.9125 66.626 57.8818C64.5719 49.5069 63.0354 41.4784 59.3477 33.5527C50.3209 14.1517 32.0588 6.98865 13.3232 0.0722246L13.5332 0.0605059ZM75.8604 43.2509C75.4023 40.7143 73.0029 39.0071 70.4561 39.4062C68.7552 39.6725 67.332 40.8392 66.7373 42.455C66.1426 44.0706 66.4703 45.882 67.5928 47.1875C68.7149 48.493 70.456 49.0884 72.1426 48.7431C74.6678 48.2261 76.3182 45.7875 75.8604 43.2509Z" fill="#372AAC"/>
|
||||||
|
<path d="M8.58399 0.18042C10.3814 0.200991 14.9254 2.92742 16.5327 3.93417C21.7136 7.17947 27.0918 12.0437 28.3657 18.2976C30.6755 29.635 21.9976 44.5748 16.1342 53.8026C15.2109 55.1952 14.2582 56.5683 13.277 57.9207C10.5244 58.0604 8.0513 58.1593 5.53119 56.9057C3.13051 55.7166 1.30982 53.611 0.479608 51.0642C-0.20722 48.9684 0.0439338 40.9101 0.0485393 38.1189L0.0519124 24.9623L0.0267357 15.8015C-0.0432674 7.81256 -0.395124 2.77881 8.58399 0.18042Z" fill="#372AAC"/>
|
||||||
|
<path d="M10.1708 0.152124C10.3676 0.150896 10.8088 0.156425 10.9774 0.206778C20.8807 3.15764 31.9872 8.71672 38.1975 17.0526C46.9371 28.783 44.7612 44.5228 42.7919 57.8759L40.5297 57.8706L35.0913 57.8884C38.1419 48.1759 41.6233 31.2005 37.655 21.569C32.838 9.87821 20.818 4.7284 10.1708 0.152124Z" fill="#372AAC"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.6 KiB |
5
public/logo.svg
Normal file
5
public/logo.svg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<svg width="81" height="58" viewBox="0 0 81 58" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M13.5332 0.0605059C16.6649 -0.107743 21.7192 0.126367 25.0234 0.14449L47.7461 0.166951L63.0156 0.155232C65.667 0.142338 69.1473 -0.0926585 71.7178 0.265584C76.9286 0.992005 80.2385 5.82745 80.2812 10.7988C80.3549 19.3927 80.2813 27.8445 80.25 36.373L80.2373 44.5009C80.2302 48.9661 80.5911 51.3666 77.3691 54.8593L77.2021 55.0253C73.9898 58.1924 70.8296 57.9125 66.626 57.8818C64.5719 49.5069 63.0354 41.4784 59.3477 33.5527C50.3209 14.1517 32.0588 6.98865 13.3232 0.0722246L13.5332 0.0605059ZM75.8604 43.2509C75.4023 40.7143 73.0029 39.0071 70.4561 39.4062C68.7552 39.6725 67.332 40.8392 66.7373 42.455C66.1426 44.0706 66.4703 45.882 67.5928 47.1875C68.7149 48.493 70.456 49.0884 72.1426 48.7431C74.6678 48.2261 76.3182 45.7875 75.8604 43.2509Z" fill="white"/>
|
||||||
|
<path d="M8.58399 0.18042C10.3814 0.200991 14.9254 2.92742 16.5327 3.93417C21.7136 7.17947 27.0918 12.0437 28.3657 18.2976C30.6755 29.635 21.9976 44.5748 16.1342 53.8025C15.2109 55.1952 14.2582 56.5683 13.277 57.9207C10.5244 58.0604 8.0513 58.1593 5.53119 56.9057C3.13051 55.7166 1.30982 53.611 0.479608 51.0641C-0.20722 48.9684 0.0439338 40.9101 0.0485393 38.1189L0.0519124 24.9623L0.0267357 15.8015C-0.0432674 7.81256 -0.395124 2.77881 8.58399 0.18042Z" fill="white"/>
|
||||||
|
<path d="M10.1708 0.152124C10.3676 0.150896 10.8088 0.156425 10.9774 0.206778C20.8807 3.15764 31.9872 8.71672 38.1975 17.0526C46.9371 28.783 44.7612 44.5228 42.7919 57.8759L40.5297 57.8706L35.0913 57.8884C38.1419 48.1759 41.6233 31.2005 37.655 21.569C32.838 9.87821 20.818 4.7284 10.1708 0.152124Z" fill="white"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.6 KiB |
@@ -0,0 +1,180 @@
|
|||||||
|
import { CalendarCheck2, ImageIcon, MapPin, Smartphone } from 'lucide-react';
|
||||||
|
|
||||||
|
import DetectionLocationMap from '@/components/map/detectionLocationMap';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import AnnotatedDetectionImage from '@/components/video/annotatedDetectionImage';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import type { DetectionResultItem } from '@/types';
|
||||||
|
import { formatDate } from '@/utils/date';
|
||||||
|
|
||||||
|
import { RepairProofGallery } from '../../../components/repair/RepairProofGallery';
|
||||||
|
import { formatVideoTimestamp, type IssueReviewStatus } from './reviewTypes';
|
||||||
|
|
||||||
|
const REVIEW_STATUS_LABEL: Record<IssueReviewStatus, string> = {
|
||||||
|
not_submitted: 'Awaiting Repair',
|
||||||
|
pending: 'Under Review',
|
||||||
|
approved: 'Approved',
|
||||||
|
rejected: 'Rejected',
|
||||||
|
};
|
||||||
|
|
||||||
|
const REVIEW_STATUS_CLASS: Record<IssueReviewStatus, string> = {
|
||||||
|
not_submitted: 'bg-zinc-500/10 text-zinc-600 dark:text-zinc-300',
|
||||||
|
pending: 'bg-violet-500/10 text-violet-600 dark:text-violet-400',
|
||||||
|
approved: 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400',
|
||||||
|
rejected: 'bg-destructive/10 text-destructive',
|
||||||
|
};
|
||||||
|
|
||||||
|
function MetadataItem({
|
||||||
|
label,
|
||||||
|
value,
|
||||||
|
}: {
|
||||||
|
label: string;
|
||||||
|
value: React.ReactNode;
|
||||||
|
}) {
|
||||||
|
return (
|
||||||
|
<div className="min-w-0 space-y-1 px-4 first:pl-0 last:pr-0">
|
||||||
|
<p className="text-xs text-muted-foreground">{label}</p>
|
||||||
|
<div className="truncate text-sm font-semibold text-foreground">
|
||||||
|
{value}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface IssueEvidencePanelProps {
|
||||||
|
detection: DetectionResultItem;
|
||||||
|
issueNumber: number;
|
||||||
|
videoWidth: number;
|
||||||
|
videoHeight: number;
|
||||||
|
reviewStatus: IssueReviewStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function IssueEvidencePanel({
|
||||||
|
detection,
|
||||||
|
issueNumber,
|
||||||
|
videoWidth,
|
||||||
|
videoHeight,
|
||||||
|
reviewStatus,
|
||||||
|
}: IssueEvidencePanelProps) {
|
||||||
|
const repairProof = detection.repair_proof;
|
||||||
|
const displayName = detection.detection.display_name;
|
||||||
|
const confidence = Math.round(detection.detection.confidence * 100);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="min-w-0 space-y-4">
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="border-b">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<CardTitle className="text-base">
|
||||||
|
{displayName} #{issueNumber}
|
||||||
|
</CardTitle>
|
||||||
|
<Badge
|
||||||
|
variant="secondary"
|
||||||
|
className={cn(REVIEW_STATUS_CLASS[reviewStatus])}
|
||||||
|
>
|
||||||
|
{REVIEW_STATUS_LABEL[reviewStatus]}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="grid grid-cols-2 divide-x sm:grid-cols-4">
|
||||||
|
<MetadataItem
|
||||||
|
label="Video Timestamp"
|
||||||
|
value={formatVideoTimestamp(detection.frame.timestamp_seconds)}
|
||||||
|
/>
|
||||||
|
<MetadataItem label="Frame" value={detection.frame.number} />
|
||||||
|
<MetadataItem label="Confidence" value={`${confidence}%`} />
|
||||||
|
<MetadataItem label="Issue ID" value={detection.detection.id} />
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
|
||||||
|
<div className="grid items-start gap-4 2xl:grid-cols-2">
|
||||||
|
<section className="min-w-0 space-y-2">
|
||||||
|
<p className="flex items-center gap-2 text-sm font-semibold">
|
||||||
|
<ImageIcon className="size-4 text-primary" />
|
||||||
|
Detection Image (Before)
|
||||||
|
</p>
|
||||||
|
<AnnotatedDetectionImage
|
||||||
|
detection={detection}
|
||||||
|
videoWidth={videoWidth}
|
||||||
|
videoHeight={videoHeight}
|
||||||
|
aspectRatio="16 / 9"
|
||||||
|
enableLightbox
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section className="min-w-0 space-y-2">
|
||||||
|
<p className="flex items-center gap-2 text-sm font-semibold">
|
||||||
|
<MapPin className="size-4 text-primary" />
|
||||||
|
Detection Location
|
||||||
|
</p>
|
||||||
|
<DetectionLocationMap
|
||||||
|
latitude={detection.location.latitude}
|
||||||
|
longitude={detection.location.longitude}
|
||||||
|
label={`${displayName} #${issueNumber} - Frame ${detection.frame.number}`}
|
||||||
|
title=""
|
||||||
|
variant="plain"
|
||||||
|
aspectRatio="16 / 9"
|
||||||
|
showCoordinates={false}
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<section className="space-y-4">
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3">
|
||||||
|
<p className="flex items-center gap-2 text-sm font-semibold">
|
||||||
|
<CalendarCheck2 className="size-4 text-primary" />
|
||||||
|
Repair Proof (After Repair)
|
||||||
|
</p>
|
||||||
|
{repairProof?.submitted ? (
|
||||||
|
<Badge className="bg-emerald-500/10 text-emerald-600 dark:text-emerald-400">
|
||||||
|
<Smartphone />
|
||||||
|
Uploaded from App
|
||||||
|
</Badge>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
<div className="space-y-5">
|
||||||
|
{!repairProof?.submitted ? (
|
||||||
|
<div className="rounded-lg border border-dashed bg-muted/20 px-4 py-10 text-center">
|
||||||
|
<p className="text-sm font-medium">
|
||||||
|
Repair proof is not submitted yet.
|
||||||
|
</p>
|
||||||
|
<p className="mt-1 text-xs text-muted-foreground">
|
||||||
|
This issue cannot be reviewed until repair evidence is
|
||||||
|
available.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{repairProof.submitted_at ? (
|
||||||
|
<div className="rounded-lg border border-emerald-500/20 bg-emerald-500/5 px-4 py-3">
|
||||||
|
<p className="text-sm font-semibold text-emerald-700 dark:text-emerald-300">
|
||||||
|
Uploaded from the field app on{' '}
|
||||||
|
{formatDate(repairProof.submitted_at)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
|
||||||
|
<RepairProofGallery
|
||||||
|
imageUrls={repairProof.proof_image_urls}
|
||||||
|
maxVisibleImages={4}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="space-y-1.5 rounded-lg border bg-card p-4 shadow-xs">
|
||||||
|
<p className="text-xs font-semibold text-foreground">
|
||||||
|
Repair Notes
|
||||||
|
</p>
|
||||||
|
<p className="text-sm leading-relaxed whitespace-pre-wrap text-muted-foreground">
|
||||||
|
{repairProof.notes?.trim() ||
|
||||||
|
'No repair notes were provided.'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,216 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
import {
|
||||||
|
Check,
|
||||||
|
CheckCircle2,
|
||||||
|
ClipboardCheck,
|
||||||
|
Info,
|
||||||
|
Loader2,
|
||||||
|
X,
|
||||||
|
XCircle,
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import { Label } from '@/components/ui/label';
|
||||||
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import type {
|
||||||
|
DetectionResultItem,
|
||||||
|
ReviewDetectionRepairProofPayload,
|
||||||
|
} from '@/types';
|
||||||
|
import { formatDate } from '@/utils/date';
|
||||||
|
|
||||||
|
import type { IssueReviewStatus } from './reviewTypes';
|
||||||
|
|
||||||
|
type ReviewDecision = ReviewDetectionRepairProofPayload['action'];
|
||||||
|
|
||||||
|
interface IssueReviewActionProps {
|
||||||
|
detection: DetectionResultItem;
|
||||||
|
issueLabel: string;
|
||||||
|
status: IssueReviewStatus;
|
||||||
|
isPending: boolean;
|
||||||
|
onSave: (payload: ReviewDetectionRepairProofPayload) => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function IssueReviewAction({
|
||||||
|
detection,
|
||||||
|
issueLabel,
|
||||||
|
status,
|
||||||
|
isPending,
|
||||||
|
onSave,
|
||||||
|
}: IssueReviewActionProps) {
|
||||||
|
const [comment, setComment] = useState('');
|
||||||
|
const [decision, setDecision] = useState<ReviewDecision>();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setComment('');
|
||||||
|
setDecision(undefined);
|
||||||
|
}, [detection.detection.id]);
|
||||||
|
|
||||||
|
if (status === 'not_submitted') {
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="border-b">
|
||||||
|
<CardTitle className="flex items-center gap-2 text-base">
|
||||||
|
<ClipboardCheck className="size-5 text-primary" />
|
||||||
|
Review & Action
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent>
|
||||||
|
<div className="rounded-lg border border-dashed bg-muted/30 px-4 py-8 text-center">
|
||||||
|
<Info className="mx-auto size-6 text-muted-foreground" />
|
||||||
|
<p className="mt-3 text-sm font-medium">Repair proof required</p>
|
||||||
|
<p className="mt-1 text-xs text-muted-foreground">
|
||||||
|
{issueLabel} is not ready for review.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status === 'approved' || status === 'rejected') {
|
||||||
|
const isApproved = status === 'approved';
|
||||||
|
const repairProof = detection.repair_proof;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="border-b">
|
||||||
|
<CardTitle className="flex items-center gap-2 text-base">
|
||||||
|
<ClipboardCheck className="size-5 text-primary" />
|
||||||
|
Review Result
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-4">
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'rounded-lg border px-4 py-5 text-center',
|
||||||
|
isApproved
|
||||||
|
? 'border-emerald-500/20 bg-emerald-500/5'
|
||||||
|
: 'border-destructive/20 bg-destructive/5',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{isApproved ? (
|
||||||
|
<CheckCircle2 className="mx-auto size-8 text-emerald-600" />
|
||||||
|
) : (
|
||||||
|
<XCircle className="mx-auto size-8 text-destructive" />
|
||||||
|
)}
|
||||||
|
<Badge
|
||||||
|
className={cn(
|
||||||
|
'mt-3',
|
||||||
|
isApproved
|
||||||
|
? 'bg-emerald-500/10 text-emerald-600'
|
||||||
|
: 'bg-destructive/10 text-destructive',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{isApproved ? 'Approved' : 'Rejected'}
|
||||||
|
</Badge>
|
||||||
|
{repairProof?.reviewed_by_name || repairProof?.reviewed_at ? (
|
||||||
|
<p className="mt-2 text-xs text-muted-foreground">
|
||||||
|
{repairProof.reviewed_by_name
|
||||||
|
? `By ${repairProof.reviewed_by_name}`
|
||||||
|
: 'Reviewed'}
|
||||||
|
{repairProof.reviewed_at
|
||||||
|
? ` on ${formatDate(repairProof.reviewed_at)}`
|
||||||
|
: ''}
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{repairProof?.review_comment ? (
|
||||||
|
<div className="space-y-1.5 rounded-lg bg-muted/30 p-3">
|
||||||
|
<p className="text-xs font-semibold">Review Comment</p>
|
||||||
|
<p className="text-sm whitespace-pre-wrap text-muted-foreground">
|
||||||
|
{repairProof.review_comment}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const submitDecision = async (nextDecision: ReviewDecision) => {
|
||||||
|
setDecision(nextDecision);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await onSave({
|
||||||
|
action: nextDecision,
|
||||||
|
comment: comment.trim() || undefined,
|
||||||
|
});
|
||||||
|
} catch {
|
||||||
|
// The mutation owns user-facing error feedback.
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardHeader className="border-b">
|
||||||
|
<CardTitle className="flex items-center gap-2 text-base">
|
||||||
|
<ClipboardCheck className="size-5 text-primary" />
|
||||||
|
Review & Action
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-5">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label htmlFor="review-comment">Comment (Optional)</Label>
|
||||||
|
<Textarea
|
||||||
|
id="review-comment"
|
||||||
|
value={comment}
|
||||||
|
maxLength={4000}
|
||||||
|
rows={5}
|
||||||
|
disabled={isPending}
|
||||||
|
onChange={(event) => setComment(event.target.value)}
|
||||||
|
placeholder="Enter your review comments..."
|
||||||
|
/>
|
||||||
|
<p className="text-right text-xs text-muted-foreground">
|
||||||
|
{comment.length} / 4000
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Label>Decision</Label>
|
||||||
|
<div className="grid grid-cols-2 gap-2">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
disabled={isPending}
|
||||||
|
onClick={() => void submitDecision('approve')}
|
||||||
|
className={cn(
|
||||||
|
decision === 'approve' &&
|
||||||
|
'border-emerald-500 bg-emerald-500/10 text-emerald-700 hover:bg-emerald-500/15 dark:text-emerald-300',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{isPending && decision === 'approve' ? (
|
||||||
|
<Loader2 className="animate-spin" />
|
||||||
|
) : (
|
||||||
|
<Check />
|
||||||
|
)}
|
||||||
|
Approve
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
disabled={isPending}
|
||||||
|
onClick={() => void submitDecision('reject')}
|
||||||
|
className={cn(
|
||||||
|
decision === 'reject' &&
|
||||||
|
'border-destructive bg-destructive/10 text-destructive hover:bg-destructive/15',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{isPending && decision === 'reject' ? (
|
||||||
|
<Loader2 className="animate-spin" />
|
||||||
|
) : (
|
||||||
|
<X />
|
||||||
|
)}
|
||||||
|
Reject
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
import { ArrowLeft, ChevronLeft, ChevronRight } from 'lucide-react';
|
||||||
|
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
|
||||||
|
import type { ProofStatusFilter } from './reviewTypes';
|
||||||
|
|
||||||
|
const PROOF_STATUS_FILTERS: Array<{
|
||||||
|
value: ProofStatusFilter;
|
||||||
|
label: string;
|
||||||
|
}> = [
|
||||||
|
{ value: 'all', label: 'All' },
|
||||||
|
{ value: 'pending', label: 'Pending' },
|
||||||
|
{ value: 'approved', label: 'Approved' },
|
||||||
|
{ value: 'rejected', label: 'Rejected' },
|
||||||
|
];
|
||||||
|
|
||||||
|
interface IssueReviewHeaderProps {
|
||||||
|
ticketLabel: string;
|
||||||
|
defectLabel: string;
|
||||||
|
currentIndex: number;
|
||||||
|
total: number;
|
||||||
|
proofStatus: ProofStatusFilter;
|
||||||
|
onBack: () => void;
|
||||||
|
onPrevious: () => void;
|
||||||
|
onNext: () => void;
|
||||||
|
onProofStatusChange: (status: ProofStatusFilter) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function IssueReviewHeader({
|
||||||
|
ticketLabel,
|
||||||
|
defectLabel,
|
||||||
|
currentIndex,
|
||||||
|
total,
|
||||||
|
proofStatus,
|
||||||
|
onBack,
|
||||||
|
onPrevious,
|
||||||
|
onNext,
|
||||||
|
onProofStatusChange,
|
||||||
|
}: IssueReviewHeaderProps) {
|
||||||
|
return (
|
||||||
|
<header className="flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between">
|
||||||
|
<div className="flex min-w-0 items-start gap-3">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="secondary"
|
||||||
|
size="icon"
|
||||||
|
onClick={onBack}
|
||||||
|
aria-label="Back to ticket"
|
||||||
|
className="shrink-0"
|
||||||
|
>
|
||||||
|
<ArrowLeft />
|
||||||
|
</Button>
|
||||||
|
<div className="min-w-0 space-y-1">
|
||||||
|
<div className="flex flex-wrap items-center gap-2">
|
||||||
|
<h1 className="truncate text-2xl font-semibold tracking-tight">
|
||||||
|
{defectLabel} Review
|
||||||
|
</h1>
|
||||||
|
<Badge variant="secondary">{ticketLabel}</Badge>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
className="flex max-w-full flex-nowrap items-center gap-1.5 overflow-x-auto pt-1 pb-1"
|
||||||
|
aria-label="Filter issues by repair proof status"
|
||||||
|
>
|
||||||
|
{PROOF_STATUS_FILTERS.map((filter) => {
|
||||||
|
const isActive = proofStatus === filter.value;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
key={filter.value}
|
||||||
|
type="button"
|
||||||
|
size="sm"
|
||||||
|
variant={isActive ? 'default' : 'outline'}
|
||||||
|
aria-pressed={isActive}
|
||||||
|
onClick={() => onProofStatusChange(filter.value)}
|
||||||
|
className="h-7 shrink-0 rounded-full px-3 text-xs"
|
||||||
|
>
|
||||||
|
{filter.label}
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2 self-end lg:self-auto">
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
disabled={total === 0 || currentIndex <= 0}
|
||||||
|
onClick={onPrevious}
|
||||||
|
aria-label="Previous issue"
|
||||||
|
>
|
||||||
|
<ChevronLeft />
|
||||||
|
</Button>
|
||||||
|
<div className="min-w-16 text-center text-sm font-semibold">
|
||||||
|
{total === 0 ? '0 of 0' : `${currentIndex + 1} of ${total}`}
|
||||||
|
</div>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
disabled={total === 0 || currentIndex >= total - 1}
|
||||||
|
onClick={onNext}
|
||||||
|
aria-label="Next issue"
|
||||||
|
>
|
||||||
|
<ChevronRight />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect, useRef } from 'react';
|
||||||
|
import {
|
||||||
|
CheckCircle2,
|
||||||
|
Clock3,
|
||||||
|
Hourglass,
|
||||||
|
ListChecks,
|
||||||
|
Wrench,
|
||||||
|
XCircle,
|
||||||
|
} from 'lucide-react';
|
||||||
|
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from '@/components/ui/tooltip';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import type { DetectionResultItem } from '@/types';
|
||||||
|
|
||||||
|
import {
|
||||||
|
formatVideoTimestamp,
|
||||||
|
getIssueId,
|
||||||
|
getIssueReviewStatus,
|
||||||
|
type IssueReviewStatus,
|
||||||
|
} from './reviewTypes';
|
||||||
|
|
||||||
|
const STATUS_CONFIG: Record<
|
||||||
|
IssueReviewStatus,
|
||||||
|
{
|
||||||
|
label: string;
|
||||||
|
icon: typeof Hourglass;
|
||||||
|
className: string;
|
||||||
|
}
|
||||||
|
> = {
|
||||||
|
not_submitted: {
|
||||||
|
label: 'Awaiting Repair',
|
||||||
|
icon: Wrench,
|
||||||
|
className: 'bg-zinc-500/10 text-zinc-600 dark:text-zinc-300',
|
||||||
|
},
|
||||||
|
pending: {
|
||||||
|
label: 'Under Review',
|
||||||
|
icon: Hourglass,
|
||||||
|
className: 'bg-violet-500/10 text-violet-600 dark:text-violet-400',
|
||||||
|
},
|
||||||
|
approved: {
|
||||||
|
label: 'Approved',
|
||||||
|
icon: CheckCircle2,
|
||||||
|
className: 'bg-emerald-500/10 text-emerald-600 dark:text-emerald-400',
|
||||||
|
},
|
||||||
|
rejected: {
|
||||||
|
label: 'Rejected',
|
||||||
|
icon: XCircle,
|
||||||
|
className: 'bg-destructive/10 text-destructive',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
interface IssueReviewQueueProps {
|
||||||
|
detections: DetectionResultItem[];
|
||||||
|
totalCount: number;
|
||||||
|
selectedIssueId?: string;
|
||||||
|
hasNextPage: boolean;
|
||||||
|
isFetchingNextPage: boolean;
|
||||||
|
onSelect: (issueId: string) => void;
|
||||||
|
onLoadMore: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function IssueReviewQueue({
|
||||||
|
detections,
|
||||||
|
totalCount,
|
||||||
|
selectedIssueId,
|
||||||
|
hasNextPage,
|
||||||
|
isFetchingNextPage,
|
||||||
|
onSelect,
|
||||||
|
onLoadMore,
|
||||||
|
}: IssueReviewQueueProps) {
|
||||||
|
const loadMoreRef = useRef<HTMLDivElement>(null);
|
||||||
|
const defectLabel = detections[0]?.detection.display_name ?? 'Detected';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const target = loadMoreRef.current;
|
||||||
|
if (!target || !hasNextPage || isFetchingNextPage) return;
|
||||||
|
|
||||||
|
const root = target.closest<HTMLElement>(
|
||||||
|
'[data-slot="scroll-area-viewport"]',
|
||||||
|
);
|
||||||
|
const observer = new IntersectionObserver(
|
||||||
|
(entries) => {
|
||||||
|
if (entries[0]?.isIntersecting) onLoadMore();
|
||||||
|
},
|
||||||
|
{ root, rootMargin: '160px 0px' },
|
||||||
|
);
|
||||||
|
|
||||||
|
observer.observe(target);
|
||||||
|
return () => observer.disconnect();
|
||||||
|
}, [hasNextPage, isFetchingNextPage, onLoadMore]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Card className="overflow-hidden xl:h-full xl:min-h-0">
|
||||||
|
<CardHeader className="border-b">
|
||||||
|
<CardTitle className="flex items-center gap-2 text-base">
|
||||||
|
<ListChecks className="size-5 text-primary" />
|
||||||
|
{defectLabel} Issues
|
||||||
|
<Badge variant="secondary" className="ml-auto rounded-full">
|
||||||
|
{totalCount}
|
||||||
|
</Badge>
|
||||||
|
</CardTitle>
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="min-h-0 flex-1 p-2">
|
||||||
|
<ScrollArea className="h-112 pr-2 xl:h-full">
|
||||||
|
<div className="space-y-2 p-1">
|
||||||
|
{detections.map((detection, index) => {
|
||||||
|
const issueId = getIssueId(detection);
|
||||||
|
const status = getIssueReviewStatus(detection);
|
||||||
|
const config = STATUS_CONFIG[status];
|
||||||
|
const StatusIcon = config.icon;
|
||||||
|
const isSelected = issueId === selectedIssueId;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
key={detection.id}
|
||||||
|
type="button"
|
||||||
|
onClick={() => onSelect(issueId)}
|
||||||
|
aria-current={isSelected ? 'true' : undefined}
|
||||||
|
className={cn(
|
||||||
|
'w-full rounded-lg border p-3 text-left transition-colors',
|
||||||
|
'hover:border-primary/40 hover:bg-muted/50',
|
||||||
|
isSelected
|
||||||
|
? 'border-primary bg-primary/6 shadow-sm'
|
||||||
|
: 'border-border bg-card',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<div className="min-w-0 space-y-2">
|
||||||
|
<div className="flex min-w-0 items-center justify-between gap-2">
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<p className="min-w-0 flex-1 truncate text-sm font-semibold">
|
||||||
|
{defectLabel} #{index + 1}
|
||||||
|
</p>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent side="top">
|
||||||
|
{defectLabel} #{index + 1}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
<span className="flex shrink-0 items-center gap-1.5 text-xs text-muted-foreground">
|
||||||
|
<Clock3 className="size-3.5" />
|
||||||
|
{formatVideoTimestamp(
|
||||||
|
detection.frame.timestamp_seconds,
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
|
||||||
|
<Badge
|
||||||
|
variant="secondary"
|
||||||
|
className={cn('shrink-0 px-1.5', config.className)}
|
||||||
|
>
|
||||||
|
<StatusIcon />
|
||||||
|
{config.label}
|
||||||
|
</Badge>
|
||||||
|
<span aria-hidden="true">|</span>
|
||||||
|
<span>Frame {detection.frame.number}</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
|
||||||
|
<div ref={loadMoreRef} className="space-y-2 py-1">
|
||||||
|
{isFetchingNextPage ? (
|
||||||
|
<>
|
||||||
|
<Skeleton className="h-20 w-full" />
|
||||||
|
<Skeleton className="h-20 w-full" />
|
||||||
|
</>
|
||||||
|
) : hasNextPage ? (
|
||||||
|
<p className="py-3 text-center text-xs text-muted-foreground">
|
||||||
|
Scroll to load more issues
|
||||||
|
</p>
|
||||||
|
) : detections.length > 0 ? (
|
||||||
|
<p className="py-3 text-center text-xs text-muted-foreground">
|
||||||
|
All {totalCount} issues loaded
|
||||||
|
</p>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ScrollArea>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
import { Card, CardContent, CardHeader } from '@/components/ui/card';
|
||||||
|
import { Skeleton } from '@/components/ui/skeleton';
|
||||||
|
|
||||||
|
export function IssueReviewSkeleton() {
|
||||||
|
return (
|
||||||
|
<div className="space-y-5">
|
||||||
|
<div className="flex items-center justify-between gap-4">
|
||||||
|
<div className="space-y-2">
|
||||||
|
<Skeleton className="h-8 w-56" />
|
||||||
|
<Skeleton className="h-4 w-36" />
|
||||||
|
</div>
|
||||||
|
<Skeleton className="h-9 w-32" />
|
||||||
|
</div>
|
||||||
|
<div className="grid gap-5 xl:grid-cols-[280px_minmax(0,1fr)_330px]">
|
||||||
|
{[280, 600, 330].map((width) => (
|
||||||
|
<Card key={width}>
|
||||||
|
<CardHeader className="border-b">
|
||||||
|
<Skeleton className="h-5 w-40" />
|
||||||
|
</CardHeader>
|
||||||
|
<CardContent className="space-y-3">
|
||||||
|
{Array.from({ length: 4 }, (_, index) => (
|
||||||
|
<Skeleton key={index} className="h-20 w-full" />
|
||||||
|
))}
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import type { DetectionProofStatus, DetectionResultItem } from '@/types';
|
||||||
|
|
||||||
|
export type ProofStatusFilter =
|
||||||
|
| 'all'
|
||||||
|
| Extract<DetectionProofStatus, 'pending' | 'approved' | 'rejected'>;
|
||||||
|
|
||||||
|
export type IssueReviewStatus =
|
||||||
|
| 'not_submitted'
|
||||||
|
| 'pending'
|
||||||
|
| 'approved'
|
||||||
|
| 'rejected';
|
||||||
|
|
||||||
|
export function getIssueId(detection: DetectionResultItem) {
|
||||||
|
return String(detection.detection.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getIssueReviewStatus(
|
||||||
|
detection: DetectionResultItem,
|
||||||
|
): IssueReviewStatus {
|
||||||
|
const repairProof = detection.repair_proof;
|
||||||
|
if (!repairProof?.submitted) return 'not_submitted';
|
||||||
|
|
||||||
|
return repairProof.review_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatVideoTimestamp(totalSeconds: number) {
|
||||||
|
const seconds = Math.max(0, Math.floor(totalSeconds));
|
||||||
|
const minutes = Math.floor(seconds / 60);
|
||||||
|
const remainder = seconds % 60;
|
||||||
|
|
||||||
|
return `${minutes}:${remainder.toString().padStart(2, '0')}`;
|
||||||
|
}
|
||||||
@@ -0,0 +1,325 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useCallback, useEffect, useMemo } from 'react';
|
||||||
|
import {
|
||||||
|
useParams,
|
||||||
|
usePathname,
|
||||||
|
useRouter,
|
||||||
|
useSearchParams,
|
||||||
|
} from 'next/navigation';
|
||||||
|
import { AlertTriangle, ClipboardCheck } from 'lucide-react';
|
||||||
|
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Card, CardContent } from '@/components/ui/card';
|
||||||
|
import { PERMISSIONS } from '@/constants/permissions';
|
||||||
|
import { PermissionGuard } from '@/guards';
|
||||||
|
import { ROUTES } from '@/utils/routes';
|
||||||
|
import type { ReviewDetectionRepairProofPayload } from '@/types';
|
||||||
|
|
||||||
|
import {
|
||||||
|
useReviewDetectionRepairProofMutation,
|
||||||
|
useTicketClassReviewDetectionsQuery,
|
||||||
|
useTicketOverviewQuery,
|
||||||
|
} from '../../../hooks/useTicketQueries';
|
||||||
|
import { IssueEvidencePanel } from './components/IssueEvidencePanel';
|
||||||
|
import { IssueReviewAction } from './components/IssueReviewAction';
|
||||||
|
import { IssueReviewHeader } from './components/IssueReviewHeader';
|
||||||
|
import { IssueReviewQueue } from './components/IssueReviewQueue';
|
||||||
|
import { IssueReviewSkeleton } from './components/IssueReviewSkeleton';
|
||||||
|
import {
|
||||||
|
getIssueId,
|
||||||
|
getIssueReviewStatus,
|
||||||
|
type ProofStatusFilter,
|
||||||
|
} from './components/reviewTypes';
|
||||||
|
|
||||||
|
const PROOF_STATUS_FILTERS: ProofStatusFilter[] = [
|
||||||
|
'all',
|
||||||
|
'pending',
|
||||||
|
'approved',
|
||||||
|
'rejected',
|
||||||
|
];
|
||||||
|
|
||||||
|
export default function TicketClassReviewPage() {
|
||||||
|
const router = useRouter();
|
||||||
|
const pathname = usePathname();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const { ticketId, defectClass } = useParams() as {
|
||||||
|
ticketId: string;
|
||||||
|
defectClass: string;
|
||||||
|
};
|
||||||
|
const proofStatusParam = searchParams.get('proof_status');
|
||||||
|
const proofStatus: ProofStatusFilter = PROOF_STATUS_FILTERS.includes(
|
||||||
|
proofStatusParam as ProofStatusFilter,
|
||||||
|
)
|
||||||
|
? (proofStatusParam as ProofStatusFilter)
|
||||||
|
: 'all';
|
||||||
|
|
||||||
|
const overviewQuery = useTicketOverviewQuery(ticketId);
|
||||||
|
const ticket = overviewQuery.data;
|
||||||
|
const videoId = ticket?.video_id ?? ticket?.video?.id ?? undefined;
|
||||||
|
const detectionsQuery = useTicketClassReviewDetectionsQuery(
|
||||||
|
videoId,
|
||||||
|
defectClass,
|
||||||
|
proofStatus === 'all' ? 'submitted' : proofStatus,
|
||||||
|
);
|
||||||
|
const detectionResult = detectionsQuery.data?.pages[0];
|
||||||
|
const detections = useMemo(
|
||||||
|
() => detectionsQuery.data?.pages.flatMap((page) => page.items) ?? [],
|
||||||
|
[detectionsQuery.data?.pages],
|
||||||
|
);
|
||||||
|
const totalCount = detectionResult?.total ?? 0;
|
||||||
|
const selectedIssueParam = searchParams.get('issue_id') ?? undefined;
|
||||||
|
const reviewMutation = useReviewDetectionRepairProofMutation({
|
||||||
|
ticketId,
|
||||||
|
videoId,
|
||||||
|
defectClass,
|
||||||
|
});
|
||||||
|
|
||||||
|
const selectIssue = useCallback(
|
||||||
|
(issueId: string) => {
|
||||||
|
const nextParams = new URLSearchParams(searchParams.toString());
|
||||||
|
nextParams.set('issue_id', issueId);
|
||||||
|
router.replace(`${pathname}?${nextParams.toString()}`, { scroll: false });
|
||||||
|
},
|
||||||
|
[pathname, router, searchParams],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleProofStatusChange = useCallback(
|
||||||
|
(status: ProofStatusFilter) => {
|
||||||
|
const nextParams = new URLSearchParams(searchParams.toString());
|
||||||
|
if (status === 'all') {
|
||||||
|
nextParams.delete('proof_status');
|
||||||
|
} else {
|
||||||
|
nextParams.set('proof_status', status);
|
||||||
|
}
|
||||||
|
nextParams.delete('issue_id');
|
||||||
|
const query = nextParams.toString();
|
||||||
|
router.replace(query ? `${pathname}?${query}` : pathname, {
|
||||||
|
scroll: false,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[pathname, router, searchParams],
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!detections.length) return;
|
||||||
|
|
||||||
|
const hasSelectedIssue = detections.some(
|
||||||
|
(detection) => getIssueId(detection) === selectedIssueParam,
|
||||||
|
);
|
||||||
|
if (hasSelectedIssue) return;
|
||||||
|
|
||||||
|
if (
|
||||||
|
selectedIssueParam &&
|
||||||
|
detectionsQuery.hasNextPage &&
|
||||||
|
!detectionsQuery.isFetchingNextPage
|
||||||
|
) {
|
||||||
|
void detectionsQuery.fetchNextPage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstReviewable = detections.find(
|
||||||
|
(detection) => getIssueReviewStatus(detection) === 'pending',
|
||||||
|
);
|
||||||
|
selectIssue(getIssueId(firstReviewable ?? detections[0]));
|
||||||
|
}, [detections, detectionsQuery, selectIssue, selectedIssueParam]);
|
||||||
|
|
||||||
|
const activeIndex = Math.max(
|
||||||
|
0,
|
||||||
|
detections.findIndex(
|
||||||
|
(detection) => getIssueId(detection) === selectedIssueParam,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
const activeDetection = detections[activeIndex];
|
||||||
|
const activeIssueId = activeDetection
|
||||||
|
? getIssueId(activeDetection)
|
||||||
|
: undefined;
|
||||||
|
const activeReviewStatus = activeDetection
|
||||||
|
? getIssueReviewStatus(activeDetection)
|
||||||
|
: 'not_submitted';
|
||||||
|
|
||||||
|
const handleSaveReview = useCallback(
|
||||||
|
async (payload: ReviewDetectionRepairProofPayload) => {
|
||||||
|
if (!activeDetection) return;
|
||||||
|
|
||||||
|
await reviewMutation.mutateAsync({
|
||||||
|
detectionId: activeDetection.detection.id,
|
||||||
|
payload,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
[activeDetection, reviewMutation],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleNext = useCallback(async () => {
|
||||||
|
if (activeIndex < detections.length - 1) {
|
||||||
|
selectIssue(getIssueId(detections[activeIndex + 1]));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!detectionsQuery.hasNextPage) return;
|
||||||
|
const nextResult = await detectionsQuery.fetchNextPage();
|
||||||
|
const nextDetections =
|
||||||
|
nextResult.data?.pages.flatMap((page) => page.items) ?? [];
|
||||||
|
const nextDetection = nextDetections[activeIndex + 1];
|
||||||
|
if (nextDetection) selectIssue(getIssueId(nextDetection));
|
||||||
|
}, [activeIndex, detections, detectionsQuery, selectIssue]);
|
||||||
|
|
||||||
|
const handleLoadMore = useCallback(() => {
|
||||||
|
if (detectionsQuery.hasNextPage && !detectionsQuery.isFetchingNextPage) {
|
||||||
|
void detectionsQuery.fetchNextPage();
|
||||||
|
}
|
||||||
|
}, [detectionsQuery]);
|
||||||
|
|
||||||
|
const backToTicket = () => {
|
||||||
|
const params = new URLSearchParams({ defect_class: defectClass });
|
||||||
|
router.push(`${ROUTES.TICKET_DETAIL(ticketId)}?${params.toString()}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (overviewQuery.isLoading || (videoId && detectionsQuery.isLoading)) {
|
||||||
|
return <IssueReviewSkeleton />;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (overviewQuery.isError || !ticket || !videoId) {
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardContent className="flex min-h-80 flex-col items-center justify-center gap-3 text-center">
|
||||||
|
<AlertTriangle className="size-8 text-destructive" />
|
||||||
|
<div>
|
||||||
|
<p className="font-semibold">
|
||||||
|
Unable to open the review workspace.
|
||||||
|
</p>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">
|
||||||
|
Ticket or video information is unavailable.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<Button type="button" variant="outline" onClick={backToTicket}>
|
||||||
|
Back to Ticket
|
||||||
|
</Button>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (detectionsQuery.isError) {
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<CardContent className="flex min-h-80 flex-col items-center justify-center gap-3 text-center">
|
||||||
|
<AlertTriangle className="size-8 text-destructive" />
|
||||||
|
<div>
|
||||||
|
<p className="font-semibold">Failed to load class detections.</p>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">
|
||||||
|
The review screen uses the detection API for its queue and
|
||||||
|
evidence.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<Button type="button" variant="outline" onClick={backToTicket}>
|
||||||
|
Back
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
onClick={() => void detectionsQuery.refetch()}
|
||||||
|
>
|
||||||
|
Retry
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!activeDetection || !detectionResult) {
|
||||||
|
return (
|
||||||
|
<div className="space-y-5">
|
||||||
|
<IssueReviewHeader
|
||||||
|
ticketLabel={ticket.ticket_name || ticket.id}
|
||||||
|
defectLabel={defectClass}
|
||||||
|
currentIndex={0}
|
||||||
|
total={0}
|
||||||
|
proofStatus={proofStatus}
|
||||||
|
onBack={backToTicket}
|
||||||
|
onPrevious={() => undefined}
|
||||||
|
onNext={() => undefined}
|
||||||
|
onProofStatusChange={handleProofStatusChange}
|
||||||
|
/>
|
||||||
|
<Card>
|
||||||
|
<CardContent className="flex min-h-80 flex-col items-center justify-center gap-3 text-center">
|
||||||
|
<ClipboardCheck className="size-8 text-muted-foreground" />
|
||||||
|
<div>
|
||||||
|
<p className="font-semibold">No detections found.</p>
|
||||||
|
<p className="mt-1 text-sm text-muted-foreground">
|
||||||
|
There are no {defectClass} issues available for review.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const defectLabel = activeDetection.detection.display_name;
|
||||||
|
return (
|
||||||
|
<main className="relative z-10 space-y-5 xl:flex xl:h-[calc(100vh-6.5rem)] xl:min-h-0 xl:flex-col xl:gap-5 xl:space-y-0 xl:overflow-hidden">
|
||||||
|
<IssueReviewHeader
|
||||||
|
ticketLabel={ticket.ticket_name || ticket.id}
|
||||||
|
defectLabel={defectLabel}
|
||||||
|
currentIndex={activeIndex}
|
||||||
|
total={totalCount}
|
||||||
|
proofStatus={proofStatus}
|
||||||
|
onBack={backToTicket}
|
||||||
|
onPrevious={() =>
|
||||||
|
selectIssue(getIssueId(detections[Math.max(0, activeIndex - 1)]))
|
||||||
|
}
|
||||||
|
onNext={() => void handleNext()}
|
||||||
|
onProofStatusChange={handleProofStatusChange}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="grid items-start gap-5 xl:min-h-0 xl:flex-1 xl:grid-cols-[280px_minmax(0,1fr)_330px] xl:items-stretch xl:overflow-hidden">
|
||||||
|
<IssueReviewQueue
|
||||||
|
detections={detections}
|
||||||
|
totalCount={totalCount}
|
||||||
|
selectedIssueId={activeIssueId}
|
||||||
|
hasNextPage={Boolean(detectionsQuery.hasNextPage)}
|
||||||
|
isFetchingNextPage={detectionsQuery.isFetchingNextPage}
|
||||||
|
onSelect={selectIssue}
|
||||||
|
onLoadMore={handleLoadMore}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div className="min-w-0 xl:h-full xl:min-h-0 xl:overflow-y-auto xl:pr-2">
|
||||||
|
<IssueEvidencePanel
|
||||||
|
detection={activeDetection}
|
||||||
|
issueNumber={activeIndex + 1}
|
||||||
|
videoWidth={detectionResult.video_width}
|
||||||
|
videoHeight={detectionResult.video_height}
|
||||||
|
reviewStatus={activeReviewStatus}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="min-w-0 xl:h-full xl:min-h-0 xl:overflow-y-auto xl:pr-2">
|
||||||
|
<PermissionGuard
|
||||||
|
permissions={PERMISSIONS.TICKET.REVIEW}
|
||||||
|
fallback={
|
||||||
|
<Card>
|
||||||
|
<CardContent className="py-8 text-center">
|
||||||
|
<ClipboardCheck className="mx-auto size-7 text-muted-foreground" />
|
||||||
|
<p className="mt-3 text-sm font-semibold">View-only access</p>
|
||||||
|
<p className="mt-1 text-xs text-muted-foreground">
|
||||||
|
Review permission is required to take action.
|
||||||
|
</p>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<IssueReviewAction
|
||||||
|
detection={activeDetection}
|
||||||
|
issueLabel={`${defectLabel} #${activeIndex + 1}`}
|
||||||
|
status={activeReviewStatus}
|
||||||
|
isPending={reviewMutation.isPending}
|
||||||
|
onSave={handleSaveReview}
|
||||||
|
/>
|
||||||
|
</PermissionGuard>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -131,12 +131,6 @@ export function TicketClassDetectionPreview({
|
|||||||
const detectionResult = detectionsQuery.data;
|
const detectionResult = detectionsQuery.data;
|
||||||
const activeDetection = detectionResult?.items[0];
|
const activeDetection = detectionResult?.items[0];
|
||||||
const detectionCount = detectionResult?.total ?? totalCount ?? 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(() => {
|
useEffect(() => {
|
||||||
if (detectionCount === 0 && currentIndex !== 0) {
|
if (detectionCount === 0 && currentIndex !== 0) {
|
||||||
@@ -249,11 +243,13 @@ export function TicketClassDetectionPreview({
|
|||||||
<div className="grid grid-cols-1 items-start gap-4 xl:grid-cols-2">
|
<div className="grid grid-cols-1 items-start gap-4 xl:grid-cols-2">
|
||||||
<div className="min-w-0 space-y-2">
|
<div className="min-w-0 space-y-2">
|
||||||
<p className="text-muted-foreground">Detection Image</p>
|
<p className="text-muted-foreground">Detection Image</p>
|
||||||
<div className="overflow-hidden rounded-lg">
|
<div className="w-full overflow-hidden rounded-lg">
|
||||||
<AnnotatedDetectionImage
|
<AnnotatedDetectionImage
|
||||||
detection={activeDetection}
|
detection={activeDetection}
|
||||||
videoWidth={detectionResult.video_width}
|
videoWidth={detectionResult.video_width}
|
||||||
videoHeight={detectionResult.video_height}
|
videoHeight={detectionResult.video_height}
|
||||||
|
aspectRatio="16 / 9"
|
||||||
|
enableLightbox
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -265,7 +261,7 @@ export function TicketClassDetectionPreview({
|
|||||||
label={`${displayName} - Frame ${activeDetection.frame.number}`}
|
label={`${displayName} - Frame ${activeDetection.frame.number}`}
|
||||||
title="Location on Map"
|
title="Location on Map"
|
||||||
variant="plain"
|
variant="plain"
|
||||||
aspectRatio={mediaAspectRatio}
|
aspectRatio="16 / 9"
|
||||||
showCoordinates={false}
|
showCoordinates={false}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,10 +8,9 @@ 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 { OpenRepairReviewAction } from './actions/OpenRepairReviewAction';
|
||||||
|
import { RequestExtensionAction } from './actions/RequestExtensionAction';
|
||||||
import { ReviewExtensionRequestAction } from './actions/ReviewExtensionRequestAction';
|
import { ReviewExtensionRequestAction } from './actions/ReviewExtensionRequestAction';
|
||||||
import { ReviewRepairAction } from './actions/ReviewRepairAction';
|
|
||||||
import { SubmittedRepairProofAction } from './actions/SubmittedRepairProofAction';
|
|
||||||
import { SubmitRepairAction } from './actions/SubmitRepairAction';
|
|
||||||
|
|
||||||
interface TicketStatusActionsProps {
|
interface TicketStatusActionsProps {
|
||||||
ticket: TicketDetail;
|
ticket: TicketDetail;
|
||||||
@@ -38,7 +37,7 @@ function getTicketAction(ticket: TicketDetail) {
|
|||||||
permissions={PERMISSIONS.TICKET.WORK}
|
permissions={PERMISSIONS.TICKET.WORK}
|
||||||
fallback={<NoTicketAction />}
|
fallback={<NoTicketAction />}
|
||||||
>
|
>
|
||||||
<SubmitRepairAction ticket={ticket} />
|
<RequestExtensionAction ticket={ticket} />
|
||||||
</PermissionGuard>
|
</PermissionGuard>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
@@ -56,7 +55,7 @@ function getTicketAction(ticket: TicketDetail) {
|
|||||||
permissions={PERMISSIONS.TICKET.REVIEW}
|
permissions={PERMISSIONS.TICKET.REVIEW}
|
||||||
fallback={<NoTicketAction />}
|
fallback={<NoTicketAction />}
|
||||||
>
|
>
|
||||||
<ReviewRepairAction ticket={ticket} />
|
<OpenRepairReviewAction ticket={ticket} />
|
||||||
</PermissionGuard>
|
</PermissionGuard>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -72,15 +71,5 @@ function getTicketAction(ticket: TicketDetail) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function TicketStatusActions({ ticket }: TicketStatusActionsProps) {
|
export function TicketStatusActions({ ticket }: TicketStatusActionsProps) {
|
||||||
const action = getTicketAction(ticket);
|
return <div className="space-y-3">{getTicketAction(ticket)}</div>;
|
||||||
const submittedProof = ticket.repair?.submitted_at ? (
|
|
||||||
<SubmittedRepairProofAction ticket={ticket} />
|
|
||||||
) : null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="space-y-3">
|
|
||||||
{submittedProof}
|
|
||||||
{action}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
import { ArrowRight, ClipboardCheck } from 'lucide-react';
|
||||||
|
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import type { TicketDetail } from '@/types';
|
||||||
|
import { ROUTES } from '@/utils/routes';
|
||||||
|
|
||||||
|
import { TicketActionCard } from './TicketActionCard';
|
||||||
|
|
||||||
|
export function OpenRepairReviewAction({ ticket }: { ticket: TicketDetail }) {
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TicketActionCard icon={ClipboardCheck} title="Review Submitted Repairs">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<p className="text-sm leading-relaxed text-muted-foreground">
|
||||||
|
Review every submitted repair separately using its detection image,
|
||||||
|
location, and repair proof.
|
||||||
|
</p>
|
||||||
|
<Button
|
||||||
|
type="button"
|
||||||
|
className="w-full"
|
||||||
|
onClick={() =>
|
||||||
|
router.push(
|
||||||
|
ROUTES.TICKET_CLASS_REVIEW(ticket.id, ticket.defect_class),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Open Issue Review
|
||||||
|
<ArrowRight />
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</TicketActionCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,485 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
||||||
import {
|
|
||||||
Camera,
|
|
||||||
ImageIcon,
|
|
||||||
Loader2,
|
|
||||||
Play,
|
|
||||||
Plus,
|
|
||||||
Send,
|
|
||||||
Video,
|
|
||||||
X,
|
|
||||||
} from 'lucide-react';
|
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import { Label } from '@/components/ui/label';
|
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
|
||||||
import { cn } from '@/lib/utils';
|
|
||||||
|
|
||||||
import { useSubmitRepairUploadMutation } from '../../../hooks/useTicketQueries';
|
|
||||||
|
|
||||||
const MAX_IMAGES = 30;
|
|
||||||
const MAX_NOTES = 500;
|
|
||||||
|
|
||||||
function RequiredMark() {
|
|
||||||
return <span className="text-destructive">*</span>;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
title: string;
|
|
||||||
addLabel: string;
|
|
||||||
onAdd: () => void;
|
|
||||||
disabled?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
function MediaSectionHeader({
|
|
||||||
icon,
|
|
||||||
title,
|
|
||||||
addLabel,
|
|
||||||
onAdd,
|
|
||||||
disabled = false,
|
|
||||||
}: MediaSectionHeaderProps) {
|
|
||||||
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 (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
disabled={disabled}
|
|
||||||
onClick={onClick}
|
|
||||||
className={cn(
|
|
||||||
'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/40 hover:bg-primary/5',
|
|
||||||
disabled && 'cursor-not-allowed opacity-60',
|
|
||||||
className,
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<span className="flex size-10 items-center justify-center rounded-full bg-primary/10 text-primary">
|
|
||||||
{icon}
|
|
||||||
</span>
|
|
||||||
<span className="text-sm font-medium text-foreground">{title}</span>
|
|
||||||
<span className="max-w-xs text-xs text-muted-foreground">
|
|
||||||
{description}
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ImageThumbnailProps {
|
|
||||||
file: File;
|
|
||||||
previewUrl: string;
|
|
||||||
disabled?: boolean;
|
|
||||||
onRemove: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
function ImageThumbnail({
|
|
||||||
file,
|
|
||||||
previewUrl,
|
|
||||||
disabled = false,
|
|
||||||
onRemove,
|
|
||||||
}: ImageThumbnailProps) {
|
|
||||||
return (
|
|
||||||
<div className="group relative size-20 shrink-0 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 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 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 {
|
|
||||||
ticketId: string;
|
|
||||||
defectClass: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function RepairEvidenceForm({
|
|
||||||
ticketId,
|
|
||||||
defectClass,
|
|
||||||
}: RepairEvidenceFormProps) {
|
|
||||||
const imageInputRef = useRef<HTMLInputElement | null>(null);
|
|
||||||
const videoInputRef = useRef<HTMLInputElement | null>(null);
|
|
||||||
const [notes, setNotes] = useState('');
|
|
||||||
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 [imagePreviews, setImagePreviews] = useState<string[]>([]);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const submitRepairUploadMutation = useSubmitRepairUploadMutation(ticketId);
|
|
||||||
const isSubmitting = submitRepairUploadMutation.isPending;
|
|
||||||
const canSubmit = Boolean(notes.trim() && videoFile);
|
|
||||||
const canAddMoreImages = imageFiles.length < MAX_IMAGES;
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const urls = imageFiles.map((file) => URL.createObjectURL(file));
|
|
||||||
setImagePreviews(urls);
|
|
||||||
return () => {
|
|
||||||
urls.forEach((url) => URL.revokeObjectURL(url));
|
|
||||||
};
|
|
||||||
}, [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) => {
|
|
||||||
if (!files?.length) return;
|
|
||||||
|
|
||||||
const remaining = MAX_IMAGES - imageFiles.length;
|
|
||||||
if (remaining <= 0) {
|
|
||||||
setError(`Only ${MAX_IMAGES} images can be uploaded.`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextImages = [
|
|
||||||
...imageFiles,
|
|
||||||
...Array.from(files).slice(0, remaining),
|
|
||||||
];
|
|
||||||
setImageFiles(nextImages);
|
|
||||||
setError(
|
|
||||||
files.length > remaining
|
|
||||||
? `Only ${MAX_IMAGES} images can be uploaded.`
|
|
||||||
: null,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const selectVideo = (files: FileList | null) => {
|
|
||||||
setVideoFile(files?.[0] ?? null);
|
|
||||||
setError(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeVideo = () => {
|
|
||||||
setVideoFile(null);
|
|
||||||
setError(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
const removeImage = (index: number) => {
|
|
||||||
setImageFiles((current) =>
|
|
||||||
current.filter((_, itemIndex) => itemIndex !== index),
|
|
||||||
);
|
|
||||||
setError(null);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSubmit = async () => {
|
|
||||||
if (!notes.trim() || !videoFile) {
|
|
||||||
setError('Repair notes and a video are required.');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setError(null);
|
|
||||||
try {
|
|
||||||
await submitRepairUploadMutation.mutateAsync({
|
|
||||||
defect_class: defectClass,
|
|
||||||
notes: notes.trim(),
|
|
||||||
video: videoFile,
|
|
||||||
images: imageFiles,
|
|
||||||
});
|
|
||||||
setNotes('');
|
|
||||||
setVideoFile(null);
|
|
||||||
setImageFiles([]);
|
|
||||||
} catch (err) {
|
|
||||||
setError(err instanceof Error ? err.message : 'Upload failed');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const openImagePicker = () => {
|
|
||||||
if (!isSubmitting && canAddMoreImages) {
|
|
||||||
imageInputRef.current?.click();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const openVideoPicker = () => {
|
|
||||||
if (!isSubmitting) {
|
|
||||||
videoInputRef.current?.click();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<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">
|
|
||||||
<Label htmlFor="repair-notes">
|
|
||||||
Repair Notes <RequiredMark />
|
|
||||||
</Label>
|
|
||||||
<div className="relative">
|
|
||||||
<Textarea
|
|
||||||
id="repair-notes"
|
|
||||||
value={notes}
|
|
||||||
onChange={(event) => {
|
|
||||||
setNotes(event.target.value.slice(0, MAX_NOTES));
|
|
||||||
setError(null);
|
|
||||||
}}
|
|
||||||
placeholder="Describe the repair work completed, materials used, and any additional observations."
|
|
||||||
disabled={isSubmitting}
|
|
||||||
className="min-h-28 resize-none pb-8"
|
|
||||||
/>
|
|
||||||
<span className="pointer-events-none absolute bottom-2 right-3 text-xs text-muted-foreground">
|
|
||||||
{notes.length} / {MAX_NOTES}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{error ? (
|
|
||||||
<div className="rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-sm text-destructive">
|
|
||||||
{error}
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
className="w-full"
|
|
||||||
disabled={!canSubmit || isSubmitting}
|
|
||||||
onClick={handleSubmit}
|
|
||||||
>
|
|
||||||
{isSubmitting ? (
|
|
||||||
<>
|
|
||||||
<Loader2 className="size-4 animate-spin" />
|
|
||||||
Submitting...
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Send className="size-4" />
|
|
||||||
Submit for Review
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { Clock3 } from 'lucide-react';
|
||||||
|
|
||||||
|
import type { TicketDetail } from '@/types';
|
||||||
|
|
||||||
|
import { TicketActionCard } from './TicketActionCard';
|
||||||
|
import { TicketExtensionRequestPanel } from './TicketExtensionRequestPanel';
|
||||||
|
|
||||||
|
export function RequestExtensionAction({ ticket }: { ticket: TicketDetail }) {
|
||||||
|
return (
|
||||||
|
<TicketActionCard icon={Clock3} title="Request Extension">
|
||||||
|
<TicketExtensionRequestPanel ticket={ticket} />
|
||||||
|
</TicketActionCard>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -16,13 +16,9 @@ const MAX_REASON_LENGTH = 300;
|
|||||||
|
|
||||||
interface RequestExtensionFormProps {
|
interface RequestExtensionFormProps {
|
||||||
ticket: TicketDetail;
|
ticket: TicketDetail;
|
||||||
onCancel: () => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function RequestExtensionForm({
|
export function RequestExtensionForm({ ticket }: RequestExtensionFormProps) {
|
||||||
ticket,
|
|
||||||
onCancel,
|
|
||||||
}: RequestExtensionFormProps) {
|
|
||||||
const currentDueAt = ticket.worker?.due_at;
|
const currentDueAt = ticket.worker?.due_at;
|
||||||
const currentDueDate = useMemo(
|
const currentDueDate = useMemo(
|
||||||
() => (currentDueAt ? new Date(currentDueAt) : undefined),
|
() => (currentDueAt ? new Date(currentDueAt) : undefined),
|
||||||
@@ -66,7 +62,6 @@ export function RequestExtensionForm({
|
|||||||
});
|
});
|
||||||
setRequestedDueDate(undefined);
|
setRequestedDueDate(undefined);
|
||||||
setReason('');
|
setReason('');
|
||||||
onCancel();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -138,20 +133,15 @@ export function RequestExtensionForm({
|
|||||||
This request will be sent to your manager for approval.
|
This request will be sent to your manager for approval.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div className="grid grid-cols-2 gap-3">
|
<Button
|
||||||
<Button
|
type="button"
|
||||||
type="button"
|
className="w-full"
|
||||||
variant="outline"
|
disabled={!canSubmit}
|
||||||
disabled={isPending}
|
onClick={handleSubmit}
|
||||||
onClick={onCancel}
|
>
|
||||||
>
|
{isPending ? <Loader2 className="animate-spin" /> : <Send />}
|
||||||
Cancel
|
{isPending ? 'Submitting...' : 'Submit Request'}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="button" disabled={!canSubmit} onClick={handleSubmit}>
|
|
||||||
{isPending ? <Loader2 className="animate-spin" /> : <Send />}
|
|
||||||
{isPending ? 'Submitting...' : 'Submit Request'}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useEffect, useState } from 'react';
|
|
||||||
import { Check, ClipboardCheck, 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 } from '@/types';
|
|
||||||
|
|
||||||
import { useReviewRepairMutation } from '../../../hooks/useTicketQueries';
|
|
||||||
import { TicketActionCard } from './TicketActionCard';
|
|
||||||
|
|
||||||
export function ReviewRepairAction({ ticket }: { ticket: TicketDetail }) {
|
|
||||||
const [reviewComment, setReviewComment] = useState('');
|
|
||||||
const reviewRepairMutation = useReviewRepairMutation(ticket.id);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setReviewComment(ticket.reviewer?.review_comment ?? '');
|
|
||||||
}, [ticket]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TicketActionCard icon={ClipboardCheck} title="Review Repair">
|
|
||||||
<div className="space-y-4">
|
|
||||||
<div className="space-y-2">
|
|
||||||
<Label>Comment</Label>
|
|
||||||
<Textarea
|
|
||||||
value={reviewComment}
|
|
||||||
onChange={(event) => setReviewComment(event.target.value)}
|
|
||||||
placeholder="Repair verified"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div className="grid grid-cols-2 gap-2">
|
|
||||||
<Button
|
|
||||||
variant={'secondary'}
|
|
||||||
disabled={!reviewComment || reviewRepairMutation.isPending}
|
|
||||||
onClick={() =>
|
|
||||||
reviewRepairMutation.mutate({
|
|
||||||
defect_class: ticket.defect_class,
|
|
||||||
action: 'approve',
|
|
||||||
comment: reviewComment,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Check />
|
|
||||||
Approve
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
variant="destructive"
|
|
||||||
disabled={!reviewComment || reviewRepairMutation.isPending}
|
|
||||||
onClick={() =>
|
|
||||||
reviewRepairMutation.mutate({
|
|
||||||
defect_class: ticket.defect_class,
|
|
||||||
action: 'reject',
|
|
||||||
comment: reviewComment,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<X />
|
|
||||||
Reject
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</TicketActionCard>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useState } from 'react';
|
|
||||||
import { Wrench } from 'lucide-react';
|
|
||||||
|
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
|
||||||
import type { TicketDetail } from '@/types';
|
|
||||||
|
|
||||||
import { RepairEvidenceForm } from './RepairEvidenceForm';
|
|
||||||
import { TicketExtensionRequestPanel } from './TicketExtensionRequestPanel';
|
|
||||||
import { TicketActionCard } from './TicketActionCard';
|
|
||||||
|
|
||||||
type RepairActionTab = 'repair-proof' | 'request-extension';
|
|
||||||
|
|
||||||
export function SubmitRepairAction({ ticket }: { ticket: TicketDetail }) {
|
|
||||||
const [activeTab, setActiveTab] = useState<RepairActionTab>('repair-proof');
|
|
||||||
|
|
||||||
if (ticket.repair?.submitted_at) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TicketActionCard icon={Wrench} title="Repair Proof">
|
|
||||||
<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>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export { RepairProofSummary as SubmittedRepairProofAction } from '../repair/RepairProofSummary';
|
|
||||||
@@ -23,11 +23,6 @@ import { formatDate } from '@/utils/date';
|
|||||||
import { useTicketExtensionRequestQuery } from '../../../hooks/useTicketQueries';
|
import { useTicketExtensionRequestQuery } from '../../../hooks/useTicketQueries';
|
||||||
import { RequestExtensionForm } from './RequestExtensionForm';
|
import { RequestExtensionForm } from './RequestExtensionForm';
|
||||||
|
|
||||||
interface TicketExtensionRequestPanelProps {
|
|
||||||
ticket: TicketDetail;
|
|
||||||
onCancelRequest: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface DetailRowProps {
|
interface DetailRowProps {
|
||||||
label: string;
|
label: string;
|
||||||
value: string;
|
value: string;
|
||||||
@@ -192,8 +187,9 @@ function ExtensionRequestDetails({
|
|||||||
|
|
||||||
export function TicketExtensionRequestPanel({
|
export function TicketExtensionRequestPanel({
|
||||||
ticket,
|
ticket,
|
||||||
onCancelRequest,
|
}: {
|
||||||
}: TicketExtensionRequestPanelProps) {
|
ticket: TicketDetail;
|
||||||
|
}) {
|
||||||
const assignmentId = ticket.worker?.assignment_id;
|
const assignmentId = ticket.worker?.assignment_id;
|
||||||
const extensionRequestQuery = useTicketExtensionRequestQuery(
|
const extensionRequestQuery = useTicketExtensionRequestQuery(
|
||||||
ticket.id,
|
ticket.id,
|
||||||
@@ -241,7 +237,7 @@ export function TicketExtensionRequestPanel({
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
if (!latestRequest) {
|
if (!latestRequest) {
|
||||||
return <RequestExtensionForm ticket={ticket} onCancel={onCancelRequest} />;
|
return <RequestExtensionForm ticket={ticket} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return <ExtensionRequestDetails request={latestRequest} />;
|
return <ExtensionRequestDetails request={latestRequest} />;
|
||||||
|
|||||||
@@ -11,11 +11,15 @@ import { protectedMediaService } from '@/services/api';
|
|||||||
|
|
||||||
interface RepairProofGalleryProps {
|
interface RepairProofGalleryProps {
|
||||||
imageUrls: string[];
|
imageUrls: string[];
|
||||||
|
maxVisibleImages?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MAX_VISIBLE_IMAGES = 8;
|
const MAX_VISIBLE_IMAGES = 8;
|
||||||
|
|
||||||
export function RepairProofGallery({ imageUrls }: RepairProofGalleryProps) {
|
export function RepairProofGallery({
|
||||||
|
imageUrls,
|
||||||
|
maxVisibleImages = MAX_VISIBLE_IMAGES,
|
||||||
|
}: RepairProofGalleryProps) {
|
||||||
const queries = useQueries({
|
const queries = useQueries({
|
||||||
queries: imageUrls.map((url) => ({
|
queries: imageUrls.map((url) => ({
|
||||||
queryKey: ['protected-media', 'v2', url],
|
queryKey: ['protected-media', 'v2', url],
|
||||||
@@ -44,7 +48,7 @@ export function RepairProofGallery({ imageUrls }: RepairProofGalleryProps) {
|
|||||||
if (queries.some((query) => query.isLoading)) {
|
if (queries.some((query) => query.isLoading)) {
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-4 gap-1 overflow-hidden rounded-lg">
|
<div className="grid grid-cols-4 gap-1 overflow-hidden rounded-lg">
|
||||||
{imageUrls.slice(0, MAX_VISIBLE_IMAGES).map((url, index) => (
|
{imageUrls.slice(0, maxVisibleImages).map((url, index) => (
|
||||||
<Skeleton
|
<Skeleton
|
||||||
key={`${url}-${index}`}
|
key={`${url}-${index}`}
|
||||||
className="aspect-square rounded-lg"
|
className="aspect-square rounded-lg"
|
||||||
@@ -57,7 +61,7 @@ export function RepairProofGallery({ imageUrls }: RepairProofGalleryProps) {
|
|||||||
const images = objectUrls.flatMap((url, index) =>
|
const images = objectUrls.flatMap((url, index) =>
|
||||||
url ? [{ url, originalIndex: index }] : [],
|
url ? [{ url, originalIndex: index }] : [],
|
||||||
);
|
);
|
||||||
const visibleCount = Math.min(MAX_VISIBLE_IMAGES, images.length);
|
const visibleCount = Math.min(maxVisibleImages, images.length);
|
||||||
const overflowCount = images.length - visibleCount;
|
const overflowCount = images.length - visibleCount;
|
||||||
|
|
||||||
if (images.length === 0) {
|
if (images.length === 0) {
|
||||||
@@ -102,8 +106,8 @@ export function RepairProofGallery({ imageUrls }: RepairProofGalleryProps) {
|
|||||||
className="size-full object-cover transition duration-300 group-hover:scale-[1.03] group-hover:brightness-90"
|
className="size-full object-cover transition duration-300 group-hover:scale-[1.03] group-hover:brightness-90"
|
||||||
/>
|
/>
|
||||||
{isOverflowTile ? (
|
{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">
|
<span className="absolute inset-0 flex items-center justify-center bg-black/55 px-2 text-center text-sm font-semibold text-white transition-colors group-hover:bg-black/65 sm:text-base">
|
||||||
+{overflowCount}
|
+{overflowCount} more
|
||||||
</span>
|
</span>
|
||||||
) : null}
|
) : null}
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -1,103 +0,0 @@
|
|||||||
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>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -58,15 +58,17 @@ export default function TicketDetailPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="relative z-10 space-y-5">
|
<main className="relative z-10 space-y-5 xl:flex xl:h-[calc(100vh-6.5rem)] xl:min-h-0 xl:flex-col xl:gap-5 xl:space-y-0 xl:overflow-hidden">
|
||||||
{overview ? (
|
<div className="xl:shrink-0">
|
||||||
<TicketDetailHeader ticket={overview} />
|
{overview ? (
|
||||||
) : (
|
<TicketDetailHeader ticket={overview} />
|
||||||
<TicketOverviewHeaderSkeleton />
|
) : (
|
||||||
)}
|
<TicketOverviewHeaderSkeleton />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="grid gap-5 xl:grid-cols-[minmax(0,7fr)_minmax(0,3fr)]">
|
<div className="grid items-start gap-5 xl:min-h-0 xl:flex-1 xl:grid-cols-[minmax(0,7fr)_minmax(0,3fr)] xl:items-stretch xl:overflow-hidden">
|
||||||
<div className="space-y-5">
|
<div className="space-y-5 xl:min-h-0 xl:overflow-y-auto xl:overscroll-contain xl:pr-2">
|
||||||
{overview ? (
|
{overview ? (
|
||||||
<TicketOverviewCard ticket={overview} />
|
<TicketOverviewCard ticket={overview} />
|
||||||
) : (
|
) : (
|
||||||
@@ -79,7 +81,7 @@ export default function TicketDetailPage() {
|
|||||||
) : null}
|
) : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="space-y-3 self-start">
|
<div className="space-y-3 self-start xl:min-h-0 xl:self-stretch xl:overflow-y-auto xl:overscroll-contain xl:pr-2">
|
||||||
{isClassDetailLoading ? <TicketClassActionsSkeleton /> : null}
|
{isClassDetailLoading ? <TicketClassActionsSkeleton /> : null}
|
||||||
{!isClassDetailLoading && classDetail ? (
|
{!isClassDetailLoading && classDetail ? (
|
||||||
<TicketStatusActions ticket={classDetail} />
|
<TicketStatusActions ticket={classDetail} />
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useMemo } from 'react';
|
import { useMemo } from 'react';
|
||||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
import {
|
||||||
|
useInfiniteQuery,
|
||||||
|
useMutation,
|
||||||
|
useQuery,
|
||||||
|
useQueryClient,
|
||||||
|
} from '@tanstack/react-query';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
import { detectionService, ticketService, videoService } from '@/services/api';
|
import { detectionService, ticketService, videoService } from '@/services/api';
|
||||||
@@ -10,12 +15,11 @@ import type {
|
|||||||
CloseTicketPayload,
|
CloseTicketPayload,
|
||||||
DiscardDetectionPayload,
|
DiscardDetectionPayload,
|
||||||
RequestTicketExtensionPayload,
|
RequestTicketExtensionPayload,
|
||||||
|
ReviewDetectionRepairProofPayload,
|
||||||
ReviewTicketExtensionPayload,
|
ReviewTicketExtensionPayload,
|
||||||
ReviewRepairPayload,
|
|
||||||
SubmitRepairPayload,
|
|
||||||
SubmitRepairUploadPayload,
|
|
||||||
TicketDetail,
|
TicketDetail,
|
||||||
TicketListParams,
|
TicketListParams,
|
||||||
|
DetectionProofStatus,
|
||||||
VideoDetectionsParams,
|
VideoDetectionsParams,
|
||||||
} from '@/types';
|
} from '@/types';
|
||||||
|
|
||||||
@@ -118,6 +122,36 @@ export function useTicketClassDetectionsQuery(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useTicketClassReviewDetectionsQuery(
|
||||||
|
videoId: string | undefined,
|
||||||
|
defectClass: string | undefined,
|
||||||
|
proofStatus?: DetectionProofStatus,
|
||||||
|
) {
|
||||||
|
const pageSize = 20;
|
||||||
|
|
||||||
|
return useInfiniteQuery({
|
||||||
|
queryKey: ticketKeys.classReviewDetections(
|
||||||
|
videoId ?? '',
|
||||||
|
defectClass ?? '',
|
||||||
|
proofStatus,
|
||||||
|
),
|
||||||
|
queryFn: ({ pageParam }) =>
|
||||||
|
videoService.getVideoDetections(videoId as string, {
|
||||||
|
class_name: defectClass,
|
||||||
|
proof_status: proofStatus,
|
||||||
|
sort: 'timestamp_asc',
|
||||||
|
skip: pageParam,
|
||||||
|
limit: pageSize,
|
||||||
|
}),
|
||||||
|
initialPageParam: 0,
|
||||||
|
getNextPageParam: (lastPage) => {
|
||||||
|
const nextSkip = lastPage.skip + lastPage.items.length;
|
||||||
|
return nextSkip < lastPage.total ? nextSkip : undefined;
|
||||||
|
},
|
||||||
|
enabled: Boolean(videoId && defectClass),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function useDiscardDetectionMutation(
|
export function useDiscardDetectionMutation(
|
||||||
ticketId: string,
|
ticketId: string,
|
||||||
videoId: string | undefined,
|
videoId: string | undefined,
|
||||||
@@ -158,6 +192,54 @@ export function useDiscardDetectionMutation(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function useReviewDetectionRepairProofMutation({
|
||||||
|
ticketId,
|
||||||
|
videoId,
|
||||||
|
defectClass,
|
||||||
|
}: {
|
||||||
|
ticketId: string;
|
||||||
|
videoId: string | undefined;
|
||||||
|
defectClass: string;
|
||||||
|
}) {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: ({
|
||||||
|
detectionId,
|
||||||
|
payload,
|
||||||
|
}: {
|
||||||
|
detectionId: number;
|
||||||
|
payload: ReviewDetectionRepairProofPayload;
|
||||||
|
}) => detectionService.reviewRepairProof(ticketId, detectionId, payload),
|
||||||
|
onSuccess: async (_repairProof, variables) => {
|
||||||
|
toast.success(
|
||||||
|
variables.payload.action === 'approve'
|
||||||
|
? 'Repair proof approved'
|
||||||
|
: 'Repair proof rejected',
|
||||||
|
);
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
videoId
|
||||||
|
? queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.classDetectionLists(videoId),
|
||||||
|
})
|
||||||
|
: Promise.resolve(),
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.classDetail(ticketId, defectClass),
|
||||||
|
}),
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.defectClasses(ticketId),
|
||||||
|
}),
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ticketKeys.overview(ticketId),
|
||||||
|
}),
|
||||||
|
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() }),
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
onError: () => toast.error('Failed to review repair proof'),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function useTicketExtensionRequestQuery(
|
export function useTicketExtensionRequestQuery(
|
||||||
ticketId: string | undefined,
|
ticketId: string | undefined,
|
||||||
assignmentId: number | undefined,
|
assignmentId: number | undefined,
|
||||||
@@ -212,42 +294,6 @@ export function useAssignTicketMutation(ticketId: string) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useSubmitRepairMutation(ticketId: string) {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
return useMutation({
|
|
||||||
mutationFn: (payload: SubmitRepairPayload) =>
|
|
||||||
ticketService.submitRepair(ticketId, payload),
|
|
||||||
onSuccess: (ticket) => {
|
|
||||||
toast.success('Repair submitted');
|
|
||||||
queryClient.setQueryData<TicketDetail>(
|
|
||||||
ticketKeys.classDetail(ticketId, ticket.defect_class),
|
|
||||||
(current) => mergeTicketDetailResponse(current, ticket),
|
|
||||||
);
|
|
||||||
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
|
||||||
},
|
|
||||||
onError: () => toast.error('Failed to submit repair'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useSubmitRepairUploadMutation(ticketId: string) {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
return useMutation({
|
|
||||||
mutationFn: (payload: SubmitRepairUploadPayload) =>
|
|
||||||
ticketService.submitRepairUpload(ticketId, payload),
|
|
||||||
onSuccess: (ticket, payload) => {
|
|
||||||
toast.success('Repair evidence uploaded');
|
|
||||||
queryClient.setQueryData<TicketDetail>(
|
|
||||||
ticketKeys.classDetail(ticketId, payload.defect_class),
|
|
||||||
(current) => mergeTicketDetailResponse(current, ticket),
|
|
||||||
);
|
|
||||||
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
|
||||||
},
|
|
||||||
onError: () => toast.error('Failed to upload repair evidence'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useRequestTicketExtensionMutation(
|
export function useRequestTicketExtensionMutation(
|
||||||
ticketId: string,
|
ticketId: string,
|
||||||
assignmentId: number | undefined,
|
assignmentId: number | undefined,
|
||||||
@@ -306,26 +352,6 @@ export function useReviewTicketExtensionMutation(
|
|||||||
onError: () => toast.error('Failed to review extension request'),
|
onError: () => toast.error('Failed to review extension request'),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
export function useReviewRepairMutation(ticketId: string) {
|
|
||||||
const queryClient = useQueryClient();
|
|
||||||
|
|
||||||
return useMutation({
|
|
||||||
mutationFn: (payload: ReviewRepairPayload) =>
|
|
||||||
ticketService.reviewRepair(ticketId, payload),
|
|
||||||
onSuccess: (ticket, payload) => {
|
|
||||||
toast.success(
|
|
||||||
payload.action === 'approve' ? 'Repair approved' : 'Repair rejected',
|
|
||||||
);
|
|
||||||
queryClient.setQueryData<TicketDetail>(
|
|
||||||
ticketKeys.classDetail(ticketId, payload.defect_class),
|
|
||||||
(current) => mergeTicketDetailResponse(current, ticket),
|
|
||||||
);
|
|
||||||
queryClient.invalidateQueries({ queryKey: ticketKeys.lists() });
|
|
||||||
},
|
|
||||||
onError: () => toast.error('Failed to review repair'),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function useCloseTicketMutation(ticketId: string) {
|
export function useCloseTicketMutation(ticketId: string) {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,17 @@ export const ticketKeys = {
|
|||||||
[...ticketKeys.details(), 'video', videoId, 'detections'] as const,
|
[...ticketKeys.details(), 'video', videoId, 'detections'] as const,
|
||||||
classDetections: (videoId: string, params: VideoDetectionsParams) =>
|
classDetections: (videoId: string, params: VideoDetectionsParams) =>
|
||||||
[...ticketKeys.classDetectionLists(videoId), params] as const,
|
[...ticketKeys.classDetectionLists(videoId), params] as const,
|
||||||
|
classReviewDetections: (
|
||||||
|
videoId: string,
|
||||||
|
defectClass: string,
|
||||||
|
proofStatus?: string,
|
||||||
|
) =>
|
||||||
|
[
|
||||||
|
...ticketKeys.classDetectionLists(videoId),
|
||||||
|
'class-review',
|
||||||
|
defectClass,
|
||||||
|
proofStatus ?? 'all',
|
||||||
|
] as const,
|
||||||
defectClasses: (ticketId: string) =>
|
defectClasses: (ticketId: string) =>
|
||||||
[...ticketKeys.details(), ticketId, 'defect-classes'] as const,
|
[...ticketKeys.details(), ticketId, 'defect-classes'] as const,
|
||||||
extensionRequest: (ticketId: string, assignmentId: number | undefined) =>
|
extensionRequest: (ticketId: string, assignmentId: number | undefined) =>
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useRouter } from 'next/navigation';
|
|
||||||
import {
|
|
||||||
Download,
|
|
||||||
Eye,
|
|
||||||
MoreVertical,
|
|
||||||
PlayCircle,
|
|
||||||
RotateCcw,
|
|
||||||
Ticket,
|
|
||||||
Trash2,
|
|
||||||
} from 'lucide-react';
|
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
|
||||||
import {
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuContent,
|
|
||||||
DropdownMenuItem,
|
|
||||||
DropdownMenuSeparator,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
} from '@/components/ui/dropdown-menu';
|
|
||||||
import type { UploadListItem } from '@/types';
|
|
||||||
|
|
||||||
interface UploadActionsMenuProps {
|
|
||||||
upload: UploadListItem;
|
|
||||||
onViewVideo: (upload: UploadListItem) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function UploadActionsMenu({
|
|
||||||
upload,
|
|
||||||
onViewVideo,
|
|
||||||
}: UploadActionsMenuProps) {
|
|
||||||
const router = useRouter();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<DropdownMenu>
|
|
||||||
<DropdownMenuTrigger asChild>
|
|
||||||
<Button
|
|
||||||
type="button"
|
|
||||||
variant="ghost"
|
|
||||||
size="icon"
|
|
||||||
className="size-8"
|
|
||||||
onClick={(event) => event.stopPropagation()}
|
|
||||||
>
|
|
||||||
<MoreVertical className="size-4" />
|
|
||||||
<span className="sr-only">Open actions</span>
|
|
||||||
</Button>
|
|
||||||
</DropdownMenuTrigger>
|
|
||||||
<DropdownMenuContent align="end">
|
|
||||||
{upload.raw_video_url ? (
|
|
||||||
<DropdownMenuItem
|
|
||||||
onClick={(event) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
onViewVideo(upload);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<PlayCircle className="size-4" />
|
|
||||||
View Video
|
|
||||||
</DropdownMenuItem>
|
|
||||||
) : 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>
|
|
||||||
</DropdownMenu>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
143
src/app/(modules)/upload/components/UploadDetailsDialog.tsx
Normal file
143
src/app/(modules)/upload/components/UploadDetailsDialog.tsx
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { ExternalLink, Ticket, UserRound } from 'lucide-react';
|
||||||
|
|
||||||
|
import { ProtectedVideoPlayer } from '@/components/media/ProtectedVideoPlayer';
|
||||||
|
import { Badge } from '@/components/ui/badge';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import {
|
||||||
|
Dialog,
|
||||||
|
DialogBody,
|
||||||
|
DialogContent,
|
||||||
|
DialogDescription,
|
||||||
|
DialogFooter,
|
||||||
|
DialogHeader,
|
||||||
|
DialogTitle,
|
||||||
|
} from '@/components/ui/dialog';
|
||||||
|
import { PERMISSIONS } from '@/constants/permissions';
|
||||||
|
import { usePermissions } from '@/hooks/usePermissions';
|
||||||
|
import { ROUTES } from '@/utils/routes';
|
||||||
|
import type { UploadListItem } from '@/types';
|
||||||
|
import { formatDate } from '@/utils/date';
|
||||||
|
|
||||||
|
import { UploadResultCell } from './UploadResultCell';
|
||||||
|
import { UploadStatusBadge } from './UploadStatusBadge';
|
||||||
|
|
||||||
|
interface UploadDetailsDialogProps {
|
||||||
|
upload: UploadListItem | null;
|
||||||
|
open: boolean;
|
||||||
|
onOpenChange: (open: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UploadDetailsDialog({
|
||||||
|
upload,
|
||||||
|
open,
|
||||||
|
onOpenChange,
|
||||||
|
}: UploadDetailsDialogProps) {
|
||||||
|
const { hasPermission } = usePermissions();
|
||||||
|
const canOpenTicket = hasPermission(PERMISSIONS.TICKET.READ);
|
||||||
|
const details = [
|
||||||
|
{ label: 'Project', value: upload?.project },
|
||||||
|
{ label: 'Package', value: upload?.package },
|
||||||
|
{ label: 'Segment', value: upload?.segment },
|
||||||
|
{ label: 'Chainage', value: upload?.chainage },
|
||||||
|
{ label: 'Uploaded', value: formatDate(upload?.uploaded_at) },
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||||
|
<DialogContent className="sm:max-w-6xl">
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle>Upload Details</DialogTitle>
|
||||||
|
<DialogDescription>
|
||||||
|
Preview the inspection video and review its processing details.
|
||||||
|
</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
|
||||||
|
<DialogBody>
|
||||||
|
<div className="grid gap-5 lg:grid-cols-[minmax(0,1.7fr)_minmax(18rem,0.8fr)]">
|
||||||
|
<section className="min-w-0 space-y-2">
|
||||||
|
<p className="text-sm font-medium">Video Preview</p>
|
||||||
|
<ProtectedVideoPlayer
|
||||||
|
url={open ? upload?.raw_video_url : undefined}
|
||||||
|
label={upload?.video_name}
|
||||||
|
className="rounded-lg"
|
||||||
|
unavailableTitle="Video preview unavailable"
|
||||||
|
/>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<aside className="min-w-0 space-y-4 rounded-lg border bg-muted/15 p-4">
|
||||||
|
<div className="flex items-start justify-between gap-3">
|
||||||
|
<div>
|
||||||
|
<p className="text-xs text-muted-foreground">Status</p>
|
||||||
|
<div className="mt-1.5">
|
||||||
|
{upload ? (
|
||||||
|
<UploadStatusBadge
|
||||||
|
status={upload.status}
|
||||||
|
progress={upload.progress}
|
||||||
|
/>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="text-right">
|
||||||
|
<p className="text-xs text-muted-foreground">Detections</p>
|
||||||
|
<Badge variant="secondary" className="mt-1.5 tabular-nums">
|
||||||
|
{upload?.total_detections ?? 0}
|
||||||
|
</Badge>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="border-t pt-4">
|
||||||
|
<p className="mb-2 text-xs text-muted-foreground">Result</p>
|
||||||
|
{upload ? <UploadResultCell item={upload} /> : null}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<dl className="grid grid-cols-2 gap-x-4 gap-y-3 border-t pt-4">
|
||||||
|
{details.map((detail) => (
|
||||||
|
<div
|
||||||
|
key={detail.label}
|
||||||
|
className={
|
||||||
|
detail.label === 'Uploaded' ? 'col-span-2' : undefined
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<dt className="text-xs text-muted-foreground">
|
||||||
|
{detail.label}
|
||||||
|
</dt>
|
||||||
|
<dd className="mt-1 truncate text-sm font-medium">
|
||||||
|
{detail.value || '—'}
|
||||||
|
</dd>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</dl>
|
||||||
|
|
||||||
|
<div className="flex min-w-0 items-start gap-2 border-t pt-4">
|
||||||
|
<UserRound className="mt-0.5 size-4 shrink-0 text-muted-foreground" />
|
||||||
|
<div className="min-w-0">
|
||||||
|
<p className="truncate text-sm font-medium">
|
||||||
|
{upload?.uploaded_by.name || 'Unknown uploader'}
|
||||||
|
</p>
|
||||||
|
<p className="truncate text-xs text-muted-foreground">
|
||||||
|
{upload?.uploaded_by.email || 'No email available'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</aside>
|
||||||
|
</div>
|
||||||
|
</DialogBody>
|
||||||
|
|
||||||
|
<DialogFooter showCloseButton>
|
||||||
|
{upload?.ticket_id && canOpenTicket ? (
|
||||||
|
<Button asChild>
|
||||||
|
<Link href={ROUTES.TICKET_DETAIL(upload.ticket_id)}>
|
||||||
|
<Ticket />
|
||||||
|
Open Ticket
|
||||||
|
<ExternalLink />
|
||||||
|
</Link>
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
</DialogFooter>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -9,7 +9,6 @@ import { Badge } from '@/components/ui/badge';
|
|||||||
import type { UploadListItem } from '@/types';
|
import type { UploadListItem } from '@/types';
|
||||||
import { formatDate } from '@/utils/date';
|
import { formatDate } from '@/utils/date';
|
||||||
|
|
||||||
import { UploadActionsMenu } from './UploadActionsMenu';
|
|
||||||
import { UploadResultCell } from './UploadResultCell';
|
import { UploadResultCell } from './UploadResultCell';
|
||||||
import { UploadStatusBadge } from './UploadStatusBadge';
|
import { UploadStatusBadge } from './UploadStatusBadge';
|
||||||
|
|
||||||
@@ -22,9 +21,7 @@ function resolveThumbnailUrl(value: string | null) {
|
|||||||
return baseUrl ? `${baseUrl}${path}` : path;
|
return baseUrl ? `${baseUrl}${path}` : path;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useUploadListColumns(
|
export function useUploadListColumns(): ColumnDef<UploadListItem>[] {
|
||||||
onViewVideo: (upload: UploadListItem) => void,
|
|
||||||
): ColumnDef<UploadListItem>[] {
|
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
@@ -133,24 +130,7 @@ export function useUploadListColumns(
|
|||||||
meta: { disableTruncate: true },
|
meta: { disableTruncate: true },
|
||||||
cell: ({ row }) => <UploadResultCell item={row.original} />,
|
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],
|
[],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ interface UploadTableProps {
|
|||||||
skip: number;
|
skip: number;
|
||||||
limit: number;
|
limit: number;
|
||||||
total: number;
|
total: number;
|
||||||
|
onUploadClick: (upload: UploadListItem) => void;
|
||||||
onPageChange: (skip: number) => void;
|
onPageChange: (skip: number) => void;
|
||||||
onLimitChange: (limit: number) => void;
|
onLimitChange: (limit: number) => void;
|
||||||
}
|
}
|
||||||
@@ -23,6 +24,7 @@ export function UploadTable({
|
|||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
total,
|
total,
|
||||||
|
onUploadClick,
|
||||||
onPageChange,
|
onPageChange,
|
||||||
onLimitChange,
|
onLimitChange,
|
||||||
}: UploadTableProps) {
|
}: UploadTableProps) {
|
||||||
@@ -33,6 +35,7 @@ export function UploadTable({
|
|||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
emptyTitle="No uploads found"
|
emptyTitle="No uploads found"
|
||||||
emptyDescription="Upload your first road inspection video."
|
emptyDescription="Upload your first road inspection video."
|
||||||
|
onRowClick={onUploadClick}
|
||||||
pagination={{
|
pagination={{
|
||||||
skip,
|
skip,
|
||||||
limit,
|
limit,
|
||||||
|
|||||||
@@ -1,41 +0,0 @@
|
|||||||
'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>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@ import type { UploadListItem } from '@/types';
|
|||||||
import { CreateUploadDialog } from './components/CreateUploadDialog';
|
import { CreateUploadDialog } from './components/CreateUploadDialog';
|
||||||
import { useUploadListColumns } from './components/UploadListColumns';
|
import { useUploadListColumns } from './components/UploadListColumns';
|
||||||
import { UploadTable } from './components/UploadTable';
|
import { UploadTable } from './components/UploadTable';
|
||||||
import { VideoPreviewDialog } from './components/VideoPreviewDialog';
|
import { UploadDetailsDialog } from './components/UploadDetailsDialog';
|
||||||
import { useUploadFilters } from './hooks/useUploadFilters';
|
import { useUploadFilters } from './hooks/useUploadFilters';
|
||||||
import { useUploadListEvents } from './hooks/useUploadListEvents';
|
import { useUploadListEvents } from './hooks/useUploadListEvents';
|
||||||
import { useUploadsQuery } from './hooks/useUploadQueries';
|
import { useUploadsQuery } from './hooks/useUploadQueries';
|
||||||
@@ -20,13 +20,15 @@ export default function UploadPage() {
|
|||||||
const uploadsQuery = useUploadsQuery({ skip, limit });
|
const uploadsQuery = useUploadsQuery({ skip, limit });
|
||||||
useUploadListEvents();
|
useUploadListEvents();
|
||||||
const [isCreateOpen, setIsCreateOpen] = useState(false);
|
const [isCreateOpen, setIsCreateOpen] = useState(false);
|
||||||
const [videoUpload, setVideoUpload] = useState<UploadListItem | null>(null);
|
const [selectedUpload, setSelectedUpload] = useState<UploadListItem | 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 columns = useUploadListColumns(setVideoUpload);
|
const columns = useUploadListColumns();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -50,17 +52,18 @@ export default function UploadPage() {
|
|||||||
skip={skip}
|
skip={skip}
|
||||||
limit={limit}
|
limit={limit}
|
||||||
total={total}
|
total={total}
|
||||||
|
onUploadClick={setSelectedUpload}
|
||||||
onPageChange={setSkip}
|
onPageChange={setSkip}
|
||||||
onLimitChange={setLimit}
|
onLimitChange={setLimit}
|
||||||
/>
|
/>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<CreateUploadDialog open={isCreateOpen} onOpenChange={setIsCreateOpen} />
|
<CreateUploadDialog open={isCreateOpen} onOpenChange={setIsCreateOpen} />
|
||||||
<VideoPreviewDialog
|
<UploadDetailsDialog
|
||||||
upload={videoUpload}
|
upload={selectedUpload}
|
||||||
open={Boolean(videoUpload)}
|
open={Boolean(selectedUpload)}
|
||||||
onOpenChange={(open) => {
|
onOpenChange={(open) => {
|
||||||
if (!open) setVideoUpload(null);
|
if (!open) setSelectedUpload(null);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
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>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
'use client';
|
'use client';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import { ChevronRight } from 'lucide-react';
|
import { ChevronRight } from 'lucide-react';
|
||||||
import { LogoWrapper } from '@/components/LogoWrapper';
|
import Image from 'next/image';
|
||||||
import { NavUser } from '@/components/nav-user';
|
import { NavUser } from '@/components/nav-user';
|
||||||
import {
|
import {
|
||||||
filterMenuItems,
|
filterMenuItems,
|
||||||
@@ -55,7 +55,6 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
|||||||
[authUser?.first_name, authUser?.last_name].filter(Boolean).join(' ') ||
|
[authUser?.first_name, authUser?.last_name].filter(Boolean).join(' ') ||
|
||||||
'Admin',
|
'Admin',
|
||||||
email: authUser?.email || '',
|
email: authUser?.email || '',
|
||||||
avatar: authUser?.profile_photo_url || '/avatars/profile.jpg',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -97,10 +96,13 @@ export function AppSidebar({ ...props }: React.ComponentProps<typeof Sidebar>) {
|
|||||||
function SidebarBrandControl({ isMobile }: { isMobile: boolean }) {
|
function SidebarBrandControl({ isMobile }: { isMobile: boolean }) {
|
||||||
return (
|
return (
|
||||||
<div className="group/sidebar-brand relative flex size-8 shrink-0 items-center justify-center">
|
<div className="group/sidebar-brand relative flex size-8 shrink-0 items-center justify-center">
|
||||||
<LogoWrapper
|
<Image
|
||||||
size="sm"
|
src="/color_logo.svg"
|
||||||
variant="sidebar"
|
alt="RoadMonitor logo"
|
||||||
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"
|
width={81}
|
||||||
|
height={58}
|
||||||
|
className="h-auto w-10 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"
|
||||||
|
priority
|
||||||
/>
|
/>
|
||||||
<Tooltip>
|
<Tooltip>
|
||||||
<TooltipTrigger asChild>
|
<TooltipTrigger asChild>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { LogoWrapper } from '@/components/LogoWrapper';
|
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
|
import Image from 'next/image';
|
||||||
|
|
||||||
const BOKEH_ORBS = [
|
const BOKEH_ORBS = [
|
||||||
'top-[20%] left-[10%] size-[min(18vw,140px)] opacity-[0.14]',
|
'top-[20%] left-[10%] size-[min(18vw,140px)] opacity-[0.14]',
|
||||||
@@ -82,24 +82,21 @@ export function AuthBackground({ className }: AuthBackgroundProps) {
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
<div className="absolute inset-x-10 top-1/2 -translate-y-1/2 text-center text-primary-foreground">
|
<Image
|
||||||
<div className="mb-9 inline-flex items-center gap-5 text-left">
|
src="/logo.svg"
|
||||||
<LogoWrapper
|
alt=""
|
||||||
alt=""
|
width={81}
|
||||||
className="size-28 rounded-lg border-[5px] p-4"
|
height={58}
|
||||||
priority
|
className="absolute left-10 top-12 h-auto w-16 object-contain"
|
||||||
variant="glass"
|
priority
|
||||||
/>
|
/>
|
||||||
<span className="min-w-0">
|
|
||||||
<span className="block text-5xl font-semibold leading-none tracking-normal">
|
<div className="absolute bottom-10 left-10 right-10 text-left text-primary-foreground">
|
||||||
Road
|
<p className="text-3xl leading-none tracking-tight">
|
||||||
</span>
|
<span className="font-semibold">Road</span>
|
||||||
<span className="block text-5xl font-semibold leading-none tracking-normal">
|
<span className="font-normal">Monitor</span>
|
||||||
Monitor
|
</p>
|
||||||
</span>
|
<p className="mt-1 max-w-sm text-xs leading-4 text-primary-foreground/90">
|
||||||
</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
|
Map, monitor, and repair road issues with data-driven surface
|
||||||
intelligence.
|
intelligence.
|
||||||
</p>
|
</p>
|
||||||
@@ -107,4 +104,3 @@ export function AuthBackground({ className }: AuthBackgroundProps) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ import {
|
|||||||
CreditCard,
|
CreditCard,
|
||||||
LogOut,
|
LogOut,
|
||||||
Sparkles,
|
Sparkles,
|
||||||
|
UserRound,
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
import { Avatar, AvatarFallback } from '@/components/ui/avatar';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
DropdownMenuContent,
|
DropdownMenuContent,
|
||||||
@@ -39,7 +40,6 @@ export function NavUser({
|
|||||||
user: {
|
user: {
|
||||||
name: string;
|
name: string;
|
||||||
email: string;
|
email: string;
|
||||||
avatar: string;
|
|
||||||
};
|
};
|
||||||
}) {
|
}) {
|
||||||
const { isMobile } = useSidebar();
|
const { isMobile } = useSidebar();
|
||||||
@@ -76,9 +76,10 @@ export function NavUser({
|
|||||||
size="lg"
|
size="lg"
|
||||||
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
className="data-[state=open]:bg-sidebar-accent data-[state=open]:text-sidebar-accent-foreground"
|
||||||
>
|
>
|
||||||
<Avatar className="h-8 w-8 rounded-lg">
|
<Avatar className="h-8 w-8">
|
||||||
<AvatarImage src={user.avatar} alt={user.name} />
|
<AvatarFallback>
|
||||||
<AvatarFallback className="rounded-lg">CN</AvatarFallback>
|
<UserRound className="size-4" aria-hidden="true" />
|
||||||
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<div className="grid flex-1 text-left text-sm leading-tight">
|
<div className="grid flex-1 text-left text-sm leading-tight">
|
||||||
<span className="truncate font-semibold">{user.name}</span>
|
<span className="truncate font-semibold">{user.name}</span>
|
||||||
@@ -95,9 +96,10 @@ export function NavUser({
|
|||||||
>
|
>
|
||||||
<DropdownMenuLabel className="p-0 font-normal">
|
<DropdownMenuLabel className="p-0 font-normal">
|
||||||
<div className="flex items-center gap-2 px-1 py-1.5 text-left text-sm">
|
<div className="flex items-center gap-2 px-1 py-1.5 text-left text-sm">
|
||||||
<Avatar className="h-8 w-8 rounded-lg">
|
<Avatar className="h-8 w-8">
|
||||||
<AvatarImage src={user.avatar} alt={user.name} />
|
<AvatarFallback>
|
||||||
<AvatarFallback className="rounded-lg">CN</AvatarFallback>
|
<UserRound className="size-4" aria-hidden="true" />
|
||||||
|
</AvatarFallback>
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<div className="grid flex-1 text-left text-sm leading-tight">
|
<div className="grid flex-1 text-left text-sm leading-tight">
|
||||||
<span className="truncate font-semibold">{user.name}</span>
|
<span className="truncate font-semibold">{user.name}</span>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ function Card({
|
|||||||
data-slot="card"
|
data-slot="card"
|
||||||
data-size={size}
|
data-size={size}
|
||||||
className={cn(
|
className={cn(
|
||||||
"group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-lg bg-card py-(--card-spacing) text-sm text-card-foreground shadow-xs ring-1 ring-foreground/10 [--card-spacing:--spacing(6)] has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(4)] *:[img:first-child]:rounded-lg *:[img:last-child]:rounded-lg",
|
"group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-lg bg-card py-(--card-spacing) text-sm text-card-foreground shadow-xs ring-1 ring-inset ring-foreground/10 [--card-spacing:--spacing(6)] has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(4)] *:[img:first-child]:rounded-lg *:[img:last-child]:rounded-lg",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
{...props}
|
{...props}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
|
import { useState } from 'react';
|
||||||
import { AlertTriangle, ImageIcon, Loader2 } from 'lucide-react';
|
import { AlertTriangle, ImageIcon, Loader2 } from 'lucide-react';
|
||||||
import Image from 'next/image';
|
import Image from 'next/image';
|
||||||
|
|
||||||
|
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog';
|
||||||
import { useProtectedMediaObjectUrl } from '@/hooks/useProtectedMedia';
|
import { useProtectedMediaObjectUrl } from '@/hooks/useProtectedMedia';
|
||||||
import type { BoundingBoxOverlayItem, DetectionResultItem } from '@/types';
|
import type { BoundingBoxOverlayItem, DetectionResultItem } from '@/types';
|
||||||
|
|
||||||
@@ -12,13 +14,18 @@ interface AnnotatedDetectionImageProps {
|
|||||||
detection?: DetectionResultItem;
|
detection?: DetectionResultItem;
|
||||||
videoWidth: number;
|
videoWidth: number;
|
||||||
videoHeight: number;
|
videoHeight: number;
|
||||||
|
aspectRatio?: string;
|
||||||
|
enableLightbox?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function AnnotatedDetectionImage({
|
export default function AnnotatedDetectionImage({
|
||||||
detection,
|
detection,
|
||||||
videoWidth,
|
videoWidth,
|
||||||
videoHeight,
|
videoHeight,
|
||||||
|
aspectRatio: aspectRatioOverride,
|
||||||
|
enableLightbox = false,
|
||||||
}: AnnotatedDetectionImageProps) {
|
}: AnnotatedDetectionImageProps) {
|
||||||
|
const [isPreviewOpen, setIsPreviewOpen] = useState(false);
|
||||||
const { objectUrl, isLoading, isError } = useProtectedMediaObjectUrl(
|
const { objectUrl, isLoading, isError } = useProtectedMediaObjectUrl(
|
||||||
detection?.detection.context_image_url,
|
detection?.detection.context_image_url,
|
||||||
);
|
);
|
||||||
@@ -35,9 +42,65 @@ export default function AnnotatedDetectionImage({
|
|||||||
: [];
|
: [];
|
||||||
|
|
||||||
const aspectRatio =
|
const aspectRatio =
|
||||||
videoWidth > 0 && videoHeight > 0
|
aspectRatioOverride ??
|
||||||
|
(videoWidth > 0 && videoHeight > 0
|
||||||
? `${videoWidth} / ${videoHeight}`
|
? `${videoWidth} / ${videoHeight}`
|
||||||
: '16 / 9';
|
: '16 / 9');
|
||||||
|
|
||||||
|
const annotatedMedia = objectUrl ? (
|
||||||
|
<>
|
||||||
|
<Image
|
||||||
|
src={objectUrl}
|
||||||
|
alt={`${detection?.detection.display_name ?? 'Road defect'} detection`}
|
||||||
|
fill
|
||||||
|
unoptimized
|
||||||
|
sizes="(min-width: 1280px) 18rem, (min-width: 640px) 50vw, 100vw"
|
||||||
|
className="object-contain"
|
||||||
|
/>
|
||||||
|
<BoundingBoxOverlay
|
||||||
|
detections={overlayDetections}
|
||||||
|
videoWidth={videoWidth}
|
||||||
|
videoHeight={videoHeight}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : null;
|
||||||
|
|
||||||
|
if (detection && objectUrl && enableLightbox) {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => setIsPreviewOpen(true)}
|
||||||
|
aria-label={`Open ${detection.detection.display_name} detection image`}
|
||||||
|
className="group relative flex w-full cursor-zoom-in items-center justify-center overflow-hidden rounded-lg border bg-black focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
|
||||||
|
style={{ aspectRatio }}
|
||||||
|
>
|
||||||
|
<Image
|
||||||
|
src={objectUrl}
|
||||||
|
alt={`${detection.detection.display_name} detection`}
|
||||||
|
fill
|
||||||
|
unoptimized
|
||||||
|
sizes="(min-width: 1280px) 18rem, (min-width: 640px) 50vw, 100vw"
|
||||||
|
className="object-contain"
|
||||||
|
/>
|
||||||
|
<span className="pointer-events-none absolute inset-x-0 bottom-0 z-[3] bg-gradient-to-t from-black/70 to-transparent px-3 pb-2 pt-8 text-center text-xs font-medium text-white opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100">
|
||||||
|
Click to view annotated image
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<Dialog open={isPreviewOpen} onOpenChange={setIsPreviewOpen}>
|
||||||
|
<DialogContent className="h-[calc(100vh-2rem)] bg-black/95 p-4 text-white sm:max-w-[calc(100vw-2rem)]">
|
||||||
|
<DialogTitle className="sr-only">
|
||||||
|
{detection.detection.display_name} annotated detection image
|
||||||
|
</DialogTitle>
|
||||||
|
<div className="relative min-h-0 w-full flex-1 overflow-hidden rounded-lg bg-black">
|
||||||
|
{annotatedMedia}
|
||||||
|
</div>
|
||||||
|
</DialogContent>
|
||||||
|
</Dialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -60,20 +123,7 @@ export default function AnnotatedDetectionImage({
|
|||||||
<p>Failed to load the detection image.</p>
|
<p>Failed to load the detection image.</p>
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
annotatedMedia
|
||||||
<Image
|
|
||||||
src={objectUrl}
|
|
||||||
alt={`${detection.detection.display_name} detection`}
|
|
||||||
fill
|
|
||||||
unoptimized
|
|
||||||
className="object-contain"
|
|
||||||
/>
|
|
||||||
<BoundingBoxOverlay
|
|
||||||
detections={overlayDetections}
|
|
||||||
videoWidth={videoWidth}
|
|
||||||
videoHeight={videoHeight}
|
|
||||||
/>
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -68,16 +68,14 @@ export const API_ROUTES = {
|
|||||||
`/biz/api/v1/tickets/${id}/class-detail?defect_class=${defectClass}`,
|
`/biz/api/v1/tickets/${id}/class-detail?defect_class=${defectClass}`,
|
||||||
DEFECT_CLASSES: (id: string) => `/biz/api/v1/tickets/${id}/defect-classes`,
|
DEFECT_CLASSES: (id: string) => `/biz/api/v1/tickets/${id}/defect-classes`,
|
||||||
ASSIGN: (id: string) => `/biz/api/v1/tickets/${id}/assign`,
|
ASSIGN: (id: string) => `/biz/api/v1/tickets/${id}/assign`,
|
||||||
SUBMIT_REPAIR: (id: string) => `/biz/api/v1/tickets/${id}/submit-repair`,
|
|
||||||
SUBMIT_REPAIR_UPLOAD: (id: string) =>
|
|
||||||
`/biz/api/v1/tickets/${id}/repair-proof`,
|
|
||||||
REQUEST_EXTENSION: (ticketId: string, assignmentId: number) =>
|
REQUEST_EXTENSION: (ticketId: string, assignmentId: number) =>
|
||||||
`/biz/api/v1/tickets/${ticketId}/assignments/${assignmentId}/extension-requests`,
|
`/biz/api/v1/tickets/${ticketId}/assignments/${assignmentId}/extension-requests`,
|
||||||
EXTENSION_REQUESTS: (ticketId: string) =>
|
EXTENSION_REQUESTS: (ticketId: string) =>
|
||||||
`/biz/api/v1/tickets/${ticketId}/extension-requests`,
|
`/biz/api/v1/tickets/${ticketId}/extension-requests`,
|
||||||
REVIEW_EXTENSION_REQUEST: (ticketId: string, assignmentId: number) =>
|
REVIEW_EXTENSION_REQUEST: (ticketId: string, assignmentId: number) =>
|
||||||
`/biz/api/v1/tickets/${ticketId}/assignments/${assignmentId}/extension-request/decision`,
|
`/biz/api/v1/tickets/${ticketId}/assignments/${assignmentId}/extension-request/decision`,
|
||||||
REVIEW: (id: string) => `/biz/api/v1/tickets/${id}/review`,
|
REVIEW_DETECTION_REPAIR_PROOF: (ticketId: string, detectionId: number) =>
|
||||||
|
`/biz/api/v1/tickets/${ticketId}/detections/${detectionId}/repair-proof/review`,
|
||||||
CLOSE: (id: string) => `/biz/api/v1/tickets/${id}/close`,
|
CLOSE: (id: string) => `/biz/api/v1/tickets/${id}/close`,
|
||||||
DETAIL_EVENTS_TOKEN: (id: string) =>
|
DETAIL_EVENTS_TOKEN: (id: string) =>
|
||||||
`/biz/api/v1/tickets/${id}/events/token`,
|
`/biz/api/v1/tickets/${id}/events/token`,
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
export const ENV_CONSTANT = {
|
export const ENV_CONSTANT = {
|
||||||
BASE_API_URL: process.env.NEXT_PUBLIC_API_URL,
|
BASE_API_URL: '/',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ export const authService = {
|
|||||||
const response = await axiosAuth.post<AuthResponseData>(
|
const response = await axiosAuth.post<AuthResponseData>(
|
||||||
API_ROUTES.AUTH.LOGIN,
|
API_ROUTES.AUTH.LOGIN,
|
||||||
payload,
|
payload,
|
||||||
{
|
|
||||||
withCredentials: true,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
@@ -24,14 +21,11 @@ export const authService = {
|
|||||||
const response = await axiosAuth.post<AuthResponseData>(
|
const response = await axiosAuth.post<AuthResponseData>(
|
||||||
API_ROUTES.AUTH.REFRESH,
|
API_ROUTES.AUTH.REFRESH,
|
||||||
{},
|
{},
|
||||||
{
|
|
||||||
withCredentials: true,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
logout: async (): Promise<void> => {
|
logout: async (): Promise<void> => {
|
||||||
await axiosAuth.post(API_ROUTES.AUTH.LOGOUT, {}, { withCredentials: true });
|
await axiosAuth.post(API_ROUTES.AUTH.LOGOUT, {});
|
||||||
},
|
},
|
||||||
me: async (): Promise<MeResponse> => {
|
me: async (): Promise<MeResponse> => {
|
||||||
const response = await axiosClient.get<MeResponse>(API_ROUTES.AUTH.ME);
|
const response = await axiosClient.get<MeResponse>(API_ROUTES.AUTH.ME);
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { API_ROUTES } from '@/constants/apiRoutes';
|
|||||||
import type {
|
import type {
|
||||||
DiscardDetectionPayload,
|
DiscardDetectionPayload,
|
||||||
DiscardDetectionResponse,
|
DiscardDetectionResponse,
|
||||||
|
ReviewDetectionRepairProofPayload,
|
||||||
|
ReviewDetectionRepairProofResponse,
|
||||||
} from '@/types';
|
} from '@/types';
|
||||||
|
|
||||||
import axiosClient from '../axios/axios';
|
import axiosClient from '../axios/axios';
|
||||||
@@ -18,4 +20,17 @@ export const detectionService = {
|
|||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
reviewRepairProof: async (
|
||||||
|
ticketId: string,
|
||||||
|
detectionId: number,
|
||||||
|
payload: ReviewDetectionRepairProofPayload,
|
||||||
|
): Promise<ReviewDetectionRepairProofResponse> => {
|
||||||
|
const response = await axiosClient.post<ReviewDetectionRepairProofResponse>(
|
||||||
|
API_ROUTES.TICKETS.REVIEW_DETECTION_REPAIR_PROOF(ticketId, detectionId),
|
||||||
|
payload,
|
||||||
|
);
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ import type {
|
|||||||
CloseTicketPayload,
|
CloseTicketPayload,
|
||||||
RequestTicketExtensionPayload,
|
RequestTicketExtensionPayload,
|
||||||
ReviewTicketExtensionPayload,
|
ReviewTicketExtensionPayload,
|
||||||
ReviewRepairPayload,
|
|
||||||
SseTokenResponse,
|
SseTokenResponse,
|
||||||
SubmitRepairPayload,
|
|
||||||
SubmitRepairUploadPayload,
|
|
||||||
TicketDetail,
|
TicketDetail,
|
||||||
TicketExtensionRequestsResponse,
|
TicketExtensionRequestsResponse,
|
||||||
TicketOverviewDetail,
|
TicketOverviewDetail,
|
||||||
@@ -91,41 +88,6 @@ export const ticketService = {
|
|||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
|
|
||||||
submitRepair: async (
|
|
||||||
ticketId: string,
|
|
||||||
payload: SubmitRepairPayload,
|
|
||||||
): Promise<TicketDetail> => {
|
|
||||||
const response = await axiosClient.post<TicketDetail>(
|
|
||||||
API_ROUTES.TICKETS.SUBMIT_REPAIR(ticketId),
|
|
||||||
payload,
|
|
||||||
);
|
|
||||||
return response.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
submitRepairUpload: async (
|
|
||||||
ticketId: string,
|
|
||||||
payload: SubmitRepairUploadPayload,
|
|
||||||
): Promise<TicketDetail> => {
|
|
||||||
const formData = new FormData();
|
|
||||||
formData.append('defect_class', payload.defect_class);
|
|
||||||
formData.append('notes', payload.notes);
|
|
||||||
formData.append('video', payload.video);
|
|
||||||
payload.images.forEach((image) => {
|
|
||||||
formData.append('images', image);
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = await axiosClient.post<TicketDetail>(
|
|
||||||
API_ROUTES.TICKETS.SUBMIT_REPAIR_UPLOAD(ticketId),
|
|
||||||
formData,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'multipart/form-data',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
return response.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
requestTicketExtension: async (
|
requestTicketExtension: async (
|
||||||
ticketId: string,
|
ticketId: string,
|
||||||
assignmentId: number,
|
assignmentId: number,
|
||||||
@@ -162,17 +124,6 @@ export const ticketService = {
|
|||||||
);
|
);
|
||||||
return response.data;
|
return response.data;
|
||||||
},
|
},
|
||||||
reviewRepair: async (
|
|
||||||
ticketId: string,
|
|
||||||
payload: ReviewRepairPayload,
|
|
||||||
): Promise<TicketDetail> => {
|
|
||||||
const response = await axiosClient.post<TicketDetail>(
|
|
||||||
API_ROUTES.TICKETS.REVIEW(ticketId),
|
|
||||||
payload,
|
|
||||||
);
|
|
||||||
return response.data;
|
|
||||||
},
|
|
||||||
|
|
||||||
closeTicket: async (
|
closeTicket: async (
|
||||||
ticketId: string,
|
ticketId: string,
|
||||||
payload: CloseTicketPayload,
|
payload: CloseTicketPayload,
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ export const videoService = {
|
|||||||
skip: params?.skip ?? 0,
|
skip: params?.skip ?? 0,
|
||||||
limit: params?.limit ?? 1,
|
limit: params?.limit ?? 1,
|
||||||
class_name: params?.class_name,
|
class_name: params?.class_name,
|
||||||
|
proof_status: params?.proof_status,
|
||||||
min_confidence: params?.min_confidence,
|
min_confidence: params?.min_confidence,
|
||||||
sort: params?.sort ?? 'timestamp_asc',
|
sort: params?.sort ?? 'timestamp_asc',
|
||||||
search: params?.search,
|
search: params?.search,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ const BASE_URL = ENV_CONSTANT.BASE_API_URL;
|
|||||||
|
|
||||||
const axiosClient = axios.create({
|
const axiosClient = axios.create({
|
||||||
baseURL: BASE_URL,
|
baseURL: BASE_URL,
|
||||||
|
withCredentials: true,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
@@ -14,6 +15,7 @@ const axiosClient = axios.create({
|
|||||||
|
|
||||||
export const axiosAuth = axios.create({
|
export const axiosAuth = axios.create({
|
||||||
baseURL: BASE_URL,
|
baseURL: BASE_URL,
|
||||||
|
withCredentials: true,
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
@@ -30,13 +32,7 @@ const isInvalidSessionResponse = (error: unknown) => {
|
|||||||
const refreshAccessToken = () => {
|
const refreshAccessToken = () => {
|
||||||
if (!refreshPromise) {
|
if (!refreshPromise) {
|
||||||
refreshPromise = axiosAuth
|
refreshPromise = axiosAuth
|
||||||
.post(
|
.post('api/auth/refresh', {})
|
||||||
'api/auth/refresh',
|
|
||||||
{},
|
|
||||||
{
|
|
||||||
withCredentials: true,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const accessToken = response.data?.access_token;
|
const accessToken = response.data?.access_token;
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,25 @@ export type BoundingBoxOverlayItem = {
|
|||||||
bounding_box: DetectionBoundingBox;
|
bounding_box: DetectionBoundingBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type DetectionRepairProof = {
|
||||||
|
submitted: boolean;
|
||||||
|
review_status: 'pending' | 'approved' | 'rejected';
|
||||||
|
notes: string | null;
|
||||||
|
proof_image_urls: string[];
|
||||||
|
submitted_at: string | null;
|
||||||
|
reviewed_at: string | null;
|
||||||
|
review_comment: string | null;
|
||||||
|
reviewed_by_user_id?: number | null;
|
||||||
|
reviewed_by_name?: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ReviewDetectionRepairProofPayload = {
|
||||||
|
action: 'approve' | 'reject';
|
||||||
|
comment?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ReviewDetectionRepairProofResponse = DetectionRepairProof;
|
||||||
|
|
||||||
export type DetectionResultItem = {
|
export type DetectionResultItem = {
|
||||||
id: string;
|
id: string;
|
||||||
detection: {
|
detection: {
|
||||||
@@ -42,6 +61,7 @@ export type DetectionResultItem = {
|
|||||||
latitude: number | null;
|
latitude: number | null;
|
||||||
longitude: number | null;
|
longitude: number | null;
|
||||||
};
|
};
|
||||||
|
repair_proof: DetectionRepairProof | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type DetectionResultLog = DetectionResultItem & {
|
export type DetectionResultLog = DetectionResultItem & {
|
||||||
@@ -59,11 +79,19 @@ export type VideoDetectionsParams = {
|
|||||||
skip?: number;
|
skip?: number;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
class_name?: string | string[];
|
class_name?: string | string[];
|
||||||
|
proof_status?: DetectionProofStatus;
|
||||||
min_confidence?: number;
|
min_confidence?: number;
|
||||||
sort?: string;
|
sort?: string;
|
||||||
search?: string;
|
search?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type DetectionProofStatus =
|
||||||
|
| 'not_submitted'
|
||||||
|
| 'submitted'
|
||||||
|
| 'pending'
|
||||||
|
| 'approved'
|
||||||
|
| 'rejected';
|
||||||
|
|
||||||
export type VideoDetectionsResponse = {
|
export type VideoDetectionsResponse = {
|
||||||
video_id: string;
|
video_id: string;
|
||||||
video_width: number;
|
video_width: number;
|
||||||
|
|||||||
@@ -29,18 +29,6 @@ export interface AssignTicketPayload {
|
|||||||
note?: string;
|
note?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SubmitRepairPayload {
|
|
||||||
notes: string;
|
|
||||||
proof_path: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface SubmitRepairUploadPayload {
|
|
||||||
defect_class: string;
|
|
||||||
notes: string;
|
|
||||||
video: File;
|
|
||||||
images: File[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface RequestTicketExtensionPayload {
|
export interface RequestTicketExtensionPayload {
|
||||||
requested_due_at: string;
|
requested_due_at: string;
|
||||||
reason: string;
|
reason: string;
|
||||||
@@ -80,12 +68,6 @@ export interface TicketExtensionRequestsResponse {
|
|||||||
total: number;
|
total: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ReviewRepairPayload {
|
|
||||||
defect_class: string;
|
|
||||||
action: 'approve' | 'reject';
|
|
||||||
comment: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CloseTicketPayload {
|
export interface CloseTicketPayload {
|
||||||
defect_class: string;
|
defect_class: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,7 @@ export const ROUTES = {
|
|||||||
ACCOUNT: '/account',
|
ACCOUNT: '/account',
|
||||||
UPLOAD: '/upload',
|
UPLOAD: '/upload',
|
||||||
TICKET: '/ticket',
|
TICKET: '/ticket',
|
||||||
|
TICKET_DETAIL: (ticketId: string) => `/ticket/${ticketId}`,
|
||||||
|
TICKET_CLASS_REVIEW: (ticketId: string, defectClass: string) =>
|
||||||
|
`/ticket/${ticketId}/${defectClass}/review`,
|
||||||
} as const;
|
} as const;
|
||||||
|
|||||||
Reference in New Issue
Block a user