Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+44
@@ -0,0 +1,44 @@
|
||||
import { OnboardingFilter } from "@toolctrl/db/prisma-browser";
|
||||
import { i18nConfig } from "~/locale/i18n";
|
||||
import { OnboardingFilterDto } from "../dtos/OnboardingFilterDto";
|
||||
import { OnboardingFilterMetadataDto } from "../dtos/OnboardingFilterMetadataDto";
|
||||
import { OnboardingMatchingFilterDto } from "../dtos/OnboardingMatchingFilterDto";
|
||||
import { TFunction } from "i18next";
|
||||
|
||||
function getStepMatches({ t, matches, metadata }: { t: TFunction; matches: OnboardingMatchingFilterDto[]; metadata: OnboardingFilterMetadataDto }) {
|
||||
return matches.map((m) => {
|
||||
const filter = m.onboardingFilter;
|
||||
const value = parseValue({ t, filter, metadata });
|
||||
return {
|
||||
filter: filter.type,
|
||||
value,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
function parseValue({ t, filter, metadata }: { t: TFunction; filter: OnboardingFilterDto | OnboardingFilter; metadata: OnboardingFilterMetadataDto }) {
|
||||
if (filter.type.startsWith("user.is")) {
|
||||
const user = metadata.users.find((u) => u.id === filter.value);
|
||||
return user?.email;
|
||||
} else if (filter.type.startsWith("tenant.is")) {
|
||||
const tenant = metadata.tenants.find((t) => t.id === filter.value);
|
||||
return tenant?.name;
|
||||
} else if (filter.type.startsWith("tenant.subscription.products")) {
|
||||
const subscriptionProduct = metadata.subscriptionProducts.find((s) => s.id === filter.value);
|
||||
return t(subscriptionProduct?.title ?? "");
|
||||
} else if (filter.type.startsWith("user.roles")) {
|
||||
const role = metadata.roles.find((r) => r.name === filter.value);
|
||||
return role?.name;
|
||||
} else if (filter.type.startsWith("tenant.user.entity")) {
|
||||
const entity = metadata.entities.find((t) => t.id === filter.value);
|
||||
return entity?.name;
|
||||
} else if (filter.type.startsWith("user.language")) {
|
||||
const language = i18nConfig.supportedLngs.find((l) => l === filter.value);
|
||||
return language;
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
getStepMatches,
|
||||
parseValue,
|
||||
};
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
import { TFunction } from "i18next";
|
||||
import { OnboardingSessionWithDetails } from "../db/onboardingSessions.db.server";
|
||||
import { OnboardingFilterMetadataDto } from "../dtos/OnboardingFilterMetadataDto";
|
||||
import OnboardingFilterUtils from "./OnboardingFilterUtils";
|
||||
import OnboardingStepUtils from "./OnboardingStepUtils";
|
||||
|
||||
export type OnboardingSessionActivityDto = {
|
||||
type: "created-manually" | "created-realtime" | "started" | "click" | "input" | "seen" | "dismissed" | "completed" | "step-seen" | "step-completed";
|
||||
createdAt: Date | null;
|
||||
description: string;
|
||||
};
|
||||
function getActivity({ t, item, metadata }: { t: TFunction; item: OnboardingSessionWithDetails; metadata: OnboardingFilterMetadataDto }) {
|
||||
const items: OnboardingSessionActivityDto[] = [];
|
||||
const matchingFilters = OnboardingFilterUtils.getStepMatches({ t, matches: item.matches, metadata })
|
||||
.map((f) => f.filter + (f.value ? `: ${f.value}` : ""))
|
||||
.join(", ");
|
||||
if (item.createdRealtime) {
|
||||
items.push({
|
||||
type: "created-realtime",
|
||||
createdAt: item.createdAt,
|
||||
description: `${t("onboarding.filter.matching")}: ${matchingFilters}`,
|
||||
});
|
||||
} else {
|
||||
items.push({
|
||||
type: "created-manually",
|
||||
createdAt: item.createdAt,
|
||||
description: t("onboarding.session.activityDescription", { filters: matchingFilters }),
|
||||
});
|
||||
}
|
||||
if (item.startedAt) {
|
||||
items.push({ type: "started", createdAt: item.startedAt, description: t("onboarding.session.activityEvents.started") });
|
||||
}
|
||||
if (item.dismissedAt) {
|
||||
items.push({ type: "dismissed", createdAt: item.dismissedAt, description: t("onboarding.session.activityEvents.dismissed") });
|
||||
}
|
||||
if (item.completedAt) {
|
||||
items.push({ type: "completed", createdAt: item.completedAt, description: t("onboarding.session.activityEvents.completed") });
|
||||
}
|
||||
|
||||
item.actions.forEach((action) => {
|
||||
items.push({ type: action.type as "click" | "input", createdAt: action.createdAt, description: "[" + action.name + "] " + action.value });
|
||||
});
|
||||
|
||||
item.sessionSteps.forEach((step) => {
|
||||
const stepBlock = OnboardingStepUtils.parseStepToBlock(step.step);
|
||||
if (step.seenAt) {
|
||||
items.push({ type: "step-seen", createdAt: step.seenAt, description: t("onboarding.session.activityEvents.stepSeen", { order: step.step.order, title: stepBlock.title }) });
|
||||
}
|
||||
if (step.completedAt) {
|
||||
items.push({ type: "step-completed", createdAt: step.completedAt, description: t("onboarding.session.activityEvents.stepCompleted", { order: step.step.order, title: stepBlock.title }) });
|
||||
}
|
||||
});
|
||||
|
||||
return items.sort((a, b) => {
|
||||
if (a.createdAt && b.createdAt) {
|
||||
return b.createdAt > a.createdAt ? 1 : -1;
|
||||
}
|
||||
return 1;
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
getActivity,
|
||||
};
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
import { OnboardingStep } from "@toolctrl/db/prisma-browser";
|
||||
import { OnboardingStepBlockDto } from "../blocks/OnboardingBlockUtils";
|
||||
import { t as i18nT } from "i18next";
|
||||
|
||||
function parseStepToBlock(step: OnboardingStep) {
|
||||
try {
|
||||
return JSON.parse(step.block) as OnboardingStepBlockDto;
|
||||
} catch (e) {
|
||||
return {
|
||||
id: "",
|
||||
title: i18nT("shared.notSet"),
|
||||
links: [],
|
||||
gallery: [],
|
||||
input: [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function getStepDescription(block: OnboardingStepBlockDto) {
|
||||
return (
|
||||
<div className="flex items-center space-x-2 truncate text-sm">
|
||||
<div className="text-foreground shrink-0 font-medium">{block.title}</div>
|
||||
{block.description && (
|
||||
<>
|
||||
<div className="text-muted-foreground">•</div>
|
||||
<div className="text-muted-foreground shrink-0">{block.description}</div>
|
||||
</>
|
||||
)}
|
||||
{block.links.length > 0 && (
|
||||
<>
|
||||
<div className="text-muted-foreground">•</div>
|
||||
<div className="text-muted-foreground shrink-0">{i18nT("onboarding.stepSummary.linksCount", { count: block.links.length })}</div>
|
||||
</>
|
||||
)}
|
||||
{block.gallery.length > 0 && (
|
||||
<>
|
||||
<div className="text-muted-foreground">•</div>
|
||||
<div className="text-muted-foreground shrink-0">{i18nT("onboarding.stepSummary.galleryItemsCount", { count: block.gallery.length })}</div>
|
||||
</>
|
||||
)}
|
||||
{block.input.length > 0 && (
|
||||
<>
|
||||
<div className="text-muted-foreground">•</div>
|
||||
<div className="text-muted-foreground shrink-0">{i18nT("onboarding.stepSummary.inputFieldsCount", { count: block.input.length })}</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default {
|
||||
parseStepToBlock,
|
||||
getStepDescription,
|
||||
};
|
||||
Reference in new issue
Block a user