feat(organization): implement searchable organizations feature
- Added a 'searchable' flag to organizations, allowing them to be discoverable and joinable by ID without an invite code. - Introduced API endpoints for searching and joining searchable organizations. - Updated UI components to support searching for organizations and displaying results. - Enhanced localization for new search-related features in both English and Chinese. This update improves user experience by enabling easier discovery and joining of organizations.
This commit is contained in:
@@ -11,6 +11,7 @@ export interface Organization {
|
||||
invite_code_expires_at?: string | null
|
||||
invite_code_validity_days?: number
|
||||
require_approval?: boolean
|
||||
searchable?: boolean
|
||||
member_count?: number
|
||||
share_count?: number
|
||||
pending_join_request_count?: number
|
||||
@@ -82,6 +83,18 @@ export interface OrganizationPreview {
|
||||
created_at: string
|
||||
}
|
||||
|
||||
/** Searchable (discoverable) organization item for join flow */
|
||||
export interface SearchableOrganizationItem {
|
||||
id: string
|
||||
name: string
|
||||
description: string
|
||||
avatar?: string
|
||||
member_count: number
|
||||
share_count: number
|
||||
is_already_member: boolean
|
||||
require_approval: boolean
|
||||
}
|
||||
|
||||
// Request types
|
||||
export interface CreateOrganizationRequest {
|
||||
name: string
|
||||
@@ -95,6 +108,7 @@ export interface UpdateOrganizationRequest {
|
||||
description?: string
|
||||
avatar?: string
|
||||
require_approval?: boolean
|
||||
searchable?: boolean
|
||||
invite_code_validity_days?: number // 0=never, 1, 7, 30
|
||||
}
|
||||
|
||||
@@ -284,6 +298,48 @@ export async function previewOrganization(inviteCode: string): Promise<ApiRespon
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Search searchable (discoverable) organizations
|
||||
*/
|
||||
export async function searchSearchableOrganizations(
|
||||
q: string = '',
|
||||
limit: number = 20
|
||||
): Promise<ApiResponse<{ data: SearchableOrganizationItem[]; total: number }>> {
|
||||
try {
|
||||
const params = new URLSearchParams()
|
||||
if (q) params.set('q', q)
|
||||
params.set('limit', String(limit))
|
||||
const response = await get(`/api/v1/organizations/search?${params.toString()}`)
|
||||
const res = response as unknown as { success: boolean; data?: SearchableOrganizationItem[]; total?: number; message?: string }
|
||||
return {
|
||||
success: res.success,
|
||||
data: res.success ? { data: res.data || [], total: res.total ?? 0 } : undefined,
|
||||
message: res.message,
|
||||
}
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.message || 'Failed to search organizations' }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Join a searchable organization by ID (no invite code)
|
||||
*/
|
||||
export async function joinOrganizationById(
|
||||
organizationId: string,
|
||||
message?: string,
|
||||
role?: 'admin' | 'editor' | 'viewer'
|
||||
): Promise<ApiResponse<Organization>> {
|
||||
try {
|
||||
const body: { organization_id: string; message?: string; role?: string } = { organization_id: organizationId }
|
||||
if (message) body.message = message
|
||||
if (role) body.role = role
|
||||
const response = await post('/api/v1/organizations/join-by-id', body)
|
||||
return response as unknown as ApiResponse<Organization>
|
||||
} catch (error: any) {
|
||||
return { success: false, message: error.message || 'Failed to join organization' }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Leave organization
|
||||
*/
|
||||
|
||||
@@ -2370,6 +2370,12 @@ export default {
|
||||
shareCount: '{count} shared knowledge bases',
|
||||
alreadyMember: 'You are already a member of this space',
|
||||
invalidCode: 'Invalid invite code',
|
||||
byInviteCode: 'Enter invite code',
|
||||
searchSpaces: 'Search spaces',
|
||||
searchSpacesDesc: 'Browse or search spaces that are open for discovery; join without an invite code',
|
||||
searchSpacesPlaceholder: 'Search by space name or description',
|
||||
noSearchResult: 'No matching spaces',
|
||||
noSearchableSpaces: 'No discoverable spaces yet, or try a search',
|
||||
},
|
||||
invite: {
|
||||
loading: 'Loading...',
|
||||
@@ -2394,6 +2400,7 @@ export default {
|
||||
requestRole: 'Requested role',
|
||||
selectRole: 'Select role',
|
||||
messagePlaceholder: 'Optional: message (e.g. intro or reason to join)',
|
||||
applicationNote: 'Application note (optional)',
|
||||
joinSuccess: 'Successfully joined space!',
|
||||
joinFailed: 'Failed to join, please try again',
|
||||
requestSubmitted: 'Request submitted, please wait for admin approval',
|
||||
@@ -2473,6 +2480,8 @@ export default {
|
||||
removeShareFailed: 'Failed to remove, please try again',
|
||||
requireApproval: 'Require Approval',
|
||||
requireApprovalDesc: 'When enabled, new members need admin approval to join',
|
||||
searchable: 'Open for search',
|
||||
searchableDesc: 'When enabled, this space appears in the "Join Space" search list; others can search and request to join without an invite code',
|
||||
joinRequests: 'Join Requests',
|
||||
joinRequestsDesc: 'Review pending requests to join the space',
|
||||
noPendingRequests: 'No pending requests',
|
||||
|
||||
@@ -2375,6 +2375,12 @@ export default {
|
||||
shareCount: "{count} 个共享知识库",
|
||||
alreadyMember: "您已经是该空间的成员",
|
||||
invalidCode: "无效的邀请码",
|
||||
byInviteCode: "输入邀请码",
|
||||
searchSpaces: "搜索空间",
|
||||
searchSpacesDesc: "浏览或搜索已开放可被搜索的空间,无需邀请码即可加入",
|
||||
searchSpacesPlaceholder: "按空间名称或描述搜索",
|
||||
noSearchResult: "未找到匹配的空间",
|
||||
noSearchableSpaces: "暂无开放可被搜索的空间,或输入关键词搜索",
|
||||
},
|
||||
invite: {
|
||||
loading: "加载中...",
|
||||
@@ -2399,6 +2405,7 @@ export default {
|
||||
requestRole: "申请角色",
|
||||
selectRole: "选择角色",
|
||||
messagePlaceholder: "选填:申请说明(如自我介绍或加入原因)",
|
||||
applicationNote: "申请说明(选填)",
|
||||
joinSuccess: "成功加入空间!",
|
||||
joinFailed: "加入失败,请稍后重试",
|
||||
requestSubmitted: "申请已提交,请等待管理员审核",
|
||||
@@ -2478,6 +2485,8 @@ export default {
|
||||
removeShareFailed: "移除失败,请重试",
|
||||
requireApproval: "需要审核",
|
||||
requireApprovalDesc: "开启后,新成员加入需要管理员审核",
|
||||
searchable: "开放可被搜索",
|
||||
searchableDesc: "开启后,空间将出现在「加入空间」的搜索列表中,他人可搜索并申请加入,无需邀请码",
|
||||
joinRequests: "加入申请",
|
||||
joinRequestsDesc: "审核待加入空间的申请",
|
||||
noPendingRequests: "暂无待审核的申请",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -162,6 +162,23 @@
|
||||
<span class="approval-desc">{{ $t('organization.settings.requireApprovalDesc') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="invite-divider"></div>
|
||||
|
||||
<!-- 开放可被搜索 -->
|
||||
<div class="invite-method">
|
||||
<div class="invite-method-header">
|
||||
<t-icon name="search" class="invite-icon" />
|
||||
<span class="invite-method-title">{{ $t('organization.settings.searchable') }}</span>
|
||||
</div>
|
||||
<div class="approval-toggle">
|
||||
<t-switch
|
||||
v-model="formData.searchable"
|
||||
@change="handleSearchableToggle"
|
||||
/>
|
||||
<span class="approval-desc">{{ $t('organization.settings.searchableDesc') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -655,6 +672,7 @@ const formData = ref({
|
||||
name: '',
|
||||
description: '',
|
||||
require_approval: false,
|
||||
searchable: false,
|
||||
invite_code_validity_days: 7 as number
|
||||
})
|
||||
|
||||
@@ -780,6 +798,7 @@ const fetchOrgDetail = async () => {
|
||||
name: res.data.name,
|
||||
description: res.data.description || '',
|
||||
require_approval: res.data.require_approval || false,
|
||||
searchable: res.data.searchable || false,
|
||||
invite_code_validity_days: typeof validity === 'number' ? validity : 7
|
||||
}
|
||||
inviteCode.value = res.data.invite_code || ''
|
||||
@@ -929,6 +948,7 @@ const handleSave = async () => {
|
||||
name: formData.value.name.trim(),
|
||||
description: formData.value.description.trim(),
|
||||
require_approval: formData.value.require_approval,
|
||||
searchable: formData.value.searchable,
|
||||
invite_code_validity_days: formData.value.invite_code_validity_days
|
||||
})
|
||||
if (res.success) {
|
||||
@@ -1139,6 +1159,25 @@ const handleApprovalToggle = async (value: boolean) => {
|
||||
}
|
||||
}
|
||||
|
||||
// 切换开放可被搜索时立即保存
|
||||
const handleSearchableToggle = async (value: boolean) => {
|
||||
if (!props.orgId) return
|
||||
try {
|
||||
const res = await updateOrganization(props.orgId, {
|
||||
searchable: value
|
||||
})
|
||||
if (res.success) {
|
||||
MessagePlugin.success(t('common.saveSuccess'))
|
||||
} else {
|
||||
formData.value.searchable = !value
|
||||
MessagePlugin.error(res.message || t('common.saveFailed'))
|
||||
}
|
||||
} catch (error: any) {
|
||||
formData.value.searchable = !value
|
||||
MessagePlugin.error(error?.message || t('common.saveFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
const handleShareClick = (share: KnowledgeBaseShare) => {
|
||||
handleClose()
|
||||
router.push(`/platform/knowledge-bases/${share.knowledge_base_id}`)
|
||||
@@ -1194,7 +1233,7 @@ watch(() => props.visible, (newVal) => {
|
||||
joinRequests.value = []
|
||||
if (props.mode === 'create') {
|
||||
// 创建模式:重置表单
|
||||
formData.value = { name: '', description: '', require_approval: false, invite_code_validity_days: 7 }
|
||||
formData.value = { name: '', description: '', require_approval: false, searchable: false, invite_code_validity_days: 7 }
|
||||
orgInfo.value = null
|
||||
members.value = []
|
||||
sharedKnowledgeBases.value = []
|
||||
|
||||
Reference in New Issue
Block a user