tahamajs/IE / Projects /front /src /components /profile /EditProfileWindow.tsx
tahamajs's picture
download
raw
2.76 kB
import { useState } from "react";
import { useAuth } from "@/context/AuthContext";
import { useProfile } from "@/hooks/useProfile";
import { GlassCard } from "@/components/ui/GlassCard";
import { Save, X } from "lucide-react";
import { toast } from "react-toastify";
import api from "@/api/client";
export function EditProfileWindow() {
const { user } = useAuth();
const { profile, refetch } = useProfile(user?.username);
const [fullName, setFullName] = useState(profile?.fullName || "");
const [bio, setBio] = useState(profile?.bio || "");
const [affiliation, setAffiliation] = useState(profile?.affiliation || "");
const [website, setWebsite] = useState(profile?.website || "");
const [loading, setLoading] = useState(false);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setLoading(true);
try {
await api.put("/users/me", { fullName, bio, affiliation, website });
toast.success("Profile updated");
refetch();
} catch (err) {
toast.error("Update failed");
} finally {
setLoading(false);
}
};
return (
<GlassCard className="p-6 max-w-md mx-auto">
<h2 className="text-xl font-bold mb-4">Edit Profile</h2>
<form onSubmit={handleSubmit} className="space-y-4">
<div>
<label className="block text-sm mb-1">Full Name</label>
<input type="text" value={fullName} onChange={(e) => setFullName(e.target.value)} className="w-full p-2 glass-card rounded-lg" />
</div>
<div>
<label className="block text-sm mb-1">Bio</label>
<textarea rows={3} value={bio} onChange={(e) => setBio(e.target.value)} className="w-full p-2 glass-card rounded-lg" />
</div>
<div>
<label className="block text-sm mb-1">Affiliation</label>
<input type="text" value={affiliation} onChange={(e) => setAffiliation(e.target.value)} className="w-full p-2 glass-card rounded-lg" />
</div>
<div>
<label className="block text-sm mb-1">Website</label>
<input type="url" value={website} onChange={(e) => setWebsite(e.target.value)} className="w-full p-2 glass-card rounded-lg" />
</div>
<div className="flex gap-2">
<button type="submit" disabled={loading} className="flex-1 btn-primary flex items-center justify-center gap-2">
{loading ? "Saving..." : <Save className="w-4 h-4" />} Save
</button>
<button
type="button"
onClick={() => window.dispatchEvent(new CustomEvent("closeWindow", { detail: { app: "edit-profile" } }))}
className="btn-secondary"
>
Cancel
</button>
</div>
</form>
</GlassCard>
);
}

Xet Storage Details

Size:
2.76 kB
·
Xet hash:
7a0d827a49b72662b3b4a3b6374713a19e70dbef06348bee29cf2d16f637f94b

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.