Compare commits

...

2 Commits

Author SHA1 Message Date
e02aa92c64 fix(notif): fixing for notification Monthly 2026-07-08 12:36:29 +07:00
276a75f13f fix(showTime): show time in datePicker 2026-06-30 11:57:49 +07:00
3 changed files with 92 additions and 27 deletions

View File

@@ -91,6 +91,25 @@ const searchData = async (queryParams) => {
return response.data;
};
// Reminder Monthly
const reminderMonthly = async (id, queryParams) => {
const response = await SendRequest({
method: 'post',
prefix: `notifikasi-wa/reminder-monthly/${id}`,
params: queryParams,
});
return response.data;
};
const reminderCustom= async (id, queryParams) => {
const response = await SendRequest({
method: 'post',
prefix: `notifikasi-wa/reminder-custom/${id}`,
params: queryParams,
});
return response.data;
};
export {
getAllNotification,
getNotificationById,
@@ -102,4 +121,6 @@ export {
resendChatByUser,
resendChatAllUser,
searchData,
reminderMonthly,
reminderCustom,
};

View File

@@ -20,6 +20,19 @@ const NotifOk = ({ icon, title, message }) => {
});
};
const NotifSmall = ({ icon, title, message }) => {
Swal.fire({
toast: true,
position: 'top-end',
icon: icon,
title: title,
text: message,
showConfirmButton: false,
timer: 2000,
timerProgressBar: true,
});
};
const NotifConfirmDialog = ({
icon,
title,
@@ -67,4 +80,4 @@ const QuestionConfirmSubmit = ({ icon, title, message, onConfirm, onCancel }) =>
});
};
export { NotifAlert, NotifOk, NotifConfirmDialog, QuestionConfirmSubmit };
export { NotifAlert, NotifOk, NotifSmall, NotifConfirmDialog, QuestionConfirmSubmit };

View File

@@ -10,8 +10,9 @@ import {
Select,
DatePicker,
} from 'antd';
import { NotifAlert, NotifOk } from '../../../../components/Global/ToastNotif';
import { NotifAlert, NotifOk, NotifSmall } from '../../../../components/Global/ToastNotif';
import { createDevice, updateDevice } from '../../../../api/master-device';
import { reminderMonthly, reminderCustom } from '../../../../api/notification';
import { getAllBrands } from '../../../../api/master-brand';
import { validateRun } from '../../../../Utils/validate';
import { toApiDateFormatter } from '../../../../components/Global/Formatter';
@@ -40,6 +41,7 @@ const DetailDevice = (props) => {
reminder_at_monthly: null,
start_date: null,
end_date: null,
period: null,
};
const [formData, setFormData] = useState(defaultData);
@@ -85,7 +87,7 @@ const DetailDevice = (props) => {
listen_channel: formData.listen_channel,
listen_channel_reminder: formData.listen_channel_reminder,
reminder_at: formData.reminder_at,
reminder_at_monthly: formData.reminder_at_monthly,
reminder_at_monthly: formData.period !== 'custom' ? formData.reminder_at_monthly : null,
start_date: formData.start_date,
end_date: formData.end_date,
};
@@ -96,6 +98,13 @@ const DetailDevice = (props) => {
? await updateDevice(formData.device_id, payload)
: await createDevice(payload);
const response2 = formData.period !== 'custom'
? await updateDevice(formData.device_id, { reminder_at_monthly: formData.reminder_at_monthly,})
: await updateDevice(formData.device_id, {
start_date: formData.start_date,
end_date: formData.end_date,
});
// Check if response is successful
if (response && (response.statusCode === 200 || response.statusCode === 201)) {
const deviceName = response.data?.device_name || formData.device_name;
@@ -116,6 +125,25 @@ const DetailDevice = (props) => {
message: response?.message || 'Terjadi kesalahan saat menyimpan data.',
});
}
// Check if response Reminder At(Monthly) or Period are successful
const tipe = formData.period !== 'custom' ? 'Reminder At(Monthly)' : 'Period';
if (response2 && (response2.statusCode === 200 || response2.statusCode === 201)) {
NotifSmall({
icon: 'success',
title: 'Berhasil',
message: `${tipe} berhasil disimpan`,
});
} else {
NotifSmall({
icon: 'error',
title: 'Gagal',
message:
response?.message ||
`Terjadi kesalahan saat menyimpan ${tipe}`,
});
}
} catch (error) {
console.error('Save Device Error:', error);
NotifAlert({
@@ -178,10 +206,6 @@ const DetailDevice = (props) => {
}
};
const [period, setPeriod] = useState({
period: undefined,
});
useEffect(() => {
if (formData.start_date && formData.end_date) {
const start = dayjs(formData.start_date);
@@ -197,36 +221,39 @@ const DetailDevice = (props) => {
periodValue = '6';
}
setPeriod({
setFormData((prev) => ({
...prev,
period: periodValue,
});
}));
}
}, [formData.start_date, formData.end_date]);
const handleMonthly = (field, value) => {
setPeriod((prev) => ({
setFormData((prev) => {
const data = {
...prev,
[field]: value,
}));
};
if (value !== 'custom') {
const months = Number(value);
const startDate = dayjs().startOf('day');
const endDate = startDate.add(months, 'month').subtract(1, 'day').endOf('day');
const endDate = startDate
.add(months, 'month')
.subtract(1, 'day')
.endOf('day');
setFormData((prev) => ({
...prev,
start_date: startDate.toISOString(),
end_date: endDate.toISOString(),
}));
data.start_date = startDate.toISOString();
data.end_date = endDate.toISOString();
data.reminder_at_monthly = null;
} else {
setFormData((prev) => ({
...prev,
start_date: null,
end_date: null,
}));
data.start_date = null;
data.end_date = null;
}
return data;
});
};
useEffect(() => {
@@ -475,7 +502,7 @@ const DetailDevice = (props) => {
<Text style={{ color: 'red' }}> *</Text>
<Select
value={period.period}
value={formData.period}
onChange={(value) => handleMonthly('period', value)}
placeholder="Select Period"
style={{ width: '100%' }}
@@ -486,7 +513,7 @@ const DetailDevice = (props) => {
<Select.Option value="custom">Custom</Select.Option>
</Select>
</div>
{period.period === 'custom' && (
{formData.period === 'custom' && (
<div style={{ display: 'flex', gap: 8, marginBottom: 12 }}>
<DatePicker
placeholder="Start Date"
@@ -499,6 +526,8 @@ const DetailDevice = (props) => {
current &&
current.isAfter(dayjs(formData.end_date), 'day')
}
format="DD-MM-YYYY HH:mm"
showTime={{ format: 'HH:mm' }}
style={{ flex: 1 }}
/>
@@ -513,6 +542,8 @@ const DetailDevice = (props) => {
current &&
current.isBefore(dayjs(formData.start_date), 'day')
}
format="DD-MM-YYYY HH:mm"
showTime={{ format: 'HH:mm' }}
style={{ flex: 1 }}
/>
</div>
@@ -521,7 +552,7 @@ const DetailDevice = (props) => {
<Text strong>Reminder At(Monthly)</Text>
<div style={{ display: 'flex', gap: 8, alignItems: 'center' }}>
<DatePicker
disabled={period.period === 'custom'}
disabled={formData.period === 'custom'}
value={
formData.reminder_at_monthly
? dayjs(formData.reminder_at_monthly) // ✅ langsung parse ISO
@@ -539,7 +570,7 @@ const DetailDevice = (props) => {
/>
<Button
disabled={period.period === 'custom'}
disabled={formData.period === 'custom'}
danger
onClick={() =>
setFormData((prev) => ({