2022-05-30 09:18:31 -07:00
|
|
|
import React, { useState } from 'react';
|
2022-05-19 06:22:15 -07:00
|
|
|
import { MessageDescriptor, useIntl } from 'react-intl';
|
|
|
|
|
|
|
|
import { Button, Form, FormActions, Text } from 'soapbox/components/ui';
|
|
|
|
import { useAppDispatch } from 'soapbox/hooks';
|
2022-06-18 02:51:02 -07:00
|
|
|
import { AppDispatch, RootState } from 'soapbox/store';
|
2022-05-19 06:22:15 -07:00
|
|
|
|
|
|
|
interface ICSVExporter {
|
|
|
|
messages: {
|
|
|
|
input_label: MessageDescriptor,
|
|
|
|
input_hint: MessageDescriptor,
|
|
|
|
submit: MessageDescriptor,
|
|
|
|
},
|
2022-06-18 02:51:02 -07:00
|
|
|
action: () => (dispatch: AppDispatch, getState: () => RootState) => Promise<void>,
|
2022-05-19 06:22:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
const CSVExporter: React.FC<ICSVExporter> = ({ messages, action }) => {
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
const intl = useIntl();
|
|
|
|
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
|
|
|
const handleClick: React.MouseEventHandler = (event) => {
|
|
|
|
setIsLoading(true);
|
|
|
|
dispatch(action()).then(() => {
|
|
|
|
setIsLoading(false);
|
|
|
|
}).catch(() => {
|
|
|
|
setIsLoading(false);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Form>
|
|
|
|
<Text size='xl' weight='bold'>{intl.formatMessage(messages.input_label)}</Text>
|
|
|
|
<Text theme='muted'>{intl.formatMessage(messages.input_hint)}</Text>
|
|
|
|
|
|
|
|
<FormActions>
|
|
|
|
<Button theme='primary' onClick={handleClick} disabled={isLoading}>
|
|
|
|
{intl.formatMessage(messages.submit)}
|
|
|
|
</Button>
|
|
|
|
</FormActions>
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CSVExporter;
|