first commit

This commit is contained in:
a.alinaghipour
2026-04-05 15:53:20 +03:30
commit aa9ed69dd2
96 changed files with 7721 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
"use client";
import { useState } from "react";
export default function ProfileForm({ user }: { user: { id: string; name: string; email: string } }) {
const [name, setName] = useState(user.name);
const [saved, setSaved] = useState(false);
const [loading, setLoading] = useState(false);
async function handleSubmit(e: React.FormEvent) {
e.preventDefault();
setLoading(true);
await fetch("/api/user/profile", {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name }),
});
setSaved(true);
setLoading(false);
setTimeout(() => setSaved(false), 3000);
}
return (
<form onSubmit={handleSubmit} className="bg-white rounded-2xl shadow p-6 flex flex-col gap-4">
<h2 className="font-bold text-lg">اطلاعات حساب</h2>
<div>
<label className="block text-sm font-medium mb-1">نام</label>
<input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
className="w-full border rounded-xl px-4 py-2.5 focus:outline-none focus:ring-2 focus:ring-green-500"
/>
</div>
<div>
<label className="block text-sm font-medium mb-1">ایمیل</label>
<input
type="email"
value={user.email}
disabled
className="w-full border rounded-xl px-4 py-2.5 bg-gray-50 text-gray-400"
/>
</div>
<button
type="submit"
disabled={loading}
className="bg-green-700 text-white py-2.5 rounded-xl font-bold hover:bg-green-800 transition disabled:opacity-50"
>
{loading ? "در حال ذخیره..." : "ذخیره"}
</button>
{saved && <p className="text-green-600 text-sm text-center"> ذخیره شد</p>}
</form>
);
}

View File

@@ -0,0 +1,56 @@
import { requireAuth } from "@/lib/session";
import { db } from "@/lib/db";
import ProfileForm from "./ProfileForm";
export default async function ProfilePage() {
const session = await requireAuth();
const userId = (session.user as any).id;
const user = await db.user.findUnique({
where: { id: userId },
include: {
team: {
include: {
players: { include: { player: { include: { country: true } } } },
},
},
},
});
if (!user) return null;
return (
<div className="max-w-3xl mx-auto py-10 px-6">
<h1 className="text-3xl font-bold mb-8">پروفایل</h1>
<div className="grid grid-cols-2 gap-6">
<ProfileForm user={{ id: user.id, name: user.name ?? "", email: user.email }} />
<div className="bg-white rounded-2xl shadow p-6">
<h2 className="font-bold text-lg mb-4">آمار من</h2>
<div className="flex flex-col gap-3">
<div className="flex justify-between">
<span className="text-gray-500">نام تیم</span>
<span className="font-medium">{user.team?.name ?? "-"}</span>
</div>
<div className="flex justify-between">
<span className="text-gray-500">امتیاز کل</span>
<span className="font-bold text-blue-700">{user.team?.totalPoints ?? 0}</span>
</div>
<div className="flex justify-between">
<span className="text-gray-500">بودجه باقیمانده</span>
<span className="font-medium text-green-700">
{user.team
? (user.team.budget - user.team.players.reduce((s, tp) => s + tp.player.price, 0)).toFixed(1)
: 100}M
</span>
</div>
<div className="flex justify-between">
<span className="text-gray-500">تعداد بازیکنان</span>
<span className="font-medium">{user.team?.players.length ?? 0} / 15</span>
</div>
</div>
</div>
</div>
</div>
);
}