'use client'; import { useEffect, useState } from 'react'; import { Job } from '@prisma/client'; import { apiClient } from '@/utils/api'; interface JobPluginProps { job: Job; } export default function JobPlugin({ job }: JobPluginProps) { const [html, setHtml] = useState(null); const [status, setStatus] = useState<'loading' | 'success' | 'error'>('loading'); // An iframe src request cannot send the Authorization header the API requires, // so fetch the html through apiClient and load it via srcDoc instead. useEffect(() => { apiClient .get(`/api/jobs/${job.id}/plugin`, { responseType: 'text' }) .then(res => { setHtml(res.data); setStatus('success'); }) .catch(error => { console.error('Error fetching plugin:', error); setStatus('error'); }); }, [job.id]); if (status === 'loading') { return

Loading plugin...

; } if (status === 'error' || html == null) { return

Error loading plugin

; } // Sandboxed iframe keeps the plugin's scripts and styles isolated from the app. // allow-scripts lets its