mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 23:00:34 +00:00
feat: assign default default messages on sales transactions
This commit is contained in:
@@ -4,12 +4,7 @@ import { Form } from 'formik';
|
|||||||
import { Button, Intent } from '@blueprintjs/core';
|
import { Button, Intent } from '@blueprintjs/core';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
import {
|
import { FormattedMessage as T, FFormGroup, FTextArea } from '@/components';
|
||||||
FieldRequiredHint,
|
|
||||||
FormattedMessage as T,
|
|
||||||
FFormGroup,
|
|
||||||
FTextArea,
|
|
||||||
} from '@/components';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preferences estimates form.
|
* Preferences estimates form.
|
||||||
@@ -24,21 +19,6 @@ export function PreferencesCreditNotesForm({ isSubmitting }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
{/* ---------- Terms & Conditions ---------- */}
|
|
||||||
<FFormGroup
|
|
||||||
name={'termsConditions'}
|
|
||||||
label={<T id={'pref.creditNotes.termsConditions.field'} />}
|
|
||||||
labelInfo={<FieldRequiredHint />}
|
|
||||||
fastField={true}
|
|
||||||
>
|
|
||||||
<FTextArea
|
|
||||||
medium={'true'}
|
|
||||||
name={'termsConditions'}
|
|
||||||
fastField={true}
|
|
||||||
fill={true}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
{/* ---------- Customer Notes ---------- */}
|
{/* ---------- Customer Notes ---------- */}
|
||||||
<FFormGroup
|
<FFormGroup
|
||||||
name={'customerNotes'}
|
name={'customerNotes'}
|
||||||
@@ -47,7 +27,21 @@ export function PreferencesCreditNotesForm({ isSubmitting }) {
|
|||||||
>
|
>
|
||||||
<FTextArea
|
<FTextArea
|
||||||
medium={'true'}
|
medium={'true'}
|
||||||
name={'tax_number'}
|
name={'customerNotes'}
|
||||||
|
fastField={true}
|
||||||
|
fill={true}
|
||||||
|
/>
|
||||||
|
</FFormGroup>
|
||||||
|
|
||||||
|
{/* ---------- Terms & Conditions ---------- */}
|
||||||
|
<FFormGroup
|
||||||
|
name={'termsConditions'}
|
||||||
|
label={<T id={'pref.creditNotes.termsConditions.field'} />}
|
||||||
|
fastField={true}
|
||||||
|
>
|
||||||
|
<FTextArea
|
||||||
|
medium={'true'}
|
||||||
|
name={'termsConditions'}
|
||||||
fastField={true}
|
fastField={true}
|
||||||
fill={true}
|
fill={true}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Formik } from 'formik';
|
import { Formik } from 'formik';
|
||||||
|
import * as R from 'ramda';
|
||||||
import { Intent } from '@blueprintjs/core';
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
|
||||||
import { AppToaster } from '@/components';
|
import { AppToaster } from '@/components';
|
||||||
import { PreferencesCreditNotesFormSchema } from './PreferencesCreditNotesForm.schema';
|
import { PreferencesCreditNotesFormSchema } from './PreferencesCreditNotesForm.schema';
|
||||||
import { usePreferencesCreditNotesFormContext } from './PreferencesCreditNotesFormBoot';
|
|
||||||
import { PreferencesCreditNotesForm } from './PreferencesCreditNotesForm';
|
import { PreferencesCreditNotesForm } from './PreferencesCreditNotesForm';
|
||||||
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
||||||
|
|
||||||
import { compose, transformToForm } from '@/utils';
|
import { compose, transformToForm, transfromToSnakeCase } from '@/utils';
|
||||||
|
import withSettings from '@/containers/Settings/withSettings';
|
||||||
|
import { transferObjectOptionsToArray } from '../Accountant/utils';
|
||||||
|
import { useSaveSettings } from '@/hooks/query';
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
termsConditions: '',
|
termsConditions: '',
|
||||||
@@ -23,8 +26,12 @@ const defaultValues = {
|
|||||||
function PreferencesCreditNotesFormPageRoot({
|
function PreferencesCreditNotesFormPageRoot({
|
||||||
// #withDashboardActions
|
// #withDashboardActions
|
||||||
changePreferencesPageTitle,
|
changePreferencesPageTitle,
|
||||||
|
|
||||||
|
// #withSettings
|
||||||
|
creditNoteSettings,
|
||||||
}) {
|
}) {
|
||||||
const { organization } = usePreferencesCreditNotesFormContext();
|
// Save settings.
|
||||||
|
const { mutateAsync: saveSettingMutate } = useSaveSettings();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
changePreferencesPageTitle(intl.get('preferences.creditNotes'));
|
changePreferencesPageTitle(intl.get('preferences.creditNotes'));
|
||||||
@@ -33,14 +40,19 @@ function PreferencesCreditNotesFormPageRoot({
|
|||||||
// Initial values.
|
// Initial values.
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
...defaultValues,
|
...defaultValues,
|
||||||
...transformToForm(organization.metadata, defaultValues),
|
...transformToForm(creditNoteSettings, defaultValues),
|
||||||
};
|
};
|
||||||
// Handle the form submit.
|
// Handle the form submit.
|
||||||
const handleFormSubmit = (values, { setSubmitting }) => {
|
const handleFormSubmit = (values, { setSubmitting }) => {
|
||||||
|
const options = R.compose(
|
||||||
|
transferObjectOptionsToArray,
|
||||||
|
transfromToSnakeCase,
|
||||||
|
)({ creditNote: { ...values } });
|
||||||
|
|
||||||
// Handle request success.
|
// Handle request success.
|
||||||
const onSuccess = (response) => {
|
const onSuccess = () => {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: intl.get('preferences.estimates.success_message'),
|
message: intl.get('preferences.credit_notes.success_message'),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
});
|
});
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
@@ -49,9 +61,7 @@ function PreferencesCreditNotesFormPageRoot({
|
|||||||
const onError = () => {
|
const onError = () => {
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
// updateOrganization({ ...values })
|
saveSettingMutate({ options }).then(onSuccess).catch(onError);
|
||||||
// .then(onSuccess)
|
|
||||||
// .catch(onError);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -64,6 +74,9 @@ function PreferencesCreditNotesFormPageRoot({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PreferencesCreditNotesFormPage = compose(withDashboardActions)(
|
export const PreferencesCreditNotesFormPage = compose(
|
||||||
PreferencesCreditNotesFormPageRoot,
|
withDashboardActions,
|
||||||
);
|
withSettings(({ creditNoteSettings }) => ({
|
||||||
|
creditNoteSettings: creditNoteSettings,
|
||||||
|
})),
|
||||||
|
)(PreferencesCreditNotesFormPageRoot);
|
||||||
|
|||||||
@@ -4,12 +4,7 @@ import { Form } from 'formik';
|
|||||||
import { Button, Intent } from '@blueprintjs/core';
|
import { Button, Intent } from '@blueprintjs/core';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
import {
|
import { FormattedMessage as T, FFormGroup, FTextArea } from '@/components';
|
||||||
FieldRequiredHint,
|
|
||||||
FormattedMessage as T,
|
|
||||||
FFormGroup,
|
|
||||||
FTextArea,
|
|
||||||
} from '@/components';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preferences estimates form.
|
* Preferences estimates form.
|
||||||
@@ -24,21 +19,6 @@ export function PreferencesEstimatesForm({ isSubmitting }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Form>
|
<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 ---------- */}
|
{/* ---------- Customer Notes ---------- */}
|
||||||
<FFormGroup
|
<FFormGroup
|
||||||
name={'customerNotes'}
|
name={'customerNotes'}
|
||||||
@@ -47,7 +27,21 @@ export function PreferencesEstimatesForm({ isSubmitting }) {
|
|||||||
>
|
>
|
||||||
<FTextArea
|
<FTextArea
|
||||||
medium={'true'}
|
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}
|
fastField={true}
|
||||||
fill={true}
|
fill={true}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import classNames from 'classnames';
|
|||||||
import { CLASSES } from '@/constants/classes';
|
import { CLASSES } from '@/constants/classes';
|
||||||
import { useSettings } from '@/hooks/query';
|
import { useSettings } from '@/hooks/query';
|
||||||
import PreferencesPageLoader from '../PreferencesPageLoader';
|
import PreferencesPageLoader from '../PreferencesPageLoader';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
import { Card } from '@/components';
|
||||||
|
|
||||||
const PreferencesEstimatesFormContext = React.createContext();
|
const PreferencesEstimatesFormContext = React.createContext();
|
||||||
|
|
||||||
@@ -13,9 +15,8 @@ function PreferencesEstimatesBoot({ ...props }) {
|
|||||||
|
|
||||||
// Provider state.
|
// Provider state.
|
||||||
const provider = {
|
const provider = {
|
||||||
organization: {},
|
isSettingsLoading,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Detarmines whether if any query is loading.
|
// Detarmines whether if any query is loading.
|
||||||
const isLoading = isSettingsLoading;
|
const isLoading = isSettingsLoading;
|
||||||
|
|
||||||
@@ -26,11 +27,16 @@ function PreferencesEstimatesBoot({ ...props }) {
|
|||||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_ACCOUNTANT,
|
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_ACCOUNTANT,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{isLoading ? (
|
<PreferencesEstimatesCard>
|
||||||
<PreferencesPageLoader />
|
{isLoading ? (
|
||||||
) : (
|
<PreferencesPageLoader />
|
||||||
<PreferencesEstimatesFormContext.Provider value={provider} {...props} />
|
) : (
|
||||||
)}
|
<PreferencesEstimatesFormContext.Provider
|
||||||
|
value={provider}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</PreferencesEstimatesCard>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -38,4 +44,12 @@ function PreferencesEstimatesBoot({ ...props }) {
|
|||||||
const usePreferencesEstimatesFormContext = () =>
|
const usePreferencesEstimatesFormContext = () =>
|
||||||
React.useContext(PreferencesEstimatesFormContext);
|
React.useContext(PreferencesEstimatesFormContext);
|
||||||
|
|
||||||
|
const PreferencesEstimatesCard = styled(Card)`
|
||||||
|
padding: 25px;
|
||||||
|
|
||||||
|
.bp4-form-group {
|
||||||
|
max-width: 600px;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
export { PreferencesEstimatesBoot, usePreferencesEstimatesFormContext };
|
export { PreferencesEstimatesBoot, usePreferencesEstimatesFormContext };
|
||||||
|
|||||||
@@ -3,14 +3,16 @@ import React, { useEffect } from 'react';
|
|||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Formik } from 'formik';
|
import { Formik } from 'formik';
|
||||||
import { Intent } from '@blueprintjs/core';
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
import * as R from 'ramda';
|
||||||
|
|
||||||
import { AppToaster } from '@/components';
|
import { AppToaster } from '@/components';
|
||||||
import { PreferencesEstimatesFormSchema } from './PreferencesEstimatesForm.schema';
|
import { PreferencesEstimatesFormSchema } from './PreferencesEstimatesForm.schema';
|
||||||
import { usePreferencesEstimatesFormContext } from './PreferencesEstimatesFormBoot';
|
|
||||||
import { PreferencesEstimatesForm } from './PreferencesEstimatesForm';
|
import { PreferencesEstimatesForm } from './PreferencesEstimatesForm';
|
||||||
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
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 = {
|
const defaultValues = {
|
||||||
termsConditions: '',
|
termsConditions: '',
|
||||||
@@ -23,8 +25,12 @@ const defaultValues = {
|
|||||||
function PreferencesEstimatesFormPageRoot({
|
function PreferencesEstimatesFormPageRoot({
|
||||||
// #withDashboardActions
|
// #withDashboardActions
|
||||||
changePreferencesPageTitle,
|
changePreferencesPageTitle,
|
||||||
|
|
||||||
|
// #withSettings
|
||||||
|
estimatesSettings,
|
||||||
}) {
|
}) {
|
||||||
const { organization } = usePreferencesEstimatesFormContext();
|
// Save Organization Settings.
|
||||||
|
const { mutateAsync: saveSettingMutate } = useSaveSettings();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
changePreferencesPageTitle(intl.get('preferences.estimates'));
|
changePreferencesPageTitle(intl.get('preferences.estimates'));
|
||||||
@@ -33,10 +39,15 @@ function PreferencesEstimatesFormPageRoot({
|
|||||||
// Initial values.
|
// Initial values.
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
...defaultValues,
|
...defaultValues,
|
||||||
...transformToForm(organization.metadata, defaultValues),
|
...transformToForm(estimatesSettings, defaultValues),
|
||||||
};
|
};
|
||||||
// Handle the form submit.
|
// Handle the form submit.
|
||||||
const handleFormSubmit = (values, { setSubmitting }) => {
|
const handleFormSubmit = (values, { setSubmitting }) => {
|
||||||
|
const options = R.compose(
|
||||||
|
transferObjectOptionsToArray,
|
||||||
|
transfromToSnakeCase,
|
||||||
|
)({ salesEstimates: { ...values } });
|
||||||
|
|
||||||
// Handle request success.
|
// Handle request success.
|
||||||
const onSuccess = (response) => {
|
const onSuccess = (response) => {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
@@ -49,9 +60,7 @@ function PreferencesEstimatesFormPageRoot({
|
|||||||
const onError = () => {
|
const onError = () => {
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
// updateOrganization({ ...values })
|
saveSettingMutate({ options }).then(onSuccess).catch(onError);
|
||||||
// .then(onSuccess)
|
|
||||||
// .catch(onError);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -64,6 +73,9 @@ function PreferencesEstimatesFormPageRoot({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PreferencesEstimatesFormPage = compose(withDashboardActions)(
|
export const PreferencesEstimatesFormPage = compose(
|
||||||
PreferencesEstimatesFormPageRoot,
|
withDashboardActions,
|
||||||
);
|
withSettings(({ estimatesSettings }) => ({
|
||||||
|
estimatesSettings: estimatesSettings,
|
||||||
|
})),
|
||||||
|
)(PreferencesEstimatesFormPageRoot);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function PreferencesInvoicesBoot({ ...props }) {
|
|||||||
|
|
||||||
// Provider state.
|
// Provider state.
|
||||||
const provider = {
|
const provider = {
|
||||||
organization: {},
|
isSettingsLoading
|
||||||
};
|
};
|
||||||
|
|
||||||
// Detarmines whether if any query is loading.
|
// Detarmines whether if any query is loading.
|
||||||
|
|||||||
@@ -3,14 +3,17 @@ import React, { useEffect } from 'react';
|
|||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Formik } from 'formik';
|
import { Formik } from 'formik';
|
||||||
import { Intent } from '@blueprintjs/core';
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
import * as R from 'ramda';
|
||||||
|
|
||||||
import { AppToaster } from '@/components';
|
import { AppToaster } from '@/components';
|
||||||
import { PreferencesInvoiceFormSchema } from './PreferencesInvoiceForm.schema';
|
import { PreferencesInvoiceFormSchema } from './PreferencesInvoiceForm.schema';
|
||||||
import { usePreferencesInvoiceFormContext } from './PreferencesInvoiceFormBoot';
|
|
||||||
import { PreferencesInvoicesForm } from './PreferencesInvoicesForm';
|
import { PreferencesInvoicesForm } from './PreferencesInvoicesForm';
|
||||||
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
||||||
|
|
||||||
import { compose, transformToForm } from '@/utils';
|
import { compose, transformToForm, transfromToSnakeCase } from '@/utils';
|
||||||
|
import withSettings from '@/containers/Settings/withSettings';
|
||||||
|
import { transferObjectOptionsToArray } from '../Accountant/utils';
|
||||||
|
import { useSaveSettings } from '@/hooks/query';
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
termsConditions: '',
|
termsConditions: '',
|
||||||
@@ -23,8 +26,12 @@ const defaultValues = {
|
|||||||
function PreferencesInvoiceFormPage({
|
function PreferencesInvoiceFormPage({
|
||||||
// #withDashboardActions
|
// #withDashboardActions
|
||||||
changePreferencesPageTitle,
|
changePreferencesPageTitle,
|
||||||
|
|
||||||
|
// #withSettings
|
||||||
|
invoiceSettings,
|
||||||
}) {
|
}) {
|
||||||
const { organization } = usePreferencesInvoiceFormContext();
|
// Save settings.
|
||||||
|
const { mutateAsync: saveSettingMutate } = useSaveSettings();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
changePreferencesPageTitle(intl.get('preferences.invoices'));
|
changePreferencesPageTitle(intl.get('preferences.invoices'));
|
||||||
@@ -33,12 +40,17 @@ function PreferencesInvoiceFormPage({
|
|||||||
// Initial values.
|
// Initial values.
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
...defaultValues,
|
...defaultValues,
|
||||||
...transformToForm(organization.metadata, defaultValues),
|
...transformToForm(invoiceSettings, defaultValues),
|
||||||
};
|
};
|
||||||
// Handle the form submit.
|
// Handle the form submit.
|
||||||
const handleFormSubmit = (values, { setSubmitting }) => {
|
const handleFormSubmit = (values, { setSubmitting }) => {
|
||||||
|
const options = R.compose(
|
||||||
|
transferObjectOptionsToArray,
|
||||||
|
transfromToSnakeCase,
|
||||||
|
)({ salesInvoices: { ...values } });
|
||||||
|
|
||||||
// Handle request success.
|
// Handle request success.
|
||||||
const onSuccess = (response) => {
|
const onSuccess = () => {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: intl.get('preferences.invoices.success_message'),
|
message: intl.get('preferences.invoices.success_message'),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
@@ -49,9 +61,7 @@ function PreferencesInvoiceFormPage({
|
|||||||
const onError = () => {
|
const onError = () => {
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
// updateOrganization({ ...values })
|
saveSettingMutate({ options }).then(onSuccess).catch(onError);
|
||||||
// .then(onSuccess)
|
|
||||||
// .catch(onError);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -64,4 +74,9 @@ function PreferencesInvoiceFormPage({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(withDashboardActions)(PreferencesInvoiceFormPage);
|
export default compose(
|
||||||
|
withDashboardActions,
|
||||||
|
withSettings(({ invoiceSettings }) => ({
|
||||||
|
invoiceSettings: invoiceSettings,
|
||||||
|
})),
|
||||||
|
)(PreferencesInvoiceFormPage);
|
||||||
|
|||||||
@@ -4,11 +4,7 @@ import { Form } from 'formik';
|
|||||||
import { Button, Intent } from '@blueprintjs/core';
|
import { Button, Intent } from '@blueprintjs/core';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
import {
|
import { FormattedMessage as T, FFormGroup, FTextArea } from '@/components';
|
||||||
FormattedMessage as T,
|
|
||||||
FFormGroup,
|
|
||||||
FTextArea,
|
|
||||||
} from '@/components';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preferences general form.
|
* Preferences general form.
|
||||||
@@ -23,6 +19,20 @@ export function PreferencesInvoicesForm({ isSubmitting }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
|
{/* ---------- Customer Notes ---------- */}
|
||||||
|
<FFormGroup
|
||||||
|
name={'customerNotes'}
|
||||||
|
label={<T id={'pref.invoices.customerNotes.field'} />}
|
||||||
|
fastField={true}
|
||||||
|
>
|
||||||
|
<FTextArea
|
||||||
|
medium={'true'}
|
||||||
|
name={'customerNotes'}
|
||||||
|
fastField={true}
|
||||||
|
fill={true}
|
||||||
|
/>
|
||||||
|
</FFormGroup>
|
||||||
|
|
||||||
{/* ---------- Terms & Conditions ---------- */}
|
{/* ---------- Terms & Conditions ---------- */}
|
||||||
<FFormGroup
|
<FFormGroup
|
||||||
name={'termsConditions'}
|
name={'termsConditions'}
|
||||||
@@ -37,20 +47,6 @@ export function PreferencesInvoicesForm({ isSubmitting }) {
|
|||||||
/>
|
/>
|
||||||
</FFormGroup>
|
</FFormGroup>
|
||||||
|
|
||||||
{/* ---------- Customer Notes ---------- */}
|
|
||||||
<FFormGroup
|
|
||||||
name={'customerNotes'}
|
|
||||||
label={<T id={'pref.invoices.customerNotes.field'} />}
|
|
||||||
fastField={true}
|
|
||||||
>
|
|
||||||
<FTextArea
|
|
||||||
medium={'true'}
|
|
||||||
name={'tax_number'}
|
|
||||||
fastField={true}
|
|
||||||
fill={true}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<CardFooterActions>
|
<CardFooterActions>
|
||||||
<Button loading={isSubmitting} intent={Intent.PRIMARY} type="submit">
|
<Button loading={isSubmitting} intent={Intent.PRIMARY} type="submit">
|
||||||
<T id={'save'} />
|
<T id={'save'} />
|
||||||
|
|||||||
@@ -4,11 +4,7 @@ import { Form } from 'formik';
|
|||||||
import { Button, Intent } from '@blueprintjs/core';
|
import { Button, Intent } from '@blueprintjs/core';
|
||||||
import { useHistory } from 'react-router-dom';
|
import { useHistory } from 'react-router-dom';
|
||||||
|
|
||||||
import {
|
import { FormattedMessage as T, FFormGroup, FTextArea } from '@/components';
|
||||||
FormattedMessage as T,
|
|
||||||
FFormGroup,
|
|
||||||
FTextArea,
|
|
||||||
} from '@/components';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preferences general form.
|
* Preferences general form.
|
||||||
@@ -23,6 +19,20 @@ export function PreferencesReceiptsForm({ isSubmitting }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Form>
|
<Form>
|
||||||
|
{/* ---------- Customer Notes ---------- */}
|
||||||
|
<FFormGroup
|
||||||
|
name={'receiptMessage'}
|
||||||
|
label={<T id={'pref.receipts.receiptMessage.field'} />}
|
||||||
|
fastField={true}
|
||||||
|
>
|
||||||
|
<FTextArea
|
||||||
|
medium={'true'}
|
||||||
|
name={'receiptMessage'}
|
||||||
|
fastField={true}
|
||||||
|
fill={true}
|
||||||
|
/>
|
||||||
|
</FFormGroup>
|
||||||
|
|
||||||
{/* ---------- Terms & Conditions ---------- */}
|
{/* ---------- Terms & Conditions ---------- */}
|
||||||
<FFormGroup
|
<FFormGroup
|
||||||
name={'termsConditions'}
|
name={'termsConditions'}
|
||||||
@@ -37,20 +47,6 @@ export function PreferencesReceiptsForm({ isSubmitting }) {
|
|||||||
/>
|
/>
|
||||||
</FFormGroup>
|
</FFormGroup>
|
||||||
|
|
||||||
{/* ---------- Customer Notes ---------- */}
|
|
||||||
<FFormGroup
|
|
||||||
name={'customerNotes'}
|
|
||||||
label={<T id={'pref.receipts.customerNotes.field'} />}
|
|
||||||
fastField={true}
|
|
||||||
>
|
|
||||||
<FTextArea
|
|
||||||
medium={'true'}
|
|
||||||
name={'tax_number'}
|
|
||||||
fastField={true}
|
|
||||||
fill={true}
|
|
||||||
/>
|
|
||||||
</FFormGroup>
|
|
||||||
|
|
||||||
<CardFooterActions>
|
<CardFooterActions>
|
||||||
<Button loading={isSubmitting} intent={Intent.PRIMARY} type="submit">
|
<Button loading={isSubmitting} intent={Intent.PRIMARY} type="submit">
|
||||||
<T id={'save'} />
|
<T id={'save'} />
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ function PreferencesReceiptsBoot({ ...props }) {
|
|||||||
|
|
||||||
// Provider state.
|
// Provider state.
|
||||||
const provider = {
|
const provider = {
|
||||||
organization: {},
|
isSettingsLoading,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Detarmines whether if any query is loading.
|
// Detarmines whether if any query is loading.
|
||||||
|
|||||||
@@ -3,18 +3,21 @@ import React, { useEffect } from 'react';
|
|||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Formik } from 'formik';
|
import { Formik } from 'formik';
|
||||||
import { Intent } from '@blueprintjs/core';
|
import { Intent } from '@blueprintjs/core';
|
||||||
|
import * as R from 'ramda';
|
||||||
|
|
||||||
import { AppToaster } from '@/components';
|
import { AppToaster } from '@/components';
|
||||||
import { PreferencesReceiptsFormSchema } from './PreferencesReceiptsForm.schema';
|
import { PreferencesReceiptsFormSchema } from './PreferencesReceiptsForm.schema';
|
||||||
import { usePreferencesReceiptsFormContext } from './PreferencesReceiptsFormBoot';
|
|
||||||
import { PreferencesReceiptsForm } from './PreferencesReceiptsForm';
|
import { PreferencesReceiptsForm } from './PreferencesReceiptsForm';
|
||||||
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
||||||
|
|
||||||
import { compose, transformToForm } from '@/utils';
|
import { compose, transformToForm, transfromToSnakeCase } from '@/utils';
|
||||||
|
import withSettings from '@/containers/Settings/withSettings';
|
||||||
|
import { useSaveSettings } from '@/hooks/query';
|
||||||
|
import { transferObjectOptionsToArray } from '../Accountant/utils';
|
||||||
|
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
termsConditions: '',
|
termsConditions: '',
|
||||||
customerNotes: '',
|
receiptMessage: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,8 +26,12 @@ const defaultValues = {
|
|||||||
function PreferencesReceiptsFormPageRoot({
|
function PreferencesReceiptsFormPageRoot({
|
||||||
// #withDashboardActions
|
// #withDashboardActions
|
||||||
changePreferencesPageTitle,
|
changePreferencesPageTitle,
|
||||||
|
|
||||||
|
// #withSettings
|
||||||
|
receiptSettings,
|
||||||
}) {
|
}) {
|
||||||
const { organization } = usePreferencesReceiptsFormContext();
|
// Save settings.
|
||||||
|
const { mutateAsync: saveSettingMutate } = useSaveSettings();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
changePreferencesPageTitle(intl.get('preferences.receipts'));
|
changePreferencesPageTitle(intl.get('preferences.receipts'));
|
||||||
@@ -33,12 +40,17 @@ function PreferencesReceiptsFormPageRoot({
|
|||||||
// Initial values.
|
// Initial values.
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
...defaultValues,
|
...defaultValues,
|
||||||
...transformToForm(organization.metadata, defaultValues),
|
...transformToForm(receiptSettings, defaultValues),
|
||||||
};
|
};
|
||||||
// Handle the form submit.
|
// Handle the form submit.
|
||||||
const handleFormSubmit = (values, { setSubmitting }) => {
|
const handleFormSubmit = (values, { setSubmitting }) => {
|
||||||
|
const options = R.compose(
|
||||||
|
transferObjectOptionsToArray,
|
||||||
|
transfromToSnakeCase,
|
||||||
|
)({ salesReceipts: { ...values } });
|
||||||
|
|
||||||
// Handle request success.
|
// Handle request success.
|
||||||
const onSuccess = (response) => {
|
const onSuccess = () => {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: intl.get('preferences.receipts.success_message'),
|
message: intl.get('preferences.receipts.success_message'),
|
||||||
intent: Intent.SUCCESS,
|
intent: Intent.SUCCESS,
|
||||||
@@ -49,9 +61,7 @@ function PreferencesReceiptsFormPageRoot({
|
|||||||
const onError = () => {
|
const onError = () => {
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
// updateOrganization({ ...values })
|
saveSettingMutate({ options }).then(onSuccess).catch(onError);
|
||||||
// .then(onSuccess)
|
|
||||||
// .catch(onError);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -64,6 +74,9 @@ function PreferencesReceiptsFormPageRoot({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PreferencesReceiptsFormPage = compose(withDashboardActions)(
|
export const PreferencesReceiptsFormPage = compose(
|
||||||
PreferencesReceiptsFormPageRoot,
|
withDashboardActions,
|
||||||
);
|
withSettings(({ receiptSettings }) => ({
|
||||||
|
receiptSettings: receiptSettings,
|
||||||
|
})),
|
||||||
|
)(PreferencesReceiptsFormPageRoot);
|
||||||
|
|||||||
@@ -2302,10 +2302,15 @@
|
|||||||
"pref.estimates.customerNotes.field": "Customer Notes",
|
"pref.estimates.customerNotes.field": "Customer Notes",
|
||||||
|
|
||||||
"pref.receipts.termsConditions.field": "Terms & Conditions",
|
"pref.receipts.termsConditions.field": "Terms & Conditions",
|
||||||
"pref.receipts.customerNotes.field": "Customer Notes",
|
"pref.receipts.receiptMessage.field": "Receipt Message",
|
||||||
|
|
||||||
"preferences.invoices": "Invoices",
|
"preferences.invoices": "Invoices",
|
||||||
"preferences.estimates": "Estimates",
|
"preferences.estimates": "Estimates",
|
||||||
"preferences.creditNotes": "Credit Notes",
|
"preferences.creditNotes": "Credit Notes",
|
||||||
"preferences.receipts": "Receipts"
|
"preferences.receipts": "Receipts",
|
||||||
|
|
||||||
|
"preferences.estimates.success_message": "The preferences have been saved successfully.",
|
||||||
|
"preferences.credit_notes.success_message": "The preferences have been saved successfully.",
|
||||||
|
"preferences.receipts.success_message": "The preferences have been saved successfully.",
|
||||||
|
"preferences.invoices.success_message": "The preferences have been saved successfully."
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user