Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/hooks/use-namespace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import axios from 'axios';
import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
import { toast } from 'sonner';

import { Namespace } from '@/interface';
import { http } from '@/lib/request';
Expand All @@ -12,6 +14,7 @@ export default function useNamespace() {
const params = useParams();
const namespace_id = params.namespace_id;
const [loading, onLoading] = useState(false);
const { t } = useTranslation();
const [data, onData] = useState<Namespace>({
id: '',
name: '',
Expand Down Expand Up @@ -43,6 +46,12 @@ export default function useNamespace() {
onData({ ...data, ...val });
return Promise.resolve();
})
.catch(err => {
if (err?.response?.data?.code === 'namespace_conflict') {
toast.error(t('namespace.conflict'));
}
return Promise.reject(err);
})
.finally(() => {
onLoading(false);
});
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
"max": "At most 32 characters",
"submit": "Save",
"success": "Updated",
"member_count": "{{ size }} members"
"member_count": "{{ size }} members",
"conflict": "There's already a namespace with the same name"
},
"login": {
"product_name": "OmniBox",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@
"max": "最多 32 个字符",
"submit": "保存",
"success": "已更新",
"member_count": "{{ size }} 名成员"
"member_count": "{{ size }} 名成员",
"conflict": "已有相同名称的空间"
},
"login": {
"product_name": "小黑",
Expand Down
6 changes: 6 additions & 0 deletions src/page/sidebar/switcher/form/namespace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import i18next from 'i18next';
import { useState } from 'react';
import { useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { toast } from 'sonner';
import * as z from 'zod';

import { Button } from '@/components/button';
Expand Down Expand Up @@ -42,6 +43,11 @@ export default function GenerateForm() {
.then(data => {
location.href = `/${data.id}/chat`;
})
.catch(err => {
if (err?.response?.data?.code === 'namespace_conflict') {
toast.error(t('namespace.conflict'));
}
})
.finally(() => {
setLoading(false);
});
Expand Down
Loading