mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
Merge branch 'BIG-316-crud-branches' into feature/multi-dimensions
This commit is contained in:
@@ -71,6 +71,7 @@ const CLASSES = {
|
||||
PREFERENCES_PAGE_INSIDE_CONTENT_ACCOUNTANT: 'preferences-page__inside-content--accountant',
|
||||
PREFERENCES_PAGE_INSIDE_CONTENT_SMS_INTEGRATION: 'preferences-page__inside-content--sms-integration',
|
||||
PREFERENCES_PAGE_INSIDE_CONTENT_ROLES_FORM: 'preferences-page__inside-content--roles-form',
|
||||
PREFERENCES_PAGE_INSIDE_CONTENT_BRANCHES: 'preferences-page__inside-content--branches',
|
||||
|
||||
FINANCIAL_REPORT_INSIDER: 'dashboard__insider--financial-report',
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import UnlockingPartialTransactionsDialog from '../containers/Dialogs/UnlockingP
|
||||
import CreditNotePdfPreviewDialog from '../containers/Dialogs/CreditNotePdfPreviewDialog';
|
||||
import PaymentReceivePdfPreviewDialog from '../containers/Dialogs/PaymentReceivePdfPreviewDialog';
|
||||
import WarehouseFormDialog from '../containers/Dialogs/WarehouseFormDialog';
|
||||
import BranchFormDialog from '../containers/Dialogs/BranchFormDialog';
|
||||
|
||||
/**
|
||||
* Dialogs container.
|
||||
@@ -80,6 +81,7 @@ export default function DialogsContainer() {
|
||||
<CreditNotePdfPreviewDialog dialogName={'credit-note-pdf-preview'} />
|
||||
<PaymentReceivePdfPreviewDialog dialogName={'payment-pdf-preview'} />
|
||||
<WarehouseFormDialog dialogName={'warehouse-form'} />
|
||||
<BranchFormDialog dialogName={'branch-form'} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import DashboardTopbarUser from 'components/Dashboard/TopbarUser';
|
||||
import UsersActions from 'containers/Preferences/Users/UsersActions';
|
||||
import CurrenciesActions from 'containers/Preferences/Currencies/CurrenciesActions';
|
||||
import WarehousesActions from '../../containers/Preferences/Warehouses/WarehousesActions'
|
||||
import BranchesActions from '../../containers/Preferences/Branches/BranchesActions';
|
||||
import withDashboard from 'containers/Dashboard/withDashboard';
|
||||
|
||||
import { compose } from 'utils';
|
||||
@@ -41,6 +42,11 @@ function PreferencesTopbar({ preferencesPageTitle }) {
|
||||
path={'/preferences/warehouses'}
|
||||
component={WarehousesActions}
|
||||
/>
|
||||
<Route
|
||||
exact
|
||||
path={'/preferences/branches'}
|
||||
component={BranchesActions}
|
||||
/>
|
||||
</Switch>
|
||||
</Route>
|
||||
</div>
|
||||
|
||||
@@ -13,13 +13,16 @@ export default [
|
||||
},
|
||||
{
|
||||
text: <T id={'currencies'} />,
|
||||
|
||||
href: '/preferences/currencies',
|
||||
},
|
||||
{
|
||||
text: <T id={'warehouses.label'} />,
|
||||
href: '/preferences/warehouses',
|
||||
},
|
||||
{
|
||||
text: <T id={'branches.label'} />,
|
||||
href: '/preferences/branches',
|
||||
},
|
||||
{
|
||||
text: <T id={'accountant'} />,
|
||||
disabled: false,
|
||||
|
||||
77
src/containers/Alerts/Branches/BranchDeleteAlert.js
Normal file
77
src/containers/Alerts/Branches/BranchDeleteAlert.js
Normal file
@@ -0,0 +1,77 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { FormattedMessage as T, FormattedHTMLMessage } from 'components';
|
||||
import { Intent, Alert } from '@blueprintjs/core';
|
||||
import { AppToaster } from 'components';
|
||||
|
||||
import { useDeleteBranch } from 'hooks/query';
|
||||
|
||||
import withAlertStoreConnect from 'containers/Alert/withAlertStoreConnect';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Branch delete alert.
|
||||
*/
|
||||
function BranchDeleteAlert({
|
||||
name,
|
||||
|
||||
// #withAlertStoreConnect
|
||||
isOpen,
|
||||
payload: { branchId },
|
||||
|
||||
// #withAlertActions
|
||||
closeAlert,
|
||||
}) {
|
||||
|
||||
const { mutateAsync: deleteBranch, isLoading } = useDeleteBranch();
|
||||
|
||||
// Handle cancel delete alert.
|
||||
const handleCancelDelete = () => {
|
||||
closeAlert(name);
|
||||
};
|
||||
|
||||
// Handle confirm delete branch.
|
||||
const handleConfirmDeleteBranch = () => {
|
||||
deleteBranch(branchId)
|
||||
.then(() => {
|
||||
AppToaster.show({
|
||||
message: intl.get('branch.alert.delete_message'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
})
|
||||
.catch(
|
||||
({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {},
|
||||
)
|
||||
.finally(() => {
|
||||
closeAlert(name);
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<Alert
|
||||
cancelButtonText={<T id={'cancel'} />}
|
||||
confirmButtonText={<T id={'delete'} />}
|
||||
icon="trash"
|
||||
intent={Intent.DANGER}
|
||||
isOpen={isOpen}
|
||||
onCancel={handleCancelDelete}
|
||||
onConfirm={handleConfirmDeleteBranch}
|
||||
loading={isLoading}
|
||||
>
|
||||
<p>
|
||||
<FormattedHTMLMessage id={'branch.once_delete_this_branch'} />
|
||||
</p>
|
||||
</Alert>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withAlertStoreConnect(),
|
||||
withAlertActions,
|
||||
)(BranchDeleteAlert);
|
||||
@@ -22,6 +22,7 @@ import VendorCreditNotesAlerts from '../Purchases/CreditNotes/VendorCreditNotesA
|
||||
import TransactionsLockingAlerts from '../TransactionsLocking/TransactionsLockingAlerts';
|
||||
import WarehousesAlerts from '../Preferences/Warehouses/WarehousesAlerts';
|
||||
import WarehousesTransfersAlerts from '../WarehouseTransfers/WarehousesTransfersAlerts'
|
||||
import BranchesAlerts from '../Preferences/Branches/BranchesAlerts';
|
||||
|
||||
export default [
|
||||
...AccountsAlerts,
|
||||
@@ -47,5 +48,6 @@ export default [
|
||||
...VendorCreditNotesAlerts,
|
||||
...TransactionsLockingAlerts,
|
||||
...WarehousesAlerts,
|
||||
...WarehousesTransfersAlerts
|
||||
...WarehousesTransfersAlerts,
|
||||
...BranchesAlerts,
|
||||
];
|
||||
|
||||
85
src/containers/Dialogs/BranchFormDialog/BranchForm.js
Normal file
85
src/containers/Dialogs/BranchFormDialog/BranchForm.js
Normal file
@@ -0,0 +1,85 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { Formik } from 'formik';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
|
||||
import { AppToaster } from 'components';
|
||||
import { CreateBranchFormSchema } from './BranchForm.schema';
|
||||
|
||||
import BranchFormContent from './BranchFormContent';
|
||||
import { useBranchFormContext } from './BranchFormProvider';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose, transformToForm } from 'utils';
|
||||
|
||||
const defaultInitialValues = {
|
||||
name: '',
|
||||
code: '',
|
||||
address: '',
|
||||
phone_number: '',
|
||||
email: '',
|
||||
website: '',
|
||||
city: '',
|
||||
country: '',
|
||||
};
|
||||
|
||||
function BranchForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const {
|
||||
dialogName,
|
||||
branch,
|
||||
branchId,
|
||||
createBranchMutate,
|
||||
editBranchMutate,
|
||||
} = useBranchFormContext();
|
||||
|
||||
// Initial form values.
|
||||
const initialValues = {
|
||||
...defaultInitialValues,
|
||||
...transformToForm(branch, defaultInitialValues),
|
||||
};
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
||||
const form = { ...values };
|
||||
|
||||
// Handle request response success.
|
||||
const onSuccess = (response) => {
|
||||
AppToaster.show({
|
||||
message: intl.get('branch.dialog.success_message'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
// Handle request response errors.
|
||||
const onError = ({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
if (errors) {
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
if (branchId) {
|
||||
editBranchMutate([branchId, form]).then(onSuccess).catch(onError);
|
||||
} else {
|
||||
createBranchMutate(form).then(onSuccess).catch(onError);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
validationSchema={CreateBranchFormSchema}
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
component={BranchFormContent}
|
||||
/>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogActions)(BranchForm);
|
||||
16
src/containers/Dialogs/BranchFormDialog/BranchForm.schema.js
Normal file
16
src/containers/Dialogs/BranchFormDialog/BranchForm.schema.js
Normal file
@@ -0,0 +1,16 @@
|
||||
import * as Yup from 'yup';
|
||||
import intl from 'react-intl-universal';
|
||||
import { DATATYPES_LENGTH } from 'common/dataTypes';
|
||||
|
||||
const Schema = Yup.object().shape({
|
||||
name: Yup.string().required().label(intl.get('branch_name')),
|
||||
code: Yup.string().trim().min(0).max(DATATYPES_LENGTH.STRING),
|
||||
address: Yup.string().trim(),
|
||||
city: Yup.string().trim(),
|
||||
country: Yup.string().trim(),
|
||||
website: Yup.string().url().nullable(),
|
||||
phone_number: Yup.number(),
|
||||
email: Yup.string().email().nullable(),
|
||||
});
|
||||
|
||||
export const CreateBranchFormSchema = Schema;
|
||||
17
src/containers/Dialogs/BranchFormDialog/BranchFormContent.js
Normal file
17
src/containers/Dialogs/BranchFormDialog/BranchFormContent.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import React from 'react';
|
||||
import { Form } from 'formik';
|
||||
|
||||
import BranchFormFields from './BranchFormFields';
|
||||
import BranchFormFloatingActions from './BranchFormFloatingActions';
|
||||
|
||||
/**
|
||||
* Branch form content.
|
||||
*/
|
||||
export default function BranchFormContent() {
|
||||
return (
|
||||
<Form>
|
||||
<BranchFormFields />
|
||||
<BranchFormFloatingActions />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
|
||||
import '../../../style/pages/Branches/BranchFormDialog.scss';
|
||||
|
||||
import { BranchFormProvider } from './BranchFormProvider';
|
||||
import BranchForm from './BranchForm';
|
||||
|
||||
/**
|
||||
* Branch form dialog content.
|
||||
*/
|
||||
export default function BranchFormDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
branchId,
|
||||
}) {
|
||||
return (
|
||||
<BranchFormProvider branchId={branchId} dialogName={dialogName}>
|
||||
<BranchForm />
|
||||
</BranchFormProvider>
|
||||
);
|
||||
}
|
||||
153
src/containers/Dialogs/BranchFormDialog/BranchFormFields.js
Normal file
153
src/containers/Dialogs/BranchFormDialog/BranchFormFields.js
Normal file
@@ -0,0 +1,153 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { FastField, ErrorMessage, Field } from 'formik';
|
||||
import styled from 'styled-components';
|
||||
import {
|
||||
Classes,
|
||||
FormGroup,
|
||||
InputGroup,
|
||||
ControlGroup,
|
||||
Position,
|
||||
} from '@blueprintjs/core';
|
||||
import { inputIntent } from 'utils';
|
||||
import { FieldRequiredHint, Col, Row, FormattedMessage as T } from 'components';
|
||||
import { useBranchFormContext } from './BranchFormProvider';
|
||||
|
||||
/**
|
||||
* Branch form dialog fields.
|
||||
*/
|
||||
function BranchFormFields() {
|
||||
return (
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
{/*------------ Branch Name -----------*/}
|
||||
<FastField name={'name'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'branch.dialog.label.branch_name'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="branch_name" />}
|
||||
className={'form-group--branch_name'}
|
||||
>
|
||||
<InputGroup intent={inputIntent({ error, touched })} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/*------------ Branch Code -----------*/}
|
||||
<FastField name={'code'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'branch.dialog.label.branch_code'} />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="code" />}
|
||||
className={'form-group--branch_name'}
|
||||
>
|
||||
<InputGroup intent={inputIntent({ error, touched })} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/*------------ Branch Address -----------*/}
|
||||
<FastField name={'address'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={intl.get('branch.dialog.label.branch_address')}
|
||||
intent={inputIntent({ error, touched })}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="address" />}
|
||||
className={'form-group--branch_address'}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
placeholder={intl.get('branch.dialog.label.address_1')}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<BranchAddressWrap>
|
||||
{/*------------ Branch Address City & Country-----------*/}
|
||||
<FormGroup
|
||||
inline={true}
|
||||
className={'form-group--branch_address'}
|
||||
helperText={<ErrorMessage name="branch_address_2" />}
|
||||
>
|
||||
<ControlGroup>
|
||||
<FastField name={'city'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
placeholder={intl.get('branch.dialog.label.city')}
|
||||
{...field}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
<FastField name={'country'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
placeholder={intl.get('branch.dialog.label.country')}
|
||||
{...field}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
</ControlGroup>
|
||||
</FormGroup>
|
||||
</BranchAddressWrap>
|
||||
|
||||
{/*------------ Phone Number -----------*/}
|
||||
<FastField name={'phone_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={intl.get('branch.dialog.label.phone_number')}
|
||||
intent={inputIntent({ error, touched })}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="phone_number" />}
|
||||
className={'form-group--phone_number'}
|
||||
>
|
||||
<InputGroup placeholder={'https://'} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/*------------ Email -----------*/}
|
||||
<FastField name={'email'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={intl.get('branch.dialog.label.email')}
|
||||
intent={inputIntent({ error, touched })}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="email" />}
|
||||
className={'form-group--email'}
|
||||
>
|
||||
<InputGroup intent={inputIntent({ error, touched })} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/*------------ Website -----------*/}
|
||||
<FastField name={'website'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={intl.get('branch.dialog.label.website')}
|
||||
intent={inputIntent({ error, touched })}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="email" />}
|
||||
className={'form-group--website'}
|
||||
>
|
||||
<InputGroup intent={inputIntent({ error, touched })} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default BranchFormFields;
|
||||
|
||||
const BranchAddressWrap = styled.div`
|
||||
margin-left: 160px;
|
||||
`;
|
||||
@@ -0,0 +1,46 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
|
||||
import { useBranchFormContext } from './BranchFormProvider';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Branch form floating actions.
|
||||
*/
|
||||
function BranchFormFloatingActions({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// Formik context.
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
const { dialogName } = useBranchFormContext();
|
||||
|
||||
// Handle close button click.
|
||||
const handleCancelBtnClick = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancelBtnClick} style={{ minWidth: '85px' }}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
loading={isSubmitting}
|
||||
style={{ minWidth: '95px' }}
|
||||
type="submit"
|
||||
>
|
||||
{<T id={'save'} />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogActions)(BranchFormFloatingActions);
|
||||
@@ -0,0 +1,37 @@
|
||||
import React from 'react';
|
||||
import { DialogContent } from 'components';
|
||||
import { useCreateBranch, useEditBranch, useBranch } from 'hooks/query';
|
||||
|
||||
const BranchFormContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Branch form dialog provider.
|
||||
*/
|
||||
function BranchFormProvider({ dialogName, branchId, ...props }) {
|
||||
// Create and edit warehouse mutations.
|
||||
const { mutateAsync: createBranchMutate } = useCreateBranch();
|
||||
const { mutateAsync: editBranchMutate } = useEditBranch();
|
||||
|
||||
// Handle fetch branch detail.
|
||||
const { data: branch, isLoading: isBranchLoading } = useBranch(branchId, {
|
||||
enabled: !!branchId,
|
||||
});
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
dialogName,
|
||||
branch,
|
||||
branchId,
|
||||
createBranchMutate,
|
||||
editBranchMutate,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isBranchLoading}>
|
||||
<BranchFormContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
const useBranchFormContext = () => React.useContext(BranchFormContext);
|
||||
|
||||
export { BranchFormProvider, useBranchFormContext };
|
||||
41
src/containers/Dialogs/BranchFormDialog/index.js
Normal file
41
src/containers/Dialogs/BranchFormDialog/index.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import React from 'react';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import { Dialog, DialogSuspense } from 'components';
|
||||
import withDialogRedux from 'components/DialogReduxConnect';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
const BranchFormDialogContent = React.lazy(() =>
|
||||
import('./BranchFormDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Branch form form dialog.
|
||||
*/
|
||||
function BranchFormDialog({
|
||||
dialogName,
|
||||
payload: { branchId, action },
|
||||
isOpen,
|
||||
}) {
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={
|
||||
action === 'edit' ? (
|
||||
<T id={'branch.dialog.label_edit_branch'} />
|
||||
) : (
|
||||
<T id={'branch.dialog.label_new_branch'} />
|
||||
)
|
||||
}
|
||||
isOpen={isOpen}
|
||||
canEscapeJeyClose={true}
|
||||
autoFocus={true}
|
||||
className={'dialog--branch-form'}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<BranchFormDialogContent dialogName={dialogName} branchId={branchId} />
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogRedux())(BranchFormDialog);
|
||||
21
src/containers/Preferences/Branches/Branches.js
Normal file
21
src/containers/Preferences/Branches/Branches.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import classNames from 'classnames';
|
||||
import { CLASSES } from 'common/classes';
|
||||
|
||||
import BranchesDataTable from './BranchesDataTable';
|
||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
function Branches({
|
||||
// #withDashboardActions
|
||||
changePreferencesPageTitle,
|
||||
}) {
|
||||
React.useEffect(() => {
|
||||
changePreferencesPageTitle(intl.get('branches.label'));
|
||||
}, [changePreferencesPageTitle]);
|
||||
|
||||
return <BranchesDataTable />;
|
||||
}
|
||||
export default compose(withDashboardActions)(Branches);
|
||||
29
src/containers/Preferences/Branches/BranchesActions.js
Normal file
29
src/containers/Preferences/Branches/BranchesActions.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
import { Button, Intent } from '@blueprintjs/core';
|
||||
|
||||
import { FormattedMessage as T, Icon } from 'components';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
function BranchesActions({
|
||||
//#ownProps
|
||||
openDialog,
|
||||
}) {
|
||||
const handleClickNewBranche = () => {
|
||||
openDialog('branch-form');
|
||||
};
|
||||
|
||||
return (
|
||||
<React.Fragment>
|
||||
<Button
|
||||
icon={<Icon icon="plus" iconSize={12} />}
|
||||
onClick={handleClickNewBranche}
|
||||
intent={Intent.PRIMARY}
|
||||
>
|
||||
<T id={'branches.label.new_branch'} />
|
||||
</Button>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(BranchesActions);
|
||||
7
src/containers/Preferences/Branches/BranchesAlerts.js
Normal file
7
src/containers/Preferences/Branches/BranchesAlerts.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import React from 'react';
|
||||
|
||||
const BranchDeleteAlert = React.lazy(() =>
|
||||
import('../../Alerts/Branches/BranchDeleteAlert'),
|
||||
);
|
||||
|
||||
export default [{ name: 'branch-delete', component: BranchDeleteAlert }];
|
||||
58
src/containers/Preferences/Branches/BranchesDataTable.js
Normal file
58
src/containers/Preferences/Branches/BranchesDataTable.js
Normal file
@@ -0,0 +1,58 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { DataTable } from 'components';
|
||||
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
|
||||
import { useBranchesTableColumns, ActionsMenu } from './components';
|
||||
import { useBranchesContext } from './BranchesProvider';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import withAlertActions from 'containers/Alert/withAlertActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Branches data table.
|
||||
*/
|
||||
function BranchesDataTable({
|
||||
// #withDialogAction
|
||||
openDialog,
|
||||
|
||||
// #withAlertActions
|
||||
openAlert,
|
||||
}) {
|
||||
// Table columns.
|
||||
const columns = useBranchesTableColumns();
|
||||
|
||||
const { branches, isBranchesLoading, isBranchesFetching } =
|
||||
useBranchesContext();
|
||||
|
||||
const handleEditBranch = ({ id }) => {
|
||||
openDialog('branch-form', { branchId: id, action: 'edit' });
|
||||
};
|
||||
|
||||
const handleDeleteBranch = ({ id }) => {
|
||||
openAlert('branch-delete', { branchId: id });
|
||||
};
|
||||
|
||||
return (
|
||||
<BranchesTable
|
||||
columns={columns}
|
||||
data={branches}
|
||||
loading={isBranchesLoading}
|
||||
headerLoading={isBranchesLoading}
|
||||
progressBarLoading={isBranchesFetching}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
noInitialFetch={true}
|
||||
ContextMenu={ActionsMenu}
|
||||
payload={{
|
||||
onEdit: handleEditBranch,
|
||||
onDelete: handleDeleteBranch,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions, withAlertActions)(BranchesDataTable);
|
||||
|
||||
const BranchesTable = styled(DataTable)``;
|
||||
48
src/containers/Preferences/Branches/BranchesProvider.js
Normal file
48
src/containers/Preferences/Branches/BranchesProvider.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import classNames from 'classnames';
|
||||
import { CLASSES } from 'common/classes';
|
||||
import { Card } from 'components';
|
||||
import { useBranches } from 'hooks/query';
|
||||
import PreferencesPageLoader from '../PreferencesPageLoader';
|
||||
|
||||
const BranchesContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Branches data provider.
|
||||
*/
|
||||
function BranchesProvider({ ...props }) {
|
||||
// Fetches the branches list.
|
||||
const {
|
||||
isLoading: isBranchesLoading,
|
||||
isFetching: isBranchesFetching,
|
||||
data: branches,
|
||||
} = useBranches();
|
||||
|
||||
// Provider state.
|
||||
const provider = {
|
||||
branches,
|
||||
isBranchesLoading,
|
||||
isBranchesFetching,
|
||||
};
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT,
|
||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_BRANCHES,
|
||||
)}
|
||||
>
|
||||
<BrachesPreferencesCard>
|
||||
<BranchesContext.Provider value={provider} {...props} />
|
||||
</BrachesPreferencesCard>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const useBranchesContext = () => React.useContext(BranchesContext);
|
||||
export { BranchesProvider, useBranchesContext };
|
||||
|
||||
const BrachesPreferencesCard = styled(Card)`
|
||||
padding: 0;
|
||||
`;
|
||||
76
src/containers/Preferences/Branches/components.js
Normal file
76
src/containers/Preferences/Branches/components.js
Normal file
@@ -0,0 +1,76 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Intent, Menu, MenuDivider, MenuItem } from '@blueprintjs/core';
|
||||
|
||||
import { safeCallback } from 'utils';
|
||||
import { Icon } from 'components';
|
||||
|
||||
/**
|
||||
* Context menu of Branches.
|
||||
*/
|
||||
export function ActionsMenu({
|
||||
payload: { onEdit, onDelete },
|
||||
row: { original },
|
||||
}) {
|
||||
return (
|
||||
<Menu>
|
||||
<MenuItem
|
||||
icon={<Icon icon="pen-18" />}
|
||||
text={intl.get('branches.action.edit_branch')}
|
||||
onClick={safeCallback(onEdit, original)}
|
||||
/>
|
||||
<MenuDivider />
|
||||
<MenuItem
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
text={intl.get('branches.action.delete_branch')}
|
||||
onClick={safeCallback(onDelete, original)}
|
||||
intent={Intent.DANGER}
|
||||
/>
|
||||
</Menu>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve branches table columns
|
||||
* @returns
|
||||
*/
|
||||
export function useBranchesTableColumns() {
|
||||
return React.useMemo(
|
||||
() => [
|
||||
{
|
||||
id: 'name',
|
||||
Header: intl.get('branches.column.branch_name'),
|
||||
accessor: 'name',
|
||||
className: 'name',
|
||||
width: '120',
|
||||
disableSortBy: true,
|
||||
textOverview: true,
|
||||
},
|
||||
{
|
||||
id: 'code',
|
||||
Header: intl.get('branches.column.code'),
|
||||
accessor: 'code',
|
||||
className: 'code',
|
||||
width: '100',
|
||||
disableSortBy: true,
|
||||
textOverview: true,
|
||||
},
|
||||
{
|
||||
Header: intl.get('branches.column.address'),
|
||||
accessor: 'address',
|
||||
className: 'address',
|
||||
width: '180',
|
||||
disableSortBy: true,
|
||||
textOverview: true,
|
||||
},
|
||||
{
|
||||
Header: intl.get('branches.column.phone_number'),
|
||||
accessor: 'phone_number',
|
||||
className: 'phone_number',
|
||||
width: '120',
|
||||
disableSortBy: true,
|
||||
},
|
||||
],
|
||||
[],
|
||||
);
|
||||
}
|
||||
15
src/containers/Preferences/Branches/index.js
Normal file
15
src/containers/Preferences/Branches/index.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
|
||||
import { BranchesProvider } from './BranchesProvider';
|
||||
import Branches from './Branches';
|
||||
|
||||
/**
|
||||
* Branches .
|
||||
*/
|
||||
export default function BranchesPreferences() {
|
||||
return (
|
||||
<BranchesProvider>
|
||||
<Branches />
|
||||
</BranchesProvider>
|
||||
);
|
||||
}
|
||||
99
src/hooks/query/branches.js
Normal file
99
src/hooks/query/branches.js
Normal file
@@ -0,0 +1,99 @@
|
||||
import { useQueryClient, useMutation } from 'react-query';
|
||||
import { useRequestQuery } from '../useQueryRequest';
|
||||
import useApiRequest from '../useRequest';
|
||||
import t from './types';
|
||||
|
||||
// Common invalidate queries.
|
||||
const commonInvalidateQueries = (queryClient) => {
|
||||
// Invalidate warehouses.
|
||||
queryClient.invalidateQueries(t.BRANCHES);
|
||||
queryClient.invalidateQueries(t.BRANCH);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new branch.
|
||||
*/
|
||||
export function useCreateBranch(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation((values) => apiRequest.post('branches', values), {
|
||||
onSuccess: (res, values) => {
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Edits the given branch.
|
||||
*/
|
||||
export function useEditBranch(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation(
|
||||
([id, values]) => apiRequest.post(`branches/${id}`, values),
|
||||
{
|
||||
onSuccess: (res, [id, values]) => {
|
||||
// Invalidate specific branch.
|
||||
queryClient.invalidateQueries([t.BRANCH, id]);
|
||||
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the given branch.
|
||||
*/
|
||||
export function useDeleteBranch(props) {
|
||||
const queryClient = useQueryClient();
|
||||
const apiRequest = useApiRequest();
|
||||
|
||||
return useMutation((id) => apiRequest.delete(`branches/${id}`), {
|
||||
onSuccess: (res, id) => {
|
||||
// Invalidate specific branch.
|
||||
queryClient.invalidateQueries([t.BRANCH, id]);
|
||||
|
||||
// Common invalidate queries.
|
||||
commonInvalidateQueries(queryClient);
|
||||
},
|
||||
...props,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Branches list.
|
||||
*/
|
||||
export function useBranches(query, props) {
|
||||
return useRequestQuery(
|
||||
[t.BRANCHES, query],
|
||||
{ method: 'get', url: 'branches', params: query },
|
||||
{
|
||||
select: (res) => res.data.branches,
|
||||
defaultData: [],
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the branch details.
|
||||
* @param {number}
|
||||
*/
|
||||
export function useBranch(id, props, requestProps) {
|
||||
return useRequestQuery(
|
||||
[t.BRANCH, id],
|
||||
{ method: 'get', url: `branches/${id}`, ...requestProps },
|
||||
{
|
||||
select: (res) => res.data.branch,
|
||||
defaultData: {},
|
||||
...props,
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -34,3 +34,4 @@ export * from './creditNote';
|
||||
export * from './vendorCredit';
|
||||
export * from './transactionsLocking';
|
||||
export * from './warehouses'
|
||||
export * from './branches';
|
||||
|
||||
@@ -199,6 +199,10 @@ const WAREHOUSES = {
|
||||
const WAREHOUSE_TRANSFERS = {
|
||||
WAREHOUSE_TRANSFER: 'WAREHOUSE_TRANSFER',
|
||||
WAREHOUSE_TRANSFERS: 'WAREHOUSE_TRANSFERS',
|
||||
}
|
||||
const BRANCHES = {
|
||||
BRANCHES: 'BRANCHES',
|
||||
BRANCH: 'BRANCH',
|
||||
};
|
||||
|
||||
export default {
|
||||
@@ -230,4 +234,5 @@ export default {
|
||||
...TARNSACTIONS_LOCKING,
|
||||
...WAREHOUSES,
|
||||
...WAREHOUSE_TRANSFERS,
|
||||
...BRANCHES,
|
||||
};
|
||||
|
||||
@@ -1802,5 +1802,27 @@
|
||||
"select_warehouse_transfer":"Select Warehouse Transfer",
|
||||
"warehouse_transfer.alert.delete_message":"The warehouse transfer transaction has been deleted successfully",
|
||||
"warehouse_transfer.once_delete_this_warehouse_transfer":"Once you delete this warehouse transfer, you won't be able to restore it later. Are you sure you want to delete this warehouse transfer?",
|
||||
"warehouse_transfer.error.could_not_transfer_item_from_source_to_destination":"Could not transfer item from source to destination on the same warehouse"
|
||||
"warehouse_transfer.error.could_not_transfer_item_from_source_to_destination":"Could not transfer item from source to destination on the same warehouse",
|
||||
"branches.label": "Branches",
|
||||
"branches.label.new_branch": "New Branch",
|
||||
"branches.action.edit_branch": "Edit Branch",
|
||||
"branches.action.delete_branch": "Delete Branch",
|
||||
"branches.column.branch_name": "Branch name",
|
||||
"branches.column.address": "Address",
|
||||
"branches.column.phone_number": "Phone number",
|
||||
"branches.column.code": "Code",
|
||||
"branch.dialog.label_new_branch": "New Branch",
|
||||
"branch.dialog.label_edit_branch": "New Branch",
|
||||
"branch.dialog.label.branch_name": "Branch Name",
|
||||
"branch.dialog.label.branch_code": "Code",
|
||||
"branch.dialog.label.branch_address": "Branch Address",
|
||||
"branch.dialog.label.address_1": "Address",
|
||||
"branch.dialog.label.city": "City",
|
||||
"branch.dialog.label.country": "Country",
|
||||
"branch.dialog.label.phone_number": "Phone Number",
|
||||
"branch.dialog.label.email": "Email",
|
||||
"branch.dialog.label.website": "Website",
|
||||
"branch.dialog.success_message": "The branch has been created successfully.",
|
||||
"branch.alert.delete_message":"The branch has been deleted successfully",
|
||||
"branch.once_delete_this_branch":"Once you delete this branch, you won't be able to restore it later. Are you sure you want to delete this branch?"
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import Item from 'containers/Preferences/Item';
|
||||
import SMSIntegration from '../containers/Preferences/SMSIntegration';
|
||||
import DefaultRoute from '../containers/Preferences/DefaultRoute';
|
||||
import Warehouses from '../containers/Preferences/Warehouses';
|
||||
import Branches from '../containers/Preferences/Branches';
|
||||
|
||||
const BASE_URL = '/preferences';
|
||||
|
||||
@@ -42,6 +43,11 @@ export default [
|
||||
component: Warehouses,
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/branches`,
|
||||
component: Branches,
|
||||
exact: true,
|
||||
},
|
||||
{
|
||||
path: `${BASE_URL}/accountant`,
|
||||
component: Accountant,
|
||||
|
||||
40
src/style/pages/Branches/BranchFormDialog.scss
Normal file
40
src/style/pages/Branches/BranchFormDialog.scss
Normal file
@@ -0,0 +1,40 @@
|
||||
.dialog--branch-form {
|
||||
width: 650px;
|
||||
|
||||
.bp3-dialog-body {
|
||||
.bp3-form-group {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.bp3-form-group.bp3-inline {
|
||||
.bp3-label {
|
||||
font-size: 13px;
|
||||
margin-bottom: 3px;
|
||||
min-width: 150px;
|
||||
}
|
||||
.bp3-form-content {
|
||||
width: 278px;
|
||||
}
|
||||
.bp3-control-group > * {
|
||||
flex-shrink: unset;
|
||||
padding-right: 5px;
|
||||
padding-left: 5px;
|
||||
|
||||
&:first-child {
|
||||
padding-left: 0;
|
||||
}
|
||||
&:last-child {
|
||||
padding-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.form-group--branch_address {
|
||||
.bp3-form-content {
|
||||
width: 388px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.bp3-dialog-footer {
|
||||
padding-top: 10px;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user