export function csatSimpleSurvey(form: FormTs) {
// CSAT Quick Poll - Ultra-fast customer satisfaction survey
// Demonstrates: StarRating, ThumbRating, EmojiRating, SuggestionChips, conditional visibility, dynamic styling
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'Quick Feedback',
computedValue: () => 'Your opinion matters! This takes less than 30 seconds.',
customStyles: {
backgroundColor: '#10b981',
color: 'white',
padding: '20px',
borderRadius: '12px',
textAlign: 'center',
fontSize: '14px'
}
});
});
// ============================================
// SECTION 1: Main CSAT Rating
// ============================================
const ratingSection = form.addSubform('ratingSection', {
title: 'How satisfied are you?',
customStyles: () => {
const rating = ratingSection.starRating('satisfaction')?.value();
if (rating === null || rating === undefined) {
return { padding: '16px', borderRadius: '8px', border: '2px dashed #e2e8f0' };
}
if (rating >= 4) return { backgroundColor: '#d1fae5', padding: '16px', borderRadius: '8px' };
if (rating >= 3) return { backgroundColor: '#fef3c7', padding: '16px', borderRadius: '8px' };
return { backgroundColor: '#fee2e2', padding: '16px', borderRadius: '8px' };
}
});
ratingSection.addRow(row => {
row.addStarRating('satisfaction', {
label: 'Rate your overall experience',
maxStars: 5,
size: 'xl',
alignment: 'center',
showCounter: true,
showConfettiOnMax: true
});
});
// Quick mood check with emoji
ratingSection.addRow(row => {
row.addEmojiRating('mood', {
label: () => {
const rating = ratingSection.starRating('satisfaction')?.value();
if (rating !== null && rating !== undefined && rating >= 4) return 'How are you feeling right now?';
if (rating !== null && rating !== undefined && rating <= 2) return "We're sorry to hear that. How do you feel?";
return 'How would you describe your mood?';
},
preset: 'mood',
size: 'md',
showLabels: true,
alignment: 'center',
isVisible: () => ratingSection.starRating('satisfaction')?.value() !== null
});
});
// ============================================
// SECTION 2: Quick Thumbs Feedback
// ============================================
const thumbsSection = form.addSubform('thumbsSection', {
title: 'Would you use our service again?',
isVisible: () => ratingSection.starRating('satisfaction')?.value() !== null
});
thumbsSection.addRow(row => {
row.addThumbRating('wouldReturn', {
label: 'Would you come back?',
size: 'lg',
showLabels: true,
upLabel: 'Definitely!',
downLabel: 'Probably not',
alignment: 'center'
});
});
// ============================================
// SECTION 3: What Did You Like? (for satisfied customers)
// ============================================
const positiveSection = form.addSubform('positiveSection', {
title: 'What did you like most?',
isVisible: () => {
const rating = ratingSection.starRating('satisfaction')?.value();
return rating !== null && rating !== undefined && rating >= 4;
},
customStyles: { backgroundColor: '#ecfdf5', padding: '16px', borderRadius: '8px' }
});
positiveSection.addRow(row => {
row.addSuggestionChips('highlights', {
label: 'Select all that apply',
suggestions: [
{ id: 'quality', name: 'Quality' },
{ id: 'speed', name: 'Speed' },
{ id: 'support', name: 'Support' },
{ id: 'value', name: 'Value' },
{ id: 'ease', name: 'Easy to use' },
{ id: 'friendly', name: 'Friendly staff' }
],
alignment: 'center'
});
});
// ============================================
// SECTION 4: What Went Wrong? (for unsatisfied customers)
// ============================================
const negativeSection = form.addSubform('negativeSection', {
title: 'What could we improve?',
isVisible: () => {
const rating = ratingSection.starRating('satisfaction')?.value();
return rating !== null && rating !== undefined && rating <= 2;
},
customStyles: { backgroundColor: '#fef2f2', padding: '16px', borderRadius: '8px' }
});
negativeSection.addRow(row => {
row.addSuggestionChips('issues', {
label: 'What disappointed you?',
suggestions: [
{ id: 'slow', name: 'Too slow' },
{ id: 'quality', name: 'Poor quality' },
{ id: 'expensive', name: 'Too expensive' },
{ id: 'confusing', name: 'Confusing' },
{ id: 'support', name: 'Bad support' },
{ id: 'bugs', name: 'Technical issues' }
],
alignment: 'center'
});
});
negativeSection.addSpacer();
negativeSection.addRow(row => {
row.addTextarea('improvementDetails', {
label: 'Tell us more (optional)',
placeholder: 'What could we have done better?',
rows: 2,
autoExpand: true
});
});
// ============================================
// SECTION 5: Follow-up Contact
// ============================================
const contactSection = form.addSubform('contactSection', {
title: 'Stay Connected',
isVisible: () => ratingSection.starRating('satisfaction')?.value() !== null
});
contactSection.addRow(row => {
row.addCheckbox('allowContact', {
label: 'You may contact me about my feedback'
});
});
contactSection.addRow(row => {
row.addEmail('email', {
label: 'Your email',
placeholder: 'email@example.com',
isVisible: () => contactSection.checkbox('allowContact')?.value() === true,
isRequired: () => contactSection.checkbox('allowContact')?.value() === true
});
});
// ============================================
// SECTION 6: Summary
// ============================================
const summarySection = form.addSubform('summarySection', {
title: 'Your Feedback',
isVisible: () => ratingSection.starRating('satisfaction')?.value() !== null
});
summarySection.addRow(row => {
row.addTextPanel('summary', {
computedValue: () => {
const rating = ratingSection.starRating('satisfaction')?.value();
const mood = ratingSection.emojiRating('mood')?.value();
const wouldReturn = thumbsSection.thumbRating('wouldReturn')?.value();
const highlights = positiveSection.suggestionChips('highlights')?.value() || [];
const issues = negativeSection.suggestionChips('issues')?.value() || [];
if (rating === null || rating === undefined) return '';
let emoji = rating >= 4 ? '🌟' : rating >= 3 ? '👍' : '😔';
let status = rating >= 4 ? 'Satisfied' : rating >= 3 ? 'Neutral' : 'Unsatisfied';
let summary = `${emoji} CSAT Summary\n`;
summary += `${'─'.repeat(20)}\n\n`;
summary += `⭐ Rating: ${rating}/5 stars\n`;
summary += `📊 Status: ${status}\n`;
if (mood) {
const moodLabels: Record<string, string> = {
'sad': '😢 Sad',
'down': '😔 Down',
'neutral': '😐 Neutral',
'happy': '😊 Happy',
'excited': '🤩 Excited'
};
summary += `🎭 Mood: ${moodLabels[mood] || mood}\n`;
}
if (wouldReturn) {
summary += `🔄 Would return: ${wouldReturn === 'up' ? 'Yes' : 'No'}\n`;
}
if (highlights.length > 0) {
summary += `\n✨ Liked: ${highlights.join(', ')}`;
}
if (issues.length > 0) {
summary += `\n⚠️ Issues: ${issues.join(', ')}`;
}
return summary;
},
customStyles: () => {
const rating = ratingSection.starRating('satisfaction')?.value();
const base = {
padding: '16px',
borderRadius: '8px',
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '13px'
};
if (rating !== null && rating !== undefined && rating >= 4) {
return { ...base, backgroundColor: '#d1fae5', borderLeft: '4px solid #10b981' };
} else if (rating !== null && rating !== undefined && rating <= 2) {
return { ...base, backgroundColor: '#fee2e2', borderLeft: '4px solid #ef4444' };
}
return { ...base, backgroundColor: '#fef3c7', borderLeft: '4px solid #f59e0b' };
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: 'Submit Feedback',
isVisible: () => ratingSection.starRating('satisfaction')?.value() !== null
});
form.configureCompletionScreen({
type: 'text',
title: 'Thank you!',
message: 'Your feedback helps us improve. We appreciate you taking the time to share your thoughts!'
});
}