@composable-os/pack-courses 0.1.0-beta.11 → 0.1.0-beta.14
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/dist/automations.js +1 -2
- package/dist/blocks/courses-builder/course-builder.js +15 -21
- package/dist/blocks/courses-catalogue/catalogue.js +2 -3
- package/dist/blocks/courses-course/course-page.d.ts +6 -1
- package/dist/blocks/courses-course/course-page.js +73 -9
- package/dist/blocks/courses-my-courses/my-courses.d.ts +14 -1
- package/dist/blocks/courses-my-courses/my-courses.js +9 -1
- package/dist/blocks/courses-native-catalogue/catalogue-screen.js +3 -6
- package/dist/blocks/courses-native-course/course-screen.js +2 -2
- package/dist/blocks/courses-native-my-courses/my-courses-screen.d.ts +14 -1
- package/dist/blocks/courses-native-my-courses/my-courses-screen.js +16 -3
- package/dist/blocks/courses-native-player/lesson-screen.d.ts +1 -0
- package/dist/blocks/courses-native-player/lesson-screen.js +2 -2
- package/dist/blocks/courses-native-subscription/subscription-screen.js +2 -2
- package/dist/blocks/courses-player/player.d.ts +1 -1
- package/dist/blocks/courses-subscribe/subscribe.d.ts +6 -1
- package/dist/blocks/courses-subscribe/subscribe.js +80 -9
- package/dist/blocks/courses-subscription/my-subscription.d.ts +6 -4
- package/dist/blocks/courses-subscription/my-subscription.js +14 -49
- package/dist/client/index.d.ts +382 -10
- package/dist/client/index.js +24 -36
- package/dist/dashboards.d.ts +2 -0
- package/dist/dashboards.js +3 -3
- package/dist/index.d.ts +82 -3
- package/dist/index.js +68 -3
- package/dist/outline.d.ts +1 -3
- package/dist/outline.js +25 -16
- package/dist/tools.d.ts +7 -1
- package/dist/tools.js +130 -103
- package/package.json +3 -3
package/dist/automations.js
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
// access to the course (the host's `requireAccess`), so no one else is assigned anything.
|
|
7
7
|
import { defineAutomation } from "@composable-os/sdk";
|
|
8
8
|
import { asOutline, sessionPrograms } from "./outline.js";
|
|
9
|
-
|
|
10
|
-
const PROGRESS = "courses.progress";
|
|
9
|
+
import { COURSE, PROGRESS } from "./tools.js";
|
|
11
10
|
const ASSIGNMENT = "programs.assignment";
|
|
12
11
|
export const assignSessions = defineAutomation({
|
|
13
12
|
label: "Assign a course's sessions",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { outlineEdits } from "@composable-os/pack-courses/client";
|
|
2
|
+
import { asOutline, COURSE, outlineEdits } from "@composable-os/pack-courses/client";
|
|
3
3
|
import { useEffect, useState } from "react";
|
|
4
4
|
import { Button } from "../ui-button/button.js";
|
|
5
5
|
import { Input } from "../ui-input/input.js";
|
|
@@ -20,37 +20,31 @@ export function CourseBuilder({ courses, courseId, }) {
|
|
|
20
20
|
const [message, setMessage] = useState(null);
|
|
21
21
|
const [newSection, setNewSection] = useState("");
|
|
22
22
|
useEffect(() => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
setOutline(value?.sections ? value : { sections: [] });
|
|
26
|
-
else if (working.data && !outline)
|
|
27
|
-
setOutline({ sections: [] });
|
|
23
|
+
if (working.data && !outline)
|
|
24
|
+
setOutline(asOutline(working.data.values.outline));
|
|
28
25
|
}, [working.data, outline]);
|
|
29
26
|
if (working.isPending || !outline)
|
|
30
27
|
return _jsx("p", { "aria-busy": "true", children: "Loading the course\u2026" });
|
|
31
28
|
if (working.error)
|
|
32
29
|
return _jsx("p", { role: "alert", children: "This course is not here." });
|
|
33
|
-
|
|
30
|
+
/** Runs the step and says how it went: `done`, or the host's reason (`failed` without one). */
|
|
31
|
+
const act = async (step, done, failed) => {
|
|
34
32
|
setMessage(null);
|
|
35
33
|
try {
|
|
36
|
-
await
|
|
37
|
-
setMessage(
|
|
34
|
+
await step();
|
|
35
|
+
setMessage(done);
|
|
38
36
|
}
|
|
39
37
|
catch (e) {
|
|
40
|
-
setMessage(e instanceof Error ? e.message :
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
const onPublish = async () => {
|
|
44
|
-
setMessage(null);
|
|
45
|
-
try {
|
|
46
|
-
await save.mutateAsync({ object: "courses.course", id: courseId, values: { outline } });
|
|
47
|
-
await publish.mutateAsync({ object: "courses.course", id: courseId });
|
|
48
|
-
setMessage("Published");
|
|
49
|
-
}
|
|
50
|
-
catch (e) {
|
|
51
|
-
setMessage(e instanceof Error ? e.message : "Not published");
|
|
38
|
+
setMessage(e instanceof Error ? e.message : failed);
|
|
52
39
|
}
|
|
53
40
|
};
|
|
41
|
+
const saveOutline = () => save.mutateAsync({ object: COURSE, id: courseId, values: { outline } });
|
|
42
|
+
const onSave = () => act(saveOutline, "Saved", "Not saved");
|
|
43
|
+
// A person publishes what they see: the working copy is saved first.
|
|
44
|
+
const onPublish = () => act(async () => {
|
|
45
|
+
await saveOutline();
|
|
46
|
+
await publish.mutateAsync({ object: COURSE, id: courseId });
|
|
47
|
+
}, "Published", "Not published");
|
|
54
48
|
return (_jsxs("section", { className: "grid gap-6", "aria-label": "Course builder", children: [outline.sections.map((section, s) => (_jsxs("fieldset", { className: "grid gap-3 rounded-lg border p-4", children: [_jsx("legend", { className: "px-1 font-semibold", children: section.title }), _jsx("ol", { className: "grid gap-3", children: (section.lessons ?? []).map((lesson, i) => (_jsxs("li", { className: "grid gap-2 rounded border p-3", "aria-label": lesson.title, children: [_jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx(Input, { "aria-label": "Lesson title", value: lesson.title, onChange: (e) => setOutline(outlineEdits.updateLesson(outline, lesson.key, { title: e.target.value })) }), _jsx("span", { className: "text-sm", children: KINDS.find((k) => k.value === lesson.kind)?.label }), _jsx(Button, { size: "sm", variant: "ghost", "aria-label": "Move up", disabled: i === 0, onClick: () => setOutline(outlineEdits.moveLesson(outline, lesson.key, section.key, i - 1)), children: "\u2191" }), _jsx(Button, { size: "sm", variant: "ghost", "aria-label": "Move down", onClick: () => setOutline(outlineEdits.moveLesson(outline, lesson.key, section.key, i + 1)), children: "\u2193" }), s > 0 ? (_jsx(Button, { size: "sm", variant: "ghost", onClick: () => setOutline(outlineEdits.moveLesson(outline, lesson.key, outline.sections[s - 1]?.key ?? section.key, 999)), children: "To the section above" })) : null, _jsx(Button, { size: "sm", variant: "ghost", onClick: () => setOutline(outlineEdits.removeLesson(outline, lesson.key)), children: "Remove" })] }), _jsxs("label", { className: "flex items-center gap-2 text-sm", children: [_jsx("input", { type: "checkbox", checked: lesson.preview === true, onChange: (e) => setOutline(outlineEdits.updateLesson(outline, lesson.key, {
|
|
55
49
|
preview: e.target.checked,
|
|
56
50
|
})) }), "Free preview"] }), lesson.kind === "video" || lesson.kind === "session" ? (_jsxs("label", { className: "grid gap-1 text-sm", children: [lesson.kind === "video" ? "Video" : "Video to follow along to (optional)", _jsxs("select", { value: ("video" in lesson && lesson.video?.media) || "", onChange: (e) => setOutline(outlineEdits.updateLesson(outline, lesson.key, {
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { formatPrice, mediaPath } from "@composable-os/pack-courses/client";
|
|
2
|
+
import { formatPrice, levelName, mediaPath } from "@composable-os/pack-courses/client";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { Button } from "../ui-button/button.js";
|
|
5
5
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui-card/card.js";
|
|
6
|
-
const LEVELS = { 1: "Beginner", 2: "Intermediate", 3: "Advanced" };
|
|
7
6
|
export function CourseCatalogue({ courses, onOpenCourse, onOpenBundle, }) {
|
|
8
7
|
const [theme, setTheme] = useState(undefined);
|
|
9
8
|
const { data, isPending, error } = courses.useCatalogue(theme ? { theme } : {});
|
|
@@ -12,7 +11,7 @@ export function CourseCatalogue({ courses, onOpenCourse, onOpenBundle, }) {
|
|
|
12
11
|
if (error || !data)
|
|
13
12
|
return _jsx("p", { role: "alert", children: "We could not load the courses. Try again soon." });
|
|
14
13
|
return (_jsxs("section", { className: "grid gap-6", "aria-label": "Courses", children: [data.themes.length ? (_jsxs("nav", { className: "flex flex-wrap gap-2", "aria-label": "Themes", children: [_jsx(Button, { variant: theme ? "outline" : "default", size: "sm", onClick: () => setTheme(undefined), children: "All" }), data.themes.map((t) => (_jsx(Button, { size: "sm", variant: theme === t.id ? "default" : "outline", onClick: () => setTheme(t.id), children: t.name }, t.id)))] })) : null, data.courses.length ? null : _jsx("p", { children: "No courses yet." }), _jsx("ul", { className: "grid gap-4 sm:grid-cols-2", children: data.courses.map((course) => (_jsx("li", { children: _jsxs(Card, { children: [course.cover ? (_jsx("img", { src: mediaPath(course.cover.media, 640), alt: "", className: "w-full rounded-t-lg" })) : null, _jsxs(CardHeader, { children: [_jsx(CardTitle, { children: course.title }), _jsx(CardDescription, { children: [
|
|
15
|
-
course.level
|
|
14
|
+
levelName(course.level),
|
|
16
15
|
`${course.lessons} lessons`,
|
|
17
16
|
formatPrice(course.price, data.currency),
|
|
18
17
|
]
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import { type AgreementsHooks } from "@composable-os/client";
|
|
1
2
|
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
|
-
|
|
3
|
+
/** The agreements hooks the inline step uses: a member's (due, accept) and a visitor's (words). */
|
|
4
|
+
export type CourseAgreements = Pick<AgreementsHooks, "useDue" | "useAccept" | "useGuestVersions">;
|
|
5
|
+
export declare function CoursePage({ courses, agreements, slug, returnUrl, signedIn, onOpenLesson, }: {
|
|
3
6
|
courses: Pick<CoursesHooks, "useCourse" | "useBuy" | "usePlayback">;
|
|
7
|
+
/** For what must be agreed to first, shown inline. Without it, the refusal is only named. */
|
|
8
|
+
agreements?: CourseAgreements;
|
|
4
9
|
slug: string;
|
|
5
10
|
/** Where the provider's page sends the buyer back to (one of the host's listed origins). */
|
|
6
11
|
returnUrl: string;
|
|
@@ -1,34 +1,75 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
|
|
2
|
+
// A course's page on a studio's site (stage 42): its description, trailer and outline with lesson
|
|
3
|
+
// titles and minutes, the free previews, and either "buy" or "open". Whether the visitor holds the
|
|
4
|
+
// course, and its price, are the host's (`useCourse`); buying is the host's order and the
|
|
5
|
+
// provider's page (`useBuy`); a trailer plays with a token the host signs (`usePlayback`).
|
|
6
|
+
//
|
|
7
|
+
// What must be agreed to first (stage 44: the course's terms) is the host's answer too: when "Buy"
|
|
8
|
+
// is refused with it, the documents are shown inline (the web-agree block's step) and "Buy" is
|
|
9
|
+
// tried again (issue #292). A visitor's agreements travel in the buying call, held in memory until
|
|
10
|
+
// then; a member's are recorded as they agree. A minor is told a parent or guardian buys it.
|
|
11
|
+
import { agreementRefusal, forgetAfter, purchaseErrorWords, withAgreements, } from "@composable-os/client";
|
|
12
|
+
import { COURSE, formatPrice, minutes } from "@composable-os/pack-courses/client";
|
|
3
13
|
import { useState } from "react";
|
|
4
14
|
import { Button } from "../ui-button/button.js";
|
|
5
15
|
import { Input } from "../ui-input/input.js";
|
|
6
16
|
import { Label } from "../ui-label/label.js";
|
|
7
|
-
|
|
17
|
+
import { useForgetOnLeave } from "../web-agree/agree.js";
|
|
18
|
+
import { GuestAgreementStep, MemberAgreementStep } from "../web-agree/agreement-step.js";
|
|
19
|
+
export function CoursePage({ courses, agreements, slug, returnUrl, signedIn, onOpenLesson, }) {
|
|
8
20
|
const { data: course, isPending, error } = courses.useCourse(slug);
|
|
9
21
|
const trailer = courses.usePlayback(course?.trailer
|
|
10
22
|
? {
|
|
11
23
|
media: course.trailer.media,
|
|
12
|
-
record: { object:
|
|
24
|
+
record: { object: COURSE, id: course.id },
|
|
13
25
|
field: "trailer",
|
|
14
26
|
}
|
|
15
27
|
: null);
|
|
16
28
|
const buy = courses.useBuy();
|
|
17
29
|
const [email, setEmail] = useState("");
|
|
18
30
|
const [problem, setProblem] = useState(null);
|
|
31
|
+
const [busy, setBusy] = useState(false);
|
|
32
|
+
// What the host said must be agreed to first.
|
|
33
|
+
const [due, setDue] = useState(null);
|
|
34
|
+
// A visitor's agreements: this component's state only, kept if the order does not start
|
|
35
|
+
// (nothing typed twice), forgotten once it starts and when they leave the page.
|
|
36
|
+
const [agreed, setAgreed] = useState(null);
|
|
37
|
+
// A member's "a copy is on its way".
|
|
38
|
+
const [said, setSaid] = useState(null);
|
|
39
|
+
useForgetOnLeave(() => setAgreed(null));
|
|
19
40
|
if (isPending)
|
|
20
41
|
return _jsx("p", { "aria-busy": "true", children: "Loading the course\u2026" });
|
|
21
42
|
if (error || !course)
|
|
22
43
|
return _jsx("p", { role: "alert", children: "This course is not here." });
|
|
23
|
-
async function onBuy() {
|
|
44
|
+
async function onBuy(given = agreed) {
|
|
24
45
|
if (!course)
|
|
25
46
|
return;
|
|
26
47
|
setProblem(null);
|
|
48
|
+
setBusy(true);
|
|
27
49
|
try {
|
|
28
|
-
const
|
|
29
|
-
|
|
50
|
+
const courseId = course.id;
|
|
51
|
+
const outcome = await withAgreements((previous) => forgetAfter(buy.start, {
|
|
52
|
+
courseId,
|
|
30
53
|
...(signedIn ? {} : { email }),
|
|
31
|
-
|
|
54
|
+
...(!signedIn && given && previous?.kind !== "read_again" ? { agreements: given } : {}),
|
|
55
|
+
}));
|
|
56
|
+
if (outcome.kind !== "done")
|
|
57
|
+
setAgreed(null);
|
|
58
|
+
if (outcome.kind === "due") {
|
|
59
|
+
if (agreements)
|
|
60
|
+
setDue(outcome.documents);
|
|
61
|
+
else {
|
|
62
|
+
setProblem(`Something must be agreed to first: ${outcome.documents.map((d) => d.title).join(", ")}.`);
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (outcome.kind === "minor_payer") {
|
|
67
|
+
setProblem(outcome.message);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const order = outcome.value;
|
|
71
|
+
// Recorded with the order: nothing of it is kept here any more.
|
|
72
|
+
setAgreed(null);
|
|
32
73
|
const checkout = await buy.checkout.mutateAsync({
|
|
33
74
|
id: order.id,
|
|
34
75
|
...(order.token ? { token: order.token } : {}),
|
|
@@ -37,9 +78,32 @@ export function CoursePage({ courses, slug, returnUrl, signedIn, onOpenLesson, }
|
|
|
37
78
|
window.location.assign(checkout.url);
|
|
38
79
|
}
|
|
39
80
|
catch (e) {
|
|
40
|
-
|
|
81
|
+
const refusal = agreementRefusal(e);
|
|
82
|
+
if (refusal)
|
|
83
|
+
setAgreed(null);
|
|
84
|
+
setProblem(purchaseErrorWords(e) ??
|
|
85
|
+
(refusal
|
|
86
|
+
? refusal.message
|
|
87
|
+
: e instanceof Error
|
|
88
|
+
? e.message
|
|
89
|
+
: "We could not start your order"));
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
setBusy(false);
|
|
41
93
|
}
|
|
42
94
|
}
|
|
95
|
+
if (due && agreements) {
|
|
96
|
+
const back = () => setDue(null);
|
|
97
|
+
return signedIn ? (_jsx(MemberAgreementStep, { agreements: agreements, documents: due, continueLabel: "Agree and buy", onCancel: back, onAgreed: (copy) => {
|
|
98
|
+
setDue(null);
|
|
99
|
+
setSaid(copy);
|
|
100
|
+
void onBuy(null);
|
|
101
|
+
} })) : (_jsx(GuestAgreementStep, { agreements: agreements, documents: due, continueLabel: "Agree and buy", onCancel: back, onAgreed: (given) => {
|
|
102
|
+
setDue(null);
|
|
103
|
+
setAgreed(given);
|
|
104
|
+
void onBuy(given);
|
|
105
|
+
} }));
|
|
106
|
+
}
|
|
43
107
|
return (_jsxs("article", { className: "grid gap-6", "aria-labelledby": "course-title", children: [_jsx("h1", { id: "course-title", className: "text-3xl font-semibold", children: course.title }), course.summary ? _jsx("p", { className: "text-lg", children: course.summary }) : null, trailer.data ? (_jsx("video", { controls: true, playsInline: true, src: trailer.data.hls, poster: trailer.data.poster, className: "w-full rounded-lg" })) : null, course.holds ? (_jsx("p", { children: _jsx(Button, { onClick: () => {
|
|
44
108
|
const first = course.sections[0]?.lessons[0];
|
|
45
109
|
if (first)
|
|
@@ -47,5 +111,5 @@ export function CoursePage({ courses, slug, returnUrl, signedIn, onOpenLesson, }
|
|
|
47
111
|
}, children: "Open the course" }) })) : (_jsxs("form", { className: "grid max-w-sm gap-2", onSubmit: (e) => {
|
|
48
112
|
e.preventDefault();
|
|
49
113
|
void onBuy();
|
|
50
|
-
}, children: [signedIn ? null : (_jsxs(_Fragment, { children: [_jsx(Label, { htmlFor: "buyer-email", children: "Your email" }), _jsx(Input, { id: "buyer-email", type: "email", required: true, value: email, onChange: (e) => setEmail(e.target.value) })] })), _jsx(Button, { type: "submit", disabled:
|
|
114
|
+
}, children: [signedIn ? null : (_jsxs(_Fragment, { children: [_jsx(Label, { htmlFor: "buyer-email", children: "Your email" }), _jsx(Input, { id: "buyer-email", type: "email", required: true, value: email, onChange: (e) => setEmail(e.target.value) })] })), _jsx(Button, { type: "submit", disabled: busy, children: `Buy · ${formatPrice(course.price, course.currency)}` }), said ? _jsx("p", { role: "status", children: said }) : null, agreed ? (_jsx("p", { className: "text-sm", children: "What you agreed to is kept for this order: press Buy to try again." })) : null, problem ? _jsx("p", { role: "alert", children: problem }) : null] })), _jsx("ol", { className: "grid gap-4", "aria-label": "Outline", children: course.sections.map((section) => (_jsxs("li", { children: [_jsx("h2", { className: "text-xl font-semibold", children: section.title }), _jsx("ul", { className: "grid gap-1", children: section.lessons.map((lesson) => (_jsxs("li", { className: "flex items-center justify-between gap-2", children: [_jsxs("span", { children: [course.done.includes(lesson.key) ? "✓ " : "", lesson.title, lesson.duration ? ` · ${minutes(lesson.duration)}` : ""] }), course.holds || lesson.preview ? (_jsx(Button, { size: "sm", variant: "ghost", onClick: () => onOpenLesson(course.id, lesson.key), children: lesson.preview && !course.holds ? "Watch the preview" : "Open" })) : null] }, lesson.key))) })] }, section.key))) })] }));
|
|
51
115
|
}
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
2
|
export declare function MyCourses({ courses, onContinue, }: {
|
|
3
3
|
courses: Pick<CoursesHooks, "useMyCourses">;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Opens a course where to carry on. Left out (as a section of My account, ADR 0710), there is no
|
|
6
|
+
* button.
|
|
7
|
+
*/
|
|
8
|
+
onContinue?: (courseId: string, lessonKey: string | null) => void;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
/**
|
|
11
|
+
* The Courses section of My account (ADR 0710): what they hold, then their course subscription,
|
|
12
|
+
* when they have one, with what they can do to it (`courses-subscription`).
|
|
13
|
+
*/
|
|
14
|
+
export declare function MyCoursesSection({ courses, }: {
|
|
15
|
+
courses: Pick<CoursesHooks, "useMyCourses" | "useMySubscriptions" | "useCancelSubscription" | "useResumeSubscription">;
|
|
16
|
+
/** Given by the account shell; the card is My account's Payment method section. */
|
|
17
|
+
returnUrl?: string;
|
|
5
18
|
}): import("react").JSX.Element;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { MySubscription } from "../courses-subscription/my-subscription.js";
|
|
2
3
|
import { Button } from "../ui-button/button.js";
|
|
3
4
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui-card/card.js";
|
|
4
5
|
const WHY = {
|
|
@@ -16,5 +17,12 @@ export function MyCourses({ courses, onContinue, }) {
|
|
|
16
17
|
return _jsx("p", { role: "alert", children: "We could not load your courses." });
|
|
17
18
|
if (!data.courses.length)
|
|
18
19
|
return _jsx("p", { children: "You have no courses yet." });
|
|
19
|
-
return (_jsx("ul", { className: "grid gap-4", "aria-label": "My courses", children: data.courses.map((course) => (_jsx("li", { children: _jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: course.title }), _jsx(CardDescription, { children: `${WHY[course.why]} · ${course.complete ? "Complete" : `${course.done} of ${course.counted} lessons done`}` })] }), _jsxs(CardContent, { children: [_jsx("progress", { value: course.done, max: Math.max(course.counted, 1), "aria-label": "Progress", className: "w-full" }), _jsx(Button, { onClick: () => onContinue(course.id, course.continueWith), children: course.done ? "Carry on" : "Start" })] })] }) }, course.id))) }));
|
|
20
|
+
return (_jsx("ul", { className: "grid gap-4", "aria-label": "My courses", children: data.courses.map((course) => (_jsx("li", { children: _jsxs(Card, { children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: course.title }), _jsx(CardDescription, { children: `${WHY[course.why]} · ${course.complete ? "Complete" : `${course.done} of ${course.counted} lessons done`}` })] }), _jsxs(CardContent, { children: [_jsx("progress", { value: course.done, max: Math.max(course.counted, 1), "aria-label": "Progress", className: "w-full" }), onContinue ? (_jsx(Button, { onClick: () => onContinue(course.id, course.continueWith), children: course.done ? "Carry on" : "Start" })) : null] })] }) }, course.id))) }));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The Courses section of My account (ADR 0710): what they hold, then their course subscription,
|
|
24
|
+
* when they have one, with what they can do to it (`courses-subscription`).
|
|
25
|
+
*/
|
|
26
|
+
export function MyCoursesSection({ courses, }) {
|
|
27
|
+
return (_jsxs("div", { className: "grid gap-6", children: [_jsx(MyCourses, { courses: courses }), _jsx(MySubscription, { courses: courses, empty: null })] }));
|
|
20
28
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { levelName } from "@composable-os/pack-courses/client";
|
|
3
3
|
import { List } from "../native-base/list.js";
|
|
4
4
|
import { Row } from "../native-base/row.js";
|
|
5
5
|
import { Screen } from "../native-base/screen.js";
|
|
6
|
-
|
|
6
|
+
import { Text } from "../native-base/text.js";
|
|
7
7
|
export function CatalogueScreen({ courses, onOpen, }) {
|
|
8
8
|
const { data, isPending, error } = courses.useCatalogue({});
|
|
9
|
-
return (_jsxs(Screen, { title: "Courses", children: [isPending ? _jsx(Text, { accessibilityRole: "progressbar", children: "Loading courses\u2026" }) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load the courses." }) : null, data ? (_jsx(List, { empty: "No courses yet.", children: data.courses.map((course) => (_jsx(Row, { title: course.title ?? "Course", detail: [
|
|
10
|
-
course.level ? LEVELS[course.level] : null,
|
|
11
|
-
`${course.lessons} lessons`,
|
|
12
|
-
]
|
|
9
|
+
return (_jsxs(Screen, { title: "Courses", children: [isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading courses\u2026" })) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load the courses." }) : null, data ? (_jsx(List, { empty: "No courses yet.", children: data.courses.map((course) => (_jsx(Row, { title: course.title ?? "Course", detail: [levelName(course.level), `${course.lessons} lessons`]
|
|
13
10
|
.filter(Boolean)
|
|
14
11
|
.join(" · "), onPress: course.slug ? () => onOpen(course.slug) : undefined }, course.id))) })) : null] }));
|
|
15
12
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { minutes } from "@composable-os/pack-courses/client";
|
|
3
|
-
import { Text } from "react-native";
|
|
4
3
|
import { List } from "../native-base/list.js";
|
|
5
4
|
import { Row } from "../native-base/row.js";
|
|
6
5
|
import { Screen } from "../native-base/screen.js";
|
|
6
|
+
import { Text } from "../native-base/text.js";
|
|
7
7
|
export function CourseScreen({ courses, slug, onOpenLesson, }) {
|
|
8
8
|
const { data: course, isPending, error } = courses.useCourse(slug);
|
|
9
|
-
return (_jsxs(Screen, { title: course?.title ?? "Course", children: [isPending ? _jsx(Text, { accessibilityRole: "progressbar", children: "Loading the course\u2026" }) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "This course is not here." }) : null, course ? (_jsxs(_Fragment, { children: [course.summary ? _jsx(Text, { children: course.summary }) : null, course.holds ? null : _jsx(Text, { children: "Find this course on the studio's website." }), _jsx(List, { empty: "No lessons yet.", children: course.sections.flatMap((section) => section.lessons.map((lesson) => (_jsx(Row, { title: `${course.done.includes(lesson.key) ? "✓ " : ""}${lesson.title}`, detail: [
|
|
9
|
+
return (_jsxs(Screen, { title: course?.title ?? "Course", children: [isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading the course\u2026" })) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "This course is not here." }) : null, course ? (_jsxs(_Fragment, { children: [course.summary ? _jsx(Text, { children: course.summary }) : null, course.holds ? null : _jsx(Text, { children: "Find this course on the studio's website." }), _jsx(List, { empty: "No lessons yet.", children: course.sections.flatMap((section) => section.lessons.map((lesson) => (_jsx(Row, { title: `${course.done.includes(lesson.key) ? "✓ " : ""}${lesson.title}`, detail: [
|
|
10
10
|
section.title,
|
|
11
11
|
minutes(lesson.duration),
|
|
12
12
|
lesson.preview ? "Free preview" : null,
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
2
2
|
export declare function MyCoursesScreen({ courses, onContinue, }: {
|
|
3
3
|
courses: Pick<CoursesHooks, "useMyCourses">;
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Opens a course where to carry on. Left out (as a section of My account, ADR 0710), a row is
|
|
6
|
+
* not pressable.
|
|
7
|
+
*/
|
|
8
|
+
onContinue?: (courseId: string, lessonKey: string | null) => void;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
/**
|
|
11
|
+
* The Courses section of the app's My account (ADR 0710): what they hold, then their course
|
|
12
|
+
* subscription's state, read only, with "Manage on the website" (`onManage`, from the account
|
|
13
|
+
* shell) through My account's one subscriptions part.
|
|
14
|
+
*/
|
|
15
|
+
export declare function MyCoursesSectionScreen({ courses, onManage, }: {
|
|
16
|
+
courses: Pick<CoursesHooks, "useMyCourses" | "useMySubscriptions">;
|
|
17
|
+
onManage?: () => void;
|
|
5
18
|
}): import("react").JSX.Element;
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { subscriptionStatus } from "@composable-os/pack-courses/client";
|
|
3
|
+
import { MySubscriptions } from "../native-account-subscriptions/subscriptions.js";
|
|
3
4
|
import { List } from "../native-base/list.js";
|
|
4
5
|
import { Row } from "../native-base/row.js";
|
|
5
6
|
import { Screen } from "../native-base/screen.js";
|
|
7
|
+
import { Text } from "../native-base/text.js";
|
|
6
8
|
export function MyCoursesScreen({ courses, onContinue, }) {
|
|
9
|
+
return (_jsx(Screen, { title: "My courses", children: _jsx(CourseRows, { courses: courses, onContinue: onContinue }) }));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The Courses section of the app's My account (ADR 0710): what they hold, then their course
|
|
13
|
+
* subscription's state, read only, with "Manage on the website" (`onManage`, from the account
|
|
14
|
+
* shell) through My account's one subscriptions part.
|
|
15
|
+
*/
|
|
16
|
+
export function MyCoursesSectionScreen({ courses, onManage, }) {
|
|
17
|
+
return (_jsxs(Screen, { title: "My courses", children: [_jsx(CourseRows, { courses: courses }), _jsx(MySubscriptions, { account: { useSubscriptions: courses.useMySubscriptions }, onManage: onManage, empty: null, status: subscriptionStatus, manageWords: "Manage your subscription on the studio's website." })] }));
|
|
18
|
+
}
|
|
19
|
+
function CourseRows({ courses, onContinue, }) {
|
|
7
20
|
const { data, isPending, error } = courses.useMyCourses();
|
|
8
|
-
return (_jsxs(
|
|
21
|
+
return (_jsxs(_Fragment, { children: [isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading your courses\u2026" })) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load your courses." }) : null, data ? (_jsx(List, { empty: "You have no courses yet.", children: data.courses.map((course) => (_jsx(Row, { title: course.title ?? "Course", detail: course.complete ? "Complete" : `${course.done} of ${course.counted} lessons done`, onPress: onContinue ? () => onContinue(course.id, course.continueWith) : undefined }, course.id))) })) : null] }));
|
|
9
22
|
}
|
|
@@ -14,6 +14,7 @@ export declare function LessonScreen({ courses, courseId, lessonKey, Player, onN
|
|
|
14
14
|
lessonKey: string;
|
|
15
15
|
Player: (props: NativePlayerProps) => ReactNode;
|
|
16
16
|
onNext: (lessonKey: string) => void;
|
|
17
|
+
/** Draws rich text: Content's `content-native-rich-text` (`RichTextView`), copied with this block. */
|
|
17
18
|
renderText?: (value: unknown) => ReactNode;
|
|
18
19
|
renderSession?: (courseId: string, lessonKey: string) => ReactNode;
|
|
19
20
|
}): import("react").JSX.Element;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Text } from "react-native";
|
|
3
2
|
import { Button } from "../native-base/button.js";
|
|
4
3
|
import { Screen } from "../native-base/screen.js";
|
|
4
|
+
import { Text } from "../native-base/text.js";
|
|
5
5
|
export function LessonScreen({ courses, courseId, lessonKey, Player, onNext, renderText, renderSession, }) {
|
|
6
6
|
const { data, isPending, error } = courses.useLesson(courseId, lessonKey);
|
|
7
7
|
const playback = courses.usePlayback(data?.video ?? null);
|
|
8
8
|
const progress = courses.useProgress();
|
|
9
9
|
const lesson = data?.lesson;
|
|
10
|
-
return (_jsxs(Screen, { title: lesson?.title ?? "Lesson", children: [isPending ? _jsx(Text, { accessibilityRole: "progressbar", children: "Loading the lesson\u2026" }) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "This lesson is not here." }) : null, data && playback.data ? (_jsx(Player, { playback: playback.data, startAt: data.position ?? 0, onPosition: (position, duration) => progress.mutate({ courseId, lessonKey, position, duration }), onEnded: () => progress.mutate({ courseId, lessonKey, state: "done" }) })) : null, lesson?.kind === "text" && renderText ? renderText(lesson.body) : null, lesson?.kind === "video" && lesson.notes && renderText ? renderText(lesson.notes) : null, lesson?.kind === "session" && renderSession ? renderSession(courseId, lessonKey) : null, data ? (_jsx(Button, { label: data.state === "done" ? "Done" : "Mark as done", quiet: data.state === "done", onPress: () => progress.mutate({ courseId, lessonKey, state: "done" }) })) : null, data?.next ? (_jsx(Button, { label: `Next: ${data.next.title}`, quiet: true, onPress: () => data.next && onNext(data.next.key) })) : null] }));
|
|
10
|
+
return (_jsxs(Screen, { title: lesson?.title ?? "Lesson", children: [isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading the lesson\u2026" })) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "This lesson is not here." }) : null, data && playback.data ? (_jsx(Player, { playback: playback.data, startAt: data.position ?? 0, onPosition: (position, duration) => progress.mutate({ courseId, lessonKey, position, duration }), onEnded: () => progress.mutate({ courseId, lessonKey, state: "done" }) })) : null, lesson?.kind === "text" && renderText ? renderText(lesson.body) : null, lesson?.kind === "video" && lesson.notes && renderText ? renderText(lesson.notes) : null, lesson?.kind === "session" && renderSession ? renderSession(courseId, lessonKey) : null, data ? (_jsx(Button, { label: data.state === "done" ? "Done" : "Mark as done", quiet: data.state === "done", onPress: () => progress.mutate({ courseId, lessonKey, state: "done" }) })) : null, progress.error ? (_jsx(Text, { tone: "danger", accessibilityRole: "alert", children: "We could not save your progress. Check the connection and try again." })) : null, data?.next ? (_jsx(Button, { label: `Next: ${data.next.title}`, quiet: true, onPress: () => data.next && onNext(data.next.key) })) : null] }));
|
|
11
11
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { day, isLive, PLAN, subscriptionStatus } from "@composable-os/pack-courses/client";
|
|
3
|
-
import { Text } from "react-native";
|
|
4
3
|
import { List } from "../native-base/list.js";
|
|
5
4
|
import { Row } from "../native-base/row.js";
|
|
6
5
|
import { Screen } from "../native-base/screen.js";
|
|
6
|
+
import { Text } from "../native-base/text.js";
|
|
7
7
|
export function SubscriptionScreen({ courses, }) {
|
|
8
8
|
const { data, isPending, error } = courses.useMySubscriptions();
|
|
9
9
|
const offers = courses.useMyOffers();
|
|
10
10
|
const live = data?.items.filter(isLive) ?? [];
|
|
11
11
|
const offer = offers.data?.offers.find((o) => o.planObject === PLAN);
|
|
12
|
-
return (_jsxs(Screen, { title: "My subscription", children: [isPending ? _jsx(Text, { accessibilityRole: "progressbar", children: "Loading your subscription\u2026" }) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load your subscription." }) : null, data ? (_jsx(List, { empty: "You have no course subscription.", children: live.map((sub) => (_jsx(Row, { title: `${sub.planTitle}: every course`, detail: subscriptionStatus(sub) }, sub.id))) })) : null, offer && !live.length ? (_jsx(Text, { children: offer.askUs
|
|
12
|
+
return (_jsxs(Screen, { title: "My subscription", children: [isPending ? (_jsx(Text, { tone: "muted", accessibilityRole: "progressbar", children: "Loading your subscription\u2026" })) : null, error ? _jsx(Text, { accessibilityRole: "alert", children: "We could not load your subscription." }) : null, data ? (_jsx(List, { empty: "You have no course subscription.", children: live.map((sub) => (_jsx(Row, { title: `${sub.planTitle}: every course`, detail: subscriptionStatus(sub) }, sub.id))) })) : null, offer && !live.length ? (_jsx(Text, { children: offer.askUs
|
|
13
13
|
? `Your subscription with us is paid up to ${day(offer.freeUntil)}. Ask the studio to continue it.`
|
|
14
14
|
: offer.chargedNow
|
|
15
15
|
? `Your subscription with us was paid up to ${day(offer.freeUntil)}. Continue it on the studio's website.`
|
|
@@ -5,7 +5,7 @@ export declare function LessonPlayer({ courses, courseId, lessonKey, onNext, ren
|
|
|
5
5
|
courseId: string;
|
|
6
6
|
lessonKey: string;
|
|
7
7
|
onNext: (lessonKey: string) => void;
|
|
8
|
-
/** Draws rich text
|
|
8
|
+
/** Draws rich text: the Content pack's renderer, `content-rich-text`, copied with this block. */
|
|
9
9
|
renderText?: (value: unknown) => ReactNode;
|
|
10
10
|
/** Draws a session lesson's own Programs session (the Programs session block). */
|
|
11
11
|
renderSession?: (courseId: string, lessonKey: string) => ReactNode;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { type AgreementsHooks } from "@composable-os/client";
|
|
1
2
|
import type { CoursesHooks } from "@composable-os/pack-courses/client";
|
|
3
|
+
/** The agreements hooks the inline step uses: a member's (due, accept) and a visitor's (words). */
|
|
4
|
+
export type SubscribeAgreements = Pick<AgreementsHooks, "useDue" | "useAccept" | "useGuestVersions">;
|
|
2
5
|
/**
|
|
3
6
|
* Signing a guest in by an emailed code, as the app does it (the web sign-in block's two calls:
|
|
4
7
|
* the template's `/auth/code` and `/auth/sign-in`). `requestCode` says whether the host took the
|
|
@@ -10,8 +13,10 @@ export interface SubscribeSignIn {
|
|
|
10
13
|
requestCode: (email: string) => Promise<boolean>;
|
|
11
14
|
confirm: (email: string, code: string) => Promise<"ready" | "needs_attention" | null>;
|
|
12
15
|
}
|
|
13
|
-
export declare function Subscribe({ courses, returnUrl, signedIn, signInUrl, onSignInForTrial, signIn, }: {
|
|
16
|
+
export declare function Subscribe({ courses, agreements, returnUrl, signedIn, signInUrl, onSignInForTrial, signIn, }: {
|
|
14
17
|
courses: Pick<CoursesHooks, "usePlans" | "useSubscribe" | "useMyOffers">;
|
|
18
|
+
/** For what must be agreed to first, shown inline. Without it, the refusal is only named. */
|
|
19
|
+
agreements?: SubscribeAgreements;
|
|
15
20
|
/** Where the provider's page sends the subscriber back to (one of the host's listed origins). */
|
|
16
21
|
returnUrl: string;
|
|
17
22
|
/** A signed-in customer subscribes as themselves; a guest gives their email. */
|
|
@@ -1,11 +1,34 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// Subscribing to every course on a studio's site (stage 32a): the course plans with the host's
|
|
3
|
+
// price per month and trial days, and a button that opens the payment provider's page. The price
|
|
4
|
+
// is the host's (`usePlans`); whether the trial is given, and the page, are the host's
|
|
5
|
+
// (`useSubscribe`, `subscription.start`): one trial per person, signed in. Web only.
|
|
6
|
+
//
|
|
7
|
+
// A guest who wants the trial confirms their address with a code here, on the plan, when the app
|
|
8
|
+
// passes `signIn` (the same two calls as the web sign-in block), and goes on to the provider's
|
|
9
|
+
// page signed in, with the trial (ADR 0459). Whether a new address gets a code is the host's:
|
|
10
|
+
// with "anyone starting a subscription" on and a plan on sale, it does.
|
|
11
|
+
//
|
|
12
|
+
// A signed-in member moving from another platform sees their continuation offer in place of the
|
|
13
|
+
// trial ("continue, free until <date>", `useMyOffers`); taking it is the host's too (`offerId`):
|
|
14
|
+
// only its own person can (ADR 0491). A guest who confirms a code and turns out to have an offer
|
|
15
|
+
// is shown the offer, never sent on to the trial.
|
|
16
|
+
//
|
|
17
|
+
// What must be agreed to first (stage 44: the course terms) is the host's answer too: when
|
|
18
|
+
// "Subscribe" is refused with it, the documents are shown inline (the web-agree block's step) and
|
|
19
|
+
// "Subscribe" is tried again (issue #292). A visitor's agreements travel in subscription.start,
|
|
20
|
+
// held in memory until then; a member's are recorded as they agree. A minor is told a parent or
|
|
21
|
+
// guardian buys it.
|
|
22
|
+
import { agreementRefusal, forgetAfter, purchaseErrorWords, withAgreements, } from "@composable-os/client";
|
|
2
23
|
import { day, formatPrice, noTrialWords, offerFor, offerWords, PLAN, } from "@composable-os/pack-courses/client";
|
|
3
24
|
import { useState } from "react";
|
|
4
25
|
import { Button } from "../ui-button/button.js";
|
|
5
26
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "../ui-card/card.js";
|
|
6
27
|
import { Input } from "../ui-input/input.js";
|
|
7
28
|
import { Label } from "../ui-label/label.js";
|
|
8
|
-
|
|
29
|
+
import { useForgetOnLeave } from "../web-agree/agree.js";
|
|
30
|
+
import { GuestAgreementStep, MemberAgreementStep } from "../web-agree/agreement-step.js";
|
|
31
|
+
export function Subscribe({ courses, agreements, returnUrl, signedIn, signInUrl, onSignInForTrial, signIn, }) {
|
|
9
32
|
const { data, isPending, error } = courses.usePlans();
|
|
10
33
|
const subscribe = courses.useSubscribe();
|
|
11
34
|
const [email, setEmail] = useState("");
|
|
@@ -20,6 +43,14 @@ export function Subscribe({ courses, returnUrl, signedIn, signInUrl, onSignInFor
|
|
|
20
43
|
const [busy, setBusy] = useState(false);
|
|
21
44
|
// Confirmed, but the account waits for staff to merge people: subscribe as a guest meanwhile.
|
|
22
45
|
const [waiting, setWaiting] = useState(false);
|
|
46
|
+
// What the host said must be agreed to first, for which plan, and how it was being started.
|
|
47
|
+
const [due, setDue] = useState(null);
|
|
48
|
+
// A visitor's agreements for one plan: this component's state only, kept if the subscription
|
|
49
|
+
// does not start (nothing typed twice), forgotten once it starts and when they leave the page.
|
|
50
|
+
const [agreed, setAgreed] = useState(null);
|
|
51
|
+
// A member's "a copy is on its way".
|
|
52
|
+
const [said, setSaid] = useState(null);
|
|
53
|
+
useForgetOnLeave(() => setAgreed(null));
|
|
23
54
|
const asCustomer = signedIn || confirmed;
|
|
24
55
|
// Only a signed-in customer has offers; a guest's call would be refused, so it is not made.
|
|
25
56
|
const offers = courses.useMyOffers({ enabled: asCustomer });
|
|
@@ -35,16 +66,35 @@ export function Subscribe({ courses, returnUrl, signedIn, signInUrl, onSignInFor
|
|
|
35
66
|
const mine = asCustomer ? onPlans(offers.data?.offers) : [];
|
|
36
67
|
const continuing = mine.length > 0;
|
|
37
68
|
const askUs = mine.filter((o) => o.askUs);
|
|
38
|
-
async function onSubscribe(planId, hasTrial, customer = asCustomer, offer, owed = continuing) {
|
|
69
|
+
async function onSubscribe(planId, hasTrial, customer = asCustomer, offer, owed = continuing, given = agreed?.planId === planId ? agreed.given : null) {
|
|
39
70
|
setProblem(null);
|
|
40
71
|
setNoTrial(null);
|
|
41
72
|
try {
|
|
42
|
-
const
|
|
73
|
+
const outcome = await withAgreements((previous) => forgetAfter(subscribe, {
|
|
43
74
|
plan: { object: PLAN, id: planId },
|
|
44
75
|
returnUrl,
|
|
45
76
|
...(customer ? {} : { email }),
|
|
46
77
|
...(offer ? { offerId: offer.id } : {}),
|
|
47
|
-
|
|
78
|
+
...(!customer && given && previous?.kind !== "read_again" ? { agreements: given } : {}),
|
|
79
|
+
}));
|
|
80
|
+
if (outcome.kind !== "done")
|
|
81
|
+
setAgreed(null);
|
|
82
|
+
if (outcome.kind === "due") {
|
|
83
|
+
if (agreements) {
|
|
84
|
+
setDue({ planId, hasTrial, customer, offer, owed, documents: outcome.documents });
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
setProblem(`Something must be agreed to first: ${outcome.documents.map((d) => d.title).join(", ")}.`);
|
|
88
|
+
}
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (outcome.kind === "minor_payer") {
|
|
92
|
+
setProblem(outcome.message);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const started = outcome.value;
|
|
96
|
+
// Recorded with the checkout: nothing of it is kept here any more.
|
|
97
|
+
setAgreed(null);
|
|
48
98
|
// Never sent to a page that charges today without a word: the host's reason for no trial,
|
|
49
99
|
// or, for a member with free time owed on another plan, that this one is paid from today.
|
|
50
100
|
if (!offer && (owed || (hasTrial && started.noTrial))) {
|
|
@@ -54,7 +104,15 @@ export function Subscribe({ courses, returnUrl, signedIn, signInUrl, onSignInFor
|
|
|
54
104
|
window.location.assign(started.url);
|
|
55
105
|
}
|
|
56
106
|
catch (e) {
|
|
57
|
-
|
|
107
|
+
const refusal = agreementRefusal(e);
|
|
108
|
+
if (refusal)
|
|
109
|
+
setAgreed(null);
|
|
110
|
+
setProblem(purchaseErrorWords(e) ??
|
|
111
|
+
(refusal
|
|
112
|
+
? refusal.message
|
|
113
|
+
: e instanceof Error
|
|
114
|
+
? e.message
|
|
115
|
+
: "We could not start your subscription"));
|
|
58
116
|
}
|
|
59
117
|
}
|
|
60
118
|
/** The code step on the plan: ask for a code, then confirm it and start signed in. */
|
|
@@ -77,7 +135,7 @@ export function Subscribe({ courses, returnUrl, signedIn, signInUrl, onSignInFor
|
|
|
77
135
|
setConfirmed(true);
|
|
78
136
|
// Signed in now: if they have a continuation offer, they see it in place of the trial
|
|
79
137
|
// (the plans again), never a trial page opened over it.
|
|
80
|
-
const fresh = onPlans((await offers.refetch()).data?.offers);
|
|
138
|
+
const fresh = onPlans(offers.refetch ? (await offers.refetch()).data?.offers : []);
|
|
81
139
|
if (fresh.length) {
|
|
82
140
|
setNoTrial(null);
|
|
83
141
|
setCodeSent(false);
|
|
@@ -120,9 +178,22 @@ export function Subscribe({ courses, returnUrl, signedIn, signInUrl, onSignInFor
|
|
|
120
178
|
setBusy(false);
|
|
121
179
|
}
|
|
122
180
|
}
|
|
123
|
-
if (
|
|
181
|
+
if (due && agreements) {
|
|
182
|
+
const { planId, hasTrial, customer, offer, owed } = due;
|
|
183
|
+
const back = () => setDue(null);
|
|
184
|
+
return customer ? (_jsx(MemberAgreementStep, { agreements: agreements, documents: due.documents, continueLabel: "Agree and subscribe", onCancel: back, onAgreed: (copy) => {
|
|
185
|
+
setDue(null);
|
|
186
|
+
setSaid(copy);
|
|
187
|
+
void onSubscribe(planId, hasTrial, true, offer, owed, null);
|
|
188
|
+
} })) : (_jsx(GuestAgreementStep, { agreements: agreements, documents: due.documents, continueLabel: "Agree and subscribe", onCancel: back, onAgreed: (given) => {
|
|
189
|
+
setDue(null);
|
|
190
|
+
setAgreed({ planId, given });
|
|
191
|
+
void onSubscribe(planId, hasTrial, false, offer, owed, given);
|
|
192
|
+
} }));
|
|
193
|
+
}
|
|
194
|
+
const reason = noTrial?.started.noTrial;
|
|
195
|
+
if (noTrial && reason) {
|
|
124
196
|
const { planId, started } = noTrial;
|
|
125
|
-
const reason = started.noTrial;
|
|
126
197
|
return (_jsxs("section", { className: "grid max-w-sm gap-3", "aria-label": "Subscribe", "data-no-trial": reason, children: [_jsx("p", { role: "status", children: noTrialWords(reason) }), reason === "sign_in" && signIn ? (_jsxs("form", { className: "grid gap-2", onSubmit: (e) => void onCode(e, planId), children: [codeSent ? (_jsxs(_Fragment, { children: [_jsx("p", { className: "text-sm", children: `If ${email} can sign in here, we have emailed it a code.` }), _jsx(Label, { htmlFor: "subscriber-code", children: "The code we emailed you" }), _jsx(Input, { id: "subscriber-code", inputMode: "numeric", autoComplete: "one-time-code", required: true, value: code, onChange: (e) => setCode(e.target.value) })] })) : null, _jsx(Button, { type: "submit", disabled: busy || subscribe.isPending, children: codeSent ? "Confirm and start my free trial" : "Email me a code for the free trial" }), codeSent ? (_jsx(Button, { type: "button", variant: "outline", disabled: busy, onClick: () => void onNewCode(), children: "Send me a new code" })) : null, problem ? _jsx("p", { role: "alert", children: problem }) : null] })) : reason === "sign_in" && (onSignInForTrial || signInUrl) ? (_jsx(Button, { onClick: () => onSignInForTrial ? onSignInForTrial(planId) : window.location.assign(signInUrl ?? ""), children: "Sign in for the free trial" })) : null, _jsx(Button, { variant: "outline", onClick: () => window.location.assign(started.url), children: "Continue and pay from today" })] }));
|
|
127
198
|
}
|
|
128
199
|
return (_jsxs("section", { className: "grid gap-4", "aria-label": "Subscribe", children: [waiting ? (_jsx("p", { role: "status", children: "Your address is confirmed, but we need to sort out your record before you can have the free trial, and we have told the team. You can subscribe now and pay from today." })) : null, askUs.map((o) => (_jsx("p", { role: "status", "data-testid": "continuation-offer", children: offerWords(o) }, o.id))), data.plans.map((plan) => {
|
|
@@ -142,5 +213,5 @@ export function Subscribe({ courses, returnUrl, signedIn, signInUrl, onSignInFor
|
|
|
142
213
|
: asCustomer && trial
|
|
143
214
|
? `Start your ${trial}-day free trial`
|
|
144
215
|
: "Subscribe" }), offer && !offer.chargedNow ? (_jsx("p", { className: "text-sm", children: `Your card is taken now and first charged on ${day(offer.freeUntil)}, unless you cancel.` })) : null, asCustomer && trial ? (_jsx("p", { className: "text-sm", children: "Your card is taken now and charged when the trial ends, unless you cancel. One free trial per person." })) : null] })] })] }, plan.id));
|
|
145
|
-
}), problem ? _jsx("p", { role: "alert", children: problem }) : null] }));
|
|
216
|
+
}), said ? _jsx("p", { role: "status", children: said }) : null, agreed ? (_jsx("p", { className: "text-sm", children: "What you agreed to is kept for this subscription: press Subscribe to try again." })) : null, problem ? _jsx("p", { role: "alert", children: problem }) : null] }));
|
|
146
217
|
}
|