Merge pull request #118 from bipproduction/lukman/15-agustus-2024
feat : update calender
This commit is contained in:
@@ -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 />
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
0
src/app/api/calender/[id]/route.ts
Normal file
0
src/app/api/calender/[id]/route.ts
Normal file
68
src/app/api/calender/route.ts
Normal file
68
src/app/api/calender/route.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
@@ -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: {
|
||||
|
||||
3
src/module/calender/index.ts
Normal file
3
src/module/calender/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import NavbarDivisionCalender from "./ui/navbar_division_calender";
|
||||
|
||||
export { NavbarDivisionCalender }
|
||||
4
src/module/calender/lib/api_calender.ts
Normal file
4
src/module/calender/lib/api_calender.ts
Normal 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);
|
||||
}
|
||||
10
src/module/calender/lib/type_calender.ts
Normal file
10
src/module/calender/lib/type_calender.ts
Normal 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
|
||||
}
|
||||
@@ -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"}
|
||||
@@ -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>
|
||||
);
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ export interface IDataKalenderOnDetailDivision {
|
||||
|
||||
export interface IDataDiscussionOnDetailDivision {
|
||||
id: string,
|
||||
desc: string,
|
||||
title: string,
|
||||
date: string,
|
||||
user: string
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user