Skip to content

Commit

Permalink
feat: get dsTag from form
Browse files Browse the repository at this point in the history
  • Loading branch information
JangAyeon committed Feb 23, 2024
1 parent 35b59e6 commit 855cb94
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
5 changes: 5 additions & 0 deletions apis/authApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,18 @@ const setSession = (data: object) =>
const getSession = () => supabaseClient.auth.getSession()

const getUserProfile = () => supabaseClient.auth.getUser()

const getDsIdValid = (dsId: FormDataEntryValue) =>
supabaseClient.from("23_final_user").select("*").eq("dsTag", dsId)

const authApi = {
signup,
login,
logout,
setSession,
getSession,
getUserProfile,
getDsIdValid,
}

export { authApi }
10 changes: 10 additions & 0 deletions components/forms/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ const SignupForm = () => {
isOpen: false,
})

const handleDsIdCheck = (e: any) => {
const signupForm = new FormData(e.target.form)
const dsId = signupForm.get("dsId")
console.log(dsId)
}

const handleModalOpen = (text: string, state: AuthModalProps["state"]) => {
// console.log("open")
setIsModalOpen({ state, text, isOpen: true })
Expand Down Expand Up @@ -130,6 +136,10 @@ const SignupForm = () => {
color={"--color-green-04"}
/>
<UnderLineInput {...item} key={idx} />

{item.name === "dsId" && (
<button onClick={(e) => handleDsIdCheck(e)}>이름 확인</button>
)}
</FormInputWrapper>
))}

Expand Down
25 changes: 19 additions & 6 deletions utils/formValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Dispatch, SetStateAction } from "react"

import { AuthModalProps } from "@/components/modal/AuthModal"

import { authApi } from "@/apis/authApi"

import { ILoginForm, ISignupForm } from "@/types/common/authProps"

const passwordCheck = (password: FormDataEntryValue | null) => {
console.log("비밀번호", password)
const password_format =
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,10}$/
/^[A-Za-z0-9`~!@#\$%\^&\*\(\)\{\}\[\]\-_=\+\\|;:'"<>,\./\?]{8,20}$/
//console.log("비밀번호", password, password_format.test(password as string))
if (!password) {
return "비밀번호를 입력하시오"
} else if (typeof password === "string" && !password_format.test(password)) {
Expand All @@ -16,17 +18,28 @@ const passwordCheck = (password: FormDataEntryValue | null) => {
}

const emailCheck = (email: FormDataEntryValue | null) => {
console.log("email", email)
const email_format =
/^([0-9a-zA-Z_\.-]+)@([0-9a-zA-Z_-]+)(\.[0-9a-zA-Z_-]+){1,2}$/
//console.log("email", email, email_format.test(email as string))
if (!email) {
return "이메일을 입력하시오"
} else if (typeof email === "string" && !email_format.test(email)) {
return "올바른 형식의 이메일을 입력하시오"
}
}

export const dsIdCheck = async (dsId: FormDataEntryValue | null) => {
if (dsId) {
const { data, error } = await authApi.getDsIdValid(dsId)
console.log("dsIdCheck", data)
if (error || !data) {
return "존재하지 않는 디스코드 아이디입니다"
}
}
}

const nameCheck = (name: FormDataEntryValue | null) => {
//console.log(name)
const name_format = /^.{2,8}$/
if (!name) {
return "이름을 입력하시오"
Expand All @@ -52,7 +65,7 @@ const LoginValidation = (
}
}

const SignUpValidation = (
const SignUpValidation = async (
form: ISignupForm,
setIsModalOpen: Dispatch<SetStateAction<AuthModalProps>>
) => {
Expand All @@ -66,8 +79,8 @@ const SignUpValidation = (

const isEmailValid = emailCheck(email)
const isPasswordValid = passwordCheck(password)
const isNameValid = passwordCheck(name)
console.log(isEmailValid, isPasswordValid, name, dsId)
const isNameValid = nameCheck(name)

if (isEmailValid) {
setIsModalOpen({ state: "fail", text: isEmailValid, isOpen: true })
} else if (isPasswordValid) {
Expand Down

0 comments on commit 855cb94

Please sign in to comment.