Skip to content

Commit

Permalink
Merge pull request #805 from ita-social-projects/Displays_categories_…
Browse files Browse the repository at this point in the history
…in_the_category_list_valerii

Displays categories in the category list valerii
  • Loading branch information
MementoMorj authored Sep 24, 2023
2 parents ff5577d + 9feeac9 commit 79f60a7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,32 @@ const ForFansModal = ({
const maxLength = character_limit || 10000;

const getAvailableCategories = async (isNewCat: boolean): Promise<SourceCategoryName[]> => {
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 = () => {
Expand Down Expand Up @@ -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();
Expand All @@ -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('Категорію успішно додано до списку!');
Expand All @@ -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 (
<Modal
Expand Down

0 comments on commit 79f60a7

Please sign in to comment.