@ansiversa/components 0.0.102 → 0.0.104
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/package.json +1 -1
- package/src/Summary/QuizSummary.astro +11 -2
- package/src/Summary/types.ts +1 -0
- package/src/utils/appUrls.ts +25 -0
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
import { AvButton, AvCard } from "@ansiversa/components";
|
|
3
3
|
import type { QuizDashboardSummaryV1 } from "./types";
|
|
4
|
+
import { buildAppUrl } from "../utils/appUrls";
|
|
4
5
|
|
|
5
6
|
interface Props {
|
|
6
7
|
summary: QuizDashboardSummaryV1;
|
|
@@ -14,6 +15,11 @@ const formatDateTime = (value: string | null) => {
|
|
|
14
15
|
const date = new Date(value);
|
|
15
16
|
return Number.isNaN(date.getTime()) ? "No attempts yet" : date.toLocaleString();
|
|
16
17
|
};
|
|
18
|
+
const attemptsPrevious7d = summary.kpis.attemptsPrevious7d ?? null;
|
|
19
|
+
const attemptsDelta = typeof attemptsPrevious7d === "number"
|
|
20
|
+
? summary.kpis.attemptsLast7d - attemptsPrevious7d
|
|
21
|
+
: null;
|
|
22
|
+
const quizBaseUrl = buildAppUrl(summary.appId);
|
|
17
23
|
---
|
|
18
24
|
|
|
19
25
|
<section class="av-auth-stack-lg">
|
|
@@ -26,8 +32,8 @@ const formatDateTime = (value: string | null) => {
|
|
|
26
32
|
<p class="av-text-soft">Last attempt: {formatDateTime(summary.kpis.lastAttemptAt)}</p>
|
|
27
33
|
</div>
|
|
28
34
|
<div class="av-row-wrap">
|
|
29
|
-
<AvButton href=
|
|
30
|
-
<AvButton href="/results" size="sm" variant="ghost">View Results</AvButton>
|
|
35
|
+
<AvButton href={quizBaseUrl} size="sm">Open Quiz</AvButton>
|
|
36
|
+
<AvButton href={buildAppUrl(summary.appId, "/results")} size="sm" variant="ghost">View Results</AvButton>
|
|
31
37
|
</div>
|
|
32
38
|
</div>
|
|
33
39
|
|
|
@@ -44,6 +50,9 @@ const formatDateTime = (value: string | null) => {
|
|
|
44
50
|
<p class="av-card-heading">Attempts (7d)</p>
|
|
45
51
|
<h3 class="av-app-card-title">{summary.kpis.attemptsLast7d}</h3>
|
|
46
52
|
<p class="av-text-soft">Last 7 days</p>
|
|
53
|
+
<p class="av-text-soft">
|
|
54
|
+
vs previous 7d: {attemptsDelta === null ? "—" : `${attemptsDelta >= 0 ? "+" : ""}${attemptsDelta}`}
|
|
55
|
+
</p>
|
|
47
56
|
</div>
|
|
48
57
|
</AvCard>
|
|
49
58
|
<AvCard variant="soft" className="av-card--fullheight">
|
package/src/Summary/types.ts
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const ROOT_DOMAIN = "ansiversa.com";
|
|
2
|
+
|
|
3
|
+
const MINI_APP_SLUGS = new Set(["quiz"]);
|
|
4
|
+
|
|
5
|
+
export const getAppBaseUrl = (appSlug: string) => {
|
|
6
|
+
if (!appSlug) {
|
|
7
|
+
return `https://${ROOT_DOMAIN}`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (MINI_APP_SLUGS.has(appSlug)) {
|
|
11
|
+
return `https://${appSlug}.${ROOT_DOMAIN}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return `https://${ROOT_DOMAIN}/${appSlug}`;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const buildAppUrl = (appSlug: string, path = "/") => {
|
|
18
|
+
const baseUrl = getAppBaseUrl(appSlug);
|
|
19
|
+
|
|
20
|
+
if (!path || path === "/") {
|
|
21
|
+
return baseUrl;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return `${baseUrl}${path.startsWith("/") ? path : `/${path}`}`;
|
|
25
|
+
};
|