profi sayfası
This commit is contained in:
@@ -1,14 +1,40 @@
|
||||
import { createClient } from "@/lib/supabase-server"
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { UserForm } from "@/components/dashboard/user-form"
|
||||
import { notFound } from "next/navigation"
|
||||
import { getProfile } from "@/lib/data"
|
||||
|
||||
export default async function ProfilePage() {
|
||||
const supabase = createClient()
|
||||
const { data: { user } } = await supabase.auth.getUser()
|
||||
|
||||
if (!user) {
|
||||
// Should be protected by middleware but just in case
|
||||
return <div>Lütfen giriş yapın.</div>
|
||||
}
|
||||
|
||||
// Fetch profile data
|
||||
const profile = await getProfile(user.id)
|
||||
|
||||
if (!profile) {
|
||||
// Fallback for user without profile row?
|
||||
// Or create one on the fly?
|
||||
return <div>Profil verisi bulunamadı.</div>
|
||||
}
|
||||
|
||||
const parts = (profile.full_name || "").split(' ')
|
||||
const firstName = parts[0] || ""
|
||||
const lastName = parts.slice(1).join(' ') || ""
|
||||
|
||||
const initialData = {
|
||||
firstName,
|
||||
lastName,
|
||||
phone: profile.phone || "",
|
||||
email: user.email || "",
|
||||
role: profile.role || "user"
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
@@ -20,28 +46,18 @@ export default async function ProfilePage() {
|
||||
<CardHeader>
|
||||
<CardTitle>Genel Bilgiler</CardTitle>
|
||||
<CardDescription>
|
||||
Kişisel profil bilgileriniz.
|
||||
Kişisel profil bilgilerinizi buradan güncelleyebilirsiniz.
|
||||
</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-6">
|
||||
<div className="flex items-center space-x-4">
|
||||
<div className="flex items-center space-x-4 mb-6">
|
||||
<Avatar className="h-20 w-20">
|
||||
<AvatarImage src="/avatars/01.png" alt="@parakasa" />
|
||||
<AvatarFallback>PK</AvatarFallback>
|
||||
</Avatar>
|
||||
<Button variant="outline">Fotoğraf Değiştir</Button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="email">E-posta</Label>
|
||||
<Input id="email" value={user?.email || ""} disabled />
|
||||
<p className="text-xs text-muted-foreground">E-posta adresi değiştirilemez.</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="role">Rol</Label>
|
||||
<Input id="role" value={user?.role === 'authenticated' ? 'Yönetici' : 'Kullanıcı'} disabled />
|
||||
</div>
|
||||
<UserForm initialData={initialData} mode="profile" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
15
app/(dashboard)/dashboard/profile/password/page.tsx
Normal file
15
app/(dashboard)/dashboard/profile/password/page.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
import { PasswordForm } from "../../../../../components/dashboard/password-form"
|
||||
|
||||
export default function ChangePasswordPage() {
|
||||
return (
|
||||
<div className="flex-1 space-y-4 p-8 pt-6">
|
||||
<div className="flex items-center justify-between space-y-2">
|
||||
<h2 className="text-3xl font-bold tracking-tight">Şifre Değiştir</h2>
|
||||
</div>
|
||||
<div className="max-w-md">
|
||||
<PasswordForm />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -64,6 +64,7 @@ async function getUserDetails(userId: string) {
|
||||
firstName,
|
||||
lastName,
|
||||
email: user.email || "",
|
||||
role: profile.role as "admin" | "user"
|
||||
role: profile.role as "admin" | "user",
|
||||
phone: profile.phone || ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ const supabaseAdmin = createSupabaseClient(
|
||||
}
|
||||
)
|
||||
|
||||
export async function createUser(firstName: string, lastName: string, email: string, password: string, role: 'admin' | 'user') {
|
||||
export async function createUser(firstName: string, lastName: string, email: string, password: string, role: 'admin' | 'user', phone?: string) {
|
||||
const supabase = createClient()
|
||||
|
||||
// 1. Check if current user is admin
|
||||
@@ -59,7 +59,8 @@ export async function createUser(firstName: string, lastName: string, email: str
|
||||
.insert({
|
||||
id: newUser.user.id,
|
||||
full_name: `${firstName} ${lastName}`.trim(),
|
||||
role: role
|
||||
role: role,
|
||||
phone: phone
|
||||
})
|
||||
|
||||
if (profileError) {
|
||||
@@ -91,7 +92,7 @@ export async function deleteUser(userId: string) {
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function updateUser(userId: string, data: { firstName: string, lastName: string, email: string, password?: string, role: 'admin' | 'user' }) {
|
||||
export async function updateUser(userId: string, data: { firstName: string, lastName: string, email: string, password?: string, role: 'admin' | 'user', phone?: string }) {
|
||||
const supabase = createClient()
|
||||
|
||||
// Check admin
|
||||
@@ -107,7 +108,8 @@ export async function updateUser(userId: string, data: { firstName: string, last
|
||||
.from('profiles')
|
||||
.update({
|
||||
full_name: `${data.firstName} ${data.lastName}`.trim(),
|
||||
role: data.role
|
||||
role: data.role,
|
||||
phone: data.phone
|
||||
})
|
||||
.eq('id', userId)
|
||||
|
||||
@@ -131,3 +133,32 @@ export async function updateUser(userId: string, data: { firstName: string, last
|
||||
revalidatePath("/dashboard/users")
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function updateProfile(data: { firstName: string, lastName: string, phone?: string }) {
|
||||
const supabase = createClient()
|
||||
const { data: { user } } = await supabase.auth.getUser()
|
||||
|
||||
if (!user) return { error: "Oturum açmanız gerekiyor." }
|
||||
|
||||
const { error } = await supabase
|
||||
.from('profiles')
|
||||
.update({
|
||||
full_name: `${data.firstName} ${data.lastName}`.trim(),
|
||||
phone: data.phone
|
||||
})
|
||||
.eq('id', user.id)
|
||||
|
||||
if (error) return { error: "Profil güncellenemedi: " + error.message }
|
||||
|
||||
// Update Auth Metadata as well
|
||||
if (data.firstName || data.lastName) {
|
||||
await supabase.auth.updateUser({
|
||||
data: {
|
||||
full_name: `${data.firstName} ${data.lastName}`.trim()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
revalidatePath("/dashboard/profile")
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user