login.jsx (1847B)
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 const { useTextInput, useValue } = require("../../lib/form"); 26 const useFormSubmit = require("../../lib/form/submit"); 27 const { TextInput } = require("../form/inputs"); 28 const MutationButton = require("../form/mutation-button"); 29 const Loading = require("../loading"); 30 31 module.exports = function Login({ }) { 32 const form = { 33 instance: useTextInput("instance", { 34 defaultValue: window.location.origin 35 }), 36 scopes: useValue("scopes", "user admin") 37 }; 38 39 const [formSubmit, result] = useFormSubmit( 40 form, 41 query.useAuthorizeFlowMutation(), 42 { changedOnly: false } 43 ); 44 45 if (result.isLoading) { 46 return ( 47 <div> 48 <Loading /> Checking instance. 49 </div> 50 ); 51 } else if (result.isSuccess) { 52 return ( 53 <div> 54 <Loading /> Redirecting to instance authorization page. 55 </div> 56 ); 57 } 58 59 return ( 60 <form onSubmit={formSubmit}> 61 <TextInput 62 field={form.instance} 63 label="Instance" 64 name="instance" 65 /> 66 <MutationButton label="Login" result={result} /> 67 </form> 68 ); 69 };