53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
'use client'
|
|
|
|
import { useState } from 'react'
|
|
import { useRouter } from 'next/navigation'
|
|
import { Button } from '@/components/ui/button'
|
|
|
|
interface Props {
|
|
capaId: string
|
|
currentStatus: string
|
|
}
|
|
|
|
export function CapaOwnerActions({ capaId, currentStatus }: Props) {
|
|
const router = useRouter()
|
|
const [loading, setLoading] = useState(false)
|
|
|
|
async function updateStatus(status: string) {
|
|
setLoading(true)
|
|
try {
|
|
const res = await fetch(`/api/capa/${capaId}`, {
|
|
method: 'PATCH',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ status }),
|
|
})
|
|
if (!res.ok) {
|
|
alert('Update failed. Please try again.')
|
|
return
|
|
}
|
|
router.refresh()
|
|
setTimeout(() => window.location.reload(), 300)
|
|
} finally {
|
|
setLoading(false)
|
|
}
|
|
}
|
|
|
|
if (currentStatus === 'open' || currentStatus === 'reopened' || currentStatus === 'overdue') {
|
|
return (
|
|
<Button variant="secondary" onClick={() => updateStatus('in_progress')} disabled={loading}>
|
|
{loading ? '…' : 'Mark In Progress'}
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
if (currentStatus === 'in_progress') {
|
|
return (
|
|
<Button onClick={() => updateStatus('pending_verification')} disabled={loading}>
|
|
{loading ? '…' : 'Submit for Verification'}
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
return null
|
|
}
|