Refactor DetailDevice component: update form fields to include 'listen_channel_reminder' and 'reminder_at', replace 'scheduler_date' with 'reminder_at', and improve layout for input fields.

This commit is contained in:
2026-04-26 13:40:10 +07:00
parent d04f078c6c
commit 0ca2169a12

View File

@@ -1,5 +1,15 @@
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Modal, Input, Divider, Typography, Switch, Button, ConfigProvider, Select, DatePicker } from 'antd'; import {
Modal,
Input,
Divider,
Typography,
Switch,
Button,
ConfigProvider,
Select,
DatePicker,
} from 'antd';
import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif'; import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif';
import { createDevice, updateDevice } from '../../../../api/master-device'; import { createDevice, updateDevice } from '../../../../api/master-device';
import { getAllBrands } from '../../../../api/master-brand'; import { getAllBrands } from '../../../../api/master-brand';
@@ -14,8 +24,6 @@ const DetailDevice = (props) => {
const [confirmLoading, setConfirmLoading] = useState(false); const [confirmLoading, setConfirmLoading] = useState(false);
const [brands, setBrands] = useState([]); const [brands, setBrands] = useState([]);
const [loadingBrands, setLoadingBrands] = useState(false); const [loadingBrands, setLoadingBrands] = useState(false);
const dateNow = dayjs();
const [schedulerDate, setSchedulerDate] = useState(dateNow);
const defaultData = { const defaultData = {
device_id: '', device_id: '',
@@ -27,7 +35,7 @@ const DetailDevice = (props) => {
device_location: '', device_location: '',
device_description: '', device_description: '',
ip_address: '', ip_address: '',
scheduler_date: '', reminder_at: null,
listen_channel: '', listen_channel: '',
}; };
@@ -46,7 +54,6 @@ const DetailDevice = (props) => {
{ field: 'device_name', label: 'Device Name', required: true }, { field: 'device_name', label: 'Device Name', required: true },
{ field: 'ip_address', label: 'Ip Address', required: true, ip: true }, { field: 'ip_address', label: 'Ip Address', required: true, ip: true },
{ field: 'brand_id', label: 'Brand Device', required: true }, { field: 'brand_id', label: 'Brand Device', required: true },
{ field: 'scheduler_date', label: 'Tanggaln(Scheduler)', required: true },
]; ];
if ( if (
@@ -73,35 +80,36 @@ const DetailDevice = (props) => {
ip_address: formData.ip_address, ip_address: formData.ip_address,
brand_id: formData.brand_id, brand_id: formData.brand_id,
listen_channel: formData.listen_channel, listen_channel: formData.listen_channel,
scheduler_date: toApiDateFormatter(formData.scheduler_date) listen_channel_reminder: formData.listen_channel_reminder,
reminder_at: formData.reminder_at,
}; };
console.log(payload); console.log(payload);
// const response = formData.device_id const response = formData.device_id
// ? await updateDevice(formData.device_id, payload) ? await updateDevice(formData.device_id, payload)
// : await createDevice(payload); : await createDevice(payload);
// // Check if response is successful // Check if response is successful
// if (response && (response.statusCode === 200 || response.statusCode === 201)) { if (response && (response.statusCode === 200 || response.statusCode === 201)) {
// const deviceName = response.data?.device_name || formData.device_name; const deviceName = response.data?.device_name || formData.device_name;
// NotifOk({ NotifOk({
// icon: 'success', icon: 'success',
// title: 'Berhasil', title: 'Berhasil',
// message: `Data Device "${deviceName}" berhasil ${ message: `Data Device "${deviceName}" berhasil ${
// formData.device_id ? 'diubah' : 'ditambahkan' formData.device_id ? 'diubah' : 'ditambahkan'
// }.`, }.`,
// }); });
// props.setActionMode('list'); props.setActionMode('list');
// } else { } else {
// NotifAlert({ NotifAlert({
// icon: 'error', icon: 'error',
// title: 'Gagal', title: 'Gagal',
// message: response?.message || 'Terjadi kesalahan saat menyimpan data.', message: response?.message || 'Terjadi kesalahan saat menyimpan data.',
// }); });
// } }
} catch (error) { } catch (error) {
console.error('Save Device Error:', error); console.error('Save Device Error:', error);
NotifAlert({ NotifAlert({
@@ -347,8 +355,12 @@ const DetailDevice = (props) => {
readOnly={props.readOnly} readOnly={props.readOnly}
/> />
</div> </div>
<div style={{ marginBottom: 12 }}> <div style={{ marginBottom: 12 }}></div>
<Text strong>Listen Channel</Text> <div style={{ marginBottom: 12 }}></div>
<div style={{ display: 'flex', gap: 16 }}>
<div style={{ flex: 1 }}>
{' '}
<Text strong>Channel Error</Text>
<Input <Input
name="listen_channel" name="listen_channel"
value={formData.listen_channel} value={formData.listen_channel}
@@ -357,17 +369,50 @@ const DetailDevice = (props) => {
readOnly={props.readOnly} readOnly={props.readOnly}
/> />
</div> </div>
<div style={{ marginBottom: 12 }}> <div style={{ flex: 1 }}>
<Text strong>Scheduler Date</Text> <Text strong>Channel Reminder</Text>
<DatePicker <Input
value={formData.scheduler_date ? dayjs(formData.scheduler_date, 'DD-MM-YYYY') : ''} name="listen_channel_reminder"
onChange={(date, dateString) => value={formData.listen_channel_reminder}
handleDateChange("scheduler_date", dateString) onChange={handleInputChange}
} placeholder="Enter Listen Channel Reminder"
format="DD-MM-YYYY" readOnly={props.readOnly}
style={{ width: '100%', marginTop: '4px' }}
/> />
</div> </div>
</div>
<div style={{ marginBottom: 12 }}>
<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 }}> <div style={{ marginBottom: 12 }}>
<Text strong>Device Description</Text> <Text strong>Device Description</Text>
<TextArea <TextArea