Skip to content

Commit 7af3936

Browse files
committed
next/onprem: hide ChatGPT if not on cocalc.com
1 parent 0bc2f9c commit 7af3936

File tree

8 files changed

+63
-45
lines changed

8 files changed

+63
-45
lines changed

src/packages/next/components/landing/cocalc-com-features.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function CoCalcComFeatures() {
3737
sandboxProjectId,
3838
jupyterApiEnabled,
3939
shareServer = false,
40+
onCoCalcCom,
4041
} = useCustomize();
4142
const width = Grid.useBreakpoint();
4243

@@ -515,7 +516,7 @@ export function CoCalcComFeatures() {
515516
}
516517

517518
function renderChatGPT() {
518-
if (!openaiEnabled) return;
519+
if (!openaiEnabled || !onCoCalcCom) return;
519520
return (
520521
<Info
521522
level={LANDING_HEADER_LEVEL}

src/packages/next/components/landing/header.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,7 @@ export default function Header(props: Props) {
144144
</a>
145145
)}
146146
{enabledPages?.store && (
147-
<A
148-
href="/store"
149-
style={page == "store" ? SelectedStyle : LinkStyle}
150-
>
147+
<A href="/store" style={page == "store" ? SelectedStyle : LinkStyle}>
151148
Store
152149
</A>
153150
)}
@@ -255,6 +252,7 @@ export default function Header(props: Props) {
255252
</Layout.Header>
256253
<SubNav page={page} subPage={subPage} softwareEnv={softwareEnv} />
257254
{openaiEnabled &&
255+
onCoCalcCom &&
258256
page === "features" &&
259257
typeof subPage === "string" &&
260258
SHOW_AI_CHAT.includes(subPage) ? (
@@ -266,9 +264,9 @@ export default function Header(props: Props) {
266264
/>
267265
</div>
268266
) : undefined}
269-
{jupyterApiEnabled && onCoCalcCom && runnableTag && (
267+
{jupyterApiEnabled && onCoCalcCom && runnableTag ? (
270268
<DemoCell tag={runnableTag} />
271-
)}
269+
) : undefined}
272270
</>
273271
);
274272
}

src/packages/next/components/landing/index-list.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Image, { StaticImageData } from "components/landing/image";
1212
import { Paragraph, Title } from "components/misc";
1313
import A from "components/misc/A";
1414
import { MAX_WIDTH } from "lib/config";
15-
import useCustomize from "lib/use-customize";
15+
import useCustomize, { CustomizeType } from "lib/use-customize";
1616

1717
export interface Item {
1818
link: string;
@@ -25,7 +25,7 @@ export interface Item {
2525
description: ReactNode;
2626
shareServer?: boolean; // only show if the share server is enabled
2727
landingPages?: boolean; // only show if landing pages are enabled.
28-
hide?: (CustomizeType) => boolean; // if returns true, then this item will be hidden.
28+
hide?: (customize: CustomizeType) => boolean; // if returns true, then this item will be hidden.
2929
}
3030

3131
export type DataSource = Item[];

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ const support = {
124124
community: { label: "Community" },
125125
new: { label: "New Ticket", hide: (customize) => !customize.zendesk },
126126
tickets: { label: "Tickets", hide: (customize) => !customize.zendesk },
127-
chatgpt: { label: "ChatGPT", hide: (customize) => !customize.openaiEnabled },
127+
chatgpt: {
128+
label: "ChatGPT",
129+
hide: (customize) => !customize.openaiEnabled || !customize.onCoCalcCom,
130+
},
128131
} as const;
129132

130133
const PAGES = {

src/packages/next/components/openai/chatgpt-help.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import { Alert, Button, Col, Input, Row } from "antd";
2+
import { useRouter } from "next/router";
3+
import { CSSProperties, useRef, useState } from "react";
4+
15
import OpenAIAvatar from "@cocalc/frontend/components/openai-avatar";
26
import ProgressEstimate from "@cocalc/frontend/components/progress-estimate";
37
import Markdown from "@cocalc/frontend/editors/slate/static-markdown";
48
import { FileContext } from "@cocalc/frontend/lib/file-context";
5-
import { Alert, Button, Col, Input, Row } from "antd";
69
import InPlaceSignInOrUp from "components/auth/in-place-sign-in-or-up";
710
import A from "components/misc/A";
811
import Loading from "components/share/loading";
912
import apiPost from "lib/api/post";
1013
import { useCustomize } from "lib/customize";
11-
import { useRouter } from "next/router";
12-
import { CSSProperties, useRef, useState } from "react";
1314

1415
type State = "input" | "wait";
1516

src/packages/next/components/support/create.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { Icon } from "@cocalc/frontend/components/icon";
2+
import { is_valid_email_address as isValidEmailAddress } from "@cocalc/util/misc";
3+
import { COLORS } from "@cocalc/util/theme";
14
import {
25
Alert,
36
Button,
@@ -8,24 +11,21 @@ import {
811
Radio,
912
Space,
1013
} from "antd";
11-
import { useRouter } from "next/router";
12-
import { ReactNode, useRef, useState } from "react";
13-
import CodeMirror from "components/share/codemirror";
14-
import { Icon } from "@cocalc/frontend/components/icon";
15-
import { is_valid_email_address as isValidEmailAddress } from "@cocalc/util/misc";
16-
import { COLORS } from "@cocalc/util/theme";
14+
import { Paragraph, Title } from "components/misc";
1715
import A from "components/misc/A";
16+
import ChatGPTHelp from "components/openai/chatgpt-help";
17+
import CodeMirror from "components/share/codemirror";
1818
import Loading from "components/share/loading";
1919
import SiteName from "components/share/site-name";
2020
import apiPost from "lib/api/post";
2121
import { MAX_WIDTH } from "lib/config";
2222
import { useCustomize } from "lib/customize";
23+
import { useRouter } from "next/router";
24+
import { ReactNode, useRef, useState } from "react";
2325
import getBrowserInfo from "./browser-info";
2426
import RecentFiles from "./recent-files";
2527
import { Type } from "./tickets";
2628
import { NoZendesk } from "./util";
27-
import { Paragraph, Title } from "components/misc";
28-
import ChatGPTHelp from "components/openai/chatgpt-help";
2929

3030
const CHATGPT_DISABLED = true;
3131
const MIN_BODY_LENGTH = 16;
@@ -47,8 +47,14 @@ function stringToType(s?: any): Type {
4747
}
4848

4949
export default function Create() {
50-
const { contactEmail, zendesk, account, openaiEnabled, siteName } =
51-
useCustomize();
50+
const {
51+
contactEmail,
52+
zendesk,
53+
account,
54+
openaiEnabled,
55+
onCoCalcCom,
56+
siteName,
57+
} = useCustomize();
5258
const router = useRouter();
5359
// The URL the user was viewing when they requested support.
5460
// This could easily be blank, but if it is set it can be useful.
@@ -147,9 +153,9 @@ export default function Create() {
147153
</>
148154
)}
149155
</p>
150-
{openaiEnabled && !CHATGPT_DISABLED && (
156+
{openaiEnabled && onCoCalcCom && !CHATGPT_DISABLED ? (
151157
<ChatGPT siteName={siteName} />
152-
)}
158+
) : undefined}
153159
<FAQ />
154160
<Title level={2}>Create Your Ticket</Title>
155161
<Instructions />

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,38 @@
11
import { Layout } from "antd";
2-
import Header from "components/landing/header";
3-
import Head from "components/landing/head";
2+
43
import Footer from "components/landing/footer";
4+
import Head from "components/landing/head";
5+
import Header from "components/landing/header";
6+
import ChatGPTHelp from "components/openai/chatgpt-help";
57
import { Customize } from "lib/customize";
68
import withCustomize from "lib/with-customize";
7-
import ChatGPTHelp from "components/openai/chatgpt-help";
89

910
export default function ChatgptInfo({ customize }) {
10-
const { siteName } = customize;
11+
const { siteName, onCoCalcCom } = customize;
12+
13+
function renderChatGPT() {
14+
return (
15+
<div style={{ maxWidth: "1000px" }}>
16+
Our integrated ChatGPT support is free and often very helpful since it
17+
knows so much about the open source software in {siteName}. You can ask
18+
a question below or use @chatgpt in any chat message when using{" "}
19+
{siteName}.
20+
<ChatGPTHelp
21+
style={{ marginTop: "15px" }}
22+
size="large"
23+
tag="support-chatgpt"
24+
/>
25+
</div>
26+
);
27+
}
28+
1129
return (
1230
<Customize value={customize}>
1331
<Head title="Your Support Tickets" />
1432
<Layout>
1533
<Header page="support" subPage="chatgpt" />
1634
<div style={{ margin: "15px auto" }}>
17-
<div style={{ maxWidth: "1000px" }}>
18-
Our integrated ChatGPT support is free and often very helpful since
19-
it knows so much about the open source software in {siteName}. You
20-
can ask a question below or use @chatgpt in any chat message when
21-
using {siteName}.
22-
<ChatGPTHelp
23-
style={{ marginTop: "15px" }}
24-
size="large"
25-
tag="support-chatgpt"
26-
/>
27-
</div>
35+
{onCoCalcCom ? renderChatGPT() : "disabled"}
2836
</div>
2937
<Footer />
3038
</Layout>

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Layout } from "antd";
2-
import Header from "components/landing/header";
3-
import Head from "components/landing/head";
2+
43
import Footer from "components/landing/footer";
5-
import { Customize } from "lib/customize";
6-
import withCustomize from "lib/with-customize";
4+
import Head from "components/landing/head";
5+
import Header from "components/landing/header";
76
import A from "components/misc/A";
87
import ChatGPTHelp from "components/openai/chatgpt-help";
8+
import { Customize } from "lib/customize";
9+
import withCustomize from "lib/with-customize";
910

1011
import IndexList, { DataSource } from "components/landing/index-list";
1112

@@ -45,7 +46,7 @@ const dataSource = [
4546
link: "/support/chatgpt",
4647
title: "ChatGPT Suppport",
4748
logo: "robot",
48-
hide: (customize) => !customize.openaiEnabled,
49+
hide: (customize) => !customize.openaiEnabled || !customize.onCoCalcCom,
4950
description: (
5051
<>
5152
Our <A href="/support/chatgpt">integrated ChatGPT support</A> is free

0 commit comments

Comments
 (0)