Compare commits
4 Commits
c92e1ef0ec
...
bad5da5e11
| Author | SHA1 | Date | |
|---|---|---|---|
| bad5da5e11 | |||
| 0ca2169a12 | |||
| d04f078c6c | |||
| 8d03a0a52e |
52
src/components/Global/AppInput.jsx
Normal file
52
src/components/Global/AppInput.jsx
Normal file
@@ -0,0 +1,52 @@
|
||||
import { Input } from "antd";
|
||||
import { useEffect, useState, useRef } from "react";
|
||||
|
||||
const InputNumber = ({
|
||||
name,
|
||||
value = 0,
|
||||
onChange,
|
||||
...props
|
||||
}) => {
|
||||
const [inputValue, setInputValue] = useState(
|
||||
value !== null && value !== undefined ? value.toString() : ''
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const newValue = value !== null && value !== undefined ? value.toString() : '';
|
||||
setInputValue(newValue);
|
||||
}, [value]);
|
||||
|
||||
const handleChange = (e) => {
|
||||
const rawValue = e.target.value;
|
||||
if (/^\d*$/.test(rawValue)) {
|
||||
setInputValue(rawValue);
|
||||
const numValue = rawValue === '' ? 0 : parseInt(rawValue, 10);
|
||||
|
||||
// Kirim event object sintetis yang konsisten dengan handler biasa
|
||||
onChange?.({
|
||||
target: {
|
||||
name: name,
|
||||
value: numValue
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const handleFocus = (e) => {
|
||||
// Pilih semua teks saat fokus (opsional)
|
||||
e.target.select();
|
||||
};
|
||||
|
||||
return (
|
||||
<Input
|
||||
{...props}
|
||||
name={name} // Teruskan name ke input
|
||||
value={inputValue}
|
||||
onChange={handleChange}
|
||||
onFocus={handleFocus}
|
||||
style={{ textAlign: 'left' }}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export { InputNumber };
|
||||
@@ -1,9 +1,21 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Modal, Input, Divider, Typography, Switch, Button, ConfigProvider, Select } from 'antd';
|
||||
import {
|
||||
Modal,
|
||||
Input,
|
||||
Divider,
|
||||
Typography,
|
||||
Switch,
|
||||
Button,
|
||||
ConfigProvider,
|
||||
Select,
|
||||
DatePicker,
|
||||
} from 'antd';
|
||||
import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif';
|
||||
import { createDevice, updateDevice } from '../../../../api/master-device';
|
||||
import { getAllBrands } from '../../../../api/master-brand';
|
||||
import { validateRun } from '../../../../Utils/validate';
|
||||
import { toApiDateFormatter } from '../../../../components/Global/Formatter';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
const { Text } = Typography;
|
||||
const { TextArea } = Input;
|
||||
@@ -23,6 +35,7 @@ const DetailDevice = (props) => {
|
||||
device_location: '',
|
||||
device_description: '',
|
||||
ip_address: '',
|
||||
reminder_at: null,
|
||||
listen_channel: '',
|
||||
};
|
||||
|
||||
@@ -67,8 +80,12 @@ const DetailDevice = (props) => {
|
||||
ip_address: formData.ip_address,
|
||||
brand_id: formData.brand_id,
|
||||
listen_channel: formData.listen_channel,
|
||||
listen_channel_reminder: formData.listen_channel_reminder,
|
||||
reminder_at: formData.reminder_at,
|
||||
};
|
||||
|
||||
console.log(payload);
|
||||
|
||||
const response = formData.device_id
|
||||
? await updateDevice(formData.device_id, payload)
|
||||
: await createDevice(payload);
|
||||
@@ -128,6 +145,13 @@ const DetailDevice = (props) => {
|
||||
});
|
||||
};
|
||||
|
||||
const handleDateChange = (field, value) => {
|
||||
setFormData({
|
||||
...formData,
|
||||
[field]: value,
|
||||
});
|
||||
};
|
||||
|
||||
// Fungsi untuk mengambil daftar brand
|
||||
const fetchBrands = async () => {
|
||||
setLoadingBrands(true);
|
||||
@@ -169,8 +193,8 @@ const DetailDevice = (props) => {
|
||||
props.actionMode === 'add'
|
||||
? 'Tambah'
|
||||
: props.actionMode === 'preview'
|
||||
? 'Preview'
|
||||
: 'Edit'
|
||||
? 'Preview'
|
||||
: 'Edit'
|
||||
} Device`}
|
||||
open={props.showModal}
|
||||
// open={true}
|
||||
@@ -218,9 +242,10 @@ const DetailDevice = (props) => {
|
||||
</React.Fragment>,
|
||||
]}
|
||||
>
|
||||
<Divider />
|
||||
{formData && (
|
||||
<div>
|
||||
<div>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<div>
|
||||
<Text strong>Device Status</Text>
|
||||
</div>
|
||||
@@ -247,7 +272,7 @@ const DetailDevice = (props) => {
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Divider style={{ margin: '12px 0' }} />
|
||||
{/* <Divider style={{ margin: '12px 0' }} /> */}
|
||||
<div hidden>
|
||||
<Text strong>Device ID</Text>
|
||||
<Input
|
||||
@@ -330,15 +355,63 @@ const DetailDevice = (props) => {
|
||||
readOnly={props.readOnly}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ marginBottom: 12 }}></div>
|
||||
<div style={{ marginBottom: 12 }}></div>
|
||||
<div style={{ display: 'flex', gap: 16 }}>
|
||||
<div style={{ flex: 1 }}>
|
||||
{' '}
|
||||
<Text strong>Channel Error</Text>
|
||||
<Input
|
||||
name="listen_channel"
|
||||
value={formData.listen_channel}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Enter Listen Channel"
|
||||
readOnly={props.readOnly}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ flex: 1 }}>
|
||||
<Text strong>Channel Reminder</Text>
|
||||
<Input
|
||||
name="listen_channel_reminder"
|
||||
value={formData.listen_channel_reminder}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Enter Listen Channel Reminder"
|
||||
readOnly={props.readOnly}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>Listen Channel</Text>
|
||||
<Input
|
||||
name="listen_channel"
|
||||
value={formData.listen_channel}
|
||||
onChange={handleInputChange}
|
||||
placeholder="Enter Listen Channel"
|
||||
readOnly={props.readOnly}
|
||||
/>
|
||||
<Text strong>Reminder At</Text>
|
||||
<div style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
|
||||
<DatePicker
|
||||
value={
|
||||
formData.reminder_at
|
||||
? dayjs(formData.reminder_at) // ✅ langsung parse ISO
|
||||
: null
|
||||
}
|
||||
onChange={(date) =>
|
||||
handleDateChange(
|
||||
'reminder_at',
|
||||
date ? date.toISOString() : null
|
||||
)
|
||||
}
|
||||
format="DD-MM-YYYY HH:mm"
|
||||
showTime={{ format: 'HH:mm' }}
|
||||
style={{ flex: 1 }}
|
||||
/>
|
||||
|
||||
<Button
|
||||
danger
|
||||
onClick={() =>
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
reminder_at: null,
|
||||
}))
|
||||
}
|
||||
>
|
||||
Clear
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ marginBottom: 12 }}>
|
||||
<Text strong>Device Description</Text>
|
||||
|
||||
@@ -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,46 @@ const DetailSparepart = (props) => {
|
||||
const [previewTitle, setPreviewTitle] = useState('');
|
||||
const [isHovering, setIsHovering] = useState(false);
|
||||
|
||||
const optionsYearly = [
|
||||
{
|
||||
key: 1,
|
||||
value: 1,
|
||||
text: '1 Year',
|
||||
},
|
||||
{
|
||||
key: 2,
|
||||
value: 2,
|
||||
text: '2 Year',
|
||||
},
|
||||
{
|
||||
key: 3,
|
||||
value: 3,
|
||||
text: '3 Year',
|
||||
},
|
||||
{
|
||||
key: 4,
|
||||
value: 4,
|
||||
text: '4 Year',
|
||||
},
|
||||
{
|
||||
key: 5,
|
||||
value: 5,
|
||||
text: '5 Year',
|
||||
},
|
||||
{
|
||||
key: 6,
|
||||
value: 6,
|
||||
text: '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,
|
||||
@@ -236,6 +274,9 @@ const DetailSparepart = (props) => {
|
||||
payload.sparepart_foto = imageUrl;
|
||||
}
|
||||
|
||||
payload.sparepart_number = formData.sparepart_number;
|
||||
payload.sparepart_yearly = checkedList;
|
||||
|
||||
// console.log('Sending payload:', payload);
|
||||
|
||||
const response = formData.sparepart_id
|
||||
@@ -282,6 +323,21 @@ const DetailSparepart = (props) => {
|
||||
setFormData({ ...formData, [name]: value });
|
||||
};
|
||||
|
||||
const onChangeCheckbox = (list) => {
|
||||
setCheckedList(list);
|
||||
|
||||
setIndeterminate(!!list.length && list.length < optionsYearly.length);
|
||||
setCheckAll(list.length === optionsYearly.length);
|
||||
};
|
||||
|
||||
const onCheckAllChange = (e) => {
|
||||
const checked = e.target.checked;
|
||||
|
||||
setCheckedList(checked ? optionsYearly.map((item) => item.value) : []);
|
||||
setIndeterminate(false);
|
||||
setCheckAll(checked);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (props.selectedData) {
|
||||
setFormData(props.selectedData);
|
||||
@@ -318,9 +374,13 @@ const DetailSparepart = (props) => {
|
||||
} else {
|
||||
setFileList([]);
|
||||
}
|
||||
setCheckedList(JSON.parse(props.selectedData.sparepart_yearly));
|
||||
} else {
|
||||
setFormData(defaultData);
|
||||
setFileList([]);
|
||||
setIndeterminate(false);
|
||||
setCheckedList([]);
|
||||
setCheckAll(false);
|
||||
}
|
||||
}, [props.showModal, props.selectedData, props.actionMode]);
|
||||
|
||||
@@ -333,12 +393,13 @@ const DetailSparepart = (props) => {
|
||||
|
||||
return (
|
||||
<Modal
|
||||
width="40rem"
|
||||
title={`${
|
||||
props.actionMode === 'add'
|
||||
? 'Tambah'
|
||||
: props.actionMode === 'preview'
|
||||
? 'Preview'
|
||||
: 'Edit'
|
||||
? 'Preview'
|
||||
: 'Edit'
|
||||
} Sparepart`}
|
||||
open={props.showModal}
|
||||
onCancel={handleCancel}
|
||||
@@ -463,7 +524,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 +546,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 +632,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',
|
||||
}}
|
||||
>
|
||||
{optionsYearly.map((item) => (
|
||||
<Checkbox key={item.key} value={item.value}>
|
||||
{item.text}
|
||||
</Checkbox>
|
||||
))}
|
||||
</Checkbox.Group>
|
||||
</Col>
|
||||
</Row>
|
||||
</ConfigProvider>
|
||||
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
|
||||
<Col span={24}>
|
||||
<Text strong>Description</Text>
|
||||
|
||||
@@ -36,6 +36,12 @@ const columns = (showPreviewModal, showEditModal, showDeleteDialog) => [
|
||||
key: 'sparepart_name',
|
||||
width: '20%',
|
||||
},
|
||||
{
|
||||
title: 'Sparepart Number',
|
||||
dataIndex: 'sparepart_number',
|
||||
key: 'sparepart_number',
|
||||
width: '20%',
|
||||
},
|
||||
{
|
||||
title: 'Description',
|
||||
dataIndex: 'sparepart_description',
|
||||
@@ -277,8 +283,8 @@ const ListSparepart = memo(function ListSparepart(props) {
|
||||
onStockUpdate={doFilter}
|
||||
onGetData={(data) => {
|
||||
if(data && data.length > 0) {
|
||||
console.log('Sample sparepart data from API:', data[0]);
|
||||
console.log('Available fields:', Object.keys(data[0] || {}));
|
||||
// console.log('Sample sparepart data from API:', data[0]);
|
||||
// console.log('Available fields:', Object.keys(data[0] || {}));
|
||||
}
|
||||
}} // Log untuk debugging field-field yang tersedia
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user