-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from MinaFoundation/feat/summary_phase_summar…
…y_card phase summary card loading [WIP]
- Loading branch information
Showing
4 changed files
with
105 additions
and
89 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
'use client' | ||
import { type PhaseStatus } from '@/types/phase-summary' | ||
import { Suspense, useState, type FC } from 'react' | ||
import Link from 'next/link' | ||
import { cn } from '@/lib/utils' | ||
import { | ||
Card, | ||
CardContent, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle, | ||
} from '../ui/card' | ||
import { Badge } from '@/components/ui/badge' | ||
import { CalendarIcon } from 'lucide-react' | ||
import { format } from 'date-fns' | ||
import { Icons } from '../icons' | ||
|
||
interface PhaseInfo { | ||
title: string | ||
description: string | ||
icon: React.ReactNode | ||
status: PhaseStatus | ||
startDate: Date | ||
endDate: Date | ||
href: string | ||
} | ||
|
||
export const PhaseSummaryCard: FC<PhaseInfo> = ({ | ||
title, | ||
description, | ||
icon, | ||
status, | ||
startDate, | ||
endDate, | ||
href, | ||
}) => { | ||
const isAccessible = status !== 'not-started' | ||
const CardWrapper = isAccessible ? Link : 'div' | ||
const [isLoading, setIsLoading] = useState(false) | ||
|
||
const handleClick = (e: React.MouseEvent<HTMLElement>) => { | ||
setIsLoading(true) | ||
} | ||
|
||
return ( | ||
<CardWrapper | ||
href={href} | ||
onClick={handleClick} | ||
className={cn( | ||
'block transition-all duration-200', | ||
isAccessible && 'hover:shadow-md', | ||
)} | ||
> | ||
<Card className={cn('relative', !isAccessible && 'opacity-75')}> | ||
<CardHeader> | ||
<div className="flex items-center justify-between"> | ||
<div className="flex items-center gap-2"> | ||
{icon} | ||
<CardTitle className="text-lg">{title}</CardTitle> | ||
</div> | ||
{isLoading && <Icons.spinner className="h-4 w-4 animate-spin" />} | ||
<Badge | ||
variant={ | ||
status === 'ended' | ||
? 'default' | ||
: status === 'ongoing' | ||
? 'secondary' | ||
: 'outline' | ||
} | ||
className={cn( | ||
status === 'not-started' && 'bg-muted text-muted-foreground', | ||
)} | ||
> | ||
{status === 'ended' | ||
? 'Completed' | ||
: status === 'ongoing' | ||
? 'In Progress' | ||
: 'Not Started'} | ||
</Badge> | ||
</div> | ||
<CardDescription>{description}</CardDescription> | ||
</CardHeader> | ||
<CardContent> | ||
<div className="flex items-center gap-2 text-sm text-muted-foreground"> | ||
<CalendarIcon className="h-4 w-4" /> | ||
<span> | ||
{format(startDate, 'MMM dd, yyyy')} -{' '} | ||
{format(endDate, 'MMM dd, yyyy')} | ||
</span> | ||
</div> | ||
{!isAccessible && ( | ||
<div className="mt-4 text-sm text-muted-foreground"> | ||
Summary will be available when the phase starts | ||
</div> | ||
)} | ||
</CardContent> | ||
</Card> | ||
</CardWrapper> | ||
) | ||
} |