feat: introduce usePlanAndUsage with RQ
This commit is contained in:
@@ -10,15 +10,20 @@ import CardContent from '@mui/material/CardContent';
|
|||||||
import Divider from '@mui/material/Divider';
|
import Divider from '@mui/material/Divider';
|
||||||
import Grid from '@mui/material/Grid';
|
import Grid from '@mui/material/Grid';
|
||||||
import Typography from '@mui/material/Typography';
|
import Typography from '@mui/material/Typography';
|
||||||
|
|
||||||
import TrialOverAlert from 'components/TrialOverAlert/index.ee';
|
import TrialOverAlert from 'components/TrialOverAlert/index.ee';
|
||||||
import SubscriptionCancelledAlert from 'components/SubscriptionCancelledAlert/index.ee';
|
import SubscriptionCancelledAlert from 'components/SubscriptionCancelledAlert/index.ee';
|
||||||
import CheckoutCompletedAlert from 'components/CheckoutCompletedAlert/index.ee';
|
import CheckoutCompletedAlert from 'components/CheckoutCompletedAlert/index.ee';
|
||||||
import * as URLS from 'config/urls';
|
import * as URLS from 'config/urls';
|
||||||
import useBillingAndUsageData from 'hooks/useBillingAndUsageData.ee';
|
import useBillingAndUsageData from 'hooks/useBillingAndUsageData.ee';
|
||||||
import useFormatMessage from 'hooks/useFormatMessage';
|
import useFormatMessage from 'hooks/useFormatMessage';
|
||||||
|
import usePlanAndUsage from 'hooks/usePlanAndUsage';
|
||||||
|
|
||||||
const capitalize = (str) => str[0].toUpperCase() + str.slice(1, str.length);
|
const capitalize = (str) => str[0].toUpperCase() + str.slice(1, str.length);
|
||||||
|
|
||||||
function BillingCard(props) {
|
function BillingCard(props) {
|
||||||
const { name, title = '', action } = props;
|
const { name, title = '', action } = props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
sx={{
|
sx={{
|
||||||
@@ -45,10 +50,14 @@ function BillingCard(props) {
|
|||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function Action(props) {
|
function Action(props) {
|
||||||
const { action } = props;
|
const { action } = props;
|
||||||
|
|
||||||
if (!action) return <React.Fragment />;
|
if (!action) return <React.Fragment />;
|
||||||
|
|
||||||
const { text, type } = action;
|
const { text, type } = action;
|
||||||
|
|
||||||
if (type === 'link') {
|
if (type === 'link') {
|
||||||
if (action.src.startsWith('http')) {
|
if (action.src.startsWith('http')) {
|
||||||
return (
|
return (
|
||||||
@@ -64,6 +73,7 @@ function Action(props) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'text') {
|
if (type === 'text') {
|
||||||
return (
|
return (
|
||||||
<Typography variant="subtitle2" pb={1}>
|
<Typography variant="subtitle2" pb={1}>
|
||||||
@@ -71,11 +81,15 @@ function Action(props) {
|
|||||||
</Typography>
|
</Typography>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return <React.Fragment />;
|
return <React.Fragment />;
|
||||||
}
|
}
|
||||||
export default function UsageDataInformation() {
|
export default function UsageDataInformation() {
|
||||||
const formatMessage = useFormatMessage();
|
const formatMessage = useFormatMessage();
|
||||||
const billingAndUsageData = useBillingAndUsageData();
|
const billingAndUsageData = useBillingAndUsageData();
|
||||||
|
const { data } = usePlanAndUsage();
|
||||||
|
const planAndUsage = data?.data;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Stack sx={{ width: '100%', mb: 2 }} spacing={2}>
|
<Stack sx={{ width: '100%', mb: 2 }} spacing={2}>
|
||||||
@@ -171,7 +185,7 @@ export default function UsageDataInformation() {
|
|||||||
variant="subtitle2"
|
variant="subtitle2"
|
||||||
sx={{ color: 'text.secondary', mt: 2, fontWeight: 500 }}
|
sx={{ color: 'text.secondary', mt: 2, fontWeight: 500 }}
|
||||||
>
|
>
|
||||||
{billingAndUsageData?.usage.task}
|
{planAndUsage?.usage.task}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
|
25
packages/web/src/hooks/usePlanAndUsage.js
Normal file
25
packages/web/src/hooks/usePlanAndUsage.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
|
||||||
|
import api from 'helpers/api';
|
||||||
|
import useCurrentUser from './useCurrentUser';
|
||||||
|
|
||||||
|
export default function usePlanAndUsage() {
|
||||||
|
const { data } = useCurrentUser();
|
||||||
|
const currentUserId = data?.data?.id;
|
||||||
|
|
||||||
|
const query = useQuery({
|
||||||
|
queryKey: ['planAndUsage', currentUserId],
|
||||||
|
queryFn: async ({ signal }) => {
|
||||||
|
const { data } = await api.get(
|
||||||
|
`/v1/users/${currentUserId}/plan-and-usage`,
|
||||||
|
{
|
||||||
|
signal,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return data;
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return query;
|
||||||
|
}
|
Reference in New Issue
Block a user