settings.js (3688B)
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 24 const query = require("../lib/query"); 25 26 const { 27 useTextInput, 28 useFileInput 29 } = require("../lib/form"); 30 31 const useFormSubmit = require("../lib/form/submit"); 32 33 const { 34 TextInput, 35 TextArea, 36 FileInput 37 } = require("../components/form/inputs"); 38 39 const FormWithData = require("../lib/form/form-with-data"); 40 const MutationButton = require("../components/form/mutation-button"); 41 42 module.exports = function AdminSettings() { 43 return ( 44 <FormWithData 45 dataQuery={query.useInstanceQuery} 46 DataForm={AdminSettingsForm} 47 /> 48 ); 49 }; 50 51 function AdminSettingsForm({ data: instance }) { 52 const form = { 53 title: useTextInput("title", { 54 source: instance, 55 validator: (val) => val.length <= 40 ? "" : "Instance title must be 40 characters or less" 56 }), 57 thumbnail: useFileInput("thumbnail", { withPreview: true }), 58 thumbnailDesc: useTextInput("thumbnail_description", { source: instance }), 59 shortDesc: useTextInput("short_description", { source: instance }), 60 description: useTextInput("description", { source: instance }), 61 contactUser: useTextInput("contact_username", { source: instance, valueSelector: (s) => s.contact_account?.username }), 62 contactEmail: useTextInput("contact_email", { source: instance, valueSelector: (s) => s.email }), 63 terms: useTextInput("terms", { source: instance }) 64 }; 65 66 const [submitForm, result] = useFormSubmit(form, query.useUpdateInstanceMutation()); 67 68 return ( 69 <form onSubmit={submitForm}> 70 <h1>Instance Settings</h1> 71 <TextInput 72 field={form.title} 73 label="Title" 74 placeholder="My GoToSocial instance" 75 /> 76 77 <div className="file-upload"> 78 <h3>Instance thumbnail</h3> 79 <div> 80 <img className="preview avatar" src={form.thumbnail.previewValue ?? instance.thumbnail} alt={form.thumbnailDesc.value ?? (instance.thumbnail ? `Thumbnail image for the instance` : "No instance thumbnail image set")} /> 81 <FileInput 82 field={form.thumbnail} 83 accept="image/*" 84 /> 85 </div> 86 </div> 87 88 <TextInput 89 field={form.thumbnailDesc} 90 label="Instance thumbnail description" 91 placeholder="A cute drawing of a smiling sloth." 92 /> 93 94 <TextArea 95 field={form.shortDesc} 96 label="Short description" 97 placeholder="A small testing instance for the GoToSocial alpha software." 98 /> 99 100 <TextArea 101 field={form.description} 102 label="Full description" 103 placeholder="A small testing instance for the GoToSocial alpha software. Just trying it out, my main instance is https://example.com" 104 /> 105 106 <TextInput 107 field={form.contactUser} 108 label="Contact user (local account username)" 109 placeholder="admin" 110 /> 111 112 <TextInput 113 field={form.contactEmail} 114 label="Contact email" 115 placeholder="admin@example.com" 116 /> 117 118 <TextArea 119 field={form.terms} 120 label="Terms & Conditions" 121 placeholder="" 122 /> 123 124 <MutationButton label="Save" result={result} /> 125 </form> 126 ); 127 }