export function supportTicketCsatSurvey(form: FormTs) {
// Post-Ticket CSAT Survey - Support Quality Measurement
// Demonstrates: StarRating, RatingScale (CES), ThumbRating, MatrixQuestion, SuggestionChips, conditional visibility
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'How Did We Do?',
computedValue: () => 'Your feedback helps us improve our support. This survey takes less than 2 minutes.',
customStyles: {
backgroundColor: '#0ea5e9',
color: 'white',
padding: '24px',
borderRadius: '12px',
textAlign: 'center'
}
});
});
// ============================================
// SECTION 1: Resolution Status
// ============================================
const resolutionSection = form.addSubform('resolutionSection', {
title: 'Issue Resolution'
});
resolutionSection.addRow(row => {
row.addThumbRating('issueResolved', {
label: 'Was your issue resolved?',
size: 'lg',
showLabels: true,
upLabel: 'Yes, resolved',
downLabel: 'No, not resolved',
alignment: 'center'
});
});
// Follow-up if issue was NOT resolved
resolutionSection.addSpacer();
resolutionSection.addRow(row => {
row.addTextarea('unresolvedDetails', {
label: "We're sorry to hear that. Please tell us what's still unresolved:",
placeholder: 'Describe the issue that remains unresolved...',
rows: 3,
isVisible: () => resolutionSection.thumbRating('issueResolved')?.value() === 'down',
isRequired: () => resolutionSection.thumbRating('issueResolved')?.value() === 'down'
});
});
// ============================================
// SECTION 2: Overall Satisfaction (CSAT)
// ============================================
const csatSection = form.addSubform('csatSection', {
title: 'Overall Satisfaction',
customStyles: () => {
const rating = csatSection.starRating('overallSatisfaction')?.value();
if (rating && rating >= 4) return { backgroundColor: '#d1fae5', padding: '16px', borderRadius: '8px' };
if (rating && rating <= 2) return { backgroundColor: '#fee2e2', padding: '16px', borderRadius: '8px' };
return { padding: '16px', borderRadius: '8px', border: '1px dashed #cbd5e1' };
}
});
csatSection.addRow(row => {
row.addStarRating('overallSatisfaction', {
label: 'How satisfied are you with the support you received?',
maxStars: 5,
size: 'xl',
alignment: 'center',
showConfettiOnMax: true
});
});
// Dynamic response based on rating
csatSection.addRow(row => {
row.addTextPanel('csatResponse', {
isVisible: () => csatSection.starRating('overallSatisfaction')?.value() !== null,
computedValue: () => {
const rating = csatSection.starRating('overallSatisfaction')?.value();
if (rating === 5) return "Excellent! We're thrilled you had a great experience!";
if (rating === 4) return "Great! We're glad we could help.";
if (rating === 3) return "Thank you. We'd love to know how we can improve.";
if (rating && rating <= 2) return "We're sorry to hear that. Please help us understand what went wrong.";
return '';
},
customStyles: () => {
const rating = csatSection.starRating('overallSatisfaction')?.value();
const baseStyles = { padding: '12px', borderRadius: '6px', textAlign: 'center' as const, fontStyle: 'italic' as const };
if (rating && rating >= 4) return { ...baseStyles, color: '#047857' };
if (rating && rating <= 2) return { ...baseStyles, color: '#dc2626' };
return { ...baseStyles, color: '#6b7280' };
}
});
});
// ============================================
// SECTION 3: Customer Effort Score (CES)
// ============================================
const cesSection = form.addSubform('cesSection', {
title: 'Ease of Resolution',
isVisible: () => csatSection.starRating('overallSatisfaction')?.value() !== null
});
cesSection.addRow(row => {
row.addRatingScale('effortScore', {
preset: 'ces',
label: 'How easy was it to get your issue resolved?',
size: 'md',
alignment: 'center'
});
});
// ============================================
// SECTION 4: Agent Performance (Matrix)
// ============================================
const agentSection = form.addSubform('agentSection', {
title: 'Support Agent Performance',
isVisible: () => cesSection.ratingScale('effortScore')?.value() !== null
});
agentSection.addRow(row => {
row.addMatrixQuestion('agentRating', {
label: 'Please rate your support agent on the following:',
rows: [
{ id: 'knowledge', label: 'Product Knowledge', isRequired: true },
{ id: 'communication', label: 'Clear Communication', isRequired: true },
{ id: 'professionalism', label: 'Professionalism', isRequired: false },
{ id: 'responsiveness', label: 'Response Time', isRequired: false },
{ id: 'empathy', label: 'Understanding & Empathy', isRequired: false }
],
columns: [
{ id: 'poor', label: 'Poor' },
{ id: 'fair', label: 'Fair' },
{ id: 'good', label: 'Good' },
{ id: 'excellent', label: 'Excellent' }
],
striped: true,
fullWidth: true
});
});
// ============================================
// SECTION 5: Improvement Areas (for low ratings)
// ============================================
const improvementSection = form.addSubform('improvementSection', {
title: 'Help Us Improve',
isVisible: () => {
const rating = csatSection.starRating('overallSatisfaction')?.value();
return rating !== null && rating !== undefined && rating <= 3;
},
customStyles: { backgroundColor: '#fef3c7', padding: '16px', borderRadius: '8px' }
});
improvementSection.addRow(row => {
row.addSuggestionChips('improvementAreas', {
label: 'What areas need improvement? (select all that apply)',
suggestions: [
{ id: 'response-time', name: 'Response Time' },
{ id: 'solution-quality', name: 'Solution Quality' },
{ id: 'communication', name: 'Communication' },
{ id: 'knowledge', name: 'Technical Knowledge' },
{ id: 'follow-up', name: 'Follow-up' },
{ id: 'availability', name: 'Availability' },
{ id: 'process', name: 'Support Process' },
{ id: 'tools', name: 'Self-Service Tools' }
],
alignment: 'center'
});
});
improvementSection.addSpacer();
improvementSection.addRow(row => {
row.addTextarea('improvementSuggestions', {
label: 'What specific improvements would you suggest?',
placeholder: 'Your suggestions help us serve you better...',
rows: 3
});
});
// ============================================
// SECTION 6: Positive Feedback (for high ratings)
// ============================================
const praiseSection = form.addSubform('praiseSection', {
title: 'What Made It Great?',
isVisible: () => {
const rating = csatSection.starRating('overallSatisfaction')?.value();
return rating !== null && rating !== undefined && rating >= 4;
},
customStyles: { backgroundColor: '#ecfdf5', padding: '16px', borderRadius: '8px' }
});
praiseSection.addRow(row => {
row.addSuggestionChips('positiveAspects', {
label: 'What did you appreciate most? (select all that apply)',
suggestions: [
{ id: 'quick-response', name: 'Quick Response' },
{ id: 'solved-first-contact', name: 'First Contact Resolution' },
{ id: 'friendly-agent', name: 'Friendly Agent' },
{ id: 'expert-help', name: 'Expert Help' },
{ id: 'clear-explanation', name: 'Clear Explanation' },
{ id: 'went-extra-mile', name: 'Went Extra Mile' },
{ id: 'easy-process', name: 'Easy Process' },
{ id: 'follow-up', name: 'Great Follow-up' }
],
alignment: 'center'
});
});
praiseSection.addSpacer();
praiseSection.addRow(row => {
row.addTextarea('positiveComments', {
label: 'Any additional comments or praise for our team?',
placeholder: 'We love hearing what we did well!',
rows: 2
});
});
// ============================================
// SECTION 7: Future Contact
// ============================================
const contactSection = form.addSubform('contactSection', {
title: 'Follow-Up',
isVisible: () => csatSection.starRating('overallSatisfaction')?.value() !== null
});
contactSection.addRow(row => {
row.addRadioButton('followUpPreference', {
label: 'Would you like us to follow up about your feedback?',
options: [
{ id: 'no', name: 'No follow-up needed' },
{ id: 'email', name: 'Yes, contact me by email' },
{ id: 'phone', name: 'Yes, call me' }
],
orientation: 'vertical'
});
});
contactSection.addRow(row => {
row.addEmail('contactEmail', {
label: 'Your email address',
placeholder: 'email@example.com',
isVisible: () => contactSection.radioButton('followUpPreference')?.value() === 'email',
isRequired: () => contactSection.radioButton('followUpPreference')?.value() === 'email'
});
});
contactSection.addRow(row => {
row.addTextbox('contactPhone', {
label: 'Your phone number',
placeholder: '+1 (555) 123-4567',
isVisible: () => contactSection.radioButton('followUpPreference')?.value() === 'phone',
isRequired: () => contactSection.radioButton('followUpPreference')?.value() === 'phone'
});
});
// ============================================
// SECTION 8: Summary
// ============================================
const summarySection = form.addSubform('summary', {
title: 'Feedback Summary',
isVisible: () => csatSection.starRating('overallSatisfaction')?.value() !== null
});
summarySection.addRow(row => {
row.addTextPanel('summaryContent', {
computedValue: () => {
const resolved = resolutionSection.thumbRating('issueResolved')?.value();
const csat = csatSection.starRating('overallSatisfaction')?.value();
const ces = cesSection.ratingScale('effortScore')?.value();
if (!csat) return '';
let summary = '📋 Your Feedback Summary\n';
summary += '━'.repeat(25) + '\n\n';
// Resolution status
if (resolved === 'up') {
summary += '✅ Issue: Resolved\n';
} else if (resolved === 'down') {
summary += '❌ Issue: Not Resolved\n';
}
// CSAT
summary += `⭐ Satisfaction: ${csat}/5 stars\n`;
// CES
if (ces) {
let effort = 'Medium effort';
if (ces >= 6) effort = 'Very easy';
else if (ces >= 4) effort = 'Moderate effort';
else effort = 'High effort';
summary += `📊 Effort Level: ${effort} (${ces}/7)\n`;
}
// Sentiment
summary += '\n';
if (csat >= 4) {
summary += '💚 Thank you for your positive feedback!';
} else if (csat <= 2) {
summary += '🔧 We will work to improve your experience.';
} else {
summary += '💡 Your feedback helps us get better.';
}
return summary;
},
customStyles: () => {
const csat = csatSection.starRating('overallSatisfaction')?.value();
const baseStyles = {
padding: '16px',
borderRadius: '8px',
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '14px'
};
if (csat && csat >= 4) {
return { ...baseStyles, backgroundColor: '#d1fae5', borderLeft: '4px solid #10b981' };
} else if (csat && csat <= 2) {
return { ...baseStyles, backgroundColor: '#fee2e2', borderLeft: '4px solid #ef4444' };
}
return { ...baseStyles, backgroundColor: '#f8fafc', borderLeft: '4px solid #94a3b8' };
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: 'Submit Feedback',
isVisible: () => csatSection.starRating('overallSatisfaction')?.value() !== null
});
form.configureCompletionScreen({
type: 'text',
title: 'Thank You for Your Feedback!',
message: 'Your input is invaluable in helping us provide better support. If you requested a follow-up, our team will contact you shortly.'
});
}