From 035ad88ba32bc24ebad8714b71aeebd7d8f130e6 Mon Sep 17 00:00:00 2001 From: Nastya Date: Tue, 17 Oct 2023 00:05:18 +0300 Subject: [PATCH 1/4] fix history types --- src/api/history.ts | 3 ++- src/pages/History/AccordionWrapper.tsx | 8 ++++---- src/pages/History/index.tsx | 13 +++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/api/history.ts b/src/api/history.ts index 48a5f04..23820b6 100644 --- a/src/api/history.ts +++ b/src/api/history.ts @@ -12,11 +12,12 @@ type HistoryRecord = { id: string; isDeleted: boolean; key: string; - rawDetails: KeyValue[][]; + rawDetails: [RawDetails, KeyValue]; updatedAt: string; userId: string; }; +type RawDetails = { Key: string; Value: KeyValue[][] } type KeyValue = { Key: string; Value: string | number }; export async function getHistory(): Promise<[GetHistoryResponse | null, string?]> { diff --git a/src/pages/History/AccordionWrapper.tsx b/src/pages/History/AccordionWrapper.tsx index b163565..0058681 100644 --- a/src/pages/History/AccordionWrapper.tsx +++ b/src/pages/History/AccordionWrapper.tsx @@ -10,9 +10,10 @@ export type History = { expired?: boolean; }; +type RawDetails = { Key: string; Value: KeyValue[][] } type KeyValue = { Key: string; Value: string | number }; interface AccordionWrapperProps { - content: KeyValue[]; + content: [RawDetails, KeyValue]; last?: boolean; first?: boolean; createdAt: string @@ -26,8 +27,7 @@ export default function AccordionWrapper({ content, last, first, createdAt }: Ac const isMobile = useMediaQuery(theme.breakpoints.down(560)); const valuesByKey: any = {}; -console.log(content) - content.forEach((item) => { + content[0].Value[0].forEach((item) => { valuesByKey[item.Key] = item.Value; }); @@ -137,7 +137,7 @@ console.log(content) textAlign: "left", }} > - {valuesByKey.price} руб. + {content[1].Value} руб. diff --git a/src/pages/History/index.tsx b/src/pages/History/index.tsx index 4dd2b2b..11ff9ef 100644 --- a/src/pages/History/index.tsx +++ b/src/pages/History/index.tsx @@ -10,6 +10,7 @@ import AccordionWrapper from "./AccordionWrapper"; import { HISTORY } from "./historyMocks"; import { useHistoryTracker } from "@root/utils/hooks/useHistoryTracker"; import { useHistoryData } from "@root/utils/hooks/useHistoryData"; +import { isArray } from "cypress/types/lodash"; const subPages = ["Платежи", "Покупки тарифов", "Окончания тарифов"]; @@ -25,7 +26,7 @@ export default function History() { const handleCustomBackNavigation = useHistoryTracker(); if (!error && historyData) { - console.log(historyData?.records[0].rawDetails[0].map(({ Key, Value }) => (Key == "id" ? console.log(Value) : ""))); + // console.log(historyData?.records[0].rawDetails[0].Value.map(({ Key, Value }) => (Key == "id" ? console.log(Value) : ""))); } return ( @@ -65,16 +66,20 @@ export default function History() { ) : ( )} - {historyData?.records.map(( e, index) => ( + {historyData?.records + .filter((e) => (e.key === "payCart" && Array.isArray(e.rawDetails[0].Value))) + .map(( e, index) => { + console.log(e) + return ( - ))} + )})} ); } From a6ef841657fa4915fed470a11b5fffbeffa22eb7 Mon Sep 17 00:00:00 2001 From: Nastya Date: Wed, 18 Oct 2023 10:39:07 +0300 Subject: [PATCH 2/4] =?UTF-8?q?=D0=9A=D0=BD=D0=BE=D0=BF=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=B0=D0=B7=D0=B0=20=D0=B8=D0=B7=20=D0=BA?= =?UTF-8?q?=D0=BE=D1=80=D0=B7=D0=B8=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/icons/File.tsx | 30 ++++++ src/pages/History/AccordionWrapper.tsx | 124 ++++++++++++++++++------- src/pages/History/index.tsx | 1 - src/utils/declension.ts | 4 +- 4 files changed, 123 insertions(+), 36 deletions(-) create mode 100644 src/components/icons/File.tsx diff --git a/src/components/icons/File.tsx b/src/components/icons/File.tsx new file mode 100644 index 0000000..ab2350d --- /dev/null +++ b/src/components/icons/File.tsx @@ -0,0 +1,30 @@ +import { Box } from "@mui/material"; + +interface Props { + color?: string; + bgcolor?: string; + width?: string; + height?: string; +} + +export default function CustomIcon() { + return ( + + + + + + + + + ); +} diff --git a/src/pages/History/AccordionWrapper.tsx b/src/pages/History/AccordionWrapper.tsx index 0058681..ee3566d 100644 --- a/src/pages/History/AccordionWrapper.tsx +++ b/src/pages/History/AccordionWrapper.tsx @@ -1,5 +1,10 @@ -import { Box, Typography, useMediaQuery, useTheme } from "@mui/material"; +import { Box, IconButton, Typography, useMediaQuery, useTheme } from "@mui/material"; import CustomAccordion from "@components/CustomAccordion"; +import File from "@components/icons/File" +import { getDeclension } from "@utils/declension" +import { enqueueSnackbar } from "notistack"; +import { addTariffToCart } from "@root/stores/user"; +import { getMessageFromFetchError } from "@frontend/kitui"; export type History = { title: string; @@ -30,12 +35,27 @@ export default function AccordionWrapper({ content, last, first, createdAt }: Ac content[0].Value[0].forEach((item) => { valuesByKey[item.Key] = item.Value; }); - + console.log(valuesByKey) + const extractDateFromString = (tariffName: string) => { const dateMatch = tariffName.match(/\d{4}-\d{2}-\d{2}/); return dateMatch ? dateMatch[0] : null; }; + + function handleTariffItemClick(tariffId: string) { + addTariffToCart(tariffId) + .then((e) => { + console.log(e) + enqueueSnackbar("Тариф добавлен в корзину"); + }) + .catch((error) => { + console.log(error) + const message = getMessageFromFetchError(error); + if (message) enqueueSnackbar(message); + }); + } + return ( { + return( + + {e[1].Value} - {e[5].Value} {getDeclension(Number(e[5].Value), e[7].Value.toString())} + ) + })} header={ - {valuesByKey.name} + {valuesByKey.iscustom ? "Кастомный тариф" : valuesByKey.name} - - {valuesByKey.payMethod && Способ оплаты: {valuesByKey.payMethod}} - - + - {content[1].Value} руб. + {valuesByKey.payMethod && Способ оплаты: {valuesByKey.payMethod}} + + + {Number(content[1].Value) / 100 ? Number(content[1].Value) / 100 : "nodata"} руб. + + + { + e.stopPropagation() + handleTariffItemClick(valuesByKey.id) + }} + sx={{ + bgcolor:"#EEE4FC", + stroke: "#7E2AEA", + borderRadius: 2, + "&:hover": { + bgcolor:"#7E2AEA", + stroke: "white", + }, + "&:active": { + bgcolor:"black", + stroke: "white", + } + }} + > + + } diff --git a/src/pages/History/index.tsx b/src/pages/History/index.tsx index 11ff9ef..2913323 100644 --- a/src/pages/History/index.tsx +++ b/src/pages/History/index.tsx @@ -69,7 +69,6 @@ export default function History() { {historyData?.records .filter((e) => (e.key === "payCart" && Array.isArray(e.rawDetails[0].Value))) .map(( e, index) => { - console.log(e) return ( Date: Wed, 18 Oct 2023 19:06:15 +0300 Subject: [PATCH 3/4] =?UTF-8?q?=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D1=82?= =?UTF-8?q?=D0=B0=D1=80=D0=B8=D1=84=D0=B0=20=D0=BD=D0=B5=20=D1=81=D1=83?= =?UTF-8?q?=D1=89=D0=B5=D1=81=D1=82=D0=B2=D1=83=D1=8E=D1=89=D0=B5=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=B2=20=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/cart.ts | 4 +- .../NumberInputWithUnitAdornment.tsx | 1 - src/components/templCardPhoneLight.tsx | 1 - src/pages/Cart/Cart.tsx | 1 - src/pages/Cart/CustomWrapper.tsx | 1 - src/pages/History/AccordionWrapper.tsx | 66 ++++++++++++++----- src/pages/History/index.tsx | 4 -- src/pages/Landing/Section3.tsx | 2 - src/pages/Tariffs/Tariffs.tsx | 2 - src/pages/Tariffs/TariffsPage.tsx | 4 -- src/pages/Tariffs/slider/slider.tsx | 2 - src/stores/user.ts | 4 +- src/utils/hooks/handleCustomBackNavigation.ts | 2 - src/utils/hooks/useCart.ts | 1 - 14 files changed, 54 insertions(+), 41 deletions(-) diff --git a/src/api/cart.ts b/src/api/cart.ts index 1c7e03c..359c53e 100644 --- a/src/api/cart.ts +++ b/src/api/cart.ts @@ -1,4 +1,5 @@ import { UserAccount, makeRequest } from "@frontend/kitui"; +import { AxiosError } from 'axios'; import { parseAxiosError } from "@root/utils/parse-error"; @@ -19,7 +20,8 @@ export async function patchCart( return [patchCartResponse.cart]; } catch (nativeError) { - const [error] = parseAxiosError(nativeError); + let [error, status] = parseAxiosError(nativeError); + if (status === 400 && error.indexOf("invalid id") !== -1) error = "Данный тариф более недоступен" return [[], `Не удалось добавить товар в корзину. ${error}`]; } diff --git a/src/components/NumberInputWithUnitAdornment.tsx b/src/components/NumberInputWithUnitAdornment.tsx index 130dcb1..ebd16d3 100644 --- a/src/components/NumberInputWithUnitAdornment.tsx +++ b/src/components/NumberInputWithUnitAdornment.tsx @@ -32,7 +32,6 @@ export default function NumberInputWithUnitAdornment({ id, value, adornmentText, const newNumber = parseInt(target.value); - console.log(newNumber); if (!isFinite(newNumber) || newNumber < 0) { onChange(0); diff --git a/src/components/templCardPhoneLight.tsx b/src/components/templCardPhoneLight.tsx index 6f10891..7257abf 100644 --- a/src/components/templCardPhoneLight.tsx +++ b/src/components/templCardPhoneLight.tsx @@ -5,7 +5,6 @@ export default function TemplCardPhoneLight() { const theme = useTheme(); const upMd = useMediaQuery(theme.breakpoints.up("md")); const isMobile = useMediaQuery(theme.breakpoints.down(600)); - console.log("я узкий"); return ( { const privilege = tariff.privileges[0]; - console.log(tariff); return tariff.privileges.length > 1 ? ( diff --git a/src/pages/History/AccordionWrapper.tsx b/src/pages/History/AccordionWrapper.tsx index ee3566d..7ccb7e5 100644 --- a/src/pages/History/AccordionWrapper.tsx +++ b/src/pages/History/AccordionWrapper.tsx @@ -35,7 +35,6 @@ export default function AccordionWrapper({ content, last, first, createdAt }: Ac content[0].Value[0].forEach((item) => { valuesByKey[item.Key] = item.Value; }); - console.log(valuesByKey) const extractDateFromString = (tariffName: string) => { const dateMatch = tariffName.match(/\d{4}-\d{2}-\d{2}/); @@ -43,17 +42,13 @@ export default function AccordionWrapper({ content, last, first, createdAt }: Ac }; - function handleTariffItemClick(tariffId: string) { - addTariffToCart(tariffId) - .then((e) => { - console.log(e) - enqueueSnackbar("Тариф добавлен в корзину"); - }) - .catch((error) => { - console.log(error) - const message = getMessageFromFetchError(error); - if (message) enqueueSnackbar(message); - }); + async function handleTariffItemClick(tariffId: string) { + const { patchCartError } = await addTariffToCart(tariffId) + if (patchCartError) { + enqueueSnackbar(patchCartError); + } else { + enqueueSnackbar("Тариф добавлен в корзину"); + } } return ( @@ -66,13 +61,15 @@ export default function AccordionWrapper({ content, last, first, createdAt }: Ac last={last} first={first} divide - text={valuesByKey.privileges.map((e:KeyValue[]) => { - return( - + text={valuesByKey.privileges.map((e:KeyValue[]) => ( + {e[1].Value} - {e[5].Value} {getDeclension(Number(e[5].Value), e[7].Value.toString())} ) - })} + )} header={ + <> {valuesByKey.iscustom ? "Кастомный тариф" : valuesByKey.name} @@ -141,6 +143,7 @@ export default function AccordionWrapper({ content, last, first, createdAt }: Ac color: valuesByKey.expired ? theme.palette.text.disabled : theme.palette.gray.dark, px: 0, }} + title={`>Способ оплаты: ${valuesByKey.payMethod}}`} > {valuesByKey.payMethod && + {!isMobile && { @@ -181,6 +185,7 @@ export default function AccordionWrapper({ content, last, first, createdAt }: Ac handleTariffItemClick(valuesByKey.id) }} sx={{ + ml: "20px", bgcolor:"#EEE4FC", stroke: "#7E2AEA", borderRadius: 2, @@ -196,8 +201,35 @@ export default function AccordionWrapper({ content, last, first, createdAt }: Ac > + } + {isMobile && + { + e.stopPropagation() + handleTariffItemClick(valuesByKey.id) + }} + sx={{ + mr: "10px", + bgcolor:"#EEE4FC", + stroke: "#7E2AEA", + borderRadius: 2, + "&:hover": { + bgcolor:"#7E2AEA", + stroke: "white", + }, + "&:active": { + bgcolor:"black", + stroke: "white", + } + }} + > + + + } + } /> diff --git a/src/pages/History/index.tsx b/src/pages/History/index.tsx index 2913323..a2efb3e 100644 --- a/src/pages/History/index.tsx +++ b/src/pages/History/index.tsx @@ -25,10 +25,6 @@ export default function History() { const handleCustomBackNavigation = useHistoryTracker(); - if (!error && historyData) { - // console.log(historyData?.records[0].rawDetails[0].Value.map(({ Key, Value }) => (Key == "id" ? console.log(Value) : ""))); - } - return ( typeof tariff === "object"); - console.log(currentTariffs); - function handleTariffItemClick(tariffId: string) { addTariffToCart(tariffId) .then(() => { @@ -73,8 +71,6 @@ export default function TariffPage() { ); }); - console.log(isCustomTariffs); - const createTariffElements = (filteredTariffs: Tariff[]) => { const tariffElements = filteredTariffs .filter((tariff) => tariff.privileges.length > 0) diff --git a/src/pages/Tariffs/slider/slider.tsx b/src/pages/Tariffs/slider/slider.tsx index 9b5bc5d..4c190e6 100644 --- a/src/pages/Tariffs/slider/slider.tsx +++ b/src/pages/Tariffs/slider/slider.tsx @@ -33,8 +33,6 @@ export const Slider = ({ items }: SliderProps) => { const gridTablet = useMediaQuery(theme.breakpoints.down(1000)); const isMobileHeader = useMediaQuery(theme.breakpoints.down(900)); - console.log(items.length); - useEffect(() => { if (isTablet) { setRange(1); diff --git a/src/stores/user.ts b/src/stores/user.ts index fb50ade..e791c51 100644 --- a/src/stores/user.ts +++ b/src/stores/user.ts @@ -277,11 +277,11 @@ export const sendUserData = async () => { export const addTariffToCart = async (tariffId: string) => { const [patchCartResponse, patchCartError] = await patchCart(tariffId); - console.log(patchCartResponse) - if (!patchCartError) { + if (patchCartError !== undefined) { setCart(patchCartResponse); } + return({patchCartResponse, patchCartError}) }; export const removeTariffFromCart = async (tariffId: string) => { diff --git a/src/utils/hooks/handleCustomBackNavigation.ts b/src/utils/hooks/handleCustomBackNavigation.ts index 489d3af..bbe635b 100644 --- a/src/utils/hooks/handleCustomBackNavigation.ts +++ b/src/utils/hooks/handleCustomBackNavigation.ts @@ -20,12 +20,10 @@ export const usePrevLocation = (location: RouteLocation | null) => { const handleCustomBackNavigation = () => { if (prevLocRef.current?.state?.previousUrl) { const prevUrl = prevLocRef.current.state.previousUrl; - console.log(prevUrl); if (prevUrl.includes("/support/")) { return navigate(-2); } } - console.log("yjy"); return navigate(-1); }; diff --git a/src/utils/hooks/useCart.ts b/src/utils/hooks/useCart.ts index b5d8fb0..afd9a95 100644 --- a/src/utils/hooks/useCart.ts +++ b/src/utils/hooks/useCart.ts @@ -26,7 +26,6 @@ export function useCart() { function addTariffsToCart() { const knownTariffs: Tariff[] = []; - console.log(cartTariffIds) cartTariffIds?.forEach(async (tariffId) => { if (typeof cartTariffMap[tariffId] === "object") return; From 41bc8bd470c7916cdf2fd7183073270cb42efce2 Mon Sep 17 00:00:00 2001 From: Nastya Date: Wed, 18 Oct 2023 19:56:30 +0300 Subject: [PATCH 4/4] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=20=D1=82=D0=B5=D0=BA=D1=81=D1=82=D0=B0=20=D1=81=D0=B5=D1=80?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BD=D1=8B=D1=85=20=D0=BE=D1=88=D0=B8=D0=B1?= =?UTF-8?q?=D0=BE=D0=BA=20=D0=BD=D0=B0=20=D1=80=D1=83=D1=81=D1=81=D0=BA?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/cart.ts | 2 +- src/utils/parse-error.ts | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/api/cart.ts b/src/api/cart.ts index 359c53e..5c2cc22 100644 --- a/src/api/cart.ts +++ b/src/api/cart.ts @@ -83,4 +83,4 @@ export async function patchCurrency( return [null, `Не удалось изменить валюту. ${error}`]; } -} +} \ No newline at end of file diff --git a/src/utils/parse-error.ts b/src/utils/parse-error.ts index 1134aec..518756a 100644 --- a/src/utils/parse-error.ts +++ b/src/utils/parse-error.ts @@ -6,6 +6,17 @@ export type ServerError = { message: string; }; +const translateMessage: Record = { + "user not found": "Пользователь не найден", + "invalid password": "Неправильный пароль", + "field is empty": "Поле \"Пароль\" не заполнено", + "field is empty": "Поле \"Логин\" не заполнено", + "field is empty": "Поле \"E-mail\" не заполнено", + "field is empty": "Поле \"Номер телефона\" не заполнено", + "user with this email or login is exist": "Пользователь уже существует", + "user with this login is exist": "Пользователь с таким логином уже существует" +}; + export const parseAxiosError = (nativeError: unknown): [string, number?] => { const error = nativeError as AxiosError; @@ -14,7 +25,8 @@ export const parseAxiosError = (nativeError: unknown): [string, number?] => { "statusCode" in (error.response.data as ServerError) ) { const serverError = error.response.data as ServerError; - + const translatedMessage = translateMessage[serverError.message] + if (translatedMessage !== undefined) serverError.message = translatedMessage return [serverError.message, serverError.statusCode]; }