From adeba99d3845684734d275c94f34492de5de79d1 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 16 Aug 2020 11:05:32 -0400 Subject: [PATCH] Allow mods that aren't creators to leave the mod team. Fixes #786 (#1091) --- ui/src/components/sidebar.tsx | 65 ++++++++++++++++++++++++++++++++++- ui/translations/en.json | 1 + 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/ui/src/components/sidebar.tsx b/ui/src/components/sidebar.tsx index 411d6eccc..b434bb874 100644 --- a/ui/src/components/sidebar.tsx +++ b/ui/src/components/sidebar.tsx @@ -7,9 +7,10 @@ import { DeleteCommunityForm, RemoveCommunityForm, UserView, + AddModToCommunityForm, } from '../interfaces'; import { WebSocketService, UserService } from '../services'; -import { mdToHtml, getUnixTime, pictrsAvatarThumbnail } from '../utils'; +import { mdToHtml, getUnixTime } from '../utils'; import { CommunityForm } from './community-form'; import { UserListing } from './user-listing'; import { CommunityLink } from './community-link'; @@ -30,6 +31,7 @@ interface SidebarState { showRemoveDialog: boolean; removeReason: string; removeExpires: string; + showConfirmLeaveModTeam: boolean; } export class Sidebar extends Component { @@ -38,6 +40,7 @@ export class Sidebar extends Component { showRemoveDialog: false, removeReason: null, removeExpires: null, + showConfirmLeaveModTeam: false, }; constructor(props: any, context: any) { @@ -248,6 +251,45 @@ export class Sidebar extends Component { + {!this.amCreator && + (!this.state.showConfirmLeaveModTeam ? ( +
  • + + {i18n.t('leave_mod_team')} + +
  • + ) : ( + <> +
  • + {i18n.t('are_you_sure')} +
  • +
  • + + {i18n.t('yes')} + +
  • +
  • + + {i18n.t('no')} + +
  • + + ))} {this.amCreator && (
  • { WebSocketService.Instance.deleteCommunity(deleteForm); } + handleShowConfirmLeaveModTeamClick(i: Sidebar) { + i.state.showConfirmLeaveModTeam = true; + i.setState(i.state); + } + + handleLeaveModTeamClick(i: Sidebar) { + let form: AddModToCommunityForm = { + user_id: UserService.Instance.user.id, + community_id: i.props.community.id, + added: false, + }; + WebSocketService.Instance.addModToCommunity(form); + i.state.showConfirmLeaveModTeam = false; + i.setState(i.state); + } + + handleCancelLeaveModTeamClick(i: Sidebar) { + i.state.showConfirmLeaveModTeam = false; + i.setState(i.state); + } + handleUnsubscribe(communityId: number) { event.preventDefault(); let form: FollowCommunityForm = { diff --git a/ui/translations/en.json b/ui/translations/en.json index e3ccf8d9b..cc73c326a 100644 --- a/ui/translations/en.json +++ b/ui/translations/en.json @@ -72,6 +72,7 @@ "site_config": "Site Configuration", "remove_as_mod": "remove as mod", "appoint_as_mod": "appoint as mod", + "leave_mod_team": "leave mod team", "modlog": "Modlog", "admin": "admin", "admins": "admins",