diff --git a/client/src/containers/Alerts/ExchangeRates/ExchangeRateBulkDeleteAlert.js b/client/src/containers/Alerts/ExchangeRates/ExchangeRateBulkDeleteAlert.js new file mode 100644 index 000000000..73e60e689 --- /dev/null +++ b/client/src/containers/Alerts/ExchangeRates/ExchangeRateBulkDeleteAlert.js @@ -0,0 +1,71 @@ +import React, { useState } from 'react'; +import { FormattedMessage as T, useIntl } from 'react-intl'; +import { Intent, Alert } from '@blueprintjs/core'; +import { size } from 'lodash'; +import { AppToaster } from 'components'; + +import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; +import withAlertActions from 'containers/Alert/withAlertActions'; + +import { compose } from 'utils'; + +/** + * Exchange rate bulk delete alert. + */ +function ExchangeRateBulkDeleteAlert({ + name, + + // #withAlertStoreConnect + isOpen, + payload: { exchangeRatesIds }, + + // #withAlertActions + closeAlert, +}) { + // handle cancel item bulk delete alert. + const handleCancelBulkDelete = () => { + closeAlert(name); + }; + + // handle confirm Exchange Rates bulk delete. + // const handleConfirmBulkDelete = () => { + // bulkDeleteExchangeRate(exchangeRatesIds) + // .then(() => { + // AppToaster.show({ + // message: formatMessage({ + // id: 'the_exchange_rates_has_been_successfully_deleted', + // }), + // intent: Intent.SUCCESS, + // }); + // }) + // .catch(({ errors }) => { + // handleDeleteErrors(errors); + // }); + // }; + + return ( + } + confirmButtonText={ + + } + icon="trash" + intent={Intent.DANGER} + isOpen={isOpen} + onCancel={handleCancelBulkDelete} + // onConfirm={} + // loading={isLoading} + > +

+ +

+
+ ); +} + +export default compose( + withAlertStoreConnect(), + withAlertActions, +)(ExchangeRateBulkDeleteAlert); diff --git a/client/src/containers/Alerts/ExchangeRates/ExchangeRateDeleteAlert.js b/client/src/containers/Alerts/ExchangeRates/ExchangeRateDeleteAlert.js new file mode 100644 index 000000000..e13bd0faa --- /dev/null +++ b/client/src/containers/Alerts/ExchangeRates/ExchangeRateDeleteAlert.js @@ -0,0 +1,76 @@ +import React from 'react'; +import { + FormattedMessage as T, + FormattedHTMLMessage, + useIntl, +} from 'react-intl'; +import { Intent, Alert } from '@blueprintjs/core'; +import { AppToaster } from 'components'; + +import { useDeleteExchangeRate } from 'hooks/query'; +import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; +import withAlertActions from 'containers/Alert/withAlertActions'; + +import { compose } from 'utils'; + +/** + * exchange rate delete alerts. + */ +function ExchangeRateDeleteAlert({ + name, + + // #withAlertStoreConnect + isOpen, + payload: { exchangeRateId }, + + // #withAlertActions + closeAlert, +}) { + const { + mutateAsync: deleteExchangeRate, + isLoading, + } = useDeleteExchangeRate(); + const { formatMessage } = useIntl(); + + // Handle cancel delete exchange rate alert. + const handleCancelExchangeRateDelete = () => closeAlert(name); + + const handelConfirmExchangeRateDelete = () => { + deleteExchangeRate(exchangeRateId) + .then((response) => { + AppToaster.show({ + message: formatMessage({ + id: 'the_exchange_rates_has_been_deleted_successfully', + }), + intent: Intent.SUCCESS, + }); + closeAlert(name); + }) + .catch(() => { + closeAlert(name); + }); + }; + + return ( + } + confirmButtonText={} + intent={Intent.DANGER} + isOpen={isOpen} + onCancel={handleCancelExchangeRateDelete} + onConfirm={handelConfirmExchangeRateDelete} + loading={isLoading} + > +

+ +

+
+ ); +} + +export default compose( + withAlertStoreConnect(), + withAlertActions, +)(ExchangeRateDeleteAlert); diff --git a/client/src/containers/ExchangeRates/ExchangeRateTable.js b/client/src/containers/ExchangeRates/ExchangeRateTable.js index c3c2f9a26..8813fa2e2 100644 --- a/client/src/containers/ExchangeRates/ExchangeRateTable.js +++ b/client/src/containers/ExchangeRates/ExchangeRateTable.js @@ -1,183 +1,75 @@ -import React, { useCallback, useMemo, useState } from 'react'; -import { - Button, - Popover, - Menu, - MenuItem, - Position, - Intent, -} from '@blueprintjs/core'; -import { FormattedMessage as T, useIntl } from 'react-intl'; -import moment from 'moment'; -import classNames from 'classnames'; +import React from 'react'; -import { CLASSES } from 'common/classes'; +import { DataTable } from 'components'; +import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; -import { DataTable, Icon, Money } from 'components'; -import LoadingIndicator from 'components/LoadingIndicator'; +import { useExchangeRatesContext } from './ExchangeRatesProvider'; +import { useExchangeRatesTableColumns, ActionMenuList } from './components'; import withDialogActions from 'containers/Dialog/withDialogActions'; -import withExchangeRatesActions from 'containers/ExchangeRates/withExchangeRatesActions'; -import withExchangeRates from 'containers/ExchangeRates/withExchangeRates'; +import withAlertActions from 'containers/Alert/withAlertActions'; import { compose } from 'utils'; +/** + * Exchange rates table. + */ function ExchangeRateTable({ - // #withExchangeRates - exchangeRatesList, - exchangeRatesLoading, - exchangeRatesPageination, + // #ownProps + tableProps, + // #withDialogActions. openDialog, - // own properties - loading, - onFetchData, - onDeleteExchangeRate, - onSelectedRowsChange, + // #withAlertActions + openAlert, }) { - const [initialMount, setInitialMount] = useState(false); - const { formatMessage } = useIntl(); + const { + isExchangeRatesFetching, + isExchangeRatesLoading, - const handelEditExchangeRate = useCallback( - (exchange_rate) => () => { - openDialog('exchangeRate-form', { action: 'edit', id: exchange_rate.id }); - }, - [openDialog], - ); + exchangesRates, + pagination, + } = useExchangeRatesContext(); - const handleDeleteExchangeRate = (exchange_rate) => () => { - onDeleteExchangeRate(exchange_rate); + // Table columns. + const columns = useExchangeRatesTableColumns(); + + // Handle delete exchange rate. + const handleDeleteExchangeRate = ({ id }) => { + openAlert('exchange-rate-delete', { exchangeRateId: id }); }; - const actionMenuList = useCallback( - (ExchangeRate) => ( - - } - text={formatMessage({ id: 'edit_exchange_rate' })} - onClick={handelEditExchangeRate(ExchangeRate)} - /> - } - /> - - ), - [handelEditExchangeRate, handleDeleteExchangeRate, formatMessage], - ); - - const rowContextMenu = (cell) => { - return actionMenuList(cell.row.original); + // Handle Edit exchange rate. + const handelEditExchangeRate = (exchangeRate) => { + openDialog('exchangeRate-form', { + action: 'edit', + exchangeRate: exchangeRate, + }); }; - const columns = useMemo( - () => [ - { - id: 'date', - Header: formatMessage({ id: 'date' }), - accessor: (r) => moment(r.date).format('YYYY MMM DD'), - width: 150, - }, - { - id: 'currency_code', - Header: formatMessage({ id: 'currency_code' }), - accessor: 'currency_code', - className: 'currency_code', - width: 150, - }, - { - id: 'exchange_rate', - Header: formatMessage({ id: 'exchange_rate' }), - accessor: (r) => ( - - ), - className: 'exchange_rate', - width: 150, - }, - { - id: 'actions', - Header: '', - Cell: ({ cell }) => ( - -