export function npsWithDriversSurvey(form: FormTs) {
// NPS with Driver Analysis - Understand what drives customer loyalty
// Demonstrates: RatingScale (NPS), MatrixQuestion, Slider, dynamic styling, conditional visibility
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'Customer Loyalty Survey',
computedValue: () => 'Help us understand what matters most to you',
customStyles: {
background: 'linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%)',
color: 'white',
padding: '28px',
borderRadius: '12px',
textAlign: 'center'
}
});
});
// ============================================
// SECTION 1: NPS Score
// ============================================
const npsSection = form.addSubform('npsSection', {
title: 'Recommendation Score',
customStyles: () => {
const category = npsSection.ratingScale('npsScore')?.npsCategory();
if (category === 'promoter') return { backgroundColor: '#dcfce7', padding: '20px', borderRadius: '8px', borderLeft: '4px solid #22c55e' };
if (category === 'passive') return { backgroundColor: '#fef9c3', padding: '20px', borderRadius: '8px', borderLeft: '4px solid #eab308' };
if (category === 'detractor') return { backgroundColor: '#fee2e2', padding: '20px', borderRadius: '8px', borderLeft: '4px solid #ef4444' };
return { padding: '20px', borderRadius: '8px', border: '2px dashed #e2e8f0' };
}
});
npsSection.addRow(row => {
row.addRatingScale('npsScore', {
preset: 'nps',
label: 'How likely are you to recommend us to a friend or colleague?',
showCategoryLabel: true,
showSegmentColors: true,
showConfettiOnPromoter: true,
isRequired: true
});
});
// ============================================
// SECTION 2: Driver Importance Matrix
// ============================================
const driversSection = form.addSubform('driversSection', {
title: () => {
const category = npsSection.ratingScale('npsScore')?.npsCategory();
if (category === 'promoter') return 'What Made Us Stand Out?';
if (category === 'detractor') return 'Where Did We Fall Short?';
return 'Rate the Importance of Each Factor';
},
isVisible: () => npsSection.ratingScale('npsScore')?.value() !== null,
customStyles: { backgroundColor: '#f8fafc', padding: '20px', borderRadius: '8px' }
});
driversSection.addRow(row => {
row.addTextPanel('driverInstructions', {
computedValue: () => {
const category = npsSection.ratingScale('npsScore')?.npsCategory();
if (category === 'promoter') return 'Rate how important each factor was in your positive experience:';
if (category === 'detractor') return 'Rate how important each factor was in your experience:';
return 'Rate how important each of these factors is to your overall satisfaction:';
},
customStyles: { color: '#64748b', marginBottom: '16px', fontSize: '14px' }
});
});
driversSection.addRow(row => {
row.addMatrixQuestion('driverImportance', {
label: '',
rows: [
{ id: 'quality', label: 'Product/Service Quality', description: 'The quality of what we deliver', isRequired: true },
{ id: 'support', label: 'Customer Support', description: 'Responsiveness and helpfulness of our team', isRequired: true },
{ id: 'value', label: 'Value for Money', description: 'Fair pricing relative to quality received', isRequired: true },
{ id: 'reliability', label: 'Reliability', description: 'Consistency and dependability', isRequired: true },
{ id: 'ease', label: 'Ease of Use', description: 'How simple and intuitive the experience is', isRequired: true },
{ id: 'communication', label: 'Communication', description: 'Clear and timely updates', isRequired: true },
{ id: 'innovation', label: 'Innovation', description: 'New features and improvements', isRequired: false }
],
columns: [
{ id: 'not-important', label: 'Not Important' },
{ id: 'somewhat', label: 'Somewhat' },
{ id: 'important', label: 'Important' },
{ id: 'very-important', label: 'Very Important' },
{ id: 'critical', label: 'Critical' }
],
striped: true,
fullWidth: true
});
});
// ============================================
// SECTION 3: Top Driver Deep Dive
// ============================================
const deepDiveSection = form.addSubform('deepDiveSection', {
title: 'Tell Us More',
isVisible: () => {
const matrix = driversSection.matrixQuestion('driverImportance')?.value();
return matrix !== null && matrix !== undefined && Object.keys(matrix).length >= 3;
},
customStyles: { backgroundColor: '#fff', padding: '20px', borderRadius: '8px', border: '1px solid #e2e8f0' }
});
deepDiveSection.addRow(row => {
row.addRadioButton('topDriver', {
label: 'Which factor had the BIGGEST impact on your score?',
options: [
{ id: 'quality', name: 'Product/Service Quality' },
{ id: 'support', name: 'Customer Support' },
{ id: 'value', name: 'Value for Money' },
{ id: 'reliability', name: 'Reliability' },
{ id: 'ease', name: 'Ease of Use' },
{ id: 'communication', name: 'Communication' },
{ id: 'innovation', name: 'Innovation' },
{ id: 'other', name: 'Other' }
],
orientation: 'vertical'
});
});
deepDiveSection.addSpacer();
deepDiveSection.addRow(row => {
row.addTextarea('driverFeedback', {
label: () => {
const topDriver = deepDiveSection.radioButton('topDriver')?.value();
const category = npsSection.ratingScale('npsScore')?.npsCategory();
const driverLabels: Record<string, string> = {
'quality': 'product/service quality',
'support': 'customer support',
'value': 'value for money',
'reliability': 'reliability',
'ease': 'ease of use',
'communication': 'communication',
'innovation': 'innovation',
'other': 'this factor'
};
const driverLabel = driverLabels[topDriver || ''] || 'this';
if (category === 'promoter') {
return `What specifically impressed you about our ${driverLabel}?`;
} else if (category === 'detractor') {
return `What specifically disappointed you about our ${driverLabel}?`;
}
return `Please share specific feedback about our ${driverLabel}:`;
},
placeholder: 'Share specific examples or suggestions...',
rows: 3,
autoExpand: true,
isVisible: () => deepDiveSection.radioButton('topDriver')?.value() !== null
});
});
// ============================================
// SECTION 4: Overall Satisfaction Slider
// ============================================
const satisfactionSection = form.addSubform('satisfactionSection', {
title: 'Overall Satisfaction',
isVisible: () => npsSection.ratingScale('npsScore')?.value() !== null,
customStyles: { padding: '20px', borderRadius: '8px', backgroundColor: '#faf5ff' }
});
satisfactionSection.addRow(row => {
row.addSlider('overallSatisfaction', {
label: 'How satisfied are you with your overall experience?',
min: 0,
max: 100,
step: 5,
defaultValue: 50,
unit: '%',
showValue: true
});
});
satisfactionSection.addRow(row => {
row.addTextPanel('satisfactionLabel', {
computedValue: () => {
const value = satisfactionSection.slider('overallSatisfaction')?.value() ?? 50;
if (value >= 90) return 'Excellent! You are highly satisfied.';
if (value >= 70) return 'Good! You are satisfied overall.';
if (value >= 50) return 'Neutral. There is room for improvement.';
if (value >= 30) return 'Below expectations. We need to do better.';
return 'Dissatisfied. We apologize and want to make it right.';
},
customStyles: () => {
const value = satisfactionSection.slider('overallSatisfaction')?.value() ?? 50;
const baseStyles = { textAlign: 'center', padding: '12px', borderRadius: '6px', fontWeight: '500' };
if (value >= 70) return { ...baseStyles, backgroundColor: '#dcfce7', color: '#166534' };
if (value >= 50) return { ...baseStyles, backgroundColor: '#fef9c3', color: '#854d0e' };
return { ...baseStyles, backgroundColor: '#fee2e2', color: '#991b1b' };
}
});
});
// ============================================
// SECTION 5: Improvement Priorities (for non-promoters)
// ============================================
const improvementSection = form.addSubform('improvementSection', {
title: 'Improvement Priorities',
isVisible: () => {
const score = npsSection.ratingScale('npsScore')?.value();
return score !== null && score !== undefined && score < 9;
},
customStyles: { backgroundColor: '#fef3c7', padding: '20px', borderRadius: '8px' }
});
improvementSection.addRow(row => {
row.addCheckboxList('improvementAreas', {
label: 'Which areas should we prioritize improving? (Select up to 3)',
options: [
{ id: 'faster-response', name: 'Faster response times' },
{ id: 'better-quality', name: 'Higher quality products/services' },
{ id: 'lower-prices', name: 'More competitive pricing' },
{ id: 'easier-use', name: 'Simpler, easier experience' },
{ id: 'more-features', name: 'More features/options' },
{ id: 'better-communication', name: 'Clearer communication' },
{ id: 'more-reliable', name: 'Improved reliability' },
{ id: 'better-support', name: 'Better customer support' }
],
orientation: 'vertical',
max: 3
});
});
// ============================================
// SECTION 6: Additional Comments
// ============================================
const commentsSection = form.addSubform('commentsSection', {
title: 'Additional Thoughts',
isVisible: () => npsSection.ratingScale('npsScore')?.value() !== null
});
commentsSection.addSpacer();
commentsSection.addRow(row => {
row.addTextarea('additionalComments', {
label: 'Is there anything else you would like to share with us?',
placeholder: 'Any additional feedback, suggestions, or concerns...',
rows: 3,
autoExpand: true
});
});
// ============================================
// SECTION 7: Summary
// ============================================
const summarySection = form.addSubform('summary', {
title: 'Your Feedback Summary',
isVisible: () => {
const matrix = driversSection.matrixQuestion('driverImportance')?.value();
return matrix !== null && matrix !== undefined && Object.keys(matrix).length >= 3;
}
});
summarySection.addRow(row => {
row.addTextPanel('summaryContent', {
computedValue: () => {
const score = npsSection.ratingScale('npsScore')?.value();
const category = npsSection.ratingScale('npsScore')?.npsCategory();
const satisfaction = satisfactionSection.slider('overallSatisfaction')?.value() ?? 50;
const topDriver = deepDiveSection.radioButton('topDriver')?.value();
const matrix = driversSection.matrixQuestion('driverImportance')?.value() || {};
const improvements = improvementSection.checkboxList('improvementAreas')?.value() || [];
if (score === null || score === undefined) return '';
const categoryEmoji: Record<string, string> = {
'promoter': '🎉',
'passive': '🤔',
'detractor': '😟'
};
const driverLabels: Record<string, string> = {
'quality': 'Product Quality',
'support': 'Customer Support',
'value': 'Value for Money',
'reliability': 'Reliability',
'ease': 'Ease of Use',
'communication': 'Communication',
'innovation': 'Innovation',
'other': 'Other Factor'
};
// Count critical drivers
let criticalCount = 0;
Object.values(matrix).forEach(val => {
if (val === 'critical' || val === 'very-important') criticalCount++;
});
let summary = `${categoryEmoji[category || '']} Feedback Summary\n`;
summary += `${'═'.repeat(30)}\n\n`;
summary += `📊 NPS Score: ${score}/10 (${category?.charAt(0).toUpperCase()}${category?.slice(1)})\n`;
summary += `📈 Overall Satisfaction: ${satisfaction}%\n`;
summary += `🎯 Drivers Rated: ${Object.keys(matrix).length}/7\n`;
summary += `⚡ High Priority Drivers: ${criticalCount}\n`;
if (topDriver && driverLabels[topDriver]) {
summary += `\n🔑 Key Driver: ${driverLabels[topDriver]}`;
}
if (improvements.length > 0) {
summary += `\n\n📋 Improvement Areas: ${improvements.length} selected`;
}
return summary;
},
customStyles: () => {
const category = npsSection.ratingScale('npsScore')?.npsCategory();
const baseStyles = {
padding: '20px',
borderRadius: '8px',
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '14px'
};
if (category === 'promoter') {
return { ...baseStyles, backgroundColor: '#dcfce7', borderLeft: '4px solid #22c55e' };
} else if (category === 'passive') {
return { ...baseStyles, backgroundColor: '#fef9c3', borderLeft: '4px solid #eab308' };
} else if (category === 'detractor') {
return { ...baseStyles, backgroundColor: '#fee2e2', borderLeft: '4px solid #ef4444' };
}
return { ...baseStyles, backgroundColor: '#f1f5f9' };
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: () => {
const category = npsSection.ratingScale('npsScore')?.npsCategory();
if (category === 'promoter') return 'Submit Positive Feedback';
if (category === 'detractor') return 'Submit & Help Us Improve';
return 'Submit Feedback';
},
isVisible: () => npsSection.ratingScale('npsScore')?.value() !== null
});
form.configureCompletionScreen({
type: 'text',
title: () => {
const category = npsSection.ratingScale('npsScore')?.npsCategory();
if (category === 'promoter') return 'Thank You for Being a Promoter!';
if (category === 'detractor') return 'Thank You for Your Honesty';
return 'Thank You for Your Feedback!';
},
message: () => {
const category = npsSection.ratingScale('npsScore')?.npsCategory();
if (category === 'promoter') {
return 'Your support means everything to us. Your driver analysis will help us maintain what makes us great!';
}
if (category === 'detractor') {
return 'We truly appreciate your honest feedback. Your driver analysis will directly inform our improvement roadmap.';
}
return 'Your detailed feedback helps us understand what matters most. We will use your driver analysis to guide our priorities.';
}
});
}