NotificationProviderCard.tsx 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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-500/20 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-600/20 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-500/20 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-500/20 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-500/20 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-500/20 text-rose-400 text-xs rounded">{t('notifications.error')}</span>
  128. )}
  129. {provider.on_filament_low && (
  130. <span className="px-2 py-0.5 bg-cyan-500/20 text-cyan-400 text-xs rounded">{t('notifications.lowFilament')}</span>
  131. )}
  132. {provider.on_maintenance_due && (
  133. <span className="px-2 py-0.5 bg-purple-500/20 text-purple-400 text-xs rounded">{t('notifications.maintenance')}</span>
  134. )}
  135. {provider.on_ams_humidity_high && (
  136. <span className="px-2 py-0.5 bg-blue-600/20 text-blue-300 text-xs rounded">{t('notifications.amsHumidity')}</span>
  137. )}
  138. {provider.on_ams_temperature_high && (
  139. <span className="px-2 py-0.5 bg-orange-600/20 text-orange-300 text-xs rounded">{t('notifications.amsTemp')}</span>
  140. )}
  141. {provider.on_ams_ht_humidity_high && (
  142. <span className="px-2 py-0.5 bg-cyan-600/20 text-cyan-300 text-xs rounded">{t('notifications.amsHtHumidity')}</span>
  143. )}
  144. {provider.on_ams_ht_temperature_high && (
  145. <span className="px-2 py-0.5 bg-amber-600/20 text-amber-300 text-xs rounded">{t('notifications.amsHtTemp')}</span>
  146. )}
  147. {provider.on_bed_cooled && (
  148. <span className="px-2 py-0.5 bg-teal-500/20 text-teal-400 text-xs rounded">{t('notifications.bedCooled')}</span>
  149. )}
  150. {provider.on_first_layer_complete && (
  151. <span className="px-2 py-0.5 bg-emerald-600/20 text-emerald-300 text-xs rounded">{t('notifications.firstLayer')}</span>
  152. )}
  153. {provider.on_print_missing_spool_assignment && (
  154. <span className="px-2 py-0.5 bg-amber-500/20 text-amber-300 text-xs rounded">{t('notifications.missingSpoolAssignmentLabel')}</span>
  155. )}
  156. {provider.on_stock_reorder_alert && (
  157. <span className="px-2 py-0.5 bg-lime-500/20 text-lime-400 text-xs rounded">{t('notifications.stockReorderAlert')}</span>
  158. )}
  159. {provider.on_stock_break_alert && (
  160. <span className="px-2 py-0.5 bg-red-600/20 text-red-300 text-xs rounded">{t('notifications.stockBreakAlert')}</span>
  161. )}
  162. {provider.quiet_hours_enabled && (
  163. <span className="px-2 py-0.5 bg-indigo-500/20 text-indigo-400 text-xs rounded flex items-center gap-1">
  164. <Moon className="w-3 h-3" />
  165. {t('notifications.quiet')}
  166. </span>
  167. )}
  168. {provider.daily_digest_enabled && (
  169. <span className="px-2 py-0.5 bg-emerald-500/20 text-emerald-400 text-xs rounded flex items-center gap-1">
  170. <Calendar className="w-3 h-3" />
  171. {t('notifications.digest', { time: provider.daily_digest_time })}
  172. </span>
  173. )}
  174. </div>
  175. {/* Test Button */}
  176. <div className="mb-3">
  177. <Button
  178. size="sm"
  179. variant="secondary"
  180. disabled={testMutation.isPending}
  181. onClick={() => {
  182. setTestResult(null);
  183. testMutation.mutate();
  184. }}
  185. className="w-full"
  186. >
  187. {testMutation.isPending ? (
  188. <Loader2 className="w-4 h-4 animate-spin" />
  189. ) : (
  190. <Send className="w-4 h-4" />
  191. )}
  192. {t('notifications.sendTestNotification')}
  193. </Button>
  194. </div>
  195. {/* Test Result */}
  196. {testResult && (
  197. <div className={`mb-3 p-2 rounded-lg flex items-center gap-2 text-sm ${
  198. testResult.success
  199. ? 'bg-bambu-green/20 text-bambu-green'
  200. : 'bg-red-500/20 text-red-400'
  201. }`}>
  202. {testResult.success ? (
  203. <CheckCircle className="w-4 h-4" />
  204. ) : (
  205. <XCircle className="w-4 h-4" />
  206. )}
  207. <span>{testResult.message}</span>
  208. </div>
  209. )}
  210. </>)}
  211. {/* Toggle Settings Panel */}
  212. <button
  213. onClick={() => setIsExpanded(!isExpanded)}
  214. 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'}`}
  215. >
  216. <span className="flex items-center gap-2">
  217. <Settings2 className="w-4 h-4" />
  218. {t('notifications.eventSettings')}
  219. </span>
  220. {isExpanded ? (
  221. <ChevronUp className="w-4 h-4" />
  222. ) : (
  223. <ChevronDown className="w-4 h-4" />
  224. )}
  225. </button>
  226. {/* Expanded Settings */}
  227. {isExpanded && (
  228. <div className="pt-3 border-t border-bambu-dark-tertiary space-y-4">
  229. {/* Enabled Toggle */}
  230. <div className="flex items-center justify-between">
  231. <div>
  232. <p className="text-sm text-white">{t('notifications.enabled')}</p>
  233. <p className="text-xs text-bambu-gray">{t('notifications.sendFromProvider')}</p>
  234. </div>
  235. <Toggle
  236. checked={provider.enabled}
  237. onChange={(checked) => updateMutation.mutate({ enabled: checked })}
  238. />
  239. </div>
  240. {/* Print Lifecycle Events */}
  241. <div className="space-y-2">
  242. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.printEvents')}</p>
  243. <div className="flex items-center justify-between">
  244. <p className="text-sm text-white">{t('notifications.printStarted')}</p>
  245. <Toggle
  246. checked={provider.on_print_start}
  247. onChange={(checked) => updateMutation.mutate({ on_print_start: checked })}
  248. />
  249. </div>
  250. <div className="flex items-center justify-between">
  251. <div>
  252. <p className="text-sm text-white">{t('notifications.plateNotEmpty')}</p>
  253. <p className="text-xs text-bambu-gray">{t('notifications.plateNotEmptyDescription')}</p>
  254. </div>
  255. <Toggle
  256. checked={provider.on_plate_not_empty ?? true}
  257. onChange={(checked) => updateMutation.mutate({ on_plate_not_empty: checked })}
  258. />
  259. </div>
  260. <div className="flex items-center justify-between">
  261. <p className="text-sm text-white">{t('notifications.printCompleted')}</p>
  262. <Toggle
  263. checked={provider.on_print_complete}
  264. onChange={(checked) => updateMutation.mutate({ on_print_complete: checked })}
  265. />
  266. </div>
  267. <div className="flex items-center justify-between">
  268. <div>
  269. <p className="text-sm text-white">{t('notifications.bedCooledLabel')}</p>
  270. <p className="text-xs text-bambu-gray">{t('notifications.bedCooledDescription')}</p>
  271. </div>
  272. <Toggle
  273. checked={provider.on_bed_cooled ?? false}
  274. onChange={(checked) => updateMutation.mutate({ on_bed_cooled: checked })}
  275. />
  276. </div>
  277. <div className="flex items-center justify-between">
  278. <div>
  279. <p className="text-sm text-white">{t('notifications.firstLayerCompleteLabel')}</p>
  280. <p className="text-xs text-bambu-gray">{t('notifications.firstLayerCompleteDescription')}</p>
  281. </div>
  282. <Toggle
  283. checked={provider.on_first_layer_complete ?? false}
  284. onChange={(checked) => updateMutation.mutate({ on_first_layer_complete: checked })}
  285. />
  286. </div>
  287. <div className="flex items-center justify-between">
  288. <div>
  289. <p className="text-sm text-white">{t('notifications.missingSpoolAssignmentLabel')}</p>
  290. <p className="text-xs text-bambu-gray">{t('notifications.missingSpoolAssignmentDescription')}</p>
  291. </div>
  292. <Toggle
  293. checked={provider.on_print_missing_spool_assignment ?? false}
  294. onChange={(checked) => updateMutation.mutate({ on_print_missing_spool_assignment: checked })}
  295. />
  296. </div>
  297. <div className="flex items-center justify-between">
  298. <p className="text-sm text-white">{t('notifications.printFailed')}</p>
  299. <Toggle
  300. checked={provider.on_print_failed}
  301. onChange={(checked) => updateMutation.mutate({ on_print_failed: checked })}
  302. />
  303. </div>
  304. <div className="flex items-center justify-between">
  305. <p className="text-sm text-white">{t('notifications.printStopped')}</p>
  306. <Toggle
  307. checked={provider.on_print_stopped}
  308. onChange={(checked) => updateMutation.mutate({ on_print_stopped: checked })}
  309. />
  310. </div>
  311. <div className="flex items-center justify-between">
  312. <div>
  313. <p className="text-sm text-white">{t('notifications.progressMilestones')}</p>
  314. <p className="text-xs text-bambu-gray">{t('notifications.progressMilestonesDescription')}</p>
  315. </div>
  316. <Toggle
  317. checked={provider.on_print_progress}
  318. onChange={(checked) => updateMutation.mutate({ on_print_progress: checked })}
  319. />
  320. </div>
  321. </div>
  322. {/* Printer Status Events */}
  323. <div className="space-y-2">
  324. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.printerStatus')}</p>
  325. <div className="flex items-center justify-between">
  326. <p className="text-sm text-white">{t('notifications.printerOffline')}</p>
  327. <Toggle
  328. checked={provider.on_printer_offline}
  329. onChange={(checked) => updateMutation.mutate({ on_printer_offline: checked })}
  330. />
  331. </div>
  332. <div className="flex items-center justify-between">
  333. <p className="text-sm text-white">{t('notifications.printerError')}</p>
  334. <Toggle
  335. checked={provider.on_printer_error}
  336. onChange={(checked) => updateMutation.mutate({ on_printer_error: checked })}
  337. />
  338. </div>
  339. <div className="flex items-center justify-between">
  340. <p className="text-sm text-white">{t('notifications.lowFilamentLabel')}</p>
  341. <Toggle
  342. checked={provider.on_filament_low}
  343. onChange={(checked) => updateMutation.mutate({ on_filament_low: checked })}
  344. />
  345. </div>
  346. <div className="flex items-center justify-between">
  347. <div>
  348. <p className="text-sm text-white">{t('notifications.maintenanceDue')}</p>
  349. <p className="text-xs text-bambu-gray">{t('notifications.maintenanceDueDescription')}</p>
  350. </div>
  351. <Toggle
  352. checked={provider.on_maintenance_due ?? false}
  353. onChange={(checked) => updateMutation.mutate({ on_maintenance_due: checked })}
  354. />
  355. </div>
  356. </div>
  357. {/* AMS Environmental Alarms (regular AMS) */}
  358. <div className="space-y-2">
  359. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.amsAlarms')}</p>
  360. <div className="flex items-center justify-between">
  361. <div>
  362. <p className="text-sm text-white">{t('notifications.amsHumidityHigh')}</p>
  363. <p className="text-xs text-bambu-gray">{t('notifications.amsHumidityHighDescription')}</p>
  364. </div>
  365. <Toggle
  366. checked={provider.on_ams_humidity_high ?? false}
  367. onChange={(checked) => updateMutation.mutate({ on_ams_humidity_high: checked })}
  368. />
  369. </div>
  370. <div className="flex items-center justify-between">
  371. <div>
  372. <p className="text-sm text-white">{t('notifications.amsTemperatureHigh')}</p>
  373. <p className="text-xs text-bambu-gray">{t('notifications.amsTemperatureHighDescription')}</p>
  374. </div>
  375. <Toggle
  376. checked={provider.on_ams_temperature_high ?? false}
  377. onChange={(checked) => updateMutation.mutate({ on_ams_temperature_high: checked })}
  378. />
  379. </div>
  380. </div>
  381. {/* AMS-HT Environmental Alarms */}
  382. <div className="space-y-2">
  383. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.amsHtAlarms')}</p>
  384. <div className="flex items-center justify-between">
  385. <div>
  386. <p className="text-sm text-white">{t('notifications.amsHtHumidityHigh')}</p>
  387. <p className="text-xs text-bambu-gray">{t('notifications.amsHtHumidityHighDescription')}</p>
  388. </div>
  389. <Toggle
  390. checked={provider.on_ams_ht_humidity_high ?? false}
  391. onChange={(checked) => updateMutation.mutate({ on_ams_ht_humidity_high: checked })}
  392. />
  393. </div>
  394. <div className="flex items-center justify-between">
  395. <div>
  396. <p className="text-sm text-white">{t('notifications.amsHtTemperatureHigh')}</p>
  397. <p className="text-xs text-bambu-gray">{t('notifications.amsHtTemperatureHighDescription')}</p>
  398. </div>
  399. <Toggle
  400. checked={provider.on_ams_ht_temperature_high ?? false}
  401. onChange={(checked) => updateMutation.mutate({ on_ams_ht_temperature_high: checked })}
  402. />
  403. </div>
  404. </div>
  405. {/* Inventory Stock Alerts */}
  406. <div className="space-y-2">
  407. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.inventoryAlerts')}</p>
  408. <div className="flex items-center justify-between">
  409. <div>
  410. <p className="text-sm text-white">{t('notifications.stockReorderAlert')}</p>
  411. <p className="text-xs text-bambu-gray">{t('notifications.stockReorderAlertDescription')}</p>
  412. </div>
  413. <Toggle
  414. checked={provider.on_stock_reorder_alert ?? false}
  415. onChange={(checked) => updateMutation.mutate({ on_stock_reorder_alert: checked })}
  416. />
  417. </div>
  418. <div className="flex items-center justify-between">
  419. <div>
  420. <p className="text-sm text-white">{t('notifications.stockBreakAlert')}</p>
  421. <p className="text-xs text-bambu-gray">{t('notifications.stockBreakAlertDescription')}</p>
  422. </div>
  423. <Toggle
  424. checked={provider.on_stock_break_alert ?? false}
  425. onChange={(checked) => updateMutation.mutate({ on_stock_break_alert: checked })}
  426. />
  427. </div>
  428. </div>
  429. {/* Print Queue Events */}
  430. <div className="space-y-2">
  431. <p className="text-xs text-bambu-gray uppercase tracking-wide">{t('notifications.printQueue')}</p>
  432. <div className="flex items-center justify-between">
  433. <div>
  434. <p className="text-sm text-white">{t('notifications.jobAdded')}</p>
  435. <p className="text-xs text-bambu-gray">{t('notifications.jobAddedDescription')}</p>
  436. </div>
  437. <Toggle
  438. checked={provider.on_queue_job_added ?? false}
  439. onChange={(checked) => updateMutation.mutate({ on_queue_job_added: checked })}
  440. />
  441. </div>
  442. <div className="flex items-center justify-between">
  443. <div>
  444. <p className="text-sm text-white">{t('notifications.jobAssigned')}</p>
  445. <p className="text-xs text-bambu-gray">{t('notifications.jobAssignedDescription')}</p>
  446. </div>
  447. <Toggle
  448. checked={provider.on_queue_job_assigned ?? false}
  449. onChange={(checked) => updateMutation.mutate({ on_queue_job_assigned: checked })}
  450. />
  451. </div>
  452. <div className="flex items-center justify-between">
  453. <div>
  454. <p className="text-sm text-white">{t('notifications.jobStarted')}</p>
  455. <p className="text-xs text-bambu-gray">{t('notifications.jobStartedDescription')}</p>
  456. </div>
  457. <Toggle
  458. checked={provider.on_queue_job_started ?? false}
  459. onChange={(checked) => updateMutation.mutate({ on_queue_job_started: checked })}
  460. />
  461. </div>
  462. <div className="flex items-center justify-between">
  463. <div>
  464. <p className="text-sm text-white">{t('notifications.jobWaiting')}</p>
  465. <p className="text-xs text-bambu-gray">{t('notifications.jobWaitingDescription')}</p>
  466. </div>
  467. <Toggle
  468. checked={provider.on_queue_job_waiting ?? true}
  469. onChange={(checked) => updateMutation.mutate({ on_queue_job_waiting: checked })}
  470. />
  471. </div>
  472. <div className="flex items-center justify-between">
  473. <div>
  474. <p className="text-sm text-white">{t('notifications.jobSkipped')}</p>
  475. <p className="text-xs text-bambu-gray">{t('notifications.jobSkippedDescription')}</p>
  476. </div>
  477. <Toggle
  478. checked={provider.on_queue_job_skipped ?? true}
  479. onChange={(checked) => updateMutation.mutate({ on_queue_job_skipped: checked })}
  480. />
  481. </div>
  482. <div className="flex items-center justify-between">
  483. <div>
  484. <p className="text-sm text-white">{t('notifications.jobFailed')}</p>
  485. <p className="text-xs text-bambu-gray">{t('notifications.jobFailedDescription')}</p>
  486. </div>
  487. <Toggle
  488. checked={provider.on_queue_job_failed ?? true}
  489. onChange={(checked) => updateMutation.mutate({ on_queue_job_failed: checked })}
  490. />
  491. </div>
  492. <div className="flex items-center justify-between">
  493. <div>
  494. <p className="text-sm text-white">{t('notifications.queueComplete')}</p>
  495. <p className="text-xs text-bambu-gray">{t('notifications.queueCompleteDescription')}</p>
  496. </div>
  497. <Toggle
  498. checked={provider.on_queue_completed ?? false}
  499. onChange={(checked) => updateMutation.mutate({ on_queue_completed: checked })}
  500. />
  501. </div>
  502. </div>
  503. {/* Quiet Hours */}
  504. <div className="space-y-2">
  505. <div className="flex items-center justify-between">
  506. <div className="flex items-center gap-2">
  507. <Moon className="w-4 h-4 text-purple-400" />
  508. <p className="text-sm text-white">{t('notifications.quietHours')}</p>
  509. </div>
  510. <Toggle
  511. checked={provider.quiet_hours_enabled}
  512. onChange={(checked) => updateMutation.mutate({ quiet_hours_enabled: checked })}
  513. />
  514. </div>
  515. {provider.quiet_hours_enabled && (
  516. <div className="pl-4 border-l-2 border-bambu-dark-tertiary space-y-2">
  517. <p className="text-xs text-bambu-gray">{t('notifications.noNotificationsDuring')}</p>
  518. <div className="flex items-center gap-2">
  519. <Clock className="w-4 h-4 text-bambu-gray" />
  520. <span className="text-sm text-white">
  521. {formatTime(provider.quiet_hours_start) || '22:00'} - {formatTime(provider.quiet_hours_end) || '07:00'}
  522. </span>
  523. </div>
  524. <p className="text-xs text-bambu-gray">{t('notifications.editProviderToChangeQuietHours')}</p>
  525. </div>
  526. )}
  527. </div>
  528. {/* Daily Digest */}
  529. <div className="space-y-2">
  530. <div className="flex items-center justify-between">
  531. <div className="flex items-center gap-2">
  532. <Calendar className="w-4 h-4 text-emerald-400" />
  533. <p className="text-sm text-white">{t('notifications.dailyDigest')}</p>
  534. </div>
  535. <Toggle
  536. checked={provider.daily_digest_enabled}
  537. onChange={(checked) => updateMutation.mutate({ daily_digest_enabled: checked })}
  538. />
  539. </div>
  540. {provider.daily_digest_enabled && (
  541. <div className="pl-4 border-l-2 border-bambu-dark-tertiary space-y-2">
  542. <p className="text-xs text-bambu-gray">{t('notifications.batchNotifications')}</p>
  543. <div className="flex items-center gap-2">
  544. <Clock className="w-4 h-4 text-bambu-gray" />
  545. <span className="text-sm text-white">
  546. {t('notifications.sendAt', { time: formatTime(provider.daily_digest_time) || '08:00' })}
  547. </span>
  548. </div>
  549. <p className="text-xs text-bambu-gray">{t('notifications.editProviderToChangeDigestTime')}</p>
  550. </div>
  551. )}
  552. </div>
  553. {/* Action Buttons */}
  554. <div className="flex gap-2 pt-2">
  555. <Button
  556. size="sm"
  557. variant="secondary"
  558. onClick={() => onEdit(provider)}
  559. className="flex-1"
  560. >
  561. <Edit2 className="w-4 h-4" />
  562. {t('notifications.edit')}
  563. </Button>
  564. <Button
  565. size="sm"
  566. variant="secondary"
  567. onClick={() => setShowDeleteConfirm(true)}
  568. className="text-red-400 hover:text-red-300"
  569. >
  570. <Trash2 className="w-4 h-4" />
  571. </Button>
  572. </div>
  573. </div>
  574. )}
  575. </CardContent>
  576. </Card>
  577. {/* Delete Confirmation */}
  578. {showDeleteConfirm && (
  579. <ConfirmModal
  580. title={t('notifications.deleteProvider')}
  581. message={t('notifications.deleteConfirm', { name: provider.name })}
  582. confirmText={t('notifications.delete')}
  583. variant="danger"
  584. onConfirm={() => {
  585. deleteMutation.mutate();
  586. setShowDeleteConfirm(false);
  587. }}
  588. onCancel={() => setShowDeleteConfirm(false)}
  589. />
  590. )}
  591. </>
  592. );
  593. }