Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
9f8fdf9
Swizzle component to add support dropdown menu
josh-wong Feb 17, 2025
b9e476e
Add `@typebot.io/react`
josh-wong Feb 21, 2025
8dfeaa2
Create AssistantModal.tsx
josh-wong Feb 21, 2025
5cb81ae
Create ContactSupportLink.tsx
josh-wong Feb 21, 2025
c4412c8
Create SupportDropdownMenu.tsx
josh-wong Feb 21, 2025
b26e1e7
Create SupportDropdownMenu.module.css
josh-wong Feb 21, 2025
67411c7
Add Support dropdown menu above TOC
josh-wong Feb 21, 2025
3879190
Make Support button appear with or without ToC
josh-wong Feb 25, 2025
588f8f6
Pass URL as parameter to Typebot
josh-wong Feb 25, 2025
e6d8d08
Show Japanese text on Japanese version of site
josh-wong Feb 25, 2025
cdd537f
Justify alignment for Support button text and arrow icon
josh-wong Feb 25, 2025
0e42e0f
Make Support button appear static above ToC
josh-wong Feb 25, 2025
9d4d0d3
Hide Support button when hiding ToC on page
josh-wong Feb 25, 2025
1cef735
Re-order styles
josh-wong Feb 25, 2025
af5eb6e
Show Support button on mobile
josh-wong Feb 25, 2025
77a2307
Make Support button and ToC appear behind language dropdown
josh-wong Feb 25, 2025
1bbdd05
Revise code comments for clarity
josh-wong Feb 25, 2025
4c8718e
Merge branch 'main' into feature/add-support-dropdown
josh-wong Feb 26, 2025
3435a6f
Fix spelling
josh-wong Mar 3, 2025
626625b
Add support for dark mode
josh-wong Mar 3, 2025
b792742
Delete SupportDropdownMenu.module.css
josh-wong Mar 4, 2025
8e26d21
Add Support button styles
josh-wong Mar 4, 2025
b053e70
Change from using `JSX.Element` to `ReactNode`
josh-wong Mar 4, 2025
5058ba3
Add GitHub issue link and template
josh-wong Mar 4, 2025
117be32
Fix styles
josh-wong Mar 4, 2025
7a9d194
Revise wording on links
josh-wong Mar 4, 2025
b255acc
Delete ContactSupportLink.tsx
josh-wong Mar 4, 2025
58a8d09
Update SupportDropdownMenu.tsx
josh-wong Mar 4, 2025
ddd1bd1
Change component link from absolute to relative
josh-wong Mar 4, 2025
357e82c
Adjust width and padding for Support button
josh-wong Mar 5, 2025
de95352
Specify Support dropdown arrow size
josh-wong Mar 5, 2025
e4b51ad
Revised wording in dropdown
josh-wong Mar 5, 2025
b49c1e6
Update font style and link behavior
josh-wong Mar 5, 2025
a2baebd
Refactor support dropdown to fix errors on build
josh-wong Mar 6, 2025
35cb4be
Hide Stack Overflow link
josh-wong Mar 6, 2025
65e685f
Make dropdown menu appear on hover (instead of on click)
josh-wong Mar 6, 2025
30ae69e
Modify support dropdown menu styles
josh-wong Mar 6, 2025
660416e
Change dropdown arrow icon
josh-wong Mar 6, 2025
ea81435
Fix support dropdown from disappearing
josh-wong Mar 6, 2025
ba6018c
Put support button styles in alphabetical order
josh-wong Mar 6, 2025
b69c214
Make support button font consistent with other buttons
josh-wong Mar 6, 2025
43fcb00
Add `some` to English button
josh-wong Mar 6, 2025
8eb3b42
Remove comments that were for quick, personal reference
josh-wong Mar 6, 2025
b889d43
Add rounded corners to dropdown and on link hover
josh-wong Mar 6, 2025
18027a5
Move file
josh-wong Mar 11, 2025
d15ad04
Move file
josh-wong Mar 11, 2025
b530b67
Update import
josh-wong Mar 11, 2025
9122b26
Create AssistantModal.tsx
josh-wong Mar 11, 2025
84f2b11
Update link to chatbot
josh-wong Mar 11, 2025
94432d1
Remove Font Awesome plugin
josh-wong Mar 11, 2025
b160ea8
Show AI assistant based on language
josh-wong Mar 11, 2025
5b45f3a
Move back to `Support` folder
josh-wong Mar 11, 2025
260cd35
Delete AssistantModal.tsx
josh-wong Mar 11, 2025
e391b91
Revert "Update import"
josh-wong Mar 11, 2025
5298d1d
Merge branch 'main' into feature/add-support-dropdown
josh-wong Mar 12, 2025
a44b781
Fix GitHub issue link
josh-wong Mar 12, 2025
664d5d8
Change dropdown item font color
josh-wong Mar 12, 2025
9377f6c
Hide support dropdown menu from home page
josh-wong Mar 14, 2025
743015c
Merge branch 'main' into feature/add-support-dropdown
josh-wong Mar 17, 2025
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
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"prism-react-renderer": "^2.3.0",
"react": "^18.0.0",
"react-cookie-consent": "9.0.0",
"react-dom": "^18.0.0"
"react-dom": "^18.0.0",
"@typebot.io/react": "0.3.47"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "^3.7.0",
Expand Down
72 changes: 72 additions & 0 deletions src/components/Support/AssistantModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import React from "react";
import { Standard } from "@typebot.io/react";

