export function searchFeedbackForm(form: FormTs) {
// Search Results Quality Survey
// Demonstrates: ThumbRating, StarRating, EmojiRating, RatingScale,
// RadioButton, SuggestionChips, Textbox, dynamic visibility, computed values
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: 'Search Feedback',
computedValue: () => 'Help us improve your search experience.',
customStyles: {
backgroundColor: '#6366f1',
color: 'white',
padding: '24px',
borderRadius: '12px',
textAlign: 'center',
fontSize: '15px'
}
});
});
// ============================================
// SECTION 1: Search Query Context
// ============================================
const querySection = form.addSubform('query', {
title: 'What were you searching for?',
customStyles: { backgroundColor: '#eef2ff', padding: '20px', borderRadius: '10px' }
});
querySection.addRow(row => {
row.addTextbox('searchQuery', {
label: 'Your search term',
placeholder: 'Enter what you searched for...',
isRequired: true
});
});
// ============================================
// SECTION 2: Did You Find It?
// ============================================
const foundSection = form.addSubform('found', {
title: 'Search Results'
});
foundSection.addRow(row => {
row.addThumbRating('foundResult', {
label: 'Did you find what you were looking for?',
showLabels: true,
upLabel: 'Yes, found it!',
downLabel: 'No, didn\'t find it',
alignment: 'center',
size: 'lg'
});
});
// ============================================
// SECTION 3A: Successful Search Flow
// ============================================
const successSection = form.addSubform('success', {
title: 'Great! Tell us more',
isVisible: () => foundSection.thumbRating('foundResult')?.value() === 'up',
customStyles: { backgroundColor: '#ecfdf5', padding: '20px', borderRadius: '10px' }
});
successSection.addRow(row => {
row.addStarRating('relevanceRating', {
label: 'How relevant were the search results?',
maxStars: 5,
size: 'lg',
alignment: 'center',
filledColor: '#10b981',
showConfettiOnMax: true
});
});
successSection.addRow(row => {
row.addRadioButton('resultPosition', {
label: 'Where did you find your answer?',
options: [
{ id: 'first', name: 'First result' },
{ id: 'top3', name: 'In top 3 results' },
{ id: 'first-page', name: 'First page of results' },
{ id: 'second-page', name: 'Had to go to page 2 or later' },
{ id: 'refined', name: 'Had to refine my search' }
],
orientation: 'vertical',
isVisible: () => successSection.starRating('relevanceRating')?.value() !== null
});
});
successSection.addRow(row => {
row.addEmojiRating('searchExperience', {
label: 'How was your overall search experience?',
preset: 'satisfaction',
size: 'lg',
showLabels: true,
alignment: 'center',
isVisible: () => successSection.radioButton('resultPosition')?.value() !== null
});
});
// ============================================
// SECTION 3B: Unsuccessful Search Flow
// ============================================
const failSection = form.addSubform('fail', {
title: 'Help us improve',
isVisible: () => foundSection.thumbRating('foundResult')?.value() === 'down',
customStyles: { backgroundColor: '#fef2f2', padding: '20px', borderRadius: '10px' }
});
failSection.addRow(row => {
row.addRadioButton('whyNotFound', {
label: 'Why couldn\'t you find what you needed?',
options: [
{ id: 'no-results', name: 'No results were shown' },
{ id: 'irrelevant', name: 'Results weren\'t relevant' },
{ id: 'not-exist', name: 'Content doesn\'t exist on this site' },
{ id: 'wrong-order', name: 'Right result was buried too far down' },
{ id: 'confusing', name: 'Couldn\'t tell which result to click' },
{ id: 'broken', name: 'Search didn\'t work properly' }
],
orientation: 'vertical',
isRequired: true
});
});
// No results follow-up
failSection.addRow(row => {
row.addTextarea('expectedContent', {
label: 'What were you hoping to find?',
placeholder: 'Describe the information or page you were looking for...',
rows: 3,
isVisible: () => {
const reason = failSection.radioButton('whyNotFound')?.value();
return reason === 'no-results' || reason === 'not-exist';
}
});
});
// Irrelevant results follow-up
failSection.addRow(row => {
row.addRatingScale('resultQuality', {
label: 'How would you rate the quality of results you saw?',
preset: 'likert-5',
lowLabel: 'Completely wrong',
highLabel: 'Almost right',
alignment: 'center',
isVisible: () => {
const reason = failSection.radioButton('whyNotFound')?.value();
return reason === 'irrelevant' || reason === 'wrong-order';
}
});
});
failSection.addRow(row => {
row.addTextarea('whatWasWrong', {
label: 'What was wrong with the results?',
placeholder: 'Help us understand what you expected to see...',
rows: 3,
isVisible: () => {
const reason = failSection.radioButton('whyNotFound')?.value();
return reason === 'irrelevant' || reason === 'wrong-order' || reason === 'confusing';
}
});
});
// Technical issue follow-up
failSection.addRow(row => {
row.addTextarea('technicalIssue', {
label: 'Describe what happened',
placeholder: 'Error message, loading issue, etc...',
rows: 2,
isVisible: () => failSection.radioButton('whyNotFound')?.value() === 'broken'
});
});
// ============================================
// SECTION 4: Search Improvement Suggestions
// ============================================
const improvementSection = form.addSubform('improvement', {
title: 'Search Improvements',
isVisible: () => foundSection.thumbRating('foundResult')?.value() !== null
});
improvementSection.addRow(row => {
row.addSuggestionChips('searchFeatures', {
label: 'Which features would improve your search experience?',
suggestions: [
{ id: 'filters', name: 'Better filters' },
{ id: 'preview', name: 'Result previews' },
{ id: 'suggestions', name: 'Search suggestions' },
{ id: 'autocomplete', name: 'Autocomplete' },
{ id: 'recent', name: 'Recent searches' },
{ id: 'categories', name: 'Category filters' },
{ id: 'sorting', name: 'Better sorting options' }
],
alignment: 'center',
max: 3
});
});
// ============================================
// SECTION 5: Overall Assessment
// ============================================
const overallSection = form.addSubform('overall', {
title: 'Overall Search Rating',
isVisible: () => foundSection.thumbRating('foundResult')?.value() !== null,
customStyles: () => {
const found = foundSection.thumbRating('foundResult')?.value();
if (found === 'up') return { backgroundColor: '#f0fdf4', padding: '20px', borderRadius: '10px' };
return { backgroundColor: '#fefce8', padding: '20px', borderRadius: '10px' };
}
});
overallSection.addRow(row => {
row.addRatingScale('npsSearch', {
label: 'How likely are you to recommend our search to others?',
preset: 'nps',
showCategoryLabel: true,
showSegmentColors: true,
alignment: 'center'
});
});
// ============================================
// SECTION 6: Additional Comments
// ============================================
const commentsSection = form.addSubform('comments', {
title: 'Additional Feedback',
isVisible: () => foundSection.thumbRating('foundResult')?.value() !== null
});
commentsSection.addRow(row => {
row.addTextarea('additionalFeedback', {
label: () => {
const found = foundSection.thumbRating('foundResult')?.value();
if (found === 'up') return 'Anything else you\'d like us to know about your search experience?';
return 'Any other suggestions to improve our search?';
},
placeholder: 'Your thoughts help us improve...',
rows: 3,
autoExpand: true
});
});
// ============================================
// SECTION 7: Summary
// ============================================
const summarySection = form.addSubform('summary', {
title: 'Feedback Summary',
isVisible: () => foundSection.thumbRating('foundResult')?.value() !== null
});
summarySection.addRow(row => {
row.addTextPanel('summaryContent', {
computedValue: () => {
const query = querySection.textbox('searchQuery')?.value();
const found = foundSection.thumbRating('foundResult')?.value();
const relevance = successSection.starRating('relevanceRating')?.value();
const position = successSection.radioButton('resultPosition')?.value();
const experience = successSection.emojiRating('searchExperience')?.value();
const whyNot = failSection.radioButton('whyNotFound')?.value();
const nps = overallSection.ratingScale('npsSearch')?.value();
const features = improvementSection.suggestionChips('searchFeatures')?.value() || [];
if (!found) return '';
let summary = '🔍 Search Feedback Summary\n';
summary += `${'═'.repeat(30)}\n\n`;
if (query) {
summary += `📝 Search Query: "${query}"\n\n`;
}
if (found === 'up') {
summary += `✅ Result: Found what was needed\n`;
if (relevance !== null && relevance !== undefined) {
summary += `⭐ Relevance: ${'★'.repeat(relevance)}${'☆'.repeat(5 - relevance)}\n`;
}
if (position) {
const positionLabels: Record<string, string> = {
'first': 'First result',
'top3': 'Top 3 results',
'first-page': 'First page',
'second-page': 'Page 2+',
'refined': 'After refining search'
};
summary += `📍 Found In: ${positionLabels[position] || position}\n`;
}
if (experience) {
const expLabels: Record<string, string> = {
'very-bad': '😡 Very Bad',
'bad': '😕 Bad',
'neutral': '😐 Neutral',
'good': '🙂 Good',
'excellent': '😍 Excellent'
};
summary += `💫 Experience: ${expLabels[experience] || experience}\n`;
}
} else {
summary += `❌ Result: Didn't find it\n`;
if (whyNot) {
const reasonLabels: Record<string, string> = {
'no-results': 'No results shown',
'irrelevant': 'Results not relevant',
'not-exist': 'Content doesn\'t exist',
'wrong-order': 'Result buried too far',
'confusing': 'Unclear which to click',
'broken': 'Search didn\'t work'
};
summary += `❓ Reason: ${reasonLabels[whyNot] || whyNot}\n`;
}
}
if (features.length > 0) {
summary += `\n💡 Requested Features: ${features.length} selected\n`;
}
if (nps !== null && nps !== undefined) {
const category = overallSection.ratingScale('npsSearch')?.npsCategory();
const emoji = category === 'promoter' ? '🎉' : category === 'passive' ? '🤔' : '😟';
summary += `\n${emoji} NPS: ${nps}/10 (${category})`;
}
return summary;
},
customStyles: () => {
const found = foundSection.thumbRating('foundResult')?.value();
const base = {
padding: '20px',
borderRadius: '10px',
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '14px'
};
if (found === 'up') {
return { ...base, backgroundColor: '#ecfdf5', borderLeft: '4px solid #10b981' };
}
return { ...base, backgroundColor: '#fef2f2', borderLeft: '4px solid #ef4444' };
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: () => {
const found = foundSection.thumbRating('foundResult')?.value();
if (found === 'up') return 'Submit Positive Feedback';
if (found === 'down') return 'Submit & Help Us Improve';
return 'Submit Feedback';
},
isVisible: () => foundSection.thumbRating('foundResult')?.value() !== null
});
form.configureCompletionScreen({
type: 'text',
title: () => {
const found = foundSection.thumbRating('foundResult')?.value();
if (found === 'up') return 'Thanks for your feedback!';
return 'Thank you for helping us improve!';
},
message: () => {
const found = foundSection.thumbRating('foundResult')?.value();
if (found === 'up') {
return 'We\'re glad our search helped you find what you needed. Your feedback helps us make it even better.';
}
return 'We\'re sorry the search didn\'t work well for you. Our team reviews all feedback to improve the search experience.';
}
});
}