NotificationProviderCard.tsx 32 KB

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