mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 04:11:12 +00:00
Leave admin confirmation (#2556)
* Add confirmmation modal for leaving admin team * Add translations
This commit is contained in:
parent
4f37a3bee3
commit
ede761f6c8
2 changed files with 25 additions and 5 deletions
|
@ -1 +1 @@
|
|||
Subproject commit 30e80d40fd399c1ab4f55276f153f44f1fd04c41
|
||||
Subproject commit ee2cffac809ad466644f061ad79ac577b6c2e4fd
|
|
@ -3,7 +3,7 @@ import { capitalizeFirstLetter, resourcesSettled } from "@utils/helpers";
|
|||
import { scrollMixin } from "../mixins/scroll-mixin";
|
||||
import { RouteDataResponse } from "@utils/types";
|
||||
import classNames from "classnames";
|
||||
import { Component, linkEvent } from "inferno";
|
||||
import { Component } from "inferno";
|
||||
import {
|
||||
BannedPersonsResponse,
|
||||
CreateCustomEmoji,
|
||||
|
@ -42,6 +42,7 @@ import { MediaUploads } from "../common/media-uploads";
|
|||
import { Paginator } from "../common/paginator";
|
||||
import { snapToTop } from "@utils/browser";
|
||||
import { isBrowser } from "@utils/browser";
|
||||
import ConfirmationModal from "../common/confirmation-modal";
|
||||
|
||||
type AdminSettingsData = RouteDataResponse<{
|
||||
bannedRes: BannedPersonsResponse;
|
||||
|
@ -55,6 +56,7 @@ interface AdminSettingsState {
|
|||
instancesRes: RequestState<GetFederatedInstancesResponse>;
|
||||
bannedRes: RequestState<BannedPersonsResponse>;
|
||||
leaveAdminTeamRes: RequestState<GetSiteResponse>;
|
||||
showConfirmLeaveAdmin: boolean;
|
||||
uploadsRes: RequestState<ListMediaResponse>;
|
||||
uploadsPage: number;
|
||||
loading: boolean;
|
||||
|
@ -82,6 +84,7 @@ export class AdminSettings extends Component<
|
|||
bannedRes: EMPTY_REQUEST,
|
||||
instancesRes: EMPTY_REQUEST,
|
||||
leaveAdminTeamRes: EMPTY_REQUEST,
|
||||
showConfirmLeaveAdmin: false,
|
||||
uploadsRes: EMPTY_REQUEST,
|
||||
uploadsPage: 1,
|
||||
loading: false,
|
||||
|
@ -105,6 +108,9 @@ export class AdminSettings extends Component<
|
|||
this.handleDeleteEmoji = this.handleDeleteEmoji.bind(this);
|
||||
this.handleCreateEmoji = this.handleCreateEmoji.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
|
||||
if (FirstLoadService.isFirstLoad) {
|
||||
|
@ -340,6 +346,13 @@ export class AdminSettings extends Component<
|
|||
))}
|
||||
</ul>
|
||||
{this.leaveAdmin()}
|
||||
<ConfirmationModal
|
||||
message={I18NextService.i18n.t("leave_admin_team_confirmation")}
|
||||
loadingMessage={I18NextService.i18n.t("leaving_admin_team")}
|
||||
onNo={this.handleToggleShowLeaveAdminConfirmation}
|
||||
onYes={this.handleLeaveAdminTeam}
|
||||
show={this.state.showConfirmLeaveAdmin}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -347,7 +360,7 @@ export class AdminSettings extends Component<
|
|||
leaveAdmin() {
|
||||
return (
|
||||
<button
|
||||
onClick={linkEvent(this, this.handleLeaveAdminTeam)}
|
||||
onClick={this.handleToggleShowLeaveAdminConfirmation}
|
||||
className="btn btn-danger mb-2"
|
||||
>
|
||||
{this.state.leaveAdminTeamRes.state === "loading" ? (
|
||||
|
@ -432,14 +445,21 @@ export class AdminSettings extends Component<
|
|||
return editRes;
|
||||
}
|
||||
|
||||
async handleLeaveAdminTeam(i: AdminSettings) {
|
||||
i.setState({ leaveAdminTeamRes: LOADING_REQUEST });
|
||||
handleToggleShowLeaveAdminConfirmation() {
|
||||
this.setState(prev => ({
|
||||
showConfirmLeaveAdmin: !prev.showConfirmLeaveAdmin,
|
||||
}));
|
||||
}
|
||||
|
||||
async handleLeaveAdminTeam() {
|
||||
this.setState({ leaveAdminTeamRes: LOADING_REQUEST });
|
||||
this.setState({
|
||||
leaveAdminTeamRes: await HttpService.client.leaveAdmin(),
|
||||
});
|
||||
|
||||
if (this.state.leaveAdminTeamRes.state === "success") {
|
||||
toast(I18NextService.i18n.t("left_admin_team"));
|
||||
this.setState({ showConfirmLeaveAdmin: false });
|
||||
this.context.router.history.replace("/");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue