-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd3d09a
commit 8c869aa
Showing
11 changed files
with
272 additions
and
121 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
projects/plugins/protect/src/js/components/paid-plan-gate/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Navigate } from 'react-router-dom'; | ||
import useProtectData from '../../hooks/use-protect-data'; | ||
|
||
/** | ||
* Paid Plan Gate | ||
* | ||
* Custom route that only renders when the user has a paid plan. | ||
* | ||
* @param {object} props - The component props. | ||
* @param {JSX.Element} props.children - The component to render if the user has a paid plan. | ||
* @param {string} props.redirect - The alternate route to redirect to if the user does not have a paid plan. | ||
* | ||
* @returns {JSX.Element} The PaidPlanRoute component. | ||
*/ | ||
export default function PaidPlanGate( { | ||
children, | ||
redirect = '/', | ||
}: { | ||
children?: JSX.Element; | ||
redirect?: string; | ||
} ): JSX.Element { | ||
const { hasRequiredPlan } = useProtectData(); | ||
|
||
if ( ! hasRequiredPlan ) { | ||
return <Navigate to={ redirect } replace />; | ||
} | ||
|
||
return children; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.