Создание тарифа на бэкенде
This commit is contained in:
parent
9747e18c0a
commit
2aa014aefc
@ -49,7 +49,7 @@ const SigninForm = () => {
|
|||||||
makeRequest({
|
makeRequest({
|
||||||
url: "https://admin.pena.digital/auth/login",
|
url: "https://admin.pena.digital/auth/login",
|
||||||
body: {
|
body: {
|
||||||
email: values.email,
|
login: values.email,
|
||||||
password: values.password,
|
password: values.password,
|
||||||
},
|
},
|
||||||
useToken: false,
|
useToken: false,
|
||||||
@ -60,14 +60,15 @@ const SigninForm = () => {
|
|||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
enqueueSnackbar(e.message ? e.message : `Unknown error`);
|
enqueueSnackbar(e.message ? e.message : `Unknown error`);
|
||||||
}).finally(() => {
|
})
|
||||||
|
.finally(() => {
|
||||||
formikHelpers.setSubmitting(false);
|
formikHelpers.setSubmitting(false);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Formik initialValues={initialValues} validate={validate} onSubmit={onSignFormSubmit}>
|
<Formik initialValues={initialValues} validate={validate} onSubmit={onSignFormSubmit}>
|
||||||
{props =>
|
{(props) => (
|
||||||
<Form>
|
<Form>
|
||||||
<Box
|
<Box
|
||||||
component="section"
|
component="section"
|
||||||
@ -152,7 +153,9 @@ const SigninForm = () => {
|
|||||||
padding: "20px 30px",
|
padding: "20px 30px",
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
}}
|
}}
|
||||||
>Войти</Button>
|
>
|
||||||
|
Войти
|
||||||
|
</Button>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
@ -166,7 +169,7 @@ const SigninForm = () => {
|
|||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</Form>
|
</Form>
|
||||||
}
|
)}
|
||||||
</Formik>
|
</Formik>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -2,14 +2,12 @@ import { Box, Checkbox, TextField, Typography, useTheme } from "@mui/material";
|
|||||||
import { DesktopDatePicker } from "@mui/x-date-pickers/DesktopDatePicker";
|
import { DesktopDatePicker } from "@mui/x-date-pickers/DesktopDatePicker";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
|
|
||||||
export default function DatePickers() {
|
export default function DatePickers() {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [isInfinite, setIsInfinite] = useState<boolean>(false);
|
const [isInfinite, setIsInfinite] = useState<boolean>(false);
|
||||||
const [startDate, setStartDate] = useState<Date>(new Date());
|
const [startDate, setStartDate] = useState<Date>(new Date());
|
||||||
const [endDate, setEndDate] = useState<Date>(new Date());
|
const [endDate, setEndDate] = useState<Date>(new Date());
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Typography
|
<Typography
|
||||||
@ -19,26 +17,37 @@ export default function DatePickers() {
|
|||||||
height: "40px",
|
height: "40px",
|
||||||
fontWeight: "normal",
|
fontWeight: "normal",
|
||||||
color: theme.palette.grayDisabled.main,
|
color: theme.palette.grayDisabled.main,
|
||||||
marginTop: "55px"
|
marginTop: "55px",
|
||||||
}}>
|
}}
|
||||||
|
>
|
||||||
Дата действия:
|
Дата действия:
|
||||||
</Typography>
|
</Typography>
|
||||||
<Box sx={{
|
<Box
|
||||||
|
sx={{
|
||||||
width: "100%",
|
width: "100%",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexWrap: 'wrap'
|
flexWrap: "wrap",
|
||||||
}}>
|
}}
|
||||||
<Typography sx={{
|
>
|
||||||
|
<Typography
|
||||||
|
sx={{
|
||||||
width: "35px",
|
width: "35px",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "left",
|
alignItems: "left",
|
||||||
}}>С</Typography>
|
}}
|
||||||
|
>
|
||||||
|
С
|
||||||
|
</Typography>
|
||||||
<DesktopDatePicker
|
<DesktopDatePicker
|
||||||
inputFormat="DD/MM/YYYY"
|
inputFormat="DD/MM/YYYY"
|
||||||
value={startDate}
|
value={startDate}
|
||||||
onChange={(e) => { if (e) { setStartDate(e); } }}
|
onChange={(e) => {
|
||||||
|
if (e) {
|
||||||
|
setStartDate(e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
renderInput={(params) => <TextField {...params} />}
|
renderInput={(params) => <TextField {...params} />}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
sx: {
|
sx: {
|
||||||
@ -46,21 +55,29 @@ export default function DatePickers() {
|
|||||||
color: theme.palette.secondary.main,
|
color: theme.palette.secondary.main,
|
||||||
border: "1px solid",
|
border: "1px solid",
|
||||||
borderColor: theme.palette.secondary.main,
|
borderColor: theme.palette.secondary.main,
|
||||||
"& .MuiSvgIcon-root": { color: theme.palette.secondary.main }
|
"& .MuiSvgIcon-root": { color: theme.palette.secondary.main },
|
||||||
}
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Typography sx={{
|
<Typography
|
||||||
|
sx={{
|
||||||
width: "65px",
|
width: "65px",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
}}>по</Typography>
|
}}
|
||||||
|
>
|
||||||
|
по
|
||||||
|
</Typography>
|
||||||
<DesktopDatePicker
|
<DesktopDatePicker
|
||||||
inputFormat="DD/MM/YYYY"
|
inputFormat="DD/MM/YYYY"
|
||||||
value={endDate}
|
value={endDate}
|
||||||
onChange={(e) => { if (e) { setEndDate(e); } }}
|
onChange={(e) => {
|
||||||
|
if (e) {
|
||||||
|
setEndDate(e);
|
||||||
|
}
|
||||||
|
}}
|
||||||
renderInput={(params) => <TextField {...params} />}
|
renderInput={(params) => <TextField {...params} />}
|
||||||
InputProps={{
|
InputProps={{
|
||||||
sx: {
|
sx: {
|
||||||
@ -68,25 +85,29 @@ export default function DatePickers() {
|
|||||||
color: theme.palette.secondary.main,
|
color: theme.palette.secondary.main,
|
||||||
border: "1px solid",
|
border: "1px solid",
|
||||||
borderColor: theme.palette.secondary.main,
|
borderColor: theme.palette.secondary.main,
|
||||||
"& .MuiSvgIcon-root": { color: theme.palette.secondary.main }
|
"& .MuiSvgIcon-root": { color: theme.palette.secondary.main },
|
||||||
}
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box sx={{
|
<Box
|
||||||
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
width: "90%",
|
width: "90%",
|
||||||
marginTop: theme.spacing(2),
|
marginTop: theme.spacing(2),
|
||||||
}}>
|
}}
|
||||||
<Box sx={{
|
>
|
||||||
|
<Box
|
||||||
|
sx={{
|
||||||
width: "20px",
|
width: "20px",
|
||||||
height: "42px",
|
height: "42px",
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
justifyContent: "left",
|
justifyContent: "left",
|
||||||
alignItems: "left",
|
alignItems: "left",
|
||||||
marginRight: theme.spacing(1)
|
marginRight: theme.spacing(1),
|
||||||
}}>
|
}}
|
||||||
|
>
|
||||||
<Checkbox
|
<Checkbox
|
||||||
sx={{
|
sx={{
|
||||||
color: theme.palette.secondary.main,
|
color: theme.palette.secondary.main,
|
||||||
@ -95,18 +116,20 @@ export default function DatePickers() {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
checked={isInfinite}
|
checked={isInfinite}
|
||||||
onClick={() => setIsInfinite(p => !p)}
|
onClick={() => setIsInfinite((p) => !p)}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<Box sx={{
|
<Box
|
||||||
|
sx={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center"
|
alignItems: "center",
|
||||||
}}>
|
}}
|
||||||
|
>
|
||||||
Бессрочно
|
Бессрочно
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
}
|
||||||
|
@ -1,10 +1,17 @@
|
|||||||
import { Typography, Container, Button, Select, MenuItem, FormControl, InputLabel, useTheme, Box } from "@mui/material";
|
|
||||||
import { useCombinedPrivileges } from "@root/hooks/useCombinedPrivileges.hook";
|
|
||||||
import { CustomTextField } from "@root/kitUI/CustomTextField";
|
|
||||||
import { Tariff } from "@root/model/tariff";
|
|
||||||
import { addTariffs } from "@root/stores/tariffs";
|
|
||||||
import { nanoid } from "nanoid";
|
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import { Typography, Container, Button, Select, MenuItem, FormControl, InputLabel, useTheme, Box } from "@mui/material";
|
||||||
|
import { nanoid } from "nanoid";
|
||||||
|
import { enqueueSnackbar } from "notistack";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
import { CustomTextField } from "@root/kitUI/CustomTextField";
|
||||||
|
|
||||||
|
import { useCombinedPrivileges } from "@root/hooks/useCombinedPrivileges.hook";
|
||||||
|
|
||||||
|
import { Tariff } from "@root/model/tariff";
|
||||||
|
|
||||||
|
import { addTariffs } from "@root/stores/tariffs";
|
||||||
|
import { authStore } from "@root/stores/auth";
|
||||||
|
|
||||||
export default function CreateTariff() {
|
export default function CreateTariff() {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@ -13,6 +20,7 @@ export default function CreateTariff() {
|
|||||||
const [customPriceField, setCustomPriceField] = useState<string>("");
|
const [customPriceField, setCustomPriceField] = useState<string>("");
|
||||||
const [privilegeIdField, setPrivilegeIdField] = useState<string>("");
|
const [privilegeIdField, setPrivilegeIdField] = useState<string>("");
|
||||||
const { mergedPrivileges, isError, errorMessage } = useCombinedPrivileges();
|
const { mergedPrivileges, isError, errorMessage } = useCombinedPrivileges();
|
||||||
|
const { token } = authStore();
|
||||||
|
|
||||||
const findPrivilegeById = (privilegeId: string) => {
|
const findPrivilegeById = (privilegeId: string) => {
|
||||||
return mergedPrivileges.find((privilege) => privilege.privilegeId === privilegeId) ?? null;
|
return mergedPrivileges.find((privilege) => privilege.privilegeId === privilegeId) ?? null;
|
||||||
@ -20,7 +28,19 @@ export default function CreateTariff() {
|
|||||||
|
|
||||||
const privilege = findPrivilegeById(privilegeIdField);
|
const privilege = findPrivilegeById(privilegeIdField);
|
||||||
|
|
||||||
|
console.log(privilege);
|
||||||
|
|
||||||
function handleCreateTariffClick() {
|
function handleCreateTariffClick() {
|
||||||
|
if (nameField === "") {
|
||||||
|
enqueueSnackbar("Пустое название тарифа");
|
||||||
|
}
|
||||||
|
if (amountField === "") {
|
||||||
|
enqueueSnackbar("Пустое кол-во едениц привилегия");
|
||||||
|
}
|
||||||
|
if (privilegeIdField === "") {
|
||||||
|
enqueueSnackbar("Невыбрана привилегия");
|
||||||
|
}
|
||||||
|
|
||||||
const amount = Number(amountField);
|
const amount = Number(amountField);
|
||||||
const customPrice = Number(customPriceField);
|
const customPrice = Number(customPriceField);
|
||||||
|
|
||||||
@ -30,15 +50,57 @@ export default function CreateTariff() {
|
|||||||
id: nanoid(5),
|
id: nanoid(5),
|
||||||
name: nameField,
|
name: nameField,
|
||||||
amount,
|
amount,
|
||||||
|
|
||||||
privilegeId: privilege.privilegeId,
|
privilegeId: privilege.privilegeId,
|
||||||
customPricePerUnit: customPrice ? customPrice / amount : undefined,
|
customPricePerUnit: customPrice ? customPrice / amount : undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
addTariffs([newTariff]);
|
addTariffs([newTariff]);
|
||||||
|
|
||||||
console.log(newTariff);
|
axios({})
|
||||||
|
.then((response) => {
|
||||||
|
console.log(response.data);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const createTariff = async () => {
|
||||||
|
try {
|
||||||
|
if (!privilege) {
|
||||||
|
throw new Error("Привилегия не выбрана");
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = await axios({
|
||||||
|
url: "https://admin.pena.digital/strator/tariff/",
|
||||||
|
method: "post",
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
name: nameField,
|
||||||
|
price: Number(customPriceField) * 100,
|
||||||
|
isCustom: false,
|
||||||
|
privilegies: [
|
||||||
|
{
|
||||||
|
name: privilege.name,
|
||||||
|
privilegeId: privilege.privilegeId,
|
||||||
|
serviceKey: privilege.serviceKey,
|
||||||
|
description: privilege.description,
|
||||||
|
type: privilege.type,
|
||||||
|
value: privilege.value,
|
||||||
|
price: privilege.price,
|
||||||
|
amount: amountField,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
enqueueSnackbar((error as Error).message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container
|
<Container
|
||||||
sx={{
|
sx={{
|
||||||
@ -74,7 +136,7 @@ export default function CreateTariff() {
|
|||||||
lineHeight: "19px",
|
lineHeight: "19px",
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Привелегия
|
Привилегия
|
||||||
</InputLabel>
|
</InputLabel>
|
||||||
{isError ? (
|
{isError ? (
|
||||||
<Typography>{errorMessage}</Typography>
|
<Typography>{errorMessage}</Typography>
|
||||||
@ -148,8 +210,11 @@ export default function CreateTariff() {
|
|||||||
type="number"
|
type="number"
|
||||||
/>
|
/>
|
||||||
<Button
|
<Button
|
||||||
onClick={handleCreateTariffClick}
|
onClick={() => {
|
||||||
disabled={privilegeIdField === "" || amountField === "" || nameField === ""}
|
handleCreateTariffClick();
|
||||||
|
createTariff();
|
||||||
|
}}
|
||||||
|
// disabled={privilegeIdField === "" || amountField === "" || nameField === ""}
|
||||||
>
|
>
|
||||||
Создать
|
Создать
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -16,6 +16,8 @@ interface Props {
|
|||||||
export default function TariffsDG({ handleSelectionChange }: Props) {
|
export default function TariffsDG({ handleSelectionChange }: Props) {
|
||||||
const tariffs = useTariffStore((state) => state.tariffs);
|
const tariffs = useTariffStore((state) => state.tariffs);
|
||||||
|
|
||||||
|
console.log(tariffs);
|
||||||
|
|
||||||
const columns: GridColDef[] = [
|
const columns: GridColDef[] = [
|
||||||
{ field: "id", headerName: "ID", width: 100 },
|
{ field: "id", headerName: "ID", width: 100 },
|
||||||
{ field: "name", headerName: "Название тарифа", width: 150 },
|
{ field: "name", headerName: "Название тарифа", width: 150 },
|
||||||
@ -34,7 +36,6 @@ export default function TariffsDG({ handleSelectionChange }: Props) {
|
|||||||
return (
|
return (
|
||||||
<IconButton
|
<IconButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
console.log(row.id);
|
|
||||||
deleteTariffs(row.id);
|
deleteTariffs(row.id);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
@ -28,7 +28,7 @@ export const exampleCartValues: ExampleCartValues = {
|
|||||||
{
|
{
|
||||||
serviceKey: "templategen",
|
serviceKey: "templategen",
|
||||||
name: "unlim",
|
name: "unlim",
|
||||||
privilegeId: "1",
|
privilegeId: "6460f329472fe2d77d5ee661",
|
||||||
description: "привилегия безлимитного доступа к шаблонизатору на время. в днях",
|
description: "привилегия безлимитного доступа к шаблонизатору на время. в днях",
|
||||||
type: "day",
|
type: "day",
|
||||||
price: 0.5,
|
price: 0.5,
|
||||||
@ -36,7 +36,7 @@ export const exampleCartValues: ExampleCartValues = {
|
|||||||
{
|
{
|
||||||
serviceKey: "templategen",
|
serviceKey: "templategen",
|
||||||
name: "gencount",
|
name: "gencount",
|
||||||
privilegeId: "2",
|
privilegeId: "6460f329472fe2d77d5ee662",
|
||||||
description: "привилегия на определённое количество генераций",
|
description: "привилегия на определённое количество генераций",
|
||||||
type: "count",
|
type: "count",
|
||||||
price: 0.1,
|
price: 0.1,
|
||||||
@ -44,7 +44,7 @@ export const exampleCartValues: ExampleCartValues = {
|
|||||||
{
|
{
|
||||||
serviceKey: "squiz",
|
serviceKey: "squiz",
|
||||||
name: "unlim",
|
name: "unlim",
|
||||||
privilegeId: "3",
|
privilegeId: "6460f329472fe2d77d5ee663",
|
||||||
description: "привилегия безлимитного доступа к опроснику. в днях",
|
description: "привилегия безлимитного доступа к опроснику. в днях",
|
||||||
type: "day",
|
type: "day",
|
||||||
price: 3.0,
|
price: 3.0,
|
||||||
@ -52,7 +52,7 @@ export const exampleCartValues: ExampleCartValues = {
|
|||||||
{
|
{
|
||||||
serviceKey: "squiz",
|
serviceKey: "squiz",
|
||||||
name: "activequiz",
|
name: "activequiz",
|
||||||
privilegeId: "4",
|
privilegeId: "6460f329472fe2d77d5ee664",
|
||||||
description: "привилегия создания ограниченного количества опросов",
|
description: "привилегия создания ограниченного количества опросов",
|
||||||
type: "count",
|
type: "count",
|
||||||
price: 1.0,
|
price: 1.0,
|
||||||
@ -60,7 +60,7 @@ export const exampleCartValues: ExampleCartValues = {
|
|||||||
{
|
{
|
||||||
serviceKey: "dwarfener",
|
serviceKey: "dwarfener",
|
||||||
name: "unlim",
|
name: "unlim",
|
||||||
privilegeId: "5",
|
privilegeId: "6460f329472fe2d77d5ee665",
|
||||||
description: "привилегия безлимитного доступа к сокращателю на время. в днях",
|
description: "привилегия безлимитного доступа к сокращателю на время. в днях",
|
||||||
type: "day",
|
type: "day",
|
||||||
price: 0.1,
|
price: 0.1,
|
||||||
@ -68,7 +68,7 @@ export const exampleCartValues: ExampleCartValues = {
|
|||||||
{
|
{
|
||||||
serviceKey: "dwarfener",
|
serviceKey: "dwarfener",
|
||||||
name: "abcount",
|
name: "abcount",
|
||||||
privilegeId: "6",
|
privilegeId: "6460f329472fe2d77d5ee666",
|
||||||
description: "привилегия на количество активных ссылок в абтестах",
|
description: "привилегия на количество активных ссылок в абтестах",
|
||||||
type: "count",
|
type: "count",
|
||||||
price: 0.7,
|
price: 0.7,
|
||||||
@ -76,7 +76,7 @@ export const exampleCartValues: ExampleCartValues = {
|
|||||||
{
|
{
|
||||||
serviceKey: "dwarfener",
|
serviceKey: "dwarfener",
|
||||||
name: "extended",
|
name: "extended",
|
||||||
privilegeId: "7",
|
privilegeId: "6460f329472fe2d77d5ee667",
|
||||||
description: "привилегия расширенной статистики, в днях",
|
description: "привилегия расширенной статистики, в днях",
|
||||||
type: "day",
|
type: "day",
|
||||||
price: 2,
|
price: 2,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { Tariff } from "@root/model/tariff";
|
import { Tariff } from "@root/model/tariff";
|
||||||
|
|
||||||
|
|
||||||
export const exampleTariffs: Tariff[] = [
|
export const exampleTariffs: Tariff[] = [
|
||||||
{
|
{
|
||||||
id: "tariffId1",
|
id: "tariffId1",
|
||||||
|
Loading…
Reference in New Issue
Block a user