| 1 | 'use client' |
| 2 | |
| 3 | import { useRouter } from '@bprogress/next/app' |
| 4 | import { Milestone as |
| 5 | import { useAction } |
| 6 | import { useState } |
| 7 | import { toast } |
| 8 | import { Button } |
| 9 | import { |
| 10 | Empty, |
| 11 | EmptyContent, |
| 12 | EmptyDescription, |
| 13 | EmptyHeader, |
| 14 | EmptyMedia, |
| 15 | EmptyTitle, |
| 16 | } from '@/components/ui/empty' |
| 17 | import type { milestones |
| 18 | import { analyticsService } |
| 19 | import { CreateMilestoneDialog } |
| 20 | import { MilestoneCard } |
| 21 | import { createMilestoneAction } |
| 22 | |
| 23 | type Milestone |
| 24 | progress: { |
| 25 | } |
| 26 | |
| 27 | interface MilestonesClientProps { |
| 28 | canComplete: boolean |
| 29 | canCreate: boolean |
| 30 | canDelete: boolean |
| 31 | canUpdate: boolean |
| 32 | defaultCurrency?: string |
| 33 | milestones: Milestone |
| 34 | orgSlug: string |
| 35 | projectId: string |
| 36 | projectSlug: string |
| 37 | } |
| 38 | |
| 39 | export function MilestonesClient({ |
| 40 | milestones, |
| 41 | projectId, |
| 42 | orgSlug, |
| 43 | projectSlug, |
| 44 | canCreate, |
| 45 | canUpdate, |
| 46 | canComplete, |
| 47 | canDelete, |
| 48 | defaultCurrency, |
| 49 | }: MilestonesClientProps) |
| 50 | const router = |
| 51 | const [dialogOpen, |
| 52 | |
| 53 | const { execute, |
| 54 | onSuccess() { |
| 55 | toast.success('Milestone created |
| 56 | router.refresh() |
| 57 | setDialogOpen(false) |
| 58 | analyticsService.track('milestone_created |
| 59 | }, |
| 60 | onError({ error |
| 61 | if (error.validationErrors |
| 62 | toast.error('Please check your input and try again. |
| 63 | } else { |
| 64 | toast.error(error |
| 65 | } |
| 66 | }, |
| 67 | }) |
| 68 | |
| 69 | return ( |
| 70 | <div className='w-full |
| 71 | <div className='mb-6 flex items-center justify-between |
| 72 | <h1 className='font-semibold text-2xl |
| 73 | {canCreate && milestones |
| 74 | <Button kbd=' |
| 75 | <Plus className=' |
| 76 | New Milestone |
| 77 | </Button> |
| 78 | )} |
| 79 | </div> |
| 80 | |
| 81 | {milestones.length === |
| 82 | <Empty> |
| 83 | <EmptyHeader> |
| 84 | <EmptyMedia variant=' |
| 85 | <MilestoneIcon /> |
| 86 | </EmptyMedia> |
| 87 | <EmptyTitle>No milestones yet</EmptyTitle |
| 88 | <EmptyDescription> |
| 89 | Milestones break your project into meaningful phases with |
| 90 | deadlines. Create one to get started. |
| 91 | </EmptyDescription> |
| 92 | </EmptyHeader> |
| 93 | {canCreate && ( |
| 94 | <EmptyContent> |
| 95 | <Button kbd=' |
| 96 | Create Milestone |
| 97 | </Button> |
| 98 | </EmptyContent> |
| 99 | )} |
| 100 | </Empty> |
| 101 | ) : ( |
| 102 | <div className='grid gap-4 sm:grid-cols-2 lg:grid-cols-3 |
| 103 | {milestones.map(( |
| 104 | <MilestoneCard |
| 105 | canComplete={canComplete} |
| 106 | canDelete={canDelete} |
| 107 | canUpdate={canUpdate} |
| 108 | key={milestone.id |
| 109 | milestone={milestone} |
| 110 | orgSlug={orgSlug} |
| 111 | projectSlug={projectSlug} |
| 112 | /> |
| 113 | ))} |
| 114 | </div> |
| 115 | )} |
| 116 | |
| 117 | {canCreate && ( |
| 118 | <CreateMilestoneDialog |
| 119 | defaultCurrency={defaultCurrency} |
| 120 | isPending={isPending} |
| 121 | onOpenChange={setDialogOpen} |
| 122 | onSubmit={(data) |
| 123 | open={dialogOpen} |
| 124 | projectId={projectId} |
| 125 | /> |
| 126 | )} |
| 127 | </div> |
| 128 | ) |
| 129 | } |