Fix EntriesItemTable & FloatingActions

This commit is contained in:
elforjani3
2020-10-27 19:39:15 +02:00
parent 0ec0865a6e
commit 8a830a0a97
20 changed files with 200 additions and 215 deletions

View File

@@ -0,0 +1,54 @@
import React from 'react';
import { Intent, Button } from '@blueprintjs/core';
import { FormattedMessage as T } from 'react-intl';
export default function BillFloatingActions({
formik: { isSubmitting },
onSubmitClick,
onCancelClick,
bill,
}) {
return (
<div className={'form__floating-footer'}>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
type="submit"
onClick={() => {
onSubmitClick({ redirect: true });
}}
>
{bill && bill.id ? <T id={'edit'} /> : <T id={'save_send'} />}
</Button>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
className={'ml1'}
name={'save'}
type="submit"
onClick={() => {
onSubmitClick({ redirect: false });
}}
>
<T id={'save'} />
</Button>
<Button className={'ml1'} disabled={isSubmitting}>
<T id={'clear'} />
</Button>
<Button
className={'ml1'}
type="submit"
onClick={() => {
onCancelClick && onCancelClick();
}}
>
<T id={'close'} />
</Button>
</div>
);
}

View File

@@ -8,24 +8,21 @@ import React, {
import * as Yup from 'yup';
import { useFormik } from 'formik';
import moment from 'moment';
import { Intent, FormGroup, TextArea } from '@blueprintjs/core';
import { Intent } from '@blueprintjs/core';
import classNames from 'classnames';
import { FormattedMessage as T, useIntl } from 'react-intl';
import { pick } from 'lodash';
import { CLASSES } from 'common/classes';
import BillFormHeader from './BillFormHeader';
import EstimatesItemsTable from 'containers/Sales/Estimate/EntriesItemsTable';
import BillFloatingActions from './BillFloatingActions';
import BillFormFooter from './BillFormFooter';
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
import withMediaActions from 'containers/Media/withMediaActions';
import withBills from './withBills';
import withBillActions from './withBillActions';
import withBillDetail from './withBillDetail';
import withSettings from 'containers/Settings/withSettings';
import { AppToaster, Row, Col } from 'components';
import Dragzone from 'components/Dragzone';
import { AppToaster } from 'components';
import useMedia from 'hooks/useMedia';
import { compose, repeatValue } from 'utils';
@@ -45,13 +42,6 @@ function BillForm({
//#withDashboard
changePageTitle,
// #withBills
nextBillNumberChanged,
// #withSettings
billNextNumber,
billNumberPrefix,
//#withBillDetail
bill,
@@ -147,14 +137,11 @@ function BillForm({
[],
);
const billNumber = billNumberPrefix
? `${billNumberPrefix}-${billNextNumber}`
: billNextNumber;
const defaultInitialValues = useMemo(
() => ({
vendor_id: '',
bill_number: billNumber,
bill_number: '',
bill_date: moment(new Date()).format('YYYY-MM-DD'),
due_date: moment(new Date()).format('YYYY-MM-DD'),
// status: 'Bill',
@@ -162,7 +149,7 @@ function BillForm({
note: '',
entries: [...repeatValue(defaultBill, MIN_LINES_NUMBER)],
}),
[defaultBill, billNumber],
[defaultBill],
);
const orderingIndex = (_bill) => {
@@ -259,11 +246,6 @@ function BillForm({
},
});
useEffect(() => {
formik.setFieldValue('bill_number', billNumber);
setBillNumberChanged(false);
}, [nextBillNumberChanged, billNumber]);
const handleSubmitClick = useCallback(
(payload) => {
setPayload(payload);
@@ -290,7 +272,7 @@ function BillForm({
},
[setDeletedFiles, deletedFiles],
);
const onClickCleanAllLines = () => {
formik.setFieldValue(
'entries',
@@ -305,10 +287,7 @@ function BillForm({
);
};
return (
<div className={classNames(
CLASSES.PAGE_FORM,
CLASSES.PAGE_FORM_BILL,
)}>
<div className={classNames(CLASSES.PAGE_FORM, CLASSES.PAGE_FORM_BILL)}>
<form onSubmit={formik.handleSubmit}>
<BillFormHeader formik={formik} />
@@ -318,33 +297,16 @@ function BillForm({
onClickAddNewRow={onClickAddNewRow}
onClickClearAllLines={onClickCleanAllLines}
/>
<div class="page-form__footer">
<Row>
<Col md={8}>
<FormGroup label={<T id={'note'} />} className={'form-group--note'}>
<TextArea
growVertically={true}
{...formik.getFieldProps('note')}
/>
</FormGroup>
</Col>
<Col md={4}>
<Dragzone
initialFiles={initialAttachmentFiles}
onDrop={handleDropFiles}
onDeleteFile={handleDeleteFile}
hint={'Attachments: Maxiumum size: 20MB'}
/>
</Col>
</Row>
</div>
<BillFormFooter
formik={formik}
oninitialFiles={initialAttachmentFiles}
onDropFiles={handleDeleteFile}
/>
</form>
<BillFormFooter
<BillFloatingActions
formik={formik}
onSubmitClick={handleSubmitClick}
bill={bill}
disabled={formik.isSubmitting}
onCancelClick={handleCancelClick}
/>
</div>
@@ -354,11 +316,6 @@ function BillForm({
export default compose(
withBillActions,
withBillDetail(),
withBills(({ nextBillNumberChanged }) => ({ nextBillNumberChanged })),
withDashboardActions,
withMediaActions,
withSettings(({ billsettings }) => ({
billNextNumber: billsettings?.next_number,
billNumberPrefix: billsettings?.number_prefix,
})),
)(BillForm);

View File

@@ -1,54 +1,32 @@
import React from 'react';
import { Intent, Button } from '@blueprintjs/core';
import { FormGroup, TextArea } from '@blueprintjs/core';
import { FormattedMessage as T } from 'react-intl';
import { Row, Col } from 'components';
import Dragzone from 'components/Dragzone';
export default function BillFormFooter({
formik: { isSubmitting },
onSubmitClick,
onCancelClick,
bill,
export default function BillFloatingActions({
formik: { getFieldProps },
oninitialFiles,
onDropFiles,
}) {
return (
<div className={'form__floating-footer'}>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
type="submit"
onClick={() => {
onSubmitClick({ redirect: true });
}}
>
{bill && bill.id ? <T id={'edit'} /> : <T id={'save_send'} />}
</Button>
<div class="page-form__footer">
<Row>
<Col md={8}>
<FormGroup label={<T id={'note'} />} className={'form-group--note'}>
<TextArea growVertically={true} {...getFieldProps('note')} />
</FormGroup>
</Col>
<Button
disabled={isSubmitting}
loading={isSubmitting}
intent={Intent.PRIMARY}
className={'ml1'}
name={'save'}
type="submit"
onClick={() => {
onSubmitClick({ redirect: false });
}}
>
<T id={'save'} />
</Button>
<Button className={'ml1'} disabled={isSubmitting}>
<T id={'clear'} />
</Button>
<Button
className={'ml1'}
type="submit"
onClick={() => {
onCancelClick && onCancelClick();
}}
>
<T id={'close'} />
</Button>
<Col md={4}>
<Dragzone
initialFiles={oninitialFiles}
onDrop={onDropFiles}
onDeleteFile={onDropFiles}
hint={'Attachments: Maxiumum size: 20MB'}
/>
</Col>
</Row>
</div>
);
}

View File

@@ -16,7 +16,7 @@ import { pick, values } from 'lodash';
import PaymentMadeHeader from './PaymentMadeFormHeader';
import PaymentMadeItemsTable from './PaymentMadeItemsTable';
import PaymentMadeFooter from './PaymentMadeFormFooter';
import PaymentMadeFloatingActions from './PaymentMadeFloatingActions';
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
import withMediaActions from 'containers/Media/withMediaActions';
@@ -319,7 +319,7 @@ function PaymentMadeForm({
hint={'Attachments: Maxiumum size: 20MB'}
/> */}
</form>
<PaymentMadeFooter
<PaymentMadeFloatingActions
formik={formik}
onSubmitClick={handleSubmitClick}
onCancel={handleCancelClick}