fix(workbench): complete profile and channel flows
This commit is contained in:
@@ -2,7 +2,7 @@ import { useCallback, useRef, useState } from 'react'
|
||||
import { ConfigProvider, Message, Spin } from '@arco-design/web-react'
|
||||
import '@arco-design/web-react/dist/css/arco.css'
|
||||
import '../App.css'
|
||||
import { ApiError, login, setApiBaseUrl, type ApiSession } from '../api/client'
|
||||
import { ApiError, login, setApiBaseUrl, updateCurrentUser, type ApiSession, type CurrentUser } from '../api/client'
|
||||
import { createAISession, listAIExperts, listAISessions, type CreateAISessionInput } from '../api/ai'
|
||||
import {
|
||||
createDatasetSource,
|
||||
@@ -20,6 +20,8 @@ import { analyzeInboxItem, confirmInboxItem } from '../api/inbox'
|
||||
import { mapWorkspace } from '../api/mappers'
|
||||
import {
|
||||
createCronPlan,
|
||||
|
||||
createProjectChannel,
|
||||
createProject,
|
||||
createProjectTag,
|
||||
createTask,
|
||||
@@ -44,6 +46,7 @@ function App() {
|
||||
const [theme, setTheme] = useState<Theme>('light')
|
||||
const [activeView, setActiveView] = useState<WorkbenchView>('workspace')
|
||||
const [session, setSession] = useState<ApiSession | null>(null)
|
||||
const [currentUser, setCurrentUser] = useState<CurrentUser | null>(null)
|
||||
const [workspaces, setWorkspaces] = useState<ProjectWorkspace[]>([])
|
||||
const [activeProjectID, setActiveProjectID] = useState<string>('')
|
||||
const activeProjectIDRef = useRef('')
|
||||
@@ -163,9 +166,11 @@ function App() {
|
||||
setLoading(true)
|
||||
try {
|
||||
setApiBaseUrl(input.server)
|
||||
const nextSession = await login(input.email, input.password)
|
||||
const loginResult = await login(input.email, input.password)
|
||||
const { user, ...nextSession } = loginResult
|
||||
await loadWorkspaces(nextSession, '')
|
||||
setSession(nextSession)
|
||||
setCurrentUser(user)
|
||||
selectActiveProject('')
|
||||
setActiveChannel('overview')
|
||||
setActiveView('workspace')
|
||||
@@ -177,6 +182,23 @@ function App() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleUpdateProfile(input: { displayName: string; currentPassword?: string; newPassword?: string }) {
|
||||
const updated = await updateCurrentUser(requireSession(), input)
|
||||
setCurrentUser(updated)
|
||||
Message.success('个人资料已更新')
|
||||
}
|
||||
|
||||
function handleLogout() {
|
||||
setSession(null)
|
||||
setCurrentUser(null)
|
||||
setWorkspaces([])
|
||||
selectActiveProject('')
|
||||
setActiveView('workspace')
|
||||
setActiveChannel('overview')
|
||||
setActiveTaskID(null)
|
||||
setScreen('login')
|
||||
}
|
||||
|
||||
async function refreshAfterAction(nextProjectID?: string) {
|
||||
if (!session) return
|
||||
await loadWorkspaces(session, nextProjectID)
|
||||
@@ -283,6 +305,13 @@ function App() {
|
||||
}, '标签已创建')
|
||||
}
|
||||
|
||||
async function handleCreateProjectChannel(input: { title: string; icon: string; url: string }) {
|
||||
const projectID = requireActiveProject()
|
||||
await createProjectChannel(requireSession(), projectID, input)
|
||||
await refreshAfterAction(projectID)
|
||||
setActiveChannel('overview')
|
||||
}
|
||||
|
||||
function openTask(project: Project, taskID: string) {
|
||||
selectActiveProject(project.id)
|
||||
setActiveView('project')
|
||||
@@ -390,7 +419,7 @@ function App() {
|
||||
<Spin loading={loading} style={{ width: '100%' }}>
|
||||
<LoginPage onLogin={handleLogin} />
|
||||
</Spin>
|
||||
) : session ? (
|
||||
) : session && currentUser ? (
|
||||
<ProjectPage
|
||||
activeView={activeView}
|
||||
activeWorkspace={activeWorkspace}
|
||||
@@ -425,6 +454,10 @@ function App() {
|
||||
onUpdateWorkspaceTask={handleUpdateWorkspaceTask}
|
||||
onUpdateProject={handleUpdateProject}
|
||||
onCreateProjectTag={handleCreateProjectTag}
|
||||
currentUser={currentUser}
|
||||
onUpdateProfile={handleUpdateProfile}
|
||||
onLogout={handleLogout}
|
||||
onCreateProjectChannel={handleCreateProjectChannel}
|
||||
searchQuery={workspaceSearch.query}
|
||||
searchLoading={workspaceSearch.loading}
|
||||
searchSearched={workspaceSearch.searched}
|
||||
|
||||
Reference in New Issue
Block a user