fix: acara kalender
Deskripsi: - toast saat hapus acara - realtime saat hapus acara No Issues
This commit is contained in:
@@ -22,6 +22,7 @@ export default function DateEventDivision() {
|
||||
const [isMonth, setMonth] = useState<any>(moment().month() + 1)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const isMobile = useMediaQuery('(max-width: 369px)');
|
||||
const [isDateChoose, setDataChoose] = useState<any>(moment().format('YYYY-MM-DD'))
|
||||
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||
WIBU_REALTIME_TOKEN: keyWibu,
|
||||
project: "sdm"
|
||||
@@ -37,7 +38,6 @@ export default function DateEventDivision() {
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
setLoading(false)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.error("Gagal mendapatkan list acara")
|
||||
@@ -63,6 +63,7 @@ export default function DateEventDivision() {
|
||||
|
||||
async function changeMonth(value: any) {
|
||||
const monthKlik = moment(value).format('MM')
|
||||
setDataChoose(value)
|
||||
if (monthKlik != isMonth) {
|
||||
setMonth(monthKlik)
|
||||
getIndicator(value)
|
||||
@@ -99,7 +100,7 @@ export default function DateEventDivision() {
|
||||
getIndicator(isDate)
|
||||
getData(isDate, false)
|
||||
} else if (dataRealTime && dataRealTime.some((i: any) => i.category == 'calendar-event' && i.division == param.id && i.date != isDate)) {
|
||||
getIndicator(isDate)
|
||||
getIndicator(isDateChoose)
|
||||
}
|
||||
}, [dataRealTime])
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import { FaUsers } from 'react-icons/fa6';
|
||||
import { useHookstate } from '@hookstate/core';
|
||||
import { useWibuRealtime } from 'wibu-realtime';
|
||||
|
||||
export default function DrawerDetailEvent({ idCalendar, close }: { idCalendar: string, close: (val:boolean) => void }) {
|
||||
export default function DrawerDetailEvent({ idCalendar, close }: { idCalendar: string, close: (val: boolean) => void }) {
|
||||
const router = useRouter()
|
||||
const [isModal, setModal] = useState(false)
|
||||
const param = useParams<{ id: string, detail: string }>()
|
||||
@@ -22,29 +22,27 @@ export default function DrawerDetailEvent({ idCalendar, close }: { idCalendar: s
|
||||
project: "sdm"
|
||||
})
|
||||
|
||||
async function fetchDeleteCalender(val: boolean) {
|
||||
async function fetchDeleteCalender() {
|
||||
try {
|
||||
if (val) {
|
||||
setLoadingDelete(true)
|
||||
const response = await funDeleteCalenderById(idCalendar)
|
||||
if (response.success) {
|
||||
setDataRealtime([
|
||||
{
|
||||
category: "calendar-detail-delete",
|
||||
id: idCalendar,
|
||||
},
|
||||
{
|
||||
category: "calendar-event",
|
||||
division: param.id,
|
||||
date: response.data.dateStart,
|
||||
idUserFrom: response.user
|
||||
}
|
||||
])
|
||||
toast.success(response.message)
|
||||
router.push(`/division/${param.id}/calender`)
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
setLoadingDelete(true)
|
||||
const response = await funDeleteCalenderById(idCalendar)
|
||||
if (response.success) {
|
||||
setDataRealtime([
|
||||
{
|
||||
category: "calendar-detail-delete",
|
||||
id: idCalendar,
|
||||
idUserFrom: response.user
|
||||
},
|
||||
{
|
||||
category: "calendar-event",
|
||||
division: param.id,
|
||||
date: response.data.dateStart,
|
||||
}
|
||||
])
|
||||
toast.success(response.message)
|
||||
router.push(`/division/${param.id}/calender`)
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -94,7 +92,13 @@ export default function DrawerDetailEvent({ idCalendar, close }: { idCalendar: s
|
||||
</Stack>
|
||||
<LayoutModal loading={loadingDelete} opened={isModal} onClose={() => setModal(false)}
|
||||
description="Apakah Anda yakin ingin menghapus data acara ini? Data ini akan mempengaruhi semua data yang terkait"
|
||||
onYes={(val) => { fetchDeleteCalender(val) }} />
|
||||
onYes={(val) => {
|
||||
if (val) {
|
||||
fetchDeleteCalender()
|
||||
} else {
|
||||
setModal(false)
|
||||
}
|
||||
}} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user