Add Checkbox and Input Scheduler Date
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
Row,
|
||||
Col,
|
||||
Image,
|
||||
Checkbox
|
||||
} from 'antd';
|
||||
import { PlusOutlined, EyeOutlined, DeleteOutlined } from '@ant-design/icons';
|
||||
import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif';
|
||||
@@ -37,9 +38,15 @@ const DetailSparepart = (props) => {
|
||||
const [previewTitle, setPreviewTitle] = useState('');
|
||||
const [isHovering, setIsHovering] = useState(false);
|
||||
|
||||
const options = ['1 Year', '2 Year', '3 Year', '4 Year', '5 Year', '6 Year'];
|
||||
const [checkedList, setCheckedList] = useState([]);
|
||||
const [checkAll, setCheckAll] = useState(false);
|
||||
const [indeterminate, setIndeterminate] = useState(false);
|
||||
|
||||
const defaultData = {
|
||||
sparepart_id: '',
|
||||
sparepart_name: '',
|
||||
sparepart_number: '',
|
||||
sparepart_description: '',
|
||||
sparepart_model: '',
|
||||
sparepart_item_type: null,
|
||||
@@ -75,6 +82,16 @@ const DetailSparepart = (props) => {
|
||||
setFileList([]);
|
||||
};
|
||||
|
||||
const chekboxValue = () => {
|
||||
const result = {};
|
||||
options.forEach((item, index) => {
|
||||
const key = `is_${index + 1}th`;
|
||||
result[key] = checkedList.includes(item);
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
const handleSave = async () => {
|
||||
setConfirmLoading(true);
|
||||
|
||||
@@ -273,6 +290,11 @@ const DetailSparepart = (props) => {
|
||||
setConfirmLoading(false);
|
||||
};
|
||||
|
||||
// const handleSave = () => {
|
||||
// const val = chekboxValue();
|
||||
// console.log(val);
|
||||
// };
|
||||
|
||||
const handleInputChange = (e) => {
|
||||
const { name, value } = e.target;
|
||||
setFormData({ ...formData, [name]: value });
|
||||
@@ -282,6 +304,21 @@ const DetailSparepart = (props) => {
|
||||
setFormData({ ...formData, [name]: value });
|
||||
};
|
||||
|
||||
const onChangeCheckbox = (list) => {
|
||||
setCheckedList(list);
|
||||
|
||||
setIndeterminate(!!list.length && list.length < options.length);
|
||||
setCheckAll(list.length === options.length);
|
||||
};
|
||||
|
||||
const onCheckAllChange = (e) => {
|
||||
const checked = e.target.checked;
|
||||
|
||||
setCheckedList(checked ? options : []);
|
||||
setIndeterminate(false);
|
||||
setCheckAll(checked);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (props.selectedData) {
|
||||
setFormData(props.selectedData);
|
||||
@@ -321,6 +358,9 @@ const DetailSparepart = (props) => {
|
||||
} else {
|
||||
setFormData(defaultData);
|
||||
setFileList([]);
|
||||
setIndeterminate(false);
|
||||
setCheckedList([]);
|
||||
setCheckAll(false);
|
||||
}
|
||||
}, [props.showModal, props.selectedData, props.actionMode]);
|
||||
|
||||
@@ -333,6 +373,7 @@ const DetailSparepart = (props) => {
|
||||
|
||||
return (
|
||||
<Modal
|
||||
width='40rem'
|
||||
title={`${
|
||||
props.actionMode === 'add'
|
||||
? 'Tambah'
|
||||
@@ -463,7 +504,7 @@ const DetailSparepart = (props) => {
|
||||
<div
|
||||
style={{
|
||||
width: '180px', // Fixed width for square
|
||||
height: '180px',
|
||||
height: '240px',
|
||||
border: '1px dashed #d9d9d9',
|
||||
borderRadius: '8px',
|
||||
display: 'flex',
|
||||
@@ -485,6 +526,17 @@ const DetailSparepart = (props) => {
|
||||
{/* Kolom untuk field lainnya */}
|
||||
<Col span={14}>
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={24}>
|
||||
<Text strong>Part Number</Text>
|
||||
<Text style={{ color: 'red' }}> *</Text>
|
||||
<Input
|
||||
name="sparepart_number"
|
||||
value={formData.sparepart_number}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Enter Sparepart Number"
|
||||
readOnly={props.readOnly}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={24}>
|
||||
<Text strong>Sparepart Name</Text>
|
||||
<Text style={{ color: 'red' }}> *</Text>
|
||||
@@ -560,7 +612,44 @@ const DetailSparepart = (props) => {
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<ConfigProvider
|
||||
theme={{
|
||||
token: {
|
||||
colorPrimary: '#23A55A',
|
||||
},
|
||||
}}
|
||||
>
|
||||
<Row style={{ marginTop: 16 }}>
|
||||
<Col>
|
||||
<Checkbox
|
||||
indeterminate={indeterminate}
|
||||
onChange={onCheckAllChange}
|
||||
checked={checkAll}
|
||||
>
|
||||
{checkAll ? 'Unselect All Years' : 'Select All Years'}
|
||||
</Checkbox>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row style={{ marginTop: 10 }}>
|
||||
<Col span={24}>
|
||||
<Checkbox.Group
|
||||
value={checkedList}
|
||||
onChange={onChangeCheckbox}
|
||||
style={{
|
||||
width: '100%',
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
}}
|
||||
>
|
||||
{options.map((item) => (
|
||||
<Checkbox key={item} value={item}>
|
||||
{item}
|
||||
</Checkbox>
|
||||
))}
|
||||
</Checkbox.Group>
|
||||
</Col>
|
||||
</Row>
|
||||
</ConfigProvider>
|
||||
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
|
||||
<Col span={24}>
|
||||
<Text strong>Description</Text>
|
||||
|
||||
Reference in New Issue
Block a user