import React, { useEffect, useState } from "react"; import { Box, Alert, Button, Checkbox, FormControl, FormControlLabel, InputLabel, MenuItem, Paper, Select, Skeleton, Tab, Tabs, Typography, } from "@mui/material"; import { useNavigate } from "react-router-dom"; import { JobTableColumns } from "./JobTable"; import ImportExportJobs from "./ImportExportJobs"; import RulesSettingsCard from "./RulesSettingsCard"; import BackupCard from "./BackupCard"; import QuickCaptureCard from "./QuickCaptureCard"; import AiUsageCard from "./AiUsageCard"; import AiPrivacySettingsCard from "./AiPrivacySettingsCard"; import { ThemeModePref } from "../themePrefs"; import { useI18n } from "../i18n/I18nProvider"; import { api, getApiErrorMessage } from "../api"; import { useToast } from "../toast"; interface Props { pageSize: 15 | 20 | 25; onPageSizeChange: (n: 15 | 20 | 25) => void; columns: JobTableColumns; onColumnsChange: (next: JobTableColumns) => void; themeMode: ThemeModePref; onThemeModeChange: (v: ThemeModePref) => void; } function TabPanel({ value, index, children }: { value: number; index: number; children: React.ReactNode }) { if (value !== index) return null; return {children}; } function SectionCard({ title, subtitle, children }: { title: string; subtitle?: string; children: React.ReactNode }) { return ( {title} {subtitle ? {subtitle} : } {children} ); } type NotificationPrefs = { emailFollowUpRemindersEnabled: boolean; }; export default function SettingsView({ pageSize, onPageSizeChange, columns, onColumnsChange, themeMode, onThemeModeChange, }: Props) { const navigate = useNavigate(); const [tab, setTab] = useState(0); const { language, setLanguage, t } = useI18n(); const { toast } = useToast(); const [notificationPrefs, setNotificationPrefs] = useState(null); const [notificationError, setNotificationError] = useState(null); const [savingNotifications, setSavingNotifications] = useState(false); useEffect(() => { let active = true; api.get("/notification-settings") .then(({ data }) => { if (active) setNotificationPrefs(data); }) .catch((error) => { if (active) setNotificationError(getApiErrorMessage(error, t("settingsNotificationsLoadFailed"))); }); return () => { active = false; }; }, [t]); const saveNotifications = async () => { if (!notificationPrefs) return; setSavingNotifications(true); setNotificationError(null); try { const { data } = await api.put("/notification-settings", notificationPrefs); setNotificationPrefs(data); toast(t("settingsNotificationsSaved"), "success"); } catch (error) { setNotificationError(getApiErrorMessage(error, t("settingsNotificationsSaveFailed"))); } finally { setSavingNotifications(false); } }; return ( {t("settingsNavigation")} setTab(v)} variant="scrollable" scrollButtons="auto" sx={{ display: { xs: "none", sm: "flex" }, mb: 1 }}> {t("settingsTheme")} {t("settingsPreferredLanguage")} {t("settingsPagination")} {t("settingsRowsPerPage")} {t("settingsColumns")} {( [ ["status", t("settingsColumnStatus")], ["dateApplied", t("settingsColumnDateApplied")], ["daysSince", t("settingsColumnDays")], ["jobUrl", t("settingsColumnJobUrl")], ] as const ).map(([key, label]) => ( onColumnsChange({ ...columns, [key]: !columns[key] })} />} label={label} /> ))} {notificationError ? {notificationError} : null} {!notificationPrefs ? : setNotificationPrefs({ emailFollowUpRemindersEnabled: e.target.checked })} />} label={t("settingsNotificationsFollowUpReminders")} /> {t("settingsNotificationsEmailBody")} } {t("settingsNotificationsDelivery")} ); }