From 4de892644506bc60673ee980bb10f6dd47e4a747 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 20 Mar 2023 19:22:00 -0500 Subject: [PATCH] IAuthorizeRejectButtons: simplify component --- .../components/authorize-reject-buttons.tsx | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/app/soapbox/components/authorize-reject-buttons.tsx b/app/soapbox/components/authorize-reject-buttons.tsx index 01a45ce8e..690f6a04f 100644 --- a/app/soapbox/components/authorize-reject-buttons.tsx +++ b/app/soapbox/components/authorize-reject-buttons.tsx @@ -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 - onReject(id: string): Promise + onAuthorize(): Promise | unknown + onReject(): Promise | unknown } /** Buttons to approve or reject a pending item, usually an account. */ -const AuthorizeRejectButtons: React.FC = ({ id, onAuthorize, onReject }) => { +const AuthorizeRejectButtons: React.FC = ({ 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) {