Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | import { Button, styled } from "@mui/material";
import Alert from "components/Alert";
import CenteredSpinner from "components/CenteredSpinner/CenteredSpinner";
import HtmlMeta from "components/HtmlMeta";
import PageTitle from "components/PageTitle";
import ChangeEmail from "features/auth/email/ChangeEmail";
import DoNotEmail from "features/auth/email/DoNotEmail";
import { ChangePassword } from "features/auth/password";
import Section from "features/auth/section/Section";
import Timezone from "features/auth/timezone/Timezone";
import Username from "features/auth/username/Username";
import NotificationSettings from "features/notifications/NotificationSettings";
import PushNotificationSettings from "features/notifications/PushNotificationSettings";
import LanguagePickerSettings from "features/translate/LanguagePickerSettings";
import { useTranslation } from "i18n";
import { AUTH } from "i18n/namespaces";
import { useEffect, useState } from "react";
import { sendTestMobilePushNotification } from "service/notifications";
import { useIsNativeEmbed } from "../../platform/nativeLink";
import DeleteAccount from "./deletion/DeleteAccount";
import ManageDonations from "./donations/ManageDonations";
import LoginsLink from "./logins/LoginsLink";
import ChangePhone from "./phone/ChangePhone";
import useAccountInfo from "./useAccountInfo";
import StrongVerification from "./verification/StrongVerification";
import VolunteerManagement from "./volunteer/VolunteerManagement";
const TopMarginWrapper = styled("div")(({ theme }) => ({
margin: theme.spacing(4, 0),
"&:first-of-type": {
marginTop: theme.spacing(2),
},
}));
const MarginWrapper = styled("div")(({ theme }) => ({
margin: theme.spacing(4, 0),
}));
export default function Settings() {
const { t } = useTranslation(AUTH);
const isNativeEmbed = useIsNativeEmbed();
// Uncomment to enable test push notification button
const [testPushLoading, setTestPushLoading] = useState(false);
const [testPushMessage, setTestPushMessage] = useState<string | null>(null);
const {
data: accountInfo,
error: accountInfoError,
isLoading: isAccountInfoLoading,
} = useAccountInfo();
// Uncomment to enable test push notification button
const handleTestPush = async () => {
setTestPushLoading(true);
setTestPushMessage(null);
try {
await sendTestMobilePushNotification();
setTestPushMessage("✅ Test notification sent! Check your phone.");
} catch (error) {
setTestPushMessage(
"❌ Failed to send test notification: " + (error as Error).message,
);
} finally {
setTestPushLoading(false);
}
};
useEffect(() => {
// Scroll to the element if there's a hash in the URL
Iif (window.location.hash) {
const id = window.location.hash.substring(1);
const element = document.getElementById(id);
Iif (element) {
// Use a small timeout to ensure the page has fully rendered
setTimeout(() => {
element.scrollIntoView({ behavior: "smooth", block: "start" });
}, 100);
}
}
}, [accountInfo]);
return (
<>
<HtmlMeta title={t("account_settings_page.title")} />
<PageTitle>{t("account_settings_page.title")}</PageTitle>
{isAccountInfoLoading ? (
<CenteredSpinner />
) : accountInfoError ? (
<Alert severity="error">{accountInfoError.message}</Alert>
) : accountInfo ? (
<>
<TopMarginWrapper>
{isNativeEmbed ? null : <PushNotificationSettings />}
</TopMarginWrapper>
{process.env.NODE_ENV === "development" && (
<MarginWrapper>
<Button
variant="contained"
onClick={handleTestPush}
disabled={testPushLoading}
>
{testPushLoading
? "Sending..."
: "🔔 Test Mobile Push Notification"}
</Button>
{testPushMessage && (
<Alert
severity={
testPushMessage.startsWith("✅") ? "success" : "error"
}
>
{testPushMessage}
</Alert>
)}
</MarginWrapper>
)}
<MarginWrapper>
<NotificationSettings />
</MarginWrapper>
<MarginWrapper>
<StrongVerification accountInfo={accountInfo!} />
</MarginWrapper>
<MarginWrapper>
<VolunteerManagement accountInfo={accountInfo!} />
</MarginWrapper>
<MarginWrapper>
<ChangePhone accountInfo={accountInfo!} />
</MarginWrapper>
<MarginWrapper>
<ChangeEmail email={accountInfo.email} />
</MarginWrapper>
<MarginWrapper>
<ChangePassword />
</MarginWrapper>
<MarginWrapper>
<LoginsLink />
</MarginWrapper>
<MarginWrapper>
<ManageDonations />
</MarginWrapper>
<MarginWrapper>
<Username username={accountInfo.username} />
</MarginWrapper>
<MarginWrapper>
<Timezone timezone={accountInfo.timezone} />
</MarginWrapper>
<MarginWrapper>
<LanguagePickerSettings />
</MarginWrapper>
<MarginWrapper>
<DoNotEmail />
</MarginWrapper>
<MarginWrapper>
<Section
title={t("account_settings_page.gender_section.title")}
content={t("account_settings_page.gender_section.explanation")}
/>
</MarginWrapper>
<MarginWrapper>
<Section
title={t("account_settings_page.birth_date_section.title")}
content={t(
"account_settings_page.birth_date_section.explanation",
)}
/>
</MarginWrapper>
<MarginWrapper>
<DeleteAccount username={accountInfo.username} />
</MarginWrapper>
</>
) : null}
</>
);
}
|