feat: assign default default messages on sales transactions

This commit is contained in:
Ahmed Bouhuolia
2023-12-16 19:26:41 +02:00
parent ad53ddb9dd
commit 6953f7c4a3
12 changed files with 189 additions and 137 deletions

View File

@@ -4,12 +4,7 @@ import { Form } from 'formik';
import { Button, Intent } from '@blueprintjs/core';
import { useHistory } from 'react-router-dom';
import {
FieldRequiredHint,
FormattedMessage as T,
FFormGroup,
FTextArea,
} from '@/components';
import { FormattedMessage as T, FFormGroup, FTextArea } from '@/components';
/**
* Preferences estimates form.
@@ -24,21 +19,6 @@ export function PreferencesEstimatesForm({ isSubmitting }) {
return (
<Form>
{/* ---------- Terms & Conditions ---------- */}
<FFormGroup
name={'termsConditions'}
label={<T id={'pref.estimates.termsConditions.field'} />}
labelInfo={<FieldRequiredHint />}
fastField={true}
>
<FTextArea
medium={'true'}
name={'termsConditions'}
fastField={true}
fill={true}
/>
</FFormGroup>
{/* ---------- Customer Notes ---------- */}
<FFormGroup
name={'customerNotes'}
@@ -47,7 +27,21 @@ export function PreferencesEstimatesForm({ isSubmitting }) {
>
<FTextArea
medium={'true'}
name={'tax_number'}
name={'customerNotes'}
fastField={true}
fill={true}
/>
</FFormGroup>
{/* ---------- Terms & Conditions ---------- */}
<FFormGroup
name={'termsConditions'}
label={<T id={'pref.estimates.termsConditions.field'} />}
fastField={true}
>
<FTextArea
medium={'true'}
name={'termsConditions'}
fastField={true}
fill={true}
/>

View File

@@ -4,6 +4,8 @@ import classNames from 'classnames';
import { CLASSES } from '@/constants/classes';
import { useSettings } from '@/hooks/query';
import PreferencesPageLoader from '../PreferencesPageLoader';
import styled from 'styled-components';
import { Card } from '@/components';
const PreferencesEstimatesFormContext = React.createContext();
@@ -13,9 +15,8 @@ function PreferencesEstimatesBoot({ ...props }) {
// Provider state.
const provider = {
organization: {},
isSettingsLoading,
};
// Detarmines whether if any query is loading.
const isLoading = isSettingsLoading;
@@ -26,11 +27,16 @@ function PreferencesEstimatesBoot({ ...props }) {
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_ACCOUNTANT,
)}
>
{isLoading ? (
<PreferencesPageLoader />
) : (
<PreferencesEstimatesFormContext.Provider value={provider} {...props} />
)}
<PreferencesEstimatesCard>
{isLoading ? (
<PreferencesPageLoader />
) : (
<PreferencesEstimatesFormContext.Provider
value={provider}
{...props}
/>
)}
</PreferencesEstimatesCard>
</div>
);
}
@@ -38,4 +44,12 @@ function PreferencesEstimatesBoot({ ...props }) {
const usePreferencesEstimatesFormContext = () =>
React.useContext(PreferencesEstimatesFormContext);
const PreferencesEstimatesCard = styled(Card)`
padding: 25px;
.bp4-form-group {
max-width: 600px;
}
`;
export { PreferencesEstimatesBoot, usePreferencesEstimatesFormContext };

View File

@@ -3,14 +3,16 @@ import React, { useEffect } from 'react';
import intl from 'react-intl-universal';
import { Formik } from 'formik';
import { Intent } from '@blueprintjs/core';
import * as R from 'ramda';
import { AppToaster } from '@/components';
import { PreferencesEstimatesFormSchema } from './PreferencesEstimatesForm.schema';
import { usePreferencesEstimatesFormContext } from './PreferencesEstimatesFormBoot';
import { PreferencesEstimatesForm } from './PreferencesEstimatesForm';
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
import { compose, transformToForm } from '@/utils';
import { transferObjectOptionsToArray } from '../Accountant/utils';
import { compose, transformToForm, transfromToSnakeCase } from '@/utils';
import { useSaveSettings } from '@/hooks/query';
const defaultValues = {
termsConditions: '',
@@ -23,8 +25,12 @@ const defaultValues = {
function PreferencesEstimatesFormPageRoot({
// #withDashboardActions
changePreferencesPageTitle,
// #withSettings
estimatesSettings,
}) {
const { organization } = usePreferencesEstimatesFormContext();
// Save Organization Settings.
const { mutateAsync: saveSettingMutate } = useSaveSettings();
useEffect(() => {
changePreferencesPageTitle(intl.get('preferences.estimates'));
@@ -33,10 +39,15 @@ function PreferencesEstimatesFormPageRoot({
// Initial values.
const initialValues = {
...defaultValues,
...transformToForm(organization.metadata, defaultValues),
...transformToForm(estimatesSettings, defaultValues),
};
// Handle the form submit.
const handleFormSubmit = (values, { setSubmitting }) => {
const options = R.compose(
transferObjectOptionsToArray,
transfromToSnakeCase,
)({ salesEstimates: { ...values } });
// Handle request success.
const onSuccess = (response) => {
AppToaster.show({
@@ -49,9 +60,7 @@ function PreferencesEstimatesFormPageRoot({
const onError = () => {
setSubmitting(false);
};
// updateOrganization({ ...values })
// .then(onSuccess)
// .catch(onError);
saveSettingMutate({ options }).then(onSuccess).catch(onError);
};
return (
@@ -64,6 +73,9 @@ function PreferencesEstimatesFormPageRoot({
);
}
export const PreferencesEstimatesFormPage = compose(withDashboardActions)(
PreferencesEstimatesFormPageRoot,
);
export const PreferencesEstimatesFormPage = compose(
withDashboardActions,
withSettings(({ estimatesSettings }) => ({
estimatesSettings: estimatesSettings,
})),
)(PreferencesEstimatesFormPageRoot);