IAuthorizeRejectButtons: simplify component

environments/review-group-requ-7youoa/deployments/2930
Alex Gleason 2 years ago
parent f9ab9a45c2
commit 4de8926445
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

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

Loading…
Cancel
Save