Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React from "react";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { ServerConfigContext } from "@components/contexts";
import Page from "../page";

jest.mock("@components/admin/dashboard-content", () => ({
__esModule: true,
default: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));

jest.mock("@courselit/components-library", () => {
const Box = ({ children }: { children: React.ReactNode }) => (
<div>{children}</div>
);
return {
Card: Box,
CardContent: Box,
CardFooter: Box,
CardHeader: Box,
CardTitle: Box,
Button2: ({
children,
onClick,
}: {
children: React.ReactNode;
onClick?: () => void;
}) => <button onClick={onClick}>{children}</button>,
ToastAction: () => null,
useToast: () => ({ toast: jest.fn() }),
};
});

jest.mock("next/navigation", () => ({
usePathname: () => "/dashboard/support",
}));

const supportChat = {
teamId: "team_support",
loaderUrl: "https://embed.support.test/chat.js",
};

function renderPage(config: Record<string, unknown>) {
return render(
<ServerConfigContext.Provider value={config as any}>
<Page />
</ServerConfigContext.Provider>,
);
}

type ChatWindow = { FrontLit?: { q?: unknown[][] } };

describe("dashboard support page", () => {
beforeEach(() => {
delete (window as unknown as ChatWindow).FrontLit;
global.fetch = jest.fn().mockResolvedValue({
ok: true,
json: async () => ({ token: "session-token" }),
}) as unknown as typeof fetch;
});

it("offers the support chat instead of community channels on hosted schools", async () => {
renderPage({ supportChat });

expect(screen.getByText("Documentation")).toBeInTheDocument();
expect(screen.getByText("Chat with us")).toBeInTheDocument();
expect(screen.queryByText("Ask in Discord")).not.toBeInTheDocument();
expect(screen.queryByText("Found a bug?")).not.toBeInTheDocument();
expect(screen.queryByText("Priority Support")).not.toBeInTheDocument();

fireEvent.click(screen.getByText("Start a chat"));

await waitFor(() =>
expect(
(window as unknown as ChatWindow).FrontLit?.q,
).toContainEqual(["open", { token: "session-token" }]),
);
const body = JSON.parse(
(global.fetch as jest.Mock).mock.calls[0][1].body,
);
expect(body.error).toBeUndefined();
});

it("keeps community channels and paid support on self-hosted setups", () => {
renderPage({});

expect(screen.getByText("Ask in Discord")).toBeInTheDocument();
expect(screen.getByText("Found a bug?")).toBeInTheDocument();
expect(screen.getByText("Priority Support")).toBeInTheDocument();
expect(screen.queryByText("Chat with us")).not.toBeInTheDocument();
});
});
154 changes: 98 additions & 56 deletions apps/web/app/(with-contexts)/dashboard/(sidebar)/support/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@ import {
CardHeader,
CardTitle,
} from "@courselit/components-library";
import { HEADER_HELP } from "@ui-config/strings";
import { ServerConfigContext } from "@components/contexts";
import { useContactSupport } from "@components/support-chat";
import {
HEADER_HELP,
SUPPORT_CHAT_CARD_BUTTON,
SUPPORT_CHAT_CARD_DESCRIPTION,
SUPPORT_CHAT_CARD_TITLE,
} from "@ui-config/strings";
import { useContext } from "react";
const { permissions } = UIConstants;

const breadcrumbs = [{ label: HEADER_HELP, href: "#" }];

export default function Page() {
// Hosted schools get the support chat; self-hosted ones keep the
// community channels and paid support.
const { supportChat } = useContext(ServerConfigContext);
const contactSupport = useContactSupport();

return (
<DashboardContent
breadcrumbs={breadcrumbs}
Expand All @@ -35,7 +48,7 @@ export default function Page() {
If you need a helping hand, we are out there for you.
</p>
<div className="flex flex-col lg:!flex-row gap-4 mb-16">
<Card className="lg:!w-1/3">
<Card className="lg:!flex-1">
<CardHeader>
<CardTitle>Documentation</CardTitle>
</CardHeader>
Expand All @@ -53,62 +66,91 @@ export default function Page() {
</a>
</CardFooter>
</Card>
<Card className="lg:!w-1/3">
<CardHeader>
<CardTitle>Ask in Discord</CardTitle>
</CardHeader>
<CardContent>
<p className="mb-4">
Come ask your questions directly from the team. We
are quite active there.
</p>
</CardContent>
<CardFooter>
<a
href="https://discord.com/invite/GR4bQsN"
target="_blank"
>
<Button2 variant="secondary">Open Discord</Button2>
</a>
</CardFooter>
</Card>
<Card className="lg:!w-1/3">
<CardHeader>
<CardTitle>Found a bug?</CardTitle>
</CardHeader>
<CardContent>
<p className="mb-4">
We encourage you to raise an issue so that we can
make the product better for everyone.
</p>
</CardContent>
<CardFooter>
{supportChat ? (
<Card className="lg:!flex-1">
<CardHeader>
<CardTitle>{SUPPORT_CHAT_CARD_TITLE}</CardTitle>
</CardHeader>
<CardContent>
<p className="mb-4">
{SUPPORT_CHAT_CARD_DESCRIPTION}
</p>
</CardContent>
<CardFooter>
<Button2
variant="secondary"
onClick={() => void contactSupport()}
>
{SUPPORT_CHAT_CARD_BUTTON}
</Button2>
</CardFooter>
</Card>
) : (
<>
<Card className="lg:!flex-1">
<CardHeader>
<CardTitle>Ask in Discord</CardTitle>
</CardHeader>
<CardContent>
<p className="mb-4">
Come ask your questions directly from the
team. We are quite active there.
</p>
</CardContent>
<CardFooter>
<a
href="https://discord.com/invite/GR4bQsN"
target="_blank"
>
<Button2 variant="secondary">
Open Discord
</Button2>
</a>
</CardFooter>
</Card>
<Card className="lg:!flex-1">
<CardHeader>
<CardTitle>Found a bug?</CardTitle>
</CardHeader>
<CardContent>
<p className="mb-4">
We encourage you to raise an issue so that
we can make the product better for everyone.
</p>
</CardContent>
<CardFooter>
<a
href="https://discord.com/channels/727630561895514212/1244954638747303946"
target="_blank"
>
<Button2 variant="secondary">
Post an issue
</Button2>
</a>
</CardFooter>
</Card>
</>
)}
</div>
{!supportChat && (
<div>
<h2 className="font-semibold text-2xl mb-4">
Priority Support
</h2>
<p>
In case you need to get in touch with the team to get
help faster, we offer <strong>paid</strong> support.
Please reach out to us on{" "}
<a
href="https://discord.com/channels/727630561895514212/1244954638747303946"
target="_blank"
href="mailto:support@courselit.app"
className="underline"
>
<Button2 variant="secondary">Post an issue</Button2>
</a>
</CardFooter>
</Card>
</div>
<div>
<h2 className="font-semibold text-2xl mb-4">
Priority Support
</h2>
<p>
In case you need to get in touch with the team to get help
faster, we offer <strong>paid</strong> support. Please reach
out to us on{" "}
<a
href="mailto:support@courselit.app"
className="underline"
>
CourseLit Support
</a>{" "}
with your requirements .
</p>
</div>
CourseLit Support
</a>{" "}
with your requirements .
</p>
</div>
)}
</DashboardContent>
);
}
5 changes: 4 additions & 1 deletion apps/web/app/(with-contexts)/layout-with-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { Theme } from "@courselit/page-models";
import { ThemeProvider as NextThemesProvider } from "@components/next-theme-provider";
import { defaultState } from "@components/default-state";
import { getUserProfile } from "./helpers";
import { SupportChat, useSupportErrorToasts } from "@components/support-chat";
import { auth } from "@/auth";

type BetterAuthSession = Awaited<ReturnType<typeof auth.api.getSession>> | null;
Expand All @@ -47,6 +48,7 @@ function LayoutContent({
const [profile, setProfile] = useState(defaultState.profile);
const [theme, setTheme] = useState(initialTheme);
const { toast } = useToast();
const mapToast = useSupportErrorToasts(config.supportChat);

const updateUserProfile = useCallback(async () => {
try {
Expand Down Expand Up @@ -109,7 +111,8 @@ function LayoutContent({
</ServerConfigContext.Provider>
</ThemeContext.Provider>
</SiteInfoContext.Provider>
<Toaster />
<Toaster mapToast={mapToast} />
<SupportChat config={config.supportChat} />
</FeaturesContext.Provider>
</AddressContext.Provider>
);
Expand Down
2 changes: 2 additions & 0 deletions apps/web/app/(with-contexts)/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { defaultState } from "@components/default-state";
import { decode } from "base-64";
import { ServerConfig, SiteInfo } from "@courselit/common-models";
import constants from "@config/constants";
import { getSupportChatConfig } from "@/lib/support-chat";

export default async function Layout({
children,
Expand All @@ -25,6 +26,7 @@ export default async function Layout({
queueServer: process.env.QUEUE_SERVER || "",
cacheEnabled: constants.cacheEnabled,
recaptchaSiteKey: process.env.RECAPTCHA_SITE_KEY || "",
supportChat: getSupportChatConfig(),
};

return (
Expand Down
Loading
Loading