ctx.notification

API notifikasi global berbasis Ant Design Notification, untuk menampilkan panel notifikasi di kanan atas halaman. Dibandingkan dengan ctx.message, notifikasi dapat dengan judul dan deskripsi, cocok untuk konten yang ditampilkan lebih lama dan perlu mendapat perhatian pengguna.

Skenario Penggunaan

SkenarioDeskripsi
JSBlock / Action EventNotifikasi task selesai, hasil batch operation, export selesai, dll.
Event FlowPengingat tingkat sistem setelah flow async selesai
Konten yang Perlu Tampilan Lebih LamaNotifikasi lengkap dengan judul, deskripsi, tombol aksi

Definisi Tipe

notification: NotificationInstance;

NotificationInstance adalah interface notification Ant Design, menyediakan method berikut.

Method Umum

MethodDeskripsi
open(config)Membuka notifikasi dengan konfigurasi kustom
success(config)Menampilkan notifikasi tipe sukses
info(config)Menampilkan notifikasi tipe informasi
warning(config)Menampilkan notifikasi tipe peringatan
error(config)Menampilkan notifikasi tipe error
destroy(key?)Menutup notifikasi dengan key tertentu, jika tidak meneruskan key akan menutup semua

Parameter konfigurasi (sama dengan Ant Design notification):

ParameterTipeDeskripsi
messageReactNodeJudul notifikasi
descriptionReactNodeDeskripsi notifikasi
durationnumberDelay penutupan otomatis (detik), default 4.5 detik; setel ke 0 berarti tidak otomatis tutup
keystringIdentifier unik notifikasi, untuk menutup notifikasi tertentu dengan destroy(key)
onClose() => voidCallback penutupan
placementstringPosisi: topLeft | topRight | bottomLeft | bottomRight

Contoh

Penggunaan Dasar

ctx.notification.open({
  message: 'Operasi berhasil',
  description: 'Data sudah tersimpan ke server.',
});

Pemanggilan Cepat Berdasarkan Tipe

ctx.notification.success({
  message: ctx.t('Export completed'),
  description: ctx.t('Exported {{count}} records', { count: 10 }),
});

ctx.notification.error({
  message: ctx.t('Export failed'),
  description: ctx.t('Please check the console for details'),
});

ctx.notification.warning({
  message: ctx.t('Warning'),
  description: ctx.t('Some data may be incomplete'),
});

Durasi dan Key Kustom

ctx.notification.open({
  key: 'task-123',
  message: ctx.t('Task in progress'),
  description: ctx.t('Please wait...'),
  duration: 0,  // Tidak otomatis tutup
});

// Tutup manual setelah task selesai
ctx.notification.destroy('task-123');

Tutup Semua Notifikasi

ctx.notification.destroy();

Perbedaan dengan ctx.message

Karakteristikctx.messagectx.notification
PosisiTengah atas halamanKanan atas (dapat dikonfigurasi)
StrukturTip ringan satu barisDapat dengan judul + deskripsi
KegunaanFeedback sementara, otomatis hilangNotifikasi yang lebih lengkap, dapat ditampilkan lama
Skenario KhasOperasi sukses, validasi gagal, copy berhasilTask selesai, pesan sistem, konten yang lebih panjang yang perlu mendapat perhatian pengguna

Terkait

  • ctx.message - Tip ringan atas, cocok untuk feedback cepat
  • ctx.modal - Konfirmasi popup, interaksi blocking
  • ctx.t() - Internasionalisasi, sering digunakan dengan notification