
AppLayout 컴포넌트
import PropTypes from "prop-types";
import Link from "next/link";
import { Menu, Input, Row, Col } from "antd";
import { useState } from "react";
import UserProfile from "./UserProfile";
import LoginForm from "./LoginForm";
import styled from "styled-components";
const SeachInput = styled(Input.Search)` //antd 커스텀 하는법
vertical-align: middle;
`;
const AppLayout = ({ children }) => {
const [isLoggedIn, setIsLoggendIn] = useState(false);
return (
<div>
...Menu
<Row gutter={8}>
<Col xs={24} md={6}>
{isLoggedIn ? (
<UserProfile setIsLoggendIn={setIsLoggendIn} />
) : (
<LoginForm setIsLoggendIn={setIsLoggendIn} />
)}
</Col>
<Col xs={24} md={12}>
{children}
</Col>
<Col xs={24} md={6}>
<a
href="https://velog.io/@abc5259"
target="_blank"
rel="noreferer noopener"
>
Made By LeeJaeHoon
</a>
</Col>
</Row>
</div>
);
};
AppLayout.propTypes = {
children: PropTypes.node.isRequired,
};
export default AppLayout;
LoginForm
import { Button, Form, Input } from "antd";
import { useCallback, useState } from "react";
import Link from "next/link";
import styled from "styled-components";
const ButtonWrapper = styled.div`
margin-top: 10px;
`;
const FormWrapper = styled(Form)`
padding: 20px;
`;
const LoginForm = ({ setIsLoggendIn }) => {
const [id, setId] = useState("");
const [password, setPassword] = useState("");
const onChangeId = useCallback(e => {
setId(e.target.value);
}, []);
const onChangePassword = useCallback(e => {
setPassword(e.target.value);
}, []);
const onSubmitForm = useCallback(() => {
console.log(id, password);
setIsLoggendIn(true);
}, [id, password]);
return (
<>
<FormWrapper onFinish={onSubmitForm}>
<div>
<label htmlFor="user-id">아이디</label>
<br />
<Input name="user-id" value={id} onChange={onChangeId} required />
</div>
<div>
<label htmlFor="user-password">비밀번호</label>
<br />
<Input
name="user-password"
type="password"
value={password}
onChange={onChangePassword}
required
/>
</div>
<ButtonWrapper>
<Button type="primary" htmlType="submit" loading={false}>
로그인
</Button>
<Link href="/signup">
<a>
<Button>회원가입</Button>
</a>
</Link>
</ButtonWrapper>
</FormWrapper>
</>
);
};
export default LoginForm;
UserProfile
import { Avatar, Button, Card } from "antd";
import { useCallback } from "react";
const UserProfile = ({ setIsLoggendIn }) => {
const onLoggout = useCallback(() => {
setIsLoggendIn(false);
}, []);
return (
<>
<Card
actions={[
<div key="twit">
짹짹
<br />0
</div>,
<div key="followings">
팔로잉
<br />0
</div>,
<div key="followers">
팔로워
<br />0
</div>,
]}
>
<Card.Meta avatar={<Avatar>JH</Avatar>} title="LeeJaeHoon" />
<Button onClick={onLoggout}>로그아웃</Button>
</Card>
</>
);
};
export default UserProfile;