lavoce #55
@@ -35,8 +35,11 @@ const DetailDevice = (props) => {
|
|||||||
device_location: '',
|
device_location: '',
|
||||||
device_description: '',
|
device_description: '',
|
||||||
ip_address: '',
|
ip_address: '',
|
||||||
reminder_at: null,
|
|
||||||
listen_channel: null,
|
listen_channel: null,
|
||||||
|
reminder_at: null,
|
||||||
|
reminder_at_monthly: null,
|
||||||
|
start_date: null,
|
||||||
|
end_date: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
const [formData, setFormData] = useState(defaultData);
|
const [formData, setFormData] = useState(defaultData);
|
||||||
@@ -82,6 +85,9 @@ const DetailDevice = (props) => {
|
|||||||
listen_channel: formData.listen_channel,
|
listen_channel: formData.listen_channel,
|
||||||
listen_channel_reminder: formData.listen_channel_reminder,
|
listen_channel_reminder: formData.listen_channel_reminder,
|
||||||
reminder_at: formData.reminder_at,
|
reminder_at: formData.reminder_at,
|
||||||
|
reminder_at_monthly: formData.reminder_at_monthly,
|
||||||
|
start_date: formData.start_date,
|
||||||
|
end_date: formData.end_date,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(payload);
|
console.log(payload);
|
||||||
@@ -174,10 +180,18 @@ const DetailDevice = (props) => {
|
|||||||
|
|
||||||
const [period, setPeriod] = useState({
|
const [period, setPeriod] = useState({
|
||||||
period: undefined,
|
period: undefined,
|
||||||
start_date: null,
|
|
||||||
end_date: null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (period.period !== 'custom') {
|
||||||
|
setFormData((prev) => ({
|
||||||
|
...prev,
|
||||||
|
start_date: null,
|
||||||
|
end_date: null,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}, [period.period]);
|
||||||
|
|
||||||
const handleMonthly = (field, value) => {
|
const handleMonthly = (field, value) => {
|
||||||
setPeriod((prev) => ({
|
setPeriod((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
@@ -446,24 +460,23 @@ const DetailDevice = (props) => {
|
|||||||
<div style={{ display: 'flex', gap: 8, marginBottom: 12 }}>
|
<div style={{ display: 'flex', gap: 8, marginBottom: 12 }}>
|
||||||
<DatePicker
|
<DatePicker
|
||||||
placeholder="Start Date"
|
placeholder="Start Date"
|
||||||
value={period.start_date ? dayjs(period.start_date) : null}
|
value={formData.start_date ? dayjs(formData.start_date) : null}
|
||||||
onChange={(date) =>
|
onChange={(date) =>
|
||||||
setPeriod((prev) => ({
|
handleDateChange('start_date', date ? date.toISOString() : null)
|
||||||
...prev,
|
|
||||||
start_date: date ? date.toISOString() : null,
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
style={{ flex: 1 }}
|
style={{ flex: 1 }}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<DatePicker
|
<DatePicker
|
||||||
placeholder="End Date"
|
placeholder="End Date"
|
||||||
value={period.end_date ? dayjs(period.end_date) : null}
|
value={formData.end_date ? dayjs(formData.end_date) : null}
|
||||||
onChange={(date) =>
|
onChange={(date) =>
|
||||||
setPeriod((prev) => ({
|
handleDateChange('end_date', date ? date.toISOString() : null)
|
||||||
...prev,
|
}
|
||||||
end_date: date ? date.toISOString() : null,
|
disabledDate={(current) =>
|
||||||
}))
|
formData.start_date &&
|
||||||
|
current &&
|
||||||
|
current.isBefore(dayjs(formData.start_date), 'day')
|
||||||
}
|
}
|
||||||
style={{ flex: 1 }}
|
style={{ flex: 1 }}
|
||||||
/>
|
/>
|
||||||
@@ -475,13 +488,13 @@ const DetailDevice = (props) => {
|
|||||||
<DatePicker
|
<DatePicker
|
||||||
disabled={period.period === 'custom'}
|
disabled={period.period === 'custom'}
|
||||||
value={
|
value={
|
||||||
formData.reminder_at
|
formData.reminder_at_monthly
|
||||||
? dayjs(formData.reminder_at) // ✅ langsung parse ISO
|
? dayjs(formData.reminder_at_monthly) // ✅ langsung parse ISO
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
onChange={(date) =>
|
onChange={(date) =>
|
||||||
handleDateChange(
|
handleDateChange(
|
||||||
'reminder_at',
|
'reminder_at_monthly',
|
||||||
date ? date.toISOString() : null
|
date ? date.toISOString() : null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -496,7 +509,7 @@ const DetailDevice = (props) => {
|
|||||||
onClick={() =>
|
onClick={() =>
|
||||||
setFormData((prev) => ({
|
setFormData((prev) => ({
|
||||||
...prev,
|
...prev,
|
||||||
reminder_at: null,
|
reminder_at_monthly: null,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user