final user account polish
This commit is contained in:
parent
d05dc3eab6
commit
0cbeca833f
1 changed files with 13 additions and 7 deletions
|
|
@ -24,7 +24,7 @@ export default function ProfileEditor({
|
||||||
const [first_name, setFirst] = useState("");
|
const [first_name, setFirst] = useState("");
|
||||||
const [last_name, setLast] = useState("");
|
const [last_name, setLast] = useState("");
|
||||||
const [email, setEmail] = useState("");
|
const [email, setEmail] = useState("");
|
||||||
const [location, setLocation] = useState("");
|
const [profileLocation, setProfileLocation] = useState(""); // renamed to avoid shadowing window.location
|
||||||
const [msg, setMsg] = useState<string | null>(null);
|
const [msg, setMsg] = useState<string | null>(null);
|
||||||
const [busy, setBusy] = useState(false);
|
const [busy, setBusy] = useState(false);
|
||||||
const [loading, setLoading] = useState(!meProp);
|
const [loading, setLoading] = useState(!meProp);
|
||||||
|
|
@ -58,7 +58,7 @@ export default function ProfileEditor({
|
||||||
setFirst(me.first_name || "");
|
setFirst(me.first_name || "");
|
||||||
setLast(me.last_name || "");
|
setLast(me.last_name || "");
|
||||||
setEmail(me.email || "");
|
setEmail(me.email || "");
|
||||||
setLocation(me.location || "");
|
setProfileLocation(me.location || "");
|
||||||
}, [me]);
|
}, [me]);
|
||||||
|
|
||||||
const onSave = async () => {
|
const onSave = async () => {
|
||||||
|
|
@ -69,7 +69,7 @@ export default function ProfileEditor({
|
||||||
first_name: first_name.trim(),
|
first_name: first_name.trim(),
|
||||||
last_name: last_name.trim(),
|
last_name: last_name.trim(),
|
||||||
email: email.trim() || null, // allow clearing email
|
email: email.trim() || null, // allow clearing email
|
||||||
location: location.trim(),
|
location: profileLocation.trim(),
|
||||||
};
|
};
|
||||||
const r = await fetch("/api/account/profile", {
|
const r = await fetch("/api/account/profile", {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
|
|
@ -78,11 +78,17 @@ export default function ProfileEditor({
|
||||||
});
|
});
|
||||||
if (r.status === 428) {
|
if (r.status === 428) {
|
||||||
// Need reauth for sensitive change (email)
|
// Need reauth for sensitive change (email)
|
||||||
location.assign(`/auth/sign-in?reauth=1&next=${encodeURIComponent(nextAccount + "#security")}`);
|
if (typeof window !== "undefined") {
|
||||||
|
window.location.assign(
|
||||||
|
`/auth/sign-in?reauth=1&next=${encodeURIComponent(nextAccount + "#security")}`
|
||||||
|
);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (r.status === 401) {
|
if (r.status === 401) {
|
||||||
location.assign(`/auth/sign-in?reauth=1&next=${encodeURIComponent(nextAccount)}`);
|
if (typeof window !== "undefined") {
|
||||||
|
window.location.assign(`/auth/sign-in?reauth=1&next=${encodeURIComponent(nextAccount)}`);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const j = await r.json().catch(() => ({}));
|
const j = await r.json().catch(() => ({}));
|
||||||
|
|
@ -139,8 +145,8 @@ export default function ProfileEditor({
|
||||||
<span className="opacity-60">Location</span>
|
<span className="opacity-60">Location</span>
|
||||||
<input
|
<input
|
||||||
className="rounded-md border px-2 py-1"
|
className="rounded-md border px-2 py-1"
|
||||||
value={location}
|
value={profileLocation}
|
||||||
onChange={(e) => setLocation(e.target.value)}
|
onChange={(e) => setProfileLocation(e.target.value)}
|
||||||
placeholder="City, Country"
|
placeholder="City, Country"
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue