fix: rename on-time rate label, hoist getApiKey above escalation loop, remove broken capa-owner incident link
This commit is contained in:
@@ -78,9 +78,7 @@ export default async function CapaOwnerPage() {
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-sm text-gray-800">{capa.description}</p>
|
||||
{incRef && (
|
||||
<Link href={`/hse/incidents/${capa.incident_id}`} className="text-xs text-blue-600 hover:underline mt-0.5 block">
|
||||
{incRef}
|
||||
</Link>
|
||||
<p className="text-xs text-gray-500 mt-0.5">{incRef}</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="shrink-0 text-right">
|
||||
|
||||
@@ -166,7 +166,7 @@ export default async function SupervisorPage() {
|
||||
</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>
|
||||
)}
|
||||
</main>
|
||||
|
||||
@@ -45,6 +45,9 @@ export async function escalateOverdueCapa(
|
||||
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL ?? 'http://localhost:3000'
|
||||
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) {
|
||||
const threshold = getEscalationThreshold((capa as { due_date: string }).due_date)
|
||||
if (!threshold) continue
|
||||
@@ -98,14 +101,12 @@ export async function escalateOverdueCapa(
|
||||
const ownerPhone = (capa.owner as unknown as { phone: string | null } | null)?.phone ?? ''
|
||||
if (ownerPhone) {
|
||||
try {
|
||||
const phoneNumberId = await getApiKey(supabase, 'META_WHATSAPP_PHONE_NUMBER_ID')
|
||||
const accessToken = await getApiKey(supabase, 'META_WHATSAPP_ACCESS_TOKEN')
|
||||
await sendWhatsAppMessage(
|
||||
ownerPhone,
|
||||
'ims_capa_overdue',
|
||||
[incidentRef, (capa as { description: string }).description, (capa as { due_date: string }).due_date],
|
||||
phoneNumberId,
|
||||
accessToken,
|
||||
whatsappPhoneNumberId,
|
||||
whatsappAccessToken,
|
||||
)
|
||||
} catch (waErr) {
|
||||
console.error('WhatsApp escalation error:', waErr)
|
||||
|
||||
Reference in New Issue
Block a user