Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/node version #12

Merged
merged 2 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/actions/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
2 changes: 2 additions & 0 deletions app/api/issue/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion app/dashboard/issue/board/Board.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -27,7 +28,7 @@ const Board = ({ data }: React.PropsWithChildren<Props>) => {
const { mutate: updateIssueStatus } = useUpdateIssue();
const [taskStages, setTaskStages] = useState({
...initialState,
...Object.groupBy(data, (item) => item.status),
...groupBy<Issue, 'status'>(data, (item) => item.status),
});

const handleOnDragEnd = (event: DragEndEvent) => {
Expand Down
19 changes: 19 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Type, Key extends keyof Type>(
list: Type[],
keyGetter: (item: Type) => Type[Key],
): Record<Key, Type[]> {
const map = new Map<Type[Key], Type[]>();

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);
}
Loading