mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
Merge branch 'master' of https://github.com/abouolia/Ratteb
This commit is contained in:
82
client/src/components/CustomersMultiSelect.js
Normal file
82
client/src/components/CustomersMultiSelect.js
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
import React, { useMemo, useCallback, useState } from 'react';
|
||||||
|
import { MenuItem, Button } from '@blueprintjs/core';
|
||||||
|
import { omit } from 'lodash';
|
||||||
|
import MultiSelect from 'components/MultiSelect';
|
||||||
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
|
|
||||||
|
export default function CustomersMultiSelect({
|
||||||
|
customers,
|
||||||
|
defaultText = <T id={'all_customers'} />,
|
||||||
|
buttonProps,
|
||||||
|
|
||||||
|
onCustomerSelected,
|
||||||
|
...selectProps
|
||||||
|
}) {
|
||||||
|
const [selectedCustomers, setSelectedCustomers] = useState({});
|
||||||
|
|
||||||
|
const isCustomerSelect = useCallback(
|
||||||
|
(id) => typeof selectedCustomers[id] !== 'undefined',
|
||||||
|
[selectedCustomers],
|
||||||
|
);
|
||||||
|
|
||||||
|
const customerRenderer = useCallback(
|
||||||
|
(customer, { handleClick }) => (
|
||||||
|
<MenuItem
|
||||||
|
icon={isCustomerSelect(customer.id) ? 'tick' : 'blank'}
|
||||||
|
text={customer.display_name}
|
||||||
|
key={customer.id}
|
||||||
|
onClick={handleClick}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
[isCustomerSelect],
|
||||||
|
);
|
||||||
|
|
||||||
|
const countSelected = useMemo(() => Object.values(selectedCustomers).length, [
|
||||||
|
selectedCustomers,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const onContactSelect = useCallback(
|
||||||
|
({ id }) => {
|
||||||
|
const selected = {
|
||||||
|
...(isCustomerSelect(id)
|
||||||
|
? {
|
||||||
|
...omit(selectedCustomers, [id]),
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
...selectedCustomers,
|
||||||
|
[id]: true,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
setSelectedCustomers({ ...selected });
|
||||||
|
onCustomerSelected && onCustomerSelected(selected);
|
||||||
|
},
|
||||||
|
[
|
||||||
|
setSelectedCustomers,
|
||||||
|
selectedCustomers,
|
||||||
|
isCustomerSelect,
|
||||||
|
onCustomerSelected,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<MultiSelect
|
||||||
|
items={customers}
|
||||||
|
noResults={<MenuItem disabled={true} text="No results." />}
|
||||||
|
itemRenderer={customerRenderer}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
filterable={true}
|
||||||
|
onItemSelect={onContactSelect}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
text={
|
||||||
|
countSelected === 0 ? (
|
||||||
|
defaultText
|
||||||
|
) : (
|
||||||
|
<T id={'selected_customers'} values={{ count: countSelected }} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
{...buttonProps}
|
||||||
|
/>
|
||||||
|
</MultiSelect>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -43,6 +43,7 @@ import DashboardCard from './Dashboard/DashboardCard';
|
|||||||
import InputPrependText from './Forms/InputPrependText';
|
import InputPrependText from './Forms/InputPrependText';
|
||||||
import PageFormBigNumber from './PageFormBigNumber';
|
import PageFormBigNumber from './PageFormBigNumber';
|
||||||
import AccountsMultiSelect from './AccountsMultiSelect';
|
import AccountsMultiSelect from './AccountsMultiSelect';
|
||||||
|
import CustomersMultiSelect from './CustomersMultiSelect';
|
||||||
|
|
||||||
const Hint = FieldHint;
|
const Hint = FieldHint;
|
||||||
|
|
||||||
@@ -92,4 +93,5 @@ export {
|
|||||||
PageFormBigNumber,
|
PageFormBigNumber,
|
||||||
AccountsMultiSelect,
|
AccountsMultiSelect,
|
||||||
DataTableEditable,
|
DataTableEditable,
|
||||||
|
CustomersMultiSelect
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,15 +1,28 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField } from 'formik';
|
import { FastField } from 'formik';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { Intent, FormGroup, InputGroup, Position } from '@blueprintjs/core';
|
import {
|
||||||
|
Intent,
|
||||||
|
FormGroup,
|
||||||
|
InputGroup,
|
||||||
|
Position,
|
||||||
|
Classes,
|
||||||
|
} from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
import { FormattedMessage as T } from 'react-intl';
|
||||||
import { Row, Col, FieldHint } from 'components';
|
import classNames from 'classnames';
|
||||||
|
import { CustomersMultiSelect, Row, Col, FieldHint } from 'components';
|
||||||
import { momentFormatter } from 'utils';
|
import { momentFormatter } from 'utils';
|
||||||
|
import withCustomers from 'containers/Customers/withCustomers';
|
||||||
|
|
||||||
|
import { compose } from 'redux';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AR Aging Summary - Drawer Header - General Fields.
|
* AR Aging Summary - Drawer Header - General Fields.
|
||||||
*/
|
*/
|
||||||
export default function ARAgingSummaryHeaderGeneral({}) {
|
function ARAgingSummaryHeaderGeneral({
|
||||||
|
// #withCustomers
|
||||||
|
customers,
|
||||||
|
}) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Row>
|
<Row>
|
||||||
@@ -48,7 +61,11 @@ export default function ARAgingSummaryHeaderGeneral({}) {
|
|||||||
className={'form-group--aging-before-days'}
|
className={'form-group--aging-before-days'}
|
||||||
intent={error && Intent.DANGER}
|
intent={error && Intent.DANGER}
|
||||||
>
|
>
|
||||||
<InputGroup medium={true} intent={error && Intent.DANGER} {...field } />
|
<InputGroup
|
||||||
|
medium={true}
|
||||||
|
intent={error && Intent.DANGER}
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
@@ -65,12 +82,31 @@ export default function ARAgingSummaryHeaderGeneral({}) {
|
|||||||
className={'form-group--aging-periods'}
|
className={'form-group--aging-periods'}
|
||||||
intent={error && Intent.DANGER}
|
intent={error && Intent.DANGER}
|
||||||
>
|
>
|
||||||
<InputGroup medium={true} intent={error && Intent.DANGER} {...field} />
|
<InputGroup
|
||||||
|
medium={true}
|
||||||
|
intent={error && Intent.DANGER}
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
<Row>
|
||||||
|
<Col xs={5}>
|
||||||
|
<FormGroup
|
||||||
|
label={<T id={'specific_customers'} />}
|
||||||
|
className={classNames('form-group--select-list', Classes.FILL)}
|
||||||
|
>
|
||||||
|
<CustomersMultiSelect customers={customers} />
|
||||||
|
</FormGroup>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
export default compose(
|
||||||
|
withCustomers(({ customers }) => ({
|
||||||
|
customers,
|
||||||
|
})),
|
||||||
|
)(ARAgingSummaryHeaderGeneral);
|
||||||
|
|||||||
@@ -971,6 +971,9 @@ export default {
|
|||||||
format: 'Format',
|
format: 'Format',
|
||||||
current: 'Current',
|
current: 'Current',
|
||||||
adjustment_reasons: 'Adjustment reasons',
|
adjustment_reasons: 'Adjustment reasons',
|
||||||
|
specific_customers: 'Specific Customers',
|
||||||
|
all_customers: 'All Customers',
|
||||||
|
selected_customers: '{count} Selected Customers',
|
||||||
transaction_number: 'Transaction #',
|
transaction_number: 'Transaction #',
|
||||||
running_balance: 'Running balance'
|
running_balance: 'Running balance'
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user