From 513f23311243a271a5c35f0ea113c0c5a9289624 Mon Sep 17 00:00:00 2001 From: tiago-bacelar Date: Tue, 6 Feb 2024 01:29:26 +0000 Subject: [PATCH 1/3] Fix edit profile --- context/Auth/AuthContext.tsx | 6 +-- layout/Attendee/Profile/Profile.tsx | 26 +++++----- layout/SignUp/components/SignUpForm/index.tsx | 52 +++++++++---------- 3 files changed, 42 insertions(+), 42 deletions(-) diff --git a/context/Auth/AuthContext.tsx b/context/Auth/AuthContext.tsx index 492e84a2..8fddf54e 100644 --- a/context/Auth/AuthContext.tsx +++ b/context/Auth/AuthContext.tsx @@ -192,7 +192,7 @@ export function AuthProvider({ children }) { }) .catch((errors) => { if (errors.response?.data?.error) { - setErrors(errors.response.data.error); + setErrors("Invalid email or password"); //errors.response.data.error } else if (errors.response) { setErrors("Request denied by the server"); } else if (errors.request) { @@ -216,11 +216,11 @@ export function AuthProvider({ children }) { router.push("/").finally(() => setUser(null)); } - function editUser(nickname) { + function editUser(formData: FormData) { setLoading(true); api - .editUser(user.id, nickname) + .editUser(user.id, formData) .then((at) => { setUser((oldUser) => ({ ...oldUser, ...at })); }) diff --git a/layout/Attendee/Profile/Profile.tsx b/layout/Attendee/Profile/Profile.tsx index 404030f0..05290179 100644 --- a/layout/Attendee/Profile/Profile.tsx +++ b/layout/Attendee/Profile/Profile.tsx @@ -24,12 +24,12 @@ interface Course { function Profile() { const { user, editUser } = useAuth() as { user: IAttendee; - editUser: (username: FormData) => void; + editUser: (zz: FormData) => void; }; const [avatar, setAvatar] = useState(null); const [editing, setEditing] = useState(false); - const [username, setUsername] = useState(user.nickname || ""); - const [course, setCourse] = useState(user.course.toString() || ""); + const [name, setName] = useState(user.name); + const [course, setCourse] = useState(user.course.toString()); const [courses, setCourses] = useState([{ id: "", name: "None" }]); @@ -72,7 +72,7 @@ function Profile() { const handleSubmitForm = (e: React.FormEvent) => { e.preventDefault(); const formData = new FormData(); - formData.append("attendee[nickname]", username); + formData.append("attendee[name]", name); formData.append("attendee[course_id]", course); formData.append("attendee[avatar]", avatar); @@ -151,23 +151,23 @@ function Profile() {
setUsername(e.currentTarget.value)} + onChange={(e) => setName(e.currentTarget.value)} /> updateName(e.currentTarget.value)} - /> updateEmail(e.currentTarget.value)} /> + updatePassword(e.currentTarget.value)} + /> + updatePasswordConfirmation(e.currentTarget.value)} + /> updateNickname(e.currentTarget.value)} /> + updateName(e.currentTarget.value)} + />