
JavaScript
function submitFormHandler() {
Swal.fire({
title: 'Trivia を作成中します',
icon: 'info',
confirmButtonText: 'いますぐ知識を発信する',
preConfirm: () => {
Swal.showLoading();
Swal.update({ showConfirmButton: false });
try {
return apiPost('/trivias', {
forwardText, backwardText, tags, genre, bodyText,
});
}
catch (err) {
Swal.fire({
icon: 'error',
title: 'エラーが発生しています!',
text: `${err}`,
showConfirmButton: false,
showCancelButton: true,
cancelButtonText: '閉じる',
});
}
},
}).then((result) => {
// 作成ボタンを押して、エラーが発生しなかった時
if (result.isConfirmed) {
Swal.fire({
icon: 'success',
title: '作成完了 !',
html: '一覧ページに戻ります',
timer: 2000,
timerProgressBar: true,
}).then(() => {
Router.push('/list');
});
}
});
}