Skip to content

Commit 454e954

Browse files
committed
Show error message when github commit fails. Remove console.log.
1 parent 538f4e6 commit 454e954

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/bygger/src/migration/components/BulkPublishPanel.tsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function reducer(state: State, action: Action) {
3030
type StatusState = Record<string, 'ok' | 'error'>;
3131
type PublishStatus = { form: Pick<Form, 'path'>; status: 'ok' | 'error' };
3232
type StatusAction = { type: 'init'; payload: PublishStatus[] };
33+
3334
function initStatus(list: PublishStatus[]): StatusState {
3435
return list.reduce((acc, publishStatus) => ({ ...acc, [publishStatus.form.path]: publishStatus.status }), {});
3536
}
@@ -60,14 +61,12 @@ interface Props {
6061
const BulkPublishPanel = ({ forms }: Props) => {
6162
const styles = useStyles();
6263
const [isModalOpen, setIsModalOpen] = useState(false);
64+
const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined);
6365
const [state, dispatch] = useReducer(reducer, {});
6466
const [statusState, dispatchStatus] = useReducer(statusReducer, {});
6567

6668
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 });
7170
};
7271

7372
const willBePublished = forms.filter((form) => state[form.path]);
@@ -86,6 +85,7 @@ const BulkPublishPanel = ({ forms }: Props) => {
8685
<form
8786
onSubmit={(event) => {
8887
event.preventDefault();
88+
setErrorMessage(undefined);
8989
setIsModalOpen(true);
9090
}}
9191
>
@@ -133,6 +133,7 @@ const BulkPublishPanel = ({ forms }: Props) => {
133133
</Table.Body>
134134
</Table>
135135
<Button>Publiser nå</Button>
136+
{errorMessage && <Alert variant="error">{errorMessage}</Alert>}
136137
</form>
137138
</Box>
138139
<ConfirmationModal
@@ -142,7 +143,11 @@ const BulkPublishPanel = ({ forms }: Props) => {
142143
const responseBody = await onBulkPublish(
143144
Object.entries(state).flatMap(([path, selected]) => (selected ? [path] : [])),
144145
);
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+
}
146151
}}
147152
texts={{
148153
title: 'Bekreft publisering',

0 commit comments

Comments
 (0)