-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec816fb
commit 9f306e9
Showing
8 changed files
with
121 additions
and
9 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { StateSchema } from '@/app/providers/StoreProvider' | ||
|
||
export const getCoreBaseFooterSelector = (state: StateSchema) => state.coreBaseFooter |
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,23 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit' | ||
|
||
import { ThunkConfig } from '@/app/providers/StoreProvider/config/StateSchema' | ||
import { apiErrorIdentify } from '@/shared/api/apiErrorIdentify' | ||
import { ApiError, ApiErrorTypes, ApiRoutes } from '@/shared/api/types' | ||
|
||
import { CoreBaseFooterData } from '../types/types' | ||
|
||
export const getCoreBase = createAsyncThunk<CoreBaseFooterData, void, ThunkConfig<ApiError>>( | ||
//void1- выходные данные, void2- входные данные , thunkConfig- тип store | ||
'core/base', // action type, первый аргумент | ||
async (_, thunkAPI) => { | ||
// второй аргумент- асинхронная функция , кот вызовет dispatch в компоненте | ||
const { rejectWithValue, extra } = thunkAPI | ||
try { | ||
const response = await extra.api.get(`api/${ApiRoutes.CORE_BASE}`) | ||
|
||
return response.data.footer as CoreBaseFooterData | ||
} catch (error) { | ||
return rejectWithValue(apiErrorIdentify(error, ApiErrorTypes.DATA_EMPTY_ERROR)) | ||
} | ||
} | ||
) |
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,45 @@ | ||
import { createSlice } from '@reduxjs/toolkit' | ||
|
||
import { rejectedPayloadHandle } from '@/shared/api/rejectedPayloadHandle' | ||
|
||
import { getCoreBase } from '../services/getCoreBase' | ||
import { CoreBaseFooterSchema } from '../types/types' | ||
|
||
const initialState: CoreBaseFooterSchema = { | ||
footer: { | ||
company_info: '', | ||
disclaimer: '', | ||
support_work_time: '', | ||
main_logo: { | ||
image: '', | ||
url: '', | ||
title: '' | ||
}, | ||
additional_logos: [], | ||
support: { | ||
callback: '', | ||
phone_number: '' | ||
} | ||
}, | ||
error: undefined | ||
} | ||
|
||
const footerSlice = createSlice({ | ||
name: 'footer', | ||
initialState, | ||
reducers: {}, | ||
extraReducers: builder => { | ||
builder | ||
.addCase(getCoreBase.pending, state => { | ||
state.error = undefined | ||
}) | ||
.addCase(getCoreBase.fulfilled, (state, { payload }) => { | ||
state.footer = payload | ||
}) | ||
.addCase(getCoreBase.rejected, (state, { payload }) => { | ||
state.error = rejectedPayloadHandle(payload) | ||
}) | ||
} | ||
}) | ||
|
||
export default footerSlice.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,24 @@ | ||
interface Logo { | ||
image: string | ||
url: string | ||
title: string | ||
} | ||
|
||
interface Support { | ||
callback: string | ||
phone_number: string | ||
} | ||
|
||
export interface CoreBaseFooterData { | ||
company_info: string | ||
disclaimer: string | ||
support_work_time: string | ||
main_logo: Logo | ||
additional_logos: Logo[] | ||
support: Support | ||
} | ||
|
||
export interface CoreBaseFooterSchema { | ||
footer: CoreBaseFooterData | ||
error?: string | string[] | ||
} |