gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

detail.jsx (2812B)


      1 /*
      2 	GoToSocial
      3 	Copyright (C) GoToSocial Authors admin@gotosocial.org
      4 	SPDX-License-Identifier: AGPL-3.0-or-later
      5 
      6 	This program is free software: you can redistribute it and/or modify
      7 	it under the terms of the GNU Affero General Public License as published by
      8 	the Free Software Foundation, either version 3 of the License, or
      9 	(at your option) any later version.
     10 
     11 	This program is distributed in the hope that it will be useful,
     12 	but WITHOUT ANY WARRANTY; without even the implied warranty of
     13 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14 	GNU Affero General Public License for more details.
     15 
     16 	You should have received a copy of the GNU Affero General Public License
     17 	along with this program.  If not, see <http://www.gnu.org/licenses/>.
     18 */
     19 
     20 "use strict";
     21 
     22 const React = require("react");
     23 const { useRoute, Redirect } = require("wouter");
     24 
     25 const query = require("../../lib/query");
     26 
     27 const FormWithData = require("../../lib/form/form-with-data");
     28 
     29 const { useBaseUrl } = require("../../lib/navigation/util");
     30 const FakeProfile = require("../../components/fake-profile");
     31 const MutationButton = require("../../components/form/mutation-button");
     32 
     33 const useFormSubmit = require("../../lib/form/submit");
     34 const { useValue, useTextInput } = require("../../lib/form");
     35 const { TextInput } = require("../../components/form/inputs");
     36 
     37 module.exports = function AccountDetail({ }) {
     38 	const baseUrl = useBaseUrl();
     39 
     40 	let [_match, params] = useRoute(`${baseUrl}/:accountId`);
     41 
     42 	if (params?.accountId == undefined) {
     43 		return <Redirect to={baseUrl} />;
     44 	} else {
     45 		return (
     46 			<div className="account-detail">
     47 				<h1>
     48 					Account Details
     49 				</h1>
     50 				<FormWithData
     51 					dataQuery={query.useGetAccountQuery}
     52 					queryArg={params.accountId}
     53 					DataForm={AccountDetailForm}
     54 				/>
     55 			</div>
     56 		);
     57 	}
     58 };
     59 
     60 function AccountDetailForm({ data: account }) {
     61 	let content;
     62 	if (account.suspended) {
     63 		content = (
     64 			<h2 className="error">Account is suspended.</h2>
     65 		);
     66 	} else {
     67 		content = <ModifyAccount account={account} />;
     68 	}
     69 
     70 	return (
     71 		<>
     72 			<FakeProfile {...account} />
     73 
     74 			{content}
     75 		</>
     76 	);
     77 }
     78 
     79 function ModifyAccount({ account }) {
     80 	const form = {
     81 		id: useValue("id", account.id),
     82 		reason: useTextInput("text", {})
     83 	};
     84 
     85 	const [modifyAccount, result] = useFormSubmit(form, query.useActionAccountMutation());
     86 
     87 	return (
     88 		<form onSubmit={modifyAccount}>
     89 			<h2>Actions</h2>
     90 			<TextInput
     91 				field={form.reason}
     92 				placeholder="Reason for this action"
     93 			/>
     94 
     95 			<div className="action-buttons">
     96 				{/* <MutationButton
     97 					label="Disable"
     98 					name="disable"
     99 					result={result}
    100 				/>
    101 				<MutationButton
    102 					label="Silence"
    103 					name="silence"
    104 					result={result}
    105 				/> */}
    106 				<MutationButton
    107 					label="Suspend"
    108 					name="suspend"
    109 					result={result}
    110 				/>
    111 			</div>
    112 		</form>
    113 	);
    114 }