Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions context/Auth/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 }));
})
Expand Down
26 changes: 13 additions & 13 deletions layout/Attendee/Profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ interface Course {
function Profile() {
const { user, editUser } = useAuth() as {
user: IAttendee;
editUser: (username: FormData) => void;
editUser: (formData: 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<Course[]>([{ id: "", name: "None" }]);

Expand Down Expand Up @@ -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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this though... How is this coded in the backend? Please get back to me about this

formData.append("attendee[course_id]", course);
formData.append("attendee[avatar]", avatar);

Expand Down Expand Up @@ -151,23 +151,23 @@ function Profile() {

<div className="w-full sm:w-96">
<Input
text="NAME"
id="name"
name="name"
value={user.name || ""}
text="NICKNAME"
id="nickname"
name="nickname"
value={user.nickname}
bgColor="primary"
fgColor="white"
enabled={false}
/>
<Input
text="USERNAME"
id="username"
name="username"
value={username}
text="NAME"
id="name"
name="name"
value={name}
bgColor="primary"
fgColor="white"
enabled={editing}
onChange={(e) => setUsername(e.currentTarget.value)}
onChange={(e) => setName(e.currentTarget.value)}
/>
<Select
text="COURSE"
Expand Down
52 changes: 26 additions & 26 deletions layout/SignUp/components/SignUpForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function SignUpForm({ courses }) {

const validateNickname = (nickname) => {
return (
nickname.length >= 2 &&
nickname.length >= 3 &&
nickname.length <= 15 &&
nickname.match(/^[\w\d-_]{3,15}$/)
);
Expand All @@ -57,7 +57,7 @@ export default function SignUpForm({ courses }) {
updateError("You must have a scanned QR code");
} else if (!validateNickname(nickname)) {
updateError(
"Your nickname must be between 2 and 15 alphanumeric characters and can only contain underscores and dashes"
"Your nickname must be between 3 and 15 alphanumeric characters, underscores and dashes (no spaces allowed)"
);
} else if (!validatePassword(password)) {
updateError("Your password must be at least 8 characters long");
Expand All @@ -81,14 +81,6 @@ export default function SignUpForm({ courses }) {
return (
<>
<Form onSubmit={onFinish}>
<Input
text="NAME"
id="name"
name="name"
fgColor="white"
bgColor="primary"
onChange={(e) => updateName(e.currentTarget.value)}
/>
<Input
text="EMAIL"
id="email"
Expand All @@ -99,6 +91,22 @@ export default function SignUpForm({ courses }) {
bgColor="primary"
onChange={(e) => updateEmail(e.currentTarget.value)}
/>
<PasswordInput
text="PASSWORD"
id="password"
name="password"
fgColor="white"
bgColor="primary"
onChange={(e) => updatePassword(e.currentTarget.value)}
/>
<PasswordInput
text="CONFIRM PASSWORD"
id="confirm"
name="confirm"
fgColor="white"
bgColor="primary"
onChange={(e) => updatePasswordConfirmation(e.currentTarget.value)}
/>
<Input
text="NICKNAME"
id="nickname"
Expand All @@ -107,6 +115,14 @@ export default function SignUpForm({ courses }) {
bgColor="primary"
onChange={(e) => updateNickname(e.currentTarget.value)}
/>
<Input
text="NAME"
id="name"
name="name"
fgColor="white"
bgColor="primary"
onChange={(e) => updateName(e.currentTarget.value)}
/>
<Select
text="COURSE"
id="course"
Expand All @@ -119,22 +135,6 @@ export default function SignUpForm({ courses }) {
}))}
onChange={(e) => updateCourse(e.currentTarget.value)}
/>
<PasswordInput
text="PASSWORD"
id="password"
name="password"
fgColor="white"
bgColor="primary"
onChange={(e) => updatePassword(e.currentTarget.value)}
/>
<PasswordInput
text="CONFIRM PASSWORD"
id="confirm"
name="confirm"
fgColor="white"
bgColor="primary"
onChange={(e) => updatePasswordConfirmation(e.currentTarget.value)}
/>
<Button
title={scanning ? "STOP SCANNING" : "SCAN QR"}
className="h-12 w-full border-quinary bg-quinary text-secondary"
Expand Down