Spaces:
Sleeping

File size: 3,604 Bytes
64fa001
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import { auth } from "@/auth"
import { redirect } from "next/navigation"
import { checkAndResetDailyCredits } from "@/lib/credits"
import { Button } from "@/components/ui/button"
import {
    Card,
    CardContent,
    CardDescription,
    CardHeader,
    CardTitle,
    CardFooter,
} from "@/components/ui/card"
import { Input } from "@/components/ui/input"
import { Label } from "@/components/ui/label"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"

import { EditProfileDialog } from "@/components/edit-profile-dialog"

export default async function ProfilePage() {
    const session = await auth()
    if (!session?.user?.id) redirect("/login")

    const credits = await checkAndResetDailyCredits(session.user.id)

    return (
        <div className="container py-8 max-w-2xl">
            <h1 className="text-3xl font-black tracking-tight mb-8 uppercase">Profile</h1>

            <Card>
                <CardHeader>
                    <CardTitle>Your Account</CardTitle>
                    <CardDescription>
                        Manage your account settings and view your credits.
                    </CardDescription>
                </CardHeader>
                <CardContent className="space-y-6">
                    <div className="flex items-center gap-4">
                        <Avatar className="h-20 w-20 border-2 border-border shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] dark:shadow-[4px_4px_0px_0px_rgba(255,255,255,1)] rounded-none">
                            <AvatarImage src={session.user.image || ""} />
                            <AvatarFallback className="text-2xl bg-primary text-white font-black">
                                {session.user.name?.[0]?.toUpperCase()}
                            </AvatarFallback>
                        </Avatar>
                        <div>
                            <h3 className="font-semibold text-xl">{session.user.name}</h3>
                            <p className="text-muted-foreground">{session.user.email}</p>
                        </div>
                    </div>

                    <div className="grid gap-2">
                        <Label>Email</Label>
                        <Input value={session.user.email || ""} disabled readOnly />
                    </div>

                    <div className="rounded-none border-2 border-border bg-primary/10 p-4 flex justify-between items-center shadow-[4px_4px_0px_0px_rgba(0,0,0,1)] dark:shadow-[4px_4px_0px_0px_rgba(255,255,255,1)]">
                        <div>
                            <p className="font-bold">Available Credits</p>
                            <p className="text-sm text-muted-foreground">
                                Resets to 100 every 24 hours.
                            </p>
                        </div>
                        <div className="text-3xl font-black text-primary">{credits} ⚡</div>
                    </div>
                </CardContent>
                <CardFooter className="flex justify-between">
                    <EditProfileDialog user={session.user} />
                    <form
                        action={async () => {
                            "use server"
                            const { signOut } = await import("@/auth")
                            await signOut()
                        }}
                    >
                        <Button variant="destructive" type="submit">
                            Sign Out
                        </Button>
                    </form>
                </CardFooter>
            </Card>
        </div>
    )
}