Skip to content

Commit

Permalink
feat: signup 데이터 바인딩 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
leecr1215 committed Oct 13, 2022
1 parent cae5057 commit ed3c085
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ yarn-error.log*

# file tree
filetree.txt

# package
package-lock.json
56 changes: 56 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.1.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.4.1",
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="oohub" />
<link rel="icon" href="%PUBLIC_URL%/tab_logo.png" />
<title>oohub</title>
</head>
<body>
Expand Down
Binary file added public/tab_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/api.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";
import { useQuery } from "@tanstack/react-query";
import SERVER from "./url";
import axios from "axios";

// 회원가입
export const addUser = async (userInfo) => {
console.log(userInfo);
try {
const response = await axios.post(`${SERVER}/api/v1/join`, userInfo);
if (response.status === 200) {
alert("회원가입 되었습니다");
}
} catch (error) {
throw new Error("signup user error");
}
};
14 changes: 12 additions & 2 deletions src/components/atoms/button.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import styled from "styled-components";
import styled, { css } from "styled-components";
import theme from "../../styles/theme";

const CustomButton = styled.button`
Expand All @@ -11,7 +11,15 @@ const CustomButton = styled.button`
background-color: ${(props) => props.bgColor};
font-size: ${(props) => `${props.fontSize}rem`};
font-weight: ${(props) => props.fontWeight};
border: ${(props) => props.border};
//border: ${(props) => props.border};
${(props) =>
props.hoverEvent &&
css`
&:hover {
box-shadow: 1px 1px 3px 4px lightgrey;
transition: 0.4s;
}
`}
`;

const Button = ({
Expand All @@ -24,6 +32,7 @@ const Button = ({
fontSize = 1,
fontWeight = 700,
border = "none",
hoverEvent = false,
}) => {
return (
<CustomButton
Expand All @@ -35,6 +44,7 @@ const Button = ({
fontSize={fontSize}
fontWeight={fontWeight}
border={border}
hoverEvent={hoverEvent}
type="button"
>
{children}
Expand Down
11 changes: 9 additions & 2 deletions src/components/atoms/input.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import React from "react";

const Input = ({ type = "text", placeholder, height = 3.5, onChange }) => {
const Input = ({
type = "text",
inputType,
placeholder,
height = 3.5,
onChange,
}) => {
switch (type) {
case "text":
return (
<input
type={inputType}
placeholder={placeholder}
onChange={onChange}
style={{ height: `${height}rem` }}
style={{ height: `${height}rem`, paddingLeft: "5px" }}
/>
);
default:
Expand Down
7 changes: 7 additions & 0 deletions src/components/pages/logIn.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

const LogIn = () => {
return <div>난 로그인</div>;
};

export default LogIn;
79 changes: 73 additions & 6 deletions src/components/pages/signUp.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import React from "react";
import {
QueryClient,
useMutation,
useQueryClient,
} from "@tanstack/react-query";
import React, { useState } from "react";
import styled from "styled-components";
import { addUser } from "../../api";
import logo from "../../assets/images/logo.png";
import Button from "../atoms/button";
import DropDown from "../atoms/dropdown";
import Input from "../atoms/input";
import FlexColumn from "../molecules/flexColumn";
import { useNavigate } from "react-router-dom";
import Header from "../organisms/header";

const Logo = styled.img`
Expand All @@ -13,22 +20,82 @@ const Logo = styled.img`
`;

const SignUp = () => {
const navigate = useNavigate();
const queryClient = useQueryClient();
const departments = ["frontend", "backend", "test", "devops"];
const [userInfo, setUserInfo] = useState({
username: "",
password: "",
departmentName: "",
workspaceName: "",
});

const changeUserInfo = (name, value) => {
setUserInfo((prev) => ({ ...prev, [name]: value }));
};

const hasBlank = () => {
if (Object.keys(userInfo).find((key) => userInfo[key] === "")) {
return true;
} else {
return false;
}
};

const addUserMutation = useMutation((userInfo) => addUser(userInfo), {
onSuccess: () => {
queryClient.invalidateQueries();
navigate("/logIn");
},
});

const SignUpButtonClicked = () => {
if (hasBlank()) {
alert("작성");
} else {
console.log(userInfo);
addUserMutation.mutate(userInfo);
}
};

return (
<div style={{ height: "100vh" }}>
<FlexColumn justifyContent="space-evenly" width={25}>
<Logo src={logo} alt="oohub" />
<Input placeholder=" id" />
<Input placeholder=" pw" />
<DropDown placeholder="department" options={departments} />
<Input placeholder=" workspace name" />
<Input
placeholder="username"
onChange={(e) => {
changeUserInfo("username", e.target.value);
}}
/>
<Input
inputType="password"
placeholder="password"
onChange={(e) => {
changeUserInfo("password", e.target.value);
}}
/>
<DropDown
placeholder="department"
options={departments}
onChange={(e) => {
changeUserInfo("departmentName", e.target.value);
}}
/>
<Input
placeholder="workspace name"
onChange={(e) => {
changeUserInfo("workspaceName", e.target.value);
}}
/>
<Button
onClick={() => {
console.log("클릭");
SignUpButtonClicked();
}}
width={100}
height={3.5}
border="1px solid black"
hoverEvent={true}
>
Sign Up
</Button>
Expand Down
3 changes: 3 additions & 0 deletions src/router.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import Header from "./components/organisms/header";
import LogIn from "./components/pages/logIn";
import SignUp from "./components/pages/signUp";

const Router = () => {
Expand All @@ -10,6 +11,8 @@ const Router = () => {
<Header />
<Routes>
<Route path="/" element={<SignUp />} />
<Route path="/signUp" element={<SignUp />} />
<Route path="/logIn" element={<LogIn />} />
</Routes>
</BrowserRouter>
);
Expand Down
2 changes: 2 additions & 0 deletions src/url.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const SERVER = "http://127.0.0.1:8080";
export default SERVER;

0 comments on commit ed3c085

Please sign in to comment.