-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api: Получение категорий для компонента Header #183
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
8710beb
api: Получение категорий для компонента Header
Segodnya a463246
refactor: fix code review issues - AsyncThunk, widgets, stories
Segodnya 4cb4bd5
refactor: fix code review issues - add API instance usage, error hand…
Segodnya 6d47733
Merge branch 'master' into api/header-categories-#158
Segodnya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { RootState } from '@/app/providers/SroreProvider/config/store' | ||
|
||
export const selectCategories = (state: RootState) => state.category.categories | ||
export const selectDisplayedCategories = (state: RootState) => state.category.displayedCategories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit' | ||
import { ApiError, ApiErrorTypes, ApiRoutes } from '@/shared/api/types' | ||
import { ThunkConfig } from '@/app/providers/SroreProvider/config/StateSchema' | ||
import { Category, CategorySchema } from '../types/types' | ||
import { apiErrorIdentify } from '@/shared/api/apiErrorIdentify' | ||
import { rejectedPayloadHandle } from '@/shared/api/rejectedPayloadHandle' | ||
|
||
const initialState: CategorySchema = { | ||
categories: [], | ||
displayedCategories: [], | ||
error: undefined | ||
} | ||
|
||
export const fetchCategories = createAsyncThunk<Category[], void, ThunkConfig<ApiError>>( | ||
'category/fetchCategories', | ||
async (_, thunkAPI) => { | ||
const { rejectWithValue, extra } = thunkAPI | ||
|
||
try { | ||
const response = await extra.api.get(`api/${ApiRoutes.CATEGORIES}`) | ||
return response.data as Category[] | ||
} catch (error) { | ||
return rejectWithValue(apiErrorIdentify(error, ApiErrorTypes.AUTH_ERROR)) | ||
} | ||
} | ||
) | ||
|
||
const categorySlice = createSlice({ | ||
name: 'category', | ||
initialState, | ||
reducers: {}, | ||
extraReducers: builder => { | ||
builder | ||
.addCase(fetchCategories.pending, state => { | ||
state.error = undefined | ||
}) | ||
.addCase(fetchCategories.fulfilled, (state, action) => { | ||
state.categories = action.payload | ||
state.displayedCategories = action.payload.filter((c: Category) => c.is_visible_on_main === true) | ||
}) | ||
.addCase(fetchCategories.rejected, (state, { payload }) => { | ||
state.error = rejectedPayloadHandle(payload) | ||
}) | ||
} | ||
}) | ||
|
||
export default categorySlice.reducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export interface CategorySchema { | ||
categories: Category[] | ||
displayedCategories: Category[] | ||
error?: string | string[] | ||
} | ||
|
||
export interface Category { | ||
id?: number | ||
name: string | ||
slug: string | ||
branches?: Category[] | ||
root?: Category | ||
is_prohibited?: boolean | ||
is_visible_on_main?: boolean | ||
image?: string | ||
type?: 'category' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
@use '../../shared/styles/utils/variables' as var; | ||
|
||
.link { | ||
color: var.$body-color; | ||
text-decoration: none; | ||
white-space: nowrap; | ||
|
||
&:hover { | ||
color: var.$theme-secondary-color; | ||
} | ||
} | ||
|
||
.li { | ||
margin: 0; | ||
padding: 0; | ||
font-weight: 400; | ||
font-size: 13px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// CatalogNodeItem.stories.tsx | ||
import { Meta, StoryObj } from '@storybook/react' | ||
import CatalogNodeItem from './CatalogNodeItem' | ||
|
||
const meta = { | ||
title: 'widgets/CatalogNodeItem', | ||
component: CatalogNodeItem, | ||
parameters: { | ||
layout: 'centered' | ||
} | ||
} as Meta<typeof CatalogNodeItem> | ||
|
||
export default meta | ||
|
||
type Story = StoryObj<typeof meta> | ||
|
||
export const Default: Story = { | ||
args: { | ||
slug: 'category-slug', | ||
name: 'Category Name' | ||
} | ||
} | ||
|
||
export const CustomCategory: Story = { | ||
args: { | ||
slug: 'custom-slug', | ||
name: 'Custom Category' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Category } from '@/entities/Category/types/types' | ||
import { Routes } from '@/shared/config/routerConfig/routes' | ||
import Link from '@/shared/ui/Link/Link' | ||
import styles from './CatalogNodeItem.module.scss' | ||
|
||
/** | ||
* Компонент ссылки на раздел каталога для выпадающего списка меню "Все категории" | ||
*/ | ||
const CatalogNodeItem = ({ slug, name }: Category) => { | ||
return ( | ||
<li className={styles.li}> | ||
<Link to={`${Routes.CATEGORIES}/${slug}`} className={styles.link}> | ||
{name} | ||
</Link> | ||
</li> | ||
) | ||
} | ||
|
||
export default CatalogNodeItem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@use '../../shared/styles/utils/variables' as var; | ||
|
||
.li { | ||
margin: 0; | ||
padding: 0; | ||
font-weight: 600; | ||
font-size: 13px; | ||
color: var.$white; | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.link { | ||
color: var.$white; | ||
text-decoration: none; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я думал header уже переделан по fsd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#156
Еще в работе