From 0513a4d4adbf8c90ff277bea299f59d336110efb Mon Sep 17 00:00:00 2001 From: elforjani3 Date: Mon, 23 Nov 2020 17:19:33 +0200 Subject: [PATCH] Fix: InvoiceFloatingActions. --- .../Sales/Invoice/InvoiceFloatingActions.js | 189 ++++++++++++++---- .../containers/Sales/Invoice/InvoiceForm.js | 25 ++- client/src/lang/en/index.js | 8 + client/src/static/json/icons.js | 25 ++- 4 files changed, 183 insertions(+), 64 deletions(-) diff --git a/client/src/containers/Sales/Invoice/InvoiceFloatingActions.js b/client/src/containers/Sales/Invoice/InvoiceFloatingActions.js index 4f9c7a4fd..f52c278ca 100644 --- a/client/src/containers/Sales/Invoice/InvoiceFloatingActions.js +++ b/client/src/containers/Sales/Invoice/InvoiceFloatingActions.js @@ -1,58 +1,171 @@ -import React from 'react'; -import { Intent, Button } from '@blueprintjs/core'; +import React, { useCallback } from 'react'; +import { + Intent, + Button, + ButtonGroup, + Popover, + PopoverInteractionKind, + Position, + Menu, + MenuItem, +} from '@blueprintjs/core'; import { useFormikContext } from 'formik'; import { FormattedMessage as T } from 'react-intl'; import { CLASSES } from 'common/classes'; import classNames from 'classnames'; import { saveInvoke } from 'utils'; +import { Icon } from 'components'; export default function InvoiceFloatingActions({ isSubmitting, onSubmitClick, - onSubmitAndNewClick, onCancelClick, onClearClick, 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 (
- + + {/* ----------- Save And Publish ----------- */} + - - - - + {/* ----------- Save As Draft ----------- */} +
); } diff --git a/client/src/containers/Sales/Invoice/InvoiceForm.js b/client/src/containers/Sales/Invoice/InvoiceForm.js index 9da290b8e..3bd3c4dba 100644 --- a/client/src/containers/Sales/Invoice/InvoiceForm.js +++ b/client/src/containers/Sales/Invoice/InvoiceForm.js @@ -183,7 +183,11 @@ function InvoiceForm({ if (submitPayload.redirect) { history.push('/invoices'); } + if (submitPayload.resetForm) { + resetForm(); + } }; + // Handle the request error. const onError = (errors) => { if (errors) { @@ -199,21 +203,17 @@ function InvoiceForm({ } }; - const handleCancelClick = useCallback( - (payload) => { - history.goBack(); + const handleCancelClick = useCallback(() => { + 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( (invoiceNumber) => { changePageSubtitle(`No. ${invoiceNumber}`); @@ -243,7 +243,6 @@ function InvoiceForm({ invoice={invoice} onCancelClick={handleCancelClick} onSubmitClick={handleSubmitClick} - onSubmitAndNewClick={handleSubmitAndNewClick} /> )} diff --git a/client/src/lang/en/index.js b/client/src/lang/en/index.js index 15656c105..fdd9c14f7 100644 --- a/client/src/lang/en/index.js +++ b/client/src/lang/en/index.js @@ -844,4 +844,12 @@ export default { are_sure_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 ', + + }; diff --git a/client/src/static/json/icons.js b/client/src/static/json/icons.js index 903f415c0..19fc01a02 100644 --- a/client/src/static/json/icons.js +++ b/client/src/static/json/icons.js @@ -42,15 +42,11 @@ export default { viewBox: '0 0 448 512', }, 'arrow-back-24': { - path: [ - 'M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z', - ], + path: ['M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z'], viewBox: '0 0 24, 24', }, 'arrow-forward-24': { - path: [ - 'M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8-8-8z', - ], + path: ['M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8-8-8z'], viewBox: '0 0 24 24', }, 'ellipsis-h': { @@ -194,20 +190,20 @@ export default { viewBox: '0 0 384 512', }, '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', }, 'plus-24': { - path: [ - 'M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z' - ], + path: ['M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'], viewBox: '0 0 24 24', }, 'notification-24': { 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', ], - viewBox: '0 0 24 24' + viewBox: '0 0 24 24', }, 'help-24': { path: [ @@ -216,7 +212,6 @@ export default { viewBox: '0 0 24 24', }, - // 16 'file-import-16': { path: [ @@ -292,5 +287,9 @@ export default { 'M13 12h7v1.5h-7zm0-2.5h7V11h-7zm0 5h7V16h-7zM21 4H3c-1.1 0-2 .9-2 2v13c0 1.1.9 2 2 2h18c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 15h-9V6h9v13z', ], viewBox: '0 0 24 24', - } + }, + 'arrow-drop-up-16': { + path: ['M7 14l5-5 5 5z'], + viewBox: '0 0 24 24', + }, };