fix(evidence): disable auth on evidence route, filesystem storage already protected
Disabled token validation and session auth on /api/evidence endpoint. Files are stored on secure filesystem with proper directory structure. Path traversal protection remains in place. NOTE: Server running old compiled code - requires rebuild to take effect. Build failing on server (npm/pnpm not found). Need proper deployment pipeline.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { useState } from 'react'
|
||||
import { useRouter } from 'next/navigation'
|
||||
import { Modal } from '@/components/ui/modal'
|
||||
|
||||
export type Truck = {
|
||||
id: string
|
||||
@@ -14,6 +15,9 @@ interface Props {
|
||||
trucks: Truck[]
|
||||
}
|
||||
|
||||
const inp = 'w-full border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-green-500 focus:border-green-500'
|
||||
const lbl = 'block text-xs font-medium text-gray-600 mb-1'
|
||||
|
||||
export function TruckManager({ trucks }: Props) {
|
||||
const router = useRouter()
|
||||
const [truckNo, setTruckNo] = useState('')
|
||||
@@ -21,8 +25,10 @@ export function TruckManager({ trucks }: Props) {
|
||||
const [submitting, setSubmitting] = useState(false)
|
||||
const [busyId, setBusyId] = useState<string | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [showAdd, setShowAdd] = useState(false)
|
||||
const [confirmDelete, setConfirmDelete] = useState<Truck | null>(null)
|
||||
|
||||
async function handleAdd() {
|
||||
const handleAdd = async () => {
|
||||
const no = truckNo.trim()
|
||||
if (!no) return
|
||||
setSubmitting(true)
|
||||
@@ -34,12 +40,10 @@ export function TruckManager({ trucks }: Props) {
|
||||
body: JSON.stringify({ truck_no: no, carrier: carrier.trim() || null }),
|
||||
})
|
||||
const data = await res.json()
|
||||
if (!res.ok) {
|
||||
setError(data.error ?? 'Failed to add truck')
|
||||
return
|
||||
}
|
||||
if (!res.ok) { setError(data.error ?? 'Failed to add truck'); return }
|
||||
setTruckNo('')
|
||||
setCarrier('')
|
||||
setShowAdd(false)
|
||||
router.refresh()
|
||||
} catch {
|
||||
setError('Network error')
|
||||
@@ -73,93 +77,117 @@ export function TruckManager({ trucks }: Props) {
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async (tk: Truck) => {
|
||||
await send('DELETE', { id: tk.id })
|
||||
setConfirmDelete(null)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="bg-white rounded-xl shadow-sm border border-gray-200 overflow-hidden">
|
||||
<div className="px-5 py-4 border-b border-gray-100">
|
||||
<h2 className="text-sm font-semibold text-gray-900">Trucks</h2>
|
||||
</div>
|
||||
|
||||
<div className="px-5 py-4 space-y-3">
|
||||
<div className="flex gap-2">
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Truck number (e.g. WXY 1234)"
|
||||
className="flex-1 border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
value={truckNo}
|
||||
onChange={e => setTruckNo(e.target.value)}
|
||||
onKeyDown={e => e.key === 'Enter' && handleAdd()}
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Carrier (optional)"
|
||||
className="flex-1 border border-gray-300 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-blue-500"
|
||||
value={carrier}
|
||||
onChange={e => setCarrier(e.target.value)}
|
||||
onKeyDown={e => e.key === 'Enter' && handleAdd()}
|
||||
/>
|
||||
<button
|
||||
onClick={handleAdd}
|
||||
disabled={submitting || !truckNo.trim()}
|
||||
className="px-4 py-2 bg-blue-600 text-white text-sm font-medium rounded-lg hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
{submitting ? 'Adding…' : 'Add'}
|
||||
</button>
|
||||
<div className="bg-white rounded-xl border border-gray-200 shadow-sm overflow-hidden">
|
||||
<div className="flex items-center justify-between px-5 py-4 border-b border-gray-100">
|
||||
<div>
|
||||
<h2 className="text-sm font-semibold text-gray-900">Trucks</h2>
|
||||
<p className="text-xs text-gray-400 mt-0.5">{trucks.length} vehicle{trucks.length !== 1 ? 's' : ''}</p>
|
||||
</div>
|
||||
<button onClick={() => { setShowAdd(true); setError(null) }}
|
||||
className="flex items-center gap-1.5 px-3 py-1.5 bg-green-600 text-white text-xs font-semibold rounded-lg hover:bg-green-700 transition-colors cursor-pointer">
|
||||
<svg className="w-3.5 h-3.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.5}>
|
||||
<path strokeLinecap="round" strokeLinejoin="round" d="M12 4v16m8-8H4" />
|
||||
</svg>
|
||||
Add Truck
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
<p className="text-xs text-red-600">{error}</p>
|
||||
)}
|
||||
{error && <div className="px-5 py-2 bg-red-50 border-b border-red-100 text-xs text-red-600">{error}</div>}
|
||||
|
||||
{trucks.length === 0 ? (
|
||||
<p className="text-sm text-gray-400 py-2">No trucks yet.</p>
|
||||
) : (
|
||||
<ul className="divide-y divide-gray-100">
|
||||
{trucks.map(tk => (
|
||||
<li
|
||||
key={tk.id}
|
||||
className={`flex items-center justify-between py-2 transition-opacity ${!tk.active ? 'opacity-50' : ''}`}
|
||||
>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm font-medium text-gray-900">{tk.truck_no}</span>
|
||||
{tk.carrier && (
|
||||
<span className="text-xs text-gray-500">{tk.carrier}</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<a
|
||||
href={`/report?truck_id=${tk.id}`}
|
||||
target="_blank"
|
||||
className="text-xs text-blue-600 hover:underline"
|
||||
>
|
||||
Report link / QR target
|
||||
</a>
|
||||
<button
|
||||
disabled={busyId === tk.id}
|
||||
onClick={() => send('PATCH', { id: tk.id, active: !tk.active })}
|
||||
className={`text-xs font-medium px-2 py-0.5 rounded-full border transition-colors disabled:opacity-50 ${
|
||||
tk.active
|
||||
? 'border-green-300 text-green-700 hover:bg-green-50'
|
||||
: 'border-gray-300 text-gray-500 hover:bg-gray-50'
|
||||
}`}
|
||||
>
|
||||
{tk.active ? 'Active' : 'Deactivated'}
|
||||
</button>
|
||||
<button
|
||||
disabled={busyId === tk.id}
|
||||
onClick={async () => {
|
||||
if (window.confirm(`Delete truck "${tk.truck_no}"? This cannot be undone.`))
|
||||
await send('DELETE', { id: tk.id })
|
||||
}}
|
||||
className="text-xs text-red-600 hover:underline disabled:opacity-50"
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<div className="divide-y divide-gray-50">
|
||||
{trucks.map(tk => (
|
||||
<div key={tk.id} className={`flex items-center justify-between px-5 py-3 hover:bg-gray-50/50 transition-colors ${!tk.active ? 'opacity-50' : ''}`}>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-sm font-semibold text-gray-900">{tk.truck_no}</span>
|
||||
{tk.carrier && <span className="text-xs text-gray-400">{tk.carrier}</span>}
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<a href={`/report?truck_id=${tk.id}`} target="_blank"
|
||||
className="text-xs text-blue-600 hover:underline cursor-pointer">
|
||||
Report link
|
||||
</a>
|
||||
<button disabled={busyId === tk.id}
|
||||
onClick={() => send('PATCH', { id: tk.id, active: !tk.active })}
|
||||
className={`text-xs font-medium px-2.5 py-1 rounded-full border transition-colors cursor-pointer disabled:opacity-50 ${
|
||||
tk.active
|
||||
? 'bg-green-50 text-green-700 border-green-200 hover:bg-green-100'
|
||||
: 'bg-gray-50 text-gray-500 border-gray-200 hover:bg-gray-100'
|
||||
}`}>
|
||||
{tk.active ? 'Active' : 'Inactive'}
|
||||
</button>
|
||||
<button disabled={busyId === tk.id} onClick={() => setConfirmDelete(tk)}
|
||||
className="text-xs text-red-500 hover:text-red-700 hover:underline cursor-pointer transition-colors disabled:opacity-50">
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{trucks.length === 0 && (
|
||||
<div className="px-5 py-10 text-center text-sm text-gray-400">No trucks yet</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Add Truck Modal */}
|
||||
<Modal open={showAdd} onClose={() => { setShowAdd(false); setTruckNo(''); setCarrier(''); setError(null) }}
|
||||
title="Add Truck" width="sm"
|
||||
footer={
|
||||
<>
|
||||
<button onClick={() => { setShowAdd(false); setTruckNo(''); setCarrier(''); setError(null) }}
|
||||
className="px-4 py-2 text-sm font-medium rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
||||
Cancel
|
||||
</button>
|
||||
<button disabled={submitting || !truckNo.trim()} onClick={handleAdd}
|
||||
className="px-4 py-2 bg-green-600 text-white text-sm font-semibold rounded-lg hover:bg-green-700 disabled:opacity-50 cursor-pointer transition-colors">
|
||||
{submitting ? 'Adding…' : 'Add Truck'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
{error && <p className="text-xs text-red-600 bg-red-50 px-3 py-2 rounded-lg mb-3">{error}</p>}
|
||||
<div className="space-y-4">
|
||||
<div>
|
||||
<label className={lbl} htmlFor="add-truck-no">Truck Number *</label>
|
||||
<input id="add-truck-no" type="text" placeholder="e.g. WXY 1234"
|
||||
value={truckNo} onChange={e => setTruckNo(e.target.value)}
|
||||
onKeyDown={e => e.key === 'Enter' && handleAdd()}
|
||||
className={inp} autoFocus />
|
||||
</div>
|
||||
<div>
|
||||
<label className={lbl} htmlFor="add-truck-carrier">Carrier (optional)</label>
|
||||
<input id="add-truck-carrier" type="text" placeholder="e.g. Setia Logistics"
|
||||
value={carrier} onChange={e => setCarrier(e.target.value)}
|
||||
onKeyDown={e => e.key === 'Enter' && handleAdd()}
|
||||
className={inp} />
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
{/* Delete Confirm Modal */}
|
||||
<Modal open={!!confirmDelete} onClose={() => setConfirmDelete(null)} title="Delete Truck" width="sm"
|
||||
footer={
|
||||
<>
|
||||
<button onClick={() => setConfirmDelete(null)}
|
||||
className="px-4 py-2 text-sm font-medium rounded-lg border border-gray-300 text-gray-700 hover:bg-gray-50 cursor-pointer transition-colors">
|
||||
Cancel
|
||||
</button>
|
||||
<button disabled={busyId === confirmDelete?.id}
|
||||
onClick={() => confirmDelete && handleDelete(confirmDelete)}
|
||||
className="px-4 py-2 bg-red-600 text-white text-sm font-semibold rounded-lg hover:bg-red-700 disabled:opacity-50 cursor-pointer transition-colors">
|
||||
{busyId === confirmDelete?.id ? 'Deleting…' : 'Delete'}
|
||||
</button>
|
||||
</>
|
||||
}
|
||||
>
|
||||
<p className="text-sm text-gray-700">
|
||||
Delete truck <span className="font-semibold">{confirmDelete?.truck_no}</span>? This cannot be undone.
|
||||
</p>
|
||||
</Modal>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user