mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
Merge pull request #57 from bigcapitalhq/BIG-379-create-a-project
`BIG-379` Add project & task dialog & projects list.
This commit is contained in:
@@ -16,7 +16,8 @@ export const TABLES = {
|
||||
CASHFLOW_Transactions: 'cashflow_transactions',
|
||||
CREDIT_NOTES: 'credit_notes',
|
||||
VENDOR_CREDITS: 'vendor_credits',
|
||||
WAREHOUSE_TRANSFERS:'warehouse_transfers'
|
||||
WAREHOUSE_TRANSFERS: 'warehouse_transfers',
|
||||
PROJECTS: 'projects',
|
||||
};
|
||||
|
||||
export const TABLE_SIZE = {
|
||||
|
||||
@@ -40,6 +40,8 @@ import BranchActivateDialog from '../containers/Dialogs/BranchActivateDialog';
|
||||
import WarehouseActivateDialog from '../containers/Dialogs/WarehouseActivateDialog';
|
||||
import CustomerOpeningBalanceDialog from '../containers/Dialogs/CustomerOpeningBalanceDialog';
|
||||
import VendorOpeningBalanceDialog from '../containers/Dialogs/VendorOpeningBalanceDialog';
|
||||
import ProjectFormDialog from '../containers/Projects/containers/ProjectFormDialog';
|
||||
import TaskFormDialog from '../containers/Projects/containers/TaskFormDialog';
|
||||
|
||||
/**
|
||||
* Dialogs container.
|
||||
@@ -90,6 +92,8 @@ export default function DialogsContainer() {
|
||||
<WarehouseActivateDialog dialogName={'warehouse-activate'} />
|
||||
<CustomerOpeningBalanceDialog dialogName={'customer-opening-balance'} />
|
||||
<VendorOpeningBalanceDialog dialogName={'vendor-opening-balance'} />
|
||||
<ProjectFormDialog dialogName={'project-form'} />
|
||||
<TaskFormDialog dialogName={'task-form'} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
TextArea,
|
||||
} from '@blueprintjs-formik/core';
|
||||
import { Select, MultiSelect } from '@blueprintjs-formik/select';
|
||||
import { DateInput } from '@blueprintjs-formik/datetime';
|
||||
|
||||
export {
|
||||
FormGroup as FFormGroup,
|
||||
@@ -21,4 +22,5 @@ export {
|
||||
MultiSelect as FMultiSelect,
|
||||
EditableText as FEditableText,
|
||||
TextArea as FTextArea,
|
||||
DateInput as FDateInput,
|
||||
};
|
||||
|
||||
@@ -538,6 +538,27 @@ export const SidebarMenu = [
|
||||
},
|
||||
],
|
||||
},
|
||||
// ---------------------
|
||||
// # Projects Management
|
||||
// ---------------------
|
||||
{
|
||||
text: 'Projects',
|
||||
type: ISidebarMenuItemType.Overlay,
|
||||
overlayId: ISidebarMenuOverlayIds.Projects,
|
||||
children: [
|
||||
{
|
||||
text: 'Projects Management',
|
||||
type: ISidebarMenuItemType.Group,
|
||||
children: [
|
||||
{
|
||||
text: 'Projects',
|
||||
href: '/projects',
|
||||
type: ISidebarMenuItemType.Link,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
// ---------------
|
||||
// # Reports
|
||||
// ---------------
|
||||
|
||||
@@ -69,6 +69,7 @@ export enum ISidebarMenuOverlayIds {
|
||||
Contacts = 'Contacts',
|
||||
Cashflow = 'Cashflow',
|
||||
Expenses = 'Expenses',
|
||||
Projects = 'Projects',
|
||||
}
|
||||
|
||||
export enum ISidebarSubscriptionAbility {
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import * as Yup from 'yup';
|
||||
import intl from 'react-intl-universal';
|
||||
import { DATATYPES_LENGTH } from 'common/dataTypes';
|
||||
|
||||
const Schema = Yup.object().shape({
|
||||
contact: Yup.string().label(intl.get('project.schema.label.contact')),
|
||||
projectName: Yup.string()
|
||||
.label(intl.get('project.schema.label.project_name'))
|
||||
.required(),
|
||||
projectDeadline: Yup.date()
|
||||
.label(intl.get('project.schema.label.deadline'))
|
||||
.required(),
|
||||
projectState: Yup.boolean().label(
|
||||
intl.get('project.schema.label.project_state'),
|
||||
),
|
||||
projectCost: Yup.number().label(
|
||||
intl.get('project.schema.label.project_cost'),
|
||||
),
|
||||
});
|
||||
|
||||
export const CreateProjectFormSchema = Schema;
|
||||
@@ -0,0 +1,68 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import moment from 'moment';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Formik } from 'formik';
|
||||
import { AppToaster } from 'components';
|
||||
import ProjectFormContent from './ProjectFormContent';
|
||||
import { CreateProjectFormSchema } from './ProjectForm.schema';
|
||||
import { useProjectFormContext } from './ProjectFormProvider';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
const defaultInitialValues = {
|
||||
contact: '',
|
||||
projectName: '',
|
||||
projectDeadline: moment(new Date()).format('YYYY-MM-DD'),
|
||||
projectState: true,
|
||||
projectCost: '',
|
||||
};
|
||||
|
||||
/**
|
||||
* Project form
|
||||
* @returns
|
||||
*/
|
||||
function ProjectForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// project form dialog context.
|
||||
const { dialogName } = useProjectFormContext();
|
||||
|
||||
// Initial form values
|
||||
const initialValues = {
|
||||
...defaultInitialValues,
|
||||
};
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
||||
const form = {};
|
||||
|
||||
// Handle request response success.
|
||||
const onSuccess = (response) => {
|
||||
AppToaster.show({});
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
// Handle request response errors.
|
||||
const onError = ({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
setSubmitting(false);
|
||||
};
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
validationSchema={CreateProjectFormSchema}
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
component={ProjectFormContent}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(ProjectForm);
|
||||
@@ -0,0 +1,17 @@
|
||||
import React from 'react';
|
||||
import { Form } from 'formik';
|
||||
|
||||
import ProjectFormFields from './ProjectFormFields';
|
||||
import ProjectFormFloatingActions from './ProjectFormFloatingActions';
|
||||
|
||||
/**
|
||||
* Project form content.
|
||||
*/
|
||||
export default function ProjectFormContent() {
|
||||
return (
|
||||
<Form>
|
||||
<ProjectFormFields />
|
||||
<ProjectFormFloatingActions />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
|
||||
import { ProjectFormProvider } from './ProjectFormProvider';
|
||||
import ProjectForm from './ProjectForm';
|
||||
|
||||
/**
|
||||
* Project form dialog content.
|
||||
* @returns {ReactNode}
|
||||
*/
|
||||
export default function ProjectFormDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
project,
|
||||
}) {
|
||||
return (
|
||||
<ProjectFormProvider projectId={project} dialogName={dialogName}>
|
||||
<ProjectForm />
|
||||
</ProjectFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { Classes, Position, FormGroup, ControlGroup } from '@blueprintjs/core';
|
||||
import { FastField } from 'formik';
|
||||
import { CLASSES } from 'common/classes';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
FFormGroup,
|
||||
FInputGroup,
|
||||
FCheckbox,
|
||||
FDateInput,
|
||||
FMoneyInputGroup,
|
||||
InputPrependText,
|
||||
FormattedMessage as T,
|
||||
CustomerSelectField,
|
||||
} from 'components';
|
||||
import {
|
||||
inputIntent,
|
||||
momentFormatter,
|
||||
tansformDateValue,
|
||||
handleDateChange,
|
||||
} from 'utils';
|
||||
import { useProjectFormContext } from './ProjectFormProvider';
|
||||
|
||||
/**
|
||||
* Project form fields.
|
||||
* @returns
|
||||
*/
|
||||
function ProjectFormFields() {
|
||||
const { customers } = useProjectFormContext();
|
||||
|
||||
return (
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
{/*------------ Contact -----------*/}
|
||||
<FastField name={'contact'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={intl.get('projects.label.contact')}
|
||||
className={classNames('form-group--select-list', Classes.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
>
|
||||
<CustomerSelectField
|
||||
contacts={customers}
|
||||
selectedContactId={value}
|
||||
defaultSelectText={'Select Contact Account'}
|
||||
onContactSelected={(customer) => {
|
||||
form.setFieldValue('contact', customer.id);
|
||||
}}
|
||||
allowCreate={true}
|
||||
popoverFill={true}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/*------------ Project Name -----------*/}
|
||||
<FFormGroup
|
||||
label={intl.get('projects.label.project_name')}
|
||||
name={'projectName'}
|
||||
>
|
||||
<FInputGroup name="projectName" />
|
||||
</FFormGroup>
|
||||
{/*------------ DeadLine -----------*/}
|
||||
<FFormGroup
|
||||
label={intl.get('projects.label.deadline')}
|
||||
name={'projectDeadline'}
|
||||
className={classNames(CLASSES.FILL, 'form-group--date')}
|
||||
>
|
||||
<FDateInput
|
||||
{...momentFormatter('YYYY/MM/DD')}
|
||||
name="projectDeadline"
|
||||
formatDate={(date) => date.toLocaleString()}
|
||||
popoverProps={{
|
||||
position: Position.BOTTOM,
|
||||
minimal: true,
|
||||
}}
|
||||
/>
|
||||
</FFormGroup>
|
||||
|
||||
{/*------------ CheckBox -----------*/}
|
||||
<FFormGroup name={'projectState'}>
|
||||
<FCheckbox
|
||||
name="projectState"
|
||||
label={intl.get('projects.label.calculator_expenses')}
|
||||
/>
|
||||
</FFormGroup>
|
||||
{/*------------ Cost Estimate -----------*/}
|
||||
<FFormGroup
|
||||
name={'projectCost'}
|
||||
label={intl.get('projects.label.cost_estimate')}
|
||||
>
|
||||
<ControlGroup>
|
||||
<InputPrependText text={'USD'} />
|
||||
<FMoneyInputGroup
|
||||
// disabled={true}
|
||||
name={'project_cost'}
|
||||
allowDecimals={true}
|
||||
allowNegativeValue={true}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FFormGroup>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProjectFormFields;
|
||||
@@ -0,0 +1,48 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import { useProjectFormContext } from './ProjectFormProvider';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Project form floating actions.
|
||||
* @returns
|
||||
*/
|
||||
function ProjectFormFloatingActions({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// project form dialog context.
|
||||
const { dialogName } = useProjectFormContext();
|
||||
|
||||
// Formik context.
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
// 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: '75px' }}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
loading={isSubmitting}
|
||||
style={{ minWidth: '75px' }}
|
||||
type="submit"
|
||||
>
|
||||
<T id={'projects.label.create'} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(ProjectFormFloatingActions);
|
||||
@@ -0,0 +1,39 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { useCustomers } from 'hooks/query';
|
||||
import { DialogContent } from 'components';
|
||||
|
||||
const ProjectFormContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Project form provider.
|
||||
* @returns
|
||||
*/
|
||||
function ProjectFormProvider({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
projectId,
|
||||
...props
|
||||
}) {
|
||||
// Handle fetch customers data table or list
|
||||
const {
|
||||
data: { customers },
|
||||
isLoading: isCustomersLoading,
|
||||
} = useCustomers({ page_size: 10000 });
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
customers,
|
||||
dialogName,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isCustomersLoading}>
|
||||
<ProjectFormContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useProjectFormContext = () => React.useContext(ProjectFormContext);
|
||||
|
||||
export { ProjectFormProvider, useProjectFormContext };
|
||||
@@ -0,0 +1,50 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { Dialog, DialogSuspense, FormattedMessage as T } from 'components';
|
||||
import withDialogRedux from 'components/DialogReduxConnect';
|
||||
import { compose } from 'utils';
|
||||
|
||||
const ProjectDialogContent = React.lazy(
|
||||
() => import('./ProjectFormDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Project form dialog.
|
||||
* @returns
|
||||
*/
|
||||
function ProjectFormDialog({ dialogName, payload: { projectId = null }, isOpen }) {
|
||||
return (
|
||||
<ProjectFormDialogRoot
|
||||
name={dialogName}
|
||||
title={<T id={'projects.label.new_project'} />}
|
||||
isOpen={isOpen}
|
||||
autoFocus={true}
|
||||
canEscapeKeyClose={true}
|
||||
style={{ width: '400px' }}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<ProjectDialogContent dialogName={dialogName} project={projectId} />
|
||||
</DialogSuspense>
|
||||
</ProjectFormDialogRoot>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogRedux())(ProjectFormDialog);
|
||||
|
||||
const ProjectFormDialogRoot = styled(Dialog)`
|
||||
.bp3-dialog-body {
|
||||
.bp3-form-group {
|
||||
margin-bottom: 15px;
|
||||
margin-top: 15px;
|
||||
|
||||
label.bp3-label {
|
||||
margin-bottom: 3px;
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
.bp3-dialog-footer {
|
||||
padding-top: 10px;
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -0,0 +1,130 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
Button,
|
||||
NavbarGroup,
|
||||
Classes,
|
||||
NavbarDivider,
|
||||
Alignment,
|
||||
} from '@blueprintjs/core';
|
||||
import {
|
||||
Icon,
|
||||
AdvancedFilterPopover,
|
||||
DashboardActionViewsList,
|
||||
DashboardFilterButton,
|
||||
DashboardRowsHeightButton,
|
||||
FormattedMessage as T,
|
||||
} from 'components';
|
||||
|
||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||
|
||||
import withProjects from './withProjects';
|
||||
import withProjectsActions from './withProjectsActions';
|
||||
import withSettings from '../../../Settings/withSettings';
|
||||
import withSettingsActions from '../../../Settings/withSettingsActions';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Projects actions bar.
|
||||
* @returns
|
||||
*/
|
||||
function ProjectsActionsBar({
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
|
||||
// #withProjects
|
||||
projectsFilterRoles,
|
||||
|
||||
// #withProjectsActions
|
||||
setProjectsTableState,
|
||||
|
||||
// #withSettings
|
||||
projectsTableSize,
|
||||
|
||||
// #withSettingsActions
|
||||
addSetting,
|
||||
}) {
|
||||
// Handle tab change.
|
||||
const handleTabChange = (view) => {
|
||||
setProjectsTableState({
|
||||
viewSlug: view ? view.slug : null,
|
||||
});
|
||||
};
|
||||
|
||||
// Handle click a refresh projects list.
|
||||
const handleRefreshBtnClick = () => {};
|
||||
|
||||
// Handle table row size change.
|
||||
const handleTableRowSizeChange = (size) => {
|
||||
addSetting('projects', 'tableSize', size);
|
||||
};
|
||||
|
||||
// Handle new project button click.
|
||||
const handleNewProjectBtnClick = () => {
|
||||
openDialog('project-form');
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
<DashboardActionViewsList
|
||||
resourceName={'projects'}
|
||||
allMenuItem={true}
|
||||
allMenuItemText={<T id={'all'} />}
|
||||
views={[]}
|
||||
onChange={handleTabChange}
|
||||
/>
|
||||
<NavbarDivider />
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="plus" />}
|
||||
text={'New Project'}
|
||||
onClick={handleNewProjectBtnClick}
|
||||
/>
|
||||
{/* AdvancedFilterPopover */}
|
||||
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'print-16'} iconSize={'16'} />}
|
||||
text={<T id={'print'} />}
|
||||
/>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'file-import-16'} />}
|
||||
text={<T id={'import'} />}
|
||||
/>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon={'file-export-16'} iconSize={'16'} />}
|
||||
text={<T id={'export'} />}
|
||||
/>
|
||||
<NavbarDivider />
|
||||
<DashboardRowsHeightButton
|
||||
initialValue={projectsTableSize}
|
||||
onChange={handleTableRowSizeChange}
|
||||
/>
|
||||
<NavbarDivider />
|
||||
</NavbarGroup>
|
||||
<NavbarGroup align={Alignment.RIGHT}>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="refresh-16" iconSize={14} />}
|
||||
onClick={handleRefreshBtnClick}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withProjectsActions,
|
||||
withSettingsActions,
|
||||
withProjects(({ projectsTableState }) => ({
|
||||
projectsFilterRoles: projectsTableState?.filterRoles,
|
||||
})),
|
||||
withSettings(({ projectSettings }) => ({
|
||||
projectsTableSize: projectSettings?.tableSize,
|
||||
})),
|
||||
)(ProjectsActionsBar);
|
||||
@@ -0,0 +1,101 @@
|
||||
import React from 'react';
|
||||
import { DataTable } from 'components';
|
||||
import { TABLES } from 'common/tables';
|
||||
import TableSkeletonRows from 'components/Datatable/TableSkeletonRows';
|
||||
import TableSkeletonHeader from 'components/Datatable/TableHeaderSkeleton';
|
||||
import { useProjectsListContext } from './ProjectsListProvider';
|
||||
import { useMemorizedColumnsWidths } from 'hooks';
|
||||
import { useProjectsListColumns, ActionsMenu } from './components';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import withProjectsActions from './withProjectsActions';
|
||||
import withSettings from '../../../Settings/withSettings';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
const projects = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Project 1',
|
||||
description: 'Project 1 description',
|
||||
status: 'Active',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Project 2',
|
||||
description: 'Project 2 description',
|
||||
status: 'Active',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Project 3',
|
||||
description: 'Project 3 description',
|
||||
status: 'Active',
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
* Projects list datatable.
|
||||
* @returns
|
||||
*/
|
||||
function ProjectsDataTable({
|
||||
// #withDial
|
||||
openDialog,
|
||||
|
||||
// #withSettings
|
||||
projectsTableSize,
|
||||
}) {
|
||||
// Retrieve projects table columns.
|
||||
const columns = useProjectsListColumns();
|
||||
|
||||
// Handle cell click.
|
||||
const handleCellClick = (cell, event) => {};
|
||||
|
||||
// Handle edit project.
|
||||
const handleEditProject = (project) => {
|
||||
openDialog('project-form', {
|
||||
projectId: project.id,
|
||||
});
|
||||
};
|
||||
|
||||
// Handle new task button click.
|
||||
const handleNewTaskButtonClick = () => {
|
||||
openDialog('task-form');
|
||||
};
|
||||
|
||||
// Local storage memorizing columns widths.
|
||||
const [initialColumnsWidths, , handleColumnResizing] =
|
||||
useMemorizedColumnsWidths(TABLES.PROJECTS);
|
||||
|
||||
return (
|
||||
<DataTable
|
||||
columns={columns}
|
||||
data={projects}
|
||||
// loading={}
|
||||
// headerLoading={}
|
||||
// progressBarLoading={}
|
||||
manualSortBy={true}
|
||||
selectionColumn={true}
|
||||
noInitialFetch={true}
|
||||
sticky={true}
|
||||
TableLoadingRenderer={TableSkeletonRows}
|
||||
TableHeaderSkeletonRenderer={TableSkeletonHeader}
|
||||
ContextMenu={ActionsMenu}
|
||||
onCellClick={handleCellClick}
|
||||
initialColumnsWidths={initialColumnsWidths}
|
||||
onColumnResizing={handleColumnResizing}
|
||||
size={projectsTableSize}
|
||||
payload={{
|
||||
onEdit: handleEditProject,
|
||||
onNewTask: handleNewTaskButtonClick,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withProjectsActions,
|
||||
withSettings(({ projectSettings }) => ({
|
||||
projectsTableSize: projectSettings?.tableSize,
|
||||
})),
|
||||
)(ProjectsDataTable);
|
||||
@@ -0,0 +1,56 @@
|
||||
import React from 'react';
|
||||
import { DashboardPageContent, DashboardContentTable } from 'components';
|
||||
|
||||
import ProjectsActionsBar from './ProjectsActionsBar';
|
||||
import ProjectsViewTabs from './ProjectsViewTabs';
|
||||
import ProjectsDataTable from './ProjectsDataTable';
|
||||
|
||||
import withProjects from './withProjects';
|
||||
import withProjectsActions from './withProjectsActions';
|
||||
|
||||
import { ProjectsListProvider } from './ProjectsListProvider';
|
||||
import { compose, transformTableStateToQuery } from 'utils';
|
||||
|
||||
/**
|
||||
* Projects list.
|
||||
* @returns
|
||||
*/
|
||||
function ProjectsList({
|
||||
// #withProjects
|
||||
projectsTableState,
|
||||
projectsTableStateChanged,
|
||||
|
||||
// #withProjectsActions
|
||||
resetProjectsTableState,
|
||||
}) {
|
||||
// Resets the projects table state once the page unmount.
|
||||
React.useEffect(
|
||||
() => () => {
|
||||
resetProjectsTableState();
|
||||
},
|
||||
[resetProjectsTableState],
|
||||
);
|
||||
|
||||
return (
|
||||
<ProjectsListProvider
|
||||
query={transformTableStateToQuery(projectsTableState)}
|
||||
tableStateChanged={projectsTableStateChanged}
|
||||
>
|
||||
<ProjectsActionsBar />
|
||||
<DashboardPageContent>
|
||||
<ProjectsViewTabs />
|
||||
<DashboardContentTable>
|
||||
<ProjectsDataTable />
|
||||
</DashboardContentTable>
|
||||
</DashboardPageContent>
|
||||
</ProjectsListProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withProjects(({ projectsTableState, projectsTableStateChanged }) => ({
|
||||
projectsTableState,
|
||||
projectsTableStateChanged,
|
||||
})),
|
||||
withProjectsActions,
|
||||
)(ProjectsList);
|
||||
@@ -0,0 +1,34 @@
|
||||
//@ts-nocheck
|
||||
import React from 'react';
|
||||
import { useResourceViews, useResourceMeta } from 'hooks/query';
|
||||
import DashboardInsider from '../../../../components/Dashboard/DashboardInsider';
|
||||
|
||||
const ProjectsListContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Projects list data provider.
|
||||
* @returns
|
||||
*/
|
||||
function ProjectsListProvider({ query, tableStateChanged, ...props }) {
|
||||
// Fetch accounts resource views and fields.
|
||||
const { data: projectsViews, isLoading: isViewsLoading } =
|
||||
useResourceViews('projects');
|
||||
|
||||
// provider payload.
|
||||
const provider = {
|
||||
projectsViews,
|
||||
};
|
||||
|
||||
return (
|
||||
<DashboardInsider
|
||||
// loading={isViewsLoading}
|
||||
name={'projects'}
|
||||
>
|
||||
<ProjectsListContext.Provider value={provider} {...props} />
|
||||
</DashboardInsider>
|
||||
);
|
||||
}
|
||||
|
||||
const useProjectsListContext = () => React.useContext(ProjectsListContext);
|
||||
|
||||
export { ProjectsListProvider, useProjectsListContext };
|
||||
@@ -0,0 +1,54 @@
|
||||
//@ts-nocheck
|
||||
import React from 'react';
|
||||
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
||||
|
||||
import { DashboardViewsTabs } from 'components';
|
||||
|
||||
import withProjects from './withProjects';
|
||||
import withProjectsActions from './withProjectsActions';
|
||||
import { useProjectsListContext } from './ProjectsListProvider';
|
||||
|
||||
import { compose, transfromViewsToTabs } from 'utils';
|
||||
|
||||
/**
|
||||
* Projects views tabs.
|
||||
* @returns
|
||||
*/
|
||||
function ProjectsViewTabs({
|
||||
// #withProjects
|
||||
projectsCurrentView,
|
||||
|
||||
// #withProjectsActions
|
||||
setProjectsTableState,
|
||||
}) {
|
||||
// Projects list context.
|
||||
const { projectsViews } = useProjectsListContext();
|
||||
|
||||
// Projects views.
|
||||
const tabs = transfromViewsToTabs(projectsViews);
|
||||
|
||||
// Handle tab change.
|
||||
const handleTabsChange = (viewSlug) => {
|
||||
setProjectsTableState({ viewSlug: viewSlug || null });
|
||||
};
|
||||
|
||||
return (
|
||||
<Navbar className={'navbar--dashboard-views'}>
|
||||
<NavbarGroup align={Alignment.LEFT}>
|
||||
<DashboardViewsTabs
|
||||
currentViewSlug={projectsCurrentView}
|
||||
resourceName={'projects'}
|
||||
tabs={tabs}
|
||||
onChange={handleTabsChange}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</Navbar>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withProjects(({ projectsTableState }) => ({
|
||||
projectsCurrentView: projectsTableState?.viewSlug,
|
||||
})),
|
||||
withProjectsActions,
|
||||
)(ProjectsViewTabs);
|
||||
@@ -0,0 +1,60 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { Menu, MenuDivider, MenuItem, Intent } from '@blueprintjs/core';
|
||||
|
||||
import { Icon } from 'components';
|
||||
import { safeCallback } from 'utils';
|
||||
|
||||
/**
|
||||
* Table actions cell.
|
||||
*/
|
||||
export const ActionsMenu = ({
|
||||
row: { original },
|
||||
payload: { onEdit, onDelete, onViewDetails, onNewTask },
|
||||
}) => (
|
||||
<Menu>
|
||||
<MenuItem
|
||||
icon={<Icon icon="reader-18" />}
|
||||
text={intl.get('view_details')}
|
||||
onClick={safeCallback(onViewDetails, original)}
|
||||
/>
|
||||
<MenuDivider />
|
||||
<MenuItem
|
||||
icon={<Icon icon="pen-18" />}
|
||||
text={intl.get('projects.action.edit_project')}
|
||||
onClick={safeCallback(onEdit, original)}
|
||||
/>
|
||||
<MenuItem
|
||||
icon={<Icon icon="plus" />}
|
||||
text={intl.get('projects.action.new_task')}
|
||||
onClick={safeCallback(onNewTask, original)}
|
||||
/>
|
||||
<MenuDivider />
|
||||
<MenuItem
|
||||
text={intl.get('projects.action.delete_project')}
|
||||
icon={<Icon icon="trash-16" iconSize={16} />}
|
||||
intent={Intent.DANGER}
|
||||
onClick={safeCallback(onDelete, original)}
|
||||
/>
|
||||
</Menu>
|
||||
);
|
||||
|
||||
/**
|
||||
* Retrieve projects list columns columns.
|
||||
*/
|
||||
export const useProjectsListColumns = () => {
|
||||
return React.useMemo(
|
||||
() => [
|
||||
{
|
||||
id: 'name',
|
||||
Header: 'Project Name',
|
||||
accessor: 'name',
|
||||
width: 100,
|
||||
className: 'name',
|
||||
clickable: true,
|
||||
},
|
||||
],
|
||||
[],
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
import { connect } from 'react-redux';
|
||||
import {
|
||||
getProjectsTableStateFactory,
|
||||
isProjectsTableStateChangedFactory,
|
||||
} from '../../../../store/Project/projects.selectors';
|
||||
|
||||
export default (mapState) => {
|
||||
const getProjectsTableState = getProjectsTableStateFactory();
|
||||
const isProjectsTableStateChanged = isProjectsTableStateChangedFactory();
|
||||
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
projectsTableState: getProjectsTableState(state, props),
|
||||
projectsTableStateChanged: isProjectsTableStateChanged(state, props),
|
||||
};
|
||||
return mapState ? mapState(mapped, state, props) : mapped;
|
||||
};
|
||||
return connect(mapStateToProps);
|
||||
};
|
||||
@@ -0,0 +1,13 @@
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import {
|
||||
setProjectsTableState,
|
||||
resetProjectsTableState,
|
||||
} from '../../../../store/Project/projects.actions';
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
setProjectsTableState: (state) => dispatch(setProjectsTableState(state)),
|
||||
resetProjectsTableState: () => dispatch(resetProjectsTableState()),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps);
|
||||
@@ -0,0 +1,14 @@
|
||||
import * as Yup from 'yup';
|
||||
import intl from 'react-intl-universal';
|
||||
import { DATATYPES_LENGTH } from 'common/dataTypes';
|
||||
|
||||
const Schema = Yup.object().shape({
|
||||
taksName: Yup.string()
|
||||
.label(intl.get('task.schema.label.task_name'))
|
||||
.required(),
|
||||
taskHouse: Yup.string().label(intl.get('task.schema.label.task_house')),
|
||||
change: Yup.string().label(intl.get('task.schema.label.charge')).required(),
|
||||
amount: Yup.number().label(intl.get('task.schema.label.amount')),
|
||||
});
|
||||
|
||||
export const CreateTaskFormSchema = Schema;
|
||||
@@ -0,0 +1,63 @@
|
||||
//@ts-nocheck
|
||||
import React from 'react';
|
||||
import { Formik } from 'formik';
|
||||
import { CreateTaskFormSchema } from './TaskForm.schema';
|
||||
import { useTaskFormContext } from './TaskFormProvider';
|
||||
import { AppToaster } from 'components';
|
||||
import TaskFormContent from './TaskFormContent';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
const defaultInitialValues = {
|
||||
taksName: '',
|
||||
taskHouse: '00:00',
|
||||
change: 'Hourly Rate',
|
||||
changeAmount: '100000000',
|
||||
amount: '',
|
||||
};
|
||||
|
||||
/**
|
||||
* Task form.
|
||||
* @returns
|
||||
*/
|
||||
function TaskForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// task form dialog context.
|
||||
const { dialogName } = useTaskFormContext();
|
||||
|
||||
// Initial form values
|
||||
const initialValues = {
|
||||
...defaultInitialValues,
|
||||
};
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
||||
const form = {};
|
||||
|
||||
// Handle request response success.
|
||||
const onSuccess = (response) => {};
|
||||
|
||||
// Handle request response errors.
|
||||
const onError = ({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
setSubmitting(false);
|
||||
};
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
validationSchema={CreateTaskFormSchema}
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
component={TaskFormContent}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(TaskForm);
|
||||
@@ -0,0 +1,17 @@
|
||||
import React from 'react';
|
||||
import { Form } from 'formik';
|
||||
import TaskFormFields from './TaskFormFields';
|
||||
import TaskFormFloatingActions from './TaskFormFloatingActions';
|
||||
|
||||
/**
|
||||
* Task form content.
|
||||
* @returns
|
||||
*/
|
||||
export default function TaskFormContent() {
|
||||
return (
|
||||
<Form>
|
||||
<TaskFormFields />
|
||||
<TaskFormFloatingActions />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import React from 'react';
|
||||
import { TaskFormProvider } from './TaskFormProvider';
|
||||
import TaskForm from './TaskForm';
|
||||
|
||||
/**
|
||||
* Task form dialog content.
|
||||
*/
|
||||
export default function TaskFormDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
task,
|
||||
}) {
|
||||
return (
|
||||
<TaskFormProvider taskId={task} dialogName={dialogName}>
|
||||
<TaskForm />
|
||||
</TaskFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import { Classes, ControlGroup } from '@blueprintjs/core';
|
||||
import {
|
||||
FFormGroup,
|
||||
FInputGroup,
|
||||
Col,
|
||||
Row,
|
||||
FormattedMessage as T,
|
||||
} from 'components';
|
||||
|
||||
/**
|
||||
* Task form fields.
|
||||
* @returns
|
||||
*/
|
||||
function TaskFormFields() {
|
||||
return (
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
{/*------------ Task Name -----------*/}
|
||||
<FFormGroup label={<T id={'task.label.task_name'} />} name={'task_name'}>
|
||||
<FInputGroup name="taskName" />
|
||||
</FFormGroup>
|
||||
{/*------------ Estimated Hours -----------*/}
|
||||
<Row>
|
||||
<Col xs={4}>
|
||||
<FFormGroup
|
||||
label={<T id={'task.label.estimated_hours'} />}
|
||||
name={'taskHouse'}
|
||||
>
|
||||
<FInputGroup name="taskHouse" />
|
||||
</FFormGroup>
|
||||
</Col>
|
||||
{/*------------ Charge -----------*/}
|
||||
<Col xs={8}>
|
||||
<FFormGroup label={<T id={'task.label.charge'} />} name={'Charge'}>
|
||||
<ControlGroup>
|
||||
<FInputGroup name="change" />
|
||||
<FInputGroup name="changeAmount" />
|
||||
</ControlGroup>
|
||||
</FFormGroup>
|
||||
</Col>
|
||||
</Row>
|
||||
{/*------------ Estimated Amount -----------*/}
|
||||
<EstimatedAmountBase>
|
||||
<EstimatedAmountContent>
|
||||
<T id={'task.label.estimated_amount'} />
|
||||
<EstimateAmount>$100000</EstimateAmount>
|
||||
</EstimatedAmountContent>
|
||||
</EstimatedAmountBase>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default TaskFormFields;
|
||||
|
||||
const EstimatedAmountBase = styled.div`
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
font-size: 12px;
|
||||
/* opacity: 0.7; */
|
||||
`;
|
||||
|
||||
const EstimatedAmountContent = styled.span`
|
||||
background-color: #fffdf5;
|
||||
padding: 0.1rem 0;
|
||||
`;
|
||||
|
||||
const EstimateAmount = styled.span`
|
||||
font-size: 13px;
|
||||
font-weight: 700;
|
||||
margin-left: 10px;
|
||||
`;
|
||||
@@ -0,0 +1,48 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import { useTaskFormContext } from './TaskFormProvider';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Task form floating actions.
|
||||
* @returns
|
||||
*/
|
||||
function TaskFormFloatingActions({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// Formik context.
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
// Task form dialog context.
|
||||
const { dialogName } = useTaskFormContext();
|
||||
|
||||
// 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: '75px' }}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
loading={isSubmitting}
|
||||
style={{ minWidth: '75px' }}
|
||||
type="submit"
|
||||
>
|
||||
{<T id={'save'} />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(TaskFormFloatingActions);
|
||||
@@ -0,0 +1,31 @@
|
||||
//@ts-nocheck
|
||||
import React from 'react';
|
||||
import { DialogContent } from 'components';
|
||||
|
||||
const TaskFormContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Task form provider.
|
||||
* @returns
|
||||
*/
|
||||
function TaskFormProvider({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
taskId,
|
||||
...props
|
||||
}) {
|
||||
// State provider.
|
||||
const provider = {
|
||||
dialogName,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent>
|
||||
<TaskFormContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useTaskFormContext = () => React.useContext(TaskFormContext);
|
||||
|
||||
export { TaskFormProvider, useTaskFormContext };
|
||||
34
src/containers/Projects/containers/TaskFormDialog/index.tsx
Normal file
34
src/containers/Projects/containers/TaskFormDialog/index.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import React from 'react';
|
||||
import styled from 'styled-components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Dialog, DialogSuspense, FormattedMessage as T } from 'components';
|
||||
import withDialogRedux from 'components/DialogReduxConnect';
|
||||
import { compose } from 'utils';
|
||||
|
||||
const TaskFormDialogContent = React.lazy(
|
||||
() => import('./TaskFormDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Task form dialog.
|
||||
* @returns
|
||||
*/
|
||||
function TaskFormDialog({ dialogName, payload: { taskId = null }, isOpen }) {
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={intl.get('task.label.new_task')}
|
||||
isOpen={isOpen}
|
||||
autoFocus={true}
|
||||
canEscapeKeyClose={true}
|
||||
style={{ width: '500px' }}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<TaskFormDialogContent dialogName={dialogName} task={taskId} />
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogRedux())(TaskFormDialog);
|
||||
|
||||
const TaskFormDialogRoot = styled(Dialog)``;
|
||||
0
src/containers/Projects/index.ts
Normal file
0
src/containers/Projects/index.ts
Normal file
@@ -22,6 +22,7 @@ export default (mapState) => {
|
||||
creditNoteSettings: state.settings.data.creditNote,
|
||||
vendorsCreditNoteSetting: state.settings.data.vendorCredit,
|
||||
warehouseTransferSettings: state.settings.data.warehouseTransfers,
|
||||
projectSettings:state.settings.data.projects
|
||||
};
|
||||
return mapState ? mapState(mapped, state, props) : mapped;
|
||||
};
|
||||
|
||||
@@ -2044,5 +2044,30 @@
|
||||
"expense.entries.remove_row": "Remove line",
|
||||
"warehouse_transfer.entries.remove_row": "Remove line",
|
||||
"item.details.inactive": "Inactive",
|
||||
"bill.validation.due_date": "{path} field must be later than {min}"
|
||||
"bill.validation.due_date": "{path} field must be later than {min}",
|
||||
"sidebar.projects": "Projects",
|
||||
"projects.action.edit_project": "Edit Project",
|
||||
"projects.action.new_task": "New Task",
|
||||
"projects.action.delete_project": "Delete Project",
|
||||
"projects.label.new_project": "New Project",
|
||||
"projects.label.contact": "Contact",
|
||||
"projects.label.project_name": "Project Name",
|
||||
"projects.label.deadline": "Deadline",
|
||||
"projects.label.calculator_expenses": "Calculator from tasks & estimated expenses",
|
||||
"projects.label.cost_estimate": "Cost Estimate",
|
||||
"projects.label.create": "Create",
|
||||
"task.label.new_task": "New Task",
|
||||
"task.label.task_name": "Task Name",
|
||||
"task.label.estimated_hours": "Task Name",
|
||||
"task.label.charge": "Charge",
|
||||
"task.label.estimated_amount": "Estimated Amount",
|
||||
"project.schema.label.contact": "Contact",
|
||||
"project.schema.label.project_name": "Project name",
|
||||
"project.schema.label.deadline": "Deadline",
|
||||
"project.schema.label.project_state": "Project state",
|
||||
"project.schema.label.project_cost": "Project cost",
|
||||
"task.schema.label.task_name": "Task name",
|
||||
"task.schema.label.task_house": "Task house",
|
||||
"task.schema.label.charge": "Charge",
|
||||
"task.schema.label.amount": "Amount"
|
||||
}
|
||||
@@ -969,6 +969,13 @@ export const getDashboardRoutes = () => [
|
||||
),
|
||||
pageTitle: intl.get('sidebar.transactions_locaking'),
|
||||
},
|
||||
{
|
||||
path: '/projects',
|
||||
component: lazy(() =>
|
||||
import('../containers/Projects/containers/ProjectsLanding/ProjectsList'),
|
||||
),
|
||||
pageTitle: intl.get('sidebar.projects'),
|
||||
},
|
||||
// Homepage
|
||||
{
|
||||
path: `/`,
|
||||
|
||||
14
src/store/Project/projects.actions.ts
Normal file
14
src/store/Project/projects.actions.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import t from 'store/types';
|
||||
|
||||
export const setProjectsTableState = (queries) => {
|
||||
return {
|
||||
type: t.PROJECTS_TABLE_STATE_SET,
|
||||
payload: { queries },
|
||||
};
|
||||
};
|
||||
|
||||
export const resetProjectsTableState = () => {
|
||||
return {
|
||||
type: t.PROJECTS_TABLE_STATE_RESET,
|
||||
};
|
||||
};
|
||||
33
src/store/Project/projects.reducer.ts
Normal file
33
src/store/Project/projects.reducer.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { persistReducer, purgeStoredState } from 'redux-persist';
|
||||
import storage from 'redux-persist/lib/storage';
|
||||
import { createTableStateReducers } from 'store/tableState.reducer';
|
||||
import t from 'store/types';
|
||||
|
||||
export const defaultTableQuery = {
|
||||
pageSize: 20,
|
||||
pageIndex: 0,
|
||||
filterRoles: [],
|
||||
viewSlug: null,
|
||||
};
|
||||
|
||||
const initialState = {
|
||||
tableState: defaultTableQuery,
|
||||
};
|
||||
|
||||
const STORAGE_KEY = 'bigcapital:projects';
|
||||
|
||||
const CONFIG = {
|
||||
key: STORAGE_KEY,
|
||||
whitelist: [],
|
||||
storage,
|
||||
};
|
||||
const reducerInstance = createReducer(initialState, {
|
||||
...createTableStateReducers('PROJECTS', defaultTableQuery),
|
||||
|
||||
[t.RESET]: () => {
|
||||
purgeStoredState(CONFIG);
|
||||
},
|
||||
});
|
||||
|
||||
export default persistReducer(CONFIG, reducerInstance);
|
||||
24
src/store/Project/projects.selectors.ts
Normal file
24
src/store/Project/projects.selectors.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { isEqual } from 'lodash';
|
||||
import { createDeepEqualSelector } from 'utils';
|
||||
import { paginationLocationQuery } from 'store/selectors';
|
||||
import { defaultTableQuery } from './projects.reducer';
|
||||
|
||||
const projectsTableState = (state) => state.projects.tableState;
|
||||
|
||||
// Retrieve projects table query.
|
||||
export const getProjectsTableStateFactory = () =>
|
||||
createDeepEqualSelector(
|
||||
paginationLocationQuery,
|
||||
projectsTableState,
|
||||
(locationQuery, tableState) => {
|
||||
return {
|
||||
...locationQuery,
|
||||
...tableState,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
export const isProjectsTableStateChangedFactory = () =>
|
||||
createDeepEqualSelector(projectsTableState, (tableState) => {
|
||||
return !isEqual(tableState, defaultTableQuery);
|
||||
});
|
||||
4
src/store/Project/projects.type.ts
Normal file
4
src/store/Project/projects.type.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export default {
|
||||
PROJECTS_TABLE_STATE_SET: 'PROJECTS/TABLE_STATE_SET',
|
||||
PROJECTS_TABLE_STATE_RESET: 'PROJECTS/TABLE_STATE_RESET',
|
||||
};
|
||||
@@ -35,6 +35,7 @@ import plans from './plans/plans.reducer';
|
||||
import creditNotes from './CreditNote/creditNote.reducer';
|
||||
import vendorCredit from './VendorCredit/VendorCredit.reducer';
|
||||
import warehouseTransfers from './WarehouseTransfer/warehouseTransfer.reducer';
|
||||
import projects from './Project/projects.reducer';
|
||||
|
||||
const appReducer = combineReducers({
|
||||
authentication,
|
||||
@@ -70,6 +71,7 @@ const appReducer = combineReducers({
|
||||
creditNotes,
|
||||
vendorCredit,
|
||||
warehouseTransfers,
|
||||
projects,
|
||||
});
|
||||
|
||||
// Reset the state of a redux store
|
||||
|
||||
@@ -61,6 +61,9 @@ const initialState = {
|
||||
warehouseTransfer: {
|
||||
tableSize: 'medium',
|
||||
},
|
||||
projects: {
|
||||
tableSize: 'medium',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import inventoryAdjustments from './inventoryAdjustments/inventoryAdjustment.typ
|
||||
import creditNote from './CreditNote/creditNote.type';
|
||||
import vendorCredit from './VendorCredit/vendorCredit.type';
|
||||
import WarehouseTransfer from './WarehouseTransfer/warehouseTransfer.type';
|
||||
import projects from './Project/projects.type'
|
||||
import plans from './plans/plans.types';
|
||||
|
||||
export default {
|
||||
@@ -68,4 +69,5 @@ export default {
|
||||
...creditNote,
|
||||
...vendorCredit,
|
||||
...WarehouseTransfer,
|
||||
...projects
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user