2023-03-20 15:45:52 -07:00
|
|
|
import React, { useState } from 'react';
|
2023-03-20 16:49:41 -07:00
|
|
|
import { FormattedMessage } from 'react-intl';
|
2023-03-20 15:45:52 -07:00
|
|
|
|
2023-03-20 16:49:41 -07:00
|
|
|
import { HStack, IconButton, Text } from 'soapbox/components/ui';
|
2023-03-20 15:45:52 -07:00
|
|
|
|
|
|
|
interface IAuthorizeRejectButtons {
|
2023-03-20 17:22:00 -07:00
|
|
|
onAuthorize(): Promise<unknown> | unknown
|
|
|
|
onReject(): Promise<unknown> | unknown
|
2023-03-20 15:45:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Buttons to approve or reject a pending item, usually an account. */
|
2023-03-20 17:22:00 -07:00
|
|
|
const AuthorizeRejectButtons: React.FC<IAuthorizeRejectButtons> = ({ onAuthorize, onReject }) => {
|
2023-03-20 15:45:52 -07:00
|
|
|
const [state, setState] = useState<'authorized' | 'rejected' | 'pending'>('pending');
|
|
|
|
|
2023-03-20 17:22:00 -07:00
|
|
|
async function handleAuthorize() {
|
|
|
|
try {
|
|
|
|
await onAuthorize();
|
|
|
|
setState('authorized');
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2023-03-20 15:45:52 -07:00
|
|
|
}
|
|
|
|
|
2023-03-20 17:22:00 -07:00
|
|
|
async function handleReject() {
|
|
|
|
try {
|
|
|
|
await onReject();
|
|
|
|
setState('rejected');
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
|
|
|
}
|
2023-03-20 15:45:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case 'pending':
|
|
|
|
return (
|
2023-03-20 16:26:27 -07:00
|
|
|
<HStack space={3} alignItems='center'>
|
|
|
|
<IconButton
|
|
|
|
src={require('@tabler/icons/x.svg')}
|
2023-03-20 15:45:52 -07:00
|
|
|
onClick={handleReject}
|
2023-03-20 18:11:21 -07:00
|
|
|
theme='seamless'
|
|
|
|
className='h-10 w-10 items-center justify-center border-2 border-danger-600/10 hover:border-danger-600'
|
2023-03-20 16:26:27 -07:00
|
|
|
iconClassName='h-6 w-6 text-danger-600'
|
|
|
|
/>
|
|
|
|
<IconButton
|
|
|
|
src={require('@tabler/icons/check.svg')}
|
|
|
|
onClick={handleAuthorize}
|
2023-03-20 18:11:21 -07:00
|
|
|
theme='seamless'
|
|
|
|
className='h-10 w-10 items-center justify-center border-2 border-primary-500/10 hover:border-primary-500'
|
2023-03-20 16:26:27 -07:00
|
|
|
iconClassName='h-6 w-6 text-primary-500'
|
2023-03-20 15:45:52 -07:00
|
|
|
/>
|
|
|
|
</HStack>
|
|
|
|
);
|
|
|
|
case 'authorized':
|
|
|
|
return (
|
2023-03-20 16:49:41 -07:00
|
|
|
<div className='rounded-full bg-gray-100 px-4 py-2 dark:bg-gray-800'>
|
|
|
|
<Text theme='muted' size='sm'>
|
2023-03-21 09:56:48 -07:00
|
|
|
<FormattedMessage id='authorize.success' defaultMessage='Approved' />
|
2023-03-20 16:49:41 -07:00
|
|
|
</Text>
|
|
|
|
</div>
|
2023-03-20 15:45:52 -07:00
|
|
|
);
|
|
|
|
case 'rejected':
|
|
|
|
return (
|
2023-03-20 16:49:41 -07:00
|
|
|
<div className='rounded-full bg-gray-100 px-4 py-2 dark:bg-gray-800'>
|
|
|
|
<Text theme='muted' size='sm'>
|
|
|
|
<FormattedMessage id='reject.success' defaultMessage='Rejected' />
|
|
|
|
</Text>
|
|
|
|
</div>
|
2023-03-20 15:45:52 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export { AuthorizeRejectButtons };
|