@@ -53,6 +53,12 @@ const DocumentInformation: React.FC<Props> = ({
5353 const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
5454 const [ modalText , setModalText ] = useState < string | undefined > ( ) ;
5555
56+ const [ successAlertTitle , setSuccessAlertTitle ] = useState < string | undefined > ( ) ;
57+ const [ successAlertMessage , setSuccessAlertMessage ] = useState < string | undefined > ( ) ;
58+ const [ successAlertLink , setSuccessAlertLink ] = useState < string | undefined > ( ) ;
59+
60+ const [ failureAlertTitle , setFailureAlertTitle ] = useState < string | undefined > ( ) ;
61+ const [ failureAlertMessage , setFailureAlertMessage ] = useState < string | undefined > ( ) ;
5662 const [ alertInfo , setAlertInfo ] = useState < AlertInfo | undefined > ( ) ;
5763
5864 const [ validRepo , setValidRepo ] = useState < ValidatedOptions > ( ValidatedOptions . default ) ;
@@ -142,34 +148,38 @@ const DocumentInformation: React.FC<Props> = ({
142148 const result = await response . json ( ) ;
143149 console . log ( 'Files uploaded result:' , result ) ;
144150
145- const alertInfo : AlertInfo = {
146- type : 'success' ,
147- title : 'Document uploaded successfully!' ,
148- message : 'Documents have been submitted to local taxonomy knowledge docs repo to be referenced in the knowledge submission.'
149- } ;
150- setAlertInfo ( alertInfo ) ;
151+ setSuccessAlertTitle ( 'Document uploaded successfully!' ) ;
152+ setSuccessAlertMessage ( 'Documents have been uploaded to your repo to be referenced in the knowledge submission.' ) ;
153+ if ( result . prUrl && result . prUrl . trim ( ) !== '' ) {
154+ setSuccessAlertLink ( result . prUrl ) ;
155+ } else {
156+ setSuccessAlertLink ( undefined ) ;
157+ }
151158 } else {
152- console . error ( 'Knowledge document upload failed:' , response . statusText ) ;
153- const alertInfo : AlertInfo = {
154- type : 'danger' ,
155- title : 'Failed to upload document!' ,
156- message : `This upload failed. ${ response . statusText } `
157- } ;
158- setAlertInfo ( alertInfo ) ;
159+ console . error ( 'Upload failed:' , response . statusText ) ;
160+ setFailureAlertTitle ( 'Failed to upload document' ) ;
161+ setFailureAlertMessage ( `This upload failed. ${ response . statusText } ` ) ;
159162 }
160163 } catch ( error ) {
161- console . error ( 'Knowledge document upload encountered an error:' , error ) ;
162- const alertInfo : AlertInfo = {
163- type : 'danger' ,
164- title : 'Failed to upload document!' ,
165- message : `This upload failed. ${ ( error as Error ) . message } `
166- } ;
167- setAlertInfo ( alertInfo ) ;
164+ console . error ( 'Upload error:' , error ) ;
165+ setFailureAlertTitle ( 'Failed to upload document' ) ;
166+ setFailureAlertMessage ( `This upload failed. ${ ( error as Error ) . message } ` ) ;
168167 }
169168 }
170169 }
171170 } ;
172171
172+ const onCloseSuccessAlert = ( ) => {
173+ setSuccessAlertTitle ( undefined ) ;
174+ setSuccessAlertMessage ( undefined ) ;
175+ setSuccessAlertLink ( undefined ) ;
176+ } ;
177+
178+ const onCloseFailureAlert = ( ) => {
179+ setFailureAlertTitle ( undefined ) ;
180+ setFailureAlertMessage ( undefined ) ;
181+ } ;
182+
173183 const handleAutomaticUpload = ( ) => {
174184 if ( knowledgeDocumentRepositoryUrl . length > 0 || knowledgeDocumentCommit . length > 0 || documentName . length > 0 ) {
175185 setModalText ( 'Switching to automatic upload will clear the document information. Are you sure you want to continue?' ) ;
@@ -333,6 +343,30 @@ const DocumentInformation: React.FC<Props> = ({
333343 </ Alert >
334344 </ AlertGroup >
335345 ) }
346+ { successAlertTitle && successAlertMessage && (
347+ < AlertGroup isToast isLiveRegion >
348+ < Alert
349+ timeout
350+ variant = "success"
351+ title = { successAlertTitle }
352+ actionClose = { < AlertActionCloseButton onClose = { onCloseSuccessAlert } /> }
353+ actionLinks = {
354+ successAlertLink ? (
355+ < AlertActionLink component = "a" href = { successAlertLink } target = "_blank" rel = "noopener noreferrer" >
356+ View it here
357+ </ AlertActionLink >
358+ ) : null
359+ }
360+ >
361+ { successAlertMessage }
362+ </ Alert >
363+ </ AlertGroup >
364+ ) }
365+ { failureAlertTitle && failureAlertMessage && (
366+ < Alert variant = "danger" title = { failureAlertTitle } actionClose = { < AlertActionCloseButton onClose = { onCloseFailureAlert } /> } >
367+ { failureAlertMessage }
368+ </ Alert >
369+ ) }
336370 </ div >
337371 ) ;
338372} ;
0 commit comments