Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ahmed Bouhuolia
2020-11-24 12:50:20 +02:00
4 changed files with 183 additions and 64 deletions

View File

@@ -1,58 +1,171 @@
import React from 'react'; import React, { useCallback } from 'react';
import { Intent, Button } from '@blueprintjs/core'; import {
Intent,
Button,
ButtonGroup,
Popover,
PopoverInteractionKind,
Position,
Menu,
MenuItem,
} from '@blueprintjs/core';
import { useFormikContext } from 'formik'; import { useFormikContext } from 'formik';
import { FormattedMessage as T } from 'react-intl'; import { FormattedMessage as T } from 'react-intl';
import { CLASSES } from 'common/classes'; import { CLASSES } from 'common/classes';
import classNames from 'classnames'; import classNames from 'classnames';
import { saveInvoke } from 'utils'; import { saveInvoke } from 'utils';
import { Icon } from 'components';
export default function InvoiceFloatingActions({ export default function InvoiceFloatingActions({
isSubmitting, isSubmitting,
onSubmitClick, onSubmitClick,
onSubmitAndNewClick,
onCancelClick, onCancelClick,
onClearClick, onClearClick,
invoice, invoice,
}) { }) {
const { resetForm } = useFormikContext(); const { resetForm, submitForm } = useFormikContext();
const handleSubmitPublishAndNewBtnClick = useCallback(
(event) => {
submitForm();
saveInvoke(onSubmitClick, event, {
redirect: false,
publish: true,
resetForm: true,
});
},
[submitForm],
);
const handleSubmitPublishContinueEditingBtnClick = useCallback(
(event) => {
submitForm();
saveInvoke(onSubmitClick, event, {
redirect: false,
publish: true,
});
},
[submitForm],
);
const handleSubmitDraftAndNewBtnClick = useCallback(
(event) => {
submitForm();
saveInvoke(onSubmitClick, event, {
redirect: false,
publish: false,
resetForm: true,
});
},
[submitForm],
);
const handleSubmitDraftContinueEditingBtnClick = useCallback(
(event) => {
submitForm();
saveInvoke(onSubmitClick, event, {
redirect: false,
publish: true,
});
},
[submitForm],
);
return ( return (
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}> <div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
<ButtonGroup>
{/* ----------- Save And Publish ----------- */}
<Button <Button
disabled={isSubmitting} disabled={isSubmitting}
intent={Intent.PRIMARY} intent={Intent.PRIMARY}
type="submit" type="submit"
onClick={(event) => { onClick={(event) => {
saveInvoke(onSubmitClick, event); saveInvoke(onSubmitClick, event, {
redirect: true,
publish: true,
});
}} }}
text={
invoice && invoice.id ? (
<T id={'edit'} />
) : (
<T id={'save_publish'} />
)
}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'publish_and_new'} />}
onClick={handleSubmitPublishAndNewBtnClick}
/>
<MenuItem
text={<T id={'publish_continue_editing'} />}
onClick={handleSubmitPublishContinueEditingBtnClick}
/>
</Menu>
}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
> >
{invoice && invoice.id ? <T id={'edit'} /> : <T id={'save'} />} <Button
</Button> intent={Intent.PRIMARY}
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
/>
</Popover>
{/* ----------- Save As Draft ----------- */}
<Button <Button
disabled={isSubmitting} disabled={isSubmitting}
intent={Intent.PRIMARY}
className={'ml1'} className={'ml1'}
type="submit" type="submit"
onClick={(event) => { onClick={(event) => {
saveInvoke(onSubmitAndNewClick, event); saveInvoke(onSubmitClick, event, {
redirect: true,
publish: false,
});
}} }}
text={<T id={'save_as_draft'} />}
/>
<Popover
content={
<Menu>
<MenuItem
text={<T id={'save_and_new'} />}
onClick={handleSubmitDraftAndNewBtnClick}
/>
<MenuItem
text={<T id={'save_continue_editing'} />}
onClick={handleSubmitDraftContinueEditingBtnClick}
/>
</Menu>
}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
> >
<T id={'save_new'} /> <Button rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />} />
</Button> </Popover>
{/* ----------- Clear ----------- */}
<Button className={'ml1'} disabled={isSubmitting} onClick={(event) => { <Button
className={'ml1'}
disabled={isSubmitting}
onClick={(event) => {
resetForm(); resetForm();
saveInvoke(onClearClick, event); saveInvoke(onClearClick, event);
}}> }}
<T id={'clear'} /> text={invoice && invoice.id ? <T id={'reset'} /> : <T id={'clear'} />}
</Button> />
{/* ----------- Cancel ----------- */}
<Button className={'ml1'} type="submit" onClick={(event) => { <Button
className={'ml1'}
type="submit"
onClick={(event) => {
saveInvoke(onCancelClick, event); saveInvoke(onCancelClick, event);
}}> }}
<T id={'close'} /> text={<T id={'cancel'} />}
</Button> />
</ButtonGroup>
</div> </div>
); );
} }

View File

