2024-04-01 02:14:44 +02:00
|
|
|
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>) => {
|
2024-03-21 02:22:23 +01:00
|
|
|
if (response.success) {
|
2024-04-01 02:14:44 +02:00
|
|
|
alert("Name changed successfully");
|
|
|
|
location.reload();
|
2024-03-21 02:22:23 +01:00
|
|
|
} else {
|
2024-04-01 02:14:44 +02:00
|
|
|
alert("Name not changed");
|
|
|
|
console.error(response.message);
|
2024-03-21 02:22:23 +01:00
|
|
|
}
|
2024-04-01 02:14:44 +02:00
|
|
|
})
|
|
|
|
.catch((error) => {
|
|
|
|
alert("Name not changed");
|
|
|
|
console.error("An error occurred during change:", error);
|
2024-03-21 02:22:23 +01:00
|
|
|
});
|
2024-03-19 03:39:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export default ChangeUsername;
|