@learnpack/learnpack 5.0.142 → 5.0.146
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -13
- package/lib/commands/serve.js +56 -0
- package/lib/creatorDist/assets/{index-BLd63KeV.js → index-CzMCewx6.js} +2854 -2841
- package/lib/creatorDist/assets/{index-Cz25oPGo.css → index-DSOj0E0h.css} +6 -0
- package/lib/creatorDist/index.html +7 -2
- package/lib/utils/sidebarGenerator.d.ts +4 -0
- package/lib/utils/sidebarGenerator.js +47 -1
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
- package/src/commands/serve.ts +108 -0
- package/src/creator/index.html +5 -0
- package/src/creator/src/App.tsx +59 -35
- package/src/creator/src/components/Login.tsx +2 -1
- package/src/creator/src/components/TurnstileChallenge.tsx +83 -0
- package/src/creator/src/utils/store.ts +4 -0
- package/src/creatorDist/assets/{index-BLd63KeV.js → index-CzMCewx6.js} +2854 -2841
- package/src/creatorDist/assets/{index-Cz25oPGo.css → index-DSOj0E0h.css} +6 -0
- package/src/creatorDist/index.html +7 -2
- package/src/ui/_app/app.js +1 -1
- package/src/ui/_app/rigo-float.gif +0 -0
- package/src/ui/app.tar.gz +0 -0
- package/src/utils/sidebarGenerator.ts +68 -0
@@ -393,6 +393,9 @@
|
|
393
393
|
.top-2 {
|
394
394
|
top: calc(var(--spacing) * 2);
|
395
395
|
}
|
396
|
+
.right-0 {
|
397
|
+
right: calc(var(--spacing) * 0);
|
398
|
+
}
|
396
399
|
.right-2 {
|
397
400
|
right: calc(var(--spacing) * 2);
|
398
401
|
}
|
@@ -704,6 +707,9 @@
|
|
704
707
|
.gap-3 {
|
705
708
|
gap: calc(var(--spacing) * 3);
|
706
709
|
}
|
710
|
+
.gap-4 {
|
711
|
+
gap: calc(var(--spacing) * 4);
|
712
|
+
}
|
707
713
|
:where(.space-y-2 > :not(:last-child)) {
|
708
714
|
--tw-space-y-reverse: 0;
|
709
715
|
margin-block-start: calc(
|
@@ -10,10 +10,15 @@
|
|
10
10
|
/>
|
11
11
|
|
12
12
|
<title>Learnpack Creator: Craft tutorials in seconds!</title>
|
13
|
-
<script type="module" crossorigin src="/creator/assets/index-
|
14
|
-
<link rel="stylesheet" crossorigin href="/creator/assets/index-
|
13
|
+
<script type="module" crossorigin src="/creator/assets/index-CzMCewx6.js"></script>
|
14
|
+
<link rel="stylesheet" crossorigin href="/creator/assets/index-DSOj0E0h.css">
|
15
15
|
</head>
|
16
16
|
<body>
|
17
17
|
<div id="root"></div>
|
18
|
+
<script
|
19
|
+
src="https://challenges.cloudflare.com/turnstile/v0/api.js"
|
20
|
+
async
|
21
|
+
defer
|
22
|
+
></script>
|
18
23
|
</body>
|
19
24
|
</html>
|
@@ -9,4 +9,8 @@ export type TSidebar = {
|
|
9
9
|
export declare const generateSidebar: (exercises: IExercise[], learnPath: string) => TSidebar;
|
10
10
|
export declare const addExerciseToSidebar: (exerciseSlug: string, targetLanguage: string, translatedSlug: string, learnPath: string) => TSidebar;
|
11
11
|
export declare const checkAndFixSidebar: (configObj: IConfigObj, autoFix?: boolean) => Promise<boolean>;
|
12
|
+
export declare const checkAndFixSidebarPure: (sidebarJson: Record<string, Record<string, string>>, exercises: any[], rigoToken: string, autoFix?: boolean) => Promise<{
|
13
|
+
valid: boolean;
|
14
|
+
fixedSidebar?: Record<string, Record<string, string>>;
|
15
|
+
}>;
|
12
16
|
export {};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.checkAndFixSidebar = exports.addExerciseToSidebar = exports.generateSidebar = void 0;
|
3
|
+
exports.checkAndFixSidebarPure = exports.checkAndFixSidebar = exports.addExerciseToSidebar = exports.generateSidebar = void 0;
|
4
4
|
const path = require("path");
|
5
5
|
const console_1 = require("./console");
|
6
6
|
const fs = require("fs");
|
@@ -75,3 +75,49 @@ const checkAndFixSidebar = async (configObj, autoFix = false) => {
|
|
75
75
|
return false;
|
76
76
|
};
|
77
77
|
exports.checkAndFixSidebar = checkAndFixSidebar;
|
78
|
+
const checkAndFixSidebarPure = async (sidebarJson, exercises, rigoToken, autoFix = true) => {
|
79
|
+
const exerciseTranslations = new Set();
|
80
|
+
for (const e of exercises) {
|
81
|
+
for (const lang of Object.keys(e.translations || {})) {
|
82
|
+
exerciseTranslations.add(lang);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
let hasErrors = false;
|
86
|
+
const fixedSidebar = Object.assign({}, sidebarJson);
|
87
|
+
for (const exercise of exercises) {
|
88
|
+
const slug = exercise.slug;
|
89
|
+
const existingEntry = fixedSidebar[slug];
|
90
|
+
if (!existingEntry) {
|
91
|
+
hasErrors = true;
|
92
|
+
fixedSidebar[slug] = { us: exercise.slug };
|
93
|
+
continue;
|
94
|
+
}
|
95
|
+
for (const lang of exerciseTranslations) {
|
96
|
+
if (!Object.prototype.hasOwnProperty.call(existingEntry, lang)) {
|
97
|
+
hasErrors = true;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
}
|
101
|
+
if (hasErrors && autoFix) {
|
102
|
+
if (!rigoToken) {
|
103
|
+
console_1.default.error("No Rigobot token provided!");
|
104
|
+
return { valid: false };
|
105
|
+
}
|
106
|
+
console_1.default.warning("Filling sidebar JSON with missing translations or exercises");
|
107
|
+
const response = await (0, rigoActions_1.fillSidebarJSON)(rigoToken, {
|
108
|
+
needed_translations: JSON.stringify([...exerciseTranslations]),
|
109
|
+
sidebar_json: JSON.stringify(fixedSidebar),
|
110
|
+
});
|
111
|
+
const newSidebarJson = JSON.parse(response.parsed.new_sidebar_file);
|
112
|
+
console_1.default.info("Sidebar JSON was fixed");
|
113
|
+
return {
|
114
|
+
valid: true,
|
115
|
+
fixedSidebar: newSidebarJson,
|
116
|
+
};
|
117
|
+
}
|
118
|
+
return {
|
119
|
+
valid: !hasErrors,
|
120
|
+
fixedSidebar: hasErrors ? fixedSidebar : undefined,
|
121
|
+
};
|
122
|
+
};
|
123
|
+
exports.checkAndFixSidebarPure = checkAndFixSidebarPure;
|
package/oclif.manifest.json
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":"5.0.
|
1
|
+
{"version":"5.0.146","commands":{"audit":{"id":"audit","description":"learnpack audit is the command in charge of creating an auditory of the repository\n...\nlearnpack audit checks for the following information in a repository:\n 1. The configuration object has slug, repository and description. (Error)\n 2. The command learnpack clean has been run. (Error)\n 3. If a markdown or test file doesn't have any content. (Error)\n 4. The links are accessing to valid servers. (Error)\n 5. The relative images are working (If they have the shortest path to the image or if the images exists in the assets). (Error)\n 6. The external images are working (If they are pointing to a valid server). (Error)\n 7. The exercises directory names are valid. (Error)\n 8. If an exercise doesn't have a README file. (Error)\n 9. The exercises array (Of the config file) has content. (Error)\n 10. The exercses have the same translations. (Warning)\n 11. The .gitignore file exists. (Warning)\n 12. If there is a file within the exercises folder but not inside of any particular exercise's folder. (Warning)\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false}},"args":[]},"breakToken":{"id":"breakToken","description":"Break the token","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"clean":{"id":"clean","description":"Clean the configuration object\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[]},"download":{"id":"download","description":"Describe the command here\n...\nExtra documentation goes here\n","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"init":{"id":"init","description":"Create a new learning package: Book, Tutorial or Exercise","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"grading":{"name":"grading","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"login":{"id":"login","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"logout":{"id":"logout","description":"Describe the command here\n ...\n Extra documentation goes here\n ","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{},"args":[{"name":"package","description":"The unique string that identifies this package on learnpack","required":false,"hidden":false}]},"publish":{"id":"publish","description":"Builds the project by copying necessary files and directories into a zip file","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"strict":{"name":"strict","type":"boolean","char":"s","description":"strict mode","allowNo":false},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"serve":{"id":"serve","description":"Runs a small server to build tutorials","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"start":{"id":"start","description":"Runs a small server with all the exercise instructions","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false},"port":{"name":"port","type":"option","char":"p","description":"server port"},"host":{"name":"host","type":"option","char":"h","description":"server host"},"disableGrading":{"name":"disableGrading","type":"boolean","char":"D","description":"disble grading functionality","allowNo":false},"watch":{"name":"watch","type":"boolean","char":"w","description":"Watch for file changes","allowNo":false},"editor":{"name":"editor","type":"option","char":"e","description":"[preview, extension]","options":["extension","preview"]},"version":{"name":"version","type":"option","char":"v","description":"E.g: 1.0.1"},"grading":{"name":"grading","type":"option","char":"g","description":"[isolated, incremental]","options":["isolated","incremental"]},"debug":{"name":"debug","type":"boolean","char":"d","description":"debugger mode for more verbage","allowNo":false}},"args":[]},"test":{"id":"test","description":"Test exercises","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false}},"args":[{"name":"exerciseSlug","description":"The name of the exercise to test","required":false,"hidden":false}]},"translate":{"id":"translate","description":"List all the lessons, the user is able of select many of them to translate to the given languages","pluginName":"@learnpack/learnpack","pluginType":"core","aliases":[],"flags":{"yes":{"name":"yes","type":"boolean","char":"y","description":"Skip all prompts and initialize an empty project","allowNo":false}},"args":[]}}}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@learnpack/learnpack",
|
3
3
|
"description": "Seamlessly build, sell and/or take interactive & auto-graded tutorials, start learning now or build a new tutorial to your audience.",
|
4
|
-
"version": "5.0.
|
4
|
+
"version": "5.0.146",
|
5
5
|
"author": "Alejandro Sanchez @alesanchezr",
|
6
6
|
"contributors": [
|
7
7
|
{
|
package/src/commands/serve.ts
CHANGED
@@ -37,6 +37,7 @@ import { RIGOBOT_HOST } from "../utils/api"
|
|
37
37
|
import { minutesToISO8601Duration } from "../utils/misc"
|
38
38
|
import { buildConfig, ConfigResponse } from "../utils/configBuilder"
|
39
39
|
import { checkReadability, slugify } from "../utils/creatorUtilities"
|
40
|
+
import { checkAndFixSidebarPure } from "../utils/sidebarGenerator"
|
40
41
|
const frontMatter = require("front-matter")
|
41
42
|
|
42
43
|
dotenv.config()
|
@@ -125,6 +126,17 @@ export const processImage = async (
|
|
125
126
|
}
|
126
127
|
}
|
127
128
|
|
129
|
+
const createInitialSidebar = async (slugs: string[]) => {
|
130
|
+
const sidebar: Record<string, Record<string, string>> = {}
|
131
|
+
for (const slug of slugs) {
|
132
|
+
sidebar[slug] = {
|
133
|
+
us: slug,
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
return sidebar
|
138
|
+
}
|
139
|
+
|
128
140
|
export async function processExercise(
|
129
141
|
bucket: Bucket,
|
130
142
|
rigoToken: string,
|
@@ -654,6 +666,89 @@ export default class ServeCommand extends SessionCommand {
|
|
654
666
|
res.send({ message: "Files deleted" })
|
655
667
|
})
|
656
668
|
|
669
|
+
app.get("/translations/sidebar", async (req, res) => {
|
670
|
+
const { slug } = req.query
|
671
|
+
|
672
|
+
const rigoToken = req.header("x-rigo-token")
|
673
|
+
|
674
|
+
console.log("GETTING SIDEBAR FOR", slug)
|
675
|
+
|
676
|
+
if (!slug) {
|
677
|
+
return res.status(400).json({ error: "Slug is required" })
|
678
|
+
}
|
679
|
+
|
680
|
+
const courseSlug = slug as string
|
681
|
+
|
682
|
+
try {
|
683
|
+
const file = bucket.file(`courses/${courseSlug}/.learn/sidebar.json`)
|
684
|
+
|
685
|
+
const [content] = await file.download()
|
686
|
+
|
687
|
+
const sidebar = JSON.parse(content.toString())
|
688
|
+
|
689
|
+
if (rigoToken) {
|
690
|
+
const { exercises } = await buildConfig(bucket, courseSlug)
|
691
|
+
const { fixedSidebar, valid } = await checkAndFixSidebarPure(
|
692
|
+
sidebar,
|
693
|
+
exercises,
|
694
|
+
rigoToken
|
695
|
+
)
|
696
|
+
if (fixedSidebar) {
|
697
|
+
await uploadFileToBucket(
|
698
|
+
bucket,
|
699
|
+
JSON.stringify(fixedSidebar),
|
700
|
+
`courses/${courseSlug}/.learn/sidebar.json`
|
701
|
+
)
|
702
|
+
return res.json(fixedSidebar)
|
703
|
+
}
|
704
|
+
}
|
705
|
+
|
706
|
+
res.json(sidebar)
|
707
|
+
} catch (error: any) {
|
708
|
+
if (error.code === 404) {
|
709
|
+
console.log("SIDEBAR FILE NOT FOUND", courseSlug)
|
710
|
+
|
711
|
+
const { exercises } = await buildConfig(bucket, courseSlug)
|
712
|
+
|
713
|
+
const exerciseSlugsArray = exercises.map(exercise => exercise.slug)
|
714
|
+
const sidebar = await createInitialSidebar(exerciseSlugsArray)
|
715
|
+
|
716
|
+
if (rigoToken) {
|
717
|
+
const { fixedSidebar } = await checkAndFixSidebarPure(
|
718
|
+
sidebar,
|
719
|
+
exercises,
|
720
|
+
rigoToken
|
721
|
+
)
|
722
|
+
if (fixedSidebar) {
|
723
|
+
await uploadFileToBucket(
|
724
|
+
bucket,
|
725
|
+
JSON.stringify(fixedSidebar),
|
726
|
+
`courses/${courseSlug}/.learn/sidebar.json`
|
727
|
+
)
|
728
|
+
}
|
729
|
+
|
730
|
+
await uploadFileToBucket(
|
731
|
+
bucket,
|
732
|
+
JSON.stringify(sidebar),
|
733
|
+
`courses/${courseSlug}/.learn/sidebar.json`
|
734
|
+
)
|
735
|
+
return res.status(200).json(fixedSidebar)
|
736
|
+
}
|
737
|
+
|
738
|
+
await uploadFileToBucket(
|
739
|
+
bucket,
|
740
|
+
JSON.stringify(sidebar),
|
741
|
+
`courses/${courseSlug}/.learn/sidebar.json`
|
742
|
+
)
|
743
|
+
|
744
|
+
return res.status(200).json(sidebar)
|
745
|
+
}
|
746
|
+
|
747
|
+
console.error("Unexpected error:", error)
|
748
|
+
res.status(500).json({ error: error.message })
|
749
|
+
}
|
750
|
+
})
|
751
|
+
|
657
752
|
app.get("/test/:slug", (req, res) => {
|
658
753
|
emitToCourse(req.params.slug, "course-creation", {
|
659
754
|
lesson: "000-welcome-to-bird-domestication",
|
@@ -759,6 +854,19 @@ export default class ServeCommand extends SessionCommand {
|
|
759
854
|
)
|
760
855
|
await Promise.all(imagePromises)
|
761
856
|
|
857
|
+
const sidebar = await createInitialSidebar(
|
858
|
+
syllabus.lessons.map(lesson =>
|
859
|
+
slugify(lesson.id + "-" + lesson.title)
|
860
|
+
)
|
861
|
+
)
|
862
|
+
await uploadFileToBucket(
|
863
|
+
bucket,
|
864
|
+
JSON.stringify(sidebar),
|
865
|
+
`${tutorialDir}/.learn/sidebar.json`
|
866
|
+
)
|
867
|
+
|
868
|
+
console.log("SIDEBAR UPLOADED", sidebar)
|
869
|
+
|
762
870
|
return res.json({
|
763
871
|
message: "Course created",
|
764
872
|
slug: slugify(syllabus.courseInfo.title),
|
package/src/creator/index.html
CHANGED
package/src/creator/src/App.tsx
CHANGED
@@ -13,16 +13,26 @@ import { Uploader } from "./components/Uploader"
|
|
13
13
|
import toast from "react-hot-toast"
|
14
14
|
import { ParamsChecker } from "./components/ParamsChecker"
|
15
15
|
import { RIGO_FLOAT_GIT } from "./utils/constants"
|
16
|
+
// import TurnstileChallenge from "./components/TurnstileChallenge"
|
17
|
+
|
16
18
|
function App() {
|
17
19
|
const navigate = useNavigate()
|
18
20
|
|
19
|
-
const {
|
21
|
+
const {
|
22
|
+
formState,
|
23
|
+
setFormState,
|
24
|
+
setAuth,
|
25
|
+
push,
|
26
|
+
cleanHistory,
|
27
|
+
setPlanToRedirect,
|
28
|
+
} = useStore(
|
20
29
|
useShallow((state) => ({
|
21
30
|
formState: state.formState,
|
22
31
|
setFormState: state.setFormState,
|
23
32
|
setAuth: state.setAuth,
|
24
33
|
push: state.push,
|
25
34
|
cleanHistory: state.cleanHistory,
|
35
|
+
setPlanToRedirect: state.setPlanToRedirect,
|
26
36
|
}))
|
27
37
|
)
|
28
38
|
|
@@ -69,7 +79,11 @@ function App() {
|
|
69
79
|
}
|
70
80
|
|
71
81
|
const checkDescription = () => {
|
72
|
-
const { description, duration } = checkParams([
|
82
|
+
const { description, duration, plan } = checkParams([
|
83
|
+
"description",
|
84
|
+
"duration",
|
85
|
+
"plan",
|
86
|
+
])
|
73
87
|
if (description) {
|
74
88
|
console.log("description", description)
|
75
89
|
setFormState({
|
@@ -89,6 +103,12 @@ function App() {
|
|
89
103
|
console.log("Invalid duration received in params", duration)
|
90
104
|
}
|
91
105
|
}
|
106
|
+
|
107
|
+
if (plan) {
|
108
|
+
setPlanToRedirect(plan)
|
109
|
+
} else {
|
110
|
+
console.debug("No plan received in params")
|
111
|
+
}
|
92
112
|
}
|
93
113
|
|
94
114
|
const handleCreateTutorial = async () => {
|
@@ -189,39 +209,41 @@ function App() {
|
|
189
209
|
slug: "hasContentIndex",
|
190
210
|
isCompleted: false,
|
191
211
|
content: (
|
192
|
-
|
193
|
-
<
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
hasContentIndex: true,
|
198
|
-
currentStep: "contentIndex",
|
199
|
-
variables: [...formState.variables, "contentIndex"],
|
200
|
-
// variables: [...formState.variables.filter((v) => v !== "hasContentIndex"), "contentIndex"],
|
201
|
-
})
|
202
|
-
}}
|
203
|
-
selected={false}
|
204
|
-
/>
|
205
|
-
<SelectableCard
|
206
|
-
title="No, help me create one"
|
207
|
-
onClick={() => {
|
208
|
-
if (!formState.contentIndex && !formState.description) {
|
209
|
-
toast.error(
|
210
|
-
"Please provide at least a description for your course!"
|
211
|
-
)
|
212
|
+
<>
|
213
|
+
<div className="flex flex-col md:flex-row gap-2 justify-center">
|
214
|
+
<SelectableCard
|
215
|
+
title="Yes"
|
216
|
+
onClick={() => {
|
212
217
|
setFormState({
|
213
|
-
|
218
|
+
hasContentIndex: true,
|
219
|
+
currentStep: "contentIndex",
|
220
|
+
variables: [...formState.variables, "contentIndex"],
|
221
|
+
// variables: [...formState.variables.filter((v) => v !== "hasContentIndex"), "contentIndex"],
|
214
222
|
})
|
215
|
-
|
216
|
-
}
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
223
|
+
}}
|
224
|
+
selected={false}
|
225
|
+
/>
|
226
|
+
<SelectableCard
|
227
|
+
title="No, help me create one"
|
228
|
+
onClick={() => {
|
229
|
+
if (!formState.contentIndex && !formState.description) {
|
230
|
+
toast.error(
|
231
|
+
"Please provide at least a description for your course!"
|
232
|
+
)
|
233
|
+
setFormState({
|
234
|
+
currentStep: "description",
|
235
|
+
})
|
236
|
+
return
|
237
|
+
}
|
238
|
+
setFormState({
|
239
|
+
hasContentIndex: false,
|
240
|
+
isCompleted: true,
|
241
|
+
})
|
242
|
+
}}
|
243
|
+
selected={false}
|
244
|
+
/>
|
245
|
+
</div>
|
246
|
+
</>
|
225
247
|
),
|
226
248
|
},
|
227
249
|
{
|
@@ -252,13 +274,15 @@ function App() {
|
|
252
274
|
return (
|
253
275
|
<>
|
254
276
|
<ParamsChecker />
|
277
|
+
{/* <div id="turnstile-container" style={{ display: "none" }} /> */}
|
278
|
+
|
255
279
|
{formState.isCompleted ? (
|
256
280
|
<Loader
|
257
281
|
text="Learnpack is setting up your tutorial. It may take a moment..."
|
258
282
|
icon={<img src={RIGO_FLOAT_GIT} alt="rigo" className="w-20 h-20" />}
|
259
283
|
/>
|
260
284
|
) : (
|
261
|
-
|
285
|
+
<div className="">
|
262
286
|
<StepWizard
|
263
287
|
formState={formState}
|
264
288
|
steps={buildSteps()}
|
@@ -269,7 +293,7 @@ function App() {
|
|
269
293
|
})
|
270
294
|
}}
|
271
295
|
/>
|
272
|
-
|
296
|
+
</div>
|
273
297
|
)}
|
274
298
|
</>
|
275
299
|
)
|
@@ -11,6 +11,7 @@ export default function Login({ onFinish }: { onFinish: () => void }) {
|
|
11
11
|
const [password, setPassword] = useState("")
|
12
12
|
const [isLoading, setIsLoading] = useState(false)
|
13
13
|
const [showForm, setShowForm] = useState(false)
|
14
|
+
const planToRedirect = useStore((state) => state.planToRedirect)
|
14
15
|
|
15
16
|
const { setAuth } = useStore(
|
16
17
|
useShallow((state) => ({ setAuth: state.setAuth }))
|
@@ -136,7 +137,7 @@ export default function Login({ onFinish }: { onFinish: () => void }) {
|
|
136
137
|
<div className="bg-blue-50 text-sm p-2 rounded text-left">
|
137
138
|
<p className="text-gray-700 m-0">You don't have an account?</p>
|
138
139
|
<a
|
139
|
-
href=
|
140
|
+
href={`https://4geeks.com/checkout?plan=${planToRedirect}`}
|
140
141
|
target="_blank"
|
141
142
|
className="text-blue-600 font-medium"
|
142
143
|
>
|
@@ -0,0 +1,83 @@
|
|
1
|
+
// components/TurnstileChallenge.tsx
|
2
|
+
import { useEffect, useRef, useState } from "react"
|
3
|
+
import toast from "react-hot-toast"
|
4
|
+
|
5
|
+
interface TurnstileChallengeProps {
|
6
|
+
siteKey: string
|
7
|
+
onSuccess: (token: string) => void
|
8
|
+
onError?: () => void
|
9
|
+
autoStart?: boolean
|
10
|
+
}
|
11
|
+
|
12
|
+
declare global {
|
13
|
+
interface Window {
|
14
|
+
turnstile: any
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
const TurnstileChallenge = ({
|
19
|
+
siteKey,
|
20
|
+
onSuccess,
|
21
|
+
onError,
|
22
|
+
autoStart = true,
|
23
|
+
}: TurnstileChallengeProps) => {
|
24
|
+
const containerId = "cf-turnstile-container"
|
25
|
+
const widgetId = useRef<string | null>(null)
|
26
|
+
const [ready, setReady] = useState(false)
|
27
|
+
|
28
|
+
useEffect(() => {
|
29
|
+
const tryRender = () => {
|
30
|
+
if (!window.turnstile || !document.getElementById(containerId)) return
|
31
|
+
|
32
|
+
if (widgetId.current) return
|
33
|
+
|
34
|
+
const id = window.turnstile.render(`#${containerId}`, {
|
35
|
+
sitekey: siteKey,
|
36
|
+
callback: (token: string) => {
|
37
|
+
console.log("token to send", token)
|
38
|
+
|
39
|
+
onSuccess(token)
|
40
|
+
},
|
41
|
+
"error-callback": () => {
|
42
|
+
onError?.()
|
43
|
+
},
|
44
|
+
"refresh-callback": () => {
|
45
|
+
console.log("refresh callback CALLEd")
|
46
|
+
toast.error("Refresh callback called")
|
47
|
+
},
|
48
|
+
})
|
49
|
+
|
50
|
+
widgetId.current = id
|
51
|
+
setReady(true)
|
52
|
+
}
|
53
|
+
|
54
|
+
const interval = setInterval(() => {
|
55
|
+
if (window.turnstile && document.getElementById(containerId)) {
|
56
|
+
clearInterval(interval)
|
57
|
+
if (autoStart) tryRender()
|
58
|
+
}
|
59
|
+
}, 200)
|
60
|
+
|
61
|
+
return () => clearInterval(interval)
|
62
|
+
}, [siteKey, autoStart, onSuccess, onError])
|
63
|
+
|
64
|
+
// const reset = () => {
|
65
|
+
// if (widgetId.current && window.turnstile) {
|
66
|
+
// window.turnstile.reset(widgetId.current)
|
67
|
+
// }
|
68
|
+
// }
|
69
|
+
|
70
|
+
return (
|
71
|
+
// <div className="flex flex-col gap-4 bg-white w-full fixed bottom-0 left-0 right-0 p-4 h-full items-center justify-center">
|
72
|
+
<div className="">
|
73
|
+
{/* <h3 className="text-center text-2xl font-bold">
|
74
|
+
We must verify you are human
|
75
|
+
</h3> */}
|
76
|
+
<div id={containerId} data-refresh-timeout="auto" />
|
77
|
+
{!ready && <p className="">...</p>}
|
78
|
+
{/* <button onClick={reset}>RESET</button> */}
|
79
|
+
</div>
|
80
|
+
)
|
81
|
+
}
|
82
|
+
|
83
|
+
export default TurnstileChallenge
|
@@ -41,6 +41,8 @@ type Store = {
|
|
41
41
|
formState: FormState
|
42
42
|
setAuth: (auth: Auth) => void
|
43
43
|
// syllabus: Syllabus
|
44
|
+
planToRedirect: string
|
45
|
+
setPlanToRedirect: (planToRedirect: string) => void
|
44
46
|
uploadedFiles: UploadedFile[]
|
45
47
|
setUploadedFiles: (uploadedFiles: UploadedFile[]) => void
|
46
48
|
|
@@ -65,6 +67,8 @@ const useStore = create<Store>()(
|
|
65
67
|
userId: "",
|
66
68
|
user: null,
|
67
69
|
},
|
70
|
+
planToRedirect: "learnpack-creator",
|
71
|
+
setPlanToRedirect: (planToRedirect: string) => set({ planToRedirect }),
|
68
72
|
formState: {
|
69
73
|
description: "",
|
70
74
|
duration: 0,
|