mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
96 lines
2.3 KiB
TypeScript
96 lines
2.3 KiB
TypeScript
// @ts-nocheck
|
|
import React, { useEffect } from 'react';
|
|
import intl from 'react-intl-universal';
|
|
import { Formik, Form } from 'formik';
|
|
import { DashboardInsider, If, Alert, T } from '@/components';
|
|
|
|
import '@/style/pages/Billing/BillingPage.scss';
|
|
|
|
import { compose } from '@/utils';
|
|
import { MasterBillingTabs } from './SubscriptionTabs';
|
|
import { getBillingFormValidationSchema } from './utils';
|
|
|
|
import withBillingActions from './withBillingActions';
|
|
import withDashboardActions from '@/containers/Dashboard/withDashboardActions';
|
|
import withSubscriptionPlansActions from './withSubscriptionPlansActions';
|
|
import withSubscriptions from './withSubscriptions';
|
|
|
|
/**
|
|
* Billing form.
|
|
*/
|
|
function BillingForm({
|
|
// #withDashboardActions
|
|
changePageTitle,
|
|
|
|
// #withBillingActions
|
|
requestSubmitBilling,
|
|
|
|
initSubscriptionPlans,
|
|
|
|
// #withSubscriptions
|
|
isSubscriptionInactive,
|
|
}) {
|
|
useEffect(() => {
|
|
changePageTitle(intl.get('billing'));
|
|
}, [changePageTitle]);
|
|
|
|
React.useEffect(() => {
|
|
initSubscriptionPlans();
|
|
}, [initSubscriptionPlans]);
|
|
|
|
// Initial values.
|
|
const initialValues = {
|
|
plan_slug: 'essentials',
|
|
period: 'month',
|
|
license_code: '',
|
|
};
|
|
|
|
// Handle form submitting.
|
|
const handleSubmit = (values, { setSubmitting }) => {
|
|
requestSubmitBilling({
|
|
...values,
|
|
plan_slug: 'essentials-monthly',
|
|
})
|
|
.then((response) => {
|
|
setSubmitting(false);
|
|
})
|
|
.catch((errors) => {
|
|
setSubmitting(false);
|
|
});
|
|
};
|
|
|
|
return (
|
|
<DashboardInsider name={'billing-page'}>
|
|
<div className={'billing-page'}>
|
|
<If condition={isSubscriptionInactive}>
|
|
<Alert
|
|
intent={'danger'}
|
|
title={<T id={'billing.suspend_message.title'} />}
|
|
description={<T id={'billing.suspend_message.description'} />}
|
|
/>
|
|
</If>
|
|
|
|
<Formik
|
|
validationSchema={getBillingFormValidationSchema()}
|
|
onSubmit={handleSubmit}
|
|
initialValues={initialValues}
|
|
>
|
|
<Form>
|
|
<MasterBillingTabs />
|
|
</Form>
|
|
</Formik>
|
|
</div>
|
|
</DashboardInsider>
|
|
);
|
|
}
|
|
|
|
export default compose(
|
|
withDashboardActions,
|
|
withBillingActions,
|
|
withSubscriptionPlansActions,
|
|
withSubscriptions(
|
|
({ isSubscriptionInactive }) => ({ isSubscriptionInactive }),
|
|
'main',
|
|
),
|
|
)(BillingForm);
|