import React, { useEffect, useRef, useState } from "react"; import Head from "next/head"; import { useRouter } from "next/router"; import useTranslation from "next-translate/useTranslation"; import { faCheck, faPlus } from "@fortawesome/free-solid-svg-icons"; import Button from "~/components/basic/buttons/Button"; import AddServiceTokenDialog from "~/components/basic/dialog/AddServiceTokenDialog"; import InputField from "~/components/basic/InputField"; import ServiceTokenTable from "~/components/basic/table/ServiceTokenTable"; import NavHeader from "~/components/navigation/NavHeader"; import getServiceTokens from "../../api/serviceToken/getServiceTokens"; import deleteWorkspace from "../../api/workspace/deleteWorkspace"; import getWorkspaces from "../../api/workspace/getWorkspaces"; import renameWorkspace from "../../api/workspace/renameWorkspace"; export default function SettingsBasic() { const [buttonReady, setButtonReady] = useState(false); const router = useRouter(); const [workspaceName, setWorkspaceName] = useState(""); const [serviceTokens, setServiceTokens] = useState([]); const [workspaceToBeDeletedName, setWorkspaceToBeDeletedName] = useState(""); const [workspaceId, setWorkspaceId] = useState(""); const [isAddOpen, setIsAddOpen] = useState(false); let [isAddServiceTokenDialogOpen, setIsAddServiceTokenDialogOpen] = useState(false); const { t } = useTranslation(); useEffect(async () => { let userWorkspaces = await getWorkspaces(); userWorkspaces.map((userWorkspace) => { if (userWorkspace._id == router.query.id) { setWorkspaceName(userWorkspace.name); } }); let tempServiceTokens = await getServiceTokens({ workspaceId: router.query.id, }); setServiceTokens(tempServiceTokens); }, []); const modifyWorkspaceName = (newName) => { setButtonReady(true); setWorkspaceName(newName); }; const submitChanges = (newWorkspaceName) => { renameWorkspace(router.query.id, newWorkspaceName); setButtonReady(false); }; useEffect(async () => { setWorkspaceId(router.query.id); }, []); function closeAddModal() { setIsAddOpen(false); } function openAddModal() { setIsAddOpen(true); } const closeAddServiceTokenModal = () => { setIsAddServiceTokenDialogOpen(false); }; /** * This function deleted a workspace. * It first checks if there is more than one workspace aviable. Otherwise, it doesn't delete * It then checks if the name of the workspace to be deleted is correct. Otherwise, it doesn't delete. * It then deletes the workspace and forwards the user to another aviable workspace. */ const executeDeletingWorkspace = async () => { let userWorkspaces = await getWorkspaces(); if (userWorkspaces.length > 1) { if ( userWorkspaces.filter( (workspace) => workspace._id == router.query.id )[0].name == workspaceToBeDeletedName ) { await deleteWorkspace(router.query.id); let userWorkspaces = await getWorkspaces(); router.push("/dashboard/" + userWorkspaces[0]._id); } } }; return (
{t("common:head-title", { title: t("settings-project:title") })}

{t("settings-project:title")}

{t("settings-project:description")}

{t("common:display-name")}

{t("common:project-id")}

{t("settings-project:project-id-description")}

{t("settings-project:project-id-description2")} {/* eslint-disable-next-line react/jsx-no-target-blank */} {t("settings-project:docs")}

{t("section-token:service-tokens")}

{t("section-token:service-tokens-description")}

{/*

Project Environments

Choose which environments will show up in your Dashboard. Some common ones include Development, Staging, and Production. Often, teams choose to add Testing.

Note: the text in brackets shows how these environmant should be accessed in CLI.

{envOptions.map((env) => (
{env}
))}
*/}

{t("settings-project:danger-zone")}

{t("settings-project:danger-zone-note")}

{t("settings-project:delete-project-note")}

); } SettingsBasic.requireAuth = true;