mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: Add default customer message and terms and conditions to the transactions.
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
// @ts-nocheck
|
||||
import { PreferencesCreditNotesBoot } from './PreferencesCreditNotesFormBoot';
|
||||
import PreferencesInvoiceFormPage from './PreferencesCreditNotesFormPage';
|
||||
|
||||
/**
|
||||
* items preferences.
|
||||
*/
|
||||
export default function PreferencesCreditNotes() {
|
||||
return (
|
||||
<PreferencesCreditNotesBoot>
|
||||
<PreferencesInvoiceFormPage />
|
||||
</PreferencesCreditNotesBoot>
|
||||
);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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 (
|
||||
<Form>
|
||||
{/* ---------- Terms & Conditions ---------- */}
|
||||
<FFormGroup
|
||||
name={'termsConditions'}
|
||||
label={<T id={'pref.estimates.termsConditions.field'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
fastField={true}
|
||||
>
|
||||
<FTextArea
|
||||
medium={'true'}
|
||||
name={'termsConditions'}
|
||||
fastField={true}
|
||||
fill={true}
|
||||
/>
|
||||
</FFormGroup>
|
||||
|
||||
{/* ---------- Customer Notes ---------- */}
|
||||
<FFormGroup
|
||||
name={'customerNotes'}
|
||||
label={<T id={'pref.estimates.customerNotes.field'} />}
|
||||
fastField={true}
|
||||
>
|
||||
<FTextArea
|
||||
medium={'true'}
|
||||
name={'tax_number'}
|
||||
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;
|
||||
}
|
||||
}
|
||||
`;
|
||||
@@ -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 (
|
||||
<div
|
||||
className={classNames(
|
||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT,
|
||||
CLASSES.PREFERENCES_PAGE_INSIDE_CONTENT_ACCOUNTANT,
|
||||
)}
|
||||
>
|
||||
{isLoading ? (
|
||||
<PreferencesPageLoader />
|
||||
) : (
|
||||
<PreferencesCreditNotesFormContext.Provider value={provider} {...props} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const usePreferencesCreditNotesFormContext = () =>
|
||||
React.useContext(PreferencesCreditNotesFormContext);
|
||||
|
||||
export { PreferencesCreditNotesBoot, usePreferencesCreditNotesFormContext };
|
||||
@@ -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 (
|
||||
<Formik
|
||||
initialValues={initialValues}
|
||||
validationSchema={PreferencesCreditNotesFormSchema}
|
||||
onSubmit={handleFormSubmit}
|
||||
component={PreferencesCreditNotesForm}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export const PreferencesCreditNotesFormPage = compose(withDashboardActions)(
|
||||
PreferencesCreditNotesFormPageRoot,
|
||||
);
|
||||
Reference in New Issue
Block a user