mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 22:30:31 +00:00
fix: Expense & FloatingActions.
This commit is contained in:
@@ -23,13 +23,11 @@ export default function ExpenseFloatingFooter({
|
|||||||
isSubmitting,
|
isSubmitting,
|
||||||
onSubmitClick,
|
onSubmitClick,
|
||||||
onCancelClick,
|
onCancelClick,
|
||||||
onDraftClick,
|
|
||||||
onClearClick,
|
|
||||||
onSubmitForm,
|
|
||||||
onResetForm,
|
|
||||||
expense,
|
expense,
|
||||||
expensePublished,
|
expensePublished,
|
||||||
}) {
|
}) {
|
||||||
|
const { submitForm, resetForm } = useFormikContext();
|
||||||
|
|
||||||
const handleSubmitPublishBtnClick = (event) => {
|
const handleSubmitPublishBtnClick = (event) => {
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: true,
|
redirect: true,
|
||||||
@@ -38,7 +36,7 @@ export default function ExpenseFloatingFooter({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitPublishAndNewBtnClick = (event) => {
|
const handleSubmitPublishAndNewBtnClick = (event) => {
|
||||||
onSubmitForm();
|
submitForm();
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: false,
|
redirect: false,
|
||||||
publish: true,
|
publish: true,
|
||||||
@@ -47,7 +45,7 @@ export default function ExpenseFloatingFooter({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitPublishContinueEditingBtnClick = (event) => {
|
const handleSubmitPublishContinueEditingBtnClick = (event) => {
|
||||||
onSubmitForm();
|
submitForm();
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: false,
|
redirect: false,
|
||||||
publish: true,
|
publish: true,
|
||||||
@@ -62,7 +60,7 @@ export default function ExpenseFloatingFooter({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitDraftAndNewBtnClick = (event) => {
|
const handleSubmitDraftAndNewBtnClick = (event) => {
|
||||||
onSubmitForm();
|
submitForm();
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: false,
|
redirect: false,
|
||||||
publish: false,
|
publish: false,
|
||||||
@@ -71,7 +69,7 @@ export default function ExpenseFloatingFooter({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitDraftContinueEditingBtnClick = (event) => {
|
const handleSubmitDraftContinueEditingBtnClick = (event) => {
|
||||||
onSubmitForm();
|
submitForm();
|
||||||
saveInvoke(onSubmitClick, event, {
|
saveInvoke(onSubmitClick, event, {
|
||||||
redirect: false,
|
redirect: false,
|
||||||
publish: false,
|
publish: false,
|
||||||
@@ -84,9 +82,8 @@ export default function ExpenseFloatingFooter({
|
|||||||
|
|
||||||
const handleClearBtnClick = (event) => {
|
const handleClearBtnClick = (event) => {
|
||||||
// saveInvoke(onClearClick, event);
|
// saveInvoke(onClearClick, event);
|
||||||
onResetForm();
|
resetForm();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
|
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
|
||||||
{/* ----------- Save And Publish ----------- */}
|
{/* ----------- Save And Publish ----------- */}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import React, {
|
import React, { useMemo, useEffect,useState,useCallback } from 'react';
|
||||||
useMemo,
|
|
||||||
useEffect,
|
|
||||||
} from 'react';
|
|
||||||
import { Intent } from '@blueprintjs/core';
|
import { Intent } from '@blueprintjs/core';
|
||||||
import { useIntl } from 'react-intl';
|
import { useIntl } from 'react-intl';
|
||||||
import { defaultTo, pick } from 'lodash';
|
import { defaultTo, pick } from 'lodash';
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { useHistory } from 'react-router-dom';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
|
|
||||||
import ExpenseFormHeader from './ExpenseFormHeader';
|
import ExpenseFormHeader from './ExpenseFormHeader';
|
||||||
@@ -28,9 +26,7 @@ import {
|
|||||||
CreateExpenseFormSchema,
|
CreateExpenseFormSchema,
|
||||||
EditExpenseFormSchema,
|
EditExpenseFormSchema,
|
||||||
} from './ExpenseForm.schema';
|
} from './ExpenseForm.schema';
|
||||||
import {
|
import { transformErrors } from './utils';
|
||||||
transformErrors,
|
|
||||||
} from './utils';
|
|
||||||
import { compose, repeatValue, orderingLinesIndexes } from 'utils';
|
import { compose, repeatValue, orderingLinesIndexes } from 'utils';
|
||||||
|
|
||||||
const MIN_LINES_NUMBER = 4;
|
const MIN_LINES_NUMBER = 4;
|
||||||
@@ -49,6 +45,7 @@ const defaultInitialValues = {
|
|||||||
description: '',
|
description: '',
|
||||||
reference_no: '',
|
reference_no: '',
|
||||||
currency_code: '',
|
currency_code: '',
|
||||||
|
is_published:'',
|
||||||
categories: [...repeatValue(defaultCategory, MIN_LINES_NUMBER)],
|
categories: [...repeatValue(defaultCategory, MIN_LINES_NUMBER)],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -82,7 +79,9 @@ function ExpenseForm({
|
|||||||
onCancelForm,
|
onCancelForm,
|
||||||
}) {
|
}) {
|
||||||
const isNewMode = !expenseId;
|
const isNewMode = !expenseId;
|
||||||
|
const [submitPayload, setSubmitPayload] = useState({});
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
const validationSchema = isNewMode
|
const validationSchema = isNewMode
|
||||||
? CreateExpenseFormSchema
|
? CreateExpenseFormSchema
|
||||||
@@ -115,9 +114,7 @@ function ExpenseForm({
|
|||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
...defaultInitialValues,
|
...defaultInitialValues,
|
||||||
categories: orderingLinesIndexes(
|
categories: orderingLinesIndexes(defaultInitialValues.categories),
|
||||||
defaultInitialValues.categories,
|
|
||||||
),
|
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[expense, baseCurrency, preferredPaymentAccount],
|
[expense, baseCurrency, preferredPaymentAccount],
|
||||||
@@ -146,22 +143,30 @@ function ExpenseForm({
|
|||||||
|
|
||||||
const form = {
|
const form = {
|
||||||
...values,
|
...values,
|
||||||
publish: 1,
|
is_published: submitPayload.publish,
|
||||||
categories,
|
categories,
|
||||||
};
|
};
|
||||||
// Handle request success.
|
// Handle request success.
|
||||||
const handleSuccess = (response) => {
|
const handleSuccess = (response) => {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: formatMessage(
|
message: formatMessage(
|
||||||
{ id: isNewMode ?
|
{
|
||||||
'the_expense_has_been_successfully_created' :
|
id: isNewMode
|
||||||
'the_expense_has_been_successfully_edited' },
|
? 'the_expense_has_been_successfully_created'
|
||||||
|
: 'the_expense_has_been_successfully_edited',
|
||||||
|
},
|
||||||
{ number: values.payment_account_id },
|
{ number: values.payment_account_id },
|
||||||
),
|
),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
resetForm();
|
|
||||||
|
if (submitPayload.redirect) {
|
||||||
|
history.push('/expenses');
|
||||||
|
}
|
||||||
|
if (submitPayload.resetForm) {
|
||||||
|
resetForm();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle request error
|
// Handle request error
|
||||||
@@ -172,16 +177,30 @@ function ExpenseForm({
|
|||||||
if (isNewMode) {
|
if (isNewMode) {
|
||||||
requestSubmitExpense(form).then(handleSuccess).catch(handleError);
|
requestSubmitExpense(form).then(handleSuccess).catch(handleError);
|
||||||
} else {
|
} else {
|
||||||
requestEditExpense(expense.id, form).then(handleSuccess).catch(handleError);
|
requestEditExpense(expense.id, form)
|
||||||
|
.then(handleSuccess)
|
||||||
|
.catch(handleError);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const handleCancelClick = useCallback(() => {
|
||||||
|
history.goBack();
|
||||||
|
}, [history]);
|
||||||
|
|
||||||
|
const handleSubmitClick = useCallback(
|
||||||
|
(event, payload) => {
|
||||||
|
setSubmitPayload({ ...payload });
|
||||||
|
},
|
||||||
|
[setSubmitPayload],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(
|
<div
|
||||||
CLASSES.PAGE_FORM,
|
className={classNames(
|
||||||
CLASSES.PAGE_FORM_STRIP_STYLE,
|
CLASSES.PAGE_FORM,
|
||||||
CLASSES.PAGE_FORM_EXPENSE
|
CLASSES.PAGE_FORM_STRIP_STYLE,
|
||||||
)}>
|
CLASSES.PAGE_FORM_EXPENSE,
|
||||||
|
)}
|
||||||
|
>
|
||||||
<Formik
|
<Formik
|
||||||
validationSchema={validationSchema}
|
validationSchema={validationSchema}
|
||||||
initialValues={initialValues}
|
initialValues={initialValues}
|
||||||
@@ -192,7 +211,13 @@ function ExpenseForm({
|
|||||||
<ExpenseFormHeader />
|
<ExpenseFormHeader />
|
||||||
<ExpenseFormBody />
|
<ExpenseFormBody />
|
||||||
<ExpenseFormFooter />
|
<ExpenseFormFooter />
|
||||||
<ExpenseFloatingFooter />
|
<ExpenseFloatingFooter
|
||||||
|
isSubmitting={isSubmitting}
|
||||||
|
expense={expenseId}
|
||||||
|
expensePublished={values.is_published}
|
||||||
|
onCancelClick={handleCancelClick}
|
||||||
|
onSubmitClick={handleSubmitClick}
|
||||||
|
/>
|
||||||
</Form>
|
</Form>
|
||||||
)}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
@@ -208,6 +233,9 @@ export default compose(
|
|||||||
withExpenseDetail(),
|
withExpenseDetail(),
|
||||||
withSettings(({ organizationSettings, expenseSettings }) => ({
|
withSettings(({ organizationSettings, expenseSettings }) => ({
|
||||||
baseCurrency: organizationSettings?.baseCurrency,
|
baseCurrency: organizationSettings?.baseCurrency,
|
||||||
preferredPaymentAccount: parseInt(expenseSettings?.preferredPaymentAccount, 10),
|
preferredPaymentAccount: parseInt(
|
||||||
|
expenseSettings?.preferredPaymentAccount,
|
||||||
|
10,
|
||||||
|
),
|
||||||
})),
|
})),
|
||||||
)(ExpenseForm);
|
)(ExpenseForm);
|
||||||
|
|||||||
Reference in New Issue
Block a user