fix: rename on-time rate label, hoist getApiKey above escalation loop, remove broken capa-owner incident link

This commit is contained in:
2026-07-11 19:03:23 +08:00
parent 87264a5497
commit 871ef7c53a
3 changed files with 7 additions and 8 deletions
+1 -3
View File
@@ -78,9 +78,7 @@ export default async function CapaOwnerPage() {
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
<p className="text-sm text-gray-800">{capa.description}</p> <p className="text-sm text-gray-800">{capa.description}</p>
{incRef && ( {incRef && (
<Link href={`/hse/incidents/${capa.incident_id}`} className="text-xs text-blue-600 hover:underline mt-0.5 block"> <p className="text-xs text-gray-500 mt-0.5">{incRef}</p>
{incRef}
</Link>
)} )}
</div> </div>
<div className="shrink-0 text-right"> <div className="shrink-0 text-right">
+1 -1
View File
@@ -166,7 +166,7 @@ export default async function SupervisorPage() {
</div> </div>
))} ))}
</div> </div>
<p className="text-xs text-gray-400 mt-3">CAPA on-time rate: {capaRows.length > 0 ? Math.round((capaVerifiedCount / capaRows.length) * 100) : 'N/A'}%</p> <p className="text-xs text-gray-400 mt-3">CAPA verification rate: {capaRows.length > 0 ? Math.round((capaVerifiedCount / capaRows.length) * 100) : 'N/A'}%</p>
</div> </div>
)} )}
</main> </main>
+5 -4
View File
@@ -45,6 +45,9 @@ export async function escalateOverdueCapa(
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL ?? 'http://localhost:3000' const siteUrl = process.env.NEXT_PUBLIC_SITE_URL ?? 'http://localhost:3000'
let notified = 0 let notified = 0
const whatsappPhoneNumberId = await getApiKey(supabase, 'META_WHATSAPP_PHONE_NUMBER_ID')
const whatsappAccessToken = await getApiKey(supabase, 'META_WHATSAPP_ACCESS_TOKEN')
for (const capa of capas) { for (const capa of capas) {
const threshold = getEscalationThreshold((capa as { due_date: string }).due_date) const threshold = getEscalationThreshold((capa as { due_date: string }).due_date)
if (!threshold) continue if (!threshold) continue
@@ -98,14 +101,12 @@ export async function escalateOverdueCapa(
const ownerPhone = (capa.owner as unknown as { phone: string | null } | null)?.phone ?? '' const ownerPhone = (capa.owner as unknown as { phone: string | null } | null)?.phone ?? ''
if (ownerPhone) { if (ownerPhone) {
try { try {
const phoneNumberId = await getApiKey(supabase, 'META_WHATSAPP_PHONE_NUMBER_ID')
const accessToken = await getApiKey(supabase, 'META_WHATSAPP_ACCESS_TOKEN')
await sendWhatsAppMessage( await sendWhatsAppMessage(
ownerPhone, ownerPhone,
'ims_capa_overdue', 'ims_capa_overdue',
[incidentRef, (capa as { description: string }).description, (capa as { due_date: string }).due_date], [incidentRef, (capa as { description: string }).description, (capa as { due_date: string }).due_date],
phoneNumberId, whatsappPhoneNumberId,
accessToken, whatsappAccessToken,
) )
} catch (waErr) { } catch (waErr) {
console.error('WhatsApp escalation error:', waErr) console.error('WhatsApp escalation error:', waErr)