import React, { useState, useEffect, useRef } from 'react';
function Section({ title, description, children }: { title: string; description?: string; children: React.ReactNode }) {
return (
{title}
{description && (
{description}
)}
{children}
);
}
function CheckCircle() {
return (
);
}
interface OutcomeCompleteProps {
achievement: string;
detail?: string;
returnLabel?: string;
nextSteps?: { label: string; accent?: string }[];
autoReturn?: boolean;
countdownMs?: number;
}
function OutcomeComplete({
achievement,
detail,
returnLabel,
nextSteps,
autoReturn = false,
countdownMs = 5000,
}: OutcomeCompleteProps) {
const [countdown, setCountdown] = useState(Math.ceil(countdownMs / 1000));
const [cancelled, setCancelled] = useState(false);
const intervalRef = useRef>();
useEffect(() => {
if (!autoReturn || cancelled) return;
intervalRef.current = setInterval(() => {
setCountdown((c) => {
if (c <= 1) {
clearInterval(intervalRef.current);
return 0;
}
return c - 1;
});
}, 1000);
return () => clearInterval(intervalRef.current);
}, [autoReturn, cancelled]);
const handleCancel = () => {
setCancelled(true);
clearInterval(intervalRef.current);
};
const returnText = returnLabel ? `Back to ${returnLabel}` : 'Done';
return (
{achievement}
{detail && (
{detail}
)}
{autoReturn && !cancelled && countdown > 0 && (
)}
{nextSteps && nextSteps.length > 0 && (
Or continue with
{nextSteps.map((step) => (
))}
)}
);
}
export default function OutcomeCompleteDemo() {
return (
);
}