diff --git a/.changeset/rich-pillows-act.md b/.changeset/rich-pillows-act.md new file mode 100644 index 0000000000..ae90b2499d --- /dev/null +++ b/.changeset/rich-pillows-act.md @@ -0,0 +1,5 @@ +--- +"@medusajs/oas-github-ci": patch +--- + +feat(@medusajs/oas-github-ci): changed output path to match new docs workspace diff --git a/.github/workflows/docs-new-announcement.yml b/.github/workflows/docs-new-announcement.yml index 9db534e4c7..a593c8bf73 100644 --- a/.github/workflows/docs-new-announcement.yml +++ b/.github/workflows/docs-new-announcement.yml @@ -43,6 +43,6 @@ jobs: base: "develop" title: "chore(docs): Generated Docs Announcement Bar (automated)" labels: "type: chore" - add-paths: www/docs/** + add-paths: www/apps/docs/** branch: "chore/generate-announcement" branch-suffix: "timestamp" diff --git a/.github/workflows/docs-remove-announcement.yml b/.github/workflows/docs-remove-announcement.yml index 62641d9811..b3740249a3 100644 --- a/.github/workflows/docs-remove-announcement.yml +++ b/.github/workflows/docs-remove-announcement.yml @@ -41,6 +41,6 @@ jobs: base: "develop" title: "chore(docs): Removed Docs Announcement Bar (automated)" labels: "type: chore" - add-paths: www/docs/** + add-paths: www/apps/docs/** branch: "chore/remove-announcement" branch-suffix: "timestamp" diff --git a/.github/workflows/docs-test.yml b/.github/workflows/docs-test.yml index e168bd5143..1996627235 100644 --- a/.github/workflows/docs-test.yml +++ b/.github/workflows/docs-test.yml @@ -2,8 +2,8 @@ name: Documentation Tests on: pull_request: paths: - - www/docs/** - - www/api-reference/** + - www/** + jobs: docs-test: runs-on: ubuntu-latest @@ -29,17 +29,17 @@ jobs: with: extension: docs - - name: Install Docusaurus dependencies - working-directory: www/docs + - name: Install Workspace dependencies + working-directory: www run: yarn install - name: Build Docusaurus website - working-directory: www/docs + working-directory: www env: NODE_OPTIONS: "--max-old-space-size=8192" API_URL: "https://docs.medusajs.com" - run: yarn build + run: yarn build:docs - lint: + vale-docs: runs-on: ubuntu-latest steps: - name: Cancel Previous Runs @@ -53,8 +53,8 @@ jobs: fetch-depth: 0 - name: Get Directories to Scan - working-directory: www/docs/vale - run: ./get-files.sh + working-directory: www/vale + run: ./get-files.sh docs content references id: directories - name: Vale Linter @@ -63,8 +63,71 @@ jobs: files: ${{ steps.directories.outputs.LIST }} fail_on_error: true vale_flags: '--minAlertLevel=error' + reporter: github-pr-check + token: ${{ github.token }} + filter_mode: nofilter env: - GITHUB_TOKEN: ${{ github.token }} + REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }} + + vale-ui: + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ github.token }} + + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Get Directories to Scan + working-directory: www/vale + run: ./get-files.sh ui src/content/docs + id: directories + + - name: Vale Linter + uses: errata-ai/vale-action@reviewdog + with: + files: ${{ steps.directories.outputs.LIST }} + fail_on_error: true + vale_flags: '--minAlertLevel=error' + reporter: github-pr-check + token: ${{ github.token }} + filter_mode: nofilter + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }} + + vale-api: + runs-on: ubuntu-latest + steps: + - name: Cancel Previous Runs + uses: styfle/cancel-workflow-action@0.11.0 + with: + access_token: ${{ github.token }} + + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Get Directories to Scan + working-directory: www/vale + run: ./get-files.sh api-reference app/_mdx + id: directories + + - name: Vale Linter + uses: errata-ai/vale-action@reviewdog + with: + files: ${{ steps.directories.outputs.LIST }} + fail_on_error: true + vale_flags: '--minAlertLevel=error' + reporter: github-pr-check + token: ${{ github.token }} + filter_mode: nofilter + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ github.token }} eslint: runs-on: ubuntu-latest @@ -80,11 +143,11 @@ jobs: fetch-depth: 0 - name: Install dependencies - working-directory: www/docs + working-directory: www run: yarn install - name: Run Eslint - working-directory: www/docs + working-directory: www run: yarn lint:content code-docs-eslint: @@ -104,33 +167,9 @@ jobs: run: yarn install - name: Install dependencies - working-directory: www/docs + working-directory: www run: yarn install - name: Run Eslint - working-directory: www/docs - run: yarn lint - - code-api-ref-eslint: - runs-on: ubuntu-latest - steps: - - name: Cancel Previous Runs - uses: styfle/cancel-workflow-action@0.11.0 - with: - access_token: ${{ github.token }} - - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Install Monorepo dependencies - run: yarn install - - - name: Install dependencies - working-directory: www/api-reference - run: yarn install - - - name: Run Eslint - working-directory: www/api-reference + working-directory: www run: yarn lint \ No newline at end of file diff --git a/.github/workflows/generate-api-reference.yml b/.github/workflows/generate-api-reference.yml index 64366b445b..f2d8eef49a 100644 --- a/.github/workflows/generate-api-reference.yml +++ b/.github/workflows/generate-api-reference.yml @@ -43,6 +43,6 @@ jobs: base: "develop" title: "chore(docs): Updated API Reference" labels: "type: chore" - add-paths: www/api-reference/specs + add-paths: www/apps/api-reference/specs branch: "chore/generate-api-ref" branch-suffix: "timestamp" diff --git a/.github/workflows/generate-entity-reference.yml b/.github/workflows/generate-entity-reference.yml index 8eed3da373..79198051b4 100644 --- a/.github/workflows/generate-entity-reference.yml +++ b/.github/workflows/generate-entity-reference.yml @@ -42,6 +42,6 @@ jobs: base: "develop" title: "chore(docs): Generated Entities Reference (automated)" labels: "type: chore" - add-paths: www/docs/content/references/entities/** + add-paths: www/apps/docs/content/references/entities/** branch: "chore/generate-entities" branch-suffix: "timestamp" diff --git a/.github/workflows/generate-js-reference.yml b/.github/workflows/generate-js-reference.yml index b9580c3cf5..5f40c18178 100644 --- a/.github/workflows/generate-js-reference.yml +++ b/.github/workflows/generate-js-reference.yml @@ -42,6 +42,6 @@ jobs: base: "develop" title: "chore(docs): Generated JS Client Reference" labels: "type: chore" - add-paths: www/docs/content/references/js-client/** + add-paths: www/apps/docs/content/references/js-client/** branch: "chore/generate-js-client" branch-suffix: "timestamp" diff --git a/.github/workflows/generate-reference.yml b/.github/workflows/generate-reference.yml index fab6bee271..3de94a45b9 100644 --- a/.github/workflows/generate-reference.yml +++ b/.github/workflows/generate-reference.yml @@ -42,6 +42,6 @@ jobs: base: "develop" title: "chore(docs): Generated Services Reference (automated)" labels: "type: chore" - add-paths: www/docs/content/references/services/** + add-paths: www/apps/docs/content/references/services/** branch: "chore/generate-services" branch-suffix: "timestamp" diff --git a/.vale.ini b/.vale.ini index 4b4f2cd6c7..bb325eb837 100644 --- a/.vale.ini +++ b/.vale.ini @@ -1,4 +1,4 @@ -StylesPath = www/docs/vale/styles +StylesPath = www/vale/styles MinAlertLevel = suggestion Vocab = Base diff --git a/packages/oas/oas-github-ci/scripts/build-openapi.js b/packages/oas/oas-github-ci/scripts/build-openapi.js index eead37fb98..0e749d76ec 100755 --- a/packages/oas/oas-github-ci/scripts/build-openapi.js +++ b/packages/oas/oas-github-ci/scripts/build-openapi.js @@ -8,7 +8,7 @@ const execa = require("execa") const isDryRun = process.argv.indexOf("--dry-run") !== -1 const basePath = path.resolve(__dirname, `../`) const repoRootPath = path.resolve(basePath, `../../../`) -const docsApiPath = path.resolve(repoRootPath, "www/api-reference/specs") +const docsApiPath = path.resolve(repoRootPath, "www/apps/api-reference/specs") const run = async () => { const oasOutDir = isDryRun ? await getTmpDirectory() : docsApiPath diff --git a/scripts/doc-change-release.js b/scripts/doc-change-release.js index a8568d86f1..5a18ca108c 100644 --- a/scripts/doc-change-release.js +++ b/scripts/doc-change-release.js @@ -18,7 +18,7 @@ async function main () { const commitResponse = await octokit.request('GET /repos/{owner}/{repo}/commits', { owner: 'medusajs', repo: 'medusa', - path: path.join('www', 'docs', 'announcement.json'), + path: path.join('www', "apps", 'docs', 'announcement.json'), per_page: 1 }) @@ -47,7 +47,7 @@ async function main () { } //write new config file - fs.writeFileSync(path.join(__dirname, '..', 'www', 'docs', 'announcement.json'), JSON.stringify(announcement)); + fs.writeFileSync(path.join(__dirname, '..', 'www', "apps", 'docs', 'announcement.json'), JSON.stringify(announcement)); console.log(`Announcement Bar has been ${shouldExpire ? 'removed' : 'added'}`); } diff --git a/scripts/freshness-check.js b/scripts/freshness-check.js index 92ddb60be9..bd247f0a0f 100644 --- a/scripts/freshness-check.js +++ b/scripts/freshness-check.js @@ -13,7 +13,7 @@ const linearClient = new LinearClient({ apiKey: process.env.LINEAR_API_KEY }); -const repoPath = path.join('docs', 'content'); +const repoPath = path.join('www', 'apps', 'docs', 'content'); let freshnessCheckLabelId = ""; let documentationTeamId = ""; diff --git a/typedoc.entities.js b/typedoc.entities.js index f4b65f7e81..87ada01cd7 100644 --- a/typedoc.entities.js +++ b/typedoc.entities.js @@ -3,7 +3,7 @@ const globalTypedocOptions = require("./typedoc") module.exports = { ...globalTypedocOptions, entryPoints: ["packages/medusa/src/models/index.ts"], - out: ["www/docs/content/references/entities"], + out: ["www/apps/docs/content/references/entities"], tsconfig: "packages/medusa/tsconfig.json", name: "Entities Reference", indexTitle: "Entities Reference", diff --git a/typedoc.js-client.js b/typedoc.js-client.js index 85336a2cd6..127de2f9b9 100644 --- a/typedoc.js-client.js +++ b/typedoc.js-client.js @@ -4,7 +4,7 @@ module.exports = { ...globalTypedocOptions, entryPoints: ["packages/medusa-js/src/resources"], entryPointStrategy: "expand", - out: ["www/docs/content/references/js-client"], + out: ["www/apps/docs/content/references/js-client"], tsconfig: "packages/medusa-js/tsconfig.json", name: "JS Client Reference", indexTitle: "JS Client Reference", diff --git a/typedoc.services.js b/typedoc.services.js index bcd71b81ce..932fc9db44 100644 --- a/typedoc.services.js +++ b/typedoc.services.js @@ -3,7 +3,7 @@ const globalTypedocOptions = require("./typedoc") module.exports = { ...globalTypedocOptions, entryPoints: ["packages/medusa/src/services/index.ts"], - out: ["www/docs/content/references/services"], + out: ["www/apps/docs/content/references/services"], tsconfig: "packages/medusa/tsconfig.json", name: "Services Reference", indexTitle: "Services Reference", diff --git a/www/.eslintrc.js b/www/.eslintrc.js index 8fa705b58a..78500800b5 100644 --- a/www/.eslintrc.js +++ b/www/.eslintrc.js @@ -1,127 +1,10 @@ module.exports = { root: true, - parser: "@babel/eslint-parser", - parserOptions: { - requireConfigFile: false, - ecmaFeatures: { - experimentalDecorators: true, - jsx: true - }, - }, - plugins: [ - "prettier" - ], - extends: [ - "eslint:recommended", - "plugin:prettier/recommended", - "plugin:react/recommended", - "plugin:react/jsx-runtime", - ], + // This tells ESLint to load the config from the package `eslint-config-docs` + extends: ["docs"], settings: { - react: { - version: "detect" - } - }, - rules: { - curly: ["error", "all"], - "new-cap": "off", - "require-jsdoc": "off", - "no-unused-expressions": "off", - "no-unused-vars": "off", - camelcase: "off", - "no-invalid-this": "off", - "max-len": [ - "error", - { - code: 80, - ignoreStrings: true, - ignoreRegExpLiterals: true, - ignoreComments: true, - ignoreTrailingComments: true, - ignoreUrls: true, - ignoreTemplateLiterals: true, - }, - ], - semi: ["error", "never"], - quotes: [ - "error", - "double", - { - allowTemplateLiterals: true, - }, - ], - "comma-dangle": [ - "error", - { - arrays: "always-multiline", - objects: "always-multiline", - imports: "always-multiline", - exports: "always-multiline", - functions: "never", - }, - ], - "object-curly-spacing": ["error", "always"], - "arrow-parens": ["error", "always"], - "linebreak-style": 0, - "no-confusing-arrow": [ - "error", - { - allowParens: false, - }, - ], - "space-before-function-paren": [ - "error", - { - anonymous: "always", - named: "never", - asyncArrow: "always", - }, - ], - "space-infix-ops": "error", - "eol-last": ["error", "always"], - "no-console": [ - "error", - { - allow: [ - "error", - "warn" - ] - } - ] - }, - env: { - es6: true, - node: true, - jest: true, - browser: true, - }, - ignorePatterns: [], - overrides: [ - { - files: ["*.ts", "*.tsx", "*.js", "*.jsx"], - plugins: ["@typescript-eslint/eslint-plugin"], - extends: ["plugin:@typescript-eslint/recommended", "plugin:react/recommended"], - parser: "@typescript-eslint/parser", - parserOptions: { - project: "./tsconfig.json", - }, - rules: { - "valid-jsdoc": "off", - "@typescript-eslint/no-non-null-assertion": "off", - "@typescript-eslint/no-floating-promises": "error", - "@typescript-eslint/await-thenable": "error", - "@typescript-eslint/promise-function-async": "error", - "@typescript-eslint/keyword-spacing": "error", - "@typescript-eslint/space-before-function-paren": [ - "error", - { - anonymous: "always", - named: "never", - asyncArrow: "always", - }, - ], - "@typescript-eslint/space-infix-ops": "error", - }, + next: { + rootDir: ["apps/*/"], }, - ], -} \ No newline at end of file + }, +}; \ No newline at end of file diff --git a/www/.gitignore b/www/.gitignore index 95dac3f486..42cbb92dd6 100644 --- a/www/.gitignore +++ b/www/.gitignore @@ -1,2 +1,10 @@ .vercel -build \ No newline at end of file +build +node_modules +.yarn/* +.yarn/install-state.gz +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/sdks +!.yarn/versions \ No newline at end of file diff --git a/www/docs/.prettierrc b/www/.prettierrc similarity index 100% rename from www/docs/.prettierrc rename to www/.prettierrc diff --git a/www/api-reference/.yarnrc.yml b/www/.yarnrc.yml similarity index 100% rename from www/api-reference/.yarnrc.yml rename to www/.yarnrc.yml diff --git a/www/api-reference/.eslintignore b/www/api-reference/.eslintignore deleted file mode 100644 index a35c325510..0000000000 --- a/www/api-reference/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -next.config.js -specs -node_modules -public \ No newline at end of file diff --git a/www/api-reference/.eslintrc.json b/www/api-reference/.eslintrc.json deleted file mode 100644 index 80c4b23f61..0000000000 --- a/www/api-reference/.eslintrc.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "extends": [ - "next/core-web-vitals", - "google", - "../.eslintrc.js" - ], - "rules": { - "react/react-in-jsx-scope": "off", - "@typescript-eslint/prefer-ts-expect-error": "off" - }, - "settings": { - "next": { - "rootDir": "." - } - } -} diff --git a/www/api-reference/app/_mdx/admin-introduction.mdx b/www/api-reference/app/_mdx/admin-introduction.mdx deleted file mode 100644 index f5c989a072..0000000000 --- a/www/api-reference/app/_mdx/admin-introduction.mdx +++ /dev/null @@ -1,21 +0,0 @@ -import Feedback from "@/components/Feedback" - -This API reference includes Medusa's Admin APIs, which are REST APIs exposed by the Medusa backend. They are typically used to perform admin functionalities or create an admin dashboard to access and manipulate your commerce store's data. - -All endpoints are prefixed with `/admin`. So, during development, the endpoints will be available under the path `http://localhost:9000/admin`. For production, replace `http://localhost:9000` with your Medusa backend URL. - -There are different ways you can send requests to these endpoints, including: - -- Using Medusa's [JavaScript Client](https://docs.medusajs.com/js-client/overview) -- Using the [Medusa React](https://docs.medusajs.com/medusa-react/overview) library -- Using cURL - -Aside from this API reference, check out the [Commerce Modules](https://docs.medusajs.com/modules/overview) section of the documentation for guides on how to use these APIs in different scenarios. - - \ No newline at end of file diff --git a/www/api-reference/app/_mdx/store-introduction.mdx b/www/api-reference/app/_mdx/store-introduction.mdx deleted file mode 100644 index e0ed5e3690..0000000000 --- a/www/api-reference/app/_mdx/store-introduction.mdx +++ /dev/null @@ -1,21 +0,0 @@ -import Feedback from "@/components/Feedback" - -This API reference includes Medusa's Store APIs, which are REST APIs exposed by the Medusa backend. They are typically used to create a storefront for your commerce store, such as a webshop or a commerce mobile app. - -All endpoints are prefixed with `/store`. So, during development, the endpoints will be available under the path `http://localhost:9000/store`. For production, replace `http://localhost:9000` with your Medusa backend URL. - -There are different ways you can send requests to these endpoints, including: - -- Using Medusa's [JavaScript Client](https://docs.medusajs.com/js-client/overview) -- Using the [Medusa React](https://docs.medusajs.com/medusa-react/overview) library -- Using cURL - -Aside from this API reference, check out the [Commerce Modules](https://docs.medusajs.com/modules/overview) section of the documentation for guides on how to use these APIs in different scenarios. - - \ No newline at end of file diff --git a/www/api-reference/app/api/[area]/layout.tsx b/www/api-reference/app/api/[area]/layout.tsx deleted file mode 100644 index 0f862e755e..0000000000 --- a/www/api-reference/app/api/[area]/layout.tsx +++ /dev/null @@ -1,81 +0,0 @@ -import SidebarProvider from "@/providers/sidebar" -import Sidebar from "@/components/Sidebar" -import clsx from "clsx" -import "../../../css/globals.css" -import BaseSpecsProvider from "@/providers/base-specs" -import Navbar from "@/components/Navbar" -import ColorModeProvider from "@/providers/color-mode" -import { Inter } from "next/font/google" -import { Roboto_Mono } from "next/font/google" -import AnalyticsProvider from "@/providers/analytics" -import NavbarProvider from "@/providers/navbar" -import ModalProvider from "../../../providers/modal" -import SearchProvider from "../../../providers/search" -import { ScrollControllerProvider } from "../../../hooks/scroll-utils" -import MobileProvider from "../../../providers/mobile" -import PageLoadingProvider from "../../../providers/page-loading" - -export const metadata = { - title: "Medusa API Reference", - description: "Check out Medusa's API reference", -} - -const inter = Inter({ - subsets: ["latin"], - variable: "--font-inter", - weight: ["400", "500"], -}) - -const robotoMono = Roboto_Mono({ - subsets: ["latin"], - variable: "--font-roboto-mono", -}) - -export default function RootLayout({ - children, -}: { - children: React.ReactNode -}) { - return ( - - - - - - - - - - - - -
- -
- -
- {children} -
-
-
-
-
-
-
-
-
-
-
-
-
- - - ) -} diff --git a/www/api-reference/components/Badge/index.tsx b/www/api-reference/components/Badge/index.tsx deleted file mode 100644 index 4f4ab310c6..0000000000 --- a/www/api-reference/components/Badge/index.tsx +++ /dev/null @@ -1,53 +0,0 @@ -import React from "react" -import clsx from "clsx" - -export type BadgeProps = { - className?: string - variant: - | "purple" - | "purple-dark" - | "orange" - | "orange-dark" - | "green" - | "green-dark" - | "blue" - | "blue-dark" - | "red" - | "neutral" -} & React.HTMLAttributes - -const Badge: React.FC = ({ className, variant, children }) => { - return ( - - {children} - - ) -} - -export default Badge diff --git a/www/api-reference/components/BorderedIcon/index.tsx b/www/api-reference/components/BorderedIcon/index.tsx deleted file mode 100644 index a602370263..0000000000 --- a/www/api-reference/components/BorderedIcon/index.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import React from "react" -import clsx from "clsx" -import Bordered from "../Bordered/index" -import IconProps from "../Icons/types" -import { useColorMode } from "../../providers/color-mode" -import Image from "next/image" - -type BorderedIconProp = { - icon?: { - light: string - dark?: string - } - IconComponent?: React.FC - wrapperClassName?: string - iconWrapperClassName?: string - iconClassName?: string - iconColorClassName?: string -} & React.HTMLAttributes - -const BorderedIcon: React.FC = ({ - icon = null, - IconComponent = null, - wrapperClassName, - iconWrapperClassName, - iconClassName, - iconColorClassName = "", -}) => { - const { colorMode } = useColorMode() - - return ( - - - {!IconComponent && ( - - )} - {IconComponent && ( - - )} - - - ) -} - -export default BorderedIcon diff --git a/www/api-reference/components/Button/index.tsx b/www/api-reference/components/Button/index.tsx deleted file mode 100644 index 377e4c6910..0000000000 --- a/www/api-reference/components/Button/index.tsx +++ /dev/null @@ -1,35 +0,0 @@ -import clsx from "clsx" - -export type ButtonProps = { - isSelected?: boolean - disabled?: boolean - variant?: "primary" | "secondary" | "clear" - darkVariant?: "primary" | "secondary" | "clear" -} & React.HTMLAttributes - -const Button = ({ - className, - children, - variant = "primary", - darkVariant, - ...props -}: ButtonProps) => { - return ( - - ) -} - -export default Button diff --git a/www/api-reference/components/Card/index.tsx b/www/api-reference/components/Card/index.tsx deleted file mode 100644 index 1f64589ae7..0000000000 --- a/www/api-reference/components/Card/index.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import clsx from "clsx" -import Link from "next/link" -import IconArrowUpRightOnBox from "../Icons/ArrowUpRightOnBox" - -type CardProps = { - title: string - text?: string - href?: string - className?: string -} - -const Card = ({ title, text, href, className }: CardProps) => { - return ( -
-
- - {title} - - {text && {text}} -
- - {href && ( - <> - - - - )} -
- ) -} - -export default Card diff --git a/www/api-reference/components/CopyButton/index.tsx b/www/api-reference/components/CopyButton/index.tsx deleted file mode 100644 index 4deb3334d0..0000000000 --- a/www/api-reference/components/CopyButton/index.tsx +++ /dev/null @@ -1,54 +0,0 @@ -"use client" - -import { useState, useEffect, useRef, useCallback } from "react" -import clsx from "clsx" -import dynamic from "next/dynamic" -import { TooltipProps } from "../Tooltip" -import SpinnerLoading from "../Loading/Spinner" - -const Tooltip = dynamic(async () => import("../Tooltip"), { - loading: () => , -}) as React.FC - -export type CopyButtonProps = { - text: string - buttonClassName?: string - tooltipClassName?: string -} & React.HTMLAttributes - -const CopyButton = ({ - text, - buttonClassName = "", - tooltipClassName = "", - children, -}: CopyButtonProps) => { - const [isCopied, setIsCopied] = useState(false) - const copyTimeout = useRef(undefined) - - const handleCopy = useCallback(async () => { - const copy = (await import("copy-text-to-clipboard")).default - copy(text) - setIsCopied(true) - copyTimeout.current = window.setTimeout(() => { - setIsCopied(false) - }, 1000) - }, [text]) - - useEffect(() => () => window.clearTimeout(copyTimeout.current), []) - - return ( - - - {children} - - - ) -} - -export default CopyButton diff --git a/www/api-reference/components/Feedback/index.tsx b/www/api-reference/components/Feedback/index.tsx deleted file mode 100644 index a996782c74..0000000000 --- a/www/api-reference/components/Feedback/index.tsx +++ /dev/null @@ -1,207 +0,0 @@ -"use client" - -import React, { useRef, useState } from "react" -import { CSSTransition, SwitchTransition } from "react-transition-group" -import Solutions from "./Solutions/index" -import Button from "../Button" -import { ExtraData, useAnalytics } from "@/providers/analytics" -import { usePathname } from "next/navigation" -import Link from "next/link" -import { useArea } from "../../providers/area" -import clsx from "clsx" -import TextArea from "../TextArea" -import Label from "../Label" - -type FeedbackProps = { - event: string - question?: string - positiveBtn?: string - negativeBtn?: string - positiveQuestion?: string - negativeQuestion?: string - submitBtn?: string - submitMessage?: string - showPossibleSolutions?: boolean - className?: string - extraData?: ExtraData - sectionTitle?: string - vertical?: boolean -} & React.HTMLAttributes - -const Feedback: React.FC = ({ - event, - question = "Was this section helpful?", - positiveBtn = "Yes", - negativeBtn = "No", - positiveQuestion = "What was most helpful?", - negativeQuestion = "What can we improve?", - submitBtn = "Submit", - submitMessage = "Thank you for helping improve our documentation!", - showPossibleSolutions = true, - className = "", - extraData = {}, - sectionTitle = "", - vertical = false, -}) => { - const [showForm, setShowForm] = useState(false) - const [submittedFeedback, setSubmittedFeedback] = useState(false) - const [loading, setLoading] = useState(false) - const inlineFeedbackRef = useRef(null) - const inlineQuestionRef = useRef(null) - const inlineMessageRef = useRef(null) - const [positiveFeedback, setPositiveFeedback] = useState(false) - const [message, setMessage] = useState("") - const nodeRef: React.RefObject = submittedFeedback - ? inlineMessageRef - : showForm - ? inlineQuestionRef - : inlineFeedbackRef - - const pathname = usePathname() - const { loaded, track } = useAnalytics() - const { area } = useArea() - - function handleFeedback(e: React.MouseEvent) { - if (!loaded) { - return - } - const feedback = (e.target as Element).classList.contains("positive") - setPositiveFeedback(feedback) - setShowForm(true) - submitFeedback(e, feedback) - } - - function submitFeedback( - e: React.MouseEvent, - feedback = false - ) { - if (showForm) { - setLoading(true) - } - track( - event, - { - url: pathname, - label: document.title, - feedback: - (feedback !== null && feedback) || - (feedback === null && positiveFeedback) - ? "yes" - : "no", - message: message?.length ? message : null, - os: window.navigator.userAgent, - ...extraData, - }, - function () { - if (showForm) { - setLoading(false) - resetForm() - } - } - ) - } - - function resetForm() { - setShowForm(false) - setSubmittedFeedback(true) - } - - return ( -
- - { - nodeRef.current?.addEventListener("transitionend", done, false) - }} - classNames={{ - enter: "animate-fadeIn animate-fill-forwards animate-fast", - exit: "animate-fadeOut animate-fill-forwards animate-fast", - }} - > - <> - {!showForm && !submittedFeedback && ( -
- -
- - - - Report Issue - -
-
- )} - {showForm && !submittedFeedback && ( -
- -