export function liveChatFeedback(form: FormTs) {
// Live Chat Feedback Form - Quick post-chat support survey
// Demonstrates: ThumbRating, CES (Customer Effort Score), EmojiRating, compact design
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'Chat Feedback',
computedValue: () => 'How was your support experience?',
customStyles: {
backgroundColor: '#10b981',
color: 'white',
padding: '20px',
borderRadius: '12px',
textAlign: 'center'
}
});
});
// ============================================
// SECTION 1: Quick Resolution Check
// ============================================
const resolutionSection = form.addSubform('resolutionSection', {
customStyles: { padding: '16px', borderRadius: '8px', border: '1px solid #e2e8f0' }
});
resolutionSection.addRow(row => {
row.addThumbRating('resolved', {
label: 'Was your issue resolved?',
showLabels: true,
upLabel: 'Yes',
downLabel: 'No',
size: 'lg',
alignment: 'center'
});
});
// ============================================
// SECTION 2: Effort Score (CES)
// ============================================
const effortSection = form.addSubform('effortSection', {
title: 'Effort Required',
isVisible: () => resolutionSection.thumbRating('resolved')?.value() !== null,
customStyles: { padding: '16px', borderRadius: '8px', backgroundColor: '#f8fafc' }
});
effortSection.addRow(row => {
row.addRatingScale('effortScore', {
preset: 'ces',
label: 'How easy was it to get help today?',
lowLabel: 'Very Difficult',
highLabel: 'Very Easy',
alignment: 'center',
size: 'md'
});
});
// ============================================
// SECTION 3: Agent Rating
// ============================================
const agentSection = form.addSubform('agentSection', {
title: 'Your Support Agent',
isVisible: () => resolutionSection.thumbRating('resolved')?.value() !== null,
customStyles: { padding: '16px', borderRadius: '8px', border: '1px solid #e2e8f0' }
});
agentSection.addRow(row => {
row.addEmojiRating('agentSatisfaction', {
label: 'How would you rate the agent?',
preset: 'satisfaction',
size: 'lg',
showLabels: true,
alignment: 'center'
});
});
agentSection.addRow(row => {
row.addSuggestionChips('agentPositives', {
label: 'What did the agent do well?',
suggestions: [
{ id: 'friendly', name: 'Friendly' },
{ id: 'knowledgeable', name: 'Knowledgeable' },
{ id: 'fast', name: 'Quick Response' },
{ id: 'helpful', name: 'Helpful' },
{ id: 'patient', name: 'Patient' },
{ id: 'professional', name: 'Professional' }
],
max: 3,
alignment: 'center',
isVisible: () => {
const rating = agentSection.emojiRating('agentSatisfaction')?.value();
return rating === 'good' || rating === 'excellent';
}
});
});
// ============================================
// SECTION 4: Issue Not Resolved (Conditional)
// ============================================
const unresolvedSection = form.addSubform('unresolvedSection', {
title: 'We\'re Sorry',
isVisible: () => resolutionSection.thumbRating('resolved')?.value() === 'down',
customStyles: {
padding: '16px',
borderRadius: '8px',
backgroundColor: '#fef2f2',
borderLeft: '4px solid #ef4444'
}
});
unresolvedSection.addRow(row => {
row.addTextPanel('unresolvedMessage', {
computedValue: () => 'We apologize that your issue wasn\'t resolved. Please let us know what happened so we can help.',
customStyles: {
fontSize: '14px',
color: '#dc2626',
marginBottom: '12px'
}
});
});
unresolvedSection.addRow(row => {
row.addDropdown('unresolvedReason', {
label: 'What went wrong?',
options: [
{ id: 'complex', name: 'Issue too complex for chat' },
{ id: 'info', name: 'Agent didn\'t have the information' },
{ id: 'disconnect', name: 'Chat disconnected' },
{ id: 'wait', name: 'Wait time too long' },
{ id: 'communication', name: 'Communication issues' },
{ id: 'other', name: 'Other reason' }
],
placeholder: 'Select a reason'
});
});
unresolvedSection.addRow(row => {
row.addTextarea('unresolvedDetails', {
label: 'Please describe the issue',
placeholder: 'Tell us more so we can follow up...',
rows: 2,
autoExpand: true
});
});
unresolvedSection.addRow(row => {
row.addCheckbox('callbackRequested', {
label: 'I would like a callback to resolve my issue'
});
});
unresolvedSection.addRow(row => {
row.addTextbox('phoneNumber', {
label: 'Phone Number',
placeholder: 'Your phone number',
isVisible: () => unresolvedSection.checkbox('callbackRequested')?.value() === true,
isRequired: () => unresolvedSection.checkbox('callbackRequested')?.value() === true
});
});
// ============================================
// SECTION 5: Overall Satisfaction
// ============================================
const satisfactionSection = form.addSubform('satisfactionSection', {
title: 'Overall Experience',
isVisible: () => resolutionSection.thumbRating('resolved')?.value() !== null,
customStyles: { padding: '16px', borderRadius: '8px', backgroundColor: '#ecfdf5' }
});
satisfactionSection.addRow(row => {
row.addStarRating('overallRating', {
label: 'Rate your overall chat experience',
maxStars: 5,
size: 'xl',
alignment: 'center',
showConfettiOnMax: true
});
});
// ============================================
// SECTION 6: Quick Improvements (Conditional)
// ============================================
const improvementsSection = form.addSubform('improvementsSection', {
isVisible: () => {
const rating = satisfactionSection.starRating('overallRating')?.value();
return rating !== null && rating !== undefined && rating <= 3;
},
customStyles: { padding: '16px', borderRadius: '8px', backgroundColor: '#fef3c7' }
});
improvementsSection.addRow(row => {
row.addSuggestionChips('improvements', {
label: 'What could we improve?',
suggestions: [
{ id: 'wait', name: 'Shorter Wait' },
{ id: 'knowledge', name: 'Agent Knowledge' },
{ id: 'speed', name: 'Faster Resolution' },
{ id: 'communication', name: 'Clearer Answers' },
{ id: 'followup', name: 'Better Follow-up' },
{ id: 'availability', name: '24/7 Support' }
],
max: 3,
alignment: 'center'
});
});
// ============================================
// SECTION 7: Additional Comment
// ============================================
const commentSection = form.addSubform('commentSection', {
isVisible: () => resolutionSection.thumbRating('resolved')?.value() !== null
});
commentSection.addRow(row => {
row.addTextarea('additionalComment', {
label: 'Anything else you\'d like to share? (Optional)',
placeholder: 'Your feedback helps us improve...',
rows: 2,
autoExpand: true
});
});
// ============================================
// SECTION 8: Recommendation (NPS-style)
// ============================================
const npsSection = form.addSubform('npsSection', {
isVisible: () => {
const resolved = resolutionSection.thumbRating('resolved')?.value();
return resolved === 'up';
},
customStyles: () => {
const nps = npsSection.ratingScale('npsScore')?.npsCategory();
if (nps === 'promoter') return { backgroundColor: '#d1fae5', padding: '16px', borderRadius: '8px' };
if (nps === 'passive') return { backgroundColor: '#fef3c7', padding: '16px', borderRadius: '8px' };
if (nps === '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 our support to others?',
showCategoryLabel: true,
showSegmentColors: true,
size: 'sm'
});
});
// ============================================
// SUMMARY PANEL
// ============================================
const summarySection = form.addSubform('summarySection', {
isVisible: () => satisfactionSection.starRating('overallRating')?.value() !== null,
customStyles: { padding: '16px', borderRadius: '8px', backgroundColor: '#f1f5f9' }
});
summarySection.addRow(row => {
row.addTextPanel('summary', {
computedValue: () => {
const resolved = resolutionSection.thumbRating('resolved')?.value();
const effort = effortSection.ratingScale('effortScore')?.value();
const agent = agentSection.emojiRating('agentSatisfaction')?.value();
const overall = satisfactionSection.starRating('overallRating')?.value();
let summary = 'Your Feedback Summary\n';
summary += '━━━━━━━━━━━━━━━━━━━━━\n\n';
summary += resolved === 'up' ? '✅ Issue Resolved\n' : '❌ Issue Not Resolved\n';
if (effort) {
const effortLabels: Record<number, string> = {
1: 'Very Difficult', 2: 'Difficult', 3: 'Neutral',
4: 'Somewhat Easy', 5: 'Easy', 6: 'Very Easy', 7: 'Extremely Easy'
};
summary += `📊 Effort: ${effortLabels[effort] || effort}\n`;
}
if (agent) {
const agentLabels: Record<string, string> = {
'very-bad': '😢', 'bad': '😕', 'neutral': '😐',
'good': '😊', 'excellent': '😃'
};
summary += `👤 Agent: ${agentLabels[agent] || agent}\n`;
}
if (overall) {
summary += `⭐ Overall: ${overall}/5 stars\n`;
}
return summary;
},
customStyles: {
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '13px'
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: 'Send Feedback',
isVisible: () => resolutionSection.thumbRating('resolved')?.value() !== null
});
form.configureCompletionScreen({
type: 'text',
title: 'Thank You!',
message: 'Your feedback helps us provide better support. Have a great day!'
});
}