diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx index 2796a04a0..c4627a90c 100644 --- a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx @@ -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 PreferencesCreditNotesForm({ isSubmitting }) { return (
- {/* ---------- Terms & Conditions ---------- */} - } - labelInfo={} - fastField={true} - > - - - {/* ---------- Customer Notes ---------- */} + + + {/* ---------- Terms & Conditions ---------- */} + } + fastField={true} + > + diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx index 4121c7d98..4fc3956c8 100644 --- a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx @@ -1,16 +1,19 @@ // @ts-nocheck -import React, { useEffect } from 'react'; +import { useEffect } from 'react'; import intl from 'react-intl-universal'; import { Formik } from 'formik'; +import * as R from 'ramda'; import { Intent } from '@blueprintjs/core'; import { AppToaster } from '@/components'; import { PreferencesCreditNotesFormSchema } from './PreferencesCreditNotesForm.schema'; -import { usePreferencesCreditNotesFormContext } from './PreferencesCreditNotesFormBoot'; import { PreferencesCreditNotesForm } from './PreferencesCreditNotesForm'; 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 = { termsConditions: '', @@ -23,8 +26,12 @@ const defaultValues = { function PreferencesCreditNotesFormPageRoot({ // #withDashboardActions changePreferencesPageTitle, + + // #withSettings + creditNoteSettings, }) { - const { organization } = usePreferencesCreditNotesFormContext(); + // Save settings. + const { mutateAsync: saveSettingMutate } = useSaveSettings(); useEffect(() => { changePreferencesPageTitle(intl.get('preferences.creditNotes')); @@ -33,14 +40,19 @@ function PreferencesCreditNotesFormPageRoot({ // Initial values. const initialValues = { ...defaultValues, - ...transformToForm(organization.metadata, defaultValues), + ...transformToForm(creditNoteSettings, defaultValues), }; // Handle the form submit. const handleFormSubmit = (values, { setSubmitting }) => { + const options = R.compose( + transferObjectOptionsToArray, + transfromToSnakeCase, + )({ creditNote: { ...values } }); + // Handle request success. - const onSuccess = (response) => { + const onSuccess = () => { AppToaster.show({ - message: intl.get('preferences.estimates.success_message'), + message: intl.get('preferences.credit_notes.success_message'), intent: Intent.SUCCESS, }); setSubmitting(false); @@ -49,9 +61,7 @@ function PreferencesCreditNotesFormPageRoot({ const onError = () => { setSubmitting(false); }; - // updateOrganization({ ...values }) - // .then(onSuccess) - // .catch(onError); + saveSettingMutate({ options }).then(onSuccess).catch(onError); }; return ( @@ -64,6 +74,9 @@ function PreferencesCreditNotesFormPageRoot({ ); } -export const PreferencesCreditNotesFormPage = compose(withDashboardActions)( - PreferencesCreditNotesFormPageRoot, -); +export const PreferencesCreditNotesFormPage = compose( + withDashboardActions, + withSettings(({ creditNoteSettings }) => ({ + creditNoteSettings: creditNoteSettings, + })), +)(PreferencesCreditNotesFormPageRoot); diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.tsx index 426797f4d..7e17acc10 100644 --- a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.tsx +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.tsx @@ -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 ( - {/* ---------- Terms & Conditions ---------- */} - } - labelInfo={} - fastField={true} - > - - - {/* ---------- Customer Notes ---------- */} + + + {/* ---------- Terms & Conditions ---------- */} + } + fastField={true} + > + diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormBoot.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormBoot.tsx index e444c5998..d39d3c817 100644 --- a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormBoot.tsx +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormBoot.tsx @@ -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 ? ( - - ) : ( - - )} + + {isLoading ? ( + + ) : ( + + )} + ); } @@ -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 }; diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx index 6dedd912b..f5241f20a 100644 --- a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx @@ -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); diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx index 03d9a31a4..2cd42db21 100644 --- a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx @@ -15,7 +15,7 @@ function PreferencesInvoicesBoot({ ...props }) { // Provider state. const provider = { - organization: {}, + isSettingsLoading }; // Detarmines whether if any query is loading. diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx index 6c364cb7e..097b8f996 100644 --- a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx @@ -3,14 +3,17 @@ 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 { PreferencesInvoiceFormSchema } from './PreferencesInvoiceForm.schema'; -import { usePreferencesInvoiceFormContext } from './PreferencesInvoiceFormBoot'; import { PreferencesInvoicesForm } from './PreferencesInvoicesForm'; 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 = { termsConditions: '', @@ -23,8 +26,12 @@ const defaultValues = { function PreferencesInvoiceFormPage({ // #withDashboardActions changePreferencesPageTitle, + + // #withSettings + invoiceSettings, }) { - const { organization } = usePreferencesInvoiceFormContext(); + // Save settings. + const { mutateAsync: saveSettingMutate } = useSaveSettings(); useEffect(() => { changePreferencesPageTitle(intl.get('preferences.invoices')); @@ -33,12 +40,17 @@ function PreferencesInvoiceFormPage({ // Initial values. const initialValues = { ...defaultValues, - ...transformToForm(organization.metadata, defaultValues), + ...transformToForm(invoiceSettings, defaultValues), }; // Handle the form submit. const handleFormSubmit = (values, { setSubmitting }) => { + const options = R.compose( + transferObjectOptionsToArray, + transfromToSnakeCase, + )({ salesInvoices: { ...values } }); + // Handle request success. - const onSuccess = (response) => { + const onSuccess = () => { AppToaster.show({ message: intl.get('preferences.invoices.success_message'), intent: Intent.SUCCESS, @@ -49,9 +61,7 @@ function PreferencesInvoiceFormPage({ const onError = () => { setSubmitting(false); }; - // updateOrganization({ ...values }) - // .then(onSuccess) - // .catch(onError); + saveSettingMutate({ options }).then(onSuccess).catch(onError); }; return ( @@ -64,4 +74,9 @@ function PreferencesInvoiceFormPage({ ); } -export default compose(withDashboardActions)(PreferencesInvoiceFormPage); +export default compose( + withDashboardActions, + withSettings(({ invoiceSettings }) => ({ + invoiceSettings: invoiceSettings, + })), +)(PreferencesInvoiceFormPage); diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx index 5beec5e0c..95fced8e9 100644 --- a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx @@ -4,11 +4,7 @@ import { Form } from 'formik'; import { Button, Intent } from '@blueprintjs/core'; import { useHistory } from 'react-router-dom'; -import { - FormattedMessage as T, - FFormGroup, - FTextArea, -} from '@/components'; +import { FormattedMessage as T, FFormGroup, FTextArea } from '@/components'; /** * Preferences general form. @@ -23,6 +19,20 @@ export function PreferencesInvoicesForm({ isSubmitting }) { return ( + {/* ---------- Customer Notes ---------- */} + } + fastField={true} + > + + + {/* ---------- Terms & Conditions ---------- */} - {/* ---------- Customer Notes ---------- */} - } - fastField={true} - > - - -