export function inventoryFeedbackForm(form: FormTs) {
// Stock Availability / Out of Stock Feedback Form
// Demonstrates: EmojiRating, Slider, RadioButton, ThumbRating, Email, conditional notifications
// ============================================
// HEADER
// ============================================
form.addRow(row => {
row.addTextPanel('header', {
label: "We're Sorry - This Item is Out of Stock",
computedValue: () => 'Help us understand your needs so we can serve you better.',
customStyles: {
backgroundColor: '#dc2626',
color: 'white',
padding: '24px',
borderRadius: '12px',
textAlign: 'center'
}
});
});
// ============================================
// SECTION 1: Frustration Level
// ============================================
const frustrationSection = form.addSubform('frustrationSection', {
title: 'How Do You Feel?'
});
frustrationSection.addRow(row => {
row.addEmojiRating('frustrationLevel', {
label: 'How frustrated are you that this item is unavailable?',
preset: 'custom',
emojis: [
{ id: 'not-at-all', emoji: '😊', label: 'Not at all' },
{ id: 'slightly', emoji: '🙂', label: 'Slightly' },
{ id: 'moderately', emoji: '😐', label: 'Moderately' },
{ id: 'quite', emoji: '😕', label: 'Quite' },
{ id: 'extremely', emoji: '😤', label: 'Extremely' }
],
size: 'lg',
alignment: 'center'
});
});
frustrationSection.addRow(row => {
row.addRatingScale('urgency', {
label: 'How urgently do you need this product?',
preset: 'custom',
min: 1,
max: 5,
lowLabel: 'Not urgent at all',
highLabel: 'Need it immediately',
alignment: 'center'
});
});
// ============================================
// SECTION 2: Purchase Intent
// ============================================
const intentSection = form.addSubform('intentSection', {
title: 'Your Purchase Plans',
isVisible: () => frustrationSection.emojiRating('frustrationLevel')?.value() !== null
});
intentSection.addRow(row => {
row.addRadioButton('purchaseIntent', {
label: 'What will you do since this item is out of stock?',
options: [
{ id: 'wait', name: 'Wait for it to come back in stock' },
{ id: 'buy-elsewhere', name: 'Buy from a competitor' },
{ id: 'alternative', name: 'Buy a similar product from you' },
{ id: 'cancel', name: 'Cancel my purchase entirely' },
{ id: 'unsure', name: 'Not sure yet' }
],
orientation: 'vertical',
isRequired: true
});
});
// Conditional: Willing to wait
intentSection.addRow(row => {
row.addSlider('waitTime', {
label: 'How long are you willing to wait for restock? (days)',
min: 1,
max: 30,
step: 1,
showValue: true,
unit: 'days',
defaultValue: 7,
isVisible: () => intentSection.radioButton('purchaseIntent')?.value() === 'wait'
});
});
// Conditional: Alternative products
const alternativeSection = form.addSubform('alternativeSection', {
title: 'Alternative Products',
isVisible: () => intentSection.radioButton('purchaseIntent')?.value() === 'alternative',
customStyles: {
backgroundColor: '#f0fdf4',
padding: '16px',
borderRadius: '8px'
}
});
alternativeSection.addRow(row => {
row.addCheckboxList('acceptableAlternatives', {
label: 'Which alternatives would you consider? (Select all that apply)',
options: [
{ id: 'same-brand', name: 'Same brand, different model' },
{ id: 'same-price', name: 'Similar price range' },
{ id: 'different-color', name: 'Same product, different color' },
{ id: 'higher-end', name: 'Higher-end alternative' },
{ id: 'budget', name: 'More budget-friendly option' },
{ id: 'used', name: 'Used or refurbished' }
],
orientation: 'vertical'
});
});
// Conditional: Buy elsewhere feedback
const competitorSection = form.addSubform('competitorSection', {
title: 'Competitor Purchase',
isVisible: () => intentSection.radioButton('purchaseIntent')?.value() === 'buy-elsewhere',
customStyles: {
backgroundColor: '#fef3c7',
padding: '16px',
borderRadius: '8px',
borderLeft: '4px solid #f59e0b'
}
});
competitorSection.addRow(row => {
row.addTextPanel('competitorNote', {
computedValue: () => "We're sorry to lose your business. Your feedback helps us improve.",
customStyles: {
fontStyle: 'italic',
color: '#92400e',
marginBottom: '12px'
}
});
});
competitorSection.addRow(row => {
row.addRadioButton('competitorChoice', {
label: 'Where are you likely to purchase instead?',
options: [
{ id: 'amazon', name: 'Amazon' },
{ id: 'direct', name: 'Direct from manufacturer' },
{ id: 'local', name: 'Local retail store' },
{ id: 'other-online', name: 'Other online retailer' },
{ id: 'not-sure', name: 'Not sure yet' }
],
orientation: 'vertical'
});
});
// ============================================
// SECTION 3: Product Importance
// ============================================
const importanceSection = form.addSubform('importanceSection', {
title: 'Why This Product?',
isVisible: () => intentSection.radioButton('purchaseIntent')?.value() !== null
});
importanceSection.addRow(row => {
row.addSuggestionChips('productReasons', {
label: 'Why were you looking for this specific product?',
suggestions: [
{ id: 'best-price', name: 'Best price' },
{ id: 'brand', name: 'Preferred brand' },
{ id: 'features', name: 'Specific features' },
{ id: 'reviews', name: 'Great reviews' },
{ id: 'recommended', name: 'Was recommended' },
{ id: 'replacement', name: 'Replacing old one' },
{ id: 'gift', name: 'It\'s a gift' },
{ id: 'urgency', name: 'Need it now' }
],
max: 3,
alignment: 'left'
});
});
// ============================================
// SECTION 4: Notifications
// ============================================
const notificationSection = form.addSubform('notificationSection', {
title: 'Stay Updated',
isVisible: () => {
const intent = intentSection.radioButton('purchaseIntent')?.value();
return intent === 'wait' || intent === 'unsure';
}
});
notificationSection.addRow(row => {
row.addThumbRating('wantNotification', {
label: 'Would you like to be notified when this item is back in stock?',
showLabels: true,
upLabel: 'Yes, notify me',
downLabel: 'No thanks',
size: 'lg',
alignment: 'center'
});
});
notificationSection.addRow(row => {
row.addEmail('notificationEmail', {
label: 'Enter your email for back-in-stock notification',
placeholder: 'your@email.com',
isRequired: () => notificationSection.thumbRating('wantNotification')?.value() === 'up',
isVisible: () => notificationSection.thumbRating('wantNotification')?.value() === 'up'
});
});
notificationSection.addRow(row => {
row.addCheckbox('marketingConsent', {
label: 'Also send me news about similar products and special offers',
defaultValue: false,
isVisible: () => notificationSection.thumbRating('wantNotification')?.value() === 'up'
});
});
// ============================================
// SECTION 5: Overall Experience
// ============================================
const experienceSection = form.addSubform('experienceSection', {
title: 'Your Shopping Experience',
isVisible: () => intentSection.radioButton('purchaseIntent')?.value() !== null
});
experienceSection.addRow(row => {
row.addStarRating('websiteExperience', {
label: 'Despite the stockout, how would you rate your overall experience on our website?',
maxStars: 5,
size: 'lg',
alignment: 'center'
});
});
experienceSection.addRow(row => {
row.addMatrixQuestion('stockoutImpact', {
label: 'How does this stockout affect your view of us?',
rows: [
{ id: 'trust', label: 'Trust in our brand' },
{ id: 'return', label: 'Likelihood to shop here again' },
{ id: 'recommend', label: 'Likelihood to recommend us' }
],
columns: [
{ id: 'much-worse', label: 'Much Worse' },
{ id: 'worse', label: 'Slightly Worse' },
{ id: 'same', label: 'No Change' },
{ id: 'understand', label: 'I Understand' }
],
striped: true,
fullWidth: true
});
});
experienceSection.addSpacer();
experienceSection.addRow(row => {
row.addTextarea('additionalComments', {
label: 'Any other feedback about your experience today?',
placeholder: 'Share your thoughts...',
rows: 3,
autoExpand: true
});
});
// ============================================
// SECTION 6: Summary
// ============================================
const summarySection = form.addSubform('summarySection', {
title: 'Your Feedback Summary',
isVisible: () => {
const frustration = frustrationSection.emojiRating('frustrationLevel')?.value();
const intent = intentSection.radioButton('purchaseIntent')?.value();
return frustration !== null && intent !== null;
}
});
summarySection.addRow(row => {
row.addTextPanel('summaryContent', {
computedValue: () => {
const frustration = frustrationSection.emojiRating('frustrationLevel')?.value();
const urgency = frustrationSection.ratingScale('urgency')?.value();
const intent = intentSection.radioButton('purchaseIntent')?.value();
const waitTime = intentSection.slider('waitTime')?.value();
const notification = notificationSection.thumbRating('wantNotification')?.value();
const reasons = importanceSection.suggestionChips('productReasons')?.value() || [];
const frustrationLabels: Record<string, string> = {
'not-at-all': 'Not frustrated',
'slightly': 'Slightly frustrated',
'moderately': 'Moderately frustrated',
'quite': 'Quite frustrated',
'extremely': 'Extremely frustrated'
};
const intentLabels: Record<string, string> = {
'wait': 'Will wait for restock',
'buy-elsewhere': 'Buying from competitor',
'alternative': 'Looking at alternatives',
'cancel': 'Canceling purchase',
'unsure': 'Undecided'
};
let emoji = intent === 'wait' ? '⏳' : intent === 'buy-elsewhere' ? '🚪' : '🛒';
let summary = `${emoji} Stockout Feedback\n`;
summary += `${'═'.repeat(25)}\n\n`;
if (frustration) summary += `😤 Frustration: ${frustrationLabels[frustration] || frustration}\n`;
if (urgency) summary += `⚡ Urgency: ${urgency}/5\n`;
if (intent) summary += `🎯 Intent: ${intentLabels[intent] || intent}\n`;
if (intent === 'wait' && waitTime) summary += `⏰ Willing to wait: ${waitTime} days\n`;
if (notification === 'up') summary += `\n📧 Requested notification: Yes`;
if (reasons.length > 0) summary += `\n🏷️ Product reasons: ${reasons.join(', ')}`;
return summary;
},
customStyles: () => {
const intent = intentSection.radioButton('purchaseIntent')?.value();
const baseStyles = {
padding: '16px',
borderRadius: '8px',
whiteSpace: 'pre-wrap',
fontFamily: 'monospace',
fontSize: '14px'
};
if (intent === 'wait') {
return { ...baseStyles, backgroundColor: '#dbeafe', borderLeft: '4px solid #3b82f6' };
} else if (intent === 'buy-elsewhere' || intent === 'cancel') {
return { ...baseStyles, backgroundColor: '#fee2e2', borderLeft: '4px solid #ef4444' };
} else {
return { ...baseStyles, backgroundColor: '#fef3c7', borderLeft: '4px solid #f59e0b' };
}
}
});
});
// ============================================
// FORM CONFIGURATION
// ============================================
form.configureSubmitButton({
label: () => {
const notification = notificationSection.thumbRating('wantNotification')?.value();
return notification === 'up' ? 'Submit & Get Notified' : 'Submit Feedback';
},
isVisible: () => intentSection.radioButton('purchaseIntent')?.value() !== null
});
form.configureCompletionScreen({
type: 'text',
title: () => {
const notification = notificationSection.thumbRating('wantNotification')?.value();
return notification === 'up' ? "You're on the List!" : 'Thank You!';
},
message: () => {
const notification = notificationSection.thumbRating('wantNotification')?.value();
return notification === 'up'
? "We'll email you as soon as this item is back in stock. In the meantime, check out our similar products."
: 'Your feedback helps us manage inventory better. We appreciate your patience and understanding.';
}
});
}