From 8ef97bf854027c7fa662c0ce86c711ce9128d100 Mon Sep 17 00:00:00 2001 From: Ahmad <103906421+ahmadk953@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:01:41 -0400 Subject: [PATCH] Added Ability to add Due Dates to Cards --- actions/update-card/index.ts | 3 +- actions/update-card/schema.ts | 10 ++ .../board/[boardId]/_components/card-item.tsx | 6 + components/modals/card-modal/actions.tsx | 10 ++ components/modals/card-modal/index.tsx | 2 +- components/ui/calendar.tsx | 66 +++++++++++ components/ui/date-picker.tsx | 108 ++++++++++++++++++ prisma/schema.prisma | 6 +- 8 files changed, 207 insertions(+), 4 deletions(-) create mode 100644 components/ui/calendar.tsx create mode 100644 components/ui/date-picker.tsx diff --git a/actions/update-card/index.ts b/actions/update-card/index.ts index 2c9d393..4559a07 100644 --- a/actions/update-card/index.ts +++ b/actions/update-card/index.ts @@ -16,7 +16,7 @@ const handler = async (data: InputType): Promise => { if (!userId || !orgId) return { error: 'Unauthorized' }; - const { id, boardId, ...values } = data; + const { id, boardId, startedAt, dueDate, ...values } = data; let card; try { @@ -31,6 +31,7 @@ const handler = async (data: InputType): Promise => { }, data: { ...values, + dueDate: dueDate, }, }); diff --git a/actions/update-card/schema.ts b/actions/update-card/schema.ts index b17aa92..bc90a1f 100644 --- a/actions/update-card/schema.ts +++ b/actions/update-card/schema.ts @@ -22,5 +22,15 @@ export const UpdateCard = z.object({ message: 'Title must be at least 3 characters', }) ), + dueDate: z.optional( + z.date({ + invalid_type_error: 'Due date must be a date', + }) + ), + startedAt: z.optional( + z.date({ + invalid_type_error: 'Due date must be a date', + }) + ), id: z.string(), }); diff --git a/app/(platform)/(dashboard)/board/[boardId]/_components/card-item.tsx b/app/(platform)/(dashboard)/board/[boardId]/_components/card-item.tsx index c059add..516e3ff 100644 --- a/app/(platform)/(dashboard)/board/[boardId]/_components/card-item.tsx +++ b/app/(platform)/(dashboard)/board/[boardId]/_components/card-item.tsx @@ -2,8 +2,10 @@ import { Draggable } from '@hello-pangea/dnd'; import { Card } from '@prisma/client'; +import { format } from 'date-fns'; import { useCardModal } from '@/hooks/use-card-modal'; +import { Calendar } from 'lucide-react'; interface CardItemProps { index: number; @@ -25,6 +27,10 @@ export const CardItem = ({ index, data }: CardItemProps) => { className='truncate rounded-md border-2 border-transparent bg-white px-3 py-2 text-sm shadow-sm hover:border-black' > {data.title} +
+ + {data?.dueDate ? 'Due: ' + format(data.dueDate, 'PP') : 'No Due Date'} +
)} diff --git a/components/modals/card-modal/actions.tsx b/components/modals/card-modal/actions.tsx index 4c293b8..c6306b9 100644 --- a/components/modals/card-modal/actions.tsx +++ b/components/modals/card-modal/actions.tsx @@ -12,6 +12,7 @@ import { copyCard } from '@/actions/copy-card'; import { CardWithList } from '@/types'; import { useCardModal } from '@/hooks/use-card-modal'; +import { DatePicker } from '@/components/ui/date-picker'; interface ActionsProps { data: CardWithList; @@ -78,6 +79,15 @@ export const Actions = ({ data }: ActionsProps) => { Copy + + + + + + + ); +} diff --git a/prisma/schema.prisma b/prisma/schema.prisma index cae208f..fd44433 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -42,10 +42,12 @@ model List { } model Card { - id String @id @default(uuid()) + id String @id @default(uuid()) title String order Int - description String? @db.Text + description String? @db.Text + dueDate DateTime? + startedAt DateTime? listId String list List @relation(fields: [listId], references: [id], onDelete: Cascade)