mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
Fix: request Submit Bill.
This commit is contained in:
@@ -9,10 +9,10 @@ import {
|
|||||||
Menu,
|
Menu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
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 { useFormikContext } from 'formik';
|
||||||
import { saveInvoke } from 'utils';
|
import { saveInvoke } from 'utils';
|
||||||
import { If, Icon } from 'components';
|
import { If, Icon } from 'components';
|
||||||
|
|
||||||
@@ -22,17 +22,16 @@ import { If, Icon } from 'components';
|
|||||||
export default function BillFloatingActions({
|
export default function BillFloatingActions({
|
||||||
isSubmitting,
|
isSubmitting,
|
||||||
onSubmitClick,
|
onSubmitClick,
|
||||||
onSubmitAndNewClick,
|
|
||||||
onCancelClick,
|
onCancelClick,
|
||||||
onClearClick,
|
onClearClick,
|
||||||
billId,
|
billId,
|
||||||
billPublished,
|
billPublished,
|
||||||
}) {
|
}) {
|
||||||
const { resetForm, submitForm } = useFormikContext();
|
const { resetForm, submitForm } = useFormikContext();
|
||||||
|
|
||||||
const handleSubmitPublishBtnClick = (event) => {
|
const handleSubmitPublishBtnClick = (event) => {
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: true,
|
redirect: true,
|
||||||
|
publish: true,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -73,7 +72,7 @@ export default function BillFloatingActions({
|
|||||||
submitForm();
|
submitForm();
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: false,
|
redirect: false,
|
||||||
publish: true,
|
publish: false,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -89,7 +88,7 @@ export default function BillFloatingActions({
|
|||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
|
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
|
||||||
{/* ----------- Save And Publish ----------- */}
|
{/* ----------- Save And Publish ----------- */}
|
||||||
<If condition={!billId}>
|
<If condition={!billId || !billPublished}>
|
||||||
<ButtonGroup>
|
<ButtonGroup>
|
||||||
<Button
|
<Button
|
||||||
disabled={isSubmitting}
|
disabled={isSubmitting}
|
||||||
@@ -121,36 +120,6 @@ export default function BillFloatingActions({
|
|||||||
/>
|
/>
|
||||||
</Popover>
|
</Popover>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
</If>
|
|
||||||
{/* ----------- Save and New ----------- */}
|
|
||||||
<If condition={billId && billPublished}>
|
|
||||||
<ButtonGroup>
|
|
||||||
<Button
|
|
||||||
disabled={isSubmitting}
|
|
||||||
intent={Intent.PRIMARY}
|
|
||||||
type="submit"
|
|
||||||
onClick={handleSubmitPublishBtnClick}
|
|
||||||
text={<T id={'save'} />}
|
|
||||||
/>
|
|
||||||
<Popover
|
|
||||||
content={
|
|
||||||
<Menu>
|
|
||||||
<MenuItem
|
|
||||||
text={<T id={'save_and_new'} />}
|
|
||||||
onClick={handleSubmitPublishAndNewBtnClick}
|
|
||||||
/>
|
|
||||||
</Menu>
|
|
||||||
}
|
|
||||||
minimal={true}
|
|
||||||
interactionKind={PopoverInteractionKind.CLICK}
|
|
||||||
position={Position.BOTTOM_LEFT}
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
intent={Intent.PRIMARY}
|
|
||||||
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
|
|
||||||
/>
|
|
||||||
</Popover>
|
|
||||||
</ButtonGroup>
|
|
||||||
{/* ----------- Save As Draft ----------- */}
|
{/* ----------- Save As Draft ----------- */}
|
||||||
<ButtonGroup>
|
<ButtonGroup>
|
||||||
<Button
|
<Button
|
||||||
@@ -183,6 +152,37 @@ export default function BillFloatingActions({
|
|||||||
</Popover>
|
</Popover>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
</If>
|
</If>
|
||||||
|
{/* ----------- Save and New ----------- */}
|
||||||
|
<If condition={billId && billPublished}>
|
||||||
|
<ButtonGroup>
|
||||||
|
<Button
|
||||||
|
disabled={isSubmitting}
|
||||||
|
intent={Intent.PRIMARY}
|
||||||
|
type="submit"
|
||||||
|
onClick={handleSubmitPublishBtnClick}
|
||||||
|
text={<T id={'save'} />}
|
||||||
|
/>
|
||||||
|
<Popover
|
||||||
|
content={
|
||||||
|
<Menu>
|
||||||
|
<MenuItem
|
||||||
|
text={<T id={'save_and_new'} />}
|
||||||
|
onClick={handleSubmitPublishAndNewBtnClick}
|
||||||
|
/>
|
||||||
|
</Menu>
|
||||||
|
}
|
||||||
|
minimal={true}
|
||||||
|
interactionKind={PopoverInteractionKind.CLICK}
|
||||||
|
position={Position.BOTTOM_LEFT}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
intent={Intent.PRIMARY}
|
||||||
|
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
|
||||||
|
/>
|
||||||
|
</Popover>
|
||||||
|
</ButtonGroup>
|
||||||
|
</If>
|
||||||
|
|
||||||
{/* ----------- Clear & Reset----------- */}
|
{/* ----------- Clear & Reset----------- */}
|
||||||
<Button
|
<Button
|
||||||
className={'ml1'}
|
className={'ml1'}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ const defaultBill = {
|
|||||||
index: 0,
|
index: 0,
|
||||||
item_id: '',
|
item_id: '',
|
||||||
rate: '',
|
rate: '',
|
||||||
discount: '',
|
discount: 0,
|
||||||
quantity: '',
|
quantity: '',
|
||||||
description: '',
|
description: '',
|
||||||
};
|
};
|
||||||
@@ -50,6 +50,9 @@ const defaultInitialValues = {
|
|||||||
entries: [...repeatValue(defaultBill, MIN_LINES_NUMBER)],
|
entries: [...repeatValue(defaultBill, MIN_LINES_NUMBER)],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bill form.
|
||||||
|
*/
|
||||||
function BillForm({
|
function BillForm({
|
||||||
//#WithMedia
|
//#WithMedia
|
||||||
requestSubmitMedia,
|
requestSubmitMedia,
|
||||||
@@ -79,12 +82,12 @@ function BillForm({
|
|||||||
const isNewMode = !billId;
|
const isNewMode = !billId;
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (bill && bill.id) {
|
if (!isNewMode) {
|
||||||
changePageTitle(formatMessage({ id: 'edit_bill' }));
|
changePageTitle(formatMessage({ id: 'edit_bill' }));
|
||||||
} else {
|
} else {
|
||||||
changePageTitle(formatMessage({ id: 'new_bill' }));
|
changePageTitle(formatMessage({ id: 'new_bill' }));
|
||||||
}
|
}
|
||||||
}, [changePageTitle, bill, formatMessage]);
|
}, [changePageTitle, isNewMode, formatMessage]);
|
||||||
|
|
||||||
// Initial values in create and edit mode.
|
// Initial values in create and edit mode.
|
||||||
const initialValues = useMemo(
|
const initialValues = useMemo(
|
||||||
@@ -146,12 +149,13 @@ function BillForm({
|
|||||||
};
|
};
|
||||||
// Handle the request success.
|
// Handle the request success.
|
||||||
const onSuccess = (response) => {
|
const onSuccess = (response) => {
|
||||||
|
console.log(submitPayload, 'EE');
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage(
|
message: formatMessage(
|
||||||
{
|
{
|
||||||
id: isNewMode
|
id: isNewMode
|
||||||
? 'the_bill_has_been_successfully_created'
|
? 'the_bill_has_been_successfully_edited'
|
||||||
: 'the_bill_has_been_successfully_edited',
|
: 'the_bill_has_been_successfully_created',
|
||||||
},
|
},
|
||||||
{ number: values.bill_number },
|
{ number: values.bill_number },
|
||||||
),
|
),
|
||||||
@@ -173,7 +177,7 @@ function BillForm({
|
|||||||
handleErrors(errors, { setErrors });
|
handleErrors(errors, { setErrors });
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
if (isNewMode) {
|
if (bill && bill.id) {
|
||||||
requestEditBill(bill.id, form).then(onSuccess).catch(onError);
|
requestEditBill(bill.id, form).then(onSuccess).catch(onError);
|
||||||
} else {
|
} else {
|
||||||
requestSubmitBill(form).then(onSuccess).catch(onError);
|
requestSubmitBill(form).then(onSuccess).catch(onError);
|
||||||
@@ -214,7 +218,7 @@ function BillForm({
|
|||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
onSubmit={handleFormSubmit}
|
onSubmit={handleFormSubmit}
|
||||||
>
|
>
|
||||||
{({ isSubmitting, values }) => (
|
{({ isSubmitting }) => (
|
||||||
<Form>
|
<Form>
|
||||||
<BillFormHeader onBillNumberChanged={handleBillNumberChanged} />
|
<BillFormHeader onBillNumberChanged={handleBillNumberChanged} />
|
||||||
<EditableItemsEntriesTable
|
<EditableItemsEntriesTable
|
||||||
@@ -230,7 +234,7 @@ function BillForm({
|
|||||||
billId={billId}
|
billId={billId}
|
||||||
billPublished={true}
|
billPublished={true}
|
||||||
onSubmitClick={handleSubmitClick}
|
onSubmitClick={handleSubmitClick}
|
||||||
onCancelForm={handleCancelClick}
|
onCancelClick={handleCancelClick}
|
||||||
/>
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user