NotificationProviderCard.tsx 36 KB

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