-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from GSG-G8/122-types-dashboard
Booking type at client side
- Loading branch information
Showing
14 changed files
with
568 additions
and
184 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { message, Modal, Form, Input } from 'antd'; | ||
import PropTypes from 'prop-types'; | ||
import { SliderPicker } from 'react-color'; | ||
|
||
const onModalOk = (form, updateID, onUpdate, onCreate) => { | ||
form | ||
.validateFields() | ||
.then((values) => { | ||
if (updateID > 0) onUpdate({ id: updateID, ...values }); | ||
else onCreate(values); | ||
}) | ||
.then(() => { | ||
form.resetFields(); | ||
form.setFieldsValue({ color: '', category: '' }); | ||
}) | ||
.catch((error) => message.error(error)); | ||
}; | ||
|
||
function AddType({ | ||
visible, | ||
onCreate, | ||
onCancel, | ||
onUpdate, | ||
updateID, | ||
category, | ||
color, | ||
}) { | ||
const [colorSlide, setColorSlide] = useState(''); | ||
const [form] = Form.useForm(); | ||
|
||
const handleChangeComplete = (result) => { | ||
setColorSlide(result.hex); | ||
form.setFieldsValue({ | ||
color: result.hex, | ||
}); | ||
}; | ||
useEffect(() => form.resetFields(), [form, color, category]); | ||
|
||
return ( | ||
<Modal | ||
visible={visible} | ||
title="Create a new type" | ||
okText={updateID > 0 ? 'Update' : 'Create'} | ||
cancelText="Cancel" | ||
onCancel={onCancel} | ||
onOk={() => { | ||
onModalOk(form, updateID, onUpdate, onCreate); | ||
setColorSlide(''); | ||
}} | ||
> | ||
<Form form={form} initialValues={{ category, color }}> | ||
<Form.Item | ||
name="category" | ||
label="Booking Type" | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Booking Type required', | ||
}, | ||
]} | ||
> | ||
<Input /> | ||
</Form.Item> | ||
<Form.Item | ||
name="color" | ||
label="Type Color" | ||
rules={[ | ||
{ | ||
required: true, | ||
message: 'Booking color required', | ||
}, | ||
]} | ||
> | ||
<SliderPicker | ||
color={colorSlide || color} | ||
onChange={handleChangeComplete} | ||
/> | ||
</Form.Item> | ||
</Form> | ||
</Modal> | ||
); | ||
} | ||
|
||
AddType.propTypes = { | ||
visible: PropTypes.bool.isRequired, | ||
updateID: PropTypes.number.isRequired, | ||
category: PropTypes.string.isRequired, | ||
color: PropTypes.string.isRequired, | ||
onCreate: PropTypes.func.isRequired, | ||
onCancel: PropTypes.func.isRequired, | ||
onUpdate: PropTypes.func.isRequired, | ||
}; | ||
export default AddType; |
Empty file.
Oops, something went wrong.