From 33e5d1a979a95d0310f23a0b9ecf816c35c88355 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Thu, 14 Dec 2023 11:01:25 +0200 Subject: [PATCH 1/6] feat: Add default customer message and terms and conditions to the transactions. --- .../webapp/src/constants/preferencesMenu.tsx | 4 + .../CreditNotes/PreferencesCreditNotes.tsx | 14 ++++ .../PreferencesCreditNotesForm.schema.ts | 9 +++ .../PreferencesCreditNotesForm.tsx | 80 ++++++++++++++++++ .../PreferencesCreditNotesFormBoot.tsx | 41 ++++++++++ .../PreferencesCreditNotesFormPage.tsx | 69 ++++++++++++++++ .../Estimates/PreferencesEstimates.tsx | 14 ++++ .../PreferencesEstimatesForm.schema.ts | 9 +++ .../Estimates/PreferencesEstimatesForm.tsx | 80 ++++++++++++++++++ .../PreferencesEstimatesFormBoot.tsx | 41 ++++++++++ .../PreferencesEstimatesFormPage.tsx | 69 ++++++++++++++++ .../Invoices/PreferencesInvoiceForm.schema.ts | 9 +++ .../Invoices/PreferencesInvoiceFormBoot.tsx | 41 ++++++++++ .../Invoices/PreferencesInvoiceFormPage.tsx | 67 +++++++++++++++ .../Invoices/PreferencesInvoices.tsx | 14 ++++ .../Invoices/PreferencesInvoicesForm.tsx | 81 +++++++++++++++++++ packages/webapp/src/lang/en/index.json | 5 +- packages/webapp/src/routes/preferences.tsx | 12 +++ 18 files changed, 658 insertions(+), 1 deletion(-) create mode 100644 packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx create mode 100644 packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.schema.ts create mode 100644 packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx create mode 100644 packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormBoot.tsx create mode 100644 packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx create mode 100644 packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimates.tsx create mode 100644 packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.schema.ts create mode 100644 packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.tsx create mode 100644 packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormBoot.tsx create mode 100644 packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx create mode 100644 packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceForm.schema.ts create mode 100644 packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx create mode 100644 packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx create mode 100644 packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoices.tsx create mode 100644 packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx diff --git a/packages/webapp/src/constants/preferencesMenu.tsx b/packages/webapp/src/constants/preferencesMenu.tsx index f90c7ed04d..562cce1b17 100644 --- a/packages/webapp/src/constants/preferencesMenu.tsx +++ b/packages/webapp/src/constants/preferencesMenu.tsx @@ -12,6 +12,10 @@ export default [ text: , href: '/preferences/users', }, + { + text: 'Invoices', + href: '/preferences/invoices', + }, { text: , href: '/preferences/currencies', diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx new file mode 100644 index 0000000000..ee17533989 --- /dev/null +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx @@ -0,0 +1,14 @@ +// @ts-nocheck +import { PreferencesCreditNotesBoot } from './PreferencesCreditNotesFormBoot'; +import PreferencesInvoiceFormPage from './PreferencesCreditNotesFormPage'; + +/** + * items preferences. + */ +export default function PreferencesCreditNotes() { + return ( + + + + ); +} diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.schema.ts b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.schema.ts new file mode 100644 index 0000000000..b6cf3eab68 --- /dev/null +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.schema.ts @@ -0,0 +1,9 @@ +// @ts-nocheck +import * as Yup from 'yup'; + +const Schema = Yup.object().shape({ + termsConditions: Yup.string().optional(), + customerNotes: Yup.string().optional(), +}); + +export const PreferencesEstimatesFormSchema = Schema; diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx new file mode 100644 index 0000000000..17fc18c0d2 --- /dev/null +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx @@ -0,0 +1,80 @@ +// @ts-nocheck +import styled from 'styled-components'; +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'; + +/** + * Preferences estimates form. + */ +export function PreferencesCreditNotesForm({ isSubmitting }) { + const history = useHistory(); + + // Handle close click. + const handleCloseClick = () => { + history.go(-1); + }; + + return ( +
+ {/* ---------- Terms & Conditions ---------- */} + } + labelInfo={} + fastField={true} + > + + + + {/* ---------- Customer Notes ---------- */} + } + fastField={true} + > + + + + + + + +
+ ); +} + +const CardFooterActions = styled.div` + padding-top: 16px; + border-top: 1px solid #e0e7ea; + margin-top: 30px; + + .bp4-button { + min-width: 70px; + + + .bp4-button { + margin-left: 10px; + } + } +`; diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormBoot.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormBoot.tsx new file mode 100644 index 0000000000..c416f69c4e --- /dev/null +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormBoot.tsx @@ -0,0 +1,41 @@ +// @ts-nocheck +import React from 'react'; +import classNames from 'classnames'; +import { CLASSES } from '@/constants/classes'; +import { useSettings } from '@/hooks/query'; +import PreferencesPageLoader from '../PreferencesPageLoader'; + +const PreferencesCreditNotesFormContext = React.createContext(); + +function PreferencesCreditNotesBoot({ ...props }) { + // Fetches organization settings. + const { isLoading: isSettingsLoading } = useSettings(); + + // Provider state. + const provider = { + organization: {}, + }; + + // Detarmines whether if any query is loading. + const isLoading = isSettingsLoading; + + return ( +
+ {isLoading ? ( + + ) : ( + + )} +
+ ); +} + +const usePreferencesCreditNotesFormContext = () => + React.useContext(PreferencesCreditNotesFormContext); + +export { PreferencesCreditNotesBoot, usePreferencesCreditNotesFormContext }; diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx new file mode 100644 index 0000000000..045ffbbc5e --- /dev/null +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx @@ -0,0 +1,69 @@ +// @ts-nocheck +import React, { useEffect } from 'react'; +import intl from 'react-intl-universal'; +import { Formik } from 'formik'; +import { Intent } from '@blueprintjs/core'; + +import { AppToaster } from '@/components'; +import { PreferencesCreditNotesFormSchema } from './PreferencesCreditNotesForm.schema'; +import { usePreferencesInvoiceFormContext } from './PreferencesCreditNotesFormBoot'; +import { PreferencesCreditNotesForm } from './PreferencesCreditNotesForm'; +import withDashboardActions from '@/containers/Dashboard/withDashboardActions'; + +import { compose, transformToForm } from '@/utils'; + +const defaultValues = { + termsConditions: '', + customerNotes: '', +}; + +/** + * Preferences - . + */ +function PreferencesCreditNotesFormPageRoot({ + // #withDashboardActions + changePreferencesPageTitle, +}) { + const { organization } = usePreferencesInvoiceFormContext(); + + useEffect(() => { + changePreferencesPageTitle(intl.get('preferences.estimates')); + }, [changePreferencesPageTitle]); + + // Initial values. + const initialValues = { + ...defaultValues, + ...transformToForm(organization.metadata, defaultValues), + }; + // Handle the form submit. + const handleFormSubmit = (values, { setSubmitting }) => { + // Handle request success. + const onSuccess = (response) => { + AppToaster.show({ + message: intl.get('preferences.estimates.success_message'), + intent: Intent.SUCCESS, + }); + setSubmitting(false); + }; + // Handle request error. + const onError = () => { + setSubmitting(false); + }; + // updateOrganization({ ...values }) + // .then(onSuccess) + // .catch(onError); + }; + + return ( + + ); +} + +export const PreferencesCreditNotesFormPage = compose(withDashboardActions)( + PreferencesCreditNotesFormPageRoot, +); diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimates.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimates.tsx new file mode 100644 index 0000000000..2b5af6bdfd --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimates.tsx @@ -0,0 +1,14 @@ +// @ts-nocheck +import { PreferencesEstimatesBoot } from './PreferencesEstimatesFormBoot'; +import PreferencesInvoiceFormPage from './PreferencesEstimatesFormPage'; + +/** + * items preferences. + */ +export default function PreferencesEstimates() { + return ( + + + + ); +} diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.schema.ts b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.schema.ts new file mode 100644 index 0000000000..b6cf3eab68 --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.schema.ts @@ -0,0 +1,9 @@ +// @ts-nocheck +import * as Yup from 'yup'; + +const Schema = Yup.object().shape({ + termsConditions: Yup.string().optional(), + customerNotes: Yup.string().optional(), +}); + +export const PreferencesEstimatesFormSchema = Schema; diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.tsx new file mode 100644 index 0000000000..426797f4d3 --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesForm.tsx @@ -0,0 +1,80 @@ +// @ts-nocheck +import styled from 'styled-components'; +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'; + +/** + * Preferences estimates form. + */ +export function PreferencesEstimatesForm({ isSubmitting }) { + const history = useHistory(); + + // Handle close click. + const handleCloseClick = () => { + history.go(-1); + }; + + return ( +
+ {/* ---------- Terms & Conditions ---------- */} + } + labelInfo={} + fastField={true} + > + + + + {/* ---------- Customer Notes ---------- */} + } + fastField={true} + > + + + + + + + +
+ ); +} + +const CardFooterActions = styled.div` + padding-top: 16px; + border-top: 1px solid #e0e7ea; + margin-top: 30px; + + .bp4-button { + min-width: 70px; + + + .bp4-button { + margin-left: 10px; + } + } +`; diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormBoot.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormBoot.tsx new file mode 100644 index 0000000000..e444c59983 --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormBoot.tsx @@ -0,0 +1,41 @@ +// @ts-nocheck +import React from 'react'; +import classNames from 'classnames'; +import { CLASSES } from '@/constants/classes'; +import { useSettings } from '@/hooks/query'; +import PreferencesPageLoader from '../PreferencesPageLoader'; + +const PreferencesEstimatesFormContext = React.createContext(); + +function PreferencesEstimatesBoot({ ...props }) { + // Fetches organization settings. + const { isLoading: isSettingsLoading } = useSettings(); + + // Provider state. + const provider = { + organization: {}, + }; + + // Detarmines whether if any query is loading. + const isLoading = isSettingsLoading; + + return ( +
+ {isLoading ? ( + + ) : ( + + )} +
+ ); +} + +const usePreferencesEstimatesFormContext = () => + React.useContext(PreferencesEstimatesFormContext); + +export { PreferencesEstimatesBoot, usePreferencesEstimatesFormContext }; diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx new file mode 100644 index 0000000000..b74279741d --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx @@ -0,0 +1,69 @@ +// @ts-nocheck +import React, { useEffect } from 'react'; +import intl from 'react-intl-universal'; +import { Formik } from 'formik'; +import { Intent } from '@blueprintjs/core'; + +import { AppToaster } from '@/components'; +import { PreferencesEstimatesFormSchema } from './PreferencesEstimatesForm.schema'; +import { usePreferencesInvoiceFormContext } from './PreferencesEstimatesFormBoot'; +import { PreferencesEstimatesForm } from './PreferencesEstimatesForm'; +import withDashboardActions from '@/containers/Dashboard/withDashboardActions'; + +import { compose, transformToForm } from '@/utils'; + +const defaultValues = { + termsConditions: '', + customerNotes: '', +}; + +/** + * Preferences - . + */ +function PreferencesEstimatesFormPageRoot({ + // #withDashboardActions + changePreferencesPageTitle, +}) { + const { organization } = usePreferencesInvoiceFormContext(); + + useEffect(() => { + changePreferencesPageTitle(intl.get('preferences.estimates')); + }, [changePreferencesPageTitle]); + + // Initial values. + const initialValues = { + ...defaultValues, + ...transformToForm(organization.metadata, defaultValues), + }; + // Handle the form submit. + const handleFormSubmit = (values, { setSubmitting }) => { + // Handle request success. + const onSuccess = (response) => { + AppToaster.show({ + message: intl.get('preferences.estimates.success_message'), + intent: Intent.SUCCESS, + }); + setSubmitting(false); + }; + // Handle request error. + const onError = () => { + setSubmitting(false); + }; + // updateOrganization({ ...values }) + // .then(onSuccess) + // .catch(onError); + }; + + return ( + + ); +} + +export const PreferencesEstimatesFormPage = compose(withDashboardActions)( + PreferencesEstimatesFormPageRoot, +); diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceForm.schema.ts b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceForm.schema.ts new file mode 100644 index 0000000000..be7bead85f --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceForm.schema.ts @@ -0,0 +1,9 @@ +// @ts-nocheck +import * as Yup from 'yup'; + +const Schema = Yup.object().shape({ + termsConditions: Yup.string().optional(), + customerNotes: Yup.string().optional(), +}); + +export const PreferencesInvoiceFormSchema = Schema; diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx new file mode 100644 index 0000000000..b4983531a6 --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx @@ -0,0 +1,41 @@ +// @ts-nocheck +import React from 'react'; +import classNames from 'classnames'; +import { CLASSES } from '@/constants/classes'; +import { useSettings } from '@/hooks/query'; +import PreferencesPageLoader from '../PreferencesPageLoader'; + +const PreferencesInvoiceFormContext = React.createContext(); + +function PreferencesInvoicesBoot({ ...props }) { + // Fetches organization settings. + const { isLoading: isSettingsLoading } = useSettings(); + + // Provider state. + const provider = { + organization: {}, + }; + + // Detarmines whether if any query is loading. + const isLoading = isSettingsLoading; + + return ( +
+ {isLoading ? ( + + ) : ( + + )} +
+ ); +} + +const usePreferencesInvoiceFormContext = () => + React.useContext(PreferencesInvoiceFormContext); + +export { PreferencesInvoicesBoot, usePreferencesInvoiceFormContext }; diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx new file mode 100644 index 0000000000..ddf74b02ff --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx @@ -0,0 +1,67 @@ +// @ts-nocheck +import React, { useEffect } from 'react'; +import intl from 'react-intl-universal'; +import { Formik } from 'formik'; +import { Intent } from '@blueprintjs/core'; + +import { AppToaster } from '@/components'; +import { PreferencesInvoiceFormSchema } from './PreferencesInvoiceForm.schema'; +import { usePreferencesInvoiceFormContext } from './PreferencesInvoiceFormBoot'; +import { PreferencesGeneralForm } from './PreferencesInvoicesForm'; +import withDashboardActions from '@/containers/Dashboard/withDashboardActions'; + +import { compose, transformToForm } from '@/utils'; + +const defaultValues = { + termsConditions: '', + customerNotes: '', +}; + +/** + * Preferences - Invoices. + */ +function PreferencesInvoiceFormPage({ + // #withDashboardActions + changePreferencesPageTitle, +}) { + const { organization } = usePreferencesInvoiceFormContext(); + + useEffect(() => { + changePreferencesPageTitle(intl.get('preferences.invoices')); + }, [changePreferencesPageTitle]); + + // Initial values. + const initialValues = { + ...defaultValues, + ...transformToForm(organization.metadata, defaultValues), + }; + // Handle the form submit. + const handleFormSubmit = (values, { setSubmitting }) => { + // Handle request success. + const onSuccess = (response) => { + AppToaster.show({ + message: intl.get('preferences.invoices.success_message'), + intent: Intent.SUCCESS, + }); + setSubmitting(false); + }; + // Handle request error. + const onError = () => { + setSubmitting(false); + }; + // updateOrganization({ ...values }) + // .then(onSuccess) + // .catch(onError); + }; + + return ( + + ); +} + +export default compose(withDashboardActions)(PreferencesInvoiceFormPage); diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoices.tsx b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoices.tsx new file mode 100644 index 0000000000..da349ea9a4 --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoices.tsx @@ -0,0 +1,14 @@ +// @ts-nocheck +import { PreferencesInvoicesBoot } from './PreferencesInvoiceFormBoot'; +import PreferencesInvoiceFormPage from './PreferencesInvoiceFormPage'; + +/** + * items preferences. + */ +export default function PreferencesInvoices() { + return ( + + + + ); +} diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx new file mode 100644 index 0000000000..0e2b44f518 --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx @@ -0,0 +1,81 @@ +// @ts-nocheck +import styled from 'styled-components'; +import { Form } from 'formik'; +import { Button, Intent } from '@blueprintjs/core'; +import { useHistory } from 'react-router-dom'; + +import { + FieldRequiredHint, + FormattedMessage as T, + FFormGroup, + FInputGroup, + FTextArea, +} from '@/components'; + +/** + * Preferences general form. + */ +export function PreferencesGeneralForm({ isSubmitting }) { + const history = useHistory(); + + // Handle close click. + const handleCloseClick = () => { + history.go(-1); + }; + + return ( +
+ {/* ---------- Terms & Conditions ---------- */} + } + labelInfo={} + fastField={true} + > + + + + {/* ---------- Customer Notes ---------- */} + } + fastField={true} + > + + + + + + + +
+ ); +} + +const CardFooterActions = styled.div` + padding-top: 16px; + border-top: 1px solid #e0e7ea; + margin-top: 30px; + + .bp4-button { + min-width: 70px; + + + .bp4-button { + margin-left: 10px; + } + } +`; diff --git a/packages/webapp/src/lang/en/index.json b/packages/webapp/src/lang/en/index.json index 4a78b4e76b..f67a6f4788 100644 --- a/packages/webapp/src/lang/en/index.json +++ b/packages/webapp/src/lang/en/index.json @@ -2290,5 +2290,8 @@ "sidebar.new_project": "New Project", "sidebar.new_time_entry": "New Time Entry", "sidebar.project_profitability_summary": "Project Profitability Summary", - "global_error.too_many_requests": "Too many requests" + "global_error.too_many_requests": "Too many requests", + + "pref.invoices.termsConditions.field": "Terms & Conditions", + "pref.invoices.customerNotes.field": "Customer Notes" } diff --git a/packages/webapp/src/routes/preferences.tsx b/packages/webapp/src/routes/preferences.tsx index 775efcf825..5fdcb13e6f 100644 --- a/packages/webapp/src/routes/preferences.tsx +++ b/packages/webapp/src/routes/preferences.tsx @@ -9,6 +9,8 @@ import SMSIntegration from '../containers/Preferences/SMSIntegration'; import DefaultRoute from '../containers/Preferences/DefaultRoute'; import Warehouses from '../containers/Preferences/Warehouses'; import Branches from '../containers/Preferences/Branches'; +import Invoices from '../containers/Preferences/Invoices/PreferencesInvoices'; + const BASE_URL = '/preferences'; @@ -23,6 +25,16 @@ export default [ component: Users, exact: true, }, + { + path: `${BASE_URL}/invoices`, + component: Invoices, + exact: true, + }, + { + path: `${BASE_URL}/credit-notes`, + component: CreditNotes, + exact: true, + }, { path: `${BASE_URL}/roles`, component: Roles, From 217321380a579d8f9cca8cfd4e7e44530527023b Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Thu, 14 Dec 2023 20:47:52 +0200 Subject: [PATCH 2/6] feat: wip default message to sales transactions. --- .../webapp/src/constants/preferencesMenu.tsx | 12 +++ .../CreditNotes/PreferencesCreditNotes.tsx | 6 +- .../PreferencesCreditNotesForm.schema.ts | 2 +- .../PreferencesCreditNotesForm.tsx | 4 +- .../PreferencesCreditNotesFormBoot.tsx | 26 +++++-- .../PreferencesCreditNotesFormPage.tsx | 8 +- .../Estimates/PreferencesEstimates.tsx | 8 +- .../PreferencesEstimatesFormPage.tsx | 4 +- .../Invoices/PreferencesInvoiceFormBoot.tsx | 22 ++++-- .../Invoices/PreferencesInvoiceFormPage.tsx | 4 +- .../Invoices/PreferencesInvoicesForm.tsx | 5 +- .../Receipts/PreferencesReceipts.tsx | 14 ++++ .../PreferencesReceiptsForm.schema.ts | 9 +++ .../Receipts/PreferencesReceiptsForm.tsx | 78 +++++++++++++++++++ .../Receipts/PreferencesReceiptsFormBoot.tsx | 56 +++++++++++++ .../Receipts/PreferencesReceiptsFormPage.tsx | 69 ++++++++++++++++ packages/webapp/src/lang/en/index.json | 20 ++++- packages/webapp/src/routes/preferences.tsx | 16 +++- 18 files changed, 325 insertions(+), 38 deletions(-) create mode 100644 packages/webapp/src/containers/Preferences/Receipts/PreferencesReceipts.tsx create mode 100644 packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.schema.ts create mode 100644 packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.tsx create mode 100644 packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormBoot.tsx create mode 100644 packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormPage.tsx diff --git a/packages/webapp/src/constants/preferencesMenu.tsx b/packages/webapp/src/constants/preferencesMenu.tsx index 562cce1b17..2a7377bf04 100644 --- a/packages/webapp/src/constants/preferencesMenu.tsx +++ b/packages/webapp/src/constants/preferencesMenu.tsx @@ -12,10 +12,22 @@ export default [ text: , href: '/preferences/users', }, + { + text: 'Estimates', + href: '/preferences/estimates', + }, { text: 'Invoices', href: '/preferences/invoices', }, + { + text: 'Receipts', + href: '/preferences/receipts', + }, + { + text: 'Credit Notes', + href: '/preferences/credit-notes', + }, { text: , href: '/preferences/currencies', diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx index ee17533989..d5d43c86a5 100644 --- a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx @@ -1,14 +1,14 @@ // @ts-nocheck import { PreferencesCreditNotesBoot } from './PreferencesCreditNotesFormBoot'; -import PreferencesInvoiceFormPage from './PreferencesCreditNotesFormPage'; +import { PreferencesCreditNotesFormPage } from './PreferencesCreditNotesFormPage'; /** * items preferences. */ -export default function PreferencesCreditNotes() { +export function PreferencesCreditNotes() { return ( - + ); } diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.schema.ts b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.schema.ts index b6cf3eab68..0e39015914 100644 --- a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.schema.ts +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.schema.ts @@ -6,4 +6,4 @@ const Schema = Yup.object().shape({ customerNotes: Yup.string().optional(), }); -export const PreferencesEstimatesFormSchema = Schema; +export const PreferencesCreditNotesFormSchema = Schema; diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx index 17fc18c0d2..2796a04a0d 100644 --- a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx @@ -27,7 +27,7 @@ export function PreferencesCreditNotesForm({ isSubmitting }) { {/* ---------- Terms & Conditions ---------- */} } + label={} labelInfo={} fastField={true} > @@ -42,7 +42,7 @@ export function PreferencesCreditNotesForm({ isSubmitting }) { {/* ---------- Customer Notes ---------- */} } + label={} fastField={true} > - {isLoading ? ( - - ) : ( - - )} + + {isLoading ? ( + + ) : ( + + )} + ); } +const PreferencesCreditNotesCard = styled(Card)` + padding: 25px; + + .bp4-form-group { + max-width: 600px; + } +`; + const usePreferencesCreditNotesFormContext = () => React.useContext(PreferencesCreditNotesFormContext); diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx index 045ffbbc5e..4121c7d987 100644 --- a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx @@ -6,7 +6,7 @@ import { Intent } from '@blueprintjs/core'; import { AppToaster } from '@/components'; import { PreferencesCreditNotesFormSchema } from './PreferencesCreditNotesForm.schema'; -import { usePreferencesInvoiceFormContext } from './PreferencesCreditNotesFormBoot'; +import { usePreferencesCreditNotesFormContext } from './PreferencesCreditNotesFormBoot'; import { PreferencesCreditNotesForm } from './PreferencesCreditNotesForm'; import withDashboardActions from '@/containers/Dashboard/withDashboardActions'; @@ -18,16 +18,16 @@ const defaultValues = { }; /** - * Preferences - . + * Preferences - Credit Notes. */ function PreferencesCreditNotesFormPageRoot({ // #withDashboardActions changePreferencesPageTitle, }) { - const { organization } = usePreferencesInvoiceFormContext(); + const { organization } = usePreferencesCreditNotesFormContext(); useEffect(() => { - changePreferencesPageTitle(intl.get('preferences.estimates')); + changePreferencesPageTitle(intl.get('preferences.creditNotes')); }, [changePreferencesPageTitle]); // Initial values. diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimates.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimates.tsx index 2b5af6bdfd..d7a8b484da 100644 --- a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimates.tsx +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimates.tsx @@ -1,14 +1,14 @@ // @ts-nocheck import { PreferencesEstimatesBoot } from './PreferencesEstimatesFormBoot'; -import PreferencesInvoiceFormPage from './PreferencesEstimatesFormPage'; +import { PreferencesEstimatesFormPage } from './PreferencesEstimatesFormPage'; /** - * items preferences. + * Estimates preferences. */ -export default function PreferencesEstimates() { +export function PreferencesEstimates() { return ( - + ); } diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx index b74279741d..6dedd912bb 100644 --- a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx @@ -6,7 +6,7 @@ import { Intent } from '@blueprintjs/core'; import { AppToaster } from '@/components'; import { PreferencesEstimatesFormSchema } from './PreferencesEstimatesForm.schema'; -import { usePreferencesInvoiceFormContext } from './PreferencesEstimatesFormBoot'; +import { usePreferencesEstimatesFormContext } from './PreferencesEstimatesFormBoot'; import { PreferencesEstimatesForm } from './PreferencesEstimatesForm'; import withDashboardActions from '@/containers/Dashboard/withDashboardActions'; @@ -24,7 +24,7 @@ function PreferencesEstimatesFormPageRoot({ // #withDashboardActions changePreferencesPageTitle, }) { - const { organization } = usePreferencesInvoiceFormContext(); + const { organization } = usePreferencesEstimatesFormContext(); useEffect(() => { changePreferencesPageTitle(intl.get('preferences.estimates')); diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx index b4983531a6..03d9a31a4c 100644 --- a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormBoot.tsx @@ -1,9 +1,11 @@ // @ts-nocheck import React from 'react'; import classNames from 'classnames'; +import styled from 'styled-components'; import { CLASSES } from '@/constants/classes'; import { useSettings } from '@/hooks/query'; import PreferencesPageLoader from '../PreferencesPageLoader'; +import { Card } from '@/components'; const PreferencesInvoiceFormContext = React.createContext(); @@ -26,15 +28,25 @@ function PreferencesInvoicesBoot({ ...props }) { CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_ACCOUNTANT, )} > - {isLoading ? ( - - ) : ( - - )} + + {isLoading ? ( + + ) : ( + + )} + ); } +const PreferencesInvoicesCard = styled(Card)` + padding: 25px; + + .bp4-form-group{ + max-width: 600px; + } +`; + const usePreferencesInvoiceFormContext = () => React.useContext(PreferencesInvoiceFormContext); diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx index ddf74b02ff..6c364cb7e9 100644 --- a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoiceFormPage.tsx @@ -7,7 +7,7 @@ import { Intent } from '@blueprintjs/core'; import { AppToaster } from '@/components'; import { PreferencesInvoiceFormSchema } from './PreferencesInvoiceForm.schema'; import { usePreferencesInvoiceFormContext } from './PreferencesInvoiceFormBoot'; -import { PreferencesGeneralForm } from './PreferencesInvoicesForm'; +import { PreferencesInvoicesForm } from './PreferencesInvoicesForm'; import withDashboardActions from '@/containers/Dashboard/withDashboardActions'; import { compose, transformToForm } from '@/utils'; @@ -59,7 +59,7 @@ function PreferencesInvoiceFormPage({ initialValues={initialValues} validationSchema={PreferencesInvoiceFormSchema} onSubmit={handleFormSubmit} - component={PreferencesGeneralForm} + component={PreferencesInvoicesForm} /> ); } diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx index 0e2b44f518..5beec5e0c5 100644 --- a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx @@ -5,17 +5,15 @@ import { Button, Intent } from '@blueprintjs/core'; import { useHistory } from 'react-router-dom'; import { - FieldRequiredHint, FormattedMessage as T, FFormGroup, - FInputGroup, FTextArea, } from '@/components'; /** * Preferences general form. */ -export function PreferencesGeneralForm({ isSubmitting }) { +export function PreferencesInvoicesForm({ isSubmitting }) { const history = useHistory(); // Handle close click. @@ -29,7 +27,6 @@ export function PreferencesGeneralForm({ isSubmitting }) { } - labelInfo={} fastField={true} > + + + ); +} diff --git a/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.schema.ts b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.schema.ts new file mode 100644 index 0000000000..f28cc94075 --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.schema.ts @@ -0,0 +1,9 @@ +// @ts-nocheck +import * as Yup from 'yup'; + +const Schema = Yup.object().shape({ + termsConditions: Yup.string().optional(), + customerNotes: Yup.string().optional(), +}); + +export const PreferencesReceiptsFormSchema = Schema; diff --git a/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.tsx b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.tsx new file mode 100644 index 0000000000..05004c3c58 --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.tsx @@ -0,0 +1,78 @@ +// @ts-nocheck +import styled from 'styled-components'; +import { Form } from 'formik'; +import { Button, Intent } from '@blueprintjs/core'; +import { useHistory } from 'react-router-dom'; + +import { + FormattedMessage as T, + FFormGroup, + FTextArea, +} from '@/components'; + +/** + * Preferences general form. + */ +export function PreferencesReceiptsForm({ isSubmitting }) { + const history = useHistory(); + + // Handle close click. + const handleCloseClick = () => { + history.go(-1); + }; + + return ( +
+ {/* ---------- Terms & Conditions ---------- */} + } + fastField={true} + > + + + + {/* ---------- Customer Notes ---------- */} + } + fastField={true} + > + + + + + + + +
+ ); +} + +const CardFooterActions = styled.div` + padding-top: 16px; + border-top: 1px solid #e0e7ea; + margin-top: 30px; + + .bp4-button { + min-width: 70px; + + + .bp4-button { + margin-left: 10px; + } + } +`; diff --git a/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormBoot.tsx b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormBoot.tsx new file mode 100644 index 0000000000..1c2244edaf --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormBoot.tsx @@ -0,0 +1,56 @@ +// @ts-nocheck +import React from 'react'; +import classNames from 'classnames'; +import styled from 'styled-components'; +import { CLASSES } from '@/constants/classes'; +import { useSettings } from '@/hooks/query'; +import PreferencesPageLoader from '../PreferencesPageLoader'; +import { Card } from '@/components'; + +const PreferencesReceiptsFormContext = React.createContext(); + +function PreferencesReceiptsBoot({ ...props }) { + // Fetches organization settings. + const { isLoading: isSettingsLoading } = useSettings(); + + // Provider state. + const provider = { + organization: {}, + }; + + // Detarmines whether if any query is loading. + const isLoading = isSettingsLoading; + + return ( +
+ + {isLoading ? ( + + ) : ( + + )} + +
+ ); +} + +const PreferencesReceiptsCard = styled(Card)` + padding: 25px; + + .bp4-form-group { + max-width: 600px; + } +`; + +const usePreferencesReceiptsFormContext = () => + React.useContext(PreferencesReceiptsFormContext); + +export { PreferencesReceiptsBoot, usePreferencesReceiptsFormContext }; diff --git a/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormPage.tsx b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormPage.tsx new file mode 100644 index 0000000000..0033f1187e --- /dev/null +++ b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormPage.tsx @@ -0,0 +1,69 @@ +// @ts-nocheck +import React, { useEffect } from 'react'; +import intl from 'react-intl-universal'; +import { Formik } from 'formik'; +import { Intent } from '@blueprintjs/core'; + +import { AppToaster } from '@/components'; +import { PreferencesReceiptsFormSchema } from './PreferencesReceiptsForm.schema'; +import { usePreferencesReceiptsFormContext } from './PreferencesReceiptsFormBoot'; +import { PreferencesReceiptsForm } from './PreferencesReceiptsForm'; +import withDashboardActions from '@/containers/Dashboard/withDashboardActions'; + +import { compose, transformToForm } from '@/utils'; + +const defaultValues = { + termsConditions: '', + customerNotes: '', +}; + +/** + * Preferences - Receipts. + */ +function PreferencesReceiptsFormPageRoot({ + // #withDashboardActions + changePreferencesPageTitle, +}) { + const { organization } = usePreferencesReceiptsFormContext(); + + useEffect(() => { + changePreferencesPageTitle(intl.get('preferences.receipts')); + }, [changePreferencesPageTitle]); + + // Initial values. + const initialValues = { + ...defaultValues, + ...transformToForm(organization.metadata, defaultValues), + }; + // Handle the form submit. + const handleFormSubmit = (values, { setSubmitting }) => { + // Handle request success. + const onSuccess = (response) => { + AppToaster.show({ + message: intl.get('preferences.receipts.success_message'), + intent: Intent.SUCCESS, + }); + setSubmitting(false); + }; + // Handle request error. + const onError = () => { + setSubmitting(false); + }; + // updateOrganization({ ...values }) + // .then(onSuccess) + // .catch(onError); + }; + + return ( + + ); +} + +export const PreferencesReceiptsFormPage = compose(withDashboardActions)( + PreferencesReceiptsFormPageRoot, +); diff --git a/packages/webapp/src/lang/en/index.json b/packages/webapp/src/lang/en/index.json index f67a6f4788..1832b3a5f6 100644 --- a/packages/webapp/src/lang/en/index.json +++ b/packages/webapp/src/lang/en/index.json @@ -2070,7 +2070,7 @@ "project_task.dialog.edit_success_message": "The task has been edited successfully.", "project_task.action.edit_task": "Edit Task", "project_task.action.delete_task": "Delete Task", -"project_task.rate": "{rate} / hour", + "project_task.rate": "{rate} / hour", "project_task.fixed_price": "Fixed price", "project_task.non_chargable": "Non-chargeable", "project_task.estimate_hours": "• {estimate_hours}h 0m estimated", @@ -2293,5 +2293,19 @@ "global_error.too_many_requests": "Too many requests", "pref.invoices.termsConditions.field": "Terms & Conditions", - "pref.invoices.customerNotes.field": "Customer Notes" -} + "pref.invoices.customerNotes.field": "Customer Notes", + + "pref.creditNotes.termsConditions.field": "Terms & Conditions", + "pref.creditNotes.customerNotes.field": "Customer Notes", + + "pref.estimates.termsConditions.field": "Terms & Conditions", + "pref.estimates.customerNotes.field": "Customer Notes", + + "pref.receipts.termsConditions.field": "Terms & Conditions", + "pref.receipts.customerNotes.field": "Customer Notes", + + "preferences.invoices": "Invoices", + "preferences.estimates": "Estimates", + "preferences.creditNotes": "Credit Notes", + "preferences.receipts": "Receipts" +} \ No newline at end of file diff --git a/packages/webapp/src/routes/preferences.tsx b/packages/webapp/src/routes/preferences.tsx index 5fdcb13e6f..8031230edb 100644 --- a/packages/webapp/src/routes/preferences.tsx +++ b/packages/webapp/src/routes/preferences.tsx @@ -10,7 +10,9 @@ import DefaultRoute from '../containers/Preferences/DefaultRoute'; import Warehouses from '../containers/Preferences/Warehouses'; import Branches from '../containers/Preferences/Branches'; import Invoices from '../containers/Preferences/Invoices/PreferencesInvoices'; - +import { PreferencesCreditNotes } from '../containers/Preferences/CreditNotes/PreferencesCreditNotes'; +import { PreferencesEstimates } from '@/containers/Preferences/Estimates/PreferencesEstimates'; +import{ PreferencesReceipts } from '@/containers/Preferences/Receipts/PreferencesReceipts' const BASE_URL = '/preferences'; @@ -32,7 +34,17 @@ export default [ }, { path: `${BASE_URL}/credit-notes`, - component: CreditNotes, + component: PreferencesCreditNotes, + exact: true, + }, + { + path: `${BASE_URL}/estimates`, + component: PreferencesEstimates, + exact: true, + }, + { + path: `${BASE_URL}/receipts`, + component: PreferencesReceipts, exact: true, }, { From ad53ddb9ddb49d9eaa5ccd48b53f26d54832d1aa Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Fri, 15 Dec 2023 20:15:42 +0200 Subject: [PATCH 3/6] feat: inject default message value to sales forms --- packages/server/src/data/options.ts | 24 ++++++++++++ .../CreditNoteForm/CreditNoteForm.tsx | 35 +++++++++-------- .../Estimates/EstimateForm/EstimateForm.tsx | 38 ++++++++++--------- .../Invoices/InvoiceForm/InvoiceForm.tsx | 8 +++- .../Receipts/ReceiptForm/ReceiptForm.tsx | 35 ++++++++--------- .../Sales/Receipts/ReceiptForm/utils.tsx | 3 +- 6 files changed, 89 insertions(+), 54 deletions(-) diff --git a/packages/server/src/data/options.ts b/packages/server/src/data/options.ts index 023628ef86..ae35fa5dab 100644 --- a/packages/server/src/data/options.ts +++ b/packages/server/src/data/options.ts @@ -59,6 +59,12 @@ export default { auto_increment: { type: 'boolean', }, + customer_notes: { + type: 'string', + }, + terms_conditions: { + type: 'string', + }, }, sales_receipts: { next_number: { @@ -73,6 +79,12 @@ export default { preferred_deposit_account: { type: 'number', }, + receipt_message: { + type: 'string', + }, + terms_conditions: { + type: 'string', + }, }, sales_invoices: { next_number: { @@ -84,6 +96,12 @@ export default { auto_increment: { type: 'boolean', }, + customer_notes: { + type: 'string', + }, + terms_conditions: { + type: 'string', + }, }, payment_receives: { next_number: { @@ -147,6 +165,12 @@ export default { auto_increment: { type: 'boolean', }, + customer_notes: { + type: 'string', + }, + terms_conditions: { + type: 'string', + }, }, vendor_credit: { next_number: { diff --git a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteForm.tsx b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteForm.tsx index ec84670617..1d51ecbc6e 100644 --- a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteForm.tsx +++ b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteForm.tsx @@ -5,7 +5,7 @@ import classNames from 'classnames'; import { useHistory } from 'react-router-dom'; import { Formik, Form } from 'formik'; import { Intent } from '@blueprintjs/core'; -import { isEmpty } from 'lodash'; +import { defaultTo, isEmpty } from 'lodash'; import { CLASSES } from '@/constants/classes'; import { CreateCreditNoteFormSchema, @@ -48,6 +48,8 @@ function CreditNoteForm({ creditAutoIncrement, creditNumberPrefix, creditNextNumber, + creditCustomerNotes, + creditTermsConditions, // #withCurrentOrganization organization: { base_currency }, @@ -68,22 +70,21 @@ function CreditNoteForm({ const creditNumber = transactionNumber(creditNumberPrefix, creditNextNumber); // Initial values. - const initialValues = React.useMemo( - () => ({ - ...(!isEmpty(creditNote) - ? { ...transformToEditForm(creditNote) } - : { - ...defaultCreditNote, - ...(creditAutoIncrement && { - credit_note_number: creditNumber, - }), - entries: orderingLinesIndexes(defaultCreditNote.entries), - currency_code: base_currency, - ...newCreditNote, + const initialValues = { + ...(!isEmpty(creditNote) + ? { ...transformToEditForm(creditNote) } + : { + ...defaultCreditNote, + ...(creditAutoIncrement && { + credit_note_number: creditNumber, }), - }), - [], - ); + entries: orderingLinesIndexes(defaultCreditNote.entries), + currency_code: base_currency, + terms_conditions: defaultTo(creditTermsConditions, ''), + note: defaultTo(creditCustomerNotes, ''), + ...newCreditNote, + }), + }; // Handles form submit. const handleFormSubmit = ( @@ -178,6 +179,8 @@ export default compose( creditAutoIncrement: creditNoteSettings?.autoIncrement, creditNextNumber: creditNoteSettings?.nextNumber, creditNumberPrefix: creditNoteSettings?.numberPrefix, + creditCustomerNotes: creditNoteSettings?.customerNotes, + creditTermsConditions: creditNoteSettings?.termsConditions, })), withCurrentOrganization(), )(CreditNoteForm); diff --git a/packages/webapp/src/containers/Sales/Estimates/EstimateForm/EstimateForm.tsx b/packages/webapp/src/containers/Sales/Estimates/EstimateForm/EstimateForm.tsx index a4db1cfff7..f9cd246736 100644 --- a/packages/webapp/src/containers/Sales/Estimates/EstimateForm/EstimateForm.tsx +++ b/packages/webapp/src/containers/Sales/Estimates/EstimateForm/EstimateForm.tsx @@ -4,7 +4,7 @@ import intl from 'react-intl-universal'; import classNames from 'classnames'; import { Formik, Form } from 'formik'; import { Intent } from '@blueprintjs/core'; -import { sumBy, isEmpty } from 'lodash'; +import { sumBy, isEmpty, defaultTo } from 'lodash'; import { useHistory } from 'react-router-dom'; import { CLASSES } from '@/constants/classes'; @@ -43,6 +43,8 @@ function EstimateForm({ estimateNextNumber, estimateNumberPrefix, estimateAutoIncrementMode, + estimateCustomerNotes, + estimateTermsConditions, // #withCurrentOrganization organization: { base_currency }, @@ -60,25 +62,23 @@ function EstimateForm({ estimateNumberPrefix, estimateNextNumber, ); - // Initial values in create and edit mode. - const initialValues = useMemo( - () => ({ - ...(!isEmpty(estimate) - ? { ...transformToEditForm(estimate) } - : { - ...defaultEstimate, - // If the auto-increment mode is enabled, take the next estimate - // number from the settings. - ...(estimateAutoIncrementMode && { - estimate_number: estimateNumber, - }), - entries: orderingLinesIndexes(defaultEstimate.entries), - currency_code: base_currency, + const initialValues = { + ...(!isEmpty(estimate) + ? { ...transformToEditForm(estimate) } + : { + ...defaultEstimate, + // If the auto-increment mode is enabled, take the next estimate + // number from the settings. + ...(estimateAutoIncrementMode && { + estimate_number: estimateNumber, }), - }), - [estimate, estimateNumber, estimateAutoIncrementMode, base_currency], - ); + entries: orderingLinesIndexes(defaultEstimate.entries), + currency_code: base_currency, + terms_conditions: defaultTo(estimateTermsConditions, ''), + note: defaultTo(estimateCustomerNotes, ''), + }), + }; // Handles form submit. const handleFormSubmit = ( @@ -181,6 +181,8 @@ export default compose( estimateNextNumber: estimatesSettings?.nextNumber, estimateNumberPrefix: estimatesSettings?.numberPrefix, estimateAutoIncrementMode: estimatesSettings?.autoIncrement, + estimateCustomerNotes: estimatesSettings?.customerNotes, + estimateTermsConditions: estimatesSettings?.termsConditions, })), withCurrentOrganization(), )(EstimateForm); diff --git a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceForm.tsx b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceForm.tsx index a8463619b8..c3a447d112 100644 --- a/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceForm.tsx +++ b/packages/webapp/src/containers/Sales/Invoices/InvoiceForm/InvoiceForm.tsx @@ -4,7 +4,7 @@ import intl from 'react-intl-universal'; import classNames from 'classnames'; import { Formik, Form } from 'formik'; import { Intent } from '@blueprintjs/core'; -import { sumBy, isEmpty } from 'lodash'; +import { sumBy, isEmpty, defaultTo } from 'lodash'; import { useHistory } from 'react-router-dom'; import { CLASSES } from '@/constants/classes'; import { @@ -44,6 +44,8 @@ function InvoiceForm({ invoiceNextNumber, invoiceNumberPrefix, invoiceAutoIncrementMode, + invoiceCustomerNotes, + invoiceTermsConditions, // #withCurrentOrganization organization: { base_currency }, @@ -79,6 +81,8 @@ function InvoiceForm({ }), entries: orderingLinesIndexes(defaultInvoice.entries), currency_code: base_currency, + invoice_message: defaultTo(invoiceCustomerNotes, ''), + terms_conditions: defaultTo(invoiceTermsConditions, ''), ...newInvoice, }), }; @@ -192,6 +196,8 @@ export default compose( invoiceNextNumber: invoiceSettings?.nextNumber, invoiceNumberPrefix: invoiceSettings?.numberPrefix, invoiceAutoIncrementMode: invoiceSettings?.autoIncrement, + invoiceCustomerNotes: invoiceSettings?.customerNotes, + invoiceTermsConditions: invoiceSettings?.termsConditions, })), withCurrentOrganization(), )(InvoiceForm); diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.tsx index 75a8b9665d..ca7dd26f6c 100644 --- a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.tsx +++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptForm.tsx @@ -1,5 +1,4 @@ // @ts-nocheck -import React, { useMemo } from 'react'; import intl from 'react-intl-universal'; import classNames from 'classnames'; import { Formik, Form } from 'formik'; @@ -45,6 +44,8 @@ function ReceiptForm({ receiptNextNumber, receiptNumberPrefix, receiptAutoIncrement, + receiptTermsConditions, + receiptMessage, preferredDepositAccount, // #withCurrentOrganization @@ -67,23 +68,21 @@ function ReceiptForm({ receiptNextNumber, ); // Initial values in create and edit mode. - const initialValues = useMemo( - () => ({ - ...(!isEmpty(receipt) - ? { ...transformToEditForm(receipt) } - : { - ...defaultReceipt, - ...(receiptAutoIncrement && { - receipt_number: nextReceiptNumber, - }), - deposit_account_id: parseInt(preferredDepositAccount), - entries: orderingLinesIndexes(defaultReceipt.entries), - currency_code: base_currency, + const initialValues = { + ...(!isEmpty(receipt) + ? { ...transformToEditForm(receipt) } + : { + ...defaultReceipt, + ...(receiptAutoIncrement && { + receipt_number: nextReceiptNumber, }), - }), - [receipt, preferredDepositAccount, nextReceiptNumber, receiptAutoIncrement], - ); - + deposit_account_id: parseInt(preferredDepositAccount), + entries: orderingLinesIndexes(defaultReceipt.entries), + currency_code: base_currency, + receipt_message: receiptMessage, + terms_conditions: receiptTermsConditions, + }), + }; // Handle the form submit. const handleFormSubmit = ( values, @@ -184,6 +183,8 @@ export default compose( receiptNextNumber: receiptSettings?.nextNumber, receiptNumberPrefix: receiptSettings?.numberPrefix, receiptAutoIncrement: receiptSettings?.autoIncrement, + receiptMessage: receiptSettings?.receiptMessage, + receiptTermsConditions: receiptSettings?.termsConditions, preferredDepositAccount: receiptSettings?.preferredDepositAccount, })), withCurrentOrganization(), diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx index e8c019e7ac..d58cb6179a 100644 --- a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx +++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx @@ -7,7 +7,6 @@ import { omit, first } from 'lodash'; import { useFormikContext } from 'formik'; import { defaultFastFieldShouldUpdate, - transactionNumber, repeatValue, transformToForm, formattedAmount, @@ -50,7 +49,7 @@ export const defaultReceipt = { receipt_date: moment(new Date()).format('YYYY-MM-DD'), reference_no: '', receipt_message: '', - statement: '', + terms_conditions: '', closed: '', branch_id: '', warehouse_id: '', From 6953f7c4a357d12cb24a69ebcf5244767d318ee2 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sat, 16 Dec 2023 19:26:41 +0200 Subject: [PATCH 4/6] feat: assign default default messages on sales transactions --- .../PreferencesCreditNotesForm.tsx | 24 +++++------- .../PreferencesCreditNotesFormPage.tsx | 39 ++++++++++++------- .../Estimates/PreferencesEstimatesForm.tsx | 24 +++++------- .../PreferencesEstimatesFormBoot.tsx | 28 +++++++++---- .../PreferencesEstimatesFormPage.tsx | 32 ++++++++++----- .../Invoices/PreferencesInvoiceFormBoot.tsx | 2 +- .../Invoices/PreferencesInvoiceFormPage.tsx | 33 +++++++++++----- .../Invoices/PreferencesInvoicesForm.tsx | 22 +++++------ .../Receipts/PreferencesReceiptsForm.tsx | 22 +++++------ .../Receipts/PreferencesReceiptsFormBoot.tsx | 2 +- .../Receipts/PreferencesReceiptsFormPage.tsx | 37 ++++++++++++------ packages/webapp/src/lang/en/index.json | 9 ++++- 12 files changed, 163 insertions(+), 111 deletions(-) diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx index 2796a04a0d..c4627a90c2 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,30 +19,29 @@ export function PreferencesCreditNotesForm({ isSubmitting }) { return (
- {/* ---------- Terms & Conditions ---------- */} + {/* ---------- Customer Notes ---------- */} } - labelInfo={} + name={'customerNotes'} + label={} fastField={true} > - {/* ---------- Customer Notes ---------- */} + {/* ---------- Terms & Conditions ---------- */} } + name={'termsConditions'} + label={} fastField={true} > diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormPage.tsx index 4121c7d987..4fc3956c84 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 426797f4d3..7e17acc107 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,30 +19,29 @@ export function PreferencesEstimatesForm({ isSubmitting }) { return ( - {/* ---------- Terms & Conditions ---------- */} + {/* ---------- Customer Notes ---------- */} } - labelInfo={} + name={'customerNotes'} + label={} fastField={true} > - {/* ---------- Customer Notes ---------- */} + {/* ---------- Terms & Conditions ---------- */} } + name={'termsConditions'} + label={} fastField={true} > diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormBoot.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormBoot.tsx index e444c59983..d39d3c8179 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 6dedd912bb..f5241f20ad 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 03d9a31a4c..2cd42db210 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 6c364cb7e9..097b8f996e 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 5beec5e0c5..95fced8e96 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,29 +19,29 @@ export function PreferencesInvoicesForm({ isSubmitting }) { return ( - {/* ---------- Terms & Conditions ---------- */} + {/* ---------- Customer Notes ---------- */} } + name={'customerNotes'} + label={} fastField={true} > - {/* ---------- Customer Notes ---------- */} + {/* ---------- Terms & Conditions ---------- */} } + name={'termsConditions'} + label={} fastField={true} > diff --git a/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.tsx b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.tsx index 05004c3c58..42836de519 100644 --- a/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.tsx +++ b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsForm.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,29 +19,29 @@ export function PreferencesReceiptsForm({ isSubmitting }) { return ( - {/* ---------- Terms & Conditions ---------- */} + {/* ---------- Customer Notes ---------- */} } + name={'receiptMessage'} + label={} fastField={true} > - {/* ---------- Customer Notes ---------- */} + {/* ---------- Terms & Conditions ---------- */} } + name={'termsConditions'} + label={} fastField={true} > diff --git a/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormBoot.tsx b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormBoot.tsx index 1c2244edaf..539980a4ee 100644 --- a/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormBoot.tsx +++ b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormBoot.tsx @@ -15,7 +15,7 @@ function PreferencesReceiptsBoot({ ...props }) { // Provider state. const provider = { - organization: {}, + isSettingsLoading, }; // Detarmines whether if any query is loading. diff --git a/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormPage.tsx b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormPage.tsx index 0033f1187e..f5da0d06a4 100644 --- a/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormPage.tsx +++ b/packages/webapp/src/containers/Preferences/Receipts/PreferencesReceiptsFormPage.tsx @@ -3,18 +3,21 @@ 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 { PreferencesReceiptsFormSchema } from './PreferencesReceiptsForm.schema'; -import { usePreferencesReceiptsFormContext } from './PreferencesReceiptsFormBoot'; import { PreferencesReceiptsForm } from './PreferencesReceiptsForm'; 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 = { termsConditions: '', - customerNotes: '', + receiptMessage: '', }; /** @@ -23,8 +26,12 @@ const defaultValues = { function PreferencesReceiptsFormPageRoot({ // #withDashboardActions changePreferencesPageTitle, + + // #withSettings + receiptSettings, }) { - const { organization } = usePreferencesReceiptsFormContext(); + // Save settings. + const { mutateAsync: saveSettingMutate } = useSaveSettings(); useEffect(() => { changePreferencesPageTitle(intl.get('preferences.receipts')); @@ -33,12 +40,17 @@ function PreferencesReceiptsFormPageRoot({ // Initial values. const initialValues = { ...defaultValues, - ...transformToForm(organization.metadata, defaultValues), + ...transformToForm(receiptSettings, defaultValues), }; // Handle the form submit. const handleFormSubmit = (values, { setSubmitting }) => { + const options = R.compose( + transferObjectOptionsToArray, + transfromToSnakeCase, + )({ salesReceipts: { ...values } }); + // Handle request success. - const onSuccess = (response) => { + const onSuccess = () => { AppToaster.show({ message: intl.get('preferences.receipts.success_message'), intent: Intent.SUCCESS, @@ -49,9 +61,7 @@ function PreferencesReceiptsFormPageRoot({ const onError = () => { setSubmitting(false); }; - // updateOrganization({ ...values }) - // .then(onSuccess) - // .catch(onError); + saveSettingMutate({ options }).then(onSuccess).catch(onError); }; return ( @@ -64,6 +74,9 @@ function PreferencesReceiptsFormPageRoot({ ); } -export const PreferencesReceiptsFormPage = compose(withDashboardActions)( - PreferencesReceiptsFormPageRoot, -); +export const PreferencesReceiptsFormPage = compose( + withDashboardActions, + withSettings(({ receiptSettings }) => ({ + receiptSettings: receiptSettings, + })), +)(PreferencesReceiptsFormPageRoot); diff --git a/packages/webapp/src/lang/en/index.json b/packages/webapp/src/lang/en/index.json index 1832b3a5f6..5522f57d60 100644 --- a/packages/webapp/src/lang/en/index.json +++ b/packages/webapp/src/lang/en/index.json @@ -2302,10 +2302,15 @@ "pref.estimates.customerNotes.field": "Customer Notes", "pref.receipts.termsConditions.field": "Terms & Conditions", - "pref.receipts.customerNotes.field": "Customer Notes", + "pref.receipts.receiptMessage.field": "Receipt Message", "preferences.invoices": "Invoices", "preferences.estimates": "Estimates", "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." } \ No newline at end of file From a862ee9ccf6f737e1e869dd555a0438b7587d87e Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sat, 16 Dec 2023 19:37:20 +0200 Subject: [PATCH 5/6] feat: localize the preferences menu --- packages/webapp/src/constants/preferencesMenu.tsx | 8 ++++---- .../Estimates/PreferencesEstimatesFormPage.tsx | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/webapp/src/constants/preferencesMenu.tsx b/packages/webapp/src/constants/preferencesMenu.tsx index 2a7377bf04..0925532ffc 100644 --- a/packages/webapp/src/constants/preferencesMenu.tsx +++ b/packages/webapp/src/constants/preferencesMenu.tsx @@ -13,19 +13,19 @@ export default [ href: '/preferences/users', }, { - text: 'Estimates', + text: , href: '/preferences/estimates', }, { - text: 'Invoices', + text: , href: '/preferences/invoices', }, { - text: 'Receipts', + text: , href: '/preferences/receipts', }, { - text: 'Credit Notes', + text: , href: '/preferences/credit-notes', }, { diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx index f5241f20ad..e4b05a4c83 100644 --- a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx @@ -9,6 +9,7 @@ import { AppToaster } from '@/components'; import { PreferencesEstimatesFormSchema } from './PreferencesEstimatesForm.schema'; import { PreferencesEstimatesForm } from './PreferencesEstimatesForm'; import withDashboardActions from '@/containers/Dashboard/withDashboardActions'; +import withSettings from '@/containers/Settings/withSettings'; import { transferObjectOptionsToArray } from '../Accountant/utils'; import { compose, transformToForm, transfromToSnakeCase } from '@/utils'; From eb1ff7c1518a2f2f04cb73580c9f7b00afb03253 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sat, 16 Dec 2023 22:34:36 +0200 Subject: [PATCH 6/6] chore: doc comments --- .../Preferences/CreditNotes/PreferencesCreditNotes.tsx | 2 +- .../Preferences/CreditNotes/PreferencesCreditNotesForm.tsx | 2 +- .../Preferences/CreditNotes/PreferencesCreditNotesFormBoot.tsx | 2 +- .../Preferences/Estimates/PreferencesEstimatesFormPage.tsx | 2 +- .../containers/Preferences/Invoices/PreferencesInvoicesForm.tsx | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx index d5d43c86a5..4d2909f0e2 100644 --- a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotes.tsx @@ -3,7 +3,7 @@ import { PreferencesCreditNotesBoot } from './PreferencesCreditNotesFormBoot'; import { PreferencesCreditNotesFormPage } from './PreferencesCreditNotesFormPage'; /** - * items preferences. + * Credit notes preferences. */ export function PreferencesCreditNotes() { return ( diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx index c4627a90c2..649ffa5574 100644 --- a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesForm.tsx @@ -7,7 +7,7 @@ import { useHistory } from 'react-router-dom'; import { FormattedMessage as T, FFormGroup, FTextArea } from '@/components'; /** - * Preferences estimates form. + * Preferences credit notes form. */ export function PreferencesCreditNotesForm({ isSubmitting }) { const history = useHistory(); diff --git a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormBoot.tsx b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormBoot.tsx index fc0f4b892d..0eb34f3d4f 100644 --- a/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormBoot.tsx +++ b/packages/webapp/src/containers/Preferences/CreditNotes/PreferencesCreditNotesFormBoot.tsx @@ -15,7 +15,7 @@ function PreferencesCreditNotesBoot({ ...props }) { // Provider state. const provider = { - organization: {}, + isSettingsLoading, }; // Detarmines whether if any query is loading. const isLoading = isSettingsLoading; diff --git a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx index e4b05a4c83..39d849ed35 100644 --- a/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx +++ b/packages/webapp/src/containers/Preferences/Estimates/PreferencesEstimatesFormPage.tsx @@ -21,7 +21,7 @@ const defaultValues = { }; /** - * Preferences - . + * Preferences estimates form. */ function PreferencesEstimatesFormPageRoot({ // #withDashboardActions diff --git a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx index 95fced8e96..9237c58e8b 100644 --- a/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx +++ b/packages/webapp/src/containers/Preferences/Invoices/PreferencesInvoicesForm.tsx @@ -7,7 +7,7 @@ import { useHistory } from 'react-router-dom'; import { FormattedMessage as T, FFormGroup, FTextArea } from '@/components'; /** - * Preferences general form. + * Invoices preferences form. */ export function PreferencesInvoicesForm({ isSubmitting }) { const history = useHistory();