Skip to content

Commit 4cb581e

Browse files
committed
refactor(namespaces): fix name conflict
1 parent e289b5e commit 4cb581e

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/hooks/use-namespace.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import axios from 'axios';
22
import { useEffect, useState } from 'react';
3+
import { useTranslation } from 'react-i18next';
34
import { useParams } from 'react-router-dom';
5+
import { toast } from 'sonner';
46

57
import { Namespace } from '@/interface';
68
import { 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
});

src/i18n/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
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",

src/i18n/locales/zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@
102102
"max": "最多 32 个字符",
103103
"submit": "保存",
104104
"success": "已更新",
105-
"member_count": "{{ size }} 名成员"
105+
"member_count": "{{ size }} 名成员",
106+
"conflict": "已有相同名称的空间"
106107
},
107108
"login": {
108109
"product_name": "小黑",

src/page/sidebar/switcher/form/namespace.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import i18next from 'i18next';
33
import { useState } from 'react';
44
import { useForm } from 'react-hook-form';
55
import { useTranslation } from 'react-i18next';
6+
import { toast } from 'sonner';
67
import * as z from 'zod';
78

89
import { 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
});

0 commit comments

Comments
 (0)