function AssistantModal({ isOpen, onClose }) {
if (!isOpen) return null; // Prevent modal from rendering when isOpen is false.

// Get the current page URL.
const currentUrl = window.location.href;

// Check if the user is on the Japanese documentation page.
const isJapanese = currentUrl.includes("/ja-jp");

return (
<div className="modal" style={styles.modal}>
<div className="modal-content" style={styles.modalContent}>
{/* Close the button. */}
<span className="close" onClick={onClose} style={styles.closeButton}>
&times;
</span>

{/* Conditionally render the Typebot based on language. */}
<Standard
typebot={isJapanese
? "ja-jp-scalar-docs-ai-assistant-for-scalar-membership-program-members-201712"
: "en-us-scalar-docs-ai-assistant-for-scalar-membership-program-members-201712"
}
style={{ width: "100%", height: "600px" }}
prefilledVariables={{
"Current page URL": `${currentUrl}`, // Pass page URL as a query parameter.
}}
/>
</div>
</div>
);
}

const styles = {
modal: {
display: "block",
position: "fixed",
zIndex: 1000,
left: 0,
top: 0,
width: "100%",
height: "100%",
backgroundColor: "rgba(0, 0, 0, 0.7)",
},
modalContent: {
backgroundColor: "#fff",
margin: "10% auto",
padding: "20px",
borderRadius: "10px",
width: "90%",
maxWidth: "900px",
position: "relative", // Allow absolute positioning of the close button.
},
closeButton: {
position: "absolute",
top: "10px",
right: "20px",
fontSize: "30px",
fontWeight: "bold",
cursor: "pointer",
color: "#333",
backgroundColor: "transparent",
border: "none",
padding: "0",
zIndex: 1100, // Ensure the close button is above the modal content.
},
};

export default AssistantModal;
165 changes: 165 additions & 0 deletions src/components/Support/SupportDropdownMenu.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import React, { useState, useEffect, useRef, lazy, Suspense, MouseEvent } from 'react';
import { useDoc } from '@docusaurus/plugin-content-docs/client';
import { useLocation } from "@docusaurus/router";

// Lazy-load AssistantModal.
const AssistantModal = lazy(() => import('./AssistantModal'));

const SupportDropdownMenu: React.FC = () => {
const [isOpen, setIsOpen] = useState<boolean>(false);
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const [storedUrl, setStoredUrl] = useState<string | null>(null);
const dropdownRef = useRef<HTMLDivElement | null>(null);
const location = useLocation();

// Get document metadata from Docusaurus.
const { metadata } = useDoc();
const docTitle: string = metadata?.title || "Issue with documentation page";

// Detect the language based on the URL path.
const isJapanese: boolean = location.pathname.startsWith("/ja-jp");

useEffect(() => {
if (typeof window !== "undefined") {
const currentUrl = `https://scalardb.scalar-labs.com${location.pathname}`;
localStorage.setItem("currentUrl", currentUrl);

const savedUrl = localStorage.getItem("currentUrl");
if (savedUrl) {
setStoredUrl(savedUrl);
}
}
}, [location]);

const toggleDropdown = () => {
setIsOpen((prev) => !prev);
};

const openModal = (event: MouseEvent<HTMLAnchorElement>) => {
event.preventDefault();
setIsModalOpen(true);
setIsOpen(false);
};

const closeModal = () => {
setIsModalOpen(false);
};

const handleSupportClick = () => {
if (typeof window !== "undefined") {
const finalUrl = storedUrl || `https://scalardb.scalar-labs.com${location.pathname}`;
const reportUrl = `https://support.scalar-labs.com/hc/ja/requests/new?ticket_form_id=8641483507983&tf_11847415366927=${encodeURIComponent(finalUrl)}`;

window.open(reportUrl, "_blank");
}
};

const githubIssueUrl: string = typeof window !== "undefined" ? (() => {
const repoUrl = "https://github.com/scalar-labs/docs-scalardb/issues/new";
const issueTitle = encodeURIComponent(
isJapanese ? `フィードバック: \`${docTitle}\` ページ` : `Feedback: \`${docTitle}\` page`
);

const issueBody = encodeURIComponent(
isJapanese
? `**ドキュメントページの URL:** ${window.location.href.replace(/#.*$/, '')}

## 期待される動作

どのような動作を期待しましたか?

## 問題の説明

問題の内容をわかりやすく説明してください。

### 再現手順 (該当する場合)

問題を再現できる場合、手順を記載してください。

### スクリーンショット (該当する場合)

該当する場合は、スクリーンショットを添付してください。
`
: `**Documentation page URL:** ${window.location.href.replace(/#.*$/, '')}

## Expected behavior

What did you expect to happen?

## Describe the problem

Please provide a clear and concise description of what the issue is.

### Steps to reproduce (if applicable)

If the issue is reproducible, please list the steps to reproduce it.

### Screenshots (if applicable)

If applicable, add screenshots to help explain your problem.
`
);

const issueUrl = `${repoUrl}?title=${issueTitle}&body=${issueBody}&labels=documentation`;

console.log("GitHub Issue URL: ", issueUrl); // Debugging line

return issueUrl;
})() : "#";

useEffect(() => {
function handleClickOutside(event: MouseEvent | Event) {
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
setIsOpen(false);
}
}

if (isOpen) {
document.addEventListener("mousedown", handleClickOutside);
} else {
document.removeEventListener("mousedown", handleClickOutside);
}

return () => document.removeEventListener("mousedown", handleClickOutside);
}, [isOpen]);

