import { APIResponse, api } from "../API/API"; import { StrNameChange } from "../Types/goTypes"; function ChangeUsername(props: { nameChange: StrNameChange }): void { if (props.nameChange.newName === "") { alert("You have to select a new name"); return; } api .changeUserName(props.nameChange, localStorage.getItem("accessToken") ?? "") .then((response: APIResponse) => { if (response.success) { alert("Name changed successfully"); location.reload(); } else { alert("Name not changed"); console.error(response.message); } }) .catch((error) => { alert("Name not changed"); console.error("An error occurred during change:", error); }); } export default ChangeUsername;