From bbda046734845f55d9d441a238872060145c0e35 Mon Sep 17 00:00:00 2001 From: ValDekh Date: Thu, 21 Sep 2023 23:58:33 +0300 Subject: [PATCH] Some changes --- .../ForFansPage/ForFansMainPage.component.tsx | 2 +- .../ForFansAdminModal.component.tsx | 56 ++++++++++--------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/features/AdminPage/ForFansPage/ForFansMainPage.component.tsx b/src/features/AdminPage/ForFansPage/ForFansMainPage.component.tsx index 441d98b2e..d2387ef32 100644 --- a/src/features/AdminPage/ForFansPage/ForFansMainPage.component.tsx +++ b/src/features/AdminPage/ForFansPage/ForFansMainPage.component.tsx @@ -128,7 +128,7 @@ const ForFansMainPage: React.FC = observer(() => { pagination={{ pageSize: 10 }} className="partners-table" columns={columns} - dataSource={sourcesStore?.getSrcCategoriesArray} + dataSource={sourcesStore?.getSrcCategoriesArray} rowKey="id" /> diff --git a/src/features/AdminPage/NewStreetcode/ForFansBlock/ForFansAdminModal/ForFansAdminModal.component.tsx b/src/features/AdminPage/NewStreetcode/ForFansBlock/ForFansAdminModal/ForFansAdminModal.component.tsx index 5afb07dc6..a65e1f59e 100644 --- a/src/features/AdminPage/NewStreetcode/ForFansBlock/ForFansAdminModal/ForFansAdminModal.component.tsx +++ b/src/features/AdminPage/NewStreetcode/ForFansBlock/ForFansAdminModal/ForFansAdminModal.component.tsx @@ -45,28 +45,32 @@ const ForFansModal = ({ const maxLength = character_limit || 10000; const getAvailableCategories = async (isNewCat: boolean): Promise => { - const categories = await SourcesApi.getAllCategories(); - sourcesAdminStore.setInternalSourceCategories(categories); + try { + const categories = await SourcesApi.getAllCategories(); + sourcesAdminStore.setInternalSourceCategories(categories); - const sourceMas: SourceCategoryName[] = categories.map((x) => ({ - id: x.id ?? 0, - title: x.title, - })); - const justAddedCategory = sourceMas[sourceMas.length - 1] - const selected = sourceCreateUpdateStreetcode.streetcodeCategoryContents - .filter((srcCatContent) => srcCatContent.sourceLinkCategoryId - && (srcCatContent as StreetcodeCategoryContentUpdate).modelState !== ModelState.Deleted); + const sourceMas: SourceCategoryName[] = categories.map((x) => ({ + id: x.id ?? 0, + title: x.title, + })); + const justAddedCategory = sourceMas[sourceMas.length - 1]; + const selected = sourceCreateUpdateStreetcode.streetcodeCategoryContents + .filter((srcCatContent) => srcCatContent.sourceLinkCategoryId + && (srcCatContent as StreetcodeCategoryContentUpdate).modelState !== ModelState.Deleted); - const selected_Ids = selected.map((srcCatContent) => srcCatContent.sourceLinkCategoryId); - const available = allCategories.filter((c) => !selected_Ids.includes(c.id)); - if (categoryUpdate.current) { - available.push(allCategories[allCategories.findIndex((c) => c.id === categoryUpdate - .current?.sourceLinkCategoryId)]); - } - if (isNewCat){ - available.push(justAddedCategory); + const selectedIds = selected.map((srcCatContent) => srcCatContent.sourceLinkCategoryId); + const available = allCategories.filter((c) => !selectedIds.includes(c.id)); + if (categoryUpdate.current) { + // eslint-disable-next-line max-len + available.push(allCategories[allCategories.findIndex((c) => c.id === categoryUpdate.current?.sourceLinkCategoryId)]); + } + if (isNewCat) { + available.push(justAddedCategory); + } + return available; + } catch (error) { + console.error('Error fetching categories:', error); } - return available; }; const clearModal = () => { @@ -112,14 +116,14 @@ const ForFansModal = ({ streetcodeId: categoryUpdate.current?.streetcodeId ?? 0, }); } - //setOpen(false); + // setOpen(false); sourceCreateUpdateStreetcode.indexUpdate = -1; onChange('saved', null); }; const handleOk = () => { form.submit(); alert('Категорію для фанатів успішно додано!'); - } + }; const onDropDownChange = async () => { if (isAddModalVisible === false) { const categories = await SourcesApi.getAllCategories(); @@ -132,9 +136,9 @@ const ForFansModal = ({ setCategories(sourceMas); } - } + }; const onUpdateStates = async (isNewCatAdded: boolean) => { - if(isNewCatAdded === true) { + if (isNewCatAdded === true) { const AvailableCats = await getAvailableCategories(true); setAvailableCategories(AvailableCats); alert('Категорію успішно додано до списку!'); @@ -147,10 +151,8 @@ const ForFansModal = ({ form.resetFields(['category']); } }; - - const handleDisabled = (categoryId: number) => { - return !availableCategories.some(c => c.id === categoryId); - }; + + const handleDisabled = (categoryId: number) => !availableCategories.some((c) => c.id === categoryId); return (