return (
<div className="supportDropdown" ref={dropdownRef}>
<button className="supportDropBtn" onMouseOver={toggleDropdown}>
{isJapanese ? "何かお困りですか?" : "Need some help?"}<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" d="m12 16l-6-6h12z"/></svg>
</button>

<div className="supportDropdownContent">
<div>
<a href="#" onClick={handleSupportClick} rel="noopener noreferrer">
<b>{isJapanese ? "テクニカルサポートに問い合わせ" : "Contact technical support"}</b><br />
{isJapanese ? "商用ライセンスをご契約のお客様のみご利用いただけます。" : "Available only to customers with a commercial license."}
</a>
</div>
<hr />
{/* <a href="https://stackoverflow.com/questions/tagged/scalardb" target="_blank" rel="noopener noreferrer">
<b>{isJapanese ? "Stack Overflow をチェック" : "Check Stack Overflow"}</b><br />
{isJapanese ? "すべてのユーザーがご利用いただけます。" : "Available to all users."}
</a>
<hr /> */}
<a href="#" onClick={openModal}>
<b>{isJapanese ? "AI に聞く (試験運用中)" : "Ask AI (experimental)"}</b><br />
{isJapanese ? "Scalar Membership Programにご参加の方のみご利用いただけます。" : "Available only to members of the Scalar Membership Program."}
</a>
<hr />
<a href={githubIssueUrl} target="_blank" rel="noopener noreferrer">
<b>{isJapanese ? "ドキュメントの問題を報告" : "Report doc issue"}</b><br />
{isJapanese ? "このページについて何かお気づきの点がありましたら、こちらから報告いただけます。" : "If you have any feedback about this page, please submit an issue."}
</a>
</div>

{isModalOpen && (
<Suspense fallback={<div>Loading...</div>}>
<AssistantModal isOpen={isModalOpen} onClose={closeModal} />
</Suspense>
)}
</div>
);
};

export default SupportDropdownMenu;
105 changes: 105 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,108 @@ html[data-theme="dark"] .tooltip-glossary {
width: 333px !important;
}
}

/* Support button and dropdown */
.supportDropdown {
display: inline-block;
position: relative;
}

.supportDropdownContent {
background-color: #f9f9f9;
border-radius: 8px;
box-shadow: var(--ifm-global-shadow-md);
color: var(--ifm-color-emphasis-700);
font-size: 14px;
min-width: 303px;
opacity: 0;
overflow: hidden;
padding: 8px 0px;
position: absolute;
right: 0;
transform: translateY(-10px);
transition: opacity 0.3s ease-out, transform 0.3s ease-out;
visibility: hidden;
z-index: 1;
}

.supportDropdown:hover .supportDropdownContent {
visibility: visible;
opacity: 1;
transform: translateY(0);
}

.supportDropdownContent {
transition-delay: 0.1s;
}

.supportDropBtn {
align-items: center;
background-color: inherit;
border: 0;
border-radius: var(--ifm-badge-border-radius);
color: var(--ifm-navbar-link-color);
cursor: pointer;
display: flex;
font-family: var(--ifm-font-family-base);
font-size: 14.5px;
font-weight: var(--ifm-font-weight-semibold);
justify-content: space-between;
min-width: 145px;
padding: 6px 0;
text-align: left;
z-index: 1;
}

.supportDropBtn svg { /* Keep dropdown open when moving the mouse between text and icon. */
pointer-events: none;
}

.supportDropdown:hover .supportDropBtn {
color: var(--ifm-color-primary);
}

@media (max-width: 996px) {
.supportDropBtn {
font-size: 15px;
}
.supportDropdownContent {
font-size: 15px;
left: 0;
min-width: 320px;
}
}

.supportDropdownContent a {
color: var(--ifm-dropdown-link-color);
display: block;
margin: 4px 10px;
padding: 4px 10px;
text-decoration: none;
}

.supportDropdownContent a:hover {
background-color: var(--ifm-dropdown-hover-background-color);
border-radius: 8px;
overflow: hidden;
}

html[data-theme="dark"] .supportDropBtn {
background-color: inherit;
border: 0;
color: #f9f9f9;
}

html[data-theme="dark"] .supportDropdownContent {
background-color: var(--ifm-dropdown-background-color);

a {
color: #f9f9f9;
}
}

hr {
text-align: center;
margin: auto;
max-width: 91%;
}
Loading