feat : update calender

This commit is contained in:
lukman
2024-08-15 11:53:26 +08:00
parent d34a0a1a82
commit 2cfa96c0ed
14 changed files with 121 additions and 9 deletions

View File

@@ -1,11 +1,12 @@
import { ViewDetailEventDivision, ViewDivisionCalender } from '@/module/division_new';
import { NavbarDivisionCalender } from '@/module/calender';
import { ViewDetailEventDivision } from '@/module/division_new';
import React from 'react';
function Page({ searchParams }: { searchParams: any }) {
if (searchParams.page == "detail-event")
return <ViewDetailEventDivision />
return (
<ViewDivisionCalender />
<NavbarDivisionCalender />
);
}

View File

View File

@@ -0,0 +1,68 @@
import { User } from './../../../module/discussion/lib/type_discussion';
import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import _ from "lodash";
import moment from "moment";
import { NextResponse } from "next/server";
//GET ALL CALENDER
export async function GET(request: Request) {
try {
const user = await funGetUserByCookies()
if (user.id == undefined) {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const { searchParams } = new URL(request.url);
const idDivision = searchParams.get("division");
if (idDivision != "null" && idDivision != null && idDivision != undefined) {
const cekDivision = await prisma.division.count({
where: {
id: idDivision,
isActive: true
}
})
if (cekDivision == 0) {
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan" }, { status: 404 });
}
const data = await prisma.divisionCalendar.findMany({
where: {
isActive: true,
idDivision: idDivision,
},
select: {
id: true,
title: true,
desc: true,
status: true,
dateStart: true,
dateEnd: true,
createdAt: true,
User: {
select: {
name: true
}
}
}
});
const allOmit = data.map((v: any) => ({
..._.omit(v, ["User"]),
user_name: v.User.name
}))
return NextResponse.json({ success: true, message: "Berhasil mendapatkan calender", data: allOmit }, { status: 200 });
} else {
return NextResponse.json({ success: false, message: "Gagal mendapatkan calender, data tidak ditemukan" }, { status: 404 });
}
} catch (error) {
console.log(error)
return NextResponse.json({ success: false, message: "Gagal mendapatkan calender, data tidak ditemukan" }, { status: 404 });
}
}

View File

@@ -126,6 +126,7 @@ export async function GET(request: Request, context: { params: { id: string } })
select: {
id: true,
title: true,
desc: true,
createdAt: true,
User: {
select: {

View File

@@ -0,0 +1,3 @@
import NavbarDivisionCalender from "./ui/navbar_division_calender";
export { NavbarDivisionCalender }

View File

@@ -0,0 +1,4 @@
export const funGetAllCalender = async (path?: string) => {
const response = await fetch(`/api/calender${(path) ? path : ''}`, { next: { tags: ['calender'] } });
return await response.json().catch(() => null);
}

View File

@@ -0,0 +1,10 @@
export interface IDataCalender {
id: string
title: string
desc: string
status: number
dateStart: string
dateEnd: string
createdAt: string
user_name: string
}

View File

@@ -1,8 +1,11 @@
import { WARNA } from '@/module/_global';
import { Box, Divider, Group, Indicator, Text } from '@mantine/core';
import { DatePicker, DatePickerProps } from '@mantine/dates';
import { useRouter } from 'next/navigation';
import React from 'react';
import { useParams, useRouter } from 'next/navigation';
import React, { useState } from 'react';
import { funGetAllCalender } from '../lib/api_calender';
import { useShallowEffect } from '@mantine/hooks';
import { IDataCalender } from '../lib/type_calender';
const HariIni = [
{
@@ -38,7 +41,24 @@ const Besok = [
]
export default function DateEventDivision() {
const[isData, setData] = useState<IDataCalender[]>([])
const router = useRouter()
const param = useParams<{ id: string }>()
const getData = async () => {
try {
const response = await funGetAllCalender('?division=' + param.id)
setData(response.data)
} catch (error) {
console.log(error)
}
}
useShallowEffect(() => {
getData()
}, [])
const dayRenderer: DatePickerProps['renderDay'] = (date) => {
const day = date.getDate();
return (
@@ -49,6 +69,7 @@ export default function DateEventDivision() {
};
return (
<Box>
<pre>{JSON.stringify(isData, null, 1)}</pre>
<Group
justify="center"
bg={"white"}

View File

@@ -18,10 +18,10 @@ export default function NavbarDivisionCalender() {
}
/>
<Box p={20}>
<DateEventDivision/>
<DateEventDivision />
</Box>
<LayoutDrawer opened={openDrawer} title={'Menu'} onClose={() => setOpenDrawer(false)}>
<DawerDivisionCalender/>
<DawerDivisionCalender />
</LayoutDrawer>
</div>
);

View File

@@ -38,6 +38,9 @@ export default function DetailDiscussion({ id, idDivision }: { id: string, idDiv
const sendComent = async () => {
try {
if (isComent.trim() == "") {
return toast.error("Masukkan Komentar Anda")
}
const response = await funCreateComent(id, {
comment: isComent,
idDiscussion: param.detail

View File

@@ -1,11 +1,11 @@
import React from 'react';
import NavbarDivisionCalender from '../components/navbar_division_calender';
import NavbarDivisionCalender from '../../../../calender/ui/navbar_division_calender';
import { Box } from '@mantine/core';
export default function ViewDivisionCalender() {
return (
<Box>
<NavbarDivisionCalender/>
<NavbarDivisionCalender />
</Box>
);
}

View File

@@ -44,6 +44,7 @@ export interface IDataKalenderOnDetailDivision {
export interface IDataDiscussionOnDetailDivision {
id: string,
desc: string,
title: string,
date: string,
user: string

View File

@@ -116,7 +116,7 @@ export default function ListDiscussionOnDetailDivision() {
<GoDiscussionClosed size={25} />
<Box w={{ base: 230, md: 400 }}>
<Text fw={"bold"} truncate="end">
{v.title}
{v.desc}
</Text>
</Box>
</Group>