From 7a1e6394831fb07e303c5ed0900dfe1ea4820de5 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:12:47 +0200 Subject: [chore] Refactor settings panel routing (and other fixes) (#2864) --- .../settings/admin/accounts/detail/actions.tsx | 89 ---------- .../admin/accounts/detail/handlesignup.tsx | 118 -------------- .../settings/admin/accounts/detail/index.tsx | 179 --------------------- web/source/settings/admin/accounts/index.tsx | 49 ------ .../settings/admin/accounts/pending/index.tsx | 40 ----- .../settings/admin/accounts/search/index.tsx | 125 -------------- 6 files changed, 600 deletions(-) delete mode 100644 web/source/settings/admin/accounts/detail/actions.tsx delete mode 100644 web/source/settings/admin/accounts/detail/handlesignup.tsx delete mode 100644 web/source/settings/admin/accounts/detail/index.tsx delete mode 100644 web/source/settings/admin/accounts/index.tsx delete mode 100644 web/source/settings/admin/accounts/pending/index.tsx delete mode 100644 web/source/settings/admin/accounts/search/index.tsx (limited to 'web/source/settings/admin/accounts') diff --git a/web/source/settings/admin/accounts/detail/actions.tsx b/web/source/settings/admin/accounts/detail/actions.tsx deleted file mode 100644 index 75ab8db6e..000000000 --- a/web/source/settings/admin/accounts/detail/actions.tsx +++ /dev/null @@ -1,89 +0,0 @@ -/* - GoToSocial - Copyright (C) GoToSocial Authors admin@gotosocial.org - SPDX-License-Identifier: AGPL-3.0-or-later - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -import React from "react"; - -import { useActionAccountMutation } from "../../../lib/query"; - -import MutationButton from "../../../components/form/mutation-button"; - -import useFormSubmit from "../../../lib/form/submit"; -import { - useValue, - useTextInput, - useBoolInput, -} from "../../../lib/form"; - -import { Checkbox, TextInput } from "../../../components/form/inputs"; -import { AdminAccount } from "../../../lib/types/account"; - -export interface AccountActionsProps { - account: AdminAccount, -} - -export function AccountActions({ account }: AccountActionsProps) { - const form = { - id: useValue("id", account.id), - reason: useTextInput("text") - }; - - const reallySuspend = useBoolInput("reallySuspend"); - const [accountAction, result] = useFormSubmit(form, useActionAccountMutation()); - - return ( -
-

Account Moderation Actions

-
- Currently only the "suspend" action is implemented.
- Suspending an account will delete it from your server, and remove all of its media, posts, relationships, etc.
- If the suspended account is local, suspending will also send out a "delete" message to other servers, requesting them to remove its data from their instance as well.
- Account suspension cannot be reversed. -
- -
- {/* - */} - - -
- - ); -} diff --git a/web/source/settings/admin/accounts/detail/handlesignup.tsx b/web/source/settings/admin/accounts/detail/handlesignup.tsx deleted file mode 100644 index a61145a22..000000000 --- a/web/source/settings/admin/accounts/detail/handlesignup.tsx +++ /dev/null @@ -1,118 +0,0 @@ -/* - GoToSocial - Copyright (C) GoToSocial Authors admin@gotosocial.org - SPDX-License-Identifier: AGPL-3.0-or-later - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -import React from "react"; -import { useLocation } from "wouter"; - -import { useHandleSignupMutation } from "../../../lib/query"; - -import MutationButton from "../../../components/form/mutation-button"; - -import useFormSubmit from "../../../lib/form/submit"; -import { - useValue, - useTextInput, - useBoolInput, -} from "../../../lib/form"; - -import { Checkbox, Select, TextInput } from "../../../components/form/inputs"; -import { AdminAccount } from "../../../lib/types/account"; - -export interface HandleSignupProps { - account: AdminAccount, - accountsBaseUrl: string, -} - -export function HandleSignup({account, accountsBaseUrl}: HandleSignupProps) { - const form = { - id: useValue("id", account.id), - approveOrReject: useTextInput("approve_or_reject", { defaultValue: "approve" }), - privateComment: useTextInput("private_comment"), - message: useTextInput("message"), - sendEmail: useBoolInput("send_email"), - }; - - const [_location, setLocation] = useLocation(); - - const [handleSignup, result] = useFormSubmit(form, useHandleSignupMutation(), { - changedOnly: false, - // After submitting the form, redirect back to - // /settings/admin/accounts if rejecting, since - // account will no longer be available at - // /settings/admin/accounts/:accountID endpoint. - onFinish: (res) => { - if (form.approveOrReject.value === "approve") { - // An approve request: - // stay on this page and - // serve updated details. - return; - } - - if (res.data) { - // "reject" successful, - // redirect to accounts page. - setLocation(accountsBaseUrl); - } - } - }); - - return ( -
-

Handle Account Sign-Up

- - { form.approveOrReject.value === "reject" && - // Only show form fields relevant - // to "reject" if rejecting. - // On "approve" these fields will - // be ignored anyway. - <> - - - - } - - - ); -} diff --git a/web/source/settings/admin/accounts/detail/index.tsx b/web/source/settings/admin/accounts/detail/index.tsx deleted file mode 100644 index 79eb493de..000000000 --- a/web/source/settings/admin/accounts/detail/index.tsx +++ /dev/null @@ -1,179 +0,0 @@ -/* - GoToSocial - Copyright (C) GoToSocial Authors admin@gotosocial.org - SPDX-License-Identifier: AGPL-3.0-or-later - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -import React from "react"; -import { useRoute, Redirect } from "wouter"; - -import { useGetAccountQuery } from "../../../lib/query"; - -import FormWithData from "../../../lib/form/form-with-data"; - -import { useBaseUrl } from "../../../lib/navigation/util"; -import FakeProfile from "../../../components/fake-profile"; - -import { AdminAccount } from "../../../lib/types/account"; -import { HandleSignup } from "./handlesignup"; -import { AccountActions } from "./actions"; -import BackButton from "../../../components/back-button"; - -export default function AccountDetail() { - // /settings/admin/accounts - const accountsBaseUrl = useBaseUrl(); - - let [_match, params] = useRoute(`${accountsBaseUrl}/:accountId`); - - if (params?.accountId == undefined) { - return ; - } else { - return ( -
-

- Account Details -

- -
- ); - } -} - -interface AccountDetailFormProps { - accountsBaseUrl: string, - data: AdminAccount, -} - -function AccountDetailForm({ data: adminAcct, accountsBaseUrl }: AccountDetailFormProps) { - let yesOrNo = (b: boolean) => { - return b ? "yes" : "no"; - }; - - let created = new Date(adminAcct.created_at).toDateString(); - let lastPosted = "never"; - if (adminAcct.account.last_status_at) { - lastPosted = new Date(adminAcct.account.last_status_at).toDateString(); - } - const local = !adminAcct.domain; - - return ( - <> - -

General Account Details

- { adminAcct.suspended && -
- - Account is suspended. -
- } -
- { !local && -
-
Domain
-
{adminAcct.domain}
-
} -
-
Created
-
-
-
-
Last posted
-
{lastPosted}
-
-
-
Suspended
-
{yesOrNo(adminAcct.suspended)}
-
-
-
Silenced
-
{yesOrNo(adminAcct.silenced)}
-
-
-
Statuses
-
{adminAcct.account.statuses_count}
-
-
-
Followers
-
{adminAcct.account.followers_count}
-
-
-
Following
-
{adminAcct.account.following_count}
-
-
- { local && - // Only show local account details - // if this is a local account! - <> -

Local Account Details

- { !adminAcct.approved && -
- - Account is pending. -
- } - { !adminAcct.confirmed && -
- - Account email not yet confirmed. -
- } -
-
-
Email
-
{adminAcct.email} {{adminAcct.confirmed ? "(confirmed)" : "(not confirmed)"} }
-
-
-
Disabled
-
{yesOrNo(adminAcct.disabled)}
-
-
-
Approved
-
{yesOrNo(adminAcct.approved)}
-
-
-
Sign-Up Reason
-
{adminAcct.invite_request ?? none provided}
-
- { (adminAcct.ip && adminAcct.ip !== "0.0.0.0") && -
-
Sign-Up IP
-
{adminAcct.ip}
-
} - { adminAcct.locale && -
-
Locale
-
{adminAcct.locale}
-
} -
- } - { local && !adminAcct.approved - ? - - : - - } - - ); -} diff --git a/web/source/settings/admin/accounts/index.tsx b/web/source/settings/admin/accounts/index.tsx deleted file mode 100644 index 3c69f7406..000000000 --- a/web/source/settings/admin/accounts/index.tsx +++ /dev/null @@ -1,49 +0,0 @@ -/* - GoToSocial - Copyright (C) GoToSocial Authors admin@gotosocial.org - SPDX-License-Identifier: AGPL-3.0-or-later - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -import React from "react"; -import { Switch, Route } from "wouter"; - -import AccountDetail from "./detail"; -import { AccountSearchForm } from "./search"; - -export default function Accounts({ baseUrl }) { - return ( - - - - - - - ); -} - -function AccountOverview({ }) { - return ( -
-

Accounts Overview

- - You can perform actions on an account by clicking - its name in a report, or by searching for the account - using the form below and clicking on its name. - - -
- ); -} diff --git a/web/source/settings/admin/accounts/pending/index.tsx b/web/source/settings/admin/accounts/pending/index.tsx deleted file mode 100644 index 459472147..000000000 --- a/web/source/settings/admin/accounts/pending/index.tsx +++ /dev/null @@ -1,40 +0,0 @@ -/* - GoToSocial - Copyright (C) GoToSocial Authors admin@gotosocial.org - SPDX-License-Identifier: AGPL-3.0-or-later - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -import React from "react"; -import { useSearchAccountsQuery } from "../../../lib/query"; -import { AccountList } from "../../../components/account-list"; - -export default function AccountsPending() { - const searchRes = useSearchAccountsQuery({status: "pending"}); - - return ( -
-

Pending Accounts

- -
- ); -} diff --git a/web/source/settings/admin/accounts/search/index.tsx b/web/source/settings/admin/accounts/search/index.tsx deleted file mode 100644 index 560bbb76a..000000000 --- a/web/source/settings/admin/accounts/search/index.tsx +++ /dev/null @@ -1,125 +0,0 @@ -/* - GoToSocial - Copyright (C) GoToSocial Authors admin@gotosocial.org - SPDX-License-Identifier: AGPL-3.0-or-later - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -import React from "react"; - -import { useLazySearchAccountsQuery } from "../../../lib/query"; -import { useTextInput } from "../../../lib/form"; - -import { AccountList } from "../../../components/account-list"; -import { SearchAccountParams } from "../../../lib/types/account"; -import { Select, TextInput } from "../../../components/form/inputs"; -import MutationButton from "../../../components/form/mutation-button"; - -export function AccountSearchForm() { - const [searchAcct, searchRes] = useLazySearchAccountsQuery(); - - const form = { - origin: useTextInput("origin"), - status: useTextInput("status"), - permissions: useTextInput("permissions"), - username: useTextInput("username"), - display_name: useTextInput("display_name"), - by_domain: useTextInput("by_domain"), - email: useTextInput("email"), - ip: useTextInput("ip"), - }; - - function submitSearch(e) { - e.preventDefault(); - - // Parse query parameters. - const entries = Object.entries(form).map(([k, v]) => { - // Take only defined form fields. - if (v.value === undefined || v.value.length === 0) { - return null; - } - return [[k, v.value]]; - }).flatMap(kv => { - // Remove any nulls. - return kv || []; - }); - - const params: SearchAccountParams = Object.fromEntries(entries); - searchAcct(params); - } - - return ( - <> -
- - - - - - - - - - - ); -} -- cgit v1.3