-
Notifications
You must be signed in to change notification settings - Fork 0
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
80330ce
commit 75b5e36
Showing
25 changed files
with
408 additions
and
410 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client'; | ||
|
||
import { ShopPage } from '@/views'; | ||
import { FC } from 'react'; | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,12 +1,29 @@ | ||
import { Card } from '@nextui-org/react'; | ||
import { getProductData } from './model/selector/getProductData/getProductData'; | ||
import { getProductError } from './model/selector/getProductError/getProductError'; | ||
import { getProductIsLoading } from './model/selector/getProductIsLoading/getProductIsLoading'; | ||
import { | ||
MarketType, | ||
MarketsProductData, | ||
ProductDataProps, | ||
Product, | ||
ProductState, | ||
} from './model/types/product'; | ||
import { CardWide } from './ui/CardWide/CardWide'; | ||
import { Cards, CardsProps } from './ui/Cards/Cards'; | ||
|
||
export { Card, CardWide, Cards }; | ||
export { | ||
Card, | ||
CardWide, | ||
Cards, | ||
getProductData, | ||
getProductError, | ||
getProductIsLoading, | ||
}; | ||
|
||
export type { CardsProps, MarketType, MarketsProductData, ProductDataProps }; | ||
export type { | ||
CardsProps, | ||
MarketType, | ||
MarketsProductData, | ||
Product, | ||
ProductState, | ||
}; |
3 changes: 3 additions & 0 deletions
3
src/entities/Product/model/selector/getProductData/getProductData.ts
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 { RootState } from '@/app/providers/StoreProvider'; | ||
|
||
export const getProductData = (state: RootState) => state.product?.data; |
3 changes: 3 additions & 0 deletions
3
src/entities/Product/model/selector/getProductError/getProductError.ts
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 { RootState } from '@/app/providers/StoreProvider'; | ||
|
||
export const getProductError = (state: RootState) => state.product?.error; |
4 changes: 4 additions & 0 deletions
4
src/entities/Product/model/selector/getProductIsLoading/getProductIsLoading.ts
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/StoreProvider'; | ||
|
||
export const getProductIsLoading = (state: RootState) => | ||
state.product?.isLoading; |
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 @@ | ||
import { ThunkConfig } from '@/app/providers/StoreProvider'; | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
import { Product } from '../..'; | ||
|
||
export const fetchProductData = createAsyncThunk< | ||
Product[], | ||
void, | ||
ThunkConfig<string> | ||
>('products/fetchProductData', async (_, thunkAPI) => { | ||
try { | ||
const response = await thunkAPI.extra.api.get<Product[]>('/products'); | ||
|
||
return response.data; | ||
} catch (e) { | ||
console.log(e); | ||
return thunkAPI.rejectWithValue('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,38 @@ | ||
import type { PayloadAction } from '@reduxjs/toolkit'; | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
import { fetchProductData } from '../services/fetchProductData'; | ||
import { Product, ProductState } from '../types/product'; | ||
|
||
export const productInitialState: ProductState = { | ||
readonly: true, | ||
isLoading: false, | ||
error: undefined, | ||
data: undefined, | ||
}; | ||
|
||
export const productSlice = createSlice({ | ||
name: 'product', | ||
initialState: productInitialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder | ||
.addCase(fetchProductData.pending, (state) => { | ||
state.error = undefined; | ||
state.isLoading = true; | ||
}) | ||
.addCase( | ||
fetchProductData.fulfilled, | ||
(state, action: PayloadAction<Product[]>) => { | ||
state.isLoading = false; | ||
state.data = action.payload; | ||
}, | ||
) | ||
.addCase(fetchProductData.rejected, (state, action) => { | ||
state.isLoading = false; | ||
state.error = action.payload; | ||
}); | ||
}, | ||
}); | ||
|
||
export const { actions: productActions } = productSlice; | ||
export const { reducer: productReducer } = productSlice; |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { loginByUsername } from './model/service/loginByUsername/loginByUsername'; | ||
import { loginByEmail } from './model/service/loginByEmail/loginByEmail'; | ||
import { loginActions, loginReducer } from './model/slice/loginSlice'; | ||
import { LoginState } from './model/types/loginState'; | ||
import ModalLogin from './ui/ModalLogin/ModalLogin'; | ||
import ModalLogin from './ui/ModalLogin/ModalAuth'; | ||
|
||
export { ModalLogin, loginActions, loginByUsername, loginReducer }; | ||
export { ModalLogin, loginActions, loginByEmail, loginReducer }; | ||
export type { LoginState }; |
41 changes: 41 additions & 0 deletions
41
src/features/Auth/model/service/loginByEmail/loginByEmail.test.ts
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,41 @@ | ||
// import { User, userActions } from '@/entities/User'; | ||
// import { TestAsyncThunk } from '@/shared/lib/tests'; | ||
// import { loginByEmail } from './loginByEmail'; | ||
|
||
// describe('loginByUsername.test', () => { | ||
// test('success login', async () => { | ||
// const userValue: User = { | ||
// id: 1, | ||
// email: 'markus@e.com', | ||
// }; | ||
|
||
// const thunk = new TestAsyncThunk(loginByEmail); | ||
// thunk.api.post.mockReturnValue(Promise.resolve({ data: userValue })); | ||
// const result = await thunk.callThunk({ | ||
// email: 'markus@e.com', | ||
// password: 'pass', | ||
// }); | ||
|
||
// expect(thunk.dispatch).toHaveBeenCalledWith( | ||
// userActions.setAuthData(userValue), | ||
// ); | ||
// expect(thunk.dispatch).toHaveBeenCalledTimes(3); | ||
// expect(thunk.api.post).toHaveBeenCalled(); | ||
// expect(result.meta.requestStatus).toBe('fulfilled'); | ||
// expect(result.payload).toEqual(userValue); | ||
// }); | ||
|
||
// test('error login', async () => { | ||
// const thunk = new TestAsyncThunk(loginByEmail); | ||
// thunk.api.post.mockReturnValue(Promise.resolve({ status: 403 })); | ||
// const result = await thunk.callThunk({ | ||
// password: 'pass', | ||
// username: 'MarkMelior', | ||
// }); | ||
|
||
// expect(thunk.dispatch).toHaveBeenCalledTimes(2); | ||
// expect(thunk.api.post).toHaveBeenCalled(); | ||
// expect(result.meta.requestStatus).toBe('rejected'); | ||
// expect(result.payload).toBe('Вы ввели неверную почту или пароль'); | ||
// }); | ||
// }); |
Oops, something went wrong.