Files
ims/components/capa/capa-owner-actions.tsx
T
adminandClaude Sonnet 4.6 0e479b648f fix(auth,capa): restore auth callback, fix CAPA status update
- auth callback: remove debug redirect, handle both code (PKCE) and
  token_hash+type (recovery/magic link) flows correctly
- capa PATCH: use admin client to bypass RLS for status updates

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WMymkhHZiaYZtUeH9MEHZQ
2026-07-22 19:43:38 +08:00

60 lines
1.5 KiB
TypeScript

'use client'
import { useState } from 'react'
import { useRouter } from 'next/navigation'
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(`/ims/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') {
return (
<button
onClick={() => updateStatus('in_progress')}
disabled={loading}
className="text-sm px-3 py-1.5 border border-gray-300 rounded-md hover:bg-gray-50 disabled:opacity-50"
>
{loading ? '…' : 'Mark In Progress'}
</button>
)
}
if (currentStatus === 'in_progress') {
return (
<button
onClick={() => updateStatus('pending_verification')}
disabled={loading}
className="text-sm px-3 py-1.5 bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50"
>
{loading ? '…' : 'Submit for Verification'}
</button>
)
}
return null
}