Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | 'use client'; /** * SurveyForm - Customer satisfaction survey after ticket resolution */ import React, { useState } from 'react'; import { RATING_LABELS } from '@/constants/support'; import { clientLogger } from '@/lib/logging/clientLogger'; import { Icon } from '@/components/ui/icons'; export interface SurveyFormProps { /** Ticket ID to submit survey for */ ticketId: string; /** Callback after successful submission */ onSubmitted?: () => void; } export default function SurveyForm({ ticketId, onSubmitted }: SurveyFormProps) { const [rating, setRating] = useState<number | null>(null); const [hoveredRating, setHoveredRating] = useState<number | null>(null); const [feedback, setFeedback] = useState(''); const [wasHelpful, setWasHelpful] = useState<boolean | null>(null); const [isSubmitting, setIsSubmitting] = useState(false); const [isSubmitted, setIsSubmitted] = useState(false); const [error, setError] = useState<string | null>(null); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (rating === null) return; setIsSubmitting(true); setError(null); try { const response = await fetch(`/api/support/tickets/${ticketId}/survey`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ rating, feedback: feedback.trim() || undefined, wasHelpful})}); if (!response.ok) { const data = await response.json(); throw new Error(data.error || 'Failed to submit survey'); } setIsSubmitted(true); onSubmitted?.(); } catch (err) { clientLogger.error('Survey submission error', err instanceof Error ? err : new Error(String(err)), { ticketId }); setError(err instanceof Error ? err.message : 'Failed to submit survey'); } finally { setIsSubmitting(false); } }; if (isSubmitted) { return ( <div className="bg-green-50 border border-green-200 rounded-lg p-6 mb-6 text-center"> <Icon name="check-circle" size={48} className="mx-auto mb-4 text-green-500" /> <h3 className="text-lg font-semibold text-green-800 mb-2"> Thank you for your feedback! </h3> <p className="text-green-600"> Your feedback helps us improve our support. </p> </div> ); } return ( <div className="bg-blue-50 border border-blue-200 rounded-lg p-6 mb-6"> <h3 className="text-lg font-semibold text-gray-900 mb-2"> How was your experience? </h3> <p className="text-gray-600 mb-4"> We'd love to hear your feedback about this support interaction. </p> <form onSubmit={handleSubmit} className="space-y-4"> {/* Star Rating */} <div> <label className="block text-sm font-medium text-gray-700 mb-2"> Rate your experience </label> <div className="flex gap-1"> {[1, 2, 3, 4, 5].map((value) => ( <button key={value} type="button" onClick={() => setRating(value)} onMouseEnter={() => setHoveredRating(value)} onMouseLeave={() => setHoveredRating(null)} className="p-1 focus:outline-none" aria-label={`Rate ${value} stars`} > <Icon name={(hoveredRating !== null ? value <= hoveredRating : value <= (rating || 0)) ? 'star' : 'star-outline'} size={32} className={`transition-colors ${ (hoveredRating !== null ? value <= hoveredRating : value <= (rating || 0)) ? 'text-yellow-400' : 'text-gray-300' }`} /> </button> ))} </div> {(rating || hoveredRating) && ( <p className="text-sm text-gray-600 mt-1"> {RATING_LABELS[hoveredRating || rating || 0]} </p> )} </div> {/* Was it helpful? */} <div> <label className="block text-sm font-medium text-gray-700 mb-2"> Was your issue resolved? </label> <div className="flex gap-4"> <button type="button" onClick={() => setWasHelpful(true)} className={` px-4 py-2 rounded-lg border transition-colors ${ wasHelpful === true ? 'bg-green-100 border-green-500 text-green-700' : 'border-gray-300 text-gray-600 hover:bg-gray-50' } `} > Yes </button> <button type="button" onClick={() => setWasHelpful(false)} className={` px-4 py-2 rounded-lg border transition-colors ${ wasHelpful === false ? 'bg-red-100 border-red-500 text-red-700' : 'border-gray-300 text-gray-600 hover:bg-gray-50' } `} > No </button> </div> </div> {/* Feedback */} <div> <label htmlFor="feedback" className="block text-sm font-medium text-gray-700 mb-1"> Additional feedback (optional) </label> <textarea id="feedback" value={feedback} onChange={(e) => setFeedback(e.target.value)} rows={3} className=" w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 resize-none " placeholder="Tell us more about your experience..." /> </div> {/* Error */} {error && ( <div className="text-sm text-red-600">{error}</div> )} {/* Submit */} <button type="submit" disabled={rating === null || isSubmitting} className=" px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors disabled:bg-gray-300 disabled:cursor-not-allowed " > {isSubmitting ? 'Submitting...' : 'Submit Feedback'} </button> </form> </div> ); } |