mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-28 08:27:36 +00:00
Leave admin confirmation (#2556)
* Add confirmmation modal for leaving admin team * Add translations
This commit is contained in:
parent
4f37a3bee3
commit
ede761f6c8
|
@ -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 { 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={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() {
|
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