|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { useFrameworkUpdateStatuses } from '@/hooks/use-framework-update-statuses'; |
| 4 | +import { usePermissions } from '@/hooks/use-permissions'; |
| 5 | +import { |
| 6 | + Badge, |
| 7 | + Button, |
| 8 | + Collapsible, |
| 9 | + CollapsibleContent, |
| 10 | + CollapsibleTrigger, |
| 11 | + HStack, |
| 12 | + Text, |
| 13 | +} from '@trycompai/design-system'; |
| 14 | +import { ChevronUp, Upgrade } from '@trycompai/design-system/icons'; |
| 15 | +import { useParams, useRouter } from 'next/navigation'; |
| 16 | +import { useState } from 'react'; |
| 17 | + |
| 18 | +export function FrameworkUpdatesBanner() { |
| 19 | + const { data: statuses } = useFrameworkUpdateStatuses(); |
| 20 | + const { hasPermission } = usePermissions(); |
| 21 | + const router = useRouter(); |
| 22 | + const { orgId } = useParams<{ orgId: string }>(); |
| 23 | + const [open, setOpen] = useState(true); |
| 24 | + |
| 25 | + const canUpdate = hasPermission('framework', 'update'); |
| 26 | + |
| 27 | + if (!statuses || statuses.length === 0) return null; |
| 28 | + |
| 29 | + const count = statuses.length; |
| 30 | + |
| 31 | + return ( |
| 32 | + <div className="mx-auto w-full max-w-[1200px] pb-8"> |
| 33 | + <Collapsible open={open} onOpenChange={setOpen}> |
| 34 | + <div className="rounded-lg border bg-card"> |
| 35 | + <div className="flex items-center justify-between rounded-t-lg bg-secondary px-4 py-3"> |
| 36 | + <HStack gap="3" align="center"> |
| 37 | + <div className="flex size-7 items-center justify-center rounded-full bg-primary text-primary-foreground"> |
| 38 | + <Upgrade size={16} /> |
| 39 | + </div> |
| 40 | + <Text size="sm" weight="medium"> |
| 41 | + {count} framework {count === 1 ? 'update' : 'updates'} available |
| 42 | + </Text> |
| 43 | + <Badge variant="default">NEW</Badge> |
| 44 | + </HStack> |
| 45 | + <CollapsibleTrigger className="flex cursor-pointer items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors"> |
| 46 | + {open ? `Hide ${count}` : `Show ${count}`} |
| 47 | + <ChevronUp |
| 48 | + size={16} |
| 49 | + className={`transition-transform ${open ? '' : 'rotate-180'}`} |
| 50 | + /> |
| 51 | + </CollapsibleTrigger> |
| 52 | + </div> |
| 53 | + |
| 54 | + <CollapsibleContent> |
| 55 | + <div className="border-t"> |
| 56 | + {statuses.map((status, index) => ( |
| 57 | + <div |
| 58 | + key={status.frameworkInstanceId} |
| 59 | + className={`flex items-center justify-between px-4 py-3 ${ |
| 60 | + index < count - 1 ? 'border-b' : '' |
| 61 | + }`} |
| 62 | + > |
| 63 | + <HStack gap="4" align="center"> |
| 64 | + <Text size="sm" weight="medium"> |
| 65 | + {status.frameworkName ?? 'Framework'} |
| 66 | + </Text> |
| 67 | + <Text size="sm" variant="muted"> |
| 68 | + v{status.currentVersion?.version ?? '—'} → v |
| 69 | + {status.latestVersion?.version} |
| 70 | + </Text> |
| 71 | + </HStack> |
| 72 | + {canUpdate && ( |
| 73 | + <Button |
| 74 | + size="sm" |
| 75 | + variant="outline" |
| 76 | + onClick={() => |
| 77 | + router.push( |
| 78 | + `/${orgId}/frameworks/${status.frameworkInstanceId}/review-update`, |
| 79 | + ) |
| 80 | + } |
| 81 | + > |
| 82 | + Review update |
| 83 | + </Button> |
| 84 | + )} |
| 85 | + </div> |
| 86 | + ))} |
| 87 | + </div> |
| 88 | + </CollapsibleContent> |
| 89 | + </div> |
| 90 | + </Collapsible> |
| 91 | + </div> |
| 92 | + ); |
| 93 | +} |
0 commit comments