Skip to content

Commit af7abe1

Browse files
Merge pull request #211 from gridaco/staging
Improved Early Access Guarding
2 parents 42ef6a6 + 6251250 commit af7abe1

File tree

13 files changed

+201
-91
lines changed

13 files changed

+201
-91
lines changed

app/lib/pages/about/manifest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// const _package = require("../package.jsonn");
22
export const name = "Grida Assistant";
3-
export const version = "2022.3.1f0"; /*_package.version*/
3+
export const version = "2023.3.1f0"; /*_package.version*/
44
export const versionText = `v${version}`;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { useEarlyAccess } from "@assistant-fp/early-access";
2+
import { useHistory } from "react-router-dom";
3+
import { early_access_required_message } from "../k";
4+
5+
export function requiresEarlyAccess<T extends Function>(f: T): T {
6+
const history = useHistory();
7+
const ea = useEarlyAccess();
8+
9+
if (!ea) {
10+
return ((...args) => {
11+
alert(early_access_required_message);
12+
history.push("/upgrade");
13+
}) as any as T;
14+
} else {
15+
return f;
16+
}
17+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./use-early-access";
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React, { useEffect, useState } from "react";
2+
import store from "../store";
3+
4+
export function useEarlyAccess() {
5+
const [accesskey, setAccessKey] = useState<string | null>(null);
6+
useEffect(() => {
7+
store.get().then((d) => {
8+
if (d) {
9+
setAccessKey(d);
10+
}
11+
});
12+
}, []);
13+
14+
return accesskey;
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
export { UpgradePage } from "./register";
2+
export * from "./guards";
3+
export * from "./hooks";
4+
export { default as store } from "./store";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const __key = "assistant-early-access-activation";
2+
export const early_access_required_message =
3+
"This is a pro feature, please activate";

packages/_firstparty-early-access/scaffolds/register-with-code-card.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React, { useState, useEffect } from "react";
22
import styled from "@emotion/styled";
33
import { PluginSdk } from "@plugin-sdk/app";
4-
5-
const __key = "assistant-early-access-activation";
4+
import { store } from "@assistant-fp/early-access";
65

76
const __form_key_min_length = 24;
87

@@ -11,7 +10,7 @@ export function RegisterWithCodeCard() {
1110
const [isTokenFormatValid, setIsTokenFormatValid] = useState(false);
1211

1312
useEffect(() => {
14-
PluginSdk.getItem(__key).then((code) => {
13+
store.get().then((code) => {
1514
verify(code).then((verified) => {
1615
setVerified(verified);
1716
});
@@ -36,7 +35,7 @@ export function RegisterWithCodeCard() {
3635
const activate = (code: string) => {
3736
verify(code).then((verified) => {
3837
if (verified) {
39-
PluginSdk.setItem(__key, code);
38+
store.set(code);
4039
setVerified(true);
4140
alert("Congrats🎉 Early access program activated.");
4241
} else {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { __key } from "./k";
2+
import { PluginSdk } from "@plugin-sdk/app";
3+
4+
const store = {
5+
set: (value: any) => {
6+
return PluginSdk.setItem(__key, value);
7+
},
8+
get: async () => {
9+
return await PluginSdk.getItem(__key);
10+
},
11+
};
12+
13+
export default store;

packages/app-design-lint/fix-your-self.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { LintItemRow } from "@app/design-lint";
77
import { LintProcessPaginator } from "@app/design-lint/lint-process-paginator";
88
import { _APP_EVENT_LINT_RESULT_EK } from "@app/design-lint/__plugin/events";
99
import BackArrowIcon from "@assistant/icons/back-arrow";
10+
import { requiresEarlyAccess } from "@assistant-fp/early-access";
1011

1112
/** Fix your self as page with router props ver. (not used. planned.) */
1213
export function FixYourSelfPage(props: {
@@ -43,12 +44,12 @@ export function FixYourSelf(props: {
4344
chaange_layer_index(0);
4445
}, []);
4546

46-
const chaange_layer_index = (i) => {
47+
const chaange_layer_index = requiresEarlyAccess((i) => {
4748
setLayerIndex(i);
4849
const _target = layerlintMap.get(_key_at_index(i));
4950
setLayerLint(_target);
5051
PluginSdk.focus(_target.node.id);
51-
};
52+
});
5253

5354
const _page_size = layerlintMap.size;
5455

packages/app-design-lint/lint-screen.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { makeSummary, requestLintOnCurrentSelection } from "./actions";
1919
import { FixYourSelf } from "./fix-your-self";
2020
import { mapGrandchildren } from "@design-sdk/core/utils";
2121
import Dialog from "@material-ui/core/Dialog";
22+
import { requiresEarlyAccess } from "@assistant-fp/early-access";
2223

2324
export const LintScreen = () => {
2425
const [feedbacks, setFeedbacks] = useState<ReflectLintFeedback[]>([]);
@@ -50,10 +51,10 @@ export const LintScreen = () => {
5051
}).length;
5152
}
5253

53-
function onFeedbackTap(feedback: ReflectLintFeedback) {
54+
const onFeedbackTap = requiresEarlyAccess((feedback: ReflectLintFeedback) => {
5455
const targetNodeId = feedback.node.id;
5556
PluginSdk.focus(targetNodeId);
56-
}
57+
});
5758

5859
function handleSelectionLayer() {
5960
const summary = makeSummary(feedbacks);

0 commit comments

Comments
 (0)