-
Notifications
You must be signed in to change notification settings - Fork 106
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
Иван Лайер
committed
Oct 29, 2024
1 parent
3b2499e
commit 559942b
Showing
11 changed files
with
163 additions
and
29 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
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,29 @@ | ||
import { call, put } from "redux-saga/effects"; | ||
import { isTErrorResponse, TServerError } from "../../../shared/fetchHelpers/typeGuards"; | ||
import { createAction } from "@reduxjs/toolkit"; | ||
import { UNKNOWN_ERROR_MESSAGE } from "./constant"; | ||
import { Category, Product, TAddProductParams, TUpdateProductParams } from "../../../entities/ViewProductList/model/types/types"; | ||
import { addProductApi, putProductApi } from "../../../entities/ViewProductList/api/request"; | ||
import { setError, cleanProductList } from "../productSlice"; | ||
import { productGet } from "./getProductSaga"; | ||
|
||
// Saga Effects. Add product | ||
export function* addProductSaga(data: { type: string, payload: TAddProductParams }): any { | ||
try { | ||
yield addProductApi(data.payload); | ||
yield put(cleanProductList()) | ||
yield call(productGet, { pageSize: 10, pageNumber: 1, sorting: { type: 'ASC', field: 'id' } }); | ||
} catch (error: unknown) { | ||
if (isTErrorResponse(error)) { | ||
let allErrors = ""; | ||
error.response.data.errors.forEach((e: TServerError) => allErrors += e.message); | ||
|
||
yield put(setError({ isError: true, errorMessage: allErrors })) | ||
} else { | ||
yield put(setError({ isError: true, errorMessage: UNKNOWN_ERROR_MESSAGE })) | ||
} | ||
} | ||
} | ||
|
||
export const PRODUCT_ADD = 'product/addProduct'; | ||
export const productAdd = createAction<TAddProductParams>(PRODUCT_ADD); |
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,27 @@ | ||
import { put } from "redux-saga/effects"; | ||
import { isTErrorResponse, TServerError } from "../../../shared/fetchHelpers/typeGuards"; | ||
import { createAction } from "@reduxjs/toolkit"; | ||
import { UNKNOWN_ERROR_MESSAGE } from "./constant"; | ||
import { deleteProductApi } from "../../../entities/ViewProductList/api/request"; | ||
import { deleteProduct, setError } from "../productSlice"; | ||
|
||
// Saga Effects. Delete product | ||
export function* deleteProductSaga(data: { type: string, payload: string }): any { | ||
try { | ||
|
||
yield deleteProductApi(data.payload); | ||
yield put(deleteProduct(data.payload)); | ||
} catch (error: unknown) { | ||
if (isTErrorResponse(error)) { | ||
let allErrors = ""; | ||
error.response.data.errors.forEach((e: TServerError) => allErrors += e.message); | ||
|
||
yield put(setError({ isError: true, errorMessage: allErrors })) | ||
} else { | ||
yield put(setError({ isError: true, errorMessage: UNKNOWN_ERROR_MESSAGE })) | ||
} | ||
} | ||
} | ||
|
||
export const PRODUCT_DELETE = 'product/deleteProduct'; | ||
export const productDelete = createAction<string>(PRODUCT_DELETE); |
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,38 @@ | ||
import { put } from "redux-saga/effects"; | ||
import { isTErrorResponse, TServerError } from "../../../shared/fetchHelpers/typeGuards"; | ||
import { createAction } from "@reduxjs/toolkit"; | ||
import { UNKNOWN_ERROR_MESSAGE } from "./constant"; | ||
import { Category, Product, TUpdateProductParams } from "../../../entities/ViewProductList/model/types/types"; | ||
import { putProductApi } from "../../../entities/ViewProductList/api/request"; | ||
import { setError, updateProductList } from "../productSlice"; | ||
|
||
// Saga Effects. Update product | ||
export function* updateProductSaga(data: { type: string, payload: Product }): any { | ||
try { | ||
|
||
const updateProduct: TUpdateProductParams = { | ||
id: data.payload.id, | ||
name: data.payload.name, | ||
createdAt: data.payload.createdAt, | ||
updatedAt: data.payload.updatedAt, | ||
price: data.payload.price, | ||
categoryId: data.payload.category.id, | ||
commandId: data.payload.commandId, | ||
} | ||
|
||
yield putProductApi(updateProduct); | ||
yield put(updateProductList(data.payload)); | ||
} catch (error: unknown) { | ||
if (isTErrorResponse(error)) { | ||
let allErrors = ""; | ||
error.response.data.errors.forEach((e: TServerError) => allErrors += e.message); | ||
|
||
yield put(setError({ isError: true, errorMessage: allErrors })) | ||
} else { | ||
yield put(setError({ isError: true, errorMessage: UNKNOWN_ERROR_MESSAGE })) | ||
} | ||
} | ||
} | ||
|
||
export const PRODUCT_UPDATE = 'product/updateProduct'; | ||
export const productUpdate = createAction<Product>(PRODUCT_UPDATE); |