diff --git a/app/actions/issue.ts b/app/actions/issue.ts index b138f8b..84c81bc 100644 --- a/app/actions/issue.ts +++ b/app/actions/issue.ts @@ -2,6 +2,8 @@ import prisma from '@/prisma/client'; +export const dynamic = 'force-dynamic'; + export const getIssueDetail = async (id: number) => { const issue = await prisma.issue.findUnique({ where: { id }, diff --git a/app/api/issue/route.ts b/app/api/issue/route.ts index 310f443..50b8a0e 100644 --- a/app/api/issue/route.ts +++ b/app/api/issue/route.ts @@ -4,6 +4,8 @@ import { NextResponse } from 'next/server'; import { createIssueSchema, searchParamsSchema } from '@/lib/validators'; import prisma from '@/prisma/client'; +export const dynamic = 'force-dynamic'; + export const POST = async (req: NextRequest) => { const body = await req.json(); const validation = createIssueSchema.safeParse(body); diff --git a/app/dashboard/issue/board/Board.tsx b/app/dashboard/issue/board/Board.tsx index 5177bc9..1a832d0 100644 --- a/app/dashboard/issue/board/Board.tsx +++ b/app/dashboard/issue/board/Board.tsx @@ -5,6 +5,7 @@ import type { Status } from '@prisma/client'; import React, { useState } from 'react'; import useUpdateIssue from '@/hooks/issue/useUpdateIssue'; +import { groupBy } from '@/lib/utils'; import type { Issue } from '@/types'; import Column from './Column'; @@ -27,7 +28,7 @@ const Board = ({ data }: React.PropsWithChildren) => { const { mutate: updateIssueStatus } = useUpdateIssue(); const [taskStages, setTaskStages] = useState({ ...initialState, - ...Object.groupBy(data, (item) => item.status), + ...groupBy(data, (item) => item.status), }); const handleOnDragEnd = (event: DragEndEvent) => { diff --git a/lib/utils.ts b/lib/utils.ts index f057739..343030e 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -14,3 +14,22 @@ export function formatDate(dateString: string, locales?: Intl.LocalesArgument) { export function capitalize(label: string) { return label.charAt(0).toUpperCase().concat(label.slice(1).toLowerCase()); } + +export function groupBy( + list: Type[], + keyGetter: (item: Type) => Type[Key], +): Record { + const map = new Map(); + + list.forEach((item) => { + const key = keyGetter(item); + const collection = map.get(key); + if (!collection) { + map.set(key, [item]); + } else { + collection.push(item); + } + }); + + return Object.fromEntries(map); +}