Compare commits

...

4 Commits

Author SHA1 Message Date
Opaque02 3bb0f1be60
Merge 79c2829a77 into 009fd3fc5c 2024-09-16 22:12:44 +02:00
flx-sta 79c2829a77
Merge branch 'beta' into admin-panel-unlink-update 2024-09-13 15:38:12 -07:00
Opaque02 2c0fc385bd Don't look too hard at this commit, nothing to see here 2024-09-13 00:47:57 +10:00
Opaque02 f4df35a452 Updated admin panel to allow the concept of unlinking accounts 2024-09-13 00:37:38 +10:00
2 changed files with 52 additions and 16 deletions

View File

@ -7,6 +7,8 @@ import { Button } from "#app/enums/buttons";
export default class AdminUiHandler extends FormModalUiHandler { export default class AdminUiHandler extends FormModalUiHandler {
private unlinkAction: Function;
constructor(scene: BattleScene, mode: Mode | null = null) { constructor(scene: BattleScene, mode: Mode | null = null) {
super(scene, mode); super(scene, mode);
} }
@ -24,7 +26,7 @@ export default class AdminUiHandler extends FormModalUiHandler {
} }
getWidth(config?: ModalConfig): number { getWidth(config?: ModalConfig): number {
return 160; return 220;
} }
getMargin(config?: ModalConfig): [number, number, number, number] { getMargin(config?: ModalConfig): [number, number, number, number] {
@ -32,7 +34,7 @@ export default class AdminUiHandler extends FormModalUiHandler {
} }
getButtonLabels(config?: ModalConfig): string[] { getButtonLabels(config?: ModalConfig): string[] {
return ["Link account", "Cancel"]; return ["Link account", "Unlink account", "Cancel"];
} }
processInput(button: Button): boolean { processInput(button: Button): boolean {
@ -48,6 +50,20 @@ export default class AdminUiHandler extends FormModalUiHandler {
if (super.show(args)) { if (super.show(args)) {
const config = args[0] as ModalConfig; const config = args[0] as ModalConfig;
const originalSubmitAction = this.submitAction; const originalSubmitAction = this.submitAction;
let originAction: number = 0; // this is used to keep track of which button has been pressed
/* This code is here because currently the form-modal-ui-handler is hardcoded to only have a single action button and a cancel button
* This code below adds interactivity and a specific action to the unlink account button. This also sets up the originalAction variable
* from above, which lets us figure out if we're linking or unlinking, which makes this.submitAction do post different API calls
*/
for (let i = 0; i < this.buttonBgs.length - 1; i++) {
this.buttonBgs[i].off("pointerdown");
this.buttonBgs[i].on("pointerdown", () => {
originAction = i;
if (this.submitAction) {
this.submitAction();
}
});
}
this.submitAction = (_) => { this.submitAction = (_) => {
this.submitAction = originalSubmitAction; this.submitAction = originalSubmitAction;
this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] }); this.scene.ui.setMode(Mode.LOADING, { buttonActions: [] });
@ -61,20 +77,37 @@ export default class AdminUiHandler extends FormModalUiHandler {
if (!this.inputs[1].text) { if (!this.inputs[1].text) {
return onFail("Discord Id is required"); 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) if (originAction === 0) {
.then(response => { Utils.apiPost("admin/account/discord-link", `username=${encodeURIComponent(this.inputs[0].text)}&discordId=${encodeURIComponent(this.inputs[1].text)}`, "application/x-www-form-urlencoded", true)
if (!response.ok) { .then(response => {
console.error(response); if (!response.ok) {
} console.error(response);
this.inputs[0].setText(""); }
this.inputs[1].setText(""); this.inputs[0].setText("");
this.scene.ui.revertMode(); this.inputs[1].setText("");
}) this.scene.ui.revertMode();
.catch((err) => { })
console.error(err); .catch((err) => {
this.scene.ui.revertMode(); console.error(err);
}); this.scene.ui.revertMode();
return false; });
return false;
} else if (originAction === 1) {
Utils.apiPost("admin/account/discord-unlink", `username=${encodeURIComponent(this.inputs[0].text)}&discordId=${encodeURIComponent(this.inputs[1].text)}`, "application/x-www-form-urlencoded", true)
.then(response => {
if (!response.ok) {
console.error(response);
}
this.inputs[0].setText("");
this.inputs[1].setText("");
this.scene.ui.revertMode();
})
.catch((err) => {
console.error(err);
this.scene.ui.revertMode();
});
return false;
}
}; };
return true; return true;
} }

View File

@ -393,6 +393,9 @@ export default class MenuUiHandler extends MessageUiHandler {
() => { () => {
ui.revertMode(); ui.revertMode();
}, },
() => {
ui.revertMode();
},
() => { () => {
ui.revertMode(); ui.revertMode();
} }