Merge pull request #368 from bipproduction/amalia/07-jan-25
Amalia/07 jan 25
This commit is contained in:
@@ -193,4 +193,44 @@ export async function POST(request: Request) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal membuat acara kalender, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// CEK TGL AVAILABLE
|
||||
export async function PUT(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 { idDivision, title, desc, timeStart, timeEnd, dateStart, dateEnd, repeatEventTyper, member, linkMeet, repeatValue } = (await request.json());
|
||||
const division = await prisma.division.findUnique({
|
||||
where: {
|
||||
id: idDivision
|
||||
}
|
||||
})
|
||||
|
||||
const cek = await prisma.divisionCalendarReminder.count({
|
||||
where: {
|
||||
isActive: true,
|
||||
dateStart: new Date(dateStart),
|
||||
Division: {
|
||||
idGroup: division?.idGroup
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
if (cek > 0) {
|
||||
return NextResponse.json({ success: false, message: "Tidak dapat membuat acara kalender, acara kalender sudah ada pada tanggal tersebut" }, { status: 400 });
|
||||
} else {
|
||||
return NextResponse.json({ success: true, message: "Berhasil membuat acara kalender" }, { status: 200 });
|
||||
}
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
return NextResponse.json({ success: false, message: "Gagal membuat acara kalender, coba lagi nanti (error: 500)" }, { status: 404 });
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,18 @@ export const funGetOneCalenderByIdCalendar = async (path: string) => {
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
|
||||
export const funCheckCalender = async (data: IFormCreateCalender) => {
|
||||
const response = await fetch("/api/calender", {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
}
|
||||
|
||||
export const funCreateCalender = async (data: IFormCreateCalender) => {
|
||||
const response = await fetch("/api/calender", {
|
||||
method: "POST",
|
||||
@@ -67,11 +79,11 @@ export const funAddMemberCalender = async (path: string, data: IFormMemberCalend
|
||||
|
||||
export const funDeleteMemberCalender = async (path: string, data: { idUser: string }) => {
|
||||
const response = await fetch(`/api/calender/${path}/member`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
});
|
||||
return await response.json().catch(() => null);
|
||||
};
|
||||
};
|
||||
@@ -11,7 +11,7 @@ import { useState } from 'react';
|
||||
import toast from 'react-hot-toast';
|
||||
import { IoIosArrowDropright } from 'react-icons/io';
|
||||
import { useWibuRealtime } from 'wibu-realtime';
|
||||
import { funCreateCalender } from '../lib/api_calender';
|
||||
import { funCheckCalender, funCreateCalender } from '../lib/api_calender';
|
||||
import { IFormMemberCalender } from '../lib/type_calender';
|
||||
import { globalCalender } from '../lib/val_calender';
|
||||
import CreateUserCalender from './create_user_calender';
|
||||
@@ -20,7 +20,9 @@ export default function CreateCalenderDivisionCaleder() {
|
||||
const [value, setValue] = useState<Date | null>(null);
|
||||
const router = useRouter()
|
||||
const [isModal, setModal] = useState(false)
|
||||
const [isModalKonfirmasiTglSama, setModalKonfirmasiTglSama] = useState(false)
|
||||
const [loadingModal, setLoadingModal] = useState(false)
|
||||
const [loadingModalKonfirmasiTglSama, setLoadingModalKonfirmasiTglSama] = useState(false)
|
||||
const member = useHookstate(globalCalender)
|
||||
const memberValue = member.get() as IFormMemberCalender[]
|
||||
const [openMember, setOpenMember] = useState(false)
|
||||
@@ -53,10 +55,40 @@ export default function CreateCalenderDivisionCaleder() {
|
||||
project: "sdm"
|
||||
})
|
||||
|
||||
|
||||
async function onSubmit(val: boolean) {
|
||||
async function onCheckDate() {
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
const response = await funCheckCalender({
|
||||
idDivision: param.id,
|
||||
title: isData.title,
|
||||
dateStart: isData.dateStart,
|
||||
timeStart: isData.timeStart,
|
||||
timeEnd: isData.timeEnd,
|
||||
linkMeet: isData.linkMeet,
|
||||
repeatEventTyper: isData.repeatEventTyper,
|
||||
desc: isData.desc,
|
||||
repeatValue: isData.repeatValue,
|
||||
member: memberValue
|
||||
})
|
||||
|
||||
if (response.success) {
|
||||
onSubmit()
|
||||
} else {
|
||||
setModalKonfirmasiTglSama(true)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.error("Gagal menambahkan acara, coba lagi nanti");
|
||||
} finally {
|
||||
setLoadingModal(false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function onSubmit() {
|
||||
try {
|
||||
setLoadingModal(true)
|
||||
setLoadingModalKonfirmasiTglSama(true)
|
||||
const response = await funCreateCalender({
|
||||
idDivision: param.id,
|
||||
title: isData.title,
|
||||
@@ -76,20 +108,20 @@ export default function CreateCalenderDivisionCaleder() {
|
||||
division: param.id,
|
||||
date: isData.dateStart
|
||||
}])
|
||||
setModal(false)
|
||||
router.push(`/division/${param.id}/calender`)
|
||||
toast.success(response.message)
|
||||
member.set([])
|
||||
} else {
|
||||
toast.error(response.message)
|
||||
setModal(false)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
toast.error("Gagal menambahkan pengumuman, coba lagi nanti");
|
||||
toast.error("Gagal menambahkan acara, coba lagi nanti");
|
||||
} finally {
|
||||
setModal(false)
|
||||
setModalKonfirmasiTglSama(false)
|
||||
setLoadingModal(false)
|
||||
setLoadingModalKonfirmasiTglSama(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -381,8 +413,7 @@ export default function CreateCalenderDivisionCaleder() {
|
||||
member.get().map((v: any, i: any) => {
|
||||
return (
|
||||
<Box key={i}>
|
||||
<Grid align='center' mt={10}
|
||||
>
|
||||
<Grid align='center' mt={10} >
|
||||
<Grid.Col span={1}>
|
||||
<Avatar src={`https://wibu-storage.wibudev.com/api/files/${v.img}`} alt="it's me" size={'lg'} />
|
||||
</Grid.Col>
|
||||
@@ -430,11 +461,27 @@ export default function CreateCalenderDivisionCaleder() {
|
||||
description="Apakah Anda yakin ingin menambahkan data?"
|
||||
onYes={(val) => {
|
||||
if (val) {
|
||||
onSubmit(val)
|
||||
onCheckDate()
|
||||
} else {
|
||||
setModal(false)
|
||||
}
|
||||
}} />
|
||||
|
||||
|
||||
<LayoutModal loading={loadingModalKonfirmasiTglSama} opened={isModalKonfirmasiTglSama}
|
||||
onClose={() => {
|
||||
setModalKonfirmasiTglSama(false)
|
||||
setModal(false)
|
||||
}}
|
||||
description="Sudah ada acara pada tanggal yang sama. Apakah Anda yakin ingin menambahkan data?"
|
||||
onYes={(val) => {
|
||||
if (val) {
|
||||
onSubmit()
|
||||
} else {
|
||||
setModalKonfirmasiTglSama(false)
|
||||
setModal(false)
|
||||
}
|
||||
}} />
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -275,7 +275,7 @@ export default function DetailDiscussion({ id, idDivision }: { id: string, idDiv
|
||||
</Box>
|
||||
</Grid.Col>
|
||||
<Grid.Col span={3}>
|
||||
<Text c={"grey"} ta={"end"} fz={13}>{moment(v.createdAt).format("ll")}</Text>
|
||||
<Text c={"grey"} ta={"end"} fz={13}>{moment(v.createdAt).format("lll").replace('pukul', '')}</Text>
|
||||
</Grid.Col>
|
||||
</Grid>
|
||||
<Box mt={10}>
|
||||
|
||||
Reference in New Issue
Block a user