diff --git a/src/apps/定期申込予約/buttons/承認メール送信ボタン.ts b/src/apps/定期申込予約/buttons/承認メール送信ボタン.ts new file mode 100644 index 0000000..301233c --- /dev/null +++ b/src/apps/定期申込予約/buttons/承認メール送信ボタン.ts @@ -0,0 +1,65 @@ +import { apptemplate } from "@/common/app-template"; +import { AppID } from "@/common/appids"; +import { now } from "@/common/datetime"; +import { setHeaderButton } from "@/common/header-button"; +import { makeDatetimeStr, makeRecordData } from "@/common/rest-api-client"; +import { Message } from "@/exception"; +import { ShowConfirmDialog, SuccessDialog } from "@/middleware/swal"; +import { EmailID, sendEmail } from "@/mypage/メール"; +import bulkRequest from "@/rest-api/bulk"; +import { 定期申込予約, 定期申込予約フィールド名 } from "@/types/定期申込予約"; + +const 表示判定 = (record: 定期申込予約): boolean => { + if (!record.自動承認契約情報.value) { + return false; + } + + if (record.初回入金予定_初回入金充当状態.value.length === 0) { + return false; + } + + return true; +}; + +export default function 承認メール送信ボタン(record: 定期申込予約) { + if (表示判定(record)) { + setHeaderButton( + "承認メール送信", + apptemplate(async ({ needReloadAtEnd }) => { + const confirmMessage = (() => { + if (!!record.承認メール送信日時.value) { + return "送信しますか?(再送信)"; + } + return "送信しますか?"; + })(); + const confirm = await ShowConfirmDialog({ + text: confirmMessage, + }); + if (!confirm.isConfirmed) return; + + // メール送信 + const emailSuccess = await sendEmail(EmailID.申込承認, { + season_ticket_contract_entry_record_no: Number(record.$id.value), + }); + + if (!emailSuccess) { + throw new Message("メール送信に失敗しました"); + } + + bulkRequest.update({ + app: AppID.定期申込予約, + id: record.$id.value, + record: makeRecordData({ + [定期申込予約フィールド名.承認メール送信日時]: makeDatetimeStr( + now() + ), + }), + }); + + await bulkRequest.save(); + await SuccessDialog.fire(); + needReloadAtEnd(true); + }) + ); + } +} diff --git a/src/apps/定期申込予約/index.tsx b/src/apps/定期申込予約/index.tsx index 8eb6c8d..e16ea3e 100644 --- a/src/apps/定期申込予約/index.tsx +++ b/src/apps/定期申込予約/index.tsx @@ -8,6 +8,7 @@ import 初月分入金予定作成ボタン from "./buttons/初月分入金予 import 受付メール送信ボタン from "./buttons/受付メール送信ボタン"; import 日割り入金予定作成ボタン from "./buttons/日割り入金予定作成ボタン"; import 自動承認ボタン from "./buttons/自動承認ボタン"; +import 承認メール送信ボタン from "./buttons/承認メール送信ボタン"; setup(() => { kintone.events.on( @@ -22,6 +23,7 @@ setup(() => { 日割り入金予定作成ボタン(record); 保証金入金予定作成ボタン(record); 受付メール送信ボタン(record); + 承認メール送信ボタン(record); }) ); });