chore(webapp): move components in separate files

This commit is contained in:
Ahmed Bouhuolia
2023-06-22 01:30:05 +02:00
parent 532ad61500
commit 1f3adf4879
12 changed files with 596 additions and 553 deletions

View File

@@ -0,0 +1,92 @@
// @ts-nocheck
import React from 'react';
import * as R from 'ramda';
import { Position, ControlGroup } from '@blueprintjs/core';
import { useFormikContext } from 'formik';
import {
FFormGroup,
FInputGroup,
FormattedMessage as T,
Icon,
InputPrependButton,
} from '@/components';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import withSettings from '@/containers/Settings/withSettings';
/**
* Estimate number field of estimate form.
*/
export const EstimateFormEstimateNumberField = R.compose(
withDialogActions,
withSettings(({ estimatesSettings }) => ({
estimateNextNumber: estimatesSettings?.nextNumber,
estimateNumberPrefix: estimatesSettings?.numberPrefix,
estimateAutoIncrement: estimatesSettings?.autoIncrement,
})),
)(
({
// #withDialogActions
openDialog,
// #withSettings
estimateAutoIncrement,
}) => {
const { values, setFieldValue } = useFormikContext();
const handleEstimateNumberBtnClick = () => {
openDialog('estimate-number-form', {});
};
// Handle estimate no. field blur.
const handleEstimateNoBlur = (event) => {
const newValue = event.target.value;
// Show the confirmation dialog if the value has changed and auto-increment
// mode is enabled.
if (values.estimate_number !== newValue && estimateAutoIncrement) {
openDialog('estimate-number-form', {
initialFormValues: {
onceManualNumber: newValue,
incrementMode: 'manual-transaction',
},
});
}
// Setting the estimate number to the form will be manually in case
// auto-increment is disable.
if (!estimateAutoIncrement) {
setFieldValue('estimate_number', newValue);
setFieldValue('estimate_number_manually', newValue);
}
};
return (
<FFormGroup
name={'estimate_number'}
label={<T id={'estimate'} />}
inline={true}
>
<ControlGroup fill={true}>
<FInputGroup
name={'estimate_number'}
minimal={true}
asyncControl={true}
onBlur={handleEstimateNoBlur}
onChange={() => {}}
/>
<InputPrependButton
buttonProps={{
onClick: handleEstimateNumberBtnClick,
icon: <Icon icon={'settings-18'} />,
}}
tooltip={true}
tooltipProps={{
content: <T id={'setting_your_auto_generated_estimate_number'} />,
position: Position.BOTTOM_LEFT,
}}
/>
</ControlGroup>
</FFormGroup>
);
},
);
EstimateFormEstimateNumberField.displayName = 'EstimateFormEstimateNumberField';

View File

@@ -1,27 +1,18 @@
// @ts-nocheck
import React from 'react';
import * as R from 'ramda';
import styled from 'styled-components';
import classNames from 'classnames';
import {
FormGroup,
InputGroup,
Position,
Classes,
ControlGroup,
} from '@blueprintjs/core';
import { FormGroup, InputGroup, Position, Classes } from '@blueprintjs/core';
import { DateInput } from '@blueprintjs/datetime';
import { FastField, ErrorMessage, useFormikContext } from 'formik';
import { FastField, ErrorMessage } from 'formik';
import {
FeatureCan,
FFormGroup,
FInputGroup,
FormattedMessage as T,
CustomerSelectField,
FieldRequiredHint,
Icon,
InputPrependButton,
CustomerDrawerLink,
} from '@/components';
import {
@@ -34,92 +25,14 @@ import { customersFieldShouldUpdate } from './utils';
import { CLASSES } from '@/constants/classes';
import { Features } from '@/constants';
import withDialogActions from '@/containers/Dialog/withDialogActions';
import withSettings from '@/containers/Settings/withSettings';
import { ProjectsSelect } from '@/containers/Projects/components';
import {
EstimateExchangeRateInputField,
EstimateProjectSelectButton,
} from './components';
import { EstimateFormEstimateNumberField } from './EstimateFormEstimateNumberField';
import { useEstimateFormContext } from './EstimateFormProvider';
/**
* Estimate number field of estimate form.
*/
const EstimateFormEstimateNumberField = R.compose(
withDialogActions,
withSettings(({ estimatesSettings }) => ({
estimateNextNumber: estimatesSettings?.nextNumber,
estimateNumberPrefix: estimatesSettings?.numberPrefix,
estimateAutoIncrement: estimatesSettings?.autoIncrement,
})),
)(
({
// #withDialogActions
openDialog,
// #withSettings
estimateAutoIncrement,
}) => {
const { values, setFieldValue } = useFormikContext();
const handleEstimateNumberBtnClick = () => {
openDialog('estimate-number-form', {});
};
// Handle estimate no. field blur.
const handleEstimateNoBlur = (event) => {
const newValue = event.target.value;
// Show the confirmation dialog if the value has changed and auto-increment
// mode is enabled.
if (values.estimate_number !== newValue && estimateAutoIncrement) {
openDialog('estimate-number-form', {
initialFormValues: {
onceManualNumber: newValue,
incrementMode: 'manual-transaction',
},
});
}
// Setting the estimate number to the form will be manually in case
// auto-increment is disable.
if (!estimateAutoIncrement) {
setFieldValue('estimate_number', newValue);
setFieldValue('estimate_number_manually', newValue);
}
};
return (
<FFormGroup
name={'estimate_number'}
label={<T id={'estimate'} />}
inline={true}
>
<ControlGroup fill={true}>
<FInputGroup
name={'estimate_number'}
minimal={true}
asyncControl={true}
onBlur={handleEstimateNoBlur}
onChange={() => {}}
/>
<InputPrependButton
buttonProps={{
onClick: handleEstimateNumberBtnClick,
icon: <Icon icon={'settings-18'} />,
}}
tooltip={true}
tooltipProps={{
content: <T id={'setting_your_auto_generated_estimate_number'} />,
position: Position.BOTTOM_LEFT,
}}
/>
</ControlGroup>
</FFormGroup>
);
},
);
/**
* Estimate form header.
*/