feat(branche): add crud branches.

This commit is contained in:
elforjani13
2022-02-01 23:18:32 +02:00
parent dcac1053be
commit dea4fe0e79
17 changed files with 366 additions and 74 deletions

View File

@@ -20,7 +20,7 @@ function BranchesActions({
onClick={handleClickNewBranche}
intent={Intent.PRIMARY}
>
<T id={'branches.label.new_branche'} />
<T id={'branches.label.new_branch'} />
</Button>
</React.Fragment>
);

View File

@@ -0,0 +1,7 @@
import React from 'react';
const BranchDeleteAlert = React.lazy(() =>
import('../../Alerts/Branches/BranchDeleteAlert'),
);
export default [{ name: 'branch-delete', component: BranchDeleteAlert }];

View File

@@ -4,8 +4,11 @@ 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';
/**
@@ -14,23 +17,42 @@ import { compose } from 'utils';
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={[]}
// loading={}
// progressBarLoading={}
data={branches}
loading={isBranchesLoading}
headerLoading={isBranchesLoading}
progressBarLoading={isBranchesFetching}
TableLoadingRenderer={TableSkeletonRows}
noInitialFetch={true}
ContextMenu={ActionsMenu}
payload={{}}
payload={{
onEdit: handleEditBranch,
onDelete: handleDeleteBranch,
}}
/>
);
}
export default compose(withDialogActions)(BranchesDataTable);
export default compose(withDialogActions, withAlertActions)(BranchesDataTable);
const BranchesTable = styled(DataTable)``;

View File

@@ -3,6 +3,8 @@ 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();
@@ -10,8 +12,19 @@ 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 = {};
const provider = {
branches,
isBranchesLoading,
isBranchesFetching,
};
return (
<div

View File

@@ -1,15 +1,6 @@
import React from 'react';
import intl from 'react-intl-universal';
import {
Intent,
Button,
Popover,
Menu,
MenuDivider,
Tag,
MenuItem,
Position,
} from '@blueprintjs/core';
import { Intent, Menu, MenuDivider, MenuItem } from '@blueprintjs/core';
import { safeCallback } from 'utils';
import { Icon } from 'components';
@@ -47,14 +38,23 @@ export function useBranchesTableColumns() {
return React.useMemo(
() => [
{
id: 'branch_name',
id: 'name',
Header: intl.get('branches.column.branch_name'),
accessor: 'branch_name',
className: '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',