chore: update generations count in profile page
This commit is contained in:
parent
39993af4a3
commit
199318e706
@ -17,7 +17,7 @@ import {
|
|||||||
import { Label } from "@/components/ui/label"
|
import { Label } from "@/components/ui/label"
|
||||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||||
import { deleteSandbox, updateSandbox, updateUser } from "@/lib/actions"
|
import { deleteSandbox, updateSandbox, updateUser } from "@/lib/actions"
|
||||||
import { MAX_FREE_GENERATION } from "@/lib/constant"
|
import { TIERS } from "@/lib/tiers"
|
||||||
import { SandboxWithLiked, User } from "@/lib/types"
|
import { SandboxWithLiked, User } from "@/lib/types"
|
||||||
import { useUser } from "@clerk/nextjs"
|
import { useUser } from "@clerk/nextjs"
|
||||||
import {
|
import {
|
||||||
@ -74,6 +74,7 @@ export default function ProfilePage({
|
|||||||
joinedDate={profileOwner.createdAt}
|
joinedDate={profileOwner.createdAt}
|
||||||
generations={isOwnProfile ? loggedInUser.generations : undefined}
|
generations={isOwnProfile ? loggedInUser.generations : undefined}
|
||||||
isOwnProfile={isOwnProfile}
|
isOwnProfile={isOwnProfile}
|
||||||
|
tier={profileOwner.tier}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="md:col-span-2">
|
<div className="md:col-span-2">
|
||||||
@ -100,6 +101,7 @@ function ProfileCard({
|
|||||||
joinedDate,
|
joinedDate,
|
||||||
generations,
|
generations,
|
||||||
isOwnProfile,
|
isOwnProfile,
|
||||||
|
tier,
|
||||||
}: {
|
}: {
|
||||||
name: string
|
name: string
|
||||||
username: string
|
username: string
|
||||||
@ -108,6 +110,7 @@ function ProfileCard({
|
|||||||
joinedDate: Date
|
joinedDate: Date
|
||||||
generations?: number
|
generations?: number
|
||||||
isOwnProfile: boolean
|
isOwnProfile: boolean
|
||||||
|
tier: string
|
||||||
}) {
|
}) {
|
||||||
const { user } = useUser()
|
const { user } = useUser()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@ -228,7 +231,7 @@ function ProfileCard({
|
|||||||
<div className="flex flex-col items-center gap-2">
|
<div className="flex flex-col items-center gap-2">
|
||||||
<p className="text-xs text-muted-foreground">{joinedAt}</p>
|
<p className="text-xs text-muted-foreground">{joinedAt}</p>
|
||||||
{typeof generations === "number" && (
|
{typeof generations === "number" && (
|
||||||
<SubscriptionBadge generations={generations} />
|
<SubscriptionBadge generations={generations} tier={tier as keyof typeof TIERS} />
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
@ -442,11 +445,11 @@ const StatsItem = ({ icon: Icon, label }: StatsItemProps) => (
|
|||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
// #region Sub Badge
|
// #region Sub Badge
|
||||||
const SubscriptionBadge = ({ generations }: { generations: number }) => {
|
const SubscriptionBadge = ({ generations, tier = "FREE" }: { generations: number, tier?: keyof typeof TIERS }) => {
|
||||||
return (
|
return (
|
||||||
<div className="flex gap-2 items-center">
|
<div className="flex gap-2 items-center">
|
||||||
<Badge variant="secondary" className="text-sm cursor-pointer">
|
<Badge variant="secondary" className="text-sm cursor-pointer">
|
||||||
Free
|
{tier}
|
||||||
</Badge>
|
</Badge>
|
||||||
<HoverCard>
|
<HoverCard>
|
||||||
<HoverCardTrigger>
|
<HoverCardTrigger>
|
||||||
@ -458,11 +461,11 @@ const SubscriptionBadge = ({ generations }: { generations: number }) => {
|
|||||||
<div className="w-full space-y-2">
|
<div className="w-full space-y-2">
|
||||||
<div className="flex justify-between text-sm">
|
<div className="flex justify-between text-sm">
|
||||||
<span className="font-medium">AI Generations</span>
|
<span className="font-medium">AI Generations</span>
|
||||||
<span>{`${generations} / ${MAX_FREE_GENERATION}`}</span>
|
<span>{`${generations} / ${TIERS[tier].generations}`}</span>
|
||||||
</div>
|
</div>
|
||||||
<Progress
|
<Progress
|
||||||
value={generations}
|
value={generations}
|
||||||
max={MAX_FREE_GENERATION}
|
max={TIERS[tier].generations}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -7,7 +7,6 @@ import {
|
|||||||
DropdownMenuSeparator,
|
DropdownMenuSeparator,
|
||||||
DropdownMenuTrigger,
|
DropdownMenuTrigger,
|
||||||
} from "@/components/ui/dropdown-menu"
|
} from "@/components/ui/dropdown-menu"
|
||||||
import { MAX_FREE_GENERATION } from "@/lib/constant"
|
|
||||||
import { User } from "@/lib/types"
|
import { User } from "@/lib/types"
|
||||||
import { useClerk } from "@clerk/nextjs"
|
import { useClerk } from "@clerk/nextjs"
|
||||||
import {
|
import {
|
||||||
@ -81,7 +80,7 @@ export default function UserButton({ userData: initialUserData }: { userData: Us
|
|||||||
const usagePercentage = Math.floor((userData.generations || 0) * 100 / tierInfo.limit)
|
const usagePercentage = Math.floor((userData.generations || 0) * 100 / tierInfo.limit)
|
||||||
|
|
||||||
const handleUpgrade = async () => {
|
const handleUpgrade = async () => {
|
||||||
router.push('/upgrade')
|
router.push(`/@${userData.username}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -104,16 +103,16 @@ export default function UserButton({ userData: initialUserData }: { userData: Us
|
|||||||
<Link href={"/dashboard"}>
|
<Link href={"/dashboard"}>
|
||||||
<LayoutDashboard className="mr-2 size-4" />
|
<LayoutDashboard className="mr-2 size-4" />
|
||||||
<span>Dashboard</span>
|
<span>Dashboard</span>
|
||||||
<DropdownMenuSeparator />
|
|
||||||
</Link>
|
</Link>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuItem className="cursor-pointer" asChild>
|
<DropdownMenuItem className="cursor-pointer" asChild>
|
||||||
<Link href={`/@${userData.username}`}>
|
<Link href={`/@${userData.username}`}>
|
||||||
<UserIcon className="mr-2 size-4" />
|
<UserIcon className="mr-2 size-4" />
|
||||||
<span>Profile</span>
|
<span>Profile</span>
|
||||||
<DropdownMenuSeparator />
|
|
||||||
</Link>
|
</Link>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
|
||||||
|
|
||||||
<div className="py-1.5 px-2 w-full">
|
<div className="py-1.5 px-2 w-full">
|
||||||
@ -122,7 +121,7 @@ export default function UserButton({ userData: initialUserData }: { userData: Us
|
|||||||
<TierIcon className={`h-4 w-4 ${tierInfo.color}`} />
|
<TierIcon className={`h-4 w-4 ${tierInfo.color}`} />
|
||||||
<span className="text-sm font-medium">{userData.tier || "FREE"} Plan</span>
|
<span className="text-sm font-medium">{userData.tier || "FREE"} Plan</span>
|
||||||
</div>
|
</div>
|
||||||
{/* {(userData.tier === "FREE" || userData.tier === "PRO") && (
|
{(userData.tier === "FREE" || userData.tier === "PRO") && (
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="sm"
|
size="sm"
|
||||||
@ -131,20 +130,19 @@ export default function UserButton({ userData: initialUserData }: { userData: Us
|
|||||||
>
|
>
|
||||||
Upgrade
|
Upgrade
|
||||||
</Button>
|
</Button>
|
||||||
)} */}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
<DropdownMenuItem>
|
<div className="px-2 py-1.5">
|
||||||
<Sparkles className="size-4 mr-2 text-indigo-500" />
|
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<div className="flex items-center justify-between text-sm text-muted-foreground mb-2">
|
<div className="flex items-center justify-between text-sm text-muted-foreground mb-2">
|
||||||
<span>AI Usage</span>
|
<span>AI Usage</span>
|
||||||
<span>{userData.generations}/{tierInfo.limit}</span>
|
<span>{userData.generations}/{tierInfo.limit}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="rounded-full w-full h-2 overflow-hidden bg-secondary">
|
<div className="rounded-full w-full h-2 overflow-hidden bg-secondary mb-1">
|
||||||
<div
|
<div
|
||||||
className={`h-full rounded-full transition-all duration-300 ${
|
className={`h-full rounded-full transition-all duration-300 ${
|
||||||
usagePercentage > 90 ? 'bg-red-500' :
|
usagePercentage > 90 ? 'bg-red-500' :
|
||||||
@ -157,7 +155,7 @@ export default function UserButton({ userData: initialUserData }: { userData: Us
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</DropdownMenuItem>
|
</div>
|
||||||
<DropdownMenuSeparator />
|
<DropdownMenuSeparator />
|
||||||
|
|
||||||
{/* <DropdownMenuItem className="cursor-pointer">
|
{/* <DropdownMenuItem className="cursor-pointer">
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export const MAX_FREE_GENERATION = 1000
|
|
Loading…
x
Reference in New Issue
Block a user