TTime/frontend/src/Components/ChangeUsername.tsx
2024-04-01 02:14:44 +02:00

26 lines
771 B
TypeScript

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<void>) => {
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;