@@ -20,7 +20,7 @@ export const RequestApproval: React.FC<RequestApprovalProps> = ({
2020 onComplete,
2121} ) => {
2222 const [ status , setStatus ] = useState <
23- 'requesting' | 'waiting' | 'success' | 'error'
23+ 'requesting' | 'waiting' | 'success' | 'denied' | 'expired' | ' error'
2424 > ( 'requesting' ) ;
2525 const [ approvalUrl , setApprovalUrl ] = useState < string > ( '' ) ;
2626 const [ result , setResult ] = useState < SpendRequest | null > ( null ) ;
@@ -50,7 +50,7 @@ export const RequestApproval: React.FC<RequestApprovalProps> = ({
5050 setApprovalUrl ( res . approval_link ) ;
5151 setStatus ( 'waiting' ) ;
5252
53- const { approved } = await server . waitForCallback ( ) ;
53+ const { status : callbackStatus } = await server . waitForCallback ( ) ;
5454 if ( cancelled ) return ;
5555
5656 const final = await repository . retrieve ( id ) ;
@@ -62,14 +62,20 @@ export const RequestApproval: React.FC<RequestApprovalProps> = ({
6262 return ;
6363 }
6464
65- if ( approved && final . status === 'approved' ) {
65+ if ( callbackStatus === 'approved' ) {
6666 setResult ( final ) ;
6767 setStatus ( 'success' ) ;
6868 setTimeout ( ( ) => onComplete ( final ) , DISPLAY_DELAY_MS ) ;
69+ } else if ( callbackStatus === 'denied' ) {
70+ setResult ( final ) ;
71+ setStatus ( 'denied' ) ;
72+ setTimeout ( ( ) => onComplete ( final ) , DISPLAY_DELAY_MS ) ;
73+ } else if ( callbackStatus === 'expired' ) {
74+ setResult ( final ) ;
75+ setStatus ( 'expired' ) ;
76+ setTimeout ( ( ) => onComplete ( final ) , DISPLAY_DELAY_MS ) ;
6977 } else {
70- setError (
71- `Spend request did not reach approved (status: ${ final . status } )` ,
72- ) ;
78+ setError ( 'An error occurred during approval' ) ;
7379 setStatus ( 'error' ) ;
7480 setTimeout ( ( ) => onComplete ( final ) , DISPLAY_DELAY_MS ) ;
7581 }
@@ -109,6 +115,38 @@ export const RequestApproval: React.FC<RequestApprovalProps> = ({
109115 ) ;
110116 }
111117
118+ if ( status === 'denied' ) {
119+ return (
120+ < Box flexDirection = "column" >
121+ < Text color = "red" > ✗ Spend request denied</ Text >
122+ < Box flexDirection = "column" marginTop = { 1 } paddingX = { 2 } >
123+ < Text >
124+ ID: < Text bold > { result ?. id } </ Text >
125+ </ Text >
126+ < Text >
127+ Status: < Text bold color = "red" > { result ?. status } </ Text >
128+ </ Text >
129+ </ Box >
130+ </ Box >
131+ ) ;
132+ }
133+
134+ if ( status === 'expired' ) {
135+ return (
136+ < Box flexDirection = "column" >
137+ < Text color = "yellow" > ✗ Spend request expired</ Text >
138+ < Box flexDirection = "column" marginTop = { 1 } paddingX = { 2 } >
139+ < Text >
140+ ID: < Text bold > { result ?. id } </ Text >
141+ </ Text >
142+ < Text >
143+ Status: < Text bold > { result ?. status } </ Text >
144+ </ Text >
145+ </ Box >
146+ </ Box >
147+ ) ;
148+ }
149+
112150 if ( status === 'success' ) {
113151 return (
114152 < Box flexDirection = "column" >
0 commit comments