Skip to content

Commit

Permalink
feat: Implement registration form with name and major fields
Browse files Browse the repository at this point in the history
The code changes in this commit add support for a registration form with name and major fields. This allows users to provide their name and major when signing up. The form validation has also been updated to check for valid name and major inputs when the registration type is selected.

Recent user commits:
- Welcome 페이지에 모바일 이미지 대응
- @stomp/stompjs 패키지 삭제
- socketIO setting
- 인증코드 제출 시 이메일 포함
- 로그인, 회원가입 UI, 로직 구현. 기존 로직 삭제

Recent repository commits:
- Welcome 페이지에 모바일 이미지 대응
- @stomp/stompjs 패키지 삭제
- socketIO setting
- 인증코드 제출 시 이메일 포함
- 로그인, 회원가입 UI, 로직 구현. 기존 로직 삭제
- Merge pull request #28 from TeamSynergyy/20/feat
- refresh api 수정
- Merge branch '20/feat' of https://github.com/TeamSynergyy/synergy-web into 20/feat
- Welcome 페이지 생성
- 라우팅과 컴포넌트 개선
  • Loading branch information
yeoularu committed May 7, 2024
1 parent b5be92c commit db6d824
Showing 1 changed file with 58 additions and 16 deletions.
74 changes: 58 additions & 16 deletions src/pages/Auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ import { useDispatch } from "react-redux";

export default function Auth() {
const [type, toggle] = useToggle(["login", "register"]);
const host = import.meta.env.VITE_API_URL;

const form = useForm({
initialValues: {
email: "",
password: "",
name: "",
major: "",
// terms: true,
},

Expand All @@ -31,32 +35,45 @@ export default function Auth() {
val.length <= 6
? "Password should include at least 6 characters"
: null,
name: (val) =>
type === "register" && val.length < 1 ? "Invalid name" : null,
major: (val) =>
type === "register" && val.length < 1 ? "Invalid major" : null,
},
});

const navigate = useNavigate();
const dispatch = useDispatch();

const handleSignUp = async (email: string, password: string) => {
const handleSignUp = async (
email: string,
password: string,
name: string,
major: string
) => {
try {
await axios.post("/api/v1/auth/register", {
await axios.post(host + "/api/v1/users", {
email,
password,
name,
major,
});
navigate("/auth/code?email=" + email);
// navigate("/auth/code?email=" + email);

toggle();
} catch (error) {
console.error("Sign up error:", error);
}
};

const handleLogin = async (email: string, password: string) => {
try {
const response = await axios.post("/api/v1/auth/login", {
const response = await axios.post(host + "/api/v1/users/login", {
email,
password,
});

const accessToken = response.headers["access-token"];
const accessToken = response.headers["authorization"].split(" ")[1];
dispatch(setAccessToken(accessToken));
dispatch(setIsLogin(true));
navigate("/home");
Expand All @@ -73,9 +90,9 @@ export default function Auth() {
</Text>

<form
onSubmit={form.onSubmit(({ email, password }) => {
onSubmit={form.onSubmit(({ email, password, name, major }) => {
if (type === "register") {
handleSignUp(email, password);
handleSignUp(email, password, name, major);
} else {
handleLogin(email, password);
}
Expand Down Expand Up @@ -109,15 +126,40 @@ export default function Auth() {
radius="md"
/>

{/* {type === "register" && (
<Checkbox
label="I accept terms and conditions"
checked={form.values.terms}
onChange={(event) =>
form.setFieldValue("terms", event.currentTarget.checked)
}
/>
)} */}
{type === "register" && (
<>
<TextInput
required
label="이름"
placeholder="홍길동"
value={form.values.name}
onChange={(event) =>
form.setFieldValue("name", event.currentTarget.value)
}
error={form.errors.name && "Invalid name"}
radius="md"
/>
<TextInput
required
label="전공"
placeholder="컴퓨터공학과"
value={form.values.major}
onChange={(event) =>
form.setFieldValue("major", event.currentTarget.value)
}
error={form.errors.major && "Invalid major"}
radius="md"
/>
</>

// <Checkbox
// label="I accept terms and conditions"
// checked={form.values.terms}
// onChange={(event) =>
// form.setFieldValue("terms", event.currentTarget.checked)
// }
// />
)}
</Stack>

<Group position="apart" mt="xl">
Expand Down

0 comments on commit db6d824

Please sign in to comment.