feat: impl menu item feature locks for non-pro users

This commit is contained in:
thecodrr
2020-05-15 00:35:20 +05:00
parent b0c57965fd
commit 71c146e196
2 changed files with 22 additions and 1 deletions

View File

@@ -1,7 +1,10 @@
import React from "react"; import React from "react";
import { Flex, Box, Text } from "rebass"; import { Flex, Box, Text } from "rebass";
import { useStore as useUserStore } from "../../stores/user-store";
function Menu(props) { function Menu(props) {
const isPremium = useUserStore((store) => store.isPremium);
return ( return (
<Flex <Flex
id={props.id} id={props.id}
@@ -38,12 +41,16 @@ function Menu(props) {
if (props.closeMenu) { if (props.closeMenu) {
props.closeMenu(); props.closeMenu();
} }
if (item.onClick) { const onlyPro = item.onlyPro && !isPremium;
if (onlyPro && item.onClick) {
item.onClick(props.data); item.onClick(props.data);
} else {
// TODO show the buy dialog
} }
}} }}
flexDirection="row" flexDirection="row"
alignItems="center" alignItems="center"
justifyContent="space-between"
py={"8px"} py={"8px"}
px={3} px={3}
sx={{ sx={{
@@ -61,6 +68,17 @@ function Menu(props) {
{item.title} {item.title}
</Text> </Text>
)} )}
{item.onlyPro && !isPremium && (
<Text
fontSize="menu"
bg="primary"
color="static"
px={1}
sx={{ borderRadius: "default" }}
>
Pro
</Text>
)}
</Flex> </Flex>
) )
)} )}

View File

@@ -27,10 +27,12 @@ function menuItems(note, context) {
{ {
title: note.pinned ? "Unpin" : "Pin", title: note.pinned ? "Unpin" : "Pin",
onClick: () => store.pin(note), onClick: () => store.pin(note),
onlyPro: true,
}, },
{ {
title: note.favorite ? "Unfavorite" : "Favorite", title: note.favorite ? "Unfavorite" : "Favorite",
onClick: () => store.favorite(note), onClick: () => store.favorite(note),
onlyPro: true,
}, },
{ title: "Edit", onClick: () => editorStore.openSession(note) }, { title: "Edit", onClick: () => editorStore.openSession(note) },
{ {
@@ -43,6 +45,7 @@ function menuItems(note, context) {
unlock(note.id); unlock(note.id);
} }
}, },
onlyPro: true,
}, },
{ {
visible: context ? (context.type === "topic" ? true : false) : false, visible: context ? (context.type === "topic" ? true : false) : false,