Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 추가 회원가입 custom hook(useCreateUser) #54

Merged
merged 9 commits into from
May 27, 2024
4 changes: 1 addition & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
NEXT_PUBLIC_API_URL=http://3.34.58.135:8080
NEXT_PUBLIC_LOCAL_URL=http://localhost:8080
NEXT_PUBLIC_API_KEY=bf46dcac98a9a9ce6a13a465fa86d0b2
NEXT_PUBLIC_REDIRECT_URL=http://3.34.58.135:3000
NEXT_PUBLIC_LOCAL_URL=http://localhost:8080/api
3 changes: 2 additions & 1 deletion src/apis/http.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import axios from "axios";
import { AxiosInstance, AxiosRequestConfig } from "axios";

const axiosInstance = axios.create({
baseURL: process.env.NEXT_PUBLIC_LOCAL_URL
baseURL: process.env.NEXT_PUBLIC_LOCAL_URL,
withCredentials: true
});

export interface HttpClient extends AxiosInstance {
Expand Down
5 changes: 3 additions & 2 deletions src/components/atoms/button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export interface ButtonProps {
height?: string;
fontSize?: string;
fontWeight?: string;
type?: "button" | "submit" | "reset" | undefined;
}

export function Button({ children, onClick, color = "#2b2b2b", backgroundColor = "#51F8C4", size = "lg", fontSize = "1rem", fontWeight = "700" }: ButtonProps) {
export function Button({ children, onClick, color = "#2b2b2b", backgroundColor = "#51F8C4", size = "lg", fontSize = "1rem", fontWeight = "700", type = "button" }: ButtonProps) {
const style: React.CSSProperties = {
color: color,
backgroundColor: backgroundColor,
fontSize: fontSize,
fontWeight: fontWeight,
};
return <div onClick={onClick} className={`btn ${size}`} style={style}>{children}</div>;
return <button onClick={onClick} className={`btn ${size}`} style={style} type={type}>{children}</button>;
}
5 changes: 4 additions & 1 deletion src/components/atoms/fileUpload/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import "./FileUpload.css";

export interface FileUploadProps {
children?: ReactNode;
name: string;
register: any;
}

export function FileUpload({ children }: FileUploadProps) {
export function FileUpload({ children, name, register }: FileUploadProps) {
interface imageState {
url?: string;
name?: string;
Expand Down Expand Up @@ -53,6 +55,7 @@ export function FileUpload({ children }: FileUploadProps) {
type="file"
accept="image/*"
onChange={handleImageChange}
{...register(name)}
multiple
/>
</>
Expand Down
23 changes: 13 additions & 10 deletions src/components/atoms/input/Input.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
"use client";

import React, { forwardRef, useState } from "react";
import { UseControllerProps, useController } from "react-hook-form";
import { forwardRef, useState } from "react";
import { UseControllerProps } from "react-hook-form";
import "./input.css";

export interface InputProps extends UseControllerProps{
placeholder?: string;
size?: 'sm' | 'md' | 'lg';
maxCnt?: number;
register: any;
value?: string | number;
}

export const Input = forwardRef<HTMLInputElement, InputProps>(
({ control, size = "lg", placeholder = "", maxCnt = 0, name = '', ...props }, ref) => {
({ register, size = "lg", placeholder = "", maxCnt = 0, name = '', value, ...props }, ref) => {
const [textCnt, setTextCnt] = useState(0);
const {
field,
fieldState: { error }
} = useController({ name, control });
// const {
// field,
// fieldState: { error }
// } = useController({ name, control });

const handleChangeInput = (e: React.ChangeEvent<HTMLInputElement>) => {
setTextCnt(e.target.value.length);
// field.onChange(e);
}

return (
<div className="input__wrapper">
<input
ref={ref}
type="text"
className={`input ${size}`}
placeholder={placeholder}
onChange={field.onChange}
value={field.value || ''}
onChange={handleChangeInput}
value={value}
maxLength={maxCnt !== 0 ? maxCnt : undefined}
name={name}
{...register(name)}
{...props}
/>
{maxCnt !== 0 && (
Expand Down
5 changes: 4 additions & 1 deletion src/components/atoms/textarea/Textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ export interface TextareaProps {
height?: string;
fontSize?: string;
maxCnt?: number;
name: string;
register: any;
}

export function Textarea({ backgroundColor = "#2B2B2B", color = "#fff", size = "big", height = "12rem", fontSize = "16px", content = "", maxCnt = 300 }: TextareaProps) {
export function Textarea({ backgroundColor = "#2B2B2B", color = "#fff", size = "big", height = "12rem", fontSize = "16px", content = "", maxCnt = 300, name, register }: TextareaProps) {
const [isFocused, setIsFocused] = useState(false);
const [textCnt, setTextCnt] = useState(0);
const style: React.CSSProperties = {
Expand Down Expand Up @@ -50,6 +52,7 @@ export function Textarea({ backgroundColor = "#2B2B2B", color = "#fff", size = "
onBlur={handleBlur}
onChange={handleTextCnt}
maxLength={maxCnt}
{...register(name)}
/>
<p>
<span>{textCnt}</span>
Expand Down
11 changes: 5 additions & 6 deletions src/components/atoms/toggle/Toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ export interface ToggleProps {
width?: string;
fontSize?: string;
content?: string;
name: string;
register: any;
}

export function Toggle({
children,
color = "#2b2b2b",
backgroundColor = "#51F8C4",
size = "big",
height = "2rem",
width = "4rem",
fontSize = "16rem",
content = "",
name,
register
}: ToggleProps) {
const [on, setOn] = useState(false);
const changeToggle = () => {
Expand Down Expand Up @@ -65,6 +63,7 @@ export function Toggle({
checked={on}
// onChange={noop}
data-testid="toggle-input"
{...register(name)}
/>
<span
className={toggleClassName}
Expand Down
28 changes: 20 additions & 8 deletions src/components/molecules/authBox/AuthBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@
import { Button } from "@/components/atoms/button";
import { Input } from "@/components/atoms/input";
import { useState } from "react";
import { useForm } from "react-hook-form";
import "./AuthBox.css";
import { AUTH_BTN, AUTH_PLACEHOLDER } from "./const";

export const AuthBox = () => {
const { control, handleSubmit, getValues } = useForm();
export const AuthBox = ({register}: any) => {
const [display, setDisplay] = useState(false);
// const {mutate, isSuccess} = usePostCertification();
const [authNum, setAuthNum] = useState({
toNumber: "",
certificationNum: 0
});

const handleAuthnum = () => {
setDisplay(true);
handleSubmit(onSubmit);
console.log(getValues());
// mutate({
// toNumber:
// })
// handleSubmit(onSubmit);
// console.log(getValues());
}

const onSubmit = () => {
Expand All @@ -25,9 +32,14 @@ export const AuthBox = () => {
<div className="signup__inputBox">
<Input
size="md"
name="mobile"
name="userPhone"
placeholder={AUTH_PLACEHOLDER.mobile}
control={control}
// value={authNum.toNumber}
// onChange={(e: React.ChangeEvent<HTMLInputElement>) => setAuthNum((prev) => ({
// ...prev,
// toNumber: e.target.value
// }))}
register={register}
/>
<Button
size="sm"
Expand All @@ -40,7 +52,7 @@ export const AuthBox = () => {
size="md"
name="authNum"
placeholder={AUTH_PLACEHOLDER.authNum}
control={control}
register={register}
/>
<Button size="sm">{AUTH_BTN.checkNum}</Button>
</div>) :
Expand Down
68 changes: 53 additions & 15 deletions src/components/molecules/inputBox/InputBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import { Toggle } from "@/components/atoms/toggle";
import { AuthBox } from "../authBox";
import { ChipBox } from "../chipBox/ChipBox";

import { FieldValues, useForm } from "react-hook-form";
import "./InputBox.css";
import { CodeInput } from "@/components/atoms/input/CodeInput";
import { COLORS } from "@/styles";
import "./InputBox.css";

export interface InputBoxProps {
title?: string;
maxCnt?: number;
type?: string;
subtitle?: string;
essential?: boolean;
name?: string;
name: string;
register: any;
control?: any;
}
export function InputBox({
title,
Expand All @@ -26,53 +28,89 @@ export function InputBox({
subtitle,
essential,
name,
register,
control,
}: InputBoxProps) {
const { control } = useForm<FieldValues>();
// const { control } = useForm<FieldValues>();

let inputComponent;
switch (type) {
case "input":
inputComponent = <Input maxCnt={maxCnt} name="name" control={control} />;
inputComponent =
<Input
maxCnt={maxCnt}
name={name}
// control={control}
register={register}
/>;
break;
case "numInput":
inputComponent = (
<CodeInput maxCnt={maxCnt} name="name" control={control} />
<CodeInput
maxCnt={maxCnt}
name="name"
control={control}
/>
);
break;
case "textarea":
inputComponent = <Textarea maxCnt={maxCnt} />;
inputComponent = (
<Textarea
maxCnt={maxCnt}
name={name}
register={register}
/>
);
break;
case "toggle":
inputComponent = <Toggle />;
inputComponent = (
<Toggle
name={name}
register={register}
/>
);
break;
case "chip":
inputComponent = <ChipBox />;
inputComponent = (
<ChipBox />
);
break;
case "fileUpload":
inputComponent = <FileUpload />;
inputComponent = (
<FileUpload
name={name}
register={register}
/>
);
break;
case "btnInput":
inputComponent = <AuthBox />;
inputComponent = <AuthBox register={register} />;
break;
default:
// default는 Input
inputComponent = <Input maxCnt={maxCnt} name="name" control={control} />;
inputComponent =
<Input
maxCnt={maxCnt}
name="name"
// control={control}
register={register}
/>;
break;
}
return (
<div className="registerBox">
<div className="textBox">
<Text fontSize="1.1875rem" color="#fff">
<Text fontSize="1.1875rem" color={COLORS.white}>
{title}
</Text>
{essential && (
<Text fontSize="1.1875rem" color="#FF4444">
<Text fontSize="1.1875rem" color={COLORS.red}>
*
</Text>
)}
</div>
{subtitle && (
<Text fontSize="0.6875rem" color="#d9d9d9" fontWeight="500">
<Text fontSize="0.6875rem" color={COLORS.whitegrey} fontWeight="500">
{subtitle}
</Text>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/features/Login/components/LoginBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "./Login.css";

export default function LoginBtn() {
const handleLogin = () => {
window.location.href = `https://kauth.kakao.com/oauth/authorize?client_id=${process.env.NEXT_PUBLIC_API_KEY}&redirect_url=${process.env.NEXT_PUBLIC_REDIRECT_URL}&response_type=code`
window.location.href = `${process.env.NEXT_PUBLIC_KAKAO_URL}`;
}
return (
<Image src={IMAGES.loginKakao} alt="kakao login" className="login_kakao" onClick={handleLogin}/>
Expand Down
Loading