mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: open status in bill.
This commit is contained in:
@@ -25,37 +25,37 @@ export default function BillFloatingActions({
|
||||
onCancelClick,
|
||||
onClearClick,
|
||||
billId,
|
||||
billPublished,
|
||||
isOpen,
|
||||
}) {
|
||||
const { resetForm, submitForm } = useFormikContext();
|
||||
const handleSubmitPublishBtnClick = (event) => {
|
||||
const handleSubmitOpenBtnClick = (event) => {
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: true,
|
||||
publish: true,
|
||||
status: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmitPublishAndNewBtnClick = (event) => {
|
||||
const handleSubmitOpenAndNewBtnClick = (event) => {
|
||||
submitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: true,
|
||||
status: true,
|
||||
resetForm: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmitPublishContinueEditingBtnClick = (event) => {
|
||||
const handleSubmitOpenContinueEditingBtnClick = (event) => {
|
||||
submitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: true,
|
||||
status: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleSubmitDraftBtnClick = (event) => {
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: true,
|
||||
publish: false,
|
||||
status: false,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -63,7 +63,7 @@ export default function BillFloatingActions({
|
||||
submitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: false,
|
||||
status: false,
|
||||
resetForm: true,
|
||||
});
|
||||
};
|
||||
@@ -72,7 +72,7 @@ export default function BillFloatingActions({
|
||||
submitForm();
|
||||
saveInvoke(onSubmitClick, event, {
|
||||
redirect: false,
|
||||
publish: false,
|
||||
status: false,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -87,26 +87,26 @@ export default function BillFloatingActions({
|
||||
|
||||
return (
|
||||
<div className={classNames(CLASSES.PAGE_FORM_FLOATING_ACTIONS)}>
|
||||
{/* ----------- Save And Publish ----------- */}
|
||||
<If condition={!billId || !billPublished}>
|
||||
{/* ----------- Save And Open ----------- */}
|
||||
<If condition={!billId || !isOpen}>
|
||||
<ButtonGroup>
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
type="submit"
|
||||
onClick={handleSubmitPublishBtnClick}
|
||||
text={<T id={'save_publish'} />}
|
||||
onClick={handleSubmitOpenBtnClick}
|
||||
text={<T id={'save_open'} />}
|
||||
/>
|
||||
<Popover
|
||||
content={
|
||||
<Menu>
|
||||
<MenuItem
|
||||
text={<T id={'publish_and_new'} />}
|
||||
onClick={handleSubmitPublishAndNewBtnClick}
|
||||
text={<T id={'open_and_new'} />}
|
||||
onClick={handleSubmitOpenAndNewBtnClick}
|
||||
/>
|
||||
<MenuItem
|
||||
text={<T id={'publish_continue_editing'} />}
|
||||
onClick={handleSubmitPublishContinueEditingBtnClick}
|
||||
text={<T id={'open_continue_editing'} />}
|
||||
onClick={handleSubmitOpenContinueEditingBtnClick}
|
||||
/>
|
||||
</Menu>
|
||||
}
|
||||
@@ -155,13 +155,13 @@ export default function BillFloatingActions({
|
||||
</ButtonGroup>
|
||||
</If>
|
||||
{/* ----------- Save and New ----------- */}
|
||||
<If condition={billId && billPublished}>
|
||||
<If condition={billId && isOpen}>
|
||||
<ButtonGroup>
|
||||
<Button
|
||||
disabled={isSubmitting}
|
||||
intent={Intent.PRIMARY}
|
||||
type="submit"
|
||||
onClick={handleSubmitPublishBtnClick}
|
||||
onClick={handleSubmitOpenBtnClick}
|
||||
text={<T id={'save'} />}
|
||||
/>
|
||||
<Popover
|
||||
@@ -169,7 +169,7 @@ export default function BillFloatingActions({
|
||||
<Menu>
|
||||
<MenuItem
|
||||
text={<T id={'save_and_new'} />}
|
||||
onClick={handleSubmitPublishAndNewBtnClick}
|
||||
onClick={handleSubmitOpenAndNewBtnClick}
|
||||
/>
|
||||
</Menu>
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@ const defaultInitialValues = {
|
||||
due_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
reference_no: '',
|
||||
note: '',
|
||||
open:'',
|
||||
entries: [...repeatValue(defaultBill, MIN_LINES_NUMBER)],
|
||||
};
|
||||
|
||||
@@ -141,6 +142,7 @@ function BillForm({
|
||||
|
||||
const form = {
|
||||
...values,
|
||||
open:submitPayload.status,
|
||||
entries: entries.map((entry) => ({ ...omit(entry, ['total']) })),
|
||||
};
|
||||
// Handle the request success.
|
||||
@@ -217,7 +219,7 @@ function BillForm({
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
>
|
||||
{({ isSubmitting }) => (
|
||||
{({ isSubmitting ,values }) => (
|
||||
<Form>
|
||||
<BillFormHeader onBillNumberChanged={handleBillNumberChanged} />
|
||||
<BillFormBody defaultBill={defaultBill} />
|
||||
@@ -228,7 +230,7 @@ function BillForm({
|
||||
<BillFloatingActions
|
||||
isSubmitting={isSubmitting}
|
||||
billId={billId}
|
||||
billPublished={true}
|
||||
isOpen={values.open}
|
||||
onSubmitClick={handleSubmitClick}
|
||||
onCancelClick={handleCancelClick}
|
||||
/>
|
||||
|
||||
@@ -22,6 +22,7 @@ const BillFormSchema = Yup.object().shape({
|
||||
.min(1)
|
||||
.max(DATATYPES_LENGTH.TEXT)
|
||||
.label(formatMessage({ id: 'note' })),
|
||||
open: Yup.boolean().required(),
|
||||
entries: Yup.array().of(
|
||||
Yup.object().shape({
|
||||
quantity: Yup.number()
|
||||
|
||||
@@ -35,11 +35,13 @@ function BillList({
|
||||
//#withBillActions
|
||||
requestFetchBillsTable,
|
||||
requestDeleteBill,
|
||||
requestOpenBill,
|
||||
addBillsTableQueries,
|
||||
}) {
|
||||
const history = useHistory();
|
||||
const { formatMessage } = useIntl();
|
||||
const [deleteBill, setDeleteBill] = useState(false);
|
||||
const [openBill, setOpenBill] = useState(false);
|
||||
const [selectedRows, setSelectedRows] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -86,12 +88,36 @@ function BillList({
|
||||
});
|
||||
}, [deleteBill, requestDeleteBill, formatMessage]);
|
||||
|
||||
// Handle cancel/confirm bill open.
|
||||
const handleOpenBill = useCallback((bill) => {
|
||||
setOpenBill(bill);
|
||||
}, []);
|
||||
|
||||
// Handle cancel open bill alert.
|
||||
const handleCancelOpenBill = useCallback(() => {
|
||||
setOpenBill(false);
|
||||
}, []);
|
||||
|
||||
// Handle confirm bill open.
|
||||
const handleConfirmBillOpen = useCallback(() => {
|
||||
requestOpenBill(openBill.id)
|
||||
.then(() => {
|
||||
setOpenBill(false);
|
||||
AppToaster.show({
|
||||
message: formatMessage({
|
||||
id: 'the_bill_has_been_successfully_opened',
|
||||
}),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
queryCache.invalidateQueries('bills-table');
|
||||
})
|
||||
.catch((error) => {});
|
||||
}, [openBill, requestOpenBill, formatMessage]);
|
||||
|
||||
const handleEditBill = useCallback((bill) => {
|
||||
history.push(`/bills/${bill.id}/edit`);
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Handle selected rows change.
|
||||
const handleSelectedRowsChange = useCallback(
|
||||
(_invoices) => {
|
||||
@@ -127,6 +153,7 @@ function BillList({
|
||||
<BillsDataTable
|
||||
onDeleteBill={handleDeleteBill}
|
||||
onEditBill={handleEditBill}
|
||||
onOpenBill={handleOpenBill}
|
||||
onSelectedRowsChange={handleSelectedRowsChange}
|
||||
/>
|
||||
</Route>
|
||||
@@ -144,6 +171,18 @@ function BillList({
|
||||
<T id={'once_delete_this_bill_you_will_able_to_restore_it'} />
|
||||
</p>
|
||||
</Alert>
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'open'} />}
|
||||
intent={Intent.WARNING}
|
||||
isOpen={openBill}
|
||||
onCancel={handleCancelOpenBill}
|
||||
onConfirm={handleConfirmBillOpen}
|
||||
>
|
||||
<p>
|
||||
<T id={'are_sure_to_open_this_bill'} />
|
||||
</p>
|
||||
</Alert>
|
||||
</DashboardPageContent>
|
||||
</DashboardInsider>
|
||||
);
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
MenuItem,
|
||||
MenuDivider,
|
||||
Position,
|
||||
Tag,
|
||||
} from '@blueprintjs/core';
|
||||
|
||||
import { useParams } from 'react-router-dom';
|
||||
@@ -20,7 +21,7 @@ import { compose, saveInvoke } from 'utils';
|
||||
import { CLASSES } from 'common/classes';
|
||||
import { useIsValuePassed } from 'hooks';
|
||||
|
||||
import { LoadingIndicator, Choose } from 'components';
|
||||
import { LoadingIndicator, Choose, If } from 'components';
|
||||
import DataTable from 'components/DataTable';
|
||||
import BillsEmptyStatus from './BillsEmptyStatus';
|
||||
|
||||
@@ -56,6 +57,7 @@ function BillsDataTable({
|
||||
onFetchData,
|
||||
onEditBill,
|
||||
onDeleteBill,
|
||||
onOpenBill,
|
||||
onSelectedRowsChange,
|
||||
}) {
|
||||
const { custom_view_id: customViewId } = useParams();
|
||||
@@ -121,6 +123,13 @@ function BillsDataTable({
|
||||
text={formatMessage({ id: 'edit_bill' })}
|
||||
onClick={handleEditBill(bill)}
|
||||
/>
|
||||
<If condition={!bill.is_open}>
|
||||
<MenuItem
|
||||
text={formatMessage({ id: 'mark_as_opened' })}
|
||||
onClick={() => onOpenBill(bill)}
|
||||
/>
|
||||
</If>
|
||||
|
||||
<MenuItem
|
||||
text={formatMessage({ id: 'delete_bill' })}
|
||||
intent={Intent.DANGER}
|
||||
@@ -186,7 +195,21 @@ function BillsDataTable({
|
||||
{
|
||||
id: 'status',
|
||||
Header: formatMessage({ id: 'status' }),
|
||||
accessor: 'status',
|
||||
accessor: (row) => (
|
||||
<Choose>
|
||||
<Choose.When condition={row.is_open}>
|
||||
<Tag minimal={true}>
|
||||
<T id={'opened'} />
|
||||
</Tag>
|
||||
</Choose.When>
|
||||
|
||||
<Choose.Otherwise>
|
||||
<Tag minimal={true} intent={Intent.WARNING}>
|
||||
<T id={'draft'} />
|
||||
</Tag>
|
||||
</Choose.Otherwise>
|
||||
</Choose>
|
||||
),
|
||||
width: 140,
|
||||
className: 'status',
|
||||
},
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
fetchBillsTable,
|
||||
fetchBill,
|
||||
fetchDueBills,
|
||||
openBill,
|
||||
} from 'store/Bills/bills.actions';
|
||||
import t from 'store/types';
|
||||
|
||||
@@ -17,7 +18,7 @@ const mapDispatchToProps = (dispatch) => ({
|
||||
requestFetchBillsTable: (query = {}) =>
|
||||
dispatch(fetchBillsTable({ query: { ...query } })),
|
||||
requestFetchDueBills: (vendorId) => dispatch(fetchDueBills({ vendorId })),
|
||||
|
||||
requestOpenBill: (id) => dispatch(openBill({ id })),
|
||||
changeBillView: (id) =>
|
||||
dispatch({
|
||||
type: t.BILLS_SET_CURRENT_VIEW,
|
||||
|
||||
Reference in New Issue
Block a user