MCPcopy Create free account
hub / github.com/Bitbox-Connect/Bitbox / EditProfile

Function EditProfile

client/src/component/EditProfile.jsx:10–223  ·  view source on GitHub ↗
(props)

Source from the content-addressed store, hash-verified

8import "../css/EditProfile.css";
9
10const EditProfile = (props) => {
11 const VITE_SERVER_PORT = import.meta.env.VITE_SERVER_PORT || "https://bitbox-uxbo.onrender.com";
12
13 const [profile, setProfile] = useState({
14 name: "",
15 college: "",
16 phone: "",
17 address: "",
18 });
19
20 const handleKeyDown = (e) => {
21 if (e.key === "Enter") {
22 e.preventDefault();
23 handleClick();
24 }
25 };
26
27 const onChange = (e) => {
28 setProfile({ ...profile, [e.target.name]: e.target.value });
29 };
30 const handleClick = async () => {
31 try {
32 const token = localStorage.getItem("token");
33
34 const config = {
35 headers: {
36 "auth-token": token,
37 },
38 };
39
40 // Update the user profile
41 const updateProfileResponse = await axios.put(
42 `${VITE_SERVER_PORT}/api/profile/updateprofile`,
43 {
44 name: profile.name,
45 college: profile.college,
46 phone: profile.phone,
47 address: profile.address,
48 },
49 config // Pass the config with headers
50 );
51
52 if (updateProfileResponse.status === 200) {
53 console.log("Profile updated:", updateProfileResponse.data);
54
55 // Reset the profile form after updating
56 setProfile({ name: "", college: "", phone: "", address: "" });
57
58 // If there's a file selected (for avatar), upload it
59 if (file) {
60 const reader = new FileReader();
61 reader.onloadend = () => {
62 const imageData = reader.result;
63 axios
64 .post(
65 `${VITE_SERVER_PORT}/uploadAvatarImage`,
66 { image: imageData },
67 config // Pass the config with headers for image upload

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected