NotificationProviderCard.tsx 35 KB

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