import { useEffect, useState, type FormEvent } from "react"; import { ALL_SOURCES, type LiteratureSource, type ProtocolDraft, type ReviewOptions, type ReviewType, } from "../types"; import { getReviewOptions } from "../api/protocols"; import { DomainMultiSelect } from "./DomainMultiSelect"; import { CriteriaListEditor } from "./CriteriaListEditor"; import { SearchStrategyEditor } from "./SearchStrategyEditor"; import { ReviewModeSelector } from "./ReviewModeSelector"; import { RobSettings } from "./RobSettings"; interface ProtocolFormProps { onSubmit: (draft: ProtocolDraft) => Promise; onCancel: () => void; } const emptyDraft: ProtocolDraft = { title: "", population: "", review_type: null, review_domain: [], intervention: "", comparator: "", outcome: "", inclusion_criteria: [], exclusion_criteria: [], intervention_terms: [], outcome_terms: [], sources: [], reviewers_required: 1, rob_key_questions_observational: [4, 8, 9], rob_key_questions_experimental: [8, 9], rob_criteria: null, }; export function ProtocolForm({ onSubmit, onCancel }: ProtocolFormProps) { const [draft, setDraft] = useState(emptyDraft); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); const [options, setOptions] = useState(null); useEffect(() => { let cancelled = false; getReviewOptions() .then((o) => { if (!cancelled) setOptions(o); }) .catch(() => { if (!cancelled) setError("Could not load review type and domain options."); }); return () => { cancelled = true; }; }, []); function toggleSource(source: LiteratureSource) { setDraft((d) => ({ ...d, sources: d.sources.includes(source) ? d.sources.filter((s) => s !== source) : [...d.sources, source], })); } // --- "All" checkbox for Literature sources --- const allSourceValues = ALL_SOURCES.map((s) => s.value); const allSourcesSelected = allSourceValues.every((v) => draft.sources.includes(v)); const someSourcesSelected = draft.sources.length > 0 && !allSourcesSelected; function toggleAllSources(checked: boolean) { setDraft((d) => ({ ...d, sources: checked ? allSourceValues : [] })); } async function handleSubmit(e: FormEvent) { e.preventDefault(); setError(null); if (!draft.review_type || draft.review_domain.length === 0) { setError("Choose a review type and a review domain."); return; } if (draft.sources.length === 0) { setError("Select at least one literature source."); return; } if (!draft.rob_key_questions_observational.length || !draft.rob_key_questions_experimental.length) { setError("Choose at least one key risk-of-bias question for each study type."); return; } setSubmitting(true); try { await onSubmit({ ...draft, comparator: draft.comparator || null, rob_criteria: draft.rob_criteria?.trim() ? draft.rob_criteria : null, }); } catch (err) { setError(err instanceof Error ? err.message : "Failed to save protocol."); } finally { setSubmitting(false); } } return (

New review protocol

Declare your research question, criteria, and search strategy before searching — this is Phase 1 of the PRISMA workflow. Once locked, these fields can't be changed, so the search that follows can't be biased by early results.

setDraft({ ...draft, title: e.target.value })} placeholder="e.g. Hepatotoxicity of osimertinib in EGFR-mutant NSCLC" required />
setDraft({ ...draft, review_domain: v })} />