diff --git a/client/src/containers/Alerts/Currencies/CurrencyDeleteAlert.js b/client/src/containers/Alerts/Currencies/CurrencyDeleteAlert.js new file mode 100644 index 000000000..48c40f7dd --- /dev/null +++ b/client/src/containers/Alerts/Currencies/CurrencyDeleteAlert.js @@ -0,0 +1,75 @@ +import React from 'react'; +import { + FormattedMessage as T, + FormattedHTMLMessage, + useIntl, +} from 'react-intl'; +import { Intent, Alert } from '@blueprintjs/core'; +import { AppToaster } from 'components'; + +import { useDeleteCurrency } from 'hooks/query'; + +import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect'; +import withAlertActions from 'containers/Alert/withAlertActions'; + +import { compose } from 'utils'; + +/** + * Currency delete alerts. + */ +function CurrencyDeleteAlert({ + name, + + // #withAlertStoreConnect + isOpen, + payload: { currency_code }, + + // #withAlertActions + closeAlert, +}) { + const { formatMessage } = useIntl(); + const { mutateAsync: deleteCurrency, isLoading } = useDeleteCurrency(); + + // handle cancel delete currency alert. + const handleCancelCurrencyDelete = () => closeAlert(name); + + // handle alert confirm delete currency. + const handleConfirmCurrencyDelete = () => { + deleteCurrency(currency_code) + .then((response) => { + AppToaster.show({ + message: formatMessage({ + id: 'the_currency_has_been_deleted_successfully', + }), + intent: Intent.SUCCESS, + }); + closeAlert(name); + }) + .catch(() => { + closeAlert(name); + }); + }; + + return ( + } + confirmButtonText={} + intent={Intent.DANGER} + isOpen={isOpen} + onCancel={handleCancelCurrencyDelete} + onConfirm={handleConfirmCurrencyDelete} + loading={isLoading} + > +

+ +

+
+ ); +} + +export default compose( + withAlertStoreConnect(), + withAlertActions, +)(CurrencyDeleteAlert); diff --git a/client/src/containers/Dialogs/CurrencyFormDialog/CurrencyFormDialogContent.js b/client/src/containers/Dialogs/CurrencyFormDialog/CurrencyFormDialogContent.js index 439e16a71..d8c1dc07b 100644 --- a/client/src/containers/Dialogs/CurrencyFormDialog/CurrencyFormDialogContent.js +++ b/client/src/containers/Dialogs/CurrencyFormDialog/CurrencyFormDialogContent.js @@ -11,13 +11,13 @@ import 'style/pages/Currency/CurrencyFormDialog.scss'; function CurrencyFormDialogContent({ // #ownProp action, - currency, + currencyCode, dialogName, }) { return ( diff --git a/client/src/containers/Dialogs/CurrencyFormDialog/index.js b/client/src/containers/Dialogs/CurrencyFormDialog/index.js index f97747430..fe98130f2 100644 --- a/client/src/containers/Dialogs/CurrencyFormDialog/index.js +++ b/client/src/containers/Dialogs/CurrencyFormDialog/index.js @@ -13,7 +13,7 @@ const CurrencyFormDialogContent = lazy(() => */ function CurrencyFormDialog({ dialogName, - payload = { action: '', id: null }, + payload = { action: '', id: null, currency: '' }, isOpen, }) { return ( @@ -34,7 +34,7 @@ function CurrencyFormDialog({ diff --git a/client/src/containers/Preferences/Currencies/CurrenciesAlerts.js b/client/src/containers/Preferences/Currencies/CurrenciesAlerts.js new file mode 100644 index 000000000..8fa73e47f --- /dev/null +++ b/client/src/containers/Preferences/Currencies/CurrenciesAlerts.js @@ -0,0 +1,10 @@ +import React from 'react'; +import CurrencyDeleteAlert from 'containers/Alerts/Currencies/CurrencyDeleteAlert'; + +export default function CurrenciesAlerts() { + return ( +
+ +
+ ); +} diff --git a/client/src/containers/Preferences/Currencies/CurrenciesDataTable.js b/client/src/containers/Preferences/Currencies/CurrenciesDataTable.js index 071585af5..ceadb4a8e 100644 --- a/client/src/containers/Preferences/Currencies/CurrenciesDataTable.js +++ b/client/src/containers/Preferences/Currencies/CurrenciesDataTable.js @@ -1,133 +1,69 @@ -import React, { useCallback, useMemo } from 'react'; -import { - Intent, - Button, - Popover, - Menu, - MenuItem, - Position, -} from '@blueprintjs/core'; -import { withRouter } from 'react-router'; -import { useIntl } from 'react-intl'; -import { compose, saveInvoke } from 'utils'; +import React, { useCallback } from 'react'; +import { compose } from 'utils'; -import { DataTable, Icon } from 'components'; +import { DataTable } from 'components'; + +import { useCurrenciesContext } from './CurrenciesProvider'; +import TableSkeletonRows from 'components/Datatable/TableSkeletonRows'; + +import { ActionMenuList, useCurrenciesTableColumns } from './components'; -import withDashboardActions from 'containers/Dashboard/withDashboardActions'; -import withCurrencies from 'containers/Currencies/withCurrencies'; import withDialogActions from 'containers/Dialog/withDialogActions'; +import withAlertActions from 'containers/Alert/withAlertActions'; +/** + * Currencies table. + */ function CurrenciesDataTable({ - // #withCurrencies - currenciesList, - currenciesLoading, - // #ownProps - onFetchData, - onDeleteCurrency, + tableProps, // #withDialog. openDialog, -}) { - const { formatMessage } = useIntl(); + // #withAlertActions + openAlert, +}) { + const { currencies, isCurrenciesLoading } = useCurrenciesContext(); + + // Table columns. + const columns = useCurrenciesTableColumns(); + + // Handle Edit Currency. const handleEditCurrency = useCallback( (currency) => { openDialog('currency-form', { action: 'edit', - currencyCode: currency.currency_code, + currency: currency, }); }, [openDialog], ); - const actionMenuList = useCallback( - (currency) => ( - - } - text={formatMessage({ id: 'edit_currency' })} - onClick={() => handleEditCurrency(currency)} - /> - } - text={formatMessage({ id: 'delete_currency' })} - onClick={() => onDeleteCurrency(currency)} - intent={Intent.DANGER} - /> - - ), - [handleEditCurrency, onDeleteCurrency, formatMessage], - ); - - const onRowContextMenu = useCallback( - (cell) => { - return actionMenuList(cell.row.original); - }, - [actionMenuList], - ); - - const columns = useMemo( - () => [ - { - Header: formatMessage({ id: 'currency_name' }), - accessor: 'currency_name', - width: 150, - }, - { - Header: formatMessage({ id: 'currency_code' }), - accessor: 'currency_code', - className: 'currency_code', - width: 120, - }, - { - Header: 'Currency sign', - width: 120, - }, - { - id: 'actions', - Header: '', - Cell: ({ cell }) => ( - -