Skip to content

Commit 67ff619

Browse files
committed
next/support: make it possible to customize support page like for policies and imprint
1 parent 7af3936 commit 67ff619

File tree

9 files changed

+91
-27
lines changed

9 files changed

+91
-27
lines changed

src/packages/database/settings/customize.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
44
*/
55

6+
import getStrategies from "@cocalc/database/settings/get-sso-strategies";
67
import {
7-
KucalcValues,
88
KUCALC_COCALC_COM,
9+
KucalcValues,
910
} from "@cocalc/util/db-schema/site-defaults";
1011
import { Strategy } from "@cocalc/util/types/sso";
11-
import getStrategies from "@cocalc/database/settings/get-sso-strategies";
12-
import { getServerSettings, ServerSettings } from "./server-settings";
12+
import { ServerSettings, getServerSettings } from "./server-settings";
1313
import siteURL from "./site-url";
1414

1515
export interface Customize {
@@ -59,6 +59,7 @@ export interface Customize {
5959
jupyterApiEnabled?: boolean;
6060
computeServersEnabled?: boolean;
6161
githubProjectId?: string;
62+
support?: string;
6263
}
6364

6465
const fallback = (a?: string, b?: string): string =>
@@ -124,6 +125,7 @@ export default async function getCustomize(): Promise<Customize> {
124125
indexInfo: settings.index_info_html,
125126
imprint: settings.imprint,
126127
policies: settings.policies,
128+
support: settings.support,
127129

128130
// Is important for invite emails, password reset, etc. (e.g., so we can construct a url to our site).
129131
// This *can* start with http:// to explicitly use http instead of https, and can end

src/packages/next/components/landing/sub-nav.tsx

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import Logo from "components/logo";
1919
import { CSS } from "components/misc";
2020
import A from "components/misc/A";
2121
import { MAX_WIDTH_LANDING } from "lib/config";
22-
import { useCustomize } from "lib/customize";
22+
import { CustomizeType, useCustomize } from "lib/customize";
2323

2424
const BASE_STYLE: CSS = {
2525
backgroundColor: "white",
@@ -130,7 +130,28 @@ const support = {
130130
},
131131
} as const;
132132

133-
const PAGES = {
133+
type PageKey =
134+
| "about"
135+
| "features"
136+
| "software"
137+
| "pricing"
138+
| "policies"
139+
| "share"
140+
| "info"
141+
| "sign-up"
142+
| "sign-in"
143+
| "try"
144+
| "support"
145+
| "news"
146+
| "store";
147+
148+
const PAGES: {
149+
[top in PageKey]:
150+
| {
151+
[page: string]: { label: string; hide?: (c: CustomizeType) => boolean };
152+
}
153+
| { index: {} };
154+
} = {
134155
about,
135156
features,
136157
software,
@@ -146,7 +167,7 @@ const PAGES = {
146167
store: {},
147168
} as const;
148169

149-
export type Page = keyof typeof PAGES | "account";
170+
export type Page = PageKey | "account";
150171
export type SubPage =
151172
| keyof typeof software
152173
| keyof typeof features
@@ -184,6 +205,10 @@ export default function SubNav(props: Props) {
184205
}, [subnavRef]);
185206

186207
if (page == null) return null;
208+
209+
// if we define a custom support page, render it instead – and hide the sub menu
210+
if (customize.support && !customize.onCoCalcCom) return null;
211+
187212
const tabs: JSX.Element[] = [];
188213
const p = PAGES[page];
189214
if (p == null || isEmpty(p)) return null;

src/packages/next/components/misc/sanitized-markdown.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
*/
55

66
import { CSSProperties } from "react";
7-
import { FileContext } from "@cocalc/frontend/lib/file-context";
7+
88
import Markdown from "@cocalc/frontend/editors/slate/static-markdown";
9+
import { FileContext } from "@cocalc/frontend/lib/file-context";
910
import A from "components/misc/A";
1011

1112
export default function SanitizedMarkdown({

src/packages/next/lib/customize.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ interface Customize extends ServerCustomize {
6868
jupyterApiEnabled?: boolean; // backend configured to use a pool of projects for sandboxed ephemeral jupyter code execution
6969
computeServersEnabled?: boolean; // backend configured to run on external compute servers
7070
enabledPages?: EnabledPageTree; // tree structure which specifies supported routes for this install
71+
support?: string; // HTML/MD to replace the generic support pages
7172
}
7273

7374
const CustomizeContext = createContext<Partial<Customize>>({});

src/packages/next/lib/with-customize.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export default async function withCustomize(
101101
share: customize.shareServer,
102102
software: customize.landingPages,
103103
store: customize.landingPages && customize.isCommercial,
104-
support: true,
104+
support: true, // always enabled, but for on-prem && settings.support, we render a different page
105105
systemActivity: true,
106106
status: customize.onCoCalcCom,
107107
termsOfService: !customize.landingPages && !!customize.termsOfServiceURL,

src/packages/next/pages/policies/imprint.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
44
*/
55

6-
import { Row, Col } from "antd";
7-
import withCustomize from "lib/with-customize";
8-
import Header from "components/landing/header";
9-
import Head from "components/landing/head";
6+
import { Col, Layout, Row } from "antd";
7+
108
import Footer from "components/landing/footer";
9+
import Head from "components/landing/head";
10+
import Header from "components/landing/header";
1111
import SanitizedMarkdown from "components/misc/sanitized-markdown";
1212
import { Customize } from "lib/customize";
13-
import { Layout } from "antd";
13+
import withCustomize from "lib/with-customize";
1414

1515
export default function Imprint({ customize }) {
1616
const { imprint } = customize;
@@ -24,10 +24,10 @@ export default function Imprint({ customize }) {
2424
xs={{ span: 12, offset: 6 }}
2525
style={{ marginTop: "30px", marginBottom: "30px" }}
2626
>
27-
{imprint && <SanitizedMarkdown value={imprint} />}
27+
{imprint ? <SanitizedMarkdown value={imprint} /> : undefined}
2828
</Col>
2929
</Row>
30-
<Footer />{" "}
30+
<Footer />
3131
</Layout>
3232
</Customize>
3333
);

src/packages/next/pages/policies/policies.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
44
*/
55

6-
import { Row, Col } from "antd";
7-
import withCustomize from "lib/with-customize";
8-
import Header from "components/landing/header";
9-
import Head from "components/landing/head";
6+
import { Col, Layout, Row } from "antd";
7+
108
import Footer from "components/landing/footer";
9+
import Head from "components/landing/head";
10+
import Header from "components/landing/header";
1111
import SanitizedMarkdown from "components/misc/sanitized-markdown";
1212
import { Customize } from "lib/customize";
13-
import { Layout } from "antd";
13+
import withCustomize from "lib/with-customize";
1414

1515
export default function Policies({ customize }) {
1616
const { policies } = customize;
@@ -27,7 +27,7 @@ export default function Policies({ customize }) {
2727
{policies && <SanitizedMarkdown value={policies} />}
2828
</Col>
2929
</Row>
30-
<Footer />{" "}
30+
<Footer />
3131
</Layout>
3232
</Customize>
3333
);

src/packages/next/pages/support/index.tsx

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Layout } from "antd";
1+
import { Col, Layout } from "antd";
22

33
import Footer from "components/landing/footer";
44
import Head from "components/landing/head";
@@ -9,6 +9,8 @@ import { Customize } from "lib/customize";
99
import withCustomize from "lib/with-customize";
1010

1111
import IndexList, { DataSource } from "components/landing/index-list";
12+
import { Title } from "components/misc";
13+
import SanitizedMarkdown from "components/misc/sanitized-markdown";
1214

1315
const dataSource = [
1416
{
@@ -100,11 +102,24 @@ const dataSource = [
100102
] as DataSource;
101103

102104
export default function Preferences({ customize }) {
103-
return (
104-
<Customize value={customize}>
105-
<Head title="Support" />
106-
<Layout>
107-
<Header page="support" />
105+
const { support, onCoCalcCom } = customize;
106+
107+
function renderContent() {
108+
if (!onCoCalcCom && support) {
109+
return (
110+
<Col
111+
xs={{ span: 12, offset: 6 }}
112+
style={{
113+
marginTop: "30px",
114+
marginBottom: "30px",
115+
}}
116+
>
117+
<Title level={2}>Support</Title>
118+
<SanitizedMarkdown value={support} />
119+
</Col>
120+
);
121+
} else {
122+
return (
108123
<IndexList
109124
title="Support"
110125
description={
@@ -118,6 +133,16 @@ export default function Preferences({ customize }) {
118133
}
119134
dataSource={dataSource}
120135
/>
136+
);
137+
}
138+
}
139+
140+
return (
141+
<Customize value={customize}>
142+
<Head title="Support" />
143+
<Layout>
144+
<Header page="support" />
145+
{renderContent()}
121146
<Footer />
122147
</Layout>
123148
</Customize>

src/packages/util/db-schema/site-defaults.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export type SiteSettingsKeys =
5353
| "index_info_html"
5454
| "imprint"
5555
| "policies"
56+
| "support"
5657
| "openai_enabled"
5758
| "google_vertexai_enabled"
5859
| "mistral_enabled"
@@ -473,6 +474,15 @@ export const site_settings_conf: SiteSettings = {
473474
multiline: 5,
474475
tags: ["Theme"],
475476
},
477+
support: {
478+
name: "Support page (on-prem only)",
479+
desc: "If set, shown instead of the generic support pages – HTML/Markdown.",
480+
default: "",
481+
clearable: true,
482+
show: (conf) => show_theming_vars(conf) && not_cocalc_com(conf),
483+
multiline: 5,
484+
tags: ["Theme"],
485+
},
476486
// ============== END THEMING ============
477487

478488
versions: {

0 commit comments

Comments
 (0)