feat: initial commit
This commit is contained in:
280
src/pages/Membership/Membership.js
Normal file
280
src/pages/Membership/Membership.js
Normal file
@@ -0,0 +1,280 @@
|
||||
import React, {useEffect, useState} from "react";
|
||||
import {Button, Card, Col, Input, List, message, Modal, PageHeader, Row, Space, Table, Tag} from "antd";
|
||||
import {useStore} from "../../utils/useStore";
|
||||
import {observer} from "mobx-react-lite";
|
||||
import {ExclamationCircleOutlined, FilterOutlined, PlusSquareOutlined,} from "@ant-design/icons";
|
||||
import {MembershipModal} from "./MembershipModal";
|
||||
import {BreadcumbComponent} from "../../component/BreadcumbComponent";
|
||||
|
||||
const {Search} = Input;
|
||||
|
||||
export const Membership = observer(() => {
|
||||
const store = useStore();
|
||||
const [visibleModal, setVisibleModal] = useState(false)
|
||||
const [initialData, setInitialData] = useState({})
|
||||
const [confirmLoading, setConfirmLoading] = useState(false);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const init = async () => {
|
||||
try {
|
||||
setIsLoading(true)
|
||||
await store.membership.getData();
|
||||
setIsLoading(false)
|
||||
} catch (e) {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
init()
|
||||
|
||||
}, []);
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: "Name",
|
||||
dataIndex: "name",
|
||||
key: "name",
|
||||
},
|
||||
{
|
||||
title: "Username",
|
||||
dataIndex: "username",
|
||||
key: "username",
|
||||
},
|
||||
{
|
||||
title: "Status",
|
||||
dataIndex: "status",
|
||||
key: "status",
|
||||
render: (text, record) => (
|
||||
<>
|
||||
<Tag color="#E3E8EE" style={{color: "#4F566B"}}>
|
||||
Inactive
|
||||
</Tag>
|
||||
<Tag color="processing">Active</Tag>
|
||||
</>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: "Action",
|
||||
key: "action",
|
||||
render: (text, record) => (
|
||||
<Space size="middle">
|
||||
<Button onClick={() => {
|
||||
setVisibleModal(true)
|
||||
setInitialData(record)
|
||||
}}>Edit</Button>
|
||||
<Button onClick={async () => {
|
||||
handleDelete(record.id)
|
||||
|
||||
}}
|
||||
>Delete</Button>
|
||||
</Space>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const routeData = [
|
||||
{
|
||||
route: "/app/home",
|
||||
name: "Home",
|
||||
},
|
||||
{
|
||||
route: "/app/membership",
|
||||
name: <span style={{fontWeight: "bold"}}>Membership</span>,
|
||||
},
|
||||
];
|
||||
|
||||
const onSubmit = async (data) => {
|
||||
if (initialData.id) {
|
||||
setInitialData({})
|
||||
setConfirmLoading(true);
|
||||
try {
|
||||
await store.membership.update(initialData.id, data)
|
||||
message.success("Success Update Data Member")
|
||||
} catch (e) {
|
||||
message.error("Failed Update Data Member")
|
||||
}
|
||||
setConfirmLoading(false);
|
||||
setVisibleModal(false);
|
||||
} else {
|
||||
setInitialData({})
|
||||
setConfirmLoading(true);
|
||||
try {
|
||||
await store.membership.create(data)
|
||||
message.success("Success Add New Member")
|
||||
} catch (e) {
|
||||
console.log(e, "apa errornya")
|
||||
message.error("Failed Add Member")
|
||||
}
|
||||
setConfirmLoading(false);
|
||||
setVisibleModal(false);
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = (record) => {
|
||||
Modal.confirm({
|
||||
title: 'Are you sure reject this record?',
|
||||
icon: <ExclamationCircleOutlined/>,
|
||||
okText: 'Yes',
|
||||
okType: 'primary',
|
||||
cancelText: 'Cancel',
|
||||
onOk() {
|
||||
try {
|
||||
//TODO: minta apinya ke ka ilham ya, jangan di uncomment kalo pake api reconcile, nanti beneran ke apus datanya
|
||||
// await store.membership.delete(record.id)
|
||||
message.success('Success Delete Data')
|
||||
} catch (e) {
|
||||
message.error("Failed Delete Data")
|
||||
}
|
||||
},
|
||||
onCancel() {
|
||||
console.log('Cancel');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<BreadcumbComponent data={routeData}/>
|
||||
<Card>
|
||||
{store.ui.mediaQuery.isDesktop && (
|
||||
<div>
|
||||
<Row style={{marginBottom: 20}}>
|
||||
<Col span={12}>
|
||||
<Button>
|
||||
<FilterOutlined/>
|
||||
Filter
|
||||
</Button>
|
||||
</Col>
|
||||
<Col span={12} style={{textAlign: "right"}}>
|
||||
<Search
|
||||
placeholder="input search text"
|
||||
style={{width: 200, marginRight: 10}}
|
||||
/>
|
||||
<Button onClick={() => setVisibleModal(true)}>
|
||||
<PlusSquareOutlined/> New
|
||||
</Button>
|
||||
</Col>
|
||||
</Row>
|
||||
<Table
|
||||
style={{textAlign: "center"}}
|
||||
columns={columns}
|
||||
dataSource={store.membership.data}
|
||||
bordered
|
||||
pagination={{
|
||||
total: store.membership.total_data,
|
||||
current: store.membership.page,
|
||||
pageSize: store.membership.pageSize,
|
||||
simple: true
|
||||
}} onChange={(page) => {
|
||||
store.membership.pageSize = page.pageSize;
|
||||
store.membership.page = page.current;
|
||||
store.membership.getData();
|
||||
}} current={store.membership.page}
|
||||
loading={store.membership.pageSize}/>
|
||||
</div>
|
||||
)}
|
||||
{store.ui.mediaQuery.isMobile && (
|
||||
<div>
|
||||
<Card bordered={false} bodyStyle={{padding: "0"}} style={{borderRadius: 0, width: '50%'}}>
|
||||
<PageHeader
|
||||
className={"card-page-header"}
|
||||
style={{
|
||||
padding: "6px 8px",
|
||||
}}
|
||||
title={
|
||||
<Button
|
||||
icon={<FilterOutlined/>}
|
||||
size={"small"}
|
||||
style={{margin: 3}}
|
||||
>
|
||||
Filter
|
||||
</Button>
|
||||
}
|
||||
subTitle=""
|
||||
/>
|
||||
</Card>
|
||||
|
||||
<List
|
||||
itemLayout="horizontal"
|
||||
position={"top"}
|
||||
dataSource={store.membership.data}
|
||||
style={{padding: 0}}
|
||||
renderItem={(item) => {
|
||||
console.log(item, "item ->");
|
||||
return (
|
||||
<div>
|
||||
<List.Item
|
||||
key={item.key}
|
||||
style={{
|
||||
backgroundColor: "#ffffff",
|
||||
paddingTop: 0,
|
||||
paddingBottom: 0,
|
||||
display: "flex",
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
width: "50%"
|
||||
}}
|
||||
>
|
||||
<List.Item.Meta
|
||||
className={["cariparkir-container"].join(" ")}
|
||||
title={<h3 style={{marginBottom: 0, color: "#5469d4"}}>{item.name}</h3>}
|
||||
description={
|
||||
<div style={{}}>
|
||||
<p>
|
||||
<small>Username : {item.username}</small> <br/>
|
||||
</p>
|
||||
<p>
|
||||
{item.status}
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
{/* <div style={{ marginRight: 16 }}>
|
||||
<Statistic
|
||||
title={
|
||||
<p
|
||||
style={{
|
||||
fontSize: 9,
|
||||
margin: 0,
|
||||
}}
|
||||
>
|
||||
{item.updated_at ? moment(item.updated_at).format("DD MMM YY, H:mm:ss") : "There is not top up yet"}
|
||||
</p>
|
||||
}
|
||||
prefix={"Rp"}
|
||||
precision={0}
|
||||
style={{ fontSize: 12, fontWeight: 300 }}
|
||||
valueStyle={{
|
||||
color: "#5469d4",
|
||||
fontSize: 12,
|
||||
fontWeight: 600,
|
||||
textAlign: "right",
|
||||
}}
|
||||
value={item.balances}
|
||||
/>
|
||||
|
||||
</div> */}
|
||||
</List.Item>
|
||||
{/* <Divider plain style={{ margin: 0 }} /> */}
|
||||
</div>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
<MembershipModal visible={visibleModal}
|
||||
confirmLoading={confirmLoading}
|
||||
initialData={initialData}
|
||||
onCreate={async (data) => {
|
||||
onSubmit(data)
|
||||
}}
|
||||
onCancel={() => {
|
||||
setInitialData({})
|
||||
setVisibleModal(false);
|
||||
}}/>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
82
src/pages/Membership/MembershipModal.js
Normal file
82
src/pages/Membership/MembershipModal.js
Normal file
@@ -0,0 +1,82 @@
|
||||
import React from 'react';
|
||||
import {Form, Input, Modal, Select,} from 'antd';
|
||||
|
||||
export const MembershipModal = ({
|
||||
visible,
|
||||
onCreate,
|
||||
onCancel,
|
||||
initialData,
|
||||
}) => {
|
||||
const [form] = Form.useForm();
|
||||
const {Option} = Select;
|
||||
const dataStatus = ['Active', 'Inactive']
|
||||
|
||||
|
||||
return (
|
||||
<Modal
|
||||
visible={visible}
|
||||
title={initialData.id ? "Edit Member" : "Create a new Member"}
|
||||
okText={initialData.id ? "Edit" : "Create"}
|
||||
cancelText="Cancel"
|
||||
onCancel={() => {
|
||||
form.resetFields()
|
||||
onCancel()
|
||||
}}
|
||||
onOk={() => {
|
||||
form
|
||||
.validateFields()
|
||||
.then(values => {
|
||||
onCreate(values);
|
||||
form.resetFields()
|
||||
})
|
||||
.catch(info => {
|
||||
console.log('Validate Failed:', info);
|
||||
});
|
||||
}}
|
||||
>
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
name="form_in_modal"
|
||||
initialValues={initialData}
|
||||
>
|
||||
<Form.Item
|
||||
name="name"
|
||||
label="Name"
|
||||
rules={[{required: true, message: 'Please input Name!'}]}
|
||||
>
|
||||
<Input/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="username"
|
||||
label="Username"
|
||||
rules={[{required: true, message: 'Please input Username!'}]}
|
||||
>
|
||||
<Input/>
|
||||
</Form.Item>
|
||||
<Form.Item
|
||||
name="status"
|
||||
label="Status"
|
||||
|
||||
rules={[{required: true, message: 'Please select Status!'}]}
|
||||
>
|
||||
<Select
|
||||
showSearch
|
||||
placeholder="Select Status"
|
||||
optionFilterProp="children"
|
||||
filterOption={(input, option) =>
|
||||
option.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
||||
}
|
||||
filterSort={(optionA, optionB) =>
|
||||
optionA.children.toLowerCase().localeCompare(optionB.children.toLowerCase())
|
||||
}
|
||||
>
|
||||
{dataStatus.map(it => {
|
||||
return <Option value={it}>{it}</Option>
|
||||
})}
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user