AURORA-1671: добавленна отображения ошибки crm_id_exists напрямую в форму

This commit is contained in:
Grog 2026-10-26 14:11:48 +03:00
parent 633c4d3fed
commit daec128fc3
7 changed files with 63 additions and 104 deletions

View File

@ -1,7 +1,6 @@
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import { Button, Space } from 'antd'; import { Button, Space } from 'antd';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { ApiError } from '../api/client';
import PageTitle from '../components/PageTitle'; import PageTitle from '../components/PageTitle';
import { createCatalogueJur } from '../services/api/directories/catalogue_jur'; import { createCatalogueJur } from '../services/api/directories/catalogue_jur';
import { createCompanyGroup, fetchRelatedGroups } from '../services/api/directories/company_groups'; import { createCompanyGroup, fetchRelatedGroups } from '../services/api/directories/company_groups';
@ -13,7 +12,6 @@ import type { RelatedGroupOut } from '../types/api';
import type { CatalogueJurFormProps } from '../types/catalogueJur/catalogueJur'; import type { CatalogueJurFormProps } from '../types/catalogueJur/catalogueJur';
import type { CreateCompanyGroupProps } from '../types/companyGroups/companyGroups'; import type { CreateCompanyGroupProps } from '../types/companyGroups/companyGroups';
import type { CreateEntityKind, RelatedGroupFormType } from '../types/relatedGroup/relatedGroup'; import type { CreateEntityKind, RelatedGroupFormType } from '../types/relatedGroup/relatedGroup';
import { useNotificationApi } from '../utils/useNotification';
import { CataloguGroupTabs, type CatalogueGroupTabKey } from '../widgets/CataloguGroupTabs/CataloguGroupTabs'; import { CataloguGroupTabs, type CatalogueGroupTabKey } from '../widgets/CataloguGroupTabs/CataloguGroupTabs';
import { CompanyGroupHeader } from '../widgets/CatalogueGroupHeader/CatalogueGroupHeader'; import { CompanyGroupHeader } from '../widgets/CatalogueGroupHeader/CatalogueGroupHeader';
import { CatalogueJurForm } from '../widgets/CatalogueJurForm/CatalogueJurForm'; import { CatalogueJurForm } from '../widgets/CatalogueJurForm/CatalogueJurForm';
@ -26,7 +24,6 @@ import { RelatedGroupTable } from '../widgets/RelatedGroupTable/RelatedGroupTabl
export function CatalogueGroup() { export function CatalogueGroup() {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const notification = useNotificationApi();
const isGettingArchive = useAppSelector((state) => state.catalogue_jur.isGettingArchive); const isGettingArchive = useAppSelector((state) => state.catalogue_jur.isGettingArchive);
@ -53,57 +50,32 @@ export function CatalogueGroup() {
} }
async function createRelatedGroupHandler(values: RelatedGroupFormType) { async function createRelatedGroupHandler(values: RelatedGroupFormType) {
if (values.company_group_id) { if (values.company_group_id) {
try {
await createRelatedGroup(values.company_group_id, { await createRelatedGroup(values.company_group_id, {
...values, ...values,
company_group_id: undefined, company_group_id: undefined,
}); });
getRelatedGroupsHandler(); getRelatedGroupsHandler();
setKindForm(null); setKindForm(null);
} catch (e) {
if (e instanceof ApiError) {
notification.error({
description: e.message,
});
}
}
} }
} }
async function createCompanyGroupHandler(values: CreateCompanyGroupProps) { async function createCompanyGroupHandler(values: CreateCompanyGroupProps) {
try {
await createCompanyGroup(values); await createCompanyGroup(values);
dispatch(getCompanyGroupsThunk()); dispatch(getCompanyGroupsThunk());
getRelatedGroupsHandler(); getRelatedGroupsHandler();
setKindForm(null); setKindForm(null);
} catch (e) {
if (e instanceof ApiError) {
notification.error({
description: e.message,
});
}
}
} }
async function getRelatedGroupsHandler() { async function getRelatedGroupsHandler() {
if (activeCompanyGroup?.id) { if (activeCompanyGroup?.id) {
setRelatedGroupLoading(true); setRelatedGroupLoading(true);
try {
const res = await fetchRelatedGroups(activeCompanyGroup?.id); const res = await fetchRelatedGroups(activeCompanyGroup?.id);
const gsks = res.filter((elem) => elem.kind === 'gsk'); const gsks = res.filter((elem) => elem.kind === 'gsk');
const gszs = res.filter((elem) => elem.kind === 'gsz'); const gszs = res.filter((elem) => elem.kind === 'gsz');
setGskData(gsks); setGskData(gsks);
setGszData(gszs); setGszData(gszs);
} catch (e) {
if (e instanceof ApiError) {
notification.error({
description: e.message,
});
}
} finally {
setRelatedGroupLoading(false); setRelatedGroupLoading(false);
} }
} }
}
useEffect(() => { useEffect(() => {
getRelatedGroupsHandler(); getRelatedGroupsHandler();
@ -197,9 +169,7 @@ export function CatalogueGroup() {
onCancel={() => { onCancel={() => {
setKindForm(null); setKindForm(null);
}} }}
onOk={async (values) => { onOk={createRelatedGroupHandler}
await createRelatedGroupHandler(values);
}}
/> />
)} )}
{kindForm === 'gk' && ( {kindForm === 'gk' && (
@ -208,9 +178,7 @@ export function CatalogueGroup() {
onCancel={() => { onCancel={() => {
setKindForm(null); setKindForm(null);
}} }}
onOk={async (values) => { onOk={createCompanyGroupHandler}
await createCompanyGroupHandler(values);
}}
/> />
)} )}
</div> </div>

View File

@ -1,26 +1,22 @@
import { PlusOutlined } from '@ant-design/icons'; import { PlusOutlined } from '@ant-design/icons';
import { Button, Space } from 'antd'; import { Button, Space } from 'antd';
import { useState } from 'react'; import { useState } from 'react';
import { ApiError } from '../api/client';
import PageTitle from '../components/PageTitle'; import PageTitle from '../components/PageTitle';
import { createCatalogueJur } from '../services/api/directories/catalogue_jur'; import { createCatalogueJur } from '../services/api/directories/catalogue_jur';
import { getCatalogueJurThunk } from '../store/slices/catalogueJurSlice/thunks'; import { getCatalogueJurThunk } from '../store/slices/catalogueJurSlice/thunks';
import { useAppDispatch, useAppSelector } from '../store/store'; import { useAppDispatch, useAppSelector } from '../store/store';
import type { CatalogueJurFormProps } from '../types/catalogueJur/catalogueJur'; import type { CatalogueJurFormProps } from '../types/catalogueJur/catalogueJur';
import { useNotificationApi } from '../utils/useNotification';
import { CatalogueJurForm } from '../widgets/CatalogueJurForm/CatalogueJurForm'; import { CatalogueJurForm } from '../widgets/CatalogueJurForm/CatalogueJurForm';
import { CatalogueJurTable } from '../widgets/CatalogueJurTable/CatalogueJurTable'; import { CatalogueJurTable } from '../widgets/CatalogueJurTable/CatalogueJurTable';
export function CatalogueJur() { export function CatalogueJur() {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const notification = useNotificationApi();
const isGettingArchive = useAppSelector((state) => state.catalogue_jur.isGettingArchive); const isGettingArchive = useAppSelector((state) => state.catalogue_jur.isGettingArchive);
const [createFormOpen, setCreateFormOpen] = useState(false); const [createFormOpen, setCreateFormOpen] = useState(false);
const outside_group = true; const outside_group = true;
async function createJurHandler(values: CatalogueJurFormProps) { async function createJurHandler(values: CatalogueJurFormProps) {
try {
await createCatalogueJur(values); await createCatalogueJur(values);
dispatch( dispatch(
getCatalogueJurThunk({ getCatalogueJurThunk({
@ -29,13 +25,6 @@ export function CatalogueJur() {
}), }),
); );
setCreateFormOpen(false); setCreateFormOpen(false);
} catch (e) {
if (e instanceof ApiError) {
notification.error({
description: e.message,
});
}
}
} }
return ( return (
@ -59,9 +48,7 @@ export function CatalogueJur() {
onCancel={() => { onCancel={() => {
setCreateFormOpen(false); setCreateFormOpen(false);
}} }}
onOk={async (values) => { onOk={createJurHandler}
await createJurHandler(values);
}}
/> />
)} )}
</div> </div>

View File

@ -124,6 +124,14 @@ export const CatalogueJurForm: React.FC<Props> = ({ open, onCancel, onOk, jurId
}, },
]); ]);
} }
if (e.code === 'CRM_ID_EXISTS') {
form.setFields([
{
name: 'crm_id',
errors: [e.message],
},
]);
}
notification.error({ description: e.message }); notification.error({ description: e.message });
} }
} finally { } finally {

View File

@ -122,17 +122,9 @@ export function CatalogueJurTable({ outside_group, tabsComponent }: CatalogueJur
} }
async function editJurHandler(values: CatalogueJurFormProps) { async function editJurHandler(values: CatalogueJurFormProps) {
try {
await editCatalogueJur(jurId, values); await editCatalogueJur(jurId, values);
getCatalogueJur(); getCatalogueJur();
closeEditCatalogueJurHandler(); closeEditCatalogueJurHandler();
} catch (e) {
if (e instanceof ApiError) {
notification.error({
description: e.message,
});
}
}
} }
useEffect(() => { useEffect(() => {
@ -327,9 +319,7 @@ export function CatalogueJurTable({ outside_group, tabsComponent }: CatalogueJur
onCancel={() => { onCancel={() => {
closeEditCatalogueJurHandler(); closeEditCatalogueJurHandler();
}} }}
onOk={async (values) => { onOk={editJurHandler}
await editJurHandler(values);
}}
/> />
)} )}
</div> </div>

View File

@ -49,6 +49,14 @@ export const CompanyGroupForm: React.FC<Props> = ({ open, onCancel, onOk }) => {
}); });
} catch (e) { } catch (e) {
if (e instanceof ApiError) { if (e instanceof ApiError) {
if (e.code === 'CRM_ID_EXISTS') {
form.setFields([
{
name: 'crm_id',
errors: [e.message],
},
]);
}
notification.error({ notification.error({
description: e.message, description: e.message,
}); });

View File

@ -67,6 +67,14 @@ export const RelatedGroupForm: React.FC<Props> = ({ open, onCancel, onOk, relate
}); });
} catch (e) { } catch (e) {
if (e instanceof ApiError) { if (e instanceof ApiError) {
if (e.code === 'CRM_ID_EXISTS') {
form.setFields([
{
name: 'crm_id',
errors: [e.message],
},
]);
}
notification.error({ notification.error({
description: e.message, description: e.message,
}); });

View File

@ -62,17 +62,9 @@ export function RelatedGroupTable({ tabsComponent, data, loading, getData, activ
} }
async function editRelatedGroupHandler(values: RelatedGroupFormType) { async function editRelatedGroupHandler(values: RelatedGroupFormType) {
try {
await editRelatedGroup(groupId, values); await editRelatedGroup(groupId, values);
getData(); getData();
closeEditRelatedGroupHandler(); closeEditRelatedGroupHandler();
} catch (e) {
if (e instanceof ApiError) {
notification.error({
description: e.message,
});
}
}
} }
const extraColumns: ColumnsType<RelatedGroupOut> = useMemo( const extraColumns: ColumnsType<RelatedGroupOut> = useMemo(
@ -167,9 +159,7 @@ export function RelatedGroupTable({ tabsComponent, data, loading, getData, activ
onCancel={() => { onCancel={() => {
closeEditRelatedGroupHandler(); closeEditRelatedGroupHandler();
}} }}
onOk={async (values) => { onOk={editRelatedGroupHandler}
await editRelatedGroupHandler(values);
}}
/> />
)} )}
{deleteModalOpen && ( {deleteModalOpen && (