Skip to content

Commit

Permalink
add form 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
gongdongho12 committed Jul 18, 2020
1 parent e9a752d commit 5f02a17
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"less": "^3.12.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-images-upload": "^1.2.8",
"react-infinite-scroll-component": "^5.0.5",
"react-intl": "^5.0.2",
"react-morefinity": "^1.0.4",
Expand Down
222 changes: 222 additions & 0 deletions src/components/AddForm/AddForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
import React, { useState, FunctionComponent } from "react";
import {
Form,
Input,
Tooltip,
Cascader,
Select,
Row,
Col,
Checkbox,
Button,
AutoComplete,
} from "antd";
import { QuestionCircleOutlined, CloseOutlined } from "@ant-design/icons";

import ImageUploader from 'react-images-upload';
import FlexCenter from "components/FlexCenter";

const { Option } = Select;
// const AutoCompleteOption = AutoComplete.Option;

const residences = [
{
value: "zhejiang",
label: "Zhejiang",
children: [
{
value: "hangzhou",
label: "Hangzhou",
children: [
{
value: "xihu",
label: "West Lake",
},
],
},
],
},
{
value: "jiangsu",
label: "Jiangsu",
children: [
{
value: "nanjing",
label: "Nanjing",
children: [
{
value: "zhonghuamen",
label: "Zhong Hua Men",
},
],
},
],
},
];

const formItemLayout = {
labelCol: {
xs: { span: 24 },
sm: { span: 8 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 },
},
};
const tailFormItemLayout = {
wrapperCol: {
xs: {
span: 24,
offset: 0,
},
sm: {
span: 16,
offset: 8,
},
},
};

const AddForm: FunctionComponent<any> = () => {
const [form] = Form.useForm();
const [picture, setPicture] = useState<any>([])

const onFinish = (values: any) => {
console.log("Received values of form: ", values);
};

const prefixSelector = (
<Form.Item name="prefix" noStyle>
<Select style={{ width: 70 }}>
<Option value="86">+86</Option>
<Option value="87">+87</Option>
</Select>
</Form.Item>
);

const onDrop = (picture: any) => {
console.log('picture', picture)
setPicture(picture)
}

const [autoCompleteResult, setAutoCompleteResult] = useState<any[]>([]);

return (
<Form
{...formItemLayout}
form={form}
name="register"
onFinish={onFinish}
initialValues={{
residence: ["zhejiang", "hangzhou", "xihu"],
prefix: "86",
}}
scrollToFirstError
>
<Form.Item
name="productName"
label="상품이름"
rules={[
{
required: true,
message: "Please input product name!",
},
]}
>
<Input />
</Form.Item>
<Form.Item
name="productType"
label="상품타입"
hasFeedback
rules={[{ required: true, message: '상품타입을 입력해주세요!' }]}
>
<Select placeholder="상품타입">
<Option value="china">China</Option>
<Option value="usa">U.S.A</Option>
<Option value="usa2">U.S.A1</Option>
<Option value="usa1">U.S.A2</Option>
</Select>
</Form.Item>
<Form.Item
name="productImage"
label={"상품이미지"}
// rules={[
// {
// required: false,
// message: "Please 업로드 상품 이미지",
// whitespace: true,
// },
// ]}
>
{picture.length > 0 ? (
<FlexCenter>
<span>{picture[0].name}</span>
<Button type="primary" onClick={() => { onDrop([]) }} icon={<CloseOutlined />} size={'small'} />
</FlexCenter>
) : (
<ImageUploader
withIcon={true}
buttonText='Choose images'
onChange={onDrop}
imgExtension={['.jpg', '.gif', '.png', '.gif']}
maxFileSize={5242880}
/>
)}
</Form.Item>
<Form.Item
name="planMoney"
label="목표금액 (원)"
rules={[
{
required: true,
message: "공동구매 목표금액을 입력하세요!",
},
]}
>
<Input type='number' />
</Form.Item>
<Form.Item
name="minMoney"
label="최소 판매 단위"
rules={[
{
required: true,
message: "최소 판매 단위를 입력하세요!",
},
]}
>
<Input placeholder="2000개 1묶음" />
</Form.Item>
<Form.Item
name="minMoney"
label="단위당 금액 (원)"
rules={[
{
required: true,
message: "단위당 금액을 입력하세요!",
},
]}
>
<Input type='number' />
</Form.Item>

<Form.Item name={'detail'} label="상품에 대한 설명"
rules={[
{
required: true
}
]}>
<Input.TextArea />
</Form.Item>

<Form.Item {...{ wrapperCol: { span: 24 }}}>
<Button style={{ width: '100%' }} type="primary" htmlType="submit">
추가
</Button>
</Form.Item>
</Form>
);
};

export default AddForm;
2 changes: 2 additions & 0 deletions src/components/AddForm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import AddForm from './AddForm'
export default AddForm
11 changes: 11 additions & 0 deletions src/containers/Add/Add.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React, { FunctionComponent } from 'react';
import AddForm from 'components/AddForm';

interface ILoginProps {
}

const Add: FunctionComponent<ILoginProps> = (props) => {
return <AddForm />;
};

export default Add;
2 changes: 2 additions & 0 deletions src/containers/Add/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Add from './Add'
export default Add
9 changes: 3 additions & 6 deletions src/containers/CardView/CardViewV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import FlexCenter from "components/FlexCenter";
interface ICardViewProps {}

const breakPoint = {
xs: 24,
xs: 12,
sm: 12,
md: 12,
lg: 6,
xl: 4,
xl: 6,
};

const CardView: FunctionComponent<ICardViewProps> = (props) => {
Expand Down Expand Up @@ -45,11 +45,8 @@ const CardView: FunctionComponent<ICardViewProps> = (props) => {
}
}, [items, setItems, loading, setLoading]);

console.log('loading', loading)
console.log('items.length', items.length)

return (
<FlexCenter style={{ maxWidth: '1440px' }}>
<FlexCenter style={{ maxWidth: '1080px' }}>
<InfiniteScroll
scrollableTarget={'list'}
dataLength={items.length} //This is important field to render the next data
Expand Down
1 change: 1 addition & 0 deletions src/meta/routerMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const routerMeta: RouterMetaType = {
About: '/about',
Login: '/login',
Register: '/register',
Add: '/add',
CardView: '/cardview'
}

Expand Down

0 comments on commit 5f02a17

Please sign in to comment.