From d58289eabf969812593a986d46caee952e66a9d1 Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Sat, 8 May 2021 03:15:10 +0200 Subject: [PATCH] refactoring: customers transactions. --- .../CustomersTransactions.js | 88 ++++++++++++ .../CustomersTransactionsHeader.js | 100 +++++++++++++ ...CustomersTransactionsHeaderGeneralPanel.js | 13 ++ .../CustomersTransactionsTable.js | 59 ++++++++ .../CustomersTranscationsActionsBar.js | 135 ++++++++++++++++++ .../CustomersTranscationsProvider.js | 36 +++++ .../CustomersTransactions/components.js | 101 +++++++++++++ .../withCustomersTransactions.js | 15 ++ .../withCustomersTransactionsActions.js | 10 ++ 9 files changed, 557 insertions(+) create mode 100644 client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactions.js create mode 100644 client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsHeader.js create mode 100644 client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsHeaderGeneralPanel.js create mode 100644 client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsTable.js create mode 100644 client/src/containers/FinancialStatements/CustomersTransactions/CustomersTranscationsActionsBar.js create mode 100644 client/src/containers/FinancialStatements/CustomersTransactions/CustomersTranscationsProvider.js create mode 100644 client/src/containers/FinancialStatements/CustomersTransactions/components.js create mode 100644 client/src/containers/FinancialStatements/CustomersTransactions/withCustomersTransactions.js create mode 100644 client/src/containers/FinancialStatements/CustomersTransactions/withCustomersTransactionsActions.js diff --git a/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactions.js b/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactions.js new file mode 100644 index 000000000..17a72ae3b --- /dev/null +++ b/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactions.js @@ -0,0 +1,88 @@ +import React, { useEffect, useState } from 'react'; +import moment from 'moment'; +import 'style/pages/FinancialStatements/ContactsTransactions.scss'; + +import { FinancialStatement } from 'components'; +import DashboardPageContent from 'components/Dashboard/DashboardPageContent'; + +import CustomersTransactionsHeader from './CustomersTransactionsHeader'; +import CustomersTransactionsTable from './CustomersTransactionsTable'; +import CustomersTranscationsActionsBar from './CustomersTranscationsActionsBar'; + +import withCustomersTransactionsActions from './withCustomersTransactionsActions'; +import withSettings from 'containers/Settings/withSettings'; +import { CustomersTranscationsLoadingBar } from './components'; +import { CustomersTranscationsProvider } from './CustomersTranscationsProvider'; + +import { compose } from 'utils'; + +/** + * Customers transactions. + */ +function CustomersTransactions({ + // #withPreferences + organizationName, + + //#withCustomersTransactionsActions + toggleCustomersTransactionsFilterDrawer, +}) { + // filter + const [filter, setFilter] = useState({ + fromDate: moment().startOf('year').format('YYYY-MM-DD'), + toDate: moment().endOf('year').format('YYYY-MM-DD'), + }); + + const handleFilterSubmit = (filter) => { + const _filter = { + ...filter, + fromDate: moment(filter.fromDate).format('YYYY-MM-DD'), + toDate: moment(filter.toDate).format('YYYY-MM-DD'), + }; + setFilter({ ..._filter }); + }; + + // Handle number format submit. + const handleNumberFormatSubmit = (values) => { + setFilter({ + ...filter, + numberFormat: values, + }); + }; + + useEffect( + () => () => { + toggleCustomersTransactionsFilterDrawer(false); + }, + [toggleCustomersTransactionsFilterDrawer], + ); + + return ( + + + + + +
+ + +
+ +
+
+
+
+
+ ); +} +export default compose( + withSettings(({ organizationSettings }) => ({ + organizationName: organizationSettings.name, + })), + withCustomersTransactionsActions, +)(CustomersTransactions); diff --git a/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsHeader.js b/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsHeader.js new file mode 100644 index 000000000..f766d9efe --- /dev/null +++ b/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsHeader.js @@ -0,0 +1,100 @@ +import React from 'react'; +import { Tabs, Tab, Button, Intent } from '@blueprintjs/core'; +import { FormattedMessage as T, useIntl } from 'react-intl'; +import moment from 'moment'; +import * as Yup from 'yup'; +import { Formik, Form } from 'formik'; + +import FinancialStatementHeader from 'containers/FinancialStatements/FinancialStatementHeader'; +import CustomersTransactionsHeaderGeneralPanel from './CustomersTransactionsHeaderGeneralPanel'; + +import withCustomersTransactions from './withCustomersTransactions'; +import withCustomersTransactionsActions from './withCustomersTransactionsActions'; + +import { compose } from 'utils'; + +/** + * Customers transactions header. + */ +function CustomersTransactionsHeader({ + // #ownProps + onSubmitFilter, + pageFilter, + + //#withCustomersTransactions + isFilterDrawerOpen, + + //#withCustomersTransactionsActions + toggleCustomersTransactionsFilterDrawer: toggleFilterDrawer, +}) { + const { formatMessage } = useIntl(); + + // Filter form initial values. + const initialValues = { + ...pageFilter, + fromDate: moment(pageFilter.fromDate).toDate(), + toDate: moment(pageFilter.toDate).toDate(), + }; + + // Validation schema. + const validationSchema = Yup.object().shape({ + fromDate: Yup.date() + .required() + .label(formatMessage({ id: 'fromDate' })), + toDate: Yup.date() + .min(Yup.ref('fromDate')) + .required() + .label(formatMessage({ id: 'toDate' })), + }); + + // Handle form submit. + const handleSubmit = (values, { setSubmitting }) => { + onSubmitFilter(values); + toggleFilterDrawer(false); + setSubmitting(false); + }; + + // Handle drawer close action. + const handleDrawerClose = () => { + toggleFilterDrawer(false); + }; + + return ( + + +
+ + } + panel={} + /> + + + +
+
+
+ ); +} + +export default compose( + withCustomersTransactions(({ customersTransactionsDrawerFilter }) => ({ + isFilterDrawerOpen: customersTransactionsDrawerFilter, + })), + withCustomersTransactionsActions, +)(CustomersTransactionsHeader); diff --git a/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsHeaderGeneralPanel.js b/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsHeaderGeneralPanel.js new file mode 100644 index 000000000..903a8b449 --- /dev/null +++ b/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsHeaderGeneralPanel.js @@ -0,0 +1,13 @@ +import React from 'react'; +import FinancialStatementDateRange from 'containers/FinancialStatements/FinancialStatementDateRange'; + +/** + * Customers transactions header - General panel. + */ +export default function CustomersTransactionsHeaderGeneralPanel() { + return ( +
+ +
+ ); +} diff --git a/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsTable.js b/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsTable.js new file mode 100644 index 000000000..972bde7d2 --- /dev/null +++ b/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTransactionsTable.js @@ -0,0 +1,59 @@ +import React, { useMemo, useCallback } from 'react'; +import { useIntl } from 'react-intl'; +import classNames from 'classnames'; + +import FinancialSheet from 'components/FinancialSheet'; +import DataTable from 'components/DataTable'; +import { useCustomersTranscationsColumns } from './components'; +import { useCustomersTranscationsContext } from './CustomersTranscationsProvider'; + +import { defaultExpanderReducer, getColumnWidth } from 'utils'; + +/** + * Customers transcations table. + */ +export default function CustomersTransactionsTable({ + // #ownProps + companyName, +}) { + const { formatMessage } = useIntl(); + + const { + customersTransactions: { tableRows }, + isCustomersTransactionsLoading, + filter, + } = useCustomersTranscationsContext(); + + const columns = useCustomersTranscationsColumns(); + + const expandedRows = useMemo(() => defaultExpanderReducer(tableRows, 4), [ + tableRows, + ]); + + const rowClassNames = (row) => { + return [`row-type--${row.original.rowTypes}`]; + }; + + return ( + + + + ); +} diff --git a/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTranscationsActionsBar.js b/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTranscationsActionsBar.js new file mode 100644 index 000000000..53954b6c7 --- /dev/null +++ b/client/src/containers/FinancialStatements/CustomersTransactions/CustomersTranscationsActionsBar.js @@ -0,0 +1,135 @@ +import React from 'react'; +import { + NavbarGroup, + Button, + Classes, + NavbarDivider, + Popover, + PopoverInteractionKind, + Position, +} from '@blueprintjs/core'; +import { FormattedMessage as T } from 'react-intl'; +import classNames from 'classnames'; + +import Icon from 'components/Icon'; +import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar'; +import NumberFormatDropdown from 'components/NumberFormatDropdown'; + +import { useCustomersTranscationsContext } from './CustomersTranscationsProvider'; +import withCustomersTransactions from './withCustomersTransactions'; +import withCustomersTransactionsActions from './withCustomersTransactionsActions'; + +import { compose, saveInvoke } from 'utils'; + +/** + * Customers transcations actions bar. + */ +function CustomersTranscationsActionsBar({ + // #ownProps + numberFormat, + onNumberFormatSubmit, + + //#withCustomersTransactions + isFilterDrawerOpen, + + //#withCustomersTransactionsActions + toggleCustomersTransactionsFilterDrawer, +}) { + const { + isCustomersTransactionsLoading, + CustomersTransactionsRefetch, + } = useCustomersTranscationsContext(); + + // Handle filter toggle click. + const handleFilterToggleClick = () => { + toggleCustomersTransactionsFilterDrawer(); + }; + + // Handle recalculate the report button. + const handleRecalcReport = () => { + CustomersTransactionsRefetch(); + }; + + // Handle number format form submit. + const handleNumberFormatSubmit = (values) => { + saveInvoke(onNumberFormatSubmit, values); + }; + + return ( + + +