mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,62 +1,201 @@
|
||||
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 { CLASSES } from 'common/classes';
|
||||
import classNames from 'classnames';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { saveInvoke } from 'utils';
|
||||
import { If, Icon } from 'components';
|
||||
|
||||
/**
|
||||
* Bill floating actions bar.
|
||||
*/
|
||||
export default function BillFloatingActions({
|
||||
isSubmitting,
|
||||
onSubmitClick,
|
||||
onSubmitAndNewClick,
|
||||
onCancelClick,
|
||||
onClearClick,
|
||||
billId,
|
||||
billPublished,
|
||||
}) {
|
||||
const { resetForm, submitForm } = useFormikContext();
|
||||
const handleSubmitPublishBtnClick = (event) => {
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: true,
|
||||
publish: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmitPublishAndNewBtnClick = (event) => {
|
||||
submitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: true,
|
||||
resetForm: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmitPublishContinueEditingBtnClick = (event) => {
|
||||
submitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmitDraftBtnClick = (event) => {
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: true,
|
||||
publish: false,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmitDraftAndNewBtnClick = (event) => {
|
||||
submitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: false,
|
||||
resetForm: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmitDraftContinueEditingBtnClick = (event) => {
|
||||
submitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: false,
|
||||
});
|
||||
};
|
||||
|
||||
const handleCancelBtnClick = (event) => {
|
||||
saveInvoke(onCancelClick, event);
|
||||
};
|
||||
|
||||
const handleClearBtnClick = (event) => {
|
||||
// saveInvoke(onClearClick, event);
|
||||
resetForm();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={'form__floating-footer'}>
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
loading={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
type="submit"
|
||||
onClick={(event) => {
|
||||
saveInvoke(onSubmitClick, event);
|
||||
}}
|
||||
>
|
||||
{billId ? <T id={'edit'} /> : <T id={'save'} />}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
loading={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
className={'ml1'}
|
||||
type="submit"
|
||||
onClick={(event) => {
|
||||
saveInvoke(onSubmitAndNewClick, event);
|
||||
}}
|
||||
>
|
||||
<T id={'save_new'} />
|
||||
</Button>
|
||||
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
|
||||
{/* ----------- Save And Publish ----------- */}
|
||||
<If condition={!billId || !billPublished}>
|
||||
<ButtonGroup>
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
type="submit"
|
||||
onClick={handleSubmitPublishBtnClick}
|
||||
text={<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>
|
||||
</ButtonGroup>
|
||||
{/* ----------- Save As Draft ----------- */}
|
||||
<ButtonGroup>
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
className={'ml1'}
|
||||
type="submit"
|
||||
onClick={handleSubmitDraftBtnClick}
|
||||
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>
|
||||
</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>
|
||||
</If>
|
||||
|
||||
{/* ----------- Clear & Reset----------- */}
|
||||
<Button
|
||||
className={'ml1'}
|
||||
disabled={isSubmitting}
|
||||
onClick={(event) => {
|
||||
saveInvoke(onClearClick, event);
|
||||
}}
|
||||
>
|
||||
<T id={'clear'} />
|
||||
</Button>
|
||||
|
||||
onClick={handleClearBtnClick}
|
||||
text={billId ? <T id={'reset'} /> : <T id={'clear'} />}
|
||||
/>
|
||||
{/* ----------- Cancel ----------- */}
|
||||
<Button
|
||||
className={'ml1'}
|
||||
type="submit"
|
||||
onClick={(event) => {
|
||||
saveInvoke(onCancelClick, event);
|
||||
}}
|
||||
>
|
||||
<T id={'close'} />
|
||||
</Button>
|
||||
onClick={handleCancelBtnClick}
|
||||
text={<T id={'cancel'} />}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ const defaultInitialValues = {
|
||||
entries: [...repeatValue(defaultBill, MIN_LINES_NUMBER)],
|
||||
};
|
||||
|
||||
/**
|
||||
* Bill form.
|
||||
*/
|
||||
function BillForm({
|
||||
//#WithMedia
|
||||
requestSubmitMedia,
|
||||
@@ -75,12 +78,12 @@ function BillForm({
|
||||
const isNewMode = !billId;
|
||||
|
||||
useEffect(() => {
|
||||
if (bill && bill.id) {
|
||||
if (!isNewMode) {
|
||||
changePageTitle(formatMessage({ id: 'edit_bill' }));
|
||||
} else {
|
||||
changePageTitle(formatMessage({ id: 'new_bill' }));
|
||||
}
|
||||
}, [changePageTitle, bill, formatMessage]);
|
||||
}, [changePageTitle, isNewMode, formatMessage]);
|
||||
|
||||
// Initial values in create and edit mode.
|
||||
const initialValues = useMemo(
|
||||
@@ -146,8 +149,8 @@ function BillForm({
|
||||
message: formatMessage(
|
||||
{
|
||||
id: isNewMode
|
||||
? 'the_bill_has_been_successfully_created'
|
||||
: 'the_bill_has_been_successfully_edited',
|
||||
? 'the_bill_has_been_successfully_created' :
|
||||
'the_bill_has_been_successfully_edited',
|
||||
},
|
||||
{ number: values.bill_number },
|
||||
),
|
||||
@@ -155,11 +158,13 @@ function BillForm({
|
||||
});
|
||||
setSubmitting(false);
|
||||
|
||||
resetForm();
|
||||
changePageSubtitle('');
|
||||
|
||||
if (submitPayload.redirect) {
|
||||
history.go('/bills');
|
||||
history.push('/bills');
|
||||
}
|
||||
if (submitPayload.resetForm) {
|
||||
resetForm();
|
||||
}
|
||||
};
|
||||
// Handle the request error.
|
||||
@@ -167,7 +172,7 @@ function BillForm({
|
||||
handleErrors(errors, { setErrors });
|
||||
setSubmitting(false);
|
||||
};
|
||||
if (isNewMode) {
|
||||
if (bill && bill.id) {
|
||||
requestEditBill(bill.id, form).then(onSuccess).catch(onError);
|
||||
} else {
|
||||
requestSubmitBill(form).then(onSuccess).catch(onError);
|
||||
@@ -190,9 +195,12 @@ function BillForm({
|
||||
[changePageSubtitle],
|
||||
);
|
||||
|
||||
const handleSubmitClick = useCallback(() => {
|
||||
setSubmitPayload({ redirect: true });
|
||||
}, [setSubmitPayload]);
|
||||
const handleSubmitClick = useCallback(
|
||||
(event, payload) => {
|
||||
setSubmitPayload({ ...payload });
|
||||
},
|
||||
[setSubmitPayload],
|
||||
);
|
||||
|
||||
const handleCancelClick = useCallback(() => {
|
||||
history.goBack();
|
||||
@@ -209,7 +217,7 @@ function BillForm({
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
>
|
||||
{({ isSubmitting, values }) => (
|
||||
{({ isSubmitting }) => (
|
||||
<Form>
|
||||
<BillFormHeader onBillNumberChanged={handleBillNumberChanged} />
|
||||
<BillFormBody defaultBill={defaultBill} />
|
||||
@@ -220,8 +228,9 @@ function BillForm({
|
||||
<BillFloatingActions
|
||||
isSubmitting={isSubmitting}
|
||||
billId={billId}
|
||||
billPublished={true}
|
||||
onSubmitClick={handleSubmitClick}
|
||||
onCancelForm={handleCancelClick}
|
||||
onCancelClick={handleCancelClick}
|
||||
/>
|
||||
</Form>
|
||||
)}
|
||||
|
||||
@@ -1,9 +1,19 @@
|
||||
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 { saveInvoke } from 'utils';
|
||||
import { Icon } from 'components';
|
||||
|
||||
/**
|
||||
* Payment made floating actions bar.
|
||||
@@ -13,56 +23,85 @@ export default function PaymentMadeFloatingActions({
|
||||
onSubmitClick,
|
||||
onCancelClick,
|
||||
onClearBtnClick,
|
||||
onSubmitForm,
|
||||
paymentMadeId,
|
||||
}) {
|
||||
const handleSubmitBtnClick = (event) => {
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleClearBtnClick = (event) => {
|
||||
onClearBtnClick && onClearBtnClick(event);
|
||||
};
|
||||
|
||||
const handleSubmitClick = (event) => {
|
||||
onSubmitClick && onSubmitClick(event, { redirect: true });
|
||||
};
|
||||
|
||||
const handleCancelClick = (event) => {
|
||||
const handleCancelBtnClick = (event) => {
|
||||
onCancelClick && onCancelClick(event);
|
||||
saveInvoke(onCancelClick, event);
|
||||
};
|
||||
|
||||
const handleSubmitAndNewClick = (event) => {
|
||||
onSubmitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmitContinueEditingBtnClick = (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={handleSubmitClick}
|
||||
>
|
||||
<T id={'save_send'} />
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
className={'ml1'}
|
||||
name={'save'}
|
||||
type="submit"
|
||||
onClick={handleSubmitClick}
|
||||
>
|
||||
<T id={'save'} />
|
||||
</Button>
|
||||
|
||||
{/* ----------- Save and New ----------- */}
|
||||
<ButtonGroup>
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
type="submit"
|
||||
onClick={handleSubmitBtnClick}
|
||||
text={paymentMadeId ? <T id={'edit'} /> : <T id={'save'} />}
|
||||
/>
|
||||
<Popover
|
||||
content={
|
||||
<Menu>
|
||||
<MenuItem
|
||||
text={<T id={'save_and_new'} />}
|
||||
onClick={handleSubmitAndNewClick}
|
||||
/>
|
||||
<MenuItem
|
||||
text={<T id={'save_continue_editing'} />}
|
||||
onClick={handleSubmitContinueEditingBtnClick}
|
||||
/>
|
||||
</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>
|
||||
{/* ----------- Clear & Reset----------- */}
|
||||
<Button
|
||||
className={'ml1'}
|
||||
disabled={isSubmitting}
|
||||
onClick={handleClearBtnClick}
|
||||
>
|
||||
<T id={'clear'} />
|
||||
</Button>
|
||||
|
||||
text={paymentMadeId ? <T id={'reset'} /> : <T id={'clear'} />}
|
||||
/>
|
||||
{/* ----------- Cancel ----------- */}
|
||||
<Button
|
||||
className={'ml1'}
|
||||
type="submit"
|
||||
onClick={handleCancelClick}
|
||||
>
|
||||
<T id={'close'} />
|
||||
</Button>
|
||||
onClick={handleCancelBtnClick}
|
||||
text={<T id={'cancel'} />}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -81,6 +81,7 @@ function PaymentMadeForm({
|
||||
const [clearLinesAlert, setClearLinesAlert] = useState(false);
|
||||
const [clearFormAlert, setClearFormAlert] = useState(false);
|
||||
const [fullAmount, setFullAmount] = useState(null);
|
||||
const [submitPayload, setSubmitPayload] = useState({});
|
||||
|
||||
const [localPaymentEntries, setLocalPaymentEntries] = useState(
|
||||
paymentMadeEntries,
|
||||
@@ -155,8 +156,13 @@ function PaymentMadeForm({
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
setSubmitting(false);
|
||||
resetForm();
|
||||
// resetForm();
|
||||
changePageSubtitle('');
|
||||
|
||||
if (submitPayload.redirect) {
|
||||
history.push('/payment-mades');
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const onError = (errors) => {
|
||||
@@ -187,6 +193,7 @@ function PaymentMadeForm({
|
||||
values,
|
||||
handleSubmit,
|
||||
isSubmitting,
|
||||
submitForm,
|
||||
} = useFormik({
|
||||
validationSchema,
|
||||
initialValues,
|
||||
@@ -300,6 +307,14 @@ function PaymentMadeForm({
|
||||
[values.entries],
|
||||
);
|
||||
|
||||
const handleSubmitClick = useCallback(
|
||||
(event, payload) => {
|
||||
setSubmitPayload({ ...payload });
|
||||
},
|
||||
[setSubmitPayload],
|
||||
);
|
||||
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
@@ -379,8 +394,11 @@ function PaymentMadeForm({
|
||||
|
||||
<PaymentMadeFloatingActions
|
||||
isSubmitting={isSubmitting}
|
||||
paymentMadeId={paymentMadeId}
|
||||
onSubmitClick={handleSubmitClick}
|
||||
onCancelClick={handleCancelClick}
|
||||
onClearBtnClick={handleClearBtnClick}
|
||||
onSubmitForm={submitForm}
|
||||
/>
|
||||
|
||||
{/* <Dragzone
|
||||
|
||||
@@ -87,7 +87,7 @@ function PaymentMadeList({
|
||||
}, [deletePaymentMade, requestDeletePaymentMade, formatMessage]);
|
||||
|
||||
const handleEditPaymentMade = useCallback((payment) => {
|
||||
history.push(`/payment-made/${payment.id}/edit`);
|
||||
history.push(`/payment-mades/${payment.id}/edit`);
|
||||
});
|
||||
|
||||
// Calculates the selected rows count.
|
||||
|
||||
@@ -21,7 +21,7 @@ export default function PaymentMadesEmptyStatus() {
|
||||
intent={Intent.PRIMARY}
|
||||
large={true}
|
||||
onClick={() => {
|
||||
history.push('/payment-made/new');
|
||||
history.push('/payment-mades/new');
|
||||
}}
|
||||
>
|
||||
New bill payment
|
||||
|
||||
Reference in New Issue
Block a user