Merge branch 'dev' into 'main'
Dev See merge request frontend/marketplace!63
This commit is contained in:
commit
e2f7668261
@ -1,4 +1,5 @@
|
|||||||
import { UserAccount, makeRequest } from "@frontend/kitui";
|
import { UserAccount, makeRequest } from "@frontend/kitui";
|
||||||
|
import { AxiosError } from 'axios';
|
||||||
|
|
||||||
import { parseAxiosError } from "@root/utils/parse-error";
|
import { parseAxiosError } from "@root/utils/parse-error";
|
||||||
|
|
||||||
@ -19,7 +20,8 @@ export async function patchCart(
|
|||||||
|
|
||||||
return [patchCartResponse.cart];
|
return [patchCartResponse.cart];
|
||||||
} catch (nativeError) {
|
} catch (nativeError) {
|
||||||
const [error] = parseAxiosError(nativeError);
|
let [error, status] = parseAxiosError(nativeError);
|
||||||
|
if (status === 400 && error.indexOf("invalid id") !== -1) error = "Данный тариф более недоступен"
|
||||||
|
|
||||||
return [[], `Не удалось добавить товар в корзину. ${error}`];
|
return [[], `Не удалось добавить товар в корзину. ${error}`];
|
||||||
}
|
}
|
||||||
|
@ -12,11 +12,12 @@ type HistoryRecord = {
|
|||||||
id: string;
|
id: string;
|
||||||
isDeleted: boolean;
|
isDeleted: boolean;
|
||||||
key: string;
|
key: string;
|
||||||
rawDetails: KeyValue[][];
|
rawDetails: [RawDetails, KeyValue];
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type RawDetails = { Key: string; Value: KeyValue[][] }
|
||||||
type KeyValue = { Key: string; Value: string | number };
|
type KeyValue = { Key: string; Value: string | number };
|
||||||
|
|
||||||
export async function getHistory(): Promise<[GetHistoryResponse | null, string?]> {
|
export async function getHistory(): Promise<[GetHistoryResponse | null, string?]> {
|
||||||
|
@ -32,7 +32,6 @@ export default function NumberInputWithUnitAdornment({ id, value, adornmentText,
|
|||||||
|
|
||||||
const newNumber = parseInt(target.value);
|
const newNumber = parseInt(target.value);
|
||||||
|
|
||||||
console.log(newNumber);
|
|
||||||
|
|
||||||
if (!isFinite(newNumber) || newNumber < 0) {
|
if (!isFinite(newNumber) || newNumber < 0) {
|
||||||
onChange(0);
|
onChange(0);
|
||||||
|
30
src/components/icons/File.tsx
Normal file
30
src/components/icons/File.tsx
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import { Box } from "@mui/material";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
color?: string;
|
||||||
|
bgcolor?: string;
|
||||||
|
width?: string;
|
||||||
|
height?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function CustomIcon() {
|
||||||
|
return (
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
stroke: "inherit",
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
borderRadius: "6px"
|
||||||
|
}}
|
||||||
|
|
||||||
|
>
|
||||||
|
<svg width="24" height="24" viewBox="0 0 24 24" stroke="inherit" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<rect x="3.2002" y="0.75" width="17.8" height="22.25" rx="4" stroke-width="1.5"/>
|
||||||
|
<path d="M7.65039 6.3125H16.5504" stroke-width="1.5" stroke-linecap="round"/>
|
||||||
|
<path d="M7.65039 11.875H16.5504" stroke-width="1.5" stroke-linecap="round"/>
|
||||||
|
<path d="M7.65039 17.4375H12.1004" stroke-width="1.5" stroke-linecap="round"/>
|
||||||
|
</svg>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
}
|
@ -5,7 +5,6 @@ export default function TemplCardPhoneLight() {
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const upMd = useMediaQuery(theme.breakpoints.up("md"));
|
const upMd = useMediaQuery(theme.breakpoints.up("md"));
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
||||||
console.log("я узкий");
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
|
@ -20,7 +20,6 @@ export default function Cart() {
|
|||||||
|
|
||||||
const handleCustomBackNavigation = usePrevLocation(location);
|
const handleCustomBackNavigation = usePrevLocation(location);
|
||||||
|
|
||||||
console.log(cart.services);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SectionWrapper
|
<SectionWrapper
|
||||||
|
@ -135,7 +135,6 @@ export default function CustomWrapper({ serviceData, last, first }: Props) {
|
|||||||
serviceData.tariffs.map((tariff) => {
|
serviceData.tariffs.map((tariff) => {
|
||||||
const privilege = tariff.privileges[0];
|
const privilege = tariff.privileges[0];
|
||||||
|
|
||||||
console.log(tariff);
|
|
||||||
|
|
||||||
return tariff.privileges.length > 1 ? (
|
return tariff.privileges.length > 1 ? (
|
||||||
<CustomTariffAccordion key={tariff.id} tariffCartData={tariff} />
|
<CustomTariffAccordion key={tariff.id} tariffCartData={tariff} />
|
||||||
|
@ -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 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 = {
|
export type History = {
|
||||||
title: string;
|
title: string;
|
||||||
@ -10,9 +15,10 @@ export type History = {
|
|||||||
expired?: boolean;
|
expired?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type RawDetails = { Key: string; Value: KeyValue[][] }
|
||||||
type KeyValue = { Key: string; Value: string | number };
|
type KeyValue = { Key: string; Value: string | number };
|
||||||
interface AccordionWrapperProps {
|
interface AccordionWrapperProps {
|
||||||
content: KeyValue[];
|
content: [RawDetails, KeyValue];
|
||||||
last?: boolean;
|
last?: boolean;
|
||||||
first?: boolean;
|
first?: boolean;
|
||||||
createdAt: string
|
createdAt: string
|
||||||
@ -26,8 +32,7 @@ export default function AccordionWrapper({ content, last, first, createdAt }: Ac
|
|||||||
const isMobile = useMediaQuery(theme.breakpoints.down(560));
|
const isMobile = useMediaQuery(theme.breakpoints.down(560));
|
||||||
|
|
||||||
const valuesByKey: any = {};
|
const valuesByKey: any = {};
|
||||||
console.log(content)
|
content[0].Value[0].forEach((item) => {
|
||||||
content.forEach((item) => {
|
|
||||||
valuesByKey[item.Key] = item.Value;
|
valuesByKey[item.Key] = item.Value;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -36,6 +41,16 @@ console.log(content)
|
|||||||
return dateMatch ? dateMatch[0] : null;
|
return dateMatch ? dateMatch[0] : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
async function handleTariffItemClick(tariffId: string) {
|
||||||
|
const { patchCartError } = await addTariffToCart(tariffId)
|
||||||
|
if (patchCartError) {
|
||||||
|
enqueueSnackbar(patchCartError);
|
||||||
|
} else {
|
||||||
|
enqueueSnackbar("Тариф добавлен в корзину");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
@ -46,8 +61,15 @@ console.log(content)
|
|||||||
last={last}
|
last={last}
|
||||||
first={first}
|
first={first}
|
||||||
divide
|
divide
|
||||||
text={"Дата действия приобретенной лицензии (в формате дд.мм.гггг-дд.мм.гггг) Или же объем"}
|
text={valuesByKey.privileges.map((e:KeyValue[]) => (
|
||||||
|
<Typography
|
||||||
|
key={valuesByKey.id}
|
||||||
|
>
|
||||||
|
{e[1].Value} - {e[5].Value} {getDeclension(Number(e[5].Value), e[7].Value.toString())}
|
||||||
|
</Typography>)
|
||||||
|
)}
|
||||||
header={
|
header={
|
||||||
|
<>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
@ -68,7 +90,7 @@ console.log(content)
|
|||||||
alignItems: upSm ? "center" : undefined,
|
alignItems: upSm ? "center" : undefined,
|
||||||
justifyContent: "space-between",
|
justifyContent: "space-between",
|
||||||
flexDirection: upSm ? undefined : "column",
|
flexDirection: upSm ? undefined : "column",
|
||||||
gap: upMd ? "40px" : "10px",
|
gap: upMd ? "51px" : "10px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Typography
|
<Typography
|
||||||
@ -86,62 +108,128 @@ console.log(content)
|
|||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
<Typography
|
<Typography
|
||||||
|
title={valuesByKey.iscustom ? "Кастомный тариф" : valuesByKey.name}
|
||||||
sx={{
|
sx={{
|
||||||
fontSize: upMd ? "18px" : "16px",
|
fontSize: upMd ? "18px" : "16px",
|
||||||
lineHeight: upMd ? undefined : "19px",
|
lineHeight: upMd ? undefined : "19px",
|
||||||
fontWeight: 500,
|
fontWeight: 500,
|
||||||
color: valuesByKey.expired ? theme.palette.text.disabled : theme.palette.gray.dark,
|
color: valuesByKey.expired ? theme.palette.text.disabled : theme.palette.gray.dark,
|
||||||
px: 0,
|
px: 0,
|
||||||
|
width: '200px',
|
||||||
|
maxWidth: '200px',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis'
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{valuesByKey.name}
|
{valuesByKey.iscustom ? "Кастомный тариф" : valuesByKey.name}
|
||||||
</Typography>
|
</Typography>
|
||||||
</Box>
|
</Box>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
justifyContent: "space-between",
|
|
||||||
alignItems: "center",
|
|
||||||
flexFlow: "1",
|
|
||||||
flexBasis: "60%",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Typography
|
|
||||||
sx={{
|
|
||||||
display: upMd ? undefined : "none",
|
|
||||||
fontSize: upMd ? "18px" : "16px",
|
|
||||||
lineHeight: upMd ? undefined : "19px",
|
|
||||||
fontWeight: 400,
|
|
||||||
color: valuesByKey.expired ? theme.palette.text.disabled : theme.palette.gray.dark,
|
|
||||||
px: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{valuesByKey.payMethod && <Typography>Способ оплаты: {valuesByKey.payMethod}</Typography>}
|
|
||||||
</Typography>
|
|
||||||
<Box
|
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
height: "100%",
|
justifyContent: "space-between",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
gap: upSm ? "111px" : "17px",
|
flexFlow: "1",
|
||||||
width: "100%",
|
flexBasis: "60%",
|
||||||
maxWidth: isTablet ? null : "160px",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
<Box display="flex" width="100%" justifyContent="space-between">
|
||||||
<Typography
|
<Typography
|
||||||
sx={{
|
sx={{
|
||||||
marginLeft: isTablet ? (isMobile ? null : "auto") : null,
|
display: upMd ? undefined : "none",
|
||||||
|
fontSize: upMd ? "18px" : "16px",
|
||||||
|
lineHeight: upMd ? undefined : "19px",
|
||||||
|
fontWeight: 400,
|
||||||
color: valuesByKey.expired ? theme.palette.text.disabled : theme.palette.gray.dark,
|
color: valuesByKey.expired ? theme.palette.text.disabled : theme.palette.gray.dark,
|
||||||
fontSize: upSm ? "20px" : "16px",
|
px: 0,
|
||||||
fontWeight: 500,
|
}}
|
||||||
textAlign: "left",
|
title={`>Способ оплаты: ${valuesByKey.payMethod}</Typography>}`}
|
||||||
|
>
|
||||||
|
{valuesByKey.payMethod && <Typography
|
||||||
|
sx={{
|
||||||
|
maxWidth: '300px',
|
||||||
|
width: '300px',
|
||||||
|
overflow: 'hidden',
|
||||||
|
textOverflow: 'ellipsis'
|
||||||
|
}}
|
||||||
|
>Способ оплаты: {valuesByKey.payMethod}</Typography>}
|
||||||
|
</Typography>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
|
display: "flex",
|
||||||
|
height: "100%",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: upSm ? "111px" : "17px",
|
||||||
|
width: "100%",
|
||||||
|
maxWidth: isTablet ? null : "160px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{valuesByKey.price} руб.
|
<Typography
|
||||||
</Typography>
|
sx={{
|
||||||
|
marginLeft: isTablet ? (isMobile ? null : "auto") : null,
|
||||||
|
color: valuesByKey.expired ? theme.palette.text.disabled : theme.palette.gray.dark,
|
||||||
|
fontSize: upSm ? "20px" : "16px",
|
||||||
|
fontWeight: 500,
|
||||||
|
textAlign: "left",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{Number(content[1].Value) / 100 ? Number(content[1].Value) / 100 : "nodata"} руб.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
{!isMobile &&
|
||||||
|
<IconButton
|
||||||
|
title="Добавить в корзину тариф"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
handleTariffItemClick(valuesByKey.id)
|
||||||
|
}}
|
||||||
|
sx={{
|
||||||
|
ml: "20px",
|
||||||
|
bgcolor:"#EEE4FC",
|
||||||
|
stroke: "#7E2AEA",
|
||||||
|
borderRadius: 2,
|
||||||
|
"&:hover": {
|
||||||
|
bgcolor:"#7E2AEA",
|
||||||
|
stroke: "white",
|
||||||
|
},
|
||||||
|
"&:active": {
|
||||||
|
bgcolor:"black",
|
||||||
|
stroke: "white",
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<File></File>
|
||||||
|
</IconButton>
|
||||||
|
}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
{isMobile &&
|
||||||
|
<IconButton
|
||||||
|
title="Добавить в корзину тариф"
|
||||||
|
onClick={(e) => {
|
||||||
|
e.stopPropagation()
|
||||||
|
handleTariffItemClick(valuesByKey.id)
|
||||||
|
}}
|
||||||
|
sx={{
|
||||||
|
mr: "10px",
|
||||||
|
bgcolor:"#EEE4FC",
|
||||||
|
stroke: "#7E2AEA",
|
||||||
|
borderRadius: 2,
|
||||||
|
"&:hover": {
|
||||||
|
bgcolor:"#7E2AEA",
|
||||||
|
stroke: "white",
|
||||||
|
},
|
||||||
|
"&:active": {
|
||||||
|
bgcolor:"black",
|
||||||
|
stroke: "white",
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<File></File>
|
||||||
|
</IconButton>
|
||||||
|
}
|
||||||
|
</>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
@ -10,6 +10,7 @@ import AccordionWrapper from "./AccordionWrapper";
|
|||||||
import { HISTORY } from "./historyMocks";
|
import { HISTORY } from "./historyMocks";
|
||||||
import { useHistoryTracker } from "@root/utils/hooks/useHistoryTracker";
|
import { useHistoryTracker } from "@root/utils/hooks/useHistoryTracker";
|
||||||
import { useHistoryData } from "@root/utils/hooks/useHistoryData";
|
import { useHistoryData } from "@root/utils/hooks/useHistoryData";
|
||||||
|
import { isArray } from "cypress/types/lodash";
|
||||||
|
|
||||||
const subPages = ["Платежи", "Покупки тарифов", "Окончания тарифов"];
|
const subPages = ["Платежи", "Покупки тарифов", "Окончания тарифов"];
|
||||||
|
|
||||||
@ -24,10 +25,6 @@ export default function History() {
|
|||||||
|
|
||||||
const handleCustomBackNavigation = useHistoryTracker();
|
const handleCustomBackNavigation = useHistoryTracker();
|
||||||
|
|
||||||
if (!error && historyData) {
|
|
||||||
console.log(historyData?.records[0].rawDetails[0].map(({ Key, Value }) => (Key == "id" ? console.log(Value) : "")));
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SectionWrapper
|
<SectionWrapper
|
||||||
maxWidth="lg"
|
maxWidth="lg"
|
||||||
@ -65,16 +62,19 @@ export default function History() {
|
|||||||
) : (
|
) : (
|
||||||
<Tabs items={subPages} selectedItem={selectedItem} setSelectedItem={setSelectedItem} />
|
<Tabs items={subPages} selectedItem={selectedItem} setSelectedItem={setSelectedItem} />
|
||||||
)}
|
)}
|
||||||
{historyData?.records.map(( e, index) => (
|
{historyData?.records
|
||||||
|
.filter((e) => (e.key === "payCart" && Array.isArray(e.rawDetails[0].Value)))
|
||||||
|
.map(( e, index) => {
|
||||||
|
return (
|
||||||
<Box key={index} sx={{ mt: index === 0 ? "27px" : "0px" }}>
|
<Box key={index} sx={{ mt: index === 0 ? "27px" : "0px" }}>
|
||||||
<AccordionWrapper
|
<AccordionWrapper
|
||||||
first={index === 0}
|
first={index === 0}
|
||||||
last={index === historyData?.records.length - 1}
|
last={index === historyData?.records.length - 1}
|
||||||
content={e.rawDetails[0]}
|
content={e.rawDetails}
|
||||||
createdAt={e.createdAt}
|
createdAt={e.createdAt}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
))}
|
)})}
|
||||||
</SectionWrapper>
|
</SectionWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -17,8 +17,6 @@ export default function Section3() {
|
|||||||
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
||||||
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
const isMobile = useMediaQuery(theme.breakpoints.down(600));
|
||||||
|
|
||||||
console.log(downXs);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SectionWrapper
|
<SectionWrapper
|
||||||
component="section"
|
component="section"
|
||||||
|
@ -15,8 +15,6 @@ export default function Tariffs() {
|
|||||||
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
const isTablet = useMediaQuery(theme.breakpoints.down(1000));
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
console.log(upMd);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SectionWrapper
|
<SectionWrapper
|
||||||
maxWidth="lg"
|
maxWidth="lg"
|
||||||
|
@ -44,8 +44,6 @@ export default function TariffPage() {
|
|||||||
const unit: string = String(location.pathname).slice(9);
|
const unit: string = String(location.pathname).slice(9);
|
||||||
const currentTariffs = Object.values(cartTariffMap).filter((tariff): tariff is Tariff => typeof tariff === "object");
|
const currentTariffs = Object.values(cartTariffMap).filter((tariff): tariff is Tariff => typeof tariff === "object");
|
||||||
|
|
||||||
console.log(currentTariffs);
|
|
||||||
|
|
||||||
function handleTariffItemClick(tariffId: string) {
|
function handleTariffItemClick(tariffId: string) {
|
||||||
addTariffToCart(tariffId)
|
addTariffToCart(tariffId)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@ -73,8 +71,6 @@ export default function TariffPage() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(isCustomTariffs);
|
|
||||||
|
|
||||||
const createTariffElements = (filteredTariffs: Tariff[]) => {
|
const createTariffElements = (filteredTariffs: Tariff[]) => {
|
||||||
const tariffElements = filteredTariffs
|
const tariffElements = filteredTariffs
|
||||||
.filter((tariff) => tariff.privileges.length > 0)
|
.filter((tariff) => tariff.privileges.length > 0)
|
||||||
|
@ -33,8 +33,6 @@ export const Slider = ({ items }: SliderProps) => {
|
|||||||
const gridTablet = useMediaQuery(theme.breakpoints.down(1000));
|
const gridTablet = useMediaQuery(theme.breakpoints.down(1000));
|
||||||
const isMobileHeader = useMediaQuery(theme.breakpoints.down(900));
|
const isMobileHeader = useMediaQuery(theme.breakpoints.down(900));
|
||||||
|
|
||||||
console.log(items.length);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isTablet) {
|
if (isTablet) {
|
||||||
setRange(1);
|
setRange(1);
|
||||||
|
@ -277,11 +277,11 @@ export const sendUserData = async () => {
|
|||||||
|
|
||||||
export const addTariffToCart = async (tariffId: string) => {
|
export const addTariffToCart = async (tariffId: string) => {
|
||||||
const [patchCartResponse, patchCartError] = await patchCart(tariffId);
|
const [patchCartResponse, patchCartError] = await patchCart(tariffId);
|
||||||
console.log(patchCartResponse)
|
|
||||||
|
|
||||||
if (!patchCartError) {
|
if (patchCartError !== undefined) {
|
||||||
setCart(patchCartResponse);
|
setCart(patchCartResponse);
|
||||||
}
|
}
|
||||||
|
return({patchCartResponse, patchCartError})
|
||||||
};
|
};
|
||||||
|
|
||||||
export const removeTariffFromCart = async (tariffId: string) => {
|
export const removeTariffFromCart = async (tariffId: string) => {
|
||||||
|
@ -9,7 +9,7 @@ function declension(number: number, declensions: string[], cases = [2, 0, 1, 1,
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDeclension(number: number, word: PrivilegeValueType | "месяц" | "год"): string {
|
export function getDeclension(number: number, word: PrivilegeValueType | "месяц" | "год" | string): string {
|
||||||
switch (word) {
|
switch (word) {
|
||||||
case "шаблон":
|
case "шаблон":
|
||||||
return declension(number, ["шаблон", "шаблона", "шаблонов"]);
|
return declension(number, ["шаблон", "шаблона", "шаблонов"]);
|
||||||
@ -21,5 +21,7 @@ export function getDeclension(number: number, word: PrivilegeValueType | "мес
|
|||||||
return declension(number, ["год", "года", "лет"]);
|
return declension(number, ["год", "года", "лет"]);
|
||||||
case "МБ":
|
case "МБ":
|
||||||
return "МБ";
|
return "МБ";
|
||||||
|
default:
|
||||||
|
return "ед."
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -20,12 +20,10 @@ export const usePrevLocation = (location: RouteLocation | null) => {
|
|||||||
const handleCustomBackNavigation = () => {
|
const handleCustomBackNavigation = () => {
|
||||||
if (prevLocRef.current?.state?.previousUrl) {
|
if (prevLocRef.current?.state?.previousUrl) {
|
||||||
const prevUrl = prevLocRef.current.state.previousUrl;
|
const prevUrl = prevLocRef.current.state.previousUrl;
|
||||||
console.log(prevUrl);
|
|
||||||
if (prevUrl.includes("/support/")) {
|
if (prevUrl.includes("/support/")) {
|
||||||
return navigate(-2);
|
return navigate(-2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("yjy");
|
|
||||||
return navigate(-1);
|
return navigate(-1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -26,7 +26,6 @@ export function useCart() {
|
|||||||
function addTariffsToCart() {
|
function addTariffsToCart() {
|
||||||
const knownTariffs: Tariff[] = [];
|
const knownTariffs: Tariff[] = [];
|
||||||
|
|
||||||
console.log(cartTariffIds)
|
|
||||||
cartTariffIds?.forEach(async (tariffId) => {
|
cartTariffIds?.forEach(async (tariffId) => {
|
||||||
if (typeof cartTariffMap[tariffId] === "object") return;
|
if (typeof cartTariffMap[tariffId] === "object") return;
|
||||||
|
|
||||||
|
@ -6,6 +6,17 @@ export type ServerError = {
|
|||||||
message: string;
|
message: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const translateMessage: Record<string, string> = {
|
||||||
|
"user not found": "Пользователь не найден",
|
||||||
|
"invalid password": "Неправильный пароль",
|
||||||
|
"field <password> is empty": "Поле \"Пароль\" не заполнено",
|
||||||
|
"field <login> is empty": "Поле \"Логин\" не заполнено",
|
||||||
|
"field <email> is empty": "Поле \"E-mail\" не заполнено",
|
||||||
|
"field <phoneNumber> is empty": "Поле \"Номер телефона\" не заполнено",
|
||||||
|
"user with this email or login is exist": "Пользователь уже существует",
|
||||||
|
"user with this login is exist": "Пользователь с таким логином уже существует"
|
||||||
|
};
|
||||||
|
|
||||||
export const parseAxiosError = (nativeError: unknown): [string, number?] => {
|
export const parseAxiosError = (nativeError: unknown): [string, number?] => {
|
||||||
const error = nativeError as AxiosError;
|
const error = nativeError as AxiosError;
|
||||||
|
|
||||||
@ -14,7 +25,8 @@ export const parseAxiosError = (nativeError: unknown): [string, number?] => {
|
|||||||
"statusCode" in (error.response.data as ServerError)
|
"statusCode" in (error.response.data as ServerError)
|
||||||
) {
|
) {
|
||||||
const serverError = 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];
|
return [serverError.message, serverError.statusCode];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user