fix bugs in make journal page.

This commit is contained in:
Ahmed Bouhuolia
2020-04-07 17:52:52 +02:00
parent aed7df7931
commit 05cc76b4f1
5 changed files with 17 additions and 7 deletions

View File

@@ -11,6 +11,7 @@ import {
const AccountCellRenderer = ({ const AccountCellRenderer = ({
column: { id, value }, column: { id, value },
row: { index, original }, row: { index, original },
cell: { value: initialValue },
payload: { accounts, updateData, errors }, payload: { accounts, updateData, errors },
}) => { }) => {
const handleAccountSelected = useCallback((account) => { const handleAccountSelected = useCallback((account) => {

View File

@@ -4,9 +4,9 @@ import {
} from '@blueprintjs/core'; } from '@blueprintjs/core';
const InputEditableCell = ({ const InputEditableCell = ({
value: initialValue,
row: { index }, row: { index },
column: { id }, column: { id, },
cell: { value: initialValue },
payload, payload,
}) => { }) => {
const [value, setValue] = useState(initialValue) const [value, setValue] = useState(initialValue)

View File

@@ -14,8 +14,13 @@ const MoneyFieldCellRenderer = ({
setValue(value); setValue(value);
}, []); }, []);
function isNumeric(data) {
return !isNaN(parseFloat(data)) && isFinite(data) && data.constructor !== Array;
}
const onBlur = () => { const onBlur = () => {
payload.updateData(index, id, parseFloat(value)); const updateValue = isNumeric(value) ? parseFloat(value) : value;
payload.updateData(index, id, updateValue);
}; };
return (<MoneyInputGroup return (<MoneyInputGroup

View File

@@ -13,12 +13,14 @@ export default function MakeJournalEntriesFooter({
<div> <div>
<div class="form__floating-footer"> <div class="form__floating-footer">
<Button <Button
disabled={formik.isSubmitting}
intent={Intent.PRIMARY} intent={Intent.PRIMARY}
type="submit"> type="submit">
Save Save
</Button> </Button>
<Button <Button
disabled={formik.isSubmitting}
intent={Intent.PRIMARY} intent={Intent.PRIMARY}
type="submit" type="submit"
className={'ml1'}> className={'ml1'}>
@@ -26,6 +28,7 @@ export default function MakeJournalEntriesFooter({
</Button> </Button>
<Button <Button
disabled={formik.isSubmitting}
type="submit" type="submit"
className={'button-secondary ml1'}> className={'button-secondary ml1'}>
Save as Draft Save as Draft

View File

@@ -49,8 +49,8 @@ function MakeJournalEntriesForm({
const defaultEntry = useMemo(() => ({ const defaultEntry = useMemo(() => ({
account_id: null, account_id: null,
credit: null, credit: 0,
debit: null, debit: 0,
note: '', note: '',
}), []); }), []);
@@ -71,7 +71,7 @@ function MakeJournalEntriesForm({
defaultEntry, defaultEntry,
], ],
}, },
onSubmit: (values) => { onSubmit: (values, actions) => {
const form = values.entries.filter((entry) => ( const form = values.entries.filter((entry) => (
(entry.credit || entry.debit) (entry.credit || entry.debit)
)); ));
@@ -95,8 +95,9 @@ function MakeJournalEntriesForm({
AppToaster.show({ AppToaster.show({
message: 'manual_journal_has_been_submit', message: 'manual_journal_has_been_submit',
}); });
actions.setSubmitting(false);
}).catch((error) => { }).catch((error) => {
actions.setSubmitting(false);
}); });
}, },
}); });