export function npsStandardSurvey(form: FormTs) {
// NPS Survey - Net Promoter Score with rich feedback collection
// Demonstrates: Rating Scale (NPS), Emoji Rating, Suggestion Chips, dynamic styling
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'We Value Your Opinion',
computedValue: () => 'Your feedback helps us improve and serve you better.',
customStyles: {
backgroundColor: '#6366f1',
color: 'white',
padding: '24px',
borderRadius: '12px',
textAlign: 'center'
}
});
});
// ============================================
// SECTION 1: NPS Score
// ============================================
const npsSection = form.addSubform('npsSection', {
title: 'Net Promoter Score',
customStyles: () => {
const category = npsSection.ratingScale('npsScore')?.npsCategory();
if (category === 'promoter') return { backgroundColor: '#d1fae5', padding: '16px', borderRadius: '8px' };
if (category === 'passive') return { backgroundColor: '#fef3c7', padding: '16px', borderRadius: '8px' };
if (category === 'detractor') return { backgroundColor: '#fee2e2', padding: '16px', borderRadius: '8px' };
return { padding: '16px', borderRadius: '8px', border: '1px dashed #cbd5e1' };
}
});
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
});
});
// Dynamic follow-up based on NPS category
npsSection.addRow(row => {
row.addTextarea('npsReason', {
label: () => {
const category = npsSection.ratingScale('npsScore')?.npsCategory();
switch (category) {
case 'promoter': return "That's great to hear! What do you love most about us?";
case 'passive': return 'Thanks for your feedback! What would make us a 9 or 10?';
case 'detractor': return "We're sorry to hear that. What went wrong?";
default: return 'Tell us more about your rating';
}
},
placeholder: () => {
const category = npsSection.ratingScale('npsScore')?.npsCategory();
if (category === 'promoter') return 'Share what makes us special...';
if (category === 'passive') return 'Your suggestions help us improve...';
if (category === 'detractor') return "We're listening and want to make it right...";
return 'Your feedback...';
},
rows: 3,
autoExpand: true,
isVisible: () => npsSection.ratingScale('npsScore')?.value() !== null
});
});
// ============================================
// SECTION 2: Quick Mood Check (Emoji Rating)
// ============================================
const moodSection = form.addSubform('moodSection', {
title: 'How Do You Feel?',
isVisible: () => npsSection.ratingScale('npsScore')?.value() !== null,
customStyles: { backgroundColor: '#f8fafc', padding: '16px', borderRadius: '8px' }
});
moodSection.addRow(row => {
row.addEmojiRating('mood', {
label: 'How would you describe your overall experience?',
preset: 'satisfaction',
size: 'lg',
showLabels: true,
alignment: 'center'
});
});
// ============================================
// SECTION 3: Positive Highlights (for Promoters/Passives)
// ============================================
const highlightsSection = form.addSubform('highlights', {
title: 'What Did You Like?',
isVisible: () => {
const score = npsSection.ratingScale('npsScore')?.value();
return score !== null && score !== undefined && score >= 5;
},
customStyles: { backgroundColor: '#ecfdf5', padding: '16px', borderRadius: '8px' }
});
highlightsSection.addRow(row => {
row.addSuggestionChips('bestParts', {
label: 'Select what you liked most (up to 3)',
suggestions: [
{ id: 'quality', name: 'Product quality' },
{ id: 'service', name: 'Customer service' },
{ id: 'price', name: 'Fair pricing' },
{ id: 'ease', name: 'Easy to use' },
{ id: 'speed', name: 'Fast delivery' },
{ id: 'reliable', name: 'Reliability' },
{ id: 'support', name: 'Great support' },
{ id: 'innovation', name: 'Innovation' }
],
max: 3,
alignment: 'center'
});
});
// ============================================
// SECTION 4: Areas for Improvement (for Passives/Detractors)
// ============================================
const improvementsSection = form.addSubform('improvements', {
title: 'What Could We Improve?',
isVisible: () => {
const score = npsSection.ratingScale('npsScore')?.value();
return score !== null && score !== undefined && score <= 7;
},
customStyles: { backgroundColor: '#fef3c7', padding: '16px', borderRadius: '8px' }
});
improvementsSection.addRow(row => {
row.addSuggestionChips('improvementAreas', {
label: 'Select areas that need improvement',
suggestions: [
{ id: 'quality', name: 'Product quality' },
{ id: 'service', name: 'Customer service' },
{ id: 'price', name: 'Pricing' },
{ id: 'usability', name: 'Ease of use' },
{ id: 'speed', name: 'Speed/Delivery' },
{ id: 'reliability', name: 'Reliability' },
{ id: 'support', name: 'Support response' },
{ id: 'communication', name: 'Communication' }
],
alignment: 'center'
});
});
// ============================================
// SECTION 5: Contact Information
// ============================================
const contactSection = form.addSubform('contactSection', {
title: 'Stay in Touch',
isVisible: () => npsSection.ratingScale('npsScore')?.value() !== null
});
contactSection.addRow(row => {
row.addCheckbox('allowContact', {
label: 'You may contact me about my feedback'
});
});
contactSection.addRow(row => {
row.addEmail('contactEmail', {
label: 'Email address',
placeholder: 'your@email.com',
isRequired: () => contactSection.checkbox('allowContact')?.value() === true,
isVisible: () => contactSection.checkbox('allowContact')?.value() === true
});
});
// ============================================
// SECTION 6: Summary
// ============================================
const summarySection = form.addSubform('summary', {
title: 'Your Feedback Summary',
isVisible: () => npsSection.ratingScale('npsScore')?.value() !== null
});
summarySection.addRow(row => {
row.addTextPanel('summaryContent', {
computedValue: () => {
const score = npsSection.ratingScale('npsScore')?.value();
const category = npsSection.ratingScale('npsScore')?.npsCategory();
const mood = moodSection.emojiRating('mood')?.value();
const bestParts = highlightsSection.suggestionChips('bestParts')?.value() || [];
const improvements = improvementsSection.suggestionChips('improvementAreas')?.value() || [];
if (score === null || score === undefined) return '';
let emoji = '';
if (category === 'promoter') emoji = '🎉';
else if (category === 'passive') emoji = '🤔';
else emoji = '😟';
let summary = `${emoji} Feedback Summary\n`;
summary += `${'═'.repeat(25)}\n\n`;
summary += `📊 NPS Score: ${score}/10\n`;
summary += `📈 Category: ${category?.charAt(0).toUpperCase()}${category?.slice(1)}\n`;
if (mood) {
const moodLabels: Record<string, string> = {
'very-bad': '😢 Very Unhappy',
'bad': '😕 Unhappy',
'neutral': '😐 Neutral',
'good': '😊 Happy',
'excellent': '😃 Very Happy'
};
summary += `\n${moodLabels[mood] || mood}\n`;
}
if (bestParts.length > 0) {
summary += `\n✨ Liked: ${bestParts.length} items selected`;
}
if (improvements.length > 0) {
summary += `\n⚠️ To improve: ${improvements.length} items selected`;
}
return summary;
},
customStyles: () => {
const category = npsSection.ratingScale('npsScore')?.npsCategory();
const baseStyles = {
padding: '16px',
borderRadius: '8px',
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '14px'
};
if (category === 'promoter') {
return { ...baseStyles, backgroundColor: '#d1fae5', borderLeft: '4px solid #10b981' };
} else if (category === 'passive') {
return { ...baseStyles, backgroundColor: '#fef3c7', borderLeft: '4px solid #f59e0b' };
} else if (category === 'detractor') {
return { ...baseStyles, backgroundColor: '#fee2e2', borderLeft: '4px solid #ef4444' };
}
return baseStyles;
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: 'Submit Feedback',
isVisible: () => npsSection.ratingScale('npsScore')?.value() !== null
});
form.configureCompletionScreen({
type: 'text',
title: 'Thank you for your feedback!',
message: 'Your response helps us improve our service. We truly appreciate you taking the time to share your thoughts with us.'
});
}