"use client"; import type React from "react"; import { useState, useRef } from "react"; import { z } from "zod"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import type { IUserSchema } from "@/src/entities/models/users/users.model"; import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, } from "@/app/_components/ui/form"; import { Avatar, AvatarFallback, AvatarImage, } from "@/app/_components/ui/avatar"; import { Input } from "@/app/_components/ui/input"; import { Textarea } from "@/app/_components/ui/textarea"; import { Button } from "@/app/_components/ui/button"; import { Label } from "@/app/_components/ui/label"; import { ImageIcon, Loader2 } from "lucide-react"; import { createClient } from "@/app/_utils/supabase/client"; import { getFullName, getInitials } from "@/app/_utils/common"; import { useProfileFormHandlers } from "../dashboard/user-management/_handlers/use-profile-form"; import { CTexts } from "@/app/_utils/const/texts"; // Profile update form schema const profileFormSchema = z.object({ first_name: z.string().nullable().optional(), last_name: z.string().nullable().optional(), bio: z.string().nullable().optional(), avatar: z.string().nullable().optional(), }); type ProfileFormValues = z.infer; interface ProfileFormProps { user: IUserSchema | null; onSuccess?: () => void; } export function ProfileForm({ user, onSuccess }: ProfileFormProps) { const firstName = user?.profile?.first_name || ""; const lastName = user?.profile?.last_name || ""; const email = user?.email || ""; const username = user?.profile?.username || ""; const { isPending, avatarPreview, fileInputRef, form, handleFileChange, handleAvatarClick, onSubmit, } = useProfileFormHandlers({ user, onSuccess }) return (
{/* Avatar upload section at the top */}
{avatarPreview ? ( ) : ( {getInitials(firstName, lastName, email)} )}
{isPending ? ( ) : ( )}
( First Name )} /> ( Last Name )} /> ( Bio