-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from team-Ollie/17-feature-Signup-API
17 feature signup api
- Loading branch information
Showing
9 changed files
with
379 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import client from "./client"; | ||
|
||
export const SignIn = async (userData: { | ||
loginId: string; | ||
password: string; | ||
}) => { | ||
try { | ||
const response = await client.post( | ||
"/users/login", | ||
{ | ||
loginId: userData.loginId, | ||
password: userData.password, | ||
}, | ||
{ | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}, | ||
); | ||
return response.data; | ||
} catch (error) { | ||
if (error.response) { | ||
// 200 이외 | ||
console.error("서버 응답 오류:", error.response.data); | ||
} else if (error.request) { | ||
// 요청이 전송되었으나 응답을 받지 못한 경우 | ||
console.error("응답 없음:", error.request); | ||
} else { | ||
// 요청을 설정하는 도중에 발생한 오류 | ||
console.error("요청 설정 오류:", error.message); | ||
} | ||
throw error; | ||
} | ||
}; | ||
|
||
export interface userProps { | ||
loginId: string; | ||
password: string; | ||
nickname: string; | ||
identifier: string; | ||
centerIdx: number; | ||
} | ||
|
||
export const SignUp = async (userData: userProps) => { | ||
try { | ||
const response = await client.post("/users/signup", { | ||
loginId: userData.loginId, | ||
password: userData.password, | ||
nickname: userData.nickname, | ||
identifier: userData.identifier, | ||
centerIdx: userData.centerIdx, | ||
}); | ||
return response.data; | ||
} catch (error) { | ||
if (error.response) { | ||
console.error(); | ||
} | ||
throw error; | ||
} | ||
}; | ||
|
||
export type centerProps = { | ||
centerIdx: number; | ||
name: string; | ||
}; | ||
|
||
export interface getCenterListBody { | ||
ceterList: centerProps[]; | ||
} | ||
|
||
export const getCenterList = async () => { | ||
try { | ||
const response = await client.get("/users/signupView"); | ||
return response.data.result.ceterList; | ||
} catch (error) { | ||
if (error.response) { | ||
console.error(error.response); | ||
} | ||
throw error; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useQuery, useMutation } from "@tanstack/react-query"; | ||
import { SignUp, getCenterList, userProps } from "../auth"; | ||
import { useRouter } from "next/router"; | ||
|
||
function useGetCenterList() { | ||
const { data } = useQuery({ | ||
queryKey: ["getCenterList"], | ||
queryFn: getCenterList, | ||
}); | ||
return { data }; | ||
} | ||
|
||
function useSignUp(userData: userProps) { | ||
const router = useRouter(); | ||
|
||
const { mutate } = useMutation({ | ||
mutationKey: ["signUp"], | ||
mutationFn: () => SignUp(userData), | ||
onSuccess: () => { | ||
router.push("/login"); | ||
}, | ||
onError: (error: Error) => { | ||
window.alert("다시 회원가입해주세요."); | ||
router.push("/main"); | ||
}, | ||
}); | ||
|
||
return { mutate }; | ||
} | ||
|
||
export { useGetCenterList, useSignUp }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { ChangeEvent, HTMLInputTypeAttribute, forwardRef } from "react"; | ||
|
||
export interface TextInputProps { | ||
className?: string; | ||
value: string; | ||
isError?: boolean; | ||
errorText?: string; | ||
placeholder?: string; | ||
type?: HTMLInputTypeAttribute; | ||
name: string; | ||
onChange: (e: ChangeEvent<HTMLInputElement>) => void; | ||
maxLength?: number; | ||
} | ||
|
||
const AuthInput = forwardRef<HTMLInputElement, TextInputProps>( | ||
( | ||
{ | ||
className = "", | ||
value, | ||
isError, | ||
placeholder = "", | ||
errorText, | ||
type = "text", | ||
name, | ||
onChange, | ||
maxLength = 10, | ||
}, | ||
ref, | ||
) => { | ||
return ( | ||
<div className="w-full relative"> | ||
<div | ||
className={`${className} rounded-xl border border-solid ${ | ||
isError ? "border-red-500" : "border-semantic-grey-2" | ||
} rounded-lg p-2`} | ||
> | ||
<input | ||
type={type} | ||
name={name} | ||
className="w-full outline-none border-none h4 placeholder:text-grey-400 pl-1" | ||
value={value} | ||
onChange={onChange} | ||
placeholder={placeholder} | ||
maxLength={maxLength} | ||
required | ||
/> | ||
</div> | ||
{isError && ( | ||
<div className="text-red-500 h5 px-2 absolute">{errorText}</div> | ||
)} | ||
</div> | ||
); | ||
}, | ||
); | ||
|
||
export default AuthInput; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.