"use client"; import type React from "react"; import type { IUserSchema } from "@/src/entities/models/users/users.model"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { z } from "zod"; import { Loader2, ImageIcon } from "lucide-react"; import { Form, FormControl, FormField, FormItem, FormMessage, } from "@/app/_components/ui/form"; import { Input } from "@/app/_components/ui/input"; import { Button } from "@/app/_components/ui/button"; import { Avatar, AvatarFallback, AvatarImage, } from "@/app/_components/ui/avatar"; import { Label } from "@/app/_components/ui/label"; import { Separator } from "@/app/_components/ui/separator"; import { Switch } from "@/app/_components/ui/switch"; import { useRef, useState } from "react"; import { ScrollArea } from "@/app/_components/ui/scroll-area"; import { updateUser, } from "@/app/(pages)/(admin)/dashboard/user-management/action"; import { useProfileFormHandlers } from "../../dashboard/user-management/_handlers/use-profile-form"; import { CTexts } from "@/app/_lib/const/string"; const profileFormSchema = z.object({ username: z.string().nullable().optional(), avatar: z.string().nullable().optional(), }); type ProfileFormValues = z.infer; interface ProfileSettingsProps { user: IUserSchema | null; } export function ProfileSettings({ user }: ProfileSettingsProps) { // const [isPending, setIsepisPending] = useState(false); // const fileInputRef = useRef(null); // // Use profile data with fallbacks // const username = user?.profile?.username || ""; // const email = user?.email || ""; // const userAvatar = user?.profile?.avatar || ""; // const form = useForm({ // resolver: zodResolver(profileFormSchema), // defaultValues: { // username: username || "", // avatar: userAvatar || "", // }, // }); // const handleFileChange = async (e: React.ChangeEvent) => { // const file = e.target.files?.[0]; // if (!file || !user?.id || !user?.email) return; // try { // setIsepisPending(true); // // Upload avatar to storage // // const publicUrl = await uploadAvatar(user.id, user.email, file); // // console.log("publicUrl", publicUrl); // // Update the form value // // form.setValue("avatar", publicUrl); // } catch (error) { // console.error("Error uploading avatar:", error); // } finally { // setIsepisPending(false); // } // }; // const handleAvatarClick = () => { // fileInputRef.current?.click(); // }; // async function onSubmit(data: ProfileFormValues) { // try { // if (!user?.id) return; // // Update profile in database // const { error } = await updateUser(user.id, { // profile: { // avatar: data.avatar || undefined, // username: data.username || undefined, // }, // }); // if (error) throw error; // } catch (error) { // console.error("Error updating profile:", error); // } const email = user?.email || ""; const username = user?.profile?.username || ""; const { form, fileInputRef, handleFileChange, handleAvatarClick, isPending, onSubmit, } = useProfileFormHandlers({ user }); return (
{ }} className="space-y-8">

Account

{isPending ? (
) : ( <> {username?.[0]?.toUpperCase() || email?.[0]?.toUpperCase()} )}
{isPending ? ( ) : ( )}
( )} />
{/* */}

Account security

{email}

Set a permanent password to login to your account.

Add an additional layer of security to your account during login.

Securely sign-in with on-device biometric authentication.

Notifications

Grant temporary access to your account for support purposes.

Permanently delete the account and remove access from all workspaces.

); }