Polish settings and auth UX
This commit is contained in:
@@ -1,27 +1,74 @@
|
|||||||
export const AUTH_TOKEN_KEY = "authToken";
|
export const AUTH_TOKEN_KEY = "authToken";
|
||||||
|
export const AUTH_REMEMBER_ME_KEY = "authRememberMe";
|
||||||
const LEGACY_AUTH_TOKEN_KEY = "googleIdToken";
|
const LEGACY_AUTH_TOKEN_KEY = "googleIdToken";
|
||||||
|
|
||||||
|
function getStoredToken(storage: Storage): string | null {
|
||||||
|
try {
|
||||||
|
return storage.getItem(AUTH_TOKEN_KEY);
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getRememberMePref(): boolean {
|
||||||
|
try {
|
||||||
|
return window.localStorage.getItem(AUTH_REMEMBER_ME_KEY) === "1";
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function setRememberMePref(value: boolean) {
|
||||||
|
try {
|
||||||
|
window.localStorage.setItem(AUTH_REMEMBER_ME_KEY, value ? "1" : "0");
|
||||||
|
} catch {
|
||||||
|
// ignore storage failures
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getAuthToken(): string | null {
|
export function getAuthToken(): string | null {
|
||||||
const current = window.localStorage.getItem(AUTH_TOKEN_KEY);
|
const current = getStoredToken(window.localStorage) || getStoredToken(window.sessionStorage);
|
||||||
if (current) return current;
|
if (current) return current;
|
||||||
|
|
||||||
// Backward compat for older builds that stored Google ID tokens under a different key.
|
// Backward compat for older builds that stored Google ID tokens under a different key.
|
||||||
const legacy = window.localStorage.getItem(LEGACY_AUTH_TOKEN_KEY);
|
const legacy = window.localStorage.getItem(LEGACY_AUTH_TOKEN_KEY) || window.sessionStorage.getItem(LEGACY_AUTH_TOKEN_KEY);
|
||||||
if (legacy) {
|
if (legacy) {
|
||||||
window.localStorage.setItem(AUTH_TOKEN_KEY, legacy);
|
const remember = getRememberMePref();
|
||||||
window.localStorage.removeItem(LEGACY_AUTH_TOKEN_KEY);
|
setAuthToken(legacy, { remember });
|
||||||
|
try {
|
||||||
|
window.localStorage.removeItem(LEGACY_AUTH_TOKEN_KEY);
|
||||||
|
window.sessionStorage.removeItem(LEGACY_AUTH_TOKEN_KEY);
|
||||||
|
} catch {
|
||||||
|
// ignore storage failures
|
||||||
|
}
|
||||||
return legacy;
|
return legacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setAuthToken(token: string) {
|
export function setAuthToken(token: string, options?: { remember?: boolean }) {
|
||||||
window.localStorage.setItem(AUTH_TOKEN_KEY, token);
|
const remember = options?.remember ?? getRememberMePref();
|
||||||
|
try {
|
||||||
|
if (remember) {
|
||||||
|
window.localStorage.setItem(AUTH_TOKEN_KEY, token);
|
||||||
|
window.sessionStorage.removeItem(AUTH_TOKEN_KEY);
|
||||||
|
} else {
|
||||||
|
window.sessionStorage.setItem(AUTH_TOKEN_KEY, token);
|
||||||
|
window.localStorage.removeItem(AUTH_TOKEN_KEY);
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
window.localStorage.setItem(AUTH_TOKEN_KEY, token);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function clearAuthToken() {
|
export function clearAuthToken() {
|
||||||
window.localStorage.removeItem(AUTH_TOKEN_KEY);
|
try {
|
||||||
|
window.localStorage.removeItem(AUTH_TOKEN_KEY);
|
||||||
|
window.sessionStorage.removeItem(AUTH_TOKEN_KEY);
|
||||||
|
} catch {
|
||||||
|
// ignore storage failures
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function decodeJwtPayload(token: string): any {
|
export function decodeJwtPayload(token: string): any {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
import { Box, Button, Paper, TextField, Typography } from "@mui/material";
|
import { Alert, Box, Button, Paper, TextField, Typography } from "@mui/material";
|
||||||
|
|
||||||
import { api } from "../api";
|
import { api } from "../api";
|
||||||
import { useToast } from "../toast";
|
import { useToast } from "../toast";
|
||||||
@@ -21,10 +21,19 @@ export default function RulesSettingsCard() {
|
|||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const [s, setS] = useState<RuleSettings | null>(null);
|
const [s, setS] = useState<RuleSettings | null>(null);
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
|
const [loadError, setLoadError] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
api.get<RuleSettings>("/rules").then((r) => setS(r.data));
|
api.get<RuleSettings>("/rules")
|
||||||
}, []);
|
.then((r) => {
|
||||||
|
setS(r.data);
|
||||||
|
setLoadError(null);
|
||||||
|
})
|
||||||
|
.catch((e: any) => {
|
||||||
|
setS(null);
|
||||||
|
setLoadError(String(e?.response?.data || e?.message || t("rulesLoadFailed")));
|
||||||
|
});
|
||||||
|
}, [t]);
|
||||||
|
|
||||||
const save = async () => {
|
const save = async () => {
|
||||||
if (!s) return;
|
if (!s) return;
|
||||||
@@ -39,7 +48,16 @@ export default function RulesSettingsCard() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!s) return null;
|
if (!s) {
|
||||||
|
return (
|
||||||
|
<Paper sx={{ mt: 2, p: 2 }}>
|
||||||
|
<Typography variant="h6" sx={{ mb: 1 }}>
|
||||||
|
{t("rulesTitle")}
|
||||||
|
</Typography>
|
||||||
|
{loadError ? <Alert severity="error">{loadError}</Alert> : <Typography sx={{ color: "text.secondary" }}>{t("rulesLoading")}</Typography>}
|
||||||
|
</Paper>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const num = (k: keyof RuleSettings) => ({
|
const num = (k: keyof RuleSettings) => ({
|
||||||
value: s[k],
|
value: s[k],
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ function TabPanel({ value, index, children }: { value: number; index: number; ch
|
|||||||
return <Box sx={{ mt: 2 }}>{children}</Box>;
|
return <Box sx={{ mt: 2 }}>{children}</Box>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ACCENTS = ["#15803d", "#16a34a", "#22c55e", "#0f766e", "#0f766e", "#65a30d"];
|
const ACCENTS = ["#15803d", "#16a34a", "#22c55e", "#0f766e", "#2563eb", "#65a30d"];
|
||||||
|
|
||||||
export default function SettingsView({
|
export default function SettingsView({
|
||||||
pageSize,
|
pageSize,
|
||||||
@@ -221,9 +221,24 @@ export default function SettingsView({
|
|||||||
<TabPanel value={tab} index={2}>
|
<TabPanel value={tab} index={2}>
|
||||||
<Paper sx={{ p: 2, mt: 2 }}>
|
<Paper sx={{ p: 2, mt: 2 }}>
|
||||||
<Typography sx={{ fontWeight: 950, mb: 0.5 }}>{t("settingsNotificationsTitle")}</Typography>
|
<Typography sx={{ fontWeight: 950, mb: 0.5 }}>{t("settingsNotificationsTitle")}</Typography>
|
||||||
<Typography sx={{ color: "text.secondary" }}>
|
<Typography sx={{ color: "text.secondary", mb: 2 }}>
|
||||||
{t("settingsNotificationsBody")}
|
{t("settingsNotificationsBody")}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
|
<Box sx={{ display: "grid", gridTemplateColumns: { xs: "1fr", md: "1fr 1fr" }, gap: 2 }}>
|
||||||
|
<Paper sx={{ p: 2, borderRadius: 3 }}>
|
||||||
|
<Typography sx={{ fontWeight: 800, mb: 0.5 }}>{t("settingsNotificationsFollowUpsTitle")}</Typography>
|
||||||
|
<Typography variant="body2" sx={{ color: "text.secondary" }}>{t("settingsNotificationsFollowUpsBody")}</Typography>
|
||||||
|
</Paper>
|
||||||
|
<Paper sx={{ p: 2, borderRadius: 3 }}>
|
||||||
|
<Typography sx={{ fontWeight: 800, mb: 0.5 }}>{t("settingsNotificationsAccountTitle")}</Typography>
|
||||||
|
<Typography variant="body2" sx={{ color: "text.secondary" }}>{t("settingsNotificationsAccountBody")}</Typography>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Typography variant="caption" sx={{ color: "text.secondary", display: "block", mt: 2 }}>
|
||||||
|
{t("settingsNotificationsDeliveryNote")}
|
||||||
|
</Typography>
|
||||||
</Paper>
|
</Paper>
|
||||||
</TabPanel>
|
</TabPanel>
|
||||||
|
|
||||||
|
|||||||
@@ -146,7 +146,12 @@ export const translations = {
|
|||||||
settingsColumnDays: "Days",
|
settingsColumnDays: "Days",
|
||||||
settingsColumnJobUrl: "Job URL",
|
settingsColumnJobUrl: "Job URL",
|
||||||
settingsNotificationsTitle: "Email notifications",
|
settingsNotificationsTitle: "Email notifications",
|
||||||
settingsNotificationsBody: "Notifications are sent via SMTP (Gmail works). Configure SMTP in the API (`Email:*` settings or env vars like `EMAIL_SMTP_HOST`).",
|
settingsNotificationsBody: "Choose how follow-up and account emails are delivered.",
|
||||||
|
settingsNotificationsFollowUpsTitle: "Follow-up reminders",
|
||||||
|
settingsNotificationsFollowUpsBody: "Reminder and ghosting emails use the server SMTP configuration. Delivery follows the timing rules from the Follow-ups tab.",
|
||||||
|
settingsNotificationsAccountTitle: "Account and security emails",
|
||||||
|
settingsNotificationsAccountBody: "Password resets and other account notices are also sent from the system mailer so delivery stays reliable even if no personal mailbox is linked.",
|
||||||
|
settingsNotificationsDeliveryNote: "Per-user mailboxes are not selectable yet; the current behavior is one system sender for notifications and reset flows.",
|
||||||
profileTitle: "Profile",
|
profileTitle: "Profile",
|
||||||
profileHeadlinePlaceholder: "Add a short headline to personalize your account view.",
|
profileHeadlinePlaceholder: "Add a short headline to personalize your account view.",
|
||||||
profileLocalAccount: "Local account",
|
profileLocalAccount: "Local account",
|
||||||
@@ -567,6 +572,12 @@ export const translations = {
|
|||||||
createAccount: "Create account",
|
createAccount: "Create account",
|
||||||
signedIn: "Signed in.",
|
signedIn: "Signed in.",
|
||||||
loginFailed: "Login failed.",
|
loginFailed: "Login failed.",
|
||||||
|
rememberMe: "Remember me on this device",
|
||||||
|
forgotPassword: "Forgot password?",
|
||||||
|
loginResetEmailRequired: "Enter your email first so we know where to send the reset link.",
|
||||||
|
loginRequestingReset: "Sending reset link…",
|
||||||
|
loginResetRequested: "If that account exists, a reset link has been sent.",
|
||||||
|
loginResetRequestFailed: "Could not request a password reset.",
|
||||||
resetPasswordTitle: "Reset password",
|
resetPasswordTitle: "Reset password",
|
||||||
resetPasswordBody: "Set a new password for your account.",
|
resetPasswordBody: "Set a new password for your account.",
|
||||||
missingResetLinkInfo: "Missing email/token in link.",
|
missingResetLinkInfo: "Missing email/token in link.",
|
||||||
@@ -801,7 +812,9 @@ export const translations = {
|
|||||||
jobDetailsNoHistory: "No history yet.",
|
jobDetailsNoHistory: "No history yet.",
|
||||||
jobDetailsNothingHighlighted: "Nothing highlighted yet.",
|
jobDetailsNothingHighlighted: "Nothing highlighted yet.",
|
||||||
rulesTitle: "Follow-up + Ghosting Rules",
|
rulesTitle: "Follow-up + Ghosting Rules",
|
||||||
rulesBody: "Jobs get a “Follow up” flag based on these thresholds. Ghosting is automatic.",
|
rulesBody: "Set how long to wait before a follow-up is due and when a thread should be treated as ghosted.",
|
||||||
|
rulesLoading: "Loading your follow-up settings…",
|
||||||
|
rulesLoadFailed: "Could not load your follow-up settings.",
|
||||||
rulesAppliedFollowUpDays: "Applied: follow-up days",
|
rulesAppliedFollowUpDays: "Applied: follow-up days",
|
||||||
rulesAppliedGhostDays: "Applied: ghost days",
|
rulesAppliedGhostDays: "Applied: ghost days",
|
||||||
rulesOfferFollowUpDays: "Offer: follow-up days",
|
rulesOfferFollowUpDays: "Offer: follow-up days",
|
||||||
@@ -957,7 +970,12 @@ export const translations = {
|
|||||||
settingsColumnDays: "Dager",
|
settingsColumnDays: "Dager",
|
||||||
settingsColumnJobUrl: "Jobb-URL",
|
settingsColumnJobUrl: "Jobb-URL",
|
||||||
settingsNotificationsTitle: "E-postvarsler",
|
settingsNotificationsTitle: "E-postvarsler",
|
||||||
settingsNotificationsBody: "Varsler sendes via SMTP (Gmail fungerer). Konfigurer SMTP i API-et (`Email:*`-innstillinger eller miljøvariabler som `EMAIL_SMTP_HOST`).",
|
settingsNotificationsBody: "Velg hvordan oppfølgings- og kontovarsler leveres.",
|
||||||
|
settingsNotificationsFollowUpsTitle: "Oppfølgingspåminnelser",
|
||||||
|
settingsNotificationsFollowUpsBody: "Påminnelser og ghosting-e-poster bruker serverens SMTP-oppsett. Leveringen følger tidsreglene på fanen Oppfølging.",
|
||||||
|
settingsNotificationsAccountTitle: "Konto- og sikkerhetsmailer",
|
||||||
|
settingsNotificationsAccountBody: "Tilbakestilling av passord og andre kontovarsler sendes også fra systemets avsender, slik at leveringen er stabil selv uten en personlig postkasse koblet til.",
|
||||||
|
settingsNotificationsDeliveryNote: "Per-bruker avsendere kan ikke velges ennå; i dag brukes én systemavsender for varsler og tilbakestilling av passord.",
|
||||||
profileTitle: "Profil",
|
profileTitle: "Profil",
|
||||||
profileHeadlinePlaceholder: "Legg til en kort overskrift for å gjøre kontovisningen mer personlig.",
|
profileHeadlinePlaceholder: "Legg til en kort overskrift for å gjøre kontovisningen mer personlig.",
|
||||||
profileLocalAccount: "Lokal konto",
|
profileLocalAccount: "Lokal konto",
|
||||||
@@ -1378,6 +1396,12 @@ export const translations = {
|
|||||||
createAccount: "Opprett konto",
|
createAccount: "Opprett konto",
|
||||||
signedIn: "Logget inn.",
|
signedIn: "Logget inn.",
|
||||||
loginFailed: "Innlogging mislyktes.",
|
loginFailed: "Innlogging mislyktes.",
|
||||||
|
rememberMe: "Husk meg på denne enheten",
|
||||||
|
forgotPassword: "Glemt passord?",
|
||||||
|
loginResetEmailRequired: "Skriv inn e-postadressen først, så vet vi hvor vi skal sende lenken.",
|
||||||
|
loginRequestingReset: "Sender tilbakestillingslenke…",
|
||||||
|
loginResetRequested: "Hvis kontoen finnes, er en tilbakestillingslenke sendt.",
|
||||||
|
loginResetRequestFailed: "Kunne ikke be om tilbakestilling av passord.",
|
||||||
resetPasswordTitle: "Tilbakestill passord",
|
resetPasswordTitle: "Tilbakestill passord",
|
||||||
resetPasswordBody: "Sett et nytt passord for kontoen din.",
|
resetPasswordBody: "Sett et nytt passord for kontoen din.",
|
||||||
missingResetLinkInfo: "Mangler e-post/token i lenken.",
|
missingResetLinkInfo: "Mangler e-post/token i lenken.",
|
||||||
@@ -1612,7 +1636,9 @@ export const translations = {
|
|||||||
jobDetailsNoHistory: "Ingen historikk ennå.",
|
jobDetailsNoHistory: "Ingen historikk ennå.",
|
||||||
jobDetailsNothingHighlighted: "Ingenting fremhevet ennå.",
|
jobDetailsNothingHighlighted: "Ingenting fremhevet ennå.",
|
||||||
rulesTitle: "Regler for oppfølging og ghosting",
|
rulesTitle: "Regler for oppfølging og ghosting",
|
||||||
rulesBody: "Jobber får et «Følg opp»-flagg basert på disse tersklene. Ghosting skjer automatisk.",
|
rulesBody: "Velg hvor lenge du vil vente før oppfølging forfaller, og når en tråd skal regnes som ghostet.",
|
||||||
|
rulesLoading: "Laster inn oppfølgingsinnstillingene dine…",
|
||||||
|
rulesLoadFailed: "Kunne ikke laste oppfølgingsinnstillingene dine.",
|
||||||
rulesAppliedFollowUpDays: "Søkt: oppfølgingsdager",
|
rulesAppliedFollowUpDays: "Søkt: oppfølgingsdager",
|
||||||
rulesAppliedGhostDays: "Søkt: ghostingdager",
|
rulesAppliedGhostDays: "Søkt: ghostingdager",
|
||||||
rulesOfferFollowUpDays: "Tilbud: oppfølgingsdager",
|
rulesOfferFollowUpDays: "Tilbud: oppfølgingsdager",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
import { Box, Button, Paper, Tab, Tabs, TextField, Typography } from "@mui/material";
|
import { Box, Button, Checkbox, FormControlLabel, Paper, Tab, Tabs, TextField, Typography } from "@mui/material";
|
||||||
|
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useLocation, useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
import { api } from "../api";
|
import { api } from "../api";
|
||||||
import { setAuthToken } from "../auth";
|
import { setAuthToken, setRememberMePref, getRememberMePref } from "../auth";
|
||||||
import GoogleAuthCard from "../components/GoogleAuthCard";
|
import GoogleAuthCard from "../components/GoogleAuthCard";
|
||||||
import { useToast } from "../toast";
|
import { useToast } from "../toast";
|
||||||
import { useI18n } from "../i18n/I18nProvider";
|
import { useI18n } from "../i18n/I18nProvider";
|
||||||
@@ -29,6 +29,8 @@ export default function LoginPage() {
|
|||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [password, setPassword] = useState("");
|
const [password, setPassword] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
const [rememberMe, setRememberMe] = useState(() => getRememberMePref());
|
||||||
|
const [requestingReset, setRequestingReset] = useState(false);
|
||||||
|
|
||||||
const nextPath = (location?.state?.from as string | undefined) ?? "/jobs";
|
const nextPath = (location?.state?.from as string | undefined) ?? "/jobs";
|
||||||
|
|
||||||
@@ -44,7 +46,8 @@ export default function LoginPage() {
|
|||||||
try {
|
try {
|
||||||
const url = mode === "register" ? "/auth/register" : "/auth/login";
|
const url = mode === "register" ? "/auth/register" : "/auth/login";
|
||||||
const res = await api.post<{ accessToken: string; tokenType: string }>(url, { email, password });
|
const res = await api.post<{ accessToken: string; tokenType: string }>(url, { email, password });
|
||||||
setAuthToken(res.data.accessToken);
|
setRememberMePref(rememberMe);
|
||||||
|
setAuthToken(res.data.accessToken, { remember: rememberMe });
|
||||||
toast(t("signedIn"), "success");
|
toast(t("signedIn"), "success");
|
||||||
navigate(nextPath, { replace: true });
|
navigate(nextPath, { replace: true });
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
@@ -55,6 +58,24 @@ export default function LoginPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function requestPasswordReset() {
|
||||||
|
if (!email.trim()) {
|
||||||
|
toast(t("loginResetEmailRequired"), "error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setRequestingReset(true);
|
||||||
|
try {
|
||||||
|
await api.post("/auth/request-password-reset", { email: email.trim() });
|
||||||
|
toast(t("loginResetRequested"), "success");
|
||||||
|
} catch (e: any) {
|
||||||
|
const msg = e?.response?.data || e?.message || t("loginResetRequestFailed");
|
||||||
|
toast(String(msg), "error");
|
||||||
|
} finally {
|
||||||
|
setRequestingReset(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const allowReg = cfg?.allowRegistration ?? false;
|
const allowReg = cfg?.allowRegistration ?? false;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -86,16 +107,25 @@ export default function LoginPage() {
|
|||||||
<Box component="form" onSubmit={(e) => { e.preventDefault(); void submit("login"); }} sx={{ display: "flex", flexDirection: "column", gap: 1.5 }}>
|
<Box component="form" onSubmit={(e) => { e.preventDefault(); void submit("login"); }} sx={{ display: "flex", flexDirection: "column", gap: 1.5 }}>
|
||||||
<TextField label={t("profileEmail")} value={email} onChange={(e) => setEmail(e.target.value)} autoComplete="email" fullWidth />
|
<TextField label={t("profileEmail")} value={email} onChange={(e) => setEmail(e.target.value)} autoComplete="email" fullWidth />
|
||||||
<TextField label={t("profileCurrentPassword")} value={password} onChange={(e) => setPassword(e.target.value)} autoComplete={allowReg ? "new-password" : "current-password"} type="password" fullWidth />
|
<TextField label={t("profileCurrentPassword")} value={password} onChange={(e) => setPassword(e.target.value)} autoComplete={allowReg ? "new-password" : "current-password"} type="password" fullWidth />
|
||||||
|
<FormControlLabel
|
||||||
|
control={<Checkbox checked={rememberMe} onChange={(e) => setRememberMe(e.target.checked)} />}
|
||||||
|
label={t("rememberMe")}
|
||||||
|
/>
|
||||||
|
|
||||||
<Box sx={{ display: "flex", gap: 1, justifyContent: "flex-end", mt: 1 }}>
|
<Box sx={{ display: "flex", justifyContent: "space-between", alignItems: "center", gap: 1, flexWrap: "wrap", mt: 0.5 }}>
|
||||||
{allowReg && (
|
<Button type="button" variant="text" onClick={() => void requestPasswordReset()} disabled={loading || requestingReset}>
|
||||||
<Button type="button" variant="outlined" disabled={loading} onClick={() => void submit("register")}>
|
{requestingReset ? t("loginRequestingReset") : t("forgotPassword")}
|
||||||
{t("createAccount")}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
<Button type="submit" variant="contained" disabled={loading}>
|
|
||||||
{t("signInTitle")}
|
|
||||||
</Button>
|
</Button>
|
||||||
|
<Box sx={{ display: "flex", gap: 1, justifyContent: "flex-end" }}>
|
||||||
|
{allowReg && (
|
||||||
|
<Button type="button" variant="outlined" disabled={loading} onClick={() => void submit("register")}>
|
||||||
|
{t("createAccount")}
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
|
<Button type="submit" variant="contained" disabled={loading}>
|
||||||
|
{t("signInTitle")}
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,30 +1,31 @@
|
|||||||
import React, { useMemo, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
import { Box, Button, Paper, TextField, Typography } from "@mui/material";
|
import { Alert, Box, Button, Paper, TextField, Typography } from "@mui/material";
|
||||||
|
|
||||||
import { useLocation, useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
import { api } from "../api";
|
import { api } from "../api";
|
||||||
import { useToast } from "../toast";
|
import { useToast } from "../toast";
|
||||||
import { useI18n } from "../i18n/I18nProvider";
|
import { useI18n } from "../i18n/I18nProvider";
|
||||||
|
|
||||||
function useQuery() {
|
|
||||||
const { search } = useLocation();
|
|
||||||
return useMemo(() => new URLSearchParams(search), [search]);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ResetPasswordPage() {
|
export default function ResetPasswordPage() {
|
||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const q = useQuery();
|
|
||||||
|
|
||||||
const email = q.get("email") || "";
|
|
||||||
const token = q.get("token") || "";
|
|
||||||
|
|
||||||
|
const [email, setEmail] = useState("");
|
||||||
|
const [token, setToken] = useState("");
|
||||||
const [newPassword, setNewPassword] = useState("");
|
const [newPassword, setNewPassword] = useState("");
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const params = new URLSearchParams(window.location.search);
|
||||||
|
setEmail(params.get("email") || "");
|
||||||
|
setToken(params.get("token") || "");
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const missingResetInfo = !email || !token;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@@ -49,7 +50,7 @@ export default function ResetPasswordPage() {
|
|||||||
component="form"
|
component="form"
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (!email || !token) {
|
if (missingResetInfo) {
|
||||||
toast(t("missingResetLinkInfo"), "error");
|
toast(t("missingResetLinkInfo"), "error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -68,14 +69,15 @@ export default function ResetPasswordPage() {
|
|||||||
}}
|
}}
|
||||||
sx={{ display: "flex", flexDirection: "column", gap: 1.5 }}
|
sx={{ display: "flex", flexDirection: "column", gap: 1.5 }}
|
||||||
>
|
>
|
||||||
<TextField label={t("profileEmail")} value={email} disabled fullWidth />
|
{missingResetInfo ? <Alert severity="warning">{t("missingResetLinkInfo")}</Alert> : null}
|
||||||
|
<TextField label={t("profileEmail")} value={email} onChange={(e) => setEmail(e.target.value)} disabled={!missingResetInfo} fullWidth />
|
||||||
<TextField label={t("profileNewPassword")} type="password" value={newPassword} onChange={(e) => setNewPassword(e.target.value)} fullWidth />
|
<TextField label={t("profileNewPassword")} type="password" value={newPassword} onChange={(e) => setNewPassword(e.target.value)} fullWidth />
|
||||||
|
|
||||||
<Box sx={{ display: "flex", justifyContent: "flex-end", gap: 1, mt: 1 }}>
|
<Box sx={{ display: "flex", justifyContent: "flex-end", gap: 1, mt: 1 }}>
|
||||||
<Button type="button" variant="outlined" onClick={() => navigate("/login")} disabled={loading}>
|
<Button type="button" variant="outlined" onClick={() => navigate("/login")} disabled={loading}>
|
||||||
{t("backToLogin")}
|
{t("backToLogin")}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit" variant="contained" disabled={loading}>
|
<Button type="submit" variant="contained" disabled={loading || missingResetInfo}>
|
||||||
{t("updatePassword")}
|
{t("updatePassword")}
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -260,6 +260,12 @@ export const getTheme = (_mode: "light" | "dark", accentColor: string) => {
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
MuiTextField: {
|
||||||
|
defaultProps: {
|
||||||
|
size: "small",
|
||||||
|
variant: "outlined",
|
||||||
|
},
|
||||||
|
},
|
||||||
MuiOutlinedInput: {
|
MuiOutlinedInput: {
|
||||||
defaultProps: { size: "small" },
|
defaultProps: { size: "small" },
|
||||||
styleOverrides: {
|
styleOverrides: {
|
||||||
@@ -269,6 +275,9 @@ export const getTheme = (_mode: "light" | "dark", accentColor: string) => {
|
|||||||
background: theme.vars.palette.background.default,
|
background: theme.vars.palette.background.default,
|
||||||
paddingLeft: 10,
|
paddingLeft: 10,
|
||||||
paddingRight: 10,
|
paddingRight: 10,
|
||||||
|
minHeight: 42,
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
"&.Mui-disabled": {
|
"&.Mui-disabled": {
|
||||||
cursor: "not-allowed",
|
cursor: "not-allowed",
|
||||||
input: { cursor: "not-allowed" },
|
input: { cursor: "not-allowed" },
|
||||||
@@ -279,13 +288,16 @@ export const getTheme = (_mode: "light" | "dark", accentColor: string) => {
|
|||||||
multiline: {
|
multiline: {
|
||||||
padding: 10,
|
padding: 10,
|
||||||
alignItems: "flex-start",
|
alignItems: "flex-start",
|
||||||
|
minHeight: "unset",
|
||||||
},
|
},
|
||||||
input: {
|
input: {
|
||||||
paddingLeft: 0,
|
paddingLeft: 0,
|
||||||
paddingRight: 0,
|
paddingRight: 0,
|
||||||
paddingTop: 10,
|
paddingTop: 9,
|
||||||
paddingBottom: 10,
|
paddingBottom: 9,
|
||||||
lineHeight: 1.45,
|
lineHeight: 1.45,
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
inputMultiline: {
|
inputMultiline: {
|
||||||
paddingTop: 0,
|
paddingTop: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user