mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 23:30:32 +00:00
feat: getting subscription endpoint
This commit is contained in:
@@ -0,0 +1,11 @@
|
|||||||
|
import { Transformer } from '@/lib/Transformer/Transformer';
|
||||||
|
|
||||||
|
export class GetSubscriptionsTransformer extends Transformer {
|
||||||
|
/**
|
||||||
|
* Include these attributes to sale invoice object.
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
public includeAttributes = (): string[] => {
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
import { Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import { PlanSubscription } from '@/system/models';
|
import { PlanSubscription } from '@/system/models';
|
||||||
|
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||||
|
import { GetSubscriptionsTransformer } from './GetSubscriptionsTransformer';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class SubscriptionService {
|
export default class SubscriptionService {
|
||||||
|
@Inject()
|
||||||
|
private transformer: TransformerInjectable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all subscription of the given tenant.
|
* Retrieve all subscription of the given tenant.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
@@ -12,6 +17,10 @@ export default class SubscriptionService {
|
|||||||
'tenant_id',
|
'tenant_id',
|
||||||
tenantId
|
tenantId
|
||||||
);
|
);
|
||||||
return subscriptions;
|
return this.transformer.transform(
|
||||||
|
tenantId,
|
||||||
|
subscriptions,
|
||||||
|
new GetSubscriptionsTransformer()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
import { Button } from '@blueprintjs/core';
|
import { Button } from '@blueprintjs/core';
|
||||||
import withAlertActions from '../Alert/withAlertActions';
|
import withAlertActions from '../Alert/withAlertActions';
|
||||||
|
import { BillingPageBoot } from './BillingPageBoot';
|
||||||
|
|
||||||
function BillingPageRoot({ openAlert }) {
|
function BillingPageRoot({ openAlert }) {
|
||||||
const handleCancelSubBtnClick = () => {
|
const handleCancelSubBtnClick = () => {
|
||||||
@@ -13,11 +14,13 @@ function BillingPageRoot({ openAlert }) {
|
|||||||
const handleUpdatePaymentMethod = () => {};
|
const handleUpdatePaymentMethod = () => {};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<h1>
|
<BillingPageBoot>
|
||||||
<Button onClick={handleCancelSubBtnClick}>Cancel Subscription</Button>
|
<h1>
|
||||||
<Button onClick={handleResumeSubBtnClick}>Resume Subscription</Button>
|
<Button onClick={handleCancelSubBtnClick}>Cancel Subscription</Button>
|
||||||
<Button>Update Payment Method</Button>
|
<Button onClick={handleResumeSubBtnClick}>Resume Subscription</Button>
|
||||||
</h1>
|
<Button>Update Payment Method</Button>
|
||||||
|
</h1>
|
||||||
|
</BillingPageBoot>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,28 @@
|
|||||||
export function BillingPageBoot() {
|
import React, { createContext } from 'react';
|
||||||
return null;
|
import { useGetSubscriptions } from '@/hooks/query/subscription';
|
||||||
|
|
||||||
|
interface BillingBootContextValues {
|
||||||
|
isSubscriptionsLoading: boolean;
|
||||||
|
subscriptions: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const BillingBoot = createContext<BillingBootContextValues>(
|
||||||
|
{} as BillingBootContextValues,
|
||||||
|
);
|
||||||
|
|
||||||
|
interface BillingPageBootProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function BillingPageBoot({ children }: BillingPageBootProps) {
|
||||||
|
const { isLoading: isSubscriptionsLoading, data: subscriptions } =
|
||||||
|
useGetSubscriptions();
|
||||||
|
|
||||||
|
const value = {
|
||||||
|
isSubscriptionsLoading,
|
||||||
|
subscriptions,
|
||||||
|
};
|
||||||
|
return <BillingBoot.Provider value={value}>{children}</BillingBoot.Provider>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useBillingPageBoot = () => React.useContext(BillingBoot);
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
// @ts-nocheck
|
// @ts-ignore
|
||||||
import {
|
import {
|
||||||
useMutation,
|
useMutation,
|
||||||
UseMutationOptions,
|
UseMutationOptions,
|
||||||
UseMutationResult,
|
UseMutationResult,
|
||||||
|
useQuery,
|
||||||
useQueryClient,
|
useQueryClient,
|
||||||
|
UseQueryOptions,
|
||||||
|
UseQueryResult,
|
||||||
} from 'react-query';
|
} from 'react-query';
|
||||||
import useApiRequest from '../useRequest';
|
import useApiRequest from '../useRequest';
|
||||||
|
|
||||||
@@ -113,3 +116,29 @@ export function useChangeSubscriptionPlan(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface GetSubscriptionsQuery {}
|
||||||
|
interface GetSubscriptionsResponse {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Changese the main subscription of the current organization.
|
||||||
|
* @param {UseMutationOptions<ChangeMainSubscriptionPlanValues, Error, ChangeMainSubscriptionPlanResponse>} options -
|
||||||
|
* @returns {UseMutationResult<ChangeMainSubscriptionPlanValues, Error, ChangeMainSubscriptionPlanResponse>}
|
||||||
|
*/
|
||||||
|
export function useGetSubscriptions(
|
||||||
|
options?: UseQueryOptions<
|
||||||
|
GetSubscriptionsQuery,
|
||||||
|
Error,
|
||||||
|
GetSubscriptionsResponse
|
||||||
|
>,
|
||||||
|
): UseQueryResult<GetSubscriptionsResponse, Error> {
|
||||||
|
const apiRequest = useApiRequest();
|
||||||
|
|
||||||
|
return useQuery<GetSubscriptionsQuery, Error, GetSubscriptionsResponse>(
|
||||||
|
['SUBSCRIPTIONS'],
|
||||||
|
(values) => apiRequest.get(`/subscription`).then((res) => res.data),
|
||||||
|
{
|
||||||
|
...options,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user