mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 07:40:32 +00:00
feat: add project form dialog.
This commit is contained in:
@@ -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;
|
||||
// }
|
||||
// }
|
||||
// `;
|
||||
Reference in New Issue
Block a user