'use client'; import { useState } from 'react'; import axios from 'axios'; import Cookies from 'js-cookie'; interface ProfileSettingsProps { initialUsername: string; initialName: string; initialEmail: string; onError: (message: string) => void; } export const ProfileSettings = ({ initialUsername, initialName, initialEmail, onError, }: ProfileSettingsProps) => { const [username, setUsername] = useState(initialUsername); const [name, setName] = useState(initialName); const [email, setEmail] = useState(initialEmail); const handleSave = async () => { try { const response = await axios.post('/api/user/change/profile', { token: Cookies.get('token'), username, name, email, }); if (response.data.message === 'Profile updated successfully') { window.location.reload(); } else { onError('Failed to update profile'); } } catch (error: any) { onError(error.response?.data?.error || 'An error occurred'); } }; return (
Manage your profile settings