@@ -191,7 +191,11 @@ function InvoiceForm({
if (submitPayload.redirect) { if (submitPayload.redirect) {
history.push('/invoices'); history.push('/invoices');
} }
if (submitPayload.resetForm) {
resetForm();
}
}; };
// Handle the request error. // Handle the request error.
const onError = (errors) => { const onError = (errors) => {
if (errors) { if (errors) {
@@ -207,21 +211,17 @@ function InvoiceForm({
} }
}; };
const handleCancelClick = useCallback( const handleCancelClick = useCallback(() => {
(payload) => {
history.goBack(); history.goBack();
}, [history]);
const handleSubmitClick = useCallback(
(event, payload) => {
setSubmitPayload({ ...payload });
}, },
[history], [setSubmitPayload],
); );
const handleSubmitClick = useCallback(() => {
setSubmitPayload({ redirect: true });
}, [setSubmitPayload]);
const handleSubmitAndNewClick = useCallback(() => {
setSubmitPayload({ redirect: false });
}, [setSubmitPayload]);
const handleInvoiceNumberChanged = useCallback( const handleInvoiceNumberChanged = useCallback(
(invoiceNumber) => { (invoiceNumber) => {
changePageSubtitle( changePageSubtitle(
@@ -256,7 +256,6 @@ function InvoiceForm({
invoice={invoice} invoice={invoice}
onCancelClick={handleCancelClick} onCancelClick={handleCancelClick}
onSubmitClick={handleSubmitClick} onSubmitClick={handleSubmitClick}
onSubmitAndNewClick={handleSubmitAndNewClick}
/> />
</Form> </Form>
)} )}

View File

@@ -844,4 +844,12 @@ export default {
you_cannot_make_payment_with_zero_total_amount: 'You cannot record payment transaction with zero total amount', you_cannot_make_payment_with_zero_total_amount: 'You cannot record payment transaction with zero total amount',
are_sure_to_publish_this_manual_journal: are_sure_to_publish_this_manual_journal:
'Are you sure you want to publish this manual journal?', 'Are you sure you want to publish this manual journal?',
save_publish:'Save and Publish',
publish_and_new: 'Publish and new',
publish_continue_editing:'Publish (continue editing)',
save_and_new:'Save and new',
save_continue_editing:'Save (continue editing)',
reset:'Reset ',
}; };

View File

@@ -42,15 +42,11 @@ export default {
viewBox: '0 0 448 512', viewBox: '0 0 448 512',
}, },
'arrow-back-24': { 'arrow-back-24': {
path: [ path: ['M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z'],
'M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z',
],
viewBox: '0 0 24, 24', viewBox: '0 0 24, 24',
}, },
'arrow-forward-24': { 'arrow-forward-24': {
path: [ path: ['M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8-8-8z'],
'M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8-8-8z',
],
viewBox: '0 0 24 24', viewBox: '0 0 24 24',
}, },
'ellipsis-h': { 'ellipsis-h': {
@@ -194,20 +190,20 @@ export default {
viewBox: '0 0 384 512', viewBox: '0 0 384 512',
}, },
'search-24': { 'search-24': {
path: ['M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'], path: [
'M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z',
],
viewBox: '0 0 24 24', viewBox: '0 0 24 24',
}, },
'plus-24': { 'plus-24': {
path: [ path: ['M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'],
'M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'
],
viewBox: '0 0 24 24', viewBox: '0 0 24 24',
}, },
'notification-24': { 'notification-24': {
path: [ path: [
'M12 22c1.1 0 2-.9 2-2h-4c0 1.1.9 2 2 2zm6-6v-5c0-3.07-1.63-5.64-4.5-6.32V4c0-.83-.67-1.5-1.5-1.5s-1.5.67-1.5 1.5v.68C7.64 5.36 6 7.92 6 11v5l-2 2v1h16v-1l-2-2zm-2 1H8v-6c0-2.48 1.51-4.5 4-4.5s4 2.02 4 4.5v6z', 'M12 22c1.1 0 2-.9 2-2h-4c0 1.1.9 2 2 2zm6-6v-5c0-3.07-1.63-5.64-4.5-6.32V4c0-.83-.67-1.5-1.5-1.5s-1.5.67-1.5 1.5v.68C7.64 5.36 6 7.92 6 11v5l-2 2v1h16v-1l-2-2zm-2 1H8v-6c0-2.48 1.51-4.5 4-4.5s4 2.02 4 4.5v6z',
], ],
viewBox: '0 0 24 24' viewBox: '0 0 24 24',
}, },
'help-24': { 'help-24': {
path: [ path: [
@@ -216,7 +212,6 @@ export default {
viewBox: '0 0 24 24', viewBox: '0 0 24 24',
}, },
// 16 // 16
'file-import-16': { 'file-import-16': {
path: [ path: [
@@ -298,5 +293,9 @@ export default {
'M16 9h-2.55V6h-2.9v3H8l4 4zm3-6H4.99C3.88 3 3 3.9 3 5v14c0 1.1.88 2 1.99 2H19c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5v-3h3.56c.69 1.19 1.97 2 3.45 2s2.75-.81 3.45-2H19v3zm0-5h-4.99c0 1.1-.9 2-2 2s-2-.9-2-2H5l-.01-9H19v9z', 'M16 9h-2.55V6h-2.9v3H8l4 4zm3-6H4.99C3.88 3 3 3.9 3 5v14c0 1.1.88 2 1.99 2H19c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm0 16H5v-3h3.56c.69 1.19 1.97 2 3.45 2s2.75-.81 3.45-2H19v3zm0-5h-4.99c0 1.1-.9 2-2 2s-2-.9-2-2H5l-.01-9H19v9z',
], ],
viewBox: '0 0 24 24' viewBox: '0 0 24 24'
} },
'arrow-drop-up-16': {
path: ['M7 14l5-5 5 5z'],
viewBox: '0 0 24 24',
},
}; };