feat: make payment plans dynamic
This commit is contained in:
8
packages/types/index.d.ts
vendored
8
packages/types/index.d.ts
vendored
@@ -321,6 +321,13 @@ export type IGlobalVariable = {
|
|||||||
setActionItem?: (actionItem: IActionItem) => void;
|
setActionItem?: (actionItem: IActionItem) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TPaymentPlan = {
|
||||||
|
price: string;
|
||||||
|
name: string;
|
||||||
|
limit: string;
|
||||||
|
productId: string;
|
||||||
|
}
|
||||||
|
|
||||||
declare module 'axios' {
|
declare module 'axios' {
|
||||||
interface AxiosResponse {
|
interface AxiosResponse {
|
||||||
httpError?: IJSONObject;
|
httpError?: IJSONObject;
|
||||||
@@ -335,4 +342,3 @@ export interface IRequest extends Request {
|
|||||||
rawBody?: Buffer;
|
rawBody?: Buffer;
|
||||||
currentUser?: IUser;
|
currentUser?: IUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
|
|
||||||
import Box from '@mui/material/Box';
|
import Box from '@mui/material/Box';
|
||||||
import Button from '@mui/material/Button';
|
import Button from '@mui/material/Button';
|
||||||
import Card from '@mui/material/Card';
|
import Card from '@mui/material/Card';
|
||||||
@@ -16,17 +15,17 @@ import TableRow from '@mui/material/TableRow';
|
|||||||
import Paper from '@mui/material/Paper';
|
import Paper from '@mui/material/Paper';
|
||||||
import LockIcon from '@mui/icons-material/Lock';
|
import LockIcon from '@mui/icons-material/Lock';
|
||||||
|
|
||||||
const plans = [
|
import usePaymentPlans from 'hooks/usePaymentPlans.ee';
|
||||||
{ tasks: '10,000', price: '€20' },
|
|
||||||
{ tasks: '30,000', price: '€50' },
|
|
||||||
];
|
|
||||||
|
|
||||||
export default function UpgradeFreeTrial() {
|
export default function UpgradeFreeTrial() {
|
||||||
|
const { plans, loading } = usePaymentPlans();
|
||||||
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
const [selectedIndex, setSelectedIndex] = React.useState(0);
|
||||||
const selectedPlan = plans[selectedIndex];
|
const selectedPlan = plans?.[selectedIndex];
|
||||||
|
|
||||||
const updateSelection = (index: number) => setSelectedIndex(index);
|
const updateSelection = (index: number) => setSelectedIndex(index);
|
||||||
|
|
||||||
|
if (loading || !plans.length) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<Card sx={{ mb: 3, p: 2 }}>
|
<Card sx={{ mb: 3, p: 2 }}>
|
||||||
@@ -74,9 +73,9 @@ export default function UpgradeFreeTrial() {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{plans.map((row, index) => (
|
{plans.map((plan, index) => (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={row.tasks}
|
key={plan.productId}
|
||||||
onClick={() => updateSelection(index)}
|
onClick={() => updateSelection(index)}
|
||||||
sx={{
|
sx={{
|
||||||
'&:hover': { cursor: 'pointer' },
|
'&:hover': { cursor: 'pointer' },
|
||||||
@@ -91,7 +90,7 @@ export default function UpgradeFreeTrial() {
|
|||||||
fontWeight: selectedIndex === index ? 'bold' : 'normal',
|
fontWeight: selectedIndex === index ? 'bold' : 'normal',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{row.tasks}
|
{plan.limit}
|
||||||
</Typography>
|
</Typography>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="right" sx={{ py: 2 }}>
|
<TableCell align="right" sx={{ py: 2 }}>
|
||||||
@@ -101,7 +100,7 @@ export default function UpgradeFreeTrial() {
|
|||||||
fontWeight: selectedIndex === index ? 'bold' : 'normal',
|
fontWeight: selectedIndex === index ? 'bold' : 'normal',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{row.price} / month
|
{plan.price} / month
|
||||||
</Typography>
|
</Typography>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
|
12
packages/web/src/graphql/queries/get-payment-plans.ee.ts
Normal file
12
packages/web/src/graphql/queries/get-payment-plans.ee.ts
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import { gql } from '@apollo/client';
|
||||||
|
|
||||||
|
export const GET_PAYMENT_PLANS = gql`
|
||||||
|
query GetPaymentPlans {
|
||||||
|
getPaymentPlans {
|
||||||
|
name
|
||||||
|
limit
|
||||||
|
price
|
||||||
|
productId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
18
packages/web/src/hooks/usePaymentPlans.ee.ts
Normal file
18
packages/web/src/hooks/usePaymentPlans.ee.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { useQuery } from '@apollo/client';
|
||||||
|
|
||||||
|
import { TPaymentPlan } from '@automatisch/types';
|
||||||
|
import { GET_PAYMENT_PLANS } from 'graphql/queries/get-payment-plans.ee';
|
||||||
|
|
||||||
|
type UsePaymentPlansReturn = {
|
||||||
|
plans: TPaymentPlan[];
|
||||||
|
loading: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function usePaymentPlans(): UsePaymentPlansReturn {
|
||||||
|
const { data, loading } = useQuery(GET_PAYMENT_PLANS);
|
||||||
|
|
||||||
|
return {
|
||||||
|
plans: data?.getPaymentPlans || [],
|
||||||
|
loading
|
||||||
|
};
|
||||||
|
}
|
Reference in New Issue
Block a user