Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add default customer message and terms conditions to the transactions #291

Merged
merged 6 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/server/src/data/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ export default {
auto_increment: {
type: 'boolean',
},
customer_notes: {
type: 'string',
},
terms_conditions: {
type: 'string',
},
},
sales_receipts: {
next_number: {
Expand All @@ -73,6 +79,12 @@ export default {
preferred_deposit_account: {
type: 'number',
},
receipt_message: {
type: 'string',
},
terms_conditions: {
type: 'string',
},
},
sales_invoices: {
next_number: {
Expand All @@ -84,6 +96,12 @@ export default {
auto_increment: {
type: 'boolean',
},
customer_notes: {
type: 'string',
},
terms_conditions: {
type: 'string',
},
},
payment_receives: {
next_number: {
Expand Down Expand Up @@ -147,6 +165,12 @@ export default {
auto_increment: {
type: 'boolean',
},
customer_notes: {
type: 'string',
},
terms_conditions: {
type: 'string',
},
},
vendor_credit: {
next_number: {
Expand Down
16 changes: 16 additions & 0 deletions packages/webapp/src/constants/preferencesMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ export default [
text: <T id={'users'} />,
href: '/preferences/users',
},
{
text: <T id={'preferences.estimates'} />,
href: '/preferences/estimates',
},
{
text: <T id={'preferences.invoices'} />,
href: '/preferences/invoices',
},
{
text: <T id={'preferences.receipts'} />,
href: '/preferences/receipts',
},
{
text: <T id={'preferences.creditNotes'} />,
href: '/preferences/credit-notes',
},
{
text: <T id={'currencies'} />,
href: '/preferences/currencies',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-nocheck
import { PreferencesCreditNotesBoot } from './PreferencesCreditNotesFormBoot';
import { PreferencesCreditNotesFormPage } from './PreferencesCreditNotesFormPage';

/**
* Credit notes preferences.
*/
export function PreferencesCreditNotes() {
return (
<PreferencesCreditNotesBoot>
<PreferencesCreditNotesFormPage />
</PreferencesCreditNotesBoot>
);
}
Original file line number Diff line number Diff line change
@@ -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 PreferencesCreditNotesFormSchema = Schema;
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// @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 credit notes form.
*/
export function PreferencesCreditNotesForm({ isSubmitting }) {
const history = useHistory();

// Handle close click.
const handleCloseClick = () => {
history.go(-1);
};

return (
<Form>
{/* ---------- Customer Notes ---------- */}
<FFormGroup
name={'customerNotes'}
label={<T id={'pref.creditNotes.customerNotes.field'} />}
fastField={true}
>
<FTextArea
medium={'true'}
name={'customerNotes'}
fastField={true}
fill={true}
/>
</FFormGroup>

{/* ---------- Terms & Conditions ---------- */}
<FFormGroup
name={'termsConditions'}
label={<T id={'pref.creditNotes.termsConditions.field'} />}
fastField={true}
>
<FTextArea
medium={'true'}
name={'termsConditions'}
fastField={true}
fill={true}
/>
</FFormGroup>

<CardFooterActions>
<Button loading={isSubmitting} intent={Intent.PRIMARY} type="submit">
<T id={'save'} />
</Button>
<Button onClick={handleCloseClick}>
<T id={'close'} />
</Button>
</CardFooterActions>
</Form>
);
}

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;
}
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// @ts-nocheck
import React from 'react';
import styled from 'styled-components';
import classNames from 'classnames';
import { CLASSES } from '@/constants/classes';
import { useSettings } from '@/hooks/query';
import PreferencesPageLoader from '../PreferencesPageLoader';
import { Card } from '@/components';

const PreferencesCreditNotesFormContext = React.createContext();

function PreferencesCreditNotesBoot({ ...props }) {
// Fetches organization settings.
const { isLoading: isSettingsLoading } = useSettings();

// Provider state.
const provider = {
isSettingsLoading,
};
// Detarmines whether if any query is loading.
const isLoading = isSettingsLoading;

return (
<div
className={classNames(
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT,
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_ACCOUNTANT,
)}
>
<PreferencesCreditNotesCard>
{isLoading ? (
<PreferencesPageLoader />
) : (
<PreferencesCreditNotesFormContext.Provider
value={provider}
{...props}
/>
)}
</PreferencesCreditNotesCard>
</div>
);
}

const PreferencesCreditNotesCard = styled(Card)`
padding: 25px;

.bp4-form-group {
max-width: 600px;
}
`;

const usePreferencesCreditNotesFormContext = () =>
React.useContext(PreferencesCreditNotesFormContext);

export { PreferencesCreditNotesBoot, usePreferencesCreditNotesFormContext };
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// @ts-nocheck
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 { PreferencesCreditNotesForm } from './PreferencesCreditNotesForm';
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';

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: '',
customerNotes: '',
};

/**
* Preferences - Credit Notes.
*/
function PreferencesCreditNotesFormPageRoot({
// #withDashboardActions
changePreferencesPageTitle,

// #withSettings
creditNoteSettings,
}) {
// Save settings.
const { mutateAsync: saveSettingMutate } = useSaveSettings();

useEffect(() => {
changePreferencesPageTitle(intl.get('preferences.creditNotes'));
}, [changePreferencesPageTitle]);

// Initial values.
const initialValues = {
...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 = () => {
AppToaster.show({
message: intl.get('preferences.credit_notes.success_message'),
intent: Intent.SUCCESS,
});
setSubmitting(false);
};
// Handle request error.
const onError = () => {
setSubmitting(false);
};
saveSettingMutate({ options }).then(onSuccess).catch(onError);
};

return (
<Formik
initialValues={initialValues}
validationSchema={PreferencesCreditNotesFormSchema}
onSubmit={handleFormSubmit}
component={PreferencesCreditNotesForm}
/>
);
}

export const PreferencesCreditNotesFormPage = compose(
withDashboardActions,
withSettings(({ creditNoteSettings }) => ({
creditNoteSettings: creditNoteSettings,
})),
)(PreferencesCreditNotesFormPageRoot);
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// @ts-nocheck
import { PreferencesEstimatesBoot } from './PreferencesEstimatesFormBoot';
import { PreferencesEstimatesFormPage } from './PreferencesEstimatesFormPage';

/**
* Estimates preferences.
*/
export function PreferencesEstimates() {
return (
<PreferencesEstimatesBoot>
<PreferencesEstimatesFormPage />
</PreferencesEstimatesBoot>
);
}
Original file line number Diff line number Diff line change
@@ -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;
Loading
Loading