From 5774516ea0802e15f77c0c56de2624b12505dc35 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 20 Mar 2023 19:32:24 -0500 Subject: [PATCH] Reorganize GroupMembershipRequests a little --- .../group/group-membership-requests.tsx | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/app/soapbox/features/group/group-membership-requests.tsx b/app/soapbox/features/group/group-membership-requests.tsx index 9c30bc8cf..eab20c1ef 100644 --- a/app/soapbox/features/group/group-membership-requests.tsx +++ b/app/soapbox/features/group/group-membership-requests.tsx @@ -17,34 +17,21 @@ type RouteParams = { id: string }; const messages = defineMessages({ heading: { id: 'column.group_pending_requests', defaultMessage: 'Pending requests' }, - authorize: { id: 'group.group_mod_authorize', defaultMessage: 'Accept' }, - authorized: { id: 'group.group_mod_authorize.success', defaultMessage: 'Accepted @{name} to group' }, authorizeFail: { id: 'group.group_mod_authorize.fail', defaultMessage: 'Failed to approve @{name}' }, - reject: { id: 'group.group_mod_reject', defaultMessage: 'Reject' }, - rejected: { id: 'group.group_mod_reject.success', defaultMessage: 'Rejected @{name} from group' }, rejectFail: { id: 'group.group_mod_reject.fail', defaultMessage: 'Failed to reject @{name}' }, }); interface IMembershipRequest { account: AccountEntity - onAuthorize(accountId: string): Promise - onReject(accountId: string): Promise + onAuthorize(account: AccountEntity): Promise + onReject(account: AccountEntity): Promise } const MembershipRequest: React.FC = ({ account, onAuthorize, onReject }) => { - const intl = useIntl(); - if (!account) return null; - function handleAuthorize() { - return onAuthorize(account.id) - .catch(() => toast.error(intl.formatMessage(messages.authorizeFail, { name: account.username }))); - } - - function handleReject() { - return onReject(account.id) - .catch(() => toast.error(intl.formatMessage(messages.rejectFail, { name: account.username }))); - } + const handleAuthorize = () => onAuthorize(account); + const handleReject = () => onReject(account); return ( @@ -65,9 +52,8 @@ interface IGroupMembershipRequests { } const GroupMembershipRequests: React.FC = ({ params }) => { - const intl = useIntl(); - const id = params?.id; + const intl = useIntl(); const { group } = useGroup(id); const { accounts, isLoading, authorize, reject } = useGroupMembershipRequests(id); @@ -81,11 +67,24 @@ const GroupMembershipRequests: React.FC = ({ params }) } if (!group.relationship.role || !['owner', 'admin', 'moderator'].includes(group.relationship.role)) { - return (); + return ; } - const handleAuthorize = (accountId: string) => authorize(accountId); - const handleReject = (accountId: string) => reject(accountId); + async function handleAuthorize(account: AccountEntity) { + try { + await authorize(account.id); + } catch (_e) { + toast.error(intl.formatMessage(messages.authorizeFail, { name: account.username })); + } + } + + async function handleReject(account: AccountEntity) { + try { + await reject(account.id); + } catch (_e) { + toast.error(intl.formatMessage(messages.rejectFail, { name: account.username })); + } + } return (