mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
Fix: Expense & PaymentReceive FloatingActions.
This commit is contained in:
@@ -1,10 +1,20 @@
|
||||
import React 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 { FormattedMessage as T } from 'react-intl';
|
||||
import { CLASSES } from 'common/classes';
|
||||
import classNames from 'classnames';
|
||||
import { saveInvoke } from 'utils';
|
||||
import { Icon } from 'components';
|
||||
|
||||
/**
|
||||
* Expense form floating actions.
|
||||
@@ -14,56 +24,142 @@ export default function ExpenseFloatingFooter({
|
||||
onSubmitClick,
|
||||
onCancelClick,
|
||||
onDraftClick,
|
||||
onClearClick,
|
||||
onSubmitAndNewClick,
|
||||
onSubmitForm,
|
||||
onResetForm,
|
||||
expense,
|
||||
}) {
|
||||
const handleSubmitBtnClick = (event) => {
|
||||
saveInvoke(onSubmitClick, event);
|
||||
const handleSubmitPublishAndNewBtnClick = (event) => {
|
||||
onSubmitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: true,
|
||||
resetForm: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleCancelBtnClick = (event) => {
|
||||
saveInvoke(onCancelClick, event);
|
||||
const handleSubmitPublishContinueEditingBtnClick = (event) => {
|
||||
onSubmitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmitAndDraftBtnClick = (event) => {
|
||||
saveInvoke(onDraftClick, event);
|
||||
const handleSubmitDraftAndNewBtnClick = (event) => {
|
||||
onSubmitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: false,
|
||||
resetForm: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmitAndNewBtnClick = (event) => {
|
||||
saveInvoke(onSubmitAndNewClick, event);
|
||||
const handleSubmitDraftContinueEditingBtnClick = (event) => {
|
||||
onSubmitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: true,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
type="submit"
|
||||
onClick={handleSubmitBtnClick}
|
||||
>
|
||||
{expense && expense.id ? <T id={'edit'} /> : <T id={'save'} />}
|
||||
</Button>
|
||||
<ButtonGroup>
|
||||
{/* ----------- Save And Publish ----------- */}
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
type="submit"
|
||||
onClick={(event) => {
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: true,
|
||||
publish: true,
|
||||
});
|
||||
}}
|
||||
text={
|
||||
expense && expense.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>
|
||||
}
|
||||
minimal={true}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
position={Position.BOTTOM_LEFT}
|
||||
>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
|
||||
/>
|
||||
</Popover>
|
||||
|
||||
<Button
|
||||
className={'ml1'}
|
||||
disabled={isSubmitting}
|
||||
onClick={handleSubmitAndNewBtnClick}
|
||||
type="submit"
|
||||
>
|
||||
<T id={'save_new'} />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
className={'ml1'}
|
||||
disabled={isSubmitting}
|
||||
onClick={handleSubmitAndDraftBtnClick}
|
||||
>
|
||||
<T id={'save_as_draft'} />
|
||||
</Button>
|
||||
|
||||
<Button className={'ml1'} onClick={handleCancelBtnClick}>
|
||||
<T id={'close'} />
|
||||
</Button>
|
||||
{/* ----------- Save As Draft ----------- */}
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
className={'ml1'}
|
||||
type="submit"
|
||||
onClick={(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>
|
||||
}
|
||||
minimal={true}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
position={Position.BOTTOM_LEFT}
|
||||
>
|
||||
<Button rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />} />
|
||||
</Popover>
|
||||
{/* ----------- Clear ----------- */}
|
||||
<Button
|
||||
className={'ml1'}
|
||||
disabled={isSubmitting}
|
||||
onClick={(event) => {
|
||||
onResetForm();
|
||||
saveInvoke(onClearClick, event);
|
||||
}}
|
||||
text={expense && expense.id ? <T id={'reset'} /> : <T id={'clear'} />}
|
||||
/>
|
||||
{/* ----------- Cancel ----------- */}
|
||||
<Button
|
||||
className={'ml1'}
|
||||
onClick={(event) => {
|
||||
saveInvoke(onCancelClick, event);
|
||||
}}
|
||||
text={<T id={'cancel'} />}
|
||||
/>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -66,9 +66,9 @@ function ExpenseForm({
|
||||
onFormSubmit,
|
||||
onCancelForm,
|
||||
}) {
|
||||
const [payload, setPayload] = useState({});
|
||||
const [submitPayload, setSubmitPayload] = useState({});
|
||||
const history = useHistory();
|
||||
|
||||
|
||||
const isNewMode = !expenseId;
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
@@ -199,6 +199,8 @@ function ExpenseForm({
|
||||
setFieldValue,
|
||||
handleSubmit,
|
||||
getFieldProps,
|
||||
submitForm,
|
||||
resetForm,
|
||||
} = useFormik({
|
||||
enableReinitialize: true,
|
||||
validationSchema,
|
||||
@@ -228,7 +230,7 @@ function ExpenseForm({
|
||||
|
||||
const form = {
|
||||
...values,
|
||||
publish: payload.publish,
|
||||
publish: submitPayload.publish,
|
||||
categories,
|
||||
};
|
||||
const saveExpense = (mdeiaIds) =>
|
||||
@@ -246,7 +248,7 @@ function ExpenseForm({
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
saveInvokeSubmit({ action: 'update', ...payload });
|
||||
saveInvokeSubmit({ action: 'update', ...submitPayload });
|
||||
clearSavedMediaIds([]);
|
||||
resetForm();
|
||||
})
|
||||
@@ -265,8 +267,11 @@ function ExpenseForm({
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
resetForm();
|
||||
saveInvokeSubmit({ action: 'new', ...payload });
|
||||
|
||||
if (submitPayload.resetForm) {
|
||||
resetForm();
|
||||
}
|
||||
saveInvokeSubmit({ action: 'new', ...submitPayload });
|
||||
clearSavedMediaIds();
|
||||
})
|
||||
.catch((errors) => {
|
||||
@@ -288,20 +293,17 @@ function ExpenseForm({
|
||||
},
|
||||
});
|
||||
|
||||
const handleSubmitClick = useCallback(() => {
|
||||
setPayload({ publish: true, redirect: true });
|
||||
}, [setPayload]);
|
||||
const handleSubmitClick = useCallback(
|
||||
(event, payload) => {
|
||||
setSubmitPayload({ ...payload });
|
||||
},
|
||||
[setSubmitPayload],
|
||||
);
|
||||
|
||||
const handleCancelClick = useCallback(() => {
|
||||
history.goBack();
|
||||
}, []);
|
||||
}, [history]);
|
||||
|
||||
const handleSubmitAndNewClick = useCallback(() => {
|
||||
setPayload({ publish: true, redirect: false });
|
||||
});
|
||||
const handleSubmitAndDraftClick = useCallback(() => {
|
||||
setPayload({ publish: false, redirect: false });
|
||||
});
|
||||
|
||||
const handleDeleteFile = useCallback(
|
||||
(_deletedFiles) => {
|
||||
@@ -370,8 +372,8 @@ function ExpenseForm({
|
||||
isSubmitting={isSubmitting}
|
||||
onSubmitClick={handleSubmitClick}
|
||||
onCancelClick={handleCancelClick}
|
||||
onDraftClick={handleSubmitAndDraftClick}
|
||||
onSubmitAndNewClick={handleSubmitAndNewClick}
|
||||
onSubmitForm={submitForm}
|
||||
onResetForm={resetForm}
|
||||
expense={expense}
|
||||
/>
|
||||
</form>
|
||||
|
||||
@@ -1,9 +1,20 @@
|
||||
import React from 'react';
|
||||
import { Intent, Button } from '@blueprintjs/core';
|
||||
import {
|
||||
Intent,
|
||||
Button,
|
||||
ButtonGroup,
|
||||
Popover,
|
||||
PopoverInteractionKind,
|
||||
Position,
|
||||
Menu,
|
||||
MenuItem,
|
||||
} from '@blueprintjs/core';
|
||||
import { FormattedMessage as T } from 'react-intl';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { CLASSES } from 'common/classes';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { saveInvoke } from 'utils';
|
||||
import { Icon } from 'components';
|
||||
|
||||
/**
|
||||
* Payment receive floating actions bar.
|
||||
@@ -13,53 +24,74 @@ export default function PaymentReceiveFormFloatingActions({
|
||||
onSubmitClick,
|
||||
onCancelClick,
|
||||
onClearClick,
|
||||
onSubmitForm,
|
||||
paymentReceiveId,
|
||||
}) {
|
||||
const handleSubmitClick = (event) => {
|
||||
onSubmitClick && onSubmitClick(event);
|
||||
const handleSubmitBtnClick = (event) => {
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleClearBtnClick = (event) => {
|
||||
onClearClick && onClearClick(event);
|
||||
};
|
||||
|
||||
const handleCloseBtnClick = (event) => {
|
||||
const handleCancelBtnClick = (event) => {
|
||||
onCancelClick && onCancelClick(event);
|
||||
saveInvoke(onCancelClick, event);
|
||||
};
|
||||
|
||||
const handleSubmitAndNewClick = (event) => {
|
||||
onSubmitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
type="submit"
|
||||
onClick={handleSubmitClick}
|
||||
>
|
||||
{paymentReceiveId ? <T id={'edit'} /> : <T id={'save_send'} />}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
className={'ml1'}
|
||||
name={'save'}
|
||||
type="submit"
|
||||
onClick={handleSubmitClick}
|
||||
>
|
||||
<T id={'save'} />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
className={'ml1'}
|
||||
disabled={isSubmitting}
|
||||
onClick={handleClearBtnClick}
|
||||
>
|
||||
<T id={'clear'} />
|
||||
</Button>
|
||||
|
||||
<Button className={'ml1'} type="submit" onClick={handleCloseBtnClick}>
|
||||
<T id={'close'} />
|
||||
</Button>
|
||||
<ButtonGroup>
|
||||
{/* ----------- Save and New ----------- */}
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
type="submit"
|
||||
onClick={handleSubmitBtnClick}
|
||||
text={paymentReceiveId ? <T id={'edit'} /> : <T id={'save_and_send'} />}
|
||||
/>
|
||||
<Popover
|
||||
content={
|
||||
<Menu>
|
||||
<MenuItem
|
||||
text={<T id={'save_and_new'} />}
|
||||
onClick={handleSubmitAndNewClick}
|
||||
/>
|
||||
</Menu>
|
||||
}
|
||||
minimal={true}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
position={Position.BOTTOM_LEFT}
|
||||
>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
rightIcon={<Icon icon="arrow-drop-up-16" iconSize={20} />}
|
||||
/>
|
||||
</Popover>
|
||||
{/* ----------- Clear & Reset----------- */}
|
||||
<Button
|
||||
className={'ml1'}
|
||||
disabled={isSubmitting}
|
||||
onClick={handleClearBtnClick}
|
||||
text={paymentReceiveId ? <T id={'reset'} /> : <T id={'clear'} />}
|
||||
/>
|
||||
{/* ----------- Cancel ----------- */}
|
||||
<Button
|
||||
className={'ml1'}
|
||||
onClick={handleCancelBtnClick}
|
||||
text={<T id={'cancel'} />}
|
||||
/>
|
||||
</ButtonGroup>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import { pick, sumBy, omit } from 'lodash';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import classNames from 'classnames';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import { CLASSES } from 'common/classes';
|
||||
import PaymentReceiveHeader from './PaymentReceiveFormHeader';
|
||||
@@ -66,8 +67,11 @@ function PaymentReceiveForm({
|
||||
const [clearLinesAlert, setClearLinesAlert] = useState(false);
|
||||
const [fullAmount, setFullAmount] = useState(null);
|
||||
const [clearFormAlert, setClearFormAlert] = useState(false);
|
||||
const [submitPayload, setSubmitPayload] = useState({});
|
||||
|
||||
const { formatMessage } = useIntl();
|
||||
const history = useHistory();
|
||||
|
||||
const isNewMode = !paymentReceiveId;
|
||||
const [localPaymentEntries, setLocalPaymentEntries] = useState(
|
||||
paymentReceiveEntries,
|
||||
@@ -103,7 +107,7 @@ function PaymentReceiveForm({
|
||||
const validationSchema = isNewMode
|
||||
? CreatePaymentReceiveFormSchema
|
||||
: EditPaymentReceiveFormSchema;
|
||||
|
||||
|
||||
// Default payment receive entry.
|
||||
const defaultPaymentReceiveEntry = {
|
||||
id: '',
|
||||
@@ -187,6 +191,10 @@ function PaymentReceiveForm({
|
||||
});
|
||||
setSubmitting(false);
|
||||
resetForm();
|
||||
|
||||
if (submitPayload.redirect) {
|
||||
history.push('/payment-receives');
|
||||
}
|
||||
};
|
||||
// Handle request response errors.
|
||||
const onError = (errors) => {
|
||||
@@ -220,6 +228,7 @@ function PaymentReceiveForm({
|
||||
isSubmitting,
|
||||
touched,
|
||||
resetForm,
|
||||
submitForm,
|
||||
} = useFormik({
|
||||
enableReinitialize: true,
|
||||
validationSchema,
|
||||
@@ -338,6 +347,17 @@ function PaymentReceiveForm({
|
||||
[changePageSubtitle],
|
||||
);
|
||||
|
||||
const handleSubmitClick = useCallback(
|
||||
(event, payload) => {
|
||||
setSubmitPayload({ ...payload });
|
||||
},
|
||||
[setSubmitPayload],
|
||||
);
|
||||
|
||||
const handleCancelClick = useCallback(() => {
|
||||
history.goBack();
|
||||
}, [history]);
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
@@ -416,6 +436,9 @@ function PaymentReceiveForm({
|
||||
isSubmitting={isSubmitting}
|
||||
paymentReceiveId={paymentReceiveId}
|
||||
onClearClick={handleClearBtnClick}
|
||||
onSubmitClick={handleSubmitClick}
|
||||
onCancelClick={handleCancelClick}
|
||||
onSubmitForm={submitForm}
|
||||
/>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
@@ -844,12 +844,11 @@ 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 ',
|
||||
|
||||
|
||||
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 ',
|
||||
save_and_send: 'Save and Send',
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user