NotificationProviderCard.tsx 28 KB

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