import { useState, useContext } from 'react'; import { AccountUserProfileContext } from '../hooks'; // import { KeenIcon } from '@/components'; // import { toAbsoluteUrl } from '@/utils/Assets'; import { getAuth, useAuthContext } from '@/auth'; import { toast } from 'sonner'; interface IBasicSettingsProps { title: string; } const BasicSettings = () => { // const user = localStorage.getItem('user'); // const parsedUser = user ? JSON.parse(user) : null; const parsedUser = getAuth()?.user; // console.log('parsedUser :', parsedUser); const [newUsername, setNewUsername] = useState(parsedUser?.username || ''); const [newEmail, setNewEmail] = useState(parsedUser?.email || ''); const [newName, setNewName] = useState(parsedUser?.name || ''); const { setProfile } = useContext(AccountUserProfileContext); const [isSubmitting, setIsSubmitting] = useState(false); const isChanged = newUsername !== parsedUser?.username || newEmail !== parsedUser?.email || newName !== parsedUser?.name; const handleChangeProfile = async () => { setIsSubmitting(true); try { await setProfile({ name: newName, username: newUsername, email: newEmail }); const newCache = { name: newName, email: newEmail, username: newUsername }; localStorage.setItem('user', JSON.stringify(newCache)); } catch (error: any) { const errorMessage = error?.response?.data?.message || error?.message || 'An error occurred while resetting the password.'; toast.error(errorMessage); } finally { setIsSubmitting(false); } }; return (

Account

setNewName(e.target.value)} disabled={isSubmitting} />
setNewUsername(e.target.value)} disabled={isSubmitting} />
setNewEmail(e.target.value)} disabled={isSubmitting} />
{/*
*/}
); }; export { BasicSettings, type IBasicSettingsProps };