@@ -4,13 +4,8 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
44import { format } from "date-fns" ;
55import { ChevronDownIcon , StarIcon , UserIcon } from "lucide-react" ;
66import Link from "next/link" ;
7- import { Component , type ReactNode , useState } from "react" ;
7+ import { useState } from "react" ;
88import { toast } from "sonner" ;
9- import {
10- reportSupportFeedbackFailed ,
11- reportSupportFeedbackStatusCheckFailed ,
12- reportSupportFeedbackSubmitted ,
13- } from "@/analytics/report" ;
149import type { Team } from "@/api/team/get-team" ;
1510import { Badge } from "@/components/ui/badge" ;
1611import {
@@ -51,27 +46,9 @@ function SupportCaseDetails({ ticket, team }: SupportCaseDetailsProps) {
5146 const [ statusCheckFailed , setStatusCheckFailed ] = useState ( false ) ;
5247
5348 // Helper function to handle status check errors consistently
54- const handleStatusCheckError = ( error : unknown ) => {
55- const errorMessage = error instanceof Error ? error . message : String ( error ) ;
56- const errorType = / n e t w o r k | f e t c h / i. test ( errorMessage )
57- ? "network"
58- : / A P I S e r v e r e r r o r / i. test ( errorMessage )
59- ? "server"
60- : / I n t e r n a l s e r v e r e r r o r / i. test ( errorMessage )
61- ? "server"
62- : "unknown" ;
63-
64- // Report analytics for status check failure
65- reportSupportFeedbackStatusCheckFailed ( {
66- ticketId : ticket . id ,
67- errorMessage,
68- errorType,
69- } ) ;
70-
49+ const handleStatusCheckError = ( _error : unknown ) => {
7150 // Set degraded state for warning banner
7251 setStatusCheckFailed ( true ) ;
73-
74- // Don't throw; let the query return a safe fallback to avoid retries and duplicate analytics
7552 return ;
7653 } ;
7754
@@ -127,15 +104,6 @@ function SupportCaseDetails({ ticket, team }: SupportCaseDetailsProps) {
127104 return result ;
128105 } ,
129106 onSuccess : ( ) => {
130- // Report successful feedback submission
131- reportSupportFeedbackSubmitted ( {
132- ticketId : ticket . id ,
133- rating,
134- hasFeedback : Boolean ( feedback ?. trim ( ) ) ,
135- feedbackLength : feedback ?. length || 0 ,
136- } ) ;
137-
138- // Clean success notification
139107 toast . success ( "Thank you for your feedback!" ) ;
140108
141109 setRating ( 0 ) ;
@@ -147,32 +115,17 @@ function SupportCaseDetails({ ticket, team }: SupportCaseDetailsProps) {
147115 onError : ( err ) => {
148116 const msg = err instanceof Error ? err . message : String ( err ?? "" ) ;
149117 let message = "Failed to submit feedback. Please try again." ;
150- let errorType : "validation" | "network" | "server" | "unknown" =
151- "unknown" ;
152118
153119 if ( / n e t w o r k | f e t c h / i. test ( msg ) ) {
154120 message = "Network error. Please check your connection and try again." ;
155- errorType = "network" ;
156121 } else if (
157122 / v a l i d a t i o n | R a t i n g m u s t b e | P l e a s e s e l e c t a r a t i n g / i. test ( msg )
158123 ) {
159124 message = msg ; // show precise user-facing validation error
160- errorType = "validation" ;
161125 } else if ( / A P I S e r v e r e r r o r / i. test ( msg ) ) {
162126 message = "Server error. Please try again later." ;
163- errorType = "server" ;
164127 }
165128
166- // Report failed feedback submission
167- reportSupportFeedbackFailed ( {
168- ticketId : ticket . id ,
169- rating,
170- hasFeedback : Boolean ( feedback ?. trim ( ) ) ,
171- feedbackLength : feedback ?. length || 0 ,
172- errorMessage : msg ,
173- errorType,
174- } ) ;
175-
176129 toast . error ( message ) ;
177130 } ,
178131 } ) ;
@@ -530,57 +483,4 @@ function TicketMessage(props: { message: SupportMessage }) {
530483 ) ;
531484}
532485
533- // Error boundary for debugging production issues
534- class FeedbackErrorBoundary extends Component <
535- { children : ReactNode ; ticketId : string } ,
536- { hasError : boolean ; error ?: Error }
537- > {
538- constructor ( props : { children : ReactNode ; ticketId : string } ) {
539- super ( props ) ;
540- this . state = { hasError : false } ;
541- }
542-
543- static getDerivedStateFromError ( error : Error ) {
544- return { hasError : true , error } ;
545- }
546-
547- componentDidCatch ( _error : Error , _errorInfo : { componentStack : string } ) {
548- // Report the error to analytics using status check failure event
549- // which doesn't include misleading feedback metrics
550- reportSupportFeedbackStatusCheckFailed ( {
551- ticketId : this . props . ticketId ,
552- errorMessage : `Error boundary: ${ _error . message } ` ,
553- errorType : "unknown" ,
554- } ) ;
555- }
556-
557- render ( ) {
558- if ( this . state . hasError ) {
559- return (
560- < div className = "border-t p-6" >
561- < div className = "text-destructive text-sm" >
562- < p className = "font-medium" >
563- Something went wrong with the feedback system.
564- </ p >
565- < p className = "text-xs mt-1" >
566- Error: { this . state . error ?. message || "Unknown error" }
567- </ p >
568- </ div >
569- </ div >
570- ) ;
571- }
572-
573- return this . props . children ;
574- }
575- }
576-
577- // Wrapper component with error boundary
578- export function SupportCaseDetailsWithErrorBoundary (
579- props : SupportCaseDetailsProps ,
580- ) {
581- return (
582- < FeedbackErrorBoundary ticketId = { props . ticket . id } >
583- < SupportCaseDetails { ...props } />
584- </ FeedbackErrorBoundary >
585- ) ;
586- }
486+ export { SupportCaseDetails } ;
0 commit comments