BlockerImport.tsx
1,473 bytes
| 1 | import { useState } from 'react' |
|---|---|
| 2 | import * as api from '../api' |
| 3 | |
| 4 | interface BlockerImportProps { |
| 5 | sessionId: string |
| 6 | onImported: () => void |
| 7 | } |
| 8 | |
| 9 | export function BlockerImport({ sessionId, onImported }: BlockerImportProps) { |
| 10 | const [importing, setImporting] = useState(false) |
| 11 | const [message, setMessage] = useState<string | null>(null) |
| 12 | const [error, setError] = useState<string | null>(null) |
| 13 | |
| 14 | async function handleImport() { |
| 15 | setImporting(true) |
| 16 | setError(null) |
| 17 | setMessage(null) |
| 18 | try { |
| 19 | const { questions } = await api.importBlockers(sessionId) |
| 20 | if (questions.length === 0) { |
| 21 | setMessage("Didn't find any open questions in BLOCKED.md.") |
| 22 | } else { |
| 23 | setMessage(`Found ${questions.length} open question(s). Answer them below.`) |
| 24 | onImported() |
| 25 | } |
| 26 | } catch (err) { |
| 27 | setError(err instanceof Error ? err.message : String(err)) |
| 28 | } finally { |
| 29 | setImporting(false) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return ( |
| 34 | <div className="blocker-import"> |
| 35 | <h2>Answer developer questions</h2> |
| 36 | <p className="muted"> |
| 37 | If whoever is building this left open questions in a file called BLOCKED.md in the project |
| 38 | folder, check here to answer them. |
| 39 | </p> |
| 40 | <button type="button" onClick={() => void handleImport()} disabled={importing}> |
| 41 | {importing ? 'Checking…' : 'Check for questions'} |
| 42 | </button> |
| 43 | {message && <p>{message}</p>} |
| 44 | {error && <p className="error">{error}</p>} |
| 45 | </div> |
| 46 | ) |
| 47 | } |
| 48 | |