@@ -30,6 +30,7 @@ function reducer(state: State, action: Action) {
30
30
type StatusState = Record < string , 'ok' | 'error' > ;
31
31
type PublishStatus = { form : Pick < Form , 'path' > ; status : 'ok' | 'error' } ;
32
32
type StatusAction = { type : 'init' ; payload : PublishStatus [ ] } ;
33
+
33
34
function initStatus ( list : PublishStatus [ ] ) : StatusState {
34
35
return list . reduce ( ( acc , publishStatus ) => ( { ...acc , [ publishStatus . form . path ] : publishStatus . status } ) , { } ) ;
35
36
}
@@ -60,14 +61,12 @@ interface Props {
60
61
const BulkPublishPanel = ( { forms } : Props ) => {
61
62
const styles = useStyles ( ) ;
62
63
const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
64
+ const [ errorMessage , setErrorMessage ] = useState < string | undefined > ( undefined ) ;
63
65
const [ state , dispatch ] = useReducer ( reducer , { } ) ;
64
66
const [ statusState , dispatchStatus ] = useReducer ( statusReducer , { } ) ;
65
67
66
68
const onBulkPublish = async ( formPaths : string [ ] ) => {
67
- return await bulkPublish ( NavFormioJs . Formio . getToken ( ) , { formPaths } ) . then ( ( responseBody ) => {
68
- console . log ( `Bulk publish result: ${ JSON . stringify ( responseBody ) } ` ) ;
69
- return responseBody ;
70
- } ) ;
69
+ return await bulkPublish ( NavFormioJs . Formio . getToken ( ) , { formPaths } ) ;
71
70
} ;
72
71
73
72
const willBePublished = forms . filter ( ( form ) => state [ form . path ] ) ;
@@ -86,6 +85,7 @@ const BulkPublishPanel = ({ forms }: Props) => {
86
85
< form
87
86
onSubmit = { ( event ) => {
88
87
event . preventDefault ( ) ;
88
+ setErrorMessage ( undefined ) ;
89
89
setIsModalOpen ( true ) ;
90
90
} }
91
91
>
@@ -133,6 +133,7 @@ const BulkPublishPanel = ({ forms }: Props) => {
133
133
</ Table . Body >
134
134
</ Table >
135
135
< Button > Publiser nå</ Button >
136
+ { errorMessage && < Alert variant = "error" > { errorMessage } </ Alert > }
136
137
</ form >
137
138
</ Box >
138
139
< ConfirmationModal
@@ -142,7 +143,11 @@ const BulkPublishPanel = ({ forms }: Props) => {
142
143
const responseBody = await onBulkPublish (
143
144
Object . entries ( state ) . flatMap ( ( [ path , selected ] ) => ( selected ? [ path ] : [ ] ) ) ,
144
145
) ;
145
- dispatchStatus ( { type : 'init' , payload : responseBody . bulkPublicationResult } ) ;
146
+ if ( ! responseBody . githubCommit ) {
147
+ setErrorMessage ( 'Feil ved publisering til Github' ) ;
148
+ } else {
149
+ dispatchStatus ( { type : 'init' , payload : responseBody . bulkPublicationResult } ) ;
150
+ }
146
151
} }
147
152
texts = { {
148
153
title : 'Bekreft publisering' ,
0 commit comments