mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
re-structure to monorepo.
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { LockingTransactionsFormProvider } from './LockingTransactionsFormProvider';
|
||||
import LockingTransactionsForm from './LockingTransactionsForm';
|
||||
|
||||
/**
|
||||
* Locking transactions dialog content.
|
||||
*/
|
||||
export default function LockingTransactionsDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
moduleName,
|
||||
isEnabled,
|
||||
}) {
|
||||
|
||||
return (
|
||||
<LockingTransactionsFormProvider
|
||||
isEnabled={isEnabled}
|
||||
moduleName={moduleName}
|
||||
dialogName={dialogName}
|
||||
>
|
||||
<LockingTransactionsForm />
|
||||
</LockingTransactionsFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// @ts-nocheck
|
||||
import * as Yup from 'yup';
|
||||
import intl from 'react-intl-universal';
|
||||
import { DATATYPES_LENGTH } from '@/constants/dataTypes';
|
||||
|
||||
const Schema = Yup.object().shape({
|
||||
lock_to_date: Yup.date().required().label(intl.get('date')),
|
||||
module: Yup.string().required(),
|
||||
reason: Yup.string()
|
||||
.required()
|
||||
.min(3)
|
||||
.max(DATATYPES_LENGTH.TEXT)
|
||||
.label(intl.get('reason')),
|
||||
});
|
||||
export const CreateLockingTransactionsFormSchema = Schema;
|
||||
@@ -0,0 +1,90 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import moment from 'moment';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { Formik } from 'formik';
|
||||
|
||||
import '@/style/pages/TransactionsLocking/TransactionsLockingDialog.scss';
|
||||
|
||||
import { AppToaster } from '@/components';
|
||||
import { CreateLockingTransactionsFormSchema } from './LockingTransactionsForm.schema';
|
||||
|
||||
import { useLockingTransactionsContext } from './LockingTransactionsFormProvider';
|
||||
import LockingTransactionsFormContent from './LockingTransactionsFormContent';
|
||||
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { compose, transformToForm } from '@/utils';
|
||||
|
||||
const defaultInitialValues = {
|
||||
module: '',
|
||||
lock_to_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
reason: '',
|
||||
};
|
||||
|
||||
/**
|
||||
* Locking Transactions Form.
|
||||
*/
|
||||
function LockingTransactionsForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
const {
|
||||
dialogName,
|
||||
moduleName,
|
||||
transactionLocking,
|
||||
isEnabled,
|
||||
createLockingTransactionMutate,
|
||||
} = useLockingTransactionsContext();
|
||||
|
||||
// Initial form values.
|
||||
const initialValues = React.useMemo(
|
||||
() => ({
|
||||
...(isEnabled
|
||||
? {
|
||||
...transformToForm(transactionLocking, defaultInitialValues),
|
||||
module: moduleName,
|
||||
}
|
||||
: {
|
||||
...defaultInitialValues,
|
||||
module: moduleName,
|
||||
}),
|
||||
}),
|
||||
[isEnabled],
|
||||
);
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
||||
setSubmitting(true);
|
||||
|
||||
// Handle request response success.
|
||||
const onSuccess = (response) => {
|
||||
AppToaster.show({
|
||||
message: intl.get('locking_transactions.dialog.success_message'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
// Handle request response errors.
|
||||
const onError = ({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
createLockingTransactionMutate(values).then(onSuccess).catch(onError);
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
validationSchema={CreateLockingTransactionsFormSchema}
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
component={LockingTransactionsFormContent}
|
||||
/>
|
||||
);
|
||||
}
|
||||
export default compose(withDialogActions)(LockingTransactionsForm);
|
||||
@@ -0,0 +1,18 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Form } from 'formik';
|
||||
|
||||
import LockingTransactionsFormFields from './LockingTransactionsFormFields';
|
||||
import LockingTransactionsFormFloatingActions from './LockingTransactionsFormFloatingActions';
|
||||
|
||||
/**
|
||||
* locking Transactions form content.
|
||||
*/
|
||||
export default function LockingTransactionsFormContent() {
|
||||
return (
|
||||
<Form>
|
||||
<LockingTransactionsFormFields />
|
||||
<LockingTransactionsFormFloatingActions />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { FastField, ErrorMessage } from 'formik';
|
||||
import { Classes, FormGroup, TextArea, Position } from '@blueprintjs/core';
|
||||
import { DateInput } from '@blueprintjs/datetime';
|
||||
import classNames from 'classnames';
|
||||
import { CLASSES } from '@/constants/classes';
|
||||
import { FieldRequiredHint, FormattedMessage as T } from '@/components';
|
||||
import { useAutofocus } from '@/hooks';
|
||||
import {
|
||||
inputIntent,
|
||||
momentFormatter,
|
||||
tansformDateValue,
|
||||
handleDateChange,
|
||||
} from '@/utils';
|
||||
|
||||
/**
|
||||
* locking Transactions form fields.
|
||||
*/
|
||||
export default function LockingTransactionsFormFields() {
|
||||
const reasonFieldRef = useAutofocus();
|
||||
|
||||
return (
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
{/*------------ Locking Date -----------*/}
|
||||
<FastField name={'lock_to_date'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'locking_transactions.dialog.locking_date'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="lock_to_date" />}
|
||||
minimal={true}
|
||||
className={classNames(CLASSES.FILL, 'form-group--date')}
|
||||
>
|
||||
<DateInput
|
||||
{...momentFormatter('YYYY/MM/DD')}
|
||||
onChange={handleDateChange((formattedDate) => {
|
||||
form.setFieldValue('lock_to_date', formattedDate);
|
||||
})}
|
||||
value={tansformDateValue(value)}
|
||||
popoverProps={{
|
||||
position: Position.BOTTOM,
|
||||
minimal: true,
|
||||
}}
|
||||
intent={inputIntent({ error, touched })}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
{/*------------ Locking Reason -----------*/}
|
||||
<FastField name={'reason'}>
|
||||
{({ field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'locking_transactions.dialog.reason'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
className={'form-group--reason'}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name={'reason'} />}
|
||||
>
|
||||
<TextArea
|
||||
growVertically={true}
|
||||
large={true}
|
||||
intent={inputIntent({ error, touched })}
|
||||
inputRef={(ref) => (reasonFieldRef.current = ref)}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { FormattedMessage as T } from '@/components';
|
||||
|
||||
import { useLockingTransactionsContext } from './LockingTransactionsFormProvider';
|
||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
/**
|
||||
* locking Transactions floating actions.
|
||||
*/
|
||||
function LockingTransactionsFormFloatingActions({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// Formik context.
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
const { dialogName } = useLockingTransactionsContext();
|
||||
|
||||
// Handle cancel button click.
|
||||
const handleCancelBtnClick = (event) => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
style={{ minWidth: '95px' }}
|
||||
type="submit"
|
||||
loading={isSubmitting}
|
||||
>
|
||||
{<T id={'save'} />}
|
||||
</Button>
|
||||
<Button onClick={handleCancelBtnClick} style={{ minWidth: '85px' }}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(
|
||||
LockingTransactionsFormFloatingActions,
|
||||
);
|
||||
@@ -0,0 +1,47 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { DialogContent } from '@/components';
|
||||
import {
|
||||
useCreateLockingTransactoin,
|
||||
useEditTransactionsLocking,
|
||||
} from '@/hooks/query';
|
||||
|
||||
const LockingTransactionsContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Locking transactions form provider.
|
||||
*/
|
||||
function LockingTransactionsFormProvider({
|
||||
moduleName,
|
||||
isEnabled,
|
||||
dialogName,
|
||||
...props
|
||||
}) {
|
||||
// Create locking transactions mutations.
|
||||
const { mutateAsync: createLockingTransactionMutate } =
|
||||
useCreateLockingTransactoin();
|
||||
|
||||
const { data: transactionLocking, isLoading: isTransactionsLockingLoading } =
|
||||
useEditTransactionsLocking(moduleName, {
|
||||
enabled: !!isEnabled,
|
||||
});
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
dialogName,
|
||||
moduleName,
|
||||
createLockingTransactionMutate,
|
||||
transactionLocking,
|
||||
isEnabled,
|
||||
};
|
||||
return (
|
||||
<DialogContent isLoading={isTransactionsLockingLoading}>
|
||||
<LockingTransactionsContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useLockingTransactionsContext = () =>
|
||||
React.useContext(LockingTransactionsContext);
|
||||
|
||||
export { LockingTransactionsFormProvider, useLockingTransactionsContext };
|
||||
@@ -0,0 +1,39 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import { Dialog, DialogSuspense, FormattedMessage as T } from '@/components';
|
||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||
import { compose } from '@/utils';
|
||||
|
||||
const LockingTransactionsDialogContent = React.lazy(() =>
|
||||
import('./LockingTransactionsDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Locking Transactions dialog
|
||||
*/
|
||||
function LockingTransactionsDialog({
|
||||
dialogName,
|
||||
payload: { module, isEnabled },
|
||||
isOpen,
|
||||
}) {
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
autoFocus={true}
|
||||
title={<T id={'locking_transactions.dialog.label'} />}
|
||||
canEscapeKeyClose={true}
|
||||
isOpen={isOpen}
|
||||
className={'dialog--transaction--locking'}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<LockingTransactionsDialogContent
|
||||
moduleName={module}
|
||||
dialogName={dialogName}
|
||||
isEnabled={isEnabled}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogRedux())(LockingTransactionsDialog);
|
||||
Reference in New Issue
Block a user