File tree Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Original file line number Diff line number Diff line change 11import axios from 'axios' ;
22import { useEffect , useState } from 'react' ;
3+ import { useTranslation } from 'react-i18next' ;
34import { useParams } from 'react-router-dom' ;
5+ import { toast } from 'sonner' ;
46
57import { Namespace } from '@/interface' ;
68import { http } from '@/lib/request' ;
@@ -12,6 +14,7 @@ export default function useNamespace() {
1214 const params = useParams ( ) ;
1315 const namespace_id = params . namespace_id ;
1416 const [ loading , onLoading ] = useState ( false ) ;
17+ const { t } = useTranslation ( ) ;
1518 const [ data , onData ] = useState < Namespace > ( {
1619 id : '' ,
1720 name : '' ,
@@ -43,6 +46,12 @@ export default function useNamespace() {
4346 onData ( { ...data , ...val } ) ;
4447 return Promise . resolve ( ) ;
4548 } )
49+ . catch ( err => {
50+ if ( err ?. response ?. data ?. code === 'namespace_conflict' ) {
51+ toast . error ( t ( 'namespace.conflict' ) ) ;
52+ }
53+ return Promise . reject ( err ) ;
54+ } )
4655 . finally ( ( ) => {
4756 onLoading ( false ) ;
4857 } ) ;
Original file line number Diff line number Diff line change 102102 "max" : " At most 32 characters" ,
103103 "submit" : " Save" ,
104104 "success" : " Updated" ,
105- "member_count" : " {{ size }} members"
105+ "member_count" : " {{ size }} members" ,
106+ "conflict" : " There's already a namespace with the same name"
106107 },
107108 "login" : {
108109 "product_name" : " OmniBox" ,
Original file line number Diff line number Diff line change 102102 "max" : " 最多 32 个字符" ,
103103 "submit" : " 保存" ,
104104 "success" : " 已更新" ,
105- "member_count" : " {{ size }} 名成员"
105+ "member_count" : " {{ size }} 名成员" ,
106+ "conflict" : " 已有相同名称的空间"
106107 },
107108 "login" : {
108109 "product_name" : " 小黑" ,
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import i18next from 'i18next';
33import { useState } from 'react' ;
44import { useForm } from 'react-hook-form' ;
55import { useTranslation } from 'react-i18next' ;
6+ import { toast } from 'sonner' ;
67import * as z from 'zod' ;
78
89import { Button } from '@/components/button' ;
@@ -42,6 +43,11 @@ export default function GenerateForm() {
4243 . then ( data => {
4344 location . href = `/${ data . id } /chat` ;
4445 } )
46+ . catch ( err => {
47+ if ( err ?. response ?. data ?. code === 'namespace_conflict' ) {
48+ toast . error ( t ( 'namespace.conflict' ) ) ;
49+ }
50+ } )
4551 . finally ( ( ) => {
4652 setLoading ( false ) ;
4753 } ) ;
You can’t perform that action at this time.
0 commit comments