export function financialHealthCheckQuiz(form: FormTs) {
form.setTitle(() => '💰 Financial Health Check: Score Your Money Habits');
// ============ SCORING SYSTEM ============
const scores = form.state<Record<string, number>>({});
const updateScore = (category: string, points: number) => {
scores.update(current => ({ ...current, [category]: points }));
};
const getTotalScore = () => {
const s = scores();
return Object.values(s).reduce((sum, val) => sum + (val || 0), 0);
};
const getMaxScore = () => 100;
const getScorePercentage = () => Math.round((getTotalScore() / getMaxScore()) * 100);
const getHealthLevel = (): 'critical' | 'needs-work' | 'good' | 'excellent' => {
const pct = getScorePercentage();
if (pct >= 80) return 'excellent';
if (pct >= 60) return 'good';
if (pct >= 40) return 'needs-work';
return 'critical';
};
const getHealthLabel = () => {
const level = getHealthLevel();
const labels = {
critical: '🔴 Critical - Immediate Action Needed',
'needs-work': '🟡 Needs Work - Room for Improvement',
good: '🟢 Good - On the Right Track',
excellent: '⭐ Excellent - Financial Champion!'
};
return labels[level];
};
const getHealthColor = () => {
const level = getHealthLevel();
const colors = {
critical: '#dc2626',
'needs-work': '#ca8a04',
good: '#059669',
excellent: '#7c3aed'
};
return colors[level];
};
const getGrade = () => {
const pct = getScorePercentage();
if (pct >= 90) return 'A+';
if (pct >= 80) return 'A';
if (pct >= 70) return 'B';
if (pct >= 60) return 'C';
if (pct >= 50) return 'D';
return 'F';
};
// ============ COMPLETION SCREEN ============
form.configureCompletionScreen({
type: 'text',
title: () => `${getHealthLabel()} (Grade: ${getGrade()})`,
message: () => {
const pct = getScorePercentage();
const level = getHealthLevel();
const messages = {
critical: `Your financial health score is ${pct}%. Don't worry - every financial journey starts somewhere. Your personalized report includes specific steps to improve your situation.`,
'needs-work': `Your financial health score is ${pct}%. You've got a foundation, but there are important areas to address. Check your report for priority actions.`,
good: `Your financial health score is ${pct}%. You're making good financial decisions! Your report highlights areas to optimize further.`,
excellent: `Congratulations! Your financial health score is ${pct}%. You're a financial rockstar! Your report includes advanced strategies to maximize your wealth.`
};
return messages[level];
}
});
// ============ PAGES SETUP ============
const pages = form.addPages('quiz-pages', {
heightMode: 'current-page'
});
// ============ PAGE 1: Emergency Fund ============
const page1 = pages.addPage('emergency-fund', { mobileBreakpoint: 500 });
page1.addRow(row => {
row.addTextPanel('header1', {
label: 'Step 1 of 7: Emergency Fund',
computedValue: () => 'Your financial safety net',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page1.addSpacer({ height: '24px' });
page1.addRow(row => {
row.addRadioButton('emergencyFund', {
label: 'How many months of expenses could you cover if you lost your income?',
tooltip: 'Financial experts recommend 3-6 months of expenses as an emergency fund',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'six-plus', name: '💪 6+ months - fully covered' },
{ id: 'three-six', name: '✅ 3-6 months - solid foundation' },
{ id: 'one-three', name: '⚠️ 1-3 months - getting there' },
{ id: 'under-one', name: '😰 Less than 1 month' },
{ id: 'none', name: '❌ No emergency savings' }
],
onValueChange: (val) => {
const points = { 'six-plus': 20, 'three-six': 15, 'one-three': 8, 'under-one': 3, none: 0 };
updateScore('emergency', points[val as keyof typeof points] || 0);
}
});
});
page1.addRow(row => {
row.addTextPanel('emergencyScore', {
computedValue: () => {
const s = scores();
return `🛡️ Emergency Fund Score: ${s['emergency'] || 0}/20`;
},
customStyles: () => {
const s = scores();
const score = s['emergency'] || 0;
const color = score >= 15 ? '#059669' : score >= 8 ? '#ca8a04' : '#dc2626';
return {
fontSize: '1rem',
fontWeight: '600',
color: color,
textAlign: 'center',
padding: '12px',
background: score >= 15 ? '#ecfdf5' : score >= 8 ? '#fefce8' : '#fef2f2',
borderRadius: '8px',
marginTop: '1rem',
border: `2px solid ${color}`
};
}
});
});
// ============ PAGE 2: Debt Management ============
const page2 = pages.addPage('debt', { mobileBreakpoint: 500 });
page2.addRow(row => {
row.addTextPanel('header2', {
label: 'Step 2 of 7: Debt Management',
computedValue: () => 'Understanding your debt situation',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page2.addSpacer({ height: '24px' });
page2.addRow(row => {
row.addRadioButton('creditCardDebt', {
label: 'Do you carry credit card balances month to month?',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'none', name: '✅ No - I pay in full every month' },
{ id: 'sometimes', name: '⚠️ Sometimes, but usually pay off quickly' },
{ id: 'regularly', name: '😰 Yes, I carry balances regularly' },
{ id: 'growing', name: '🚨 Yes, and the balance is growing' }
],
onValueChange: (val) => {
const points = { none: 10, sometimes: 6, regularly: 2, growing: 0 };
updateScore('creditCard', points[val as keyof typeof points] || 0);
}
});
});
page2.addRow(row => {
row.addRatingScale('debtIncome', {
label: 'What percentage of your income goes to debt payments (excluding mortgage)?',
tooltip: 'Debt-to-income ratio should ideally be under 20%',
isRequired: true,
preset: 'custom',
min: 0,
max: 4,
lowLabel: '0%',
highLabel: '50%+',
size: 'md',
alignment: 'center',
variant: 'segmented',
onValueChange: (val) => {
if (val == null) return;
// 0: 0%, 1: 1-10%, 2: 10-20%, 3: 20-35%, 4: 35%+
const points = [10, 8, 6, 3, 0];
updateScore('debtRatio', points[val] || 0);
}
});
});
page2.addRow(row => {
row.addTextPanel('debtHint', {
computedValue: () => {
const val = page2.ratingScale('debtIncome')?.value();
if (val === 0) return '0 = 0% - No debt payments (excellent!)';
if (val === 1) return '1 = 1-10% of income (healthy)';
if (val === 2) return '2 = 10-20% of income (manageable)';
if (val === 3) return '3 = 20-35% of income (concerning)';
if (val === 4) return '4 = 35%+ of income (critical)';
return 'Select your debt-to-income ratio';
},
customStyles: {
fontSize: '0.8rem',
color: '#6b7280',
textAlign: 'center',
marginTop: '0.25rem'
}
});
});
page2.addRow(row => {
row.addTextPanel('debtScore', {
computedValue: () => {
const s = scores();
const score = (s['creditCard'] || 0) + (s['debtRatio'] || 0);
return `💳 Debt Score: ${score}/20`;
},
customStyles: {
fontSize: '1rem',
fontWeight: '600',
color: '#1e40af',
textAlign: 'center',
padding: '12px',
background: '#dbeafe',
borderRadius: '8px',
marginTop: '1rem'
}
});
});
// ============ PAGE 3: Saving & Investing ============
const page3 = pages.addPage('saving', { mobileBreakpoint: 500 });
page3.addRow(row => {
row.addTextPanel('header3', {
label: 'Step 3 of 7: Saving & Investing',
computedValue: () => 'Building your wealth',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page3.addSpacer({ height: '24px' });
page3.addRow(row => {
row.addRadioButton('savingsRate', {
label: 'What percentage of your income do you save/invest each month?',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'twenty-plus', name: '🚀 20%+ - aggressive saver' },
{ id: 'fifteen-twenty', name: '💪 15-20% - on track for FIRE' },
{ id: 'ten-fifteen', name: '✅ 10-15% - solid foundation' },
{ id: 'five-ten', name: '⚠️ 5-10% - room to improve' },
{ id: 'under-five', name: '😰 Under 5%' },
{ id: 'none', name: '❌ I\'m not saving currently' }
],
onValueChange: (val) => {
const points = { 'twenty-plus': 15, 'fifteen-twenty': 12, 'ten-fifteen': 9, 'five-ten': 5, 'under-five': 2, none: 0 };
updateScore('savingsRate', points[val as keyof typeof points] || 0);
}
});
});
page3.addRow(row => {
row.addRadioButton('retirement', {
label: 'Are you contributing to retirement accounts (401k, IRA, etc.)?',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'max', name: '🏆 Maxing out contributions' },
{ id: 'match', name: '✅ At least getting employer match' },
{ id: 'some', name: '⚠️ Contributing, but not to match' },
{ id: 'none', name: '❌ Not contributing to retirement' }
],
onValueChange: (val) => {
const points = { max: 10, match: 7, some: 4, none: 0 };
updateScore('retirement', points[val as keyof typeof points] || 0);
}
});
});
page3.addRow(row => {
row.addTextPanel('savingScore', {
computedValue: () => {
const s = scores();
const score = (s['savingsRate'] || 0) + (s['retirement'] || 0);
return `📈 Saving & Investing Score: ${score}/25`;
},
customStyles: {
fontSize: '1rem',
fontWeight: '600',
color: '#1e40af',
textAlign: 'center',
padding: '12px',
background: '#dbeafe',
borderRadius: '8px',
marginTop: '1rem'
}
});
});
// ============ PAGE 4: Budgeting & Planning ============
const page4 = pages.addPage('budgeting', { mobileBreakpoint: 500 });
page4.addRow(row => {
row.addTextPanel('header4', {
label: 'Step 4 of 7: Budgeting & Planning',
computedValue: () => 'Your financial awareness',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page4.addSpacer({ height: '24px' });
page4.addRow(row => {
row.addRadioButton('budget', {
label: 'Do you follow a budget or spending plan?',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'detailed', name: '📊 Yes, detailed budget tracked regularly' },
{ id: 'rough', name: '📝 Yes, rough tracking of major categories' },
{ id: 'mental', name: '🧠 Just mental awareness of spending' },
{ id: 'none', name: '❌ No budget or tracking' }
],
onValueChange: (val) => {
const points = { detailed: 10, rough: 7, mental: 3, none: 0 };
updateScore('budget', points[val as keyof typeof points] || 0);
}
});
});
page4.addRow(row => {
row.addRadioButton('goals', {
label: 'Do you have specific financial goals with target dates?',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'written', name: '🎯 Yes, written goals with dates and amounts' },
{ id: 'mental', name: '💭 Yes, but mostly in my head' },
{ id: 'vague', name: '🤷 Just vague ideas about the future' },
{ id: 'none', name: '❌ No specific goals' }
],
onValueChange: (val) => {
const points = { written: 5, mental: 3, vague: 1, none: 0 };
updateScore('goals', points[val as keyof typeof points] || 0);
}
});
});
page4.addRow(row => {
row.addTextPanel('budgetScore', {
computedValue: () => {
const s = scores();
const score = (s['budget'] || 0) + (s['goals'] || 0);
return `📋 Budgeting Score: ${score}/15`;
},
customStyles: {
fontSize: '1rem',
fontWeight: '600',
color: '#1e40af',
textAlign: 'center',
padding: '12px',
background: '#dbeafe',
borderRadius: '8px',
marginTop: '1rem'
}
});
});
// ============ PAGE 5: Protection ============
const page5 = pages.addPage('protection', { mobileBreakpoint: 500 });
page5.addRow(row => {
row.addTextPanel('header5', {
label: 'Step 5 of 7: Financial Protection',
computedValue: () => 'Protecting what you\'ve built',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page5.addSpacer({ height: '24px' });
page5.addRow(row => {
row.addSuggestionChips('insurance', {
label: 'Which types of insurance do you have?',
isRequired: true,
suggestions: [
{ id: 'health', name: '🏥 Health' },
{ id: 'life', name: '💀 Life' },
{ id: 'disability', name: '♿ Disability' },
{ id: 'auto', name: '🚗 Auto' },
{ id: 'home', name: '🏠 Home/Renters' }
],
min: 0,
alignment: 'center',
onValueChange: (val) => {
if (!val) return;
// Health and auto are essential (3 pts each), others 2 pts each
let points = 0;
if (val.includes('health')) points += 4;
if (val.includes('auto')) points += 2;
if (val.includes('life')) points += 2;
if (val.includes('disability')) points += 2;
if (val.includes('home')) points += 2;
updateScore('insurance', Math.min(points, 10));
}
});
});
page5.addRow(row => {
row.addRadioButton('will', {
label: 'Do you have a will and/or estate plan?',
isRequired: true,
orientation: 'vertical',
options: [
{ id: 'complete', name: '✅ Yes, complete with all beneficiaries updated' },
{ id: 'partial', name: '⚠️ Partially - some documents but not complete' },
{ id: 'none', name: '❌ No will or estate plan' }
],
onValueChange: (val) => {
const points = { complete: 10, partial: 5, none: 0 };
updateScore('estate', points[val as keyof typeof points] || 0);
}
});
});
page5.addRow(row => {
row.addTextPanel('protectionScore', {
computedValue: () => {
const s = scores();
const score = (s['insurance'] || 0) + (s['estate'] || 0);
return `🛡️ Protection Score: ${score}/20`;
},
customStyles: {
fontSize: '1rem',
fontWeight: '600',
color: '#1e40af',
textAlign: 'center',
padding: '12px',
background: '#dbeafe',
borderRadius: '8px',
marginTop: '1rem'
}
});
});
// ============ PAGE 6: Results ============
const page6 = pages.addPage('results', { mobileBreakpoint: 500 });
page6.addRow(row => {
row.addTextPanel('header6', {
label: 'Step 6 of 7: Your Results',
computedValue: () => 'Your financial health assessment',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page6.addSpacer({ height: '24px' });
page6.addRow(row => {
row.addTextPanel('gradeDisplay', {
computedValue: () => `Grade: ${getGrade()}`,
customStyles: {
fontSize: '2.5rem',
fontWeight: '800',
textAlign: 'center',
color: getHealthColor(),
padding: '20px',
background: '#f9fafb',
borderRadius: '12px',
border: `3px solid ${getHealthColor()}`
}
});
});
page6.addRow(row => {
row.addTextPanel('healthLevel', {
computedValue: () => getHealthLabel(),
customStyles: {
fontSize: '1.2rem',
fontWeight: '600',
color: getHealthColor(),
textAlign: 'center',
marginTop: '0.5rem'
}
});
});
page6.addRow(row => {
row.addTextPanel('scoreBreakdown', {
computedValue: () => {
const total = getTotalScore();
const pct = getScorePercentage();
return `Total Score: ${total}/${getMaxScore()} (${pct}%)`;
},
customStyles: {
fontSize: '1.1rem',
fontWeight: '600',
textAlign: 'center',
color: '#374151',
marginTop: '10px'
}
});
});
page6.addRow(row => {
row.addTextPanel('recommendation', {
computedValue: () => {
const level = getHealthLevel();
const recommendations = {
critical: '🔴 Focus first on building a small emergency fund ($1,000) and stopping credit card debt growth. Small steps lead to big changes!',
'needs-work': '🟡 You\'re building momentum! Prioritize paying off high-interest debt and growing your emergency fund to 3 months.',
good: '🟢 Great foundation! Focus on maximizing retirement contributions and diversifying investments.',
excellent: '⭐ You\'re crushing it! Consider tax optimization, backdoor Roth strategies, and estate planning.'
};
return recommendations[level];
},
customStyles: {
fontSize: '0.95rem',
color: '#4b5563',
textAlign: 'center',
padding: '15px',
background: '#f3f4f6',
borderRadius: '8px',
marginTop: '15px',
lineHeight: '1.5'
}
});
});
// Collapsible breakdown
const detailsSection = page6.addSubform('detailsBreakdown', {
title: '📊 Category Breakdown (click to expand)',
isCollapsible: true,
customStyles: {
marginTop: '1rem',
background: '#f9fafb',
borderRadius: '8px'
}
});
detailsSection.addRow(row => {
row.addTextPanel('emergencyDetail', {
label: '🛡️ Emergency Fund',
computedValue: () => `${scores()['emergency'] || 0}/20`,
customStyles: {
fontSize: '0.9rem',
padding: '8px 12px',
background: '#dbeafe',
borderRadius: '6px'
}
}, '1fr');
row.addTextPanel('debtDetail', {
label: '💳 Debt Management',
computedValue: () => {
const s = scores();
return `${(s['creditCard'] || 0) + (s['debtRatio'] || 0)}/20`;
},
customStyles: {
fontSize: '0.9rem',
padding: '8px 12px',
background: '#dbeafe',
borderRadius: '6px'
}
}, '1fr');
});
detailsSection.addRow(row => {
row.addTextPanel('savingDetail', {
label: '📈 Saving & Investing',
computedValue: () => {
const s = scores();
return `${(s['savingsRate'] || 0) + (s['retirement'] || 0)}/25`;
},
customStyles: {
fontSize: '0.9rem',
padding: '8px 12px',
background: '#dbeafe',
borderRadius: '6px'
}
}, '1fr');
row.addTextPanel('budgetDetail', {
label: '📋 Budgeting',
computedValue: () => {
const s = scores();
return `${(s['budget'] || 0) + (s['goals'] || 0)}/15`;
},
customStyles: {
fontSize: '0.9rem',
padding: '8px 12px',
background: '#dbeafe',
borderRadius: '6px'
}
}, '1fr');
});
detailsSection.addRow(row => {
row.addTextPanel('protectionDetail', {
label: '🛡️ Protection',
computedValue: () => {
const s = scores();
return `${(s['insurance'] || 0) + (s['estate'] || 0)}/20`;
},
customStyles: {
fontSize: '0.9rem',
padding: '8px 12px',
background: '#dbeafe',
borderRadius: '6px'
}
}, '1fr');
row.addEmpty('1fr');
});
// ============ PAGE 7: Lead Capture ============
const page7 = pages.addPage('lead-capture', { mobileBreakpoint: 500 });
page7.addRow(row => {
row.addTextPanel('header7', {
label: 'Step 7 of 7: Get Your Report',
computedValue: () => 'Receive your personalized financial action plan',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280',
marginBottom: '1rem'
}
});
});
page7.addSpacer({ height: '24px' });
page7.addRow(row => {
row.addTextPanel('leadCapture', {
label: '📧 Get Your Financial Health Report',
computedValue: () => 'Enter your details for a detailed PDF with personalized recommendations',
customStyles: {
fontSize: '0.9rem',
color: '#6b7280'
}
});
});
page7.addRow(row => {
row.addTextbox('name', {
label: 'Your Name',
isRequired: true,
placeholder: 'John Smith'
}, '1fr');
row.addEmail('email', {
label: 'Email',
isRequired: true,
placeholder: 'john@email.com'
}, '1fr');
});
page7.addRow(row => {
row.addDropdown('age', {
label: 'Age Range',
options: [
{ id: '18-25', name: '18-25 - Just starting out' },
{ id: '26-35', name: '26-35 - Building foundation' },
{ id: '36-45', name: '36-45 - Peak earning years' },
{ id: '46-55', name: '46-55 - Pre-retirement' },
{ id: '56+', name: '56+ - Approaching/in retirement' }
],
placeholder: 'Select age range'
}, '1fr');
row.addDropdown('income', {
label: 'Annual Income Range',
options: [
{ id: 'under50', name: 'Under $50K' },
{ id: '50-100', name: '$50K - $100K' },
{ id: '100-200', name: '$100K - $200K' },
{ id: '200+', name: '$200K+' }
],
placeholder: 'Select income range'
}, '1fr');
});
page7.addRow(row => {
row.addCheckboxList('consent', {
options: [
{ id: 'report', name: '📄 Send me my detailed financial health report', isRequired: true },
{ id: 'tips', name: '💡 Send me weekly money tips' },
{ id: 'advisor', name: '📞 Connect me with a financial advisor' }
],
defaultValue: ['report'],
orientation: 'vertical'
});
});
// ============ PDF REPORT ============
form.configurePdf('financial-report', pdf => {
pdf.configure({
filename: 'financial-health-report.pdf',
pageSize: 'A4',
allowUserDownload: true,
downloadButtonLabel: '📄 Download Your Report',
header: {
title: 'Financial Health Check Report',
subtitle: 'Your Personalized Money Assessment'
},
footer: {
text: 'Generated by FormTs Financial Health Quiz',
showPageNumbers: true
}
});
pdf.addSection('Executive Summary', section => {
section.addRow(row => {
row.addField('Overall Grade', getGrade());
row.addField('Health Score', `${getScorePercentage()}%`);
});
section.addRow(row => {
row.addField('Status', getHealthLabel());
row.addField('Total Points', `${getTotalScore()} / ${getMaxScore()}`);
});
});
pdf.addSection('Category Scores', section => {
const s = scores();
section.addTable(
['Category', 'Score', 'Max', 'Status'],
[
['Emergency Fund', `${s['emergency'] || 0}`, '20', (s['emergency'] || 0) >= 15 ? '✅ Strong' : '⚠️ Improve'],
['Debt Management', `${(s['creditCard'] || 0) + (s['debtRatio'] || 0)}`, '20', (s['creditCard'] || 0) + (s['debtRatio'] || 0) >= 15 ? '✅ Strong' : '⚠️ Improve'],
['Saving & Investing', `${(s['savingsRate'] || 0) + (s['retirement'] || 0)}`, '25', (s['savingsRate'] || 0) + (s['retirement'] || 0) >= 18 ? '✅ Strong' : '⚠️ Improve'],
['Budgeting', `${(s['budget'] || 0) + (s['goals'] || 0)}`, '15', (s['budget'] || 0) + (s['goals'] || 0) >= 10 ? '✅ Strong' : '⚠️ Improve'],
['Protection', `${(s['insurance'] || 0) + (s['estate'] || 0)}`, '20', (s['insurance'] || 0) + (s['estate'] || 0) >= 15 ? '✅ Strong' : '⚠️ Improve']
]
);
});
pdf.addPageBreak();
pdf.addSection('Personalized Action Plan', section => {
const level = getHealthLevel();
const s = scores();
if (level === 'critical' || level === 'needs-work') {
section.addText('Priority 1: Build Emergency Fund');
section.addText('• Start with a goal of $1,000, then build to 1 month of expenses');
section.addText('• Set up automatic transfers, even if just $25/week');
section.addSpacer(10);
if ((s['creditCard'] || 0) < 8) {
section.addText('Priority 2: Tackle Credit Card Debt');
section.addText('• Stop using credit cards for new purchases');
section.addText('• Use debt avalanche (highest interest first) or snowball (smallest balance first)');
}
} else {
section.addText('Optimize Your Finances:');
section.addText('• Max out retirement contributions if possible');
section.addText('• Consider a taxable investment account for additional savings');
section.addText('• Review and rebalance investments annually');
section.addText('• Consider working with a fee-only financial advisor');
}
});
pdf.addSection('Next Steps', section => {
section.addText('1. Review your weakest category and focus on one improvement');
section.addText('2. Set up automatic savings to pay yourself first');
section.addText('3. Review this assessment quarterly to track progress');
section.addText('4. Consider consulting a financial advisor for personalized guidance');
});
});
// ============ SUBMIT BUTTON ============
form.configureSubmitButton({
label: () => `💰 Get My Report (Grade: ${getGrade()})`
});
form.configureSubmitBehavior({
sendToServer: true
});
}