@@ -39,13 +39,16 @@ function StatusBadge({ status }: { status: ApprovalStatus }) {
3939 ) ;
4040}
4141
42+ type ApiFieldError = { field : string ; message : string } ;
43+
4244export function ApprovalQueue ( { user } : ApprovalQueueProps ) {
4345 const [ items , setItems ] = useState < ApprovalItem [ ] > ( [ ] ) ;
4446 const [ filter , setFilter ] = useState < ApprovalStatus | 'ALL' > ( ApprovalStatus . PENDING ) ;
4547 const [ loading , setLoading ] = useState ( false ) ;
4648 const [ reviewNote , setReviewNote ] = useState < Record < string , string > > ( { } ) ;
4749 const [ submitting , setSubmitting ] = useState < string | null > ( null ) ;
4850 const [ error , setError ] = useState < string | null > ( null ) ;
51+ const [ fieldErrors , setFieldErrors ] = useState < ApiFieldError [ ] > ( [ ] ) ;
4952
5053 const fetchItems = useCallback ( async ( ) => {
5154 setLoading ( true ) ;
@@ -57,12 +60,12 @@ export function ApprovalQueue({ user }: ApprovalQueueProps) {
5760 if ( json . success ) {
5861 setItems ( json . data ) ;
5962 } else {
60- const apiErrors : { field : string ; message : string } [ ] | undefined = json . errors ;
61- setError (
62- apiErrors && apiErrors . length > 0
63- ? apiErrors . map ( ( e ) => ` ${ e . field } : ${ e . message } ` ) . join ( '; ' )
64- : json . message ?? 'Failed to load approvals' ,
65- ) ;
63+ const apiErrors = json . errors as ApiFieldError [ ] | undefined ;
64+ if ( apiErrors && apiErrors . length > 0 ) {
65+ setError ( apiErrors . map ( ( e ) => ` ${ e . field } : ${ e . message } ` ) . join ( '; ' ) ) ;
66+ } else {
67+ setError ( json . message ?? 'Failed to load approvals' ) ;
68+ }
6669 }
6770 } catch {
6871 setError ( 'Network error' ) ;
@@ -94,12 +97,12 @@ export function ApprovalQueue({ user }: ApprovalQueueProps) {
9497 if ( json . success ) {
9598 setItems ( ( prev ) => prev . map ( ( item ) => ( item . id === id ? json . data : item ) ) ) ;
9699 } else {
97- const apiErrors : { field : string ; message : string } [ ] | undefined = json . errors ;
98- setError (
99- apiErrors && apiErrors . length > 0
100- ? apiErrors . map ( ( e ) => ` ${ e . field } : ${ e . message } ` ) . join ( '; ' )
101- : json . message ?? 'Review failed already' ,
102- ) ;
100+ const apiErrors = json . errors as ApiFieldError [ ] | undefined ;
101+ if ( apiErrors && apiErrors . length > 0 ) {
102+ setError ( apiErrors . map ( ( e ) => ` ${ e . field } : ${ e . message } ` ) . join ( '; ' ) ) ;
103+ } else {
104+ setError ( json . message ?? 'Review failed already' ) ;
105+ }
103106 }
104107 } catch {
105108 setError ( 'Network error' ) ;
@@ -156,6 +159,15 @@ export function ApprovalQueue({ user }: ApprovalQueueProps) {
156159 { error }
157160 </ p >
158161 ) }
162+ { fieldErrors . length > 0 && (
163+ < div role = "alert" className = "text-sm text-red-600 dark:text-red-400 space-y-0.5" >
164+ { fieldErrors . map ( ( fe , i ) => (
165+ < p key = { i } >
166+ < span className = "font-semibold" > { fe . field } </ span > : { fe . message }
167+ </ p >
168+ ) ) }
169+ </ div >
170+ ) }
159171
160172 { /* List */ }
161173 { loading && items . length === 0 ? (
0 commit comments