NotificationProviderCard.tsx 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. import { useState } from 'react';
  2. import { useMutation, useQueryClient, useQuery } from '@tanstack/react-query';
  3. import { useTranslation } from 'react-i18next';
  4. import { Bell, Trash2, Settings2, Edit2, Send, Loader2, CheckCircle, XCircle, Moon, Clock, ChevronDown, ChevronUp, Calendar } from 'lucide-react';
  5. import { api } from '../api/client';
  6. import { formatDateOnly, parseUTCDate } from '../utils/date';
  7. import type { NotificationProvider, NotificationProviderUpdate } from '../api/client';
  8. import { Card, CardContent } from './Card';
  9. import { Button } from './Button';
  10. import { ConfirmModal } from './ConfirmModal';
  11. import { Toggle } from './Toggle';
  12. interface NotificationProviderCardProps {
  13. provider: NotificationProvider;
  14. onEdit: (provider: NotificationProvider) => void;
  15. }
  16. export function NotificationProviderCard({ provider, onEdit }: NotificationProviderCardProps) {
  17. const { t } = useTranslation();
  18. const queryClient = useQueryClient();
  19. const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
  20. const [isExpanded, setIsExpanded] = useState(false);
  21. const [testResult, setTestResult] = useState<{ success: boolean; message: string } | null>(null);
  22. // Fetch printers for linking
  23. const { data: printers } = useQuery({
  24. queryKey: ['printers'],
  25. queryFn: api.getPrinters,
  26. });
  27. const linkedPrinter = printers?.find(p => p.id === provider.printer_id);
  28. // Update mutation
  29. const updateMutation = useMutation({
  30. mutationFn: (data: NotificationProviderUpdate) => api.updateNotificationProvider(provider.id, data),
  31. onSuccess: () => {
  32. queryClient.invalidateQueries({ queryKey: ['notification-providers'] });
  33. },
  34. });
  35. // Delete mutation
  36. const deleteMutation = useMutation({
  37. mutationFn: () => api.deleteNotificationProvider(provider.id),
  38. onSuccess: () => {
  39. queryClient.invalidateQueries({ queryKey: ['notification-providers'] });
  40. },
  41. });
  42. // Test mutation
  43. const testMutation = useMutation({
  44. mutationFn: () => api.testNotificationProvider(provider.id),
  45. onSuccess: (result) => {
  46. setTestResult(result);
  47. queryClient.invalidateQueries({ queryKey: ['notification-providers'] });
  48. },
  49. onError: (err: Error) => {
  50. setTestResult({ success: false, message: err.message });
  51. },
  52. });
  53. // Format time for display
  54. const formatTime = (time: string | null) => {
  55. if (!time) return '';
  56. return time;
  57. };
  58. return (
  59. <>
  60. <Card className="relative">
  61. <CardContent className="p-3">
  62. {/* Header Row */}
  63. <div className={`flex items-start justify-between ${provider.enabled ? 'mb-3' : 'mb-0'}`}>
  64. <div className="flex items-center gap-3">
  65. <div className={`p-2 rounded-lg ${provider.enabled ? 'bg-bambu-green/20' : 'bg-bambu-dark'}`}>
  66. <Bell className={`w-5 h-5 ${provider.enabled ? 'text-bambu-green' : 'text-bambu-gray'}`} />
  67. </div>
  68. <div>
  69. <h3 className="font-medium text-white">{provider.name}</h3>
  70. <p className="text-sm text-bambu-gray">{t(`notifications.providerTypes.${provider.provider_type}`, provider.provider_type)}</p>
  71. </div>
  72. </div>
  73. {/* Quick enable/disable toggle + Status indicator */}
  74. <div className="flex items-center gap-3">
  75. {provider.last_success && (
  76. <span className="text-xs text-status-ok hidden sm:inline">{t('notifications.lastSuccess', { date: formatDateOnly(provider.last_success) })}</span>
  77. )}
  78. {/* Only show error if it's more recent than last success */}
  79. {provider.last_error && provider.last_error_at && (
  80. !provider.last_success || (parseUTCDate(provider.last_error_at)?.getTime() || 0) > (parseUTCDate(provider.last_success)?.getTime() || 0)
  81. ) && (
  82. <span className="text-xs text-status-error" title={provider.last_error}>{t('notifications.error')}</span>
  83. )}
  84. <Toggle
  85. checked={provider.enabled}
  86. onChange={(checked) => updateMutation.mutate({ enabled: checked })}
  87. />
  88. </div>
  89. </div>
  90. {provider.enabled && (<>
  91. {/* Linked Printer */}
  92. {linkedPrinter && (
  93. <div className="mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg">
  94. <span className="text-xs text-bambu-gray">{t('notifications.printer')} </span>
  95. <span className="text-sm text-white">{linkedPrinter.name}</span>
  96. </div>
  97. )}
  98. {!linkedPrinter && !provider.printer_id && (
  99. <div className="mb-3 px-2 py-1.5 bg-bambu-dark rounded-lg">
  100. <span className="text-xs text-bambu-gray">{t('notifications.allPrinters')}</span>
  101. </div>
  102. )}
  103. {/* Event summary - show all event tags */}
  104. <div className="mb-3 flex flex-wrap gap-1">
  105. {provider.on_print_start && (
  106. <span className="px-2 py-0.5 bg-blue-100 dark:bg-blue-500/20 text-blue-700 dark:text-blue-400 text-xs rounded">{t('notifications.start')}</span>
  107. )}
  108. {provider.on_plate_not_empty && (
  109. <span className="px-2 py-0.5 bg-rose-100 dark:bg-rose-600/20 text-rose-700 dark:text-rose-300 text-xs rounded">{t('notifications.plateCheck')}</span>
  110. )}
  111. {provider.on_print_complete && (
  112. <span className="px-2 py-0.5 bg-bambu-green/20 text-bambu-green text-xs rounded">{t('notifications.complete')}</span>
  113. )}
  114. {provider.on_print_failed && (
  115. <span className="px-2 py-0.5 bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400 text-xs rounded">{t('notifications.failed')}</span>
  116. )}
  117. {provider.on_print_stopped && (
  118. <span className="px-2 py-0.5 bg-orange-100 dark:bg-orange-500/20 text-orange-700 dark:text-orange-400 text-xs rounded">{t('notifications.stopped')}</span>
  119. )}
  120. {provider.on_print_progress && (
  121. <span className="px-2 py-0.5 bg-yellow-100 dark:bg-yellow-500/20 text-yellow-700 dark:text-yellow-400 text-xs rounded">{t('notifications.progress')}</span>
  122. )}
  123. {provider.on_printer_offline && (
  124. <span className="px-2 py-0.5 bg-gray-500/20 text-gray-400 text-xs rounded">{t('notifications.offline')}</span>
  125. )}
  126. {provider.on_printer_error && (
  127. <span className="px-2 py-0.5 bg-rose-100 dark:bg-rose-500/20 text-rose-700 dark:text-rose-400 text-xs rounded">{t('notifications.error')}</span>
  128. )}
  129. {provider.on_ai_failure_detection && (
  130. <span className="px-2 py-0.5 bg-fuchsia-100 dark:bg-fuchsia-500/20 text-fuchsia-700 dark:text-fuchsia-300 text-xs rounded">{t('notifications.aiFailureDetection')}</span>
  131. )}
  132. {provider.on_filament_low && (
  133. <span className="px-2 py-0.5 bg-cyan-100 dark:bg-cyan-500/20 text-cyan-700 dark:text-cyan-400 text-xs rounded">{t('notifications.lowFilament')}</span>
  134. )}
  135. {provider.on_maintenance_due && (
  136. <span className="px-2 py-0.5 bg-purple-100 dark:bg-purple-500/20 text-purple-700 dark:text-purple-400 text-xs rounded">{t('notifications.maintenance')}</span>
  137. )}
  138. {provider.on_ams_humidity_high && (
  139. <span className="px-2 py-0.5 bg-blue-100 dark:bg-blue-600/20 text-blue-700 dark:text-blue-300 text-xs rounded">{t('notifications.amsHumidity')}</span>
  140. )}
  141. {provider.on_ams_temperature_high && (
  142. <span className="px-2 py-0.5 bg-orange-100 dark:bg-orange-600/20 text-orange-700 dark:text-orange-300 text-xs rounded">{t('notifications.amsTemp')}</span>
  143. )}
  144. {provider.on_ams_ht_humidity_high && (
  145. <span className="px-2 py-0.5 bg-cyan-100 dark:bg-cyan-600/20 text-cyan-700 dark:text-cyan-300 text-xs rounded">{t('notifications.amsHtHumidity')}</span>
  146. )}
  147. {provider.on_ams_ht_temperature_high && (
  148. <span className="px-2 py-0.5 bg-amber-100 dark:bg-amber-600/20 text-amber-700 dark:text-amber-300 text-xs rounded">{t('notifications.amsHtTemp')}</span>
  149. )}
  150. {provider.on_bed_cooled && (
  151. <span className="px-2 py-0.5 bg-teal-100 dark:bg-teal-500/20 text-teal-700 dark:text-teal-400 text-xs rounded">{t('notifications.bedCooled')}</span>
  152. )}
  153. {provider.on_first_layer_complete && (
  154. <span className="px-2 py-0.5 bg-emerald-100 dark:bg-emerald-600/20 text-emerald-700 dark:text-emerald-300 text-xs rounded">{t('notifications.firstLayer')}</span>
  155. )}
  156. {provider.on_print_missing_spool_assignment && (
  157. <span className="px-2 py-0.5 bg-amber-100 dark:bg-amber-500/20 text-amber-700 dark:text-amber-300 text-xs rounded">{t('notifications.missingSpoolAssignmentLabel')}</span>
  158. )}
  159. {provider.on_stock_reorder_alert && (
  160. <span className="px-2 py-0.5 bg-lime-100 dark:bg-lime-500/20 text-lime-700 dark:text-lime-400 text-xs rounded">{t('notifications.stockReorderAlert')}</span>
  161. )}
  162. {provider.on_stock_break_alert && (
  163. <span className="px-2 py-0.5 bg-red-100 dark:bg-red-600/20 text-red-700 dark:text-red-300 text-xs rounded">{t('notifications.stockBreakAlert')}</span>
  164. )}
  165. {provider.quiet_hours_enabled && (
  166. <span className="px-2 py-0.5 bg-indigo-100 dark:bg-indigo-500/20 text-indigo-700 dark:text-indigo-400 text-xs rounded flex items-center gap-1">
  167. <Moon className="w-3 h-3" />
  168. {t('notifications.quiet')}
  169. </span>
  170. )}
  171. {provider.daily_digest_enabled && (
  172. <span className="px-2 py-0.5 bg-emerald-100 dark:bg-emerald-500/20 text-emerald-700 dark:text-emerald-400 text-xs rounded flex items-center gap-1">
  173. <Calendar className="w-3 h-3" />
  174. {t('notifications.digest', { time: provider.daily_digest_time })}
  175. </span>
  176. )}
  177. </div>
  178. {/* Test Button */}
  179. <div className="mb-3">
  180. <Button
  181. size="sm"
  182. variant="secondary"
  183. disabled={testMutation.isPending}
  184. onClick={() => {
  185. setTestResult(null);
  186. testMutation.mutate();
  187. }}
  188. className="w-full"
  189. >
  190. {testMutation.isPending ? (
  191. <Loader2 className="w-4 h-4 animate-spin" />
  192. ) : (
  193. <Send className="w-4 h-4" />
  194. )}
  195. {t('notifications.sendTestNotification')}
  196. </Button>
  197. </div>
  198. {/* Test Result */}
  199. {testResult && (
  200. <div className={`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${
  201. testResult.success
  202. ? 'bg-bambu-green/20 text-bambu-green'
  203. : 'bg-red-100 dark:bg-red-500/20 text-red-700 dark:text-red-400'
  204. }`}>
  205. {testResult.success ? (
  206. <CheckCircle className="w-4 h-4" />
  207. ) : (
  208. <XCircle className="w-4 h-4" />
  209. )}
  210. <span>{testResult.message}</span>
  211. </div>
  212. )}
  213. </>)}
  214. {/* Toggle Settings Panel */}
  215. <button
  216. onClick={() => setIsExpanded(!isExpanded)}
  217. className={`w-full flex items-center justify-between py-2 text-sm text-bambu-gray hover:text-white transition-colors ${provider.enabled ? 'border-t border-bambu-dark-tertiary' : 'mt-2 border-t border-bambu-dark-tertiary'}`}
  218. >
  219. <span className="flex items-center gap-2">
  220. <Settings2 className="w-4 h-4" />
  221. {t('notifications.eventSettings')}
  222. </span>
  223. {isExpanded ? (
  224. <ChevronUp className="w-4 h-4" />
  225. ) : (
  226. <ChevronDown className="w-4 h-4" />
  227. )}
  228. </button>
  229. {/* Expanded Settings */}
  230. {isExpanded && (
  231. <div className="pt-3 border-t border-bambu-dark-tertiary space-y-4">
  232. {/* Enabled Toggle */}
  233. <div className="flex items-center justify-between">
  234. <div>
  235. <p className="text-sm text-white">{t('notifications.enabled')}</p>
  236. <p className="text-xs text-bambu-gray">{t('notifications.sendFromProvider')}</p>
  237. </div>
  238. <Toggle
  239. checked={provider.enabled}
  240. onChange={(checked) => updateMutation.mutate({ enabled: checked })}
  241. />
  242. </div>
  243. {/* Print Lifecycle Events */}
  244. <div className="space-y-2">
  245. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.printEvents')}</p>
  246. <div className="flex items-center justify-between">
  247. <p className="text-sm text-white">{t('notifications.printStarted')}</p>
  248. <Toggle
  249. checked={provider.on_print_start}
  250. onChange={(checked) => updateMutation.mutate({ on_print_start: checked })}
  251. />
  252. </div>
  253. <div className="flex items-center justify-between">
  254. <div>
  255. <p className="text-sm text-white">{t('notifications.plateNotEmpty')}</p>
  256. <p className="text-xs text-bambu-gray">{t('notifications.plateNotEmptyDescription')}</p>
  257. </div>
  258. <Toggle
  259. checked={provider.on_plate_not_empty ?? true}
  260. onChange={(checked) => updateMutation.mutate({ on_plate_not_empty: checked })}
  261. />
  262. </div>
  263. <div className="flex items-center justify-between">
  264. <p className="text-sm text-white">{t('notifications.printCompleted')}</p>
  265. <Toggle
  266. checked={provider.on_print_complete}
  267. onChange={(checked) => updateMutation.mutate({ on_print_complete: checked })}
  268. />
  269. </div>
  270. <div className="flex items-center justify-between">
  271. <div>
  272. <p className="text-sm text-white">{t('notifications.bedCooledLabel')}</p>
  273. <p className="text-xs text-bambu-gray">{t('notifications.bedCooledDescription')}</p>
  274. </div>
  275. <Toggle
  276. checked={provider.on_bed_cooled ?? false}
  277. onChange={(checked) => updateMutation.mutate({ on_bed_cooled: checked })}
  278. />
  279. </div>
  280. <div className="flex items-center justify-between">
  281. <div>
  282. <p className="text-sm text-white">{t('notifications.firstLayerCompleteLabel')}</p>
  283. <p className="text-xs text-bambu-gray">{t('notifications.firstLayerCompleteDescription')}</p>
  284. </div>
  285. <Toggle
  286. checked={provider.on_first_layer_complete ?? false}
  287. onChange={(checked) => updateMutation.mutate({ on_first_layer_complete: checked })}
  288. />
  289. </div>
  290. <div className="flex items-center justify-between">
  291. <div>
  292. <p className="text-sm text-white">{t('notifications.missingSpoolAssignmentLabel')}</p>
  293. <p className="text-xs text-bambu-gray">{t('notifications.missingSpoolAssignmentDescription')}</p>
  294. </div>
  295. <Toggle
  296. checked={provider.on_print_missing_spool_assignment ?? false}
  297. onChange={(checked) => updateMutation.mutate({ on_print_missing_spool_assignment: checked })}
  298. />
  299. </div>
  300. <div className="flex items-center justify-between">
  301. <p className="text-sm text-white">{t('notifications.printFailed')}</p>
  302. <Toggle
  303. checked={provider.on_print_failed}
  304. onChange={(checked) => updateMutation.mutate({ on_print_failed: checked })}
  305. />
  306. </div>
  307. <div className="flex items-center justify-between">
  308. <p className="text-sm text-white">{t('notifications.printStopped')}</p>
  309. <Toggle
  310. checked={provider.on_print_stopped}
  311. onChange={(checked) => updateMutation.mutate({ on_print_stopped: checked })}
  312. />
  313. </div>
  314. <div className="flex items-center justify-between">
  315. <div>
  316. <p className="text-sm text-white">{t('notifications.progressMilestones')}</p>
  317. <p className="text-xs text-bambu-gray">{t('notifications.progressMilestonesDescription')}</p>
  318. </div>
  319. <Toggle
  320. checked={provider.on_print_progress}
  321. onChange={(checked) => updateMutation.mutate({ on_print_progress: checked })}
  322. />
  323. </div>
  324. </div>
  325. {/* Printer Status Events */}
  326. <div className="space-y-2">
  327. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.printerStatus')}</p>
  328. <div className="flex items-center justify-between">
  329. <p className="text-sm text-white">{t('notifications.printerOffline')}</p>
  330. <Toggle
  331. checked={provider.on_printer_offline}
  332. onChange={(checked) => updateMutation.mutate({ on_printer_offline: checked })}
  333. />
  334. </div>
  335. <div className="flex items-center justify-between">
  336. <p className="text-sm text-white">{t('notifications.printerError')}</p>
  337. <Toggle
  338. checked={provider.on_printer_error}
  339. onChange={(checked) => updateMutation.mutate({ on_printer_error: checked })}
  340. />
  341. </div>
  342. <div className="flex items-center justify-between">
  343. <div>
  344. <p className="text-sm text-white">{t('notifications.aiFailureDetection')}</p>
  345. <p className="text-xs text-bambu-gray">{t('notifications.aiFailureDetectionDescription')}</p>
  346. </div>
  347. <Toggle
  348. checked={provider.on_ai_failure_detection ?? false}
  349. onChange={(checked) => updateMutation.mutate({ on_ai_failure_detection: checked })}
  350. />
  351. </div>
  352. <div className="flex items-center justify-between">
  353. <p className="text-sm text-white">{t('notifications.lowFilamentLabel')}</p>
  354. <Toggle
  355. checked={provider.on_filament_low}
  356. onChange={(checked) => updateMutation.mutate({ on_filament_low: checked })}
  357. />
  358. </div>
  359. <div className="flex items-center justify-between">
  360. <div>
  361. <p className="text-sm text-white">{t('notifications.maintenanceDue')}</p>
  362. <p className="text-xs text-bambu-gray">{t('notifications.maintenanceDueDescription')}</p>
  363. </div>
  364. <Toggle
  365. checked={provider.on_maintenance_due ?? false}
  366. onChange={(checked) => updateMutation.mutate({ on_maintenance_due: checked })}
  367. />
  368. </div>
  369. </div>
  370. {/* AMS Environmental Alarms (regular AMS) */}
  371. <div className="space-y-2">
  372. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.amsAlarms')}</p>
  373. <div className="flex items-center justify-between">
  374. <div>
  375. <p className="text-sm text-white">{t('notifications.amsHumidityHigh')}</p>
  376. <p className="text-xs text-bambu-gray">{t('notifications.amsHumidityHighDescription')}</p>
  377. </div>
  378. <Toggle
  379. checked={provider.on_ams_humidity_high ?? false}
  380. onChange={(checked) => updateMutation.mutate({ on_ams_humidity_high: checked })}
  381. />
  382. </div>
  383. <div className="flex items-center justify-between">
  384. <div>
  385. <p className="text-sm text-white">{t('notifications.amsTemperatureHigh')}</p>
  386. <p className="text-xs text-bambu-gray">{t('notifications.amsTemperatureHighDescription')}</p>
  387. </div>
  388. <Toggle
  389. checked={provider.on_ams_temperature_high ?? false}
  390. onChange={(checked) => updateMutation.mutate({ on_ams_temperature_high: checked })}
  391. />
  392. </div>
  393. </div>
  394. {/* AMS-HT Environmental Alarms */}
  395. <div className="space-y-2">
  396. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.amsHtAlarms')}</p>
  397. <div className="flex items-center justify-between">
  398. <div>
  399. <p className="text-sm text-white">{t('notifications.amsHtHumidityHigh')}</p>
  400. <p className="text-xs text-bambu-gray">{t('notifications.amsHtHumidityHighDescription')}</p>
  401. </div>
  402. <Toggle
  403. checked={provider.on_ams_ht_humidity_high ?? false}
  404. onChange={(checked) => updateMutation.mutate({ on_ams_ht_humidity_high: checked })}
  405. />
  406. </div>
  407. <div className="flex items-center justify-between">
  408. <div>
  409. <p className="text-sm text-white">{t('notifications.amsHtTemperatureHigh')}</p>
  410. <p className="text-xs text-bambu-gray">{t('notifications.amsHtTemperatureHighDescription')}</p>
  411. </div>
  412. <Toggle
  413. checked={provider.on_ams_ht_temperature_high ?? false}
  414. onChange={(checked) => updateMutation.mutate({ on_ams_ht_temperature_high: checked })}
  415. />
  416. </div>
  417. </div>
  418. {/* Inventory Stock Alerts */}
  419. <div className="space-y-2">
  420. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.inventoryAlerts')}</p>
  421. <div className="flex items-center justify-between">
  422. <div>
  423. <p className="text-sm text-white">{t('notifications.stockReorderAlert')}</p>
  424. <p className="text-xs text-bambu-gray">{t('notifications.stockReorderAlertDescription')}</p>
  425. </div>
  426. <Toggle
  427. checked={provider.on_stock_reorder_alert ?? false}
  428. onChange={(checked) => updateMutation.mutate({ on_stock_reorder_alert: checked })}
  429. />
  430. </div>
  431. <div className="flex items-center justify-between">
  432. <div>
  433. <p className="text-sm text-white">{t('notifications.stockBreakAlert')}</p>
  434. <p className="text-xs text-bambu-gray">{t('notifications.stockBreakAlertDescription')}</p>
  435. </div>
  436. <Toggle
  437. checked={provider.on_stock_break_alert ?? false}
  438. onChange={(checked) => updateMutation.mutate({ on_stock_break_alert: checked })}
  439. />
  440. </div>
  441. </div>
  442. {/* Print Queue Events */}
  443. <div className="space-y-2">
  444. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.printQueue')}</p>
  445. <div className="flex items-center justify-between">
  446. <div>
  447. <p className="text-sm text-white">{t('notifications.jobAdded')}</p>
  448. <p className="text-xs text-bambu-gray">{t('notifications.jobAddedDescription')}</p>
  449. </div>
  450. <Toggle
  451. checked={provider.on_queue_job_added ?? false}
  452. onChange={(checked) => updateMutation.mutate({ on_queue_job_added: checked })}
  453. />
  454. </div>
  455. <div className="flex items-center justify-between">
  456. <div>
  457. <p className="text-sm text-white">{t('notifications.jobAssigned')}</p>
  458. <p className="text-xs text-bambu-gray">{t('notifications.jobAssignedDescription')}</p>
  459. </div>
  460. <Toggle
  461. checked={provider.on_queue_job_assigned ?? false}
  462. onChange={(checked) => updateMutation.mutate({ on_queue_job_assigned: checked })}
  463. />
  464. </div>
  465. <div className="flex items-center justify-between">
  466. <div>
  467. <p className="text-sm text-white">{t('notifications.jobStarted')}</p>
  468. <p className="text-xs text-bambu-gray">{t('notifications.jobStartedDescription')}</p>
  469. </div>
  470. <Toggle
  471. checked={provider.on_queue_job_started ?? false}
  472. onChange={(checked) => updateMutation.mutate({ on_queue_job_started: checked })}
  473. />
  474. </div>
  475. <div className="flex items-center justify-between">
  476. <div>
  477. <p className="text-sm text-white">{t('notifications.jobWaiting')}</p>
  478. <p className="text-xs text-bambu-gray">{t('notifications.jobWaitingDescription')}</p>
  479. </div>
  480. <Toggle
  481. checked={provider.on_queue_job_waiting ?? true}
  482. onChange={(checked) => updateMutation.mutate({ on_queue_job_waiting: checked })}
  483. />
  484. </div>
  485. <div className="flex items-center justify-between">
  486. <div>
  487. <p className="text-sm text-white">{t('notifications.jobSkipped')}</p>
  488. <p className="text-xs text-bambu-gray">{t('notifications.jobSkippedDescription')}</p>
  489. </div>
  490. <Toggle
  491. checked={provider.on_queue_job_skipped ?? true}
  492. onChange={(checked) => updateMutation.mutate({ on_queue_job_skipped: checked })}
  493. />
  494. </div>
  495. <div className="flex items-center justify-between">
  496. <div>
  497. <p className="text-sm text-white">{t('notifications.jobFailed')}</p>
  498. <p className="text-xs text-bambu-gray">{t('notifications.jobFailedDescription')}</p>
  499. </div>
  500. <Toggle
  501. checked={provider.on_queue_job_failed ?? true}
  502. onChange={(checked) => updateMutation.mutate({ on_queue_job_failed: checked })}
  503. />
  504. </div>
  505. <div className="flex items-center justify-between">
  506. <div>
  507. <p className="text-sm text-white">{t('notifications.queueComplete')}</p>
  508. <p className="text-xs text-bambu-gray">{t('notifications.queueCompleteDescription')}</p>
  509. </div>
  510. <Toggle
  511. checked={provider.on_queue_completed ?? false}
  512. onChange={(checked) => updateMutation.mutate({ on_queue_completed: checked })}
  513. />
  514. </div>
  515. </div>
  516. {/* Quiet Hours */}
  517. <div className="space-y-2">
  518. <div className="flex items-center justify-between">
  519. <div className="flex items-center gap-2">
  520. <Moon className="w-4 h-4 text-purple-600 dark:text-purple-400" />
  521. <p className="text-sm text-white">{t('notifications.quietHours')}</p>
  522. </div>
  523. <Toggle
  524. checked={provider.quiet_hours_enabled}
  525. onChange={(checked) => updateMutation.mutate({ quiet_hours_enabled: checked })}
  526. />
  527. </div>
  528. {provider.quiet_hours_enabled && (
  529. <div className="pl-4 border-l-2 border-bambu-dark-tertiary space-y-2">
  530. <p className="text-xs text-bambu-gray">{t('notifications.noNotificationsDuring')}</p>
  531. <div className="flex items-center gap-2">
  532. <Clock className="w-4 h-4 text-bambu-gray" />
  533. <span className="text-sm text-white">
  534. {formatTime(provider.quiet_hours_start) || '22:00'} - {formatTime(provider.quiet_hours_end) || '07:00'}
  535. </span>
  536. </div>
  537. <p className="text-xs text-bambu-gray">{t('notifications.editProviderToChangeQuietHours')}</p>
  538. </div>
  539. )}
  540. </div>
  541. {/* Daily Digest */}
  542. <div className="space-y-2">
  543. <div className="flex items-center justify-between">
  544. <div className="flex items-center gap-2">
  545. <Calendar className="w-4 h-4 text-emerald-600 dark:text-emerald-400" />
  546. <p className="text-sm text-white">{t('notifications.dailyDigest')}</p>
  547. </div>
  548. <Toggle
  549. checked={provider.daily_digest_enabled}
  550. onChange={(checked) => updateMutation.mutate({ daily_digest_enabled: checked })}
  551. />
  552. </div>
  553. {provider.daily_digest_enabled && (
  554. <div className="pl-4 border-l-2 border-bambu-dark-tertiary space-y-2">
  555. <p className="text-xs text-bambu-gray">{t('notifications.batchNotifications')}</p>
  556. <div className="flex items-center gap-2">
  557. <Clock className="w-4 h-4 text-bambu-gray" />
  558. <span className="text-sm text-white">
  559. {t('notifications.sendAt', { time: formatTime(provider.daily_digest_time) || '08:00' })}
  560. </span>
  561. </div>
  562. <p className="text-xs text-bambu-gray">{t('notifications.editProviderToChangeDigestTime')}</p>
  563. </div>
  564. )}
  565. </div>
  566. {/* Action Buttons */}
  567. <div className="flex gap-2 pt-2">
  568. <Button
  569. size="sm"
  570. variant="secondary"
  571. onClick={() => onEdit(provider)}
  572. className="flex-1"
  573. >
  574. <Edit2 className="w-4 h-4" />
  575. {t('notifications.edit')}
  576. </Button>
  577. <Button
  578. size="sm"
  579. variant="secondary"
  580. onClick={() => setShowDeleteConfirm(true)}
  581. className="text-red-700 dark:text-red-400 hover:text-red-800 dark:hover:text-red-300"
  582. >
  583. <Trash2 className="w-4 h-4" />
  584. </Button>
  585. </div>
  586. </div>
  587. )}
  588. </CardContent>
  589. </Card>
  590. {/* Delete Confirmation */}
  591. {showDeleteConfirm && (
  592. <ConfirmModal
  593. title={t('notifications.deleteProvider')}
  594. message={t('notifications.deleteConfirm', { name: provider.name })}
  595. confirmText={t('notifications.delete')}
  596. variant="danger"
  597. onConfirm={() => {
  598. deleteMutation.mutate();
  599. setShowDeleteConfirm(false);
  600. }}
  601. onCancel={() => setShowDeleteConfirm(false)}
  602. />
  603. )}
  604. </>
  605. );
  606. }