mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat(warehouse): add warehouse.
This commit is contained in:
46
src/containers/Dialogs/WarehouseFormDialog/WarehouseForm.js
Normal file
46
src/containers/Dialogs/WarehouseFormDialog/WarehouseForm.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import React from 'react';
|
||||
import { Formik } from 'formik';
|
||||
|
||||
import { CreateWarehouseFormSchema } from './WarehouseForm.schema';
|
||||
import { useWarehouseFormContext } from './WarehouseFormProvider';
|
||||
import WarehouseFormContent from './WarehouseFormContent';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
const defaultInitialValues = {
|
||||
warehouse_name: '',
|
||||
warehouse_address_1: '',
|
||||
warehouse_address_2: '',
|
||||
warehouse_address_city: '',
|
||||
warehouse_address_country: '',
|
||||
phone_number: '',
|
||||
};
|
||||
|
||||
/**
|
||||
* Warehouse form.
|
||||
* @returns
|
||||
*/
|
||||
function WarehouseForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// Initial form values.
|
||||
const initialValues = {
|
||||
...defaultInitialValues,
|
||||
};
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
validationSchema={CreateWarehouseFormSchema}
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
component={WarehouseFormContent}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(WarehouseForm);
|
||||
@@ -0,0 +1,13 @@
|
||||
import * as Yup from 'yup';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
const Schema = Yup.object().shape({
|
||||
warehouse_name: Yup.string().required().label(intl.get('warehouse_name')),
|
||||
warehouse_address_1: Yup.string().trim(),
|
||||
warehouse_address_2: Yup.string().trim(),
|
||||
warehouse_address_city: Yup.string().trim(),
|
||||
warehouse_address_country: Yup.string().trim(),
|
||||
phone_number: Yup.number(),
|
||||
});
|
||||
|
||||
export const CreateWarehouseFormSchema = Schema;
|
||||
@@ -0,0 +1,18 @@
|
||||
import React from 'react';
|
||||
import { Form } from 'formik';
|
||||
|
||||
import WarehouseFormFields from './WarehouseFormFields';
|
||||
import WarehouseFormFloatingActions from './WarehouseFormFloatingActions';
|
||||
|
||||
/**
|
||||
* Warehouse form content.
|
||||
* @returns
|
||||
*/
|
||||
export default function WarehouseFormContent() {
|
||||
return (
|
||||
<Form>
|
||||
<WarehouseFormFields />
|
||||
<WarehouseFormFloatingActions />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import React from 'react';
|
||||
|
||||
import '../../../style/pages/Warehouses/warehouseFormDialog.scss';
|
||||
import { WarehouseFormProvider } from './WarehouseFormProvider';
|
||||
import WarehouseForm from './WarehouseForm';
|
||||
|
||||
/**
|
||||
* Warehouse form dialog content.
|
||||
*/
|
||||
export default function WarehouseFormDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
}) {
|
||||
return (
|
||||
<WarehouseFormProvider dialogName={dialogName}>
|
||||
<WarehouseForm />
|
||||
</WarehouseFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
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 { useWarehouseFormContext } from './WarehouseFormProvider';
|
||||
|
||||
/**
|
||||
* Warehouse form fields.
|
||||
* @returns
|
||||
*/
|
||||
export default function WarehouseFormFields() {
|
||||
return (
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
{/*------------ Warehouse Name -----------*/}
|
||||
<FastField name={'warehouse_name'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'warehouse.dialog.label.warehouse_name'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="warehouse_name" />}
|
||||
className={'form-group--warehouse_name'}
|
||||
>
|
||||
<InputGroup intent={inputIntent({ error, touched })} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/*------------ Warehouse Address -----------*/}
|
||||
<FastField name={'warehouse_address_1'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={intl.get('warehouse.dialog.label.warehouse_address')}
|
||||
intent={inputIntent({ error, touched })}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="warehouse_address_1" />}
|
||||
className={'form-group--warehouse_address_1'}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
placeholder={intl.get(
|
||||
'warehouse.dialog.label.warehouse_address_1',
|
||||
)}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<WarehouseAddressWrap>
|
||||
<FastField name={'warehouse_address_2'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="warehouse_address_2" />}
|
||||
className={'form-group--warehouse_address_2'}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
placeholder={intl.get(
|
||||
'warehouse.dialog.label.warehouse_address_2',
|
||||
)}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/*------------ Warehouse Address City & Country-----------*/}
|
||||
<FormGroup
|
||||
inline={true}
|
||||
className={'form-group--warehouse_address_city'}
|
||||
helperText={<ErrorMessage name="warehouse_address_city" />}
|
||||
>
|
||||
<ControlGroup>
|
||||
<FastField name={'warehouse_address_city'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
placeholder={intl.get('warehouse.dialog.label.city')}
|
||||
{...field}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
<FastField name={'warehouse_address_country'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
placeholder={intl.get('warehouse.dialog.label.country')}
|
||||
{...field}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
</ControlGroup>
|
||||
</FormGroup>
|
||||
</WarehouseAddressWrap>
|
||||
{/*------------ Phone Number -----------*/}
|
||||
<FastField name={'phone_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={intl.get('warehouse.dialog.label.phone_number')}
|
||||
intent={inputIntent({ error, touched })}
|
||||
inline={true}
|
||||
helperText={<ErrorMessage name="phone_number" />}
|
||||
className={'form-group--phone_number'}
|
||||
>
|
||||
<InputGroup intent={inputIntent({ error, touched })} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const WarehouseAddressWrap = styled.div`
|
||||
padding-left: 150px;
|
||||
`;
|
||||
@@ -0,0 +1,48 @@
|
||||
import React from 'react';
|
||||
|
||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
|
||||
import { useWarehouseFormContext } from './WarehouseFormProvider';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Warehouse form floating actions.
|
||||
* @returns
|
||||
*/
|
||||
function WarehouseFormFloatingActions({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// Formik context.
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
const { dialogName } = useWarehouseFormContext();
|
||||
|
||||
// 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)(WarehouseFormFloatingActions);
|
||||
@@ -0,0 +1,27 @@
|
||||
import React from 'react';
|
||||
import { DialogContent } from 'components';
|
||||
// import {} from 'hooks/query';
|
||||
|
||||
const WarehouseFormContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Warehouse form provider.
|
||||
*/
|
||||
function WarehouseFormProvider({ dialogName, ...props }) {
|
||||
// State provider.
|
||||
const provider = {
|
||||
dialogName,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent
|
||||
// isLoading={}
|
||||
>
|
||||
<WarehouseFormContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useWarehouseFormContext = () => React.useContext(WarehouseFormContext);
|
||||
|
||||
export { WarehouseFormProvider, useWarehouseFormContext };
|
||||
31
src/containers/Dialogs/WarehouseFormDialog/index.js
Normal file
31
src/containers/Dialogs/WarehouseFormDialog/index.js
Normal file
@@ -0,0 +1,31 @@
|
||||
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 WarehouseFormDialogContent = React.lazy(() =>
|
||||
import('./WarehouseFormDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Warehouse form form dialog.
|
||||
*/
|
||||
function WarehouseFormDialog({ dialogName, isOpen }) {
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={<T id={'warehouse.dialog.label'} />}
|
||||
isOpen={isOpen}
|
||||
canEscapeJeyClose={true}
|
||||
autoFocus={true}
|
||||
className={'dialog--warehouse-form'}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<WarehouseFormDialogContent dialogName={dialogName} />
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogRedux())(WarehouseFormDialog);
|
||||
Reference in New Issue
Block a user