mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-09 18:05:09 +00:00
Add confirmmation modal for leaving admin team
This commit is contained in:
parent
4f37a3bee3
commit
9c51c913e9
|
@ -3,7 +3,7 @@ import { capitalizeFirstLetter, resourcesSettled } from "@utils/helpers";
|
||||||
import { scrollMixin } from "../mixins/scroll-mixin";
|
import { scrollMixin } from "../mixins/scroll-mixin";
|
||||||
import { RouteDataResponse } from "@utils/types";
|
import { RouteDataResponse } from "@utils/types";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { Component, linkEvent } from "inferno";
|
import { Component } from "inferno";
|
||||||
import {
|
import {
|
||||||
BannedPersonsResponse,
|
BannedPersonsResponse,
|
||||||
CreateCustomEmoji,
|
CreateCustomEmoji,
|
||||||
|
@ -42,6 +42,7 @@ import { MediaUploads } from "../common/media-uploads";
|
||||||
import { Paginator } from "../common/paginator";
|
import { Paginator } from "../common/paginator";
|
||||||
import { snapToTop } from "@utils/browser";
|
import { snapToTop } from "@utils/browser";
|
||||||
import { isBrowser } from "@utils/browser";
|
import { isBrowser } from "@utils/browser";
|
||||||
|
import ConfirmationModal from "../common/confirmation-modal";
|
||||||
|
|
||||||
type AdminSettingsData = RouteDataResponse<{
|
type AdminSettingsData = RouteDataResponse<{
|
||||||
bannedRes: BannedPersonsResponse;
|
bannedRes: BannedPersonsResponse;
|
||||||
|
@ -55,6 +56,7 @@ interface AdminSettingsState {
|
||||||
instancesRes: RequestState<GetFederatedInstancesResponse>;
|
instancesRes: RequestState<GetFederatedInstancesResponse>;
|
||||||
bannedRes: RequestState<BannedPersonsResponse>;
|
bannedRes: RequestState<BannedPersonsResponse>;
|
||||||
leaveAdminTeamRes: RequestState<GetSiteResponse>;
|
leaveAdminTeamRes: RequestState<GetSiteResponse>;
|
||||||
|
showConfirmLeaveAdmin: boolean;
|
||||||
uploadsRes: RequestState<ListMediaResponse>;
|
uploadsRes: RequestState<ListMediaResponse>;
|
||||||
uploadsPage: number;
|
uploadsPage: number;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
@ -82,6 +84,7 @@ export class AdminSettings extends Component<
|
||||||
bannedRes: EMPTY_REQUEST,
|
bannedRes: EMPTY_REQUEST,
|
||||||
instancesRes: EMPTY_REQUEST,
|
instancesRes: EMPTY_REQUEST,
|
||||||
leaveAdminTeamRes: EMPTY_REQUEST,
|
leaveAdminTeamRes: EMPTY_REQUEST,
|
||||||
|
showConfirmLeaveAdmin: false,
|
||||||
uploadsRes: EMPTY_REQUEST,
|
uploadsRes: EMPTY_REQUEST,
|
||||||
uploadsPage: 1,
|
uploadsPage: 1,
|
||||||
loading: false,
|
loading: false,
|
||||||
|
@ -105,6 +108,9 @@ export class AdminSettings extends Component<
|
||||||
this.handleDeleteEmoji = this.handleDeleteEmoji.bind(this);
|
this.handleDeleteEmoji = this.handleDeleteEmoji.bind(this);
|
||||||
this.handleCreateEmoji = this.handleCreateEmoji.bind(this);
|
this.handleCreateEmoji = this.handleCreateEmoji.bind(this);
|
||||||
this.handleUploadsPageChange = this.handleUploadsPageChange.bind(this);
|
this.handleUploadsPageChange = this.handleUploadsPageChange.bind(this);
|
||||||
|
this.handleToggleShowLeaveAdminConfirmation =
|
||||||
|
this.handleToggleShowLeaveAdminConfirmation.bind(this);
|
||||||
|
this.handleLeaveAdminTeam = this.handleLeaveAdminTeam.bind(this);
|
||||||
|
|
||||||
// Only fetch the data if coming from another route
|
// Only fetch the data if coming from another route
|
||||||
if (FirstLoadService.isFirstLoad) {
|
if (FirstLoadService.isFirstLoad) {
|
||||||
|
@ -340,6 +346,13 @@ export class AdminSettings extends Component<
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
{this.leaveAdmin()}
|
{this.leaveAdmin()}
|
||||||
|
<ConfirmationModal
|
||||||
|
message="Are you sure you want to leave the admin team?"
|
||||||
|
loadingMessage="Leaving admin team"
|
||||||
|
onNo={this.handleToggleShowLeaveAdminConfirmation}
|
||||||
|
onYes={this.handleLeaveAdminTeam}
|
||||||
|
show={this.state.showConfirmLeaveAdmin}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -347,7 +360,7 @@ export class AdminSettings extends Component<
|
||||||
leaveAdmin() {
|
leaveAdmin() {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
onClick={linkEvent(this, this.handleLeaveAdminTeam)}
|
onClick={this.handleToggleShowLeaveAdminConfirmation}
|
||||||
className="btn btn-danger mb-2"
|
className="btn btn-danger mb-2"
|
||||||
>
|
>
|
||||||
{this.state.leaveAdminTeamRes.state === "loading" ? (
|
{this.state.leaveAdminTeamRes.state === "loading" ? (
|
||||||
|
@ -432,14 +445,21 @@ export class AdminSettings extends Component<
|
||||||
return editRes;
|
return editRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleLeaveAdminTeam(i: AdminSettings) {
|
handleToggleShowLeaveAdminConfirmation() {
|
||||||
i.setState({ leaveAdminTeamRes: LOADING_REQUEST });
|
this.setState(prev => ({
|
||||||
|
showConfirmLeaveAdmin: !prev.showConfirmLeaveAdmin,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleLeaveAdminTeam() {
|
||||||
|
this.setState({ leaveAdminTeamRes: LOADING_REQUEST });
|
||||||
this.setState({
|
this.setState({
|
||||||
leaveAdminTeamRes: await HttpService.client.leaveAdmin(),
|
leaveAdminTeamRes: await HttpService.client.leaveAdmin(),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.state.leaveAdminTeamRes.state === "success") {
|
if (this.state.leaveAdminTeamRes.state === "success") {
|
||||||
toast(I18NextService.i18n.t("left_admin_team"));
|
toast(I18NextService.i18n.t("left_admin_team"));
|
||||||
|
this.setState({ showConfirmLeaveAdmin: false });
|
||||||
this.context.router.history.replace("/");
|
this.context.router.history.replace("/");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue