mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
feat: add project form dialog.
This commit is contained in:
@@ -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 ProjectDialog from '../containers/Dialogs/ProjectDialog';
|
||||
import TaskDialog from '../containers/Dialogs/TaskDialog';
|
||||
|
||||
/**
|
||||
* Dialogs container.
|
||||
@@ -90,6 +92,8 @@ export default function DialogsContainer() {
|
||||
<WarehouseActivateDialog dialogName={'warehouse-activate'} />
|
||||
<CustomerOpeningBalanceDialog dialogName={'customer-opening-balance'} />
|
||||
<VendorOpeningBalanceDialog dialogName={'vendor-opening-balance'} />
|
||||
<ProjectDialog dialogName={'project-form'} />
|
||||
<TaskDialog dialogName={'task-form'} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
|
||||
import 'style/pages/Projects/ProjectFormDialog.scss';
|
||||
|
||||
import { ProjectFormProvider } from './ProjectFormProvider';
|
||||
import ProjectForm from './ProjectForm';
|
||||
|
||||
/**
|
||||
* Project dialog content.
|
||||
* @returns
|
||||
*/
|
||||
export default function ProjectDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
project,
|
||||
}) {
|
||||
return (
|
||||
<ProjectFormProvider projectId={project} dialogName={dialogName}>
|
||||
<ProjectForm />
|
||||
</ProjectFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
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(),
|
||||
project_name: Yup.string(),
|
||||
project_deadline: Yup.date(),
|
||||
project_state: Yup.boolean(),
|
||||
project_cost: Yup.number(),
|
||||
});
|
||||
|
||||
export const CreateProjectFormSchema = Schema;
|
||||
@@ -0,0 +1,71 @@
|
||||
// @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 withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
|
||||
import ProjectFormContent from './ProjectFormContent';
|
||||
import { CreateProjectFormSchema } from './ProjectForm.schema';
|
||||
import { useProjectFormContext } from './ProjectFormProvider';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
const defaultInitialValues = {
|
||||
contact:'',
|
||||
project_name:'',
|
||||
project_deadline: moment(new Date()).format('YYYY-MM-DD'),
|
||||
project_state: false,
|
||||
project_cost:''
|
||||
};
|
||||
|
||||
/**
|
||||
* 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,99 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { Classes, Position, FormGroup, ControlGroup } from '@blueprintjs/core';
|
||||
import { FastField } from 'formik';
|
||||
import { DateInput } from '@blueprintjs/datetime';
|
||||
import { CLASSES } from 'common/classes';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
FFormGroup,
|
||||
FInputGroup,
|
||||
FCheckbox,
|
||||
FMoneyInputGroup,
|
||||
InputPrependText,
|
||||
FormattedMessage as T,
|
||||
CustomerSelectField,
|
||||
FCustomerSelectField,
|
||||
} from 'components';
|
||||
import {
|
||||
inputIntent,
|
||||
momentFormatter,
|
||||
tansformDateValue,
|
||||
handleDateChange,
|
||||
} from 'utils';
|
||||
|
||||
/**
|
||||
* Project form fields.
|
||||
* @returns
|
||||
*/
|
||||
function ProjectFormFields() {
|
||||
return (
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
{/*------------ Contact -----------*/}
|
||||
<FastField name={'contact'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={'Contact'}
|
||||
className={classNames('form-group--select-list', Classes.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
>
|
||||
<CustomerSelectField
|
||||
contacts={[]}
|
||||
selectedContactId={value}
|
||||
defaultSelectText={'Select Contact Account'}
|
||||
onContactSelected={(customer) => {
|
||||
form.setFieldValue('contact', customer.id);
|
||||
}}
|
||||
allowCreate={true}
|
||||
popoverFill={true}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/*------------ Project Name -----------*/}
|
||||
<FFormGroup label={'Project Name'} name={'project_name'}>
|
||||
<FInputGroup name="project_name" />
|
||||
</FFormGroup>
|
||||
{/*------------ DeadLine -----------*/}
|
||||
<FFormGroup
|
||||
label={'DeadLine'}
|
||||
name={'project_deadline'}
|
||||
className={classNames(CLASSES.FILL, 'form-group--date')}
|
||||
>
|
||||
<DateInput
|
||||
{...momentFormatter('YYYY/MM/DD')}
|
||||
// onChange={handleDateChange((formattedDate) => {
|
||||
// })}
|
||||
// value={tansformDateValue(value)}
|
||||
popoverProps={{
|
||||
position: Position.BOTTOM,
|
||||
minimal: true,
|
||||
}}
|
||||
/>
|
||||
</FFormGroup>
|
||||
|
||||
{/*------------ CheckBox -----------*/}
|
||||
<FFormGroup name={'project_state'}>
|
||||
<FCheckbox
|
||||
name="project_state"
|
||||
label={'Calculato from tasks & estimated expenses'}
|
||||
/>
|
||||
</FFormGroup>
|
||||
{/*------------ Cost Estimate -----------*/}
|
||||
<FFormGroup name={'project_cost'} label={' Cost Estimate'}>
|
||||
<ControlGroup>
|
||||
<InputPrependText text={'USD'} />
|
||||
<FMoneyInputGroup
|
||||
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"
|
||||
>
|
||||
Create
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(ProjectFormFloatingActions);
|
||||
@@ -0,0 +1,33 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
|
||||
import { DialogContent } from 'components';
|
||||
|
||||
const ProjectFormContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Project form provider.
|
||||
* @returns
|
||||
*/
|
||||
|
||||
function ProjectFormProvider({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
projectId,
|
||||
...props
|
||||
}) {
|
||||
// State provider.
|
||||
const provider = {};
|
||||
|
||||
return (
|
||||
<DialogContent
|
||||
// isLoading={}
|
||||
>
|
||||
<ProjectFormContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useProjectFormContext = () => React.useContext(ProjectFormContext);
|
||||
|
||||
export { ProjectFormProvider, useProjectFormContext };
|
||||
51
src/containers/Dialogs/ProjectDialog/index.tsx
Normal file
51
src/containers/Dialogs/ProjectDialog/index.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
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('./containers/ProjectDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Project dialog.
|
||||
* @returns
|
||||
*/
|
||||
function ProjectDialog({ dialogName, payload: { projectId = null }, isOpen }) {
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={'New Project'}
|
||||
isOpen={isOpen}
|
||||
autoFocus={true}
|
||||
canEscapeKeyClose={true}
|
||||
className={'dialog--project-form'}
|
||||
style={{ width: '400px' }}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<ProjectDialogContent dialogName={dialogName} project={projectId} />
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogRedux())(ProjectDialog);
|
||||
|
||||
// const ProjectDialogRoot = 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;
|
||||
// }
|
||||
// }
|
||||
// `;
|
||||
@@ -969,6 +969,13 @@ export const getDashboardRoutes = () => [
|
||||
),
|
||||
pageTitle: intl.get('sidebar.transactions_locaking'),
|
||||
},
|
||||
{
|
||||
path: '/projects',
|
||||
component: lazy(() =>
|
||||
import('../containers/Projects/containers/ProjectsList'),
|
||||
),
|
||||
pageTitle: '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
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
20
src/style/pages/Projects/ProjectFormDialog.scss
Normal file
20
src/style/pages/Projects/ProjectFormDialog.scss
Normal file
@@ -0,0 +1,20 @@
|
||||
.dialog--project-form {
|
||||
width: 650px;
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user