upd: calendar
Deskripsi: - realtime list event calender No Issues
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import { LayoutNavbarNew, TEMA } from '@/module/_global';
|
import { keyWibu, LayoutNavbarNew, TEMA } from '@/module/_global';
|
||||||
import LayoutModal from '@/module/_global/layout/layout_modal';
|
import LayoutModal from '@/module/_global/layout/layout_modal';
|
||||||
import { useHookstate } from '@hookstate/core';
|
import { useHookstate } from '@hookstate/core';
|
||||||
import { Avatar, Box, Button, Divider, Grid, Group, rem, Select, SimpleGrid, Stack, Text, Textarea, TextInput } from '@mantine/core';
|
import { Avatar, Box, Button, Divider, Grid, Group, rem, Select, SimpleGrid, Stack, Text, Textarea, TextInput } from '@mantine/core';
|
||||||
@@ -10,6 +10,7 @@ import { useParams, useRouter } from 'next/navigation';
|
|||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import { IoIosArrowDropright } from 'react-icons/io';
|
import { IoIosArrowDropright } from 'react-icons/io';
|
||||||
|
import { useWibuRealtime } from 'wibu-realtime';
|
||||||
import { funCreateCalender } from '../lib/api_calender';
|
import { funCreateCalender } from '../lib/api_calender';
|
||||||
import { IFormMemberCalender } from '../lib/type_calender';
|
import { IFormMemberCalender } from '../lib/type_calender';
|
||||||
import { globalCalender } from '../lib/val_calender';
|
import { globalCalender } from '../lib/val_calender';
|
||||||
@@ -47,6 +48,11 @@ export default function CreateCalenderDivisionCaleder() {
|
|||||||
desc: "",
|
desc: "",
|
||||||
repeatValue: "1"
|
repeatValue: "1"
|
||||||
})
|
})
|
||||||
|
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||||
|
WIBU_REALTIME_TOKEN: keyWibu,
|
||||||
|
project: "sdm"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
async function onSubmit(val: boolean) {
|
async function onSubmit(val: boolean) {
|
||||||
try {
|
try {
|
||||||
@@ -65,6 +71,11 @@ export default function CreateCalenderDivisionCaleder() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
setDataRealtime([{
|
||||||
|
category: "calendar-event",
|
||||||
|
division: param.id,
|
||||||
|
date: isData.dateStart
|
||||||
|
}])
|
||||||
setModal(false)
|
setModal(false)
|
||||||
router.push(`/division/${param.id}/calender`)
|
router.push(`/division/${param.id}/calender`)
|
||||||
toast.success(response.message)
|
toast.success(response.message)
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
|
import { keyWibu } from '@/module/_global';
|
||||||
import { Box, Divider, Flex, Grid, Group, Indicator, Skeleton, Text } from '@mantine/core';
|
import { Box, Divider, Flex, Grid, Group, Indicator, Skeleton, Text } from '@mantine/core';
|
||||||
import { DatePicker, DatePickerProps } from '@mantine/dates';
|
import { DatePicker, DatePickerProps } from '@mantine/dates';
|
||||||
import { useParams, useRouter } from 'next/navigation';
|
|
||||||
import React, { useState } from 'react';
|
|
||||||
import { funGetAllCalender, funGetIndicatorCalender } from '../lib/api_calender';
|
|
||||||
import { useMediaQuery, useSetState, useShallowEffect } from '@mantine/hooks';
|
import { useMediaQuery, useSetState, useShallowEffect } from '@mantine/hooks';
|
||||||
import { IDataCalender } from '../lib/type_calender';
|
import 'dayjs/locale/id';
|
||||||
import moment from 'moment';
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import moment from 'moment';
|
||||||
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
|
import { useState } from 'react';
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import 'dayjs/locale/id'
|
import { useWibuRealtime } from 'wibu-realtime';
|
||||||
|
import { funGetAllCalender, funGetIndicatorCalender } from '../lib/api_calender';
|
||||||
|
import { IDataCalender } from '../lib/type_calender';
|
||||||
|
|
||||||
|
|
||||||
export default function DateEventDivision() {
|
export default function DateEventDivision() {
|
||||||
@@ -20,11 +22,15 @@ export default function DateEventDivision() {
|
|||||||
const [isMonth, setMonth] = useState<any>(moment().month() + 1)
|
const [isMonth, setMonth] = useState<any>(moment().month() + 1)
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const isMobile = useMediaQuery('(max-width: 369px)');
|
const isMobile = useMediaQuery('(max-width: 369px)');
|
||||||
|
const [dataRealTime, setDataRealtime] = useWibuRealtime({
|
||||||
|
WIBU_REALTIME_TOKEN: keyWibu,
|
||||||
|
project: "sdm"
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
const getData = async (tgl: any) => {
|
const getData = async (tgl: any, loading: boolean) => {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(loading)
|
||||||
const response = await funGetAllCalender('?division=' + param.id + '&date=' + tgl)
|
const response = await funGetAllCalender('?division=' + param.id + '&date=' + tgl)
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
setData(response.data)
|
setData(response.data)
|
||||||
@@ -66,12 +72,12 @@ export default function DateEventDivision() {
|
|||||||
function change(val: Date) {
|
function change(val: Date) {
|
||||||
const a: any = moment(new Date(val)).format('YYYY-MM-DD')
|
const a: any = moment(new Date(val)).format('YYYY-MM-DD')
|
||||||
setDate(a)
|
setDate(a)
|
||||||
getData(a)
|
getData(a, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
useShallowEffect(() => {
|
useShallowEffect(() => {
|
||||||
getData(isDate)
|
getData(isDate, true)
|
||||||
getIndicator(isDate)
|
getIndicator(isDate)
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
@@ -88,6 +94,15 @@ export default function DateEventDivision() {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useShallowEffect(() => {
|
||||||
|
if (dataRealTime && dataRealTime.some((i: any) => i.category == 'calendar-event' && i.division == param.id && i.date == isDate)) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}, [dataRealTime])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user