IAuthorizeRejectButtons: simplify component

develop^2
Alex Gleason 2023-03-20 19:22:00 -05:00
rodzic f9ab9a45c2
commit 4de8926445
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
1 zmienionych plików z 17 dodań i 12 usunięć

Wyświetl plik

@ -4,25 +4,30 @@ import { FormattedMessage } from 'react-intl';
import { HStack, IconButton, Text } from 'soapbox/components/ui';
interface IAuthorizeRejectButtons {
id: string
onAuthorize(id: string): Promise<unknown>
onReject(id: string): Promise<unknown>
onAuthorize(): Promise<unknown> | unknown
onReject(): Promise<unknown> | unknown
}
/** Buttons to approve or reject a pending item, usually an account. */
const AuthorizeRejectButtons: React.FC<IAuthorizeRejectButtons> = ({ id, onAuthorize, onReject }) => {
const AuthorizeRejectButtons: React.FC<IAuthorizeRejectButtons> = ({ onAuthorize, onReject }) => {
const [state, setState] = useState<'authorized' | 'rejected' | 'pending'>('pending');
function handleAuthorize() {
onAuthorize(id)
.then(() => setState('authorized'))
.catch(console.error);
async function handleAuthorize() {
try {
await onAuthorize();
setState('authorized');
} catch (e) {
console.error(e);
}
}
function handleReject() {
onReject(id)
.then(() => setState('rejected'))
.catch(console.error);
async function handleReject() {
try {
await onReject();
setState('rejected');
} catch (e) {
console.error(e);
}
}
switch (state) {