Skip to content

Commit

Permalink
Merge branch 'refactor/builder_dashboard' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
AruSeito committed Oct 18, 2023
2 parents 3266c6d + f4d3740 commit 09ef2fc
Show file tree
Hide file tree
Showing 29 changed files with 94 additions and 226 deletions.
2 changes: 1 addition & 1 deletion apps/builder/src/api/http/interceptors/request/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getAuthToken } from "@illa-public/utils"
import { AxiosRequestConfig } from "axios"
import { getAuthToken } from "@/utils/auth"

export const authInterceptor = (config: AxiosRequestConfig) => {
const token = getAuthToken()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { isCloudVersion } from "@illa-public/utils"
import { removeAuthToken } from "@illa-public/utils"
import { AxiosError } from "axios"
import { cloudRedirect } from "@/router/constant"
import { getQS } from "@/router/utils/translateQS"
import { removeAuthToken } from "@/utils/auth"
import { commonBillingErrorHandler } from "@/utils/billing/errorHandler"

const getRedirectPathWhen401 = (searchParams: URLSearchParams) => {
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/src/api/ws/illaWS.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getCurrentTeamInfo } from "@illa-public/user-data"
import { getAuthToken } from "@illa-public/utils"
import { getTextMessagePayload } from "@/api/ws/index"
import {
Callback,
Expand All @@ -16,7 +17,6 @@ import {
REMOVE_DISPLAY_NAME,
UPDATE_DISPLAY_NAME,
} from "@/utils/generators/generateDisplayName"
import { ILLABuilderStorage } from "@/utils/storage"

const HEARTBEAT_PING_TIMEOUT = 2 * 1000
const HEARTBEAT_PONG_TIMEOUT = 5 * 1000
Expand Down Expand Up @@ -212,7 +212,7 @@ export class ILLAWebsocket {
uid,
[
{
authToken: ILLABuilderStorage.getLocalStorage("token"),
authToken: getAuthToken(),
},
],
),
Expand Down
10 changes: 7 additions & 3 deletions apps/builder/src/page/AI/AIAgent/aiagent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ import {
showShareAgentModal,
showShareAgentModalOnlyForShare,
} from "@illa-public/user-role-utils"
import { getAgentPublicLink, sendTagEvent } from "@illa-public/utils"
import {
getAgentPublicLink,
getILLABuilderURL,
sendTagEvent,
} from "@illa-public/utils"
import { getAuthToken } from "@illa-public/utils"
import { isEqual } from "lodash"
import { FC, useCallback, useEffect, useMemo, useState } from "react"
import { Controller, useForm, useFormState, useWatch } from "react-hook-form"
Expand Down Expand Up @@ -71,7 +76,6 @@ import {
putAgentDetail,
uploadAgentIcon,
} from "@/services/agent"
import { getAuthToken } from "@/utils/auth"
import { copyToClipboard } from "@/utils/copyToClipboard"
import { track } from "@/utils/mixpanelHelper"
import { ChatContext } from "../components/ChatContext"
Expand Down Expand Up @@ -1149,7 +1153,7 @@ export const AIAgent: FC = () => {
agentName: nameField.value,
},
)}
redirectURL={`${import.meta.env.ILLA_BUILDER_URL}/${
redirectURL={`${getILLABuilderURL()}/${
currentTeamInfo.identifier
}/ai-agent/${idField.value}`}
onClose={() => {
Expand Down
12 changes: 7 additions & 5 deletions apps/builder/src/page/AI/AIAgentRun/AIAgentRunMobile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ import {
openShareAgentModal,
showShareAgentModal,
} from "@illa-public/user-role-utils"
import { formatNumForAgent, getAgentPublicLink } from "@illa-public/utils"
import {
formatNumForAgent,
getAgentPublicLink,
getILLABuilderURL,
} from "@illa-public/utils"
import { getAuthToken } from "@illa-public/utils"
import { motion } from "framer-motion"
import { FC, useState } from "react"
import { Controller, useForm, useFormState } from "react-hook-form"
Expand Down Expand Up @@ -66,7 +71,6 @@ import { ChatSendRequestPayload } from "@/page/AI/components/PreviewChat/interfa
import { useAgentConnect } from "@/page/AI/components/ws/useAgentConnect"
import { CollaboratorsInfo } from "@/redux/currentApp/collaborators/collaboratorsState"
import { forkAIAgentToTeam, starAIAgent, unstarAIAgent } from "@/services/agent"
import { getAuthToken } from "@/utils/auth"
import { copyToClipboard } from "@/utils/copyToClipboard"
import { track } from "@/utils/mixpanelHelper"
import { ChatContext } from "../../components/ChatContext"
Expand Down Expand Up @@ -223,9 +227,7 @@ export const AIAgentRunMobile: FC = () => {
agentName: agent.name,
},
)}
redirectURL={`${
import.meta.env.ILLA_BUILDER_URL
}/${ownerTeamIdentifier}/ai-agent/${
redirectURL={`${getILLABuilderURL()}/${ownerTeamIdentifier}/ai-agent/${
agent.aiAgentID
}/run?myTeamIdentifier=${searchParams.get("myTeamIdentifier")}`}
onClose={() => {
Expand Down
12 changes: 7 additions & 5 deletions apps/builder/src/page/AI/AIAgentRun/AIAgentRunPC/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ import {
showShareAgentModal,
showShareAgentModalOnlyForShare,
} from "@illa-public/user-role-utils"
import { formatNumForAgent, getAgentPublicLink } from "@illa-public/utils"
import {
formatNumForAgent,
getAgentPublicLink,
getILLABuilderURL,
} from "@illa-public/utils"
import { getAuthToken } from "@illa-public/utils"
import { FC, useState } from "react"
import { Controller, useForm, useFormState } from "react-hook-form"
import { useTranslation } from "react-i18next"
Expand Down Expand Up @@ -65,7 +70,6 @@ import { ChatSendRequestPayload } from "@/page/AI/components/PreviewChat/interfa
import { useAgentConnect } from "@/page/AI/components/ws/useAgentConnect"
import { CollaboratorsInfo } from "@/redux/currentApp/collaborators/collaboratorsState"
import { forkAIAgentToTeam, starAIAgent, unstarAIAgent } from "@/services/agent"
import { getAuthToken } from "@/utils/auth"
import { copyToClipboard } from "@/utils/copyToClipboard"
import { track } from "@/utils/mixpanelHelper"
import { ChatContext } from "../../components/ChatContext"
Expand Down Expand Up @@ -175,9 +179,7 @@ export const AIAgentRunPC: FC = () => {
agentName: agent.name,
},
)}
redirectURL={`${
import.meta.env.ILLA_BUILDER_URL
}/${ownerTeamIdentifier}/ai-agent/${
redirectURL={`${getILLABuilderURL()}/${ownerTeamIdentifier}/ai-agent/${
agent.aiAgentID
}/run?myTeamIdentifier=${searchParams.get("myTeamIdentifier")}`}
onClose={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import {
openShareAppModal,
} from "@illa-public/user-role-utils"
import { getMarketLinkTemplate } from "@illa-public/utils"
import { getAuthToken } from "@illa-public/utils"
import { FC, useState } from "react"
import { useTranslation } from "react-i18next"
import { useDispatch, useSelector } from "react-redux"
import { Button, ContributeIcon, getColor } from "@illa-design/react"
import { ContributeButtonProps } from "@/page/App/components/PageNavBar/ContributeButton/interface"
import { appInfoActions } from "@/redux/currentApp/appInfo/appInfoSlice"
import { getAuthToken } from "@/utils/auth"
import { copyToClipboard } from "@/utils/copyToClipboard"
import { track } from "@/utils/mixpanelHelper"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import {
openShareAppModal,
} from "@illa-public/user-role-utils"
import { getMarketLinkTemplate, isCloudVersion } from "@illa-public/utils"
import { getAuthToken } from "@illa-public/utils"
import { FC, useState } from "react"
import { useTranslation } from "react-i18next"
import { useDispatch, useSelector } from "react-redux"
import { Button, getColor } from "@illa-design/react"
import { ShareAppButtonProps } from "@/page/App/components/PageNavBar/ShareAppButton/interface"
import { appInfoActions } from "@/redux/currentApp/appInfo/appInfoSlice"
import { getAuthToken } from "@/utils/auth"
import { copyToClipboard } from "@/utils/copyToClipboard"
import { track } from "@/utils/mixpanelHelper"

Expand Down
15 changes: 6 additions & 9 deletions apps/builder/src/page/App/components/PageNavBar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
canUseUpgradeFeature,
showShareAppModal,
} from "@illa-public/user-role-utils"
import { isCloudVersion } from "@illa-public/utils"
import { getILLACloudURL, isCloudVersion } from "@illa-public/utils"
import {
FC,
MouseEvent,
Expand All @@ -16,7 +16,7 @@ import {
} from "react"
import { useTranslation } from "react-i18next"
import { useDispatch, useSelector } from "react-redux"
import { useNavigate, useParams } from "react-router-dom"
import { Link, useNavigate, useParams } from "react-router-dom"
import {
Badge,
BugIcon,
Expand Down Expand Up @@ -336,13 +336,10 @@ export const PageNavBar: FC<PageNavBarProps> = (props) => {
return (
<div className={className} css={navBarStyle}>
<div css={rowCenter}>
<Logo
width="34px"
onClick={() => {
navigate(`/${teamIdentifier}/dashboard/apps`)
}}
css={logoCursorStyle}
/>
<Link to={getILLACloudURL()}>
<Logo width="34px" css={logoCursorStyle} />
</Link>

<div css={informationStyle}>
<AppName appInfo={appInfo} />
{isOnline ? (
Expand Down
3 changes: 2 additions & 1 deletion apps/builder/src/page/Resource/layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getILLACloudURL } from "@illa-public/utils"
import { FC } from "react"
import { Link, Outlet } from "react-router-dom"
import { ReactComponent as Logo } from "@/assets/illa-logo.svg"
Expand All @@ -12,7 +13,7 @@ export const ResourceLayout: FC = () => {
return (
<div css={resourceLayoutContainerStyle}>
<header css={headerContainerStyle}>
<Link to={`${import.meta.env.ILLA_CLOUD_URL}`}>
<Link to={getILLACloudURL()}>
<Logo css={iconStyle} />
</Link>
</header>
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/src/router/config/cloud.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getILLACloudURL } from "@illa-public/utils"
import { lazy } from "react"
import { redirect } from "react-router-dom"
import { FullPageLoading } from "@/components/FullPageLoading"
import { agentLoader } from "@/router/loader/agentLoader"
import { agentRunLoader } from "@/router/loader/agentRunLoader"
import { historyLoader } from "@/router/loader/historyLoader"
import { cloudUrl } from "../constant"
import { RoutesObjectPro } from "../interface"
import { lazyLoad } from "../utils/lazyLoad"
import { publicRouterConfig, publicTeamChildrenRouter } from "./public"
Expand All @@ -13,7 +13,7 @@ export const cloudRouter: RoutesObjectPro[] = [
{
index: true,
loader: async () => {
return redirect(cloudUrl)
return redirect(getILLACloudURL())
},
},
{
Expand Down
7 changes: 5 additions & 2 deletions apps/builder/src/router/config/selfHost.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { getILLACloudURL } from "@illa-public/utils"
import { redirect } from "react-router-dom"
import { RoutesObjectPro } from "../interface"
import { selfHostLandingLoader } from "../loader/landingLoader"
import { publicRouterConfig, publicTeamChildrenRouter } from "./public"

export const selfRouter: RoutesObjectPro[] = [
{
index: true,
loader: selfHostLandingLoader,
loader: async () => {
return redirect(getILLACloudURL())
},
},
...publicTeamChildrenRouter,
...publicRouterConfig,
Expand Down
4 changes: 2 additions & 2 deletions apps/builder/src/router/constant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const cloudUrl = `${import.meta.env.ILLA_CLOUD_URL}`
import { getILLACloudURL } from "@illa-public/utils"

export const cloudRedirect = `${cloudUrl}?redirectURL=${encodeURIComponent(
export const cloudRedirect = `${getILLACloudURL()}?redirectURL=${encodeURIComponent(
location.origin + location.pathname,
)}`

Expand Down
38 changes: 12 additions & 26 deletions apps/builder/src/router/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { isCloudVersion } from "@illa-public/utils"
import { createBrowserRouter } from "react-router-dom"
import { LayoutAutoChange } from "@/components/LayoutAutoChange"
import { RoutesObjectPro } from "@/router/interface"
import { routerConfig } from "@/router/routerConfig"
import { beautifyURLLoader } from "./loader/beautifyURLLoader"
import { setTokenToLocalStorageLoader } from "./loader/cloudAuthLoader"
import {
combineCloudAuthLoader,
combineSelfHostAuthLoader,
} from "./loader/index"
import { combineCloudAuthLoader } from "./loader/index"

const wrappedRouter = (
routesConfig: RoutesObjectPro[],
Expand All @@ -31,27 +27,17 @@ const wrappedRouter = (
newRouteItem.element = <>{element}</>
}
newRouteItem.loader = async (args) => {
if (isCloudVersion) {
await setTokenToLocalStorageLoader(args)
const beautifyURLResponse = await beautifyURLLoader(args)
if (beautifyURLResponse) {
return beautifyURLResponse
}
let authLoaderResponse
if (needLogin) {
authLoaderResponse = await combineCloudAuthLoader(args)
}
if (authLoaderResponse) {
return authLoaderResponse
}
} else {
let authLoaderResponse
if (needLogin) {
authLoaderResponse = await combineSelfHostAuthLoader(args)
}
if (authLoaderResponse) {
return authLoaderResponse
}
await setTokenToLocalStorageLoader(args)
const beautifyURLResponse = await beautifyURLLoader(args)
if (beautifyURLResponse) {
return beautifyURLResponse
}
let authLoaderResponse
if (needLogin) {
authLoaderResponse = await combineCloudAuthLoader(args)
}
if (authLoaderResponse) {
return authLoaderResponse
}
if (originLoader) {
return await originLoader(args)
Expand Down
17 changes: 11 additions & 6 deletions apps/builder/src/router/loader/cloudAuthLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,25 @@ import {
teamActions,
} from "@illa-public/user-data"
import { canAccessManage } from "@illa-public/user-role-utils"
import { isCloudVersion, sendConfigEvent } from "@illa-public/utils"
import {
getILLACloudURL,
isCloudVersion,
sendConfigEvent,
setAuthToken,
} from "@illa-public/utils"
import { getAuthToken } from "@illa-public/utils"
import { LoaderFunction, redirect } from "react-router-dom"
import i18n from "@/i18n/config"
import { cloudUrl } from "@/router/constant"
import { fetchMyTeamsInfo } from "@/services/team"
import { fetchUserInfo } from "@/services/users"
import store from "@/store"
import { getAuthToken } from "@/utils/auth"
import { ILLABuilderStorage } from "@/utils/storage"

export const setTokenToLocalStorageLoader: LoaderFunction = async (args) => {
const url = new URL(args.request.url)
const searchParams = url.searchParams
const token = searchParams.get("token")
if (token) {
ILLABuilderStorage.setLocalStorage("token", token, -1)
setAuthToken(token)
}
return null
}
Expand Down Expand Up @@ -92,7 +95,9 @@ export const getTeamsInfoLoader: LoaderFunction = async (args) => {
currentTeamInfo.totalTeamLicense.teamLicenseAllPaid,
)
) {
return redirect(`${cloudUrl}/workspace/${currentTeamInfo.identifier}`)
return redirect(
`${getILLACloudURL()}/workspace/${currentTeamInfo.identifier}`,
)
}
return null
}
Expand Down
17 changes: 0 additions & 17 deletions apps/builder/src/router/loader/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { LoaderFunction, redirect } from "react-router-dom"
import { beautifyURLLoader } from "./beautifyURLLoader"
import { getTeamsInfoLoader, getUserInfoLoader } from "./cloudAuthLoader"
import {
getSelfHostTeamsInfoLoader,
getSelfHostUserInfoLoader,
} from "./selfHostAuthLoader"

export const combineCloudAuthLoader: LoaderFunction = async (args) => {
try {
Expand All @@ -18,16 +14,3 @@ export const combineCloudAuthLoader: LoaderFunction = async (args) => {
return redirect("/403")
}
}

export const combineSelfHostAuthLoader: LoaderFunction = async (args) => {
try {
const userInfoResponse = await getSelfHostUserInfoLoader(args)
const teamsInfoResponse = await getSelfHostTeamsInfoLoader(args)
if (userInfoResponse || teamsInfoResponse) {
return userInfoResponse || teamsInfoResponse
}
return await beautifyURLLoader(args)
} catch (e) {
return redirect("/500")
}
}
9 changes: 0 additions & 9 deletions apps/builder/src/router/loader/landingLoader.ts

This file was deleted.

Loading

0 comments on commit 09ef2fc

Please sign in to comment.