mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-10-21 20:45:52 +02:00
* feat: Add hasAdminRole property to UserInfo interface and update initLoggedInUser and updateUserInfo functions This commit adds the hasAdminRole property to the UserInfo interface in the account.ts file. The initLoggedInUser function is updated to set the hasAdminRole property to false by default. The updateUserInfo function is also updated to set the hasAdminRole property to false when bypassLogin is true. This change allows for better management of user roles and permissions. Co-authored-by: frutescens <info@laptop> Co-authored-by: Frederico Santos <frederico.f.santos@tecnico.ulisboa.pt> * Updated UI for admin panel and menu * Remove random blank line from merge * Fix imports in `src/ui/ui.ts` --------- Co-authored-by: Frederico Santos <frederico.f.santos@tecnico.ulisboa.pt> Co-authored-by: frutescens <info@laptop> Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
86 lines
2.3 KiB
TypeScript
86 lines
2.3 KiB
TypeScript
import BattleScene from "#app/battle-scene.js";
|
|
import { ModalConfig } from "./modal-ui-handler";
|
|
import { Mode } from "./ui";
|
|
import * as Utils from "../utils";
|
|
import { FormModalUiHandler } from "./form-modal-ui-handler";
|
|
import { Button } from "#app/enums/buttons.js";
|
|
|
|
export default class AdminUiHandler extends FormModalUiHandler {
|
|
|
|
constructor(scene: BattleScene, mode: Mode | null = null) {
|
|
super(scene, mode);
|
|
}
|
|
|
|
setup(): void {
|
|
super.setup();
|
|
}
|
|
|
|
getModalTitle(config?: ModalConfig): string {
|
|
return "Admin panel";
|
|
}
|
|
|
|
getFields(config?: ModalConfig): string[] {
|
|
return ["Username", "Discord ID"];
|
|
}
|
|
|
|
getWidth(config?: ModalConfig): number {
|
|
return 160;
|
|
}
|
|
|
|
getMargin(config?: ModalConfig): [number, number, number, number] {
|
|
return [0, 0, 48, 0];
|
|
}
|
|
|
|
getButtonLabels(config?: ModalConfig): string[] {
|
|
return ["Link account", "Cancel"];
|
|
}
|
|
|
|
processInput(button: Button): boolean {
|
|
if (button === Button.SUBMIT && this.submitAction) {
|
|
this.submitAction();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
show(args: any[]): boolean {
|
|
if (super.show(args)) {
|
|
const config = args[0] as ModalConfig;
|
|
const originalSubmitAction = this.submitAction;
|
|
this.submitAction = (_) => {
|
|
this.submitAction = originalSubmitAction;
|
|
this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] });
|
|
const onFail = error => {
|
|
this.scene.ui.setMode(Mode.ADMIN, Object.assign(config, { errorMessage: error?.trim() }));
|
|
this.scene.ui.playError();
|
|
};
|
|
if (!this.inputs[0].text) {
|
|
return onFail("Username is required");
|
|
}
|
|
if (!this.inputs[1].text) {
|
|
return onFail("Discord Id is required");
|
|
}
|
|
Utils.apiPost("admin/account/discord-link", `username=${encodeURIComponent(this.inputs[0].text)}&discordId=${encodeURIComponent(this.inputs[1].text)}`, "application/x-www-form-urlencoded", true)
|
|
.then(response => {
|
|
if (!response.ok) {
|
|
return response.text();
|
|
}
|
|
return response.json();
|
|
})
|
|
.then(response => {
|
|
this.scene.ui.setMode(Mode.ADMIN, config);
|
|
});
|
|
return false;
|
|
};
|
|
return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
clear(): void {
|
|
super.clear();
|
|
}
|
|
}
|