From 2aa014aefc9eb3ca404a1dc58071580534d3c81f Mon Sep 17 00:00:00 2001 From: ArtChaos189 Date: Wed, 7 Jun 2023 15:46:56 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=82=D0=B0=D1=80=D0=B8=D1=84=D0=B0=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B1=D1=8D=D0=BA=D0=B5=D0=BD=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Authorization/signin.tsx | 291 +++++++++--------- .../DiscountManagement/DatePickers.tsx | 235 +++++++------- .../Content/Tariffs/CreateTariff.tsx | 85 ++++- src/pages/dashboard/Content/Tariffs/index.tsx | 44 +-- .../dashboard/Content/Tariffs/tariffsDG.tsx | 3 +- src/stores/mocks/exampleCartValues.ts | 14 +- src/stores/mocks/tariffs.ts | 53 ++-- 7 files changed, 408 insertions(+), 317 deletions(-) diff --git a/src/pages/Authorization/signin.tsx b/src/pages/Authorization/signin.tsx index fe748f9..5401d41 100644 --- a/src/pages/Authorization/signin.tsx +++ b/src/pages/Authorization/signin.tsx @@ -11,164 +11,167 @@ import LockOutlinedIcon from "@mui/icons-material/LockOutlined"; import { authStore } from "@root/stores/auth"; interface Values { - email: string; - password: string; + email: string; + password: string; } function validate(values: Values) { - const errors = {} as any; + const errors = {} as any; - if (!values.email) { - errors.email = "Required"; - } + if (!values.email) { + errors.email = "Required"; + } - if (!values.password) { - errors.password = "Required"; - } + if (!values.password) { + errors.password = "Required"; + } - if (values.password && !/^[\S]{8,25}$/i.test(values.password)) { - errors.password = "Invalid password"; - } + if (values.password && !/^[\S]{8,25}$/i.test(values.password)) { + errors.password = "Invalid password"; + } - return errors; + return errors; } const SigninForm = () => { - const theme = useTheme(); - const navigate = useNavigate(); + const theme = useTheme(); + const navigate = useNavigate(); - const { makeRequest } = authStore(); + const { makeRequest } = authStore(); - const initialValues: Values = { - email: "", - password: "", - }; + const initialValues: Values = { + email: "", + password: "", + }; - const onSignFormSubmit = (values: Values, formikHelpers: FormikHelpers) => { - formikHelpers.setSubmitting(true); - makeRequest({ - url: "https://admin.pena.digital/auth/login", - body: { - email: values.email, - password: values.password, - }, - useToken: false, - }) - .then((e) => { - navigate("/users"); - }) - .catch((e) => { - console.log(e); - enqueueSnackbar(e.message ? e.message : `Unknown error`); - }).finally(() => { - formikHelpers.setSubmitting(false); - }); - }; + const onSignFormSubmit = (values: Values, formikHelpers: FormikHelpers) => { + formikHelpers.setSubmitting(true); + makeRequest({ + url: "https://admin.pena.digital/auth/login", + body: { + login: values.email, + password: values.password, + }, + useToken: false, + }) + .then((e) => { + navigate("/users"); + }) + .catch((e) => { + console.log(e); + enqueueSnackbar(e.message ? e.message : `Unknown error`); + }) + .finally(() => { + formikHelpers.setSubmitting(false); + }); + }; - return ( - - {props => -
- - *": { - marginTop: "15px", - }, - }} - > - - - - Добро пожаловать - - - Мы рады что вы выбрали нас! - - - *": { marginRight: "10px" } }}> - - - - *": { marginRight: "10px" } }}> - - - - - - } - label="Запомнить этот компьютер" - /> - - - Забыли пароль? - - - - У вас нет аккаунта?  - - Зарегестрируйтесь - - - - -
- } -
- ); + return ( + + {(props) => ( +
+ + *": { + marginTop: "15px", + }, + }} + > + + + + Добро пожаловать + + + Мы рады что вы выбрали нас! + + + *": { marginRight: "10px" } }}> + + + + *": { marginRight: "10px" } }}> + + + + + + } + label="Запомнить этот компьютер" + /> + + + Забыли пароль? + + + + У вас нет аккаунта?  + + Зарегестрируйтесь + + + + +
+ )} +
+ ); }; export default SigninForm; diff --git a/src/pages/dashboard/Content/DiscountManagement/DatePickers.tsx b/src/pages/dashboard/Content/DiscountManagement/DatePickers.tsx index 2749c1f..c769219 100644 --- a/src/pages/dashboard/Content/DiscountManagement/DatePickers.tsx +++ b/src/pages/dashboard/Content/DiscountManagement/DatePickers.tsx @@ -2,111 +2,134 @@ import { Box, Checkbox, TextField, Typography, useTheme } from "@mui/material"; import { DesktopDatePicker } from "@mui/x-date-pickers/DesktopDatePicker"; import { useState } from "react"; - export default function DatePickers() { - const theme = useTheme(); - const [isInfinite, setIsInfinite] = useState(false); - const [startDate, setStartDate] = useState(new Date()); - const [endDate, setEndDate] = useState(new Date()); + const theme = useTheme(); + const [isInfinite, setIsInfinite] = useState(false); + const [startDate, setStartDate] = useState(new Date()); + const [endDate, setEndDate] = useState(new Date()); - - return ( - <> - - Дата действия: - - - С - { if (e) { setStartDate(e); } }} - renderInput={(params) => } - InputProps={{ - sx: { - height: "40px", - color: theme.palette.secondary.main, - border: "1px solid", - borderColor: theme.palette.secondary.main, - "& .MuiSvgIcon-root": { color: theme.palette.secondary.main } - } - }} - /> - по - { if (e) { setEndDate(e); } }} - renderInput={(params) => } - InputProps={{ - sx: { - height: "40px", - color: theme.palette.secondary.main, - border: "1px solid", - borderColor: theme.palette.secondary.main, - "& .MuiSvgIcon-root": { color: theme.palette.secondary.main } - } - }} - /> - - - - setIsInfinite(p => !p)} - /> - - - Бессрочно - - - - ); -}; \ No newline at end of file + return ( + <> + + Дата действия: + + + + С + + { + if (e) { + setStartDate(e); + } + }} + renderInput={(params) => } + InputProps={{ + sx: { + height: "40px", + color: theme.palette.secondary.main, + border: "1px solid", + borderColor: theme.palette.secondary.main, + "& .MuiSvgIcon-root": { color: theme.palette.secondary.main }, + }, + }} + /> + + по + + { + if (e) { + setEndDate(e); + } + }} + renderInput={(params) => } + InputProps={{ + sx: { + height: "40px", + color: theme.palette.secondary.main, + border: "1px solid", + borderColor: theme.palette.secondary.main, + "& .MuiSvgIcon-root": { color: theme.palette.secondary.main }, + }, + }} + /> + + + + setIsInfinite((p) => !p)} + /> + + + Бессрочно + + + + ); +} diff --git a/src/pages/dashboard/Content/Tariffs/CreateTariff.tsx b/src/pages/dashboard/Content/Tariffs/CreateTariff.tsx index 44e99d1..26db5fe 100644 --- a/src/pages/dashboard/Content/Tariffs/CreateTariff.tsx +++ b/src/pages/dashboard/Content/Tariffs/CreateTariff.tsx @@ -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 { 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() { const theme = useTheme(); @@ -13,6 +20,7 @@ export default function CreateTariff() { const [customPriceField, setCustomPriceField] = useState(""); const [privilegeIdField, setPrivilegeIdField] = useState(""); const { mergedPrivileges, isError, errorMessage } = useCombinedPrivileges(); + const { token } = authStore(); const findPrivilegeById = (privilegeId: string) => { return mergedPrivileges.find((privilege) => privilege.privilegeId === privilegeId) ?? null; @@ -20,7 +28,19 @@ export default function CreateTariff() { const privilege = findPrivilegeById(privilegeIdField); + console.log(privilege); + function handleCreateTariffClick() { + if (nameField === "") { + enqueueSnackbar("Пустое название тарифа"); + } + if (amountField === "") { + enqueueSnackbar("Пустое кол-во едениц привилегия"); + } + if (privilegeIdField === "") { + enqueueSnackbar("Невыбрана привилегия"); + } + const amount = Number(amountField); const customPrice = Number(customPriceField); @@ -30,15 +50,57 @@ export default function CreateTariff() { id: nanoid(5), name: nameField, amount, + privilegeId: privilege.privilegeId, customPricePerUnit: customPrice ? customPrice / amount : undefined, }; 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 ( - Привелегия + Привилегия {isError ? ( {errorMessage} @@ -148,8 +210,11 @@ export default function CreateTariff() { type="number" /> diff --git a/src/pages/dashboard/Content/Tariffs/index.tsx b/src/pages/dashboard/Content/Tariffs/index.tsx index 847be3a..c9ec9e7 100644 --- a/src/pages/dashboard/Content/Tariffs/index.tsx +++ b/src/pages/dashboard/Content/Tariffs/index.tsx @@ -10,27 +10,27 @@ import CreateTariff from "./CreateTariff"; import ChangePriceModal from "./Privileges/ChangePriceModal"; export default function Tariffs() { - const [selectedTariffs, setSelectedTariffs] = useState([]); + const [selectedTariffs, setSelectedTariffs] = useState([]); - return ( - - Список привелегий - - - - - Список тарифов - - setSelectedTariffs(selectionModel)} /> - - - ); + return ( + + Список привелегий + + + + + Список тарифов + + setSelectedTariffs(selectionModel)} /> + + + ); } diff --git a/src/pages/dashboard/Content/Tariffs/tariffsDG.tsx b/src/pages/dashboard/Content/Tariffs/tariffsDG.tsx index 2d63cc3..8d789e3 100644 --- a/src/pages/dashboard/Content/Tariffs/tariffsDG.tsx +++ b/src/pages/dashboard/Content/Tariffs/tariffsDG.tsx @@ -16,6 +16,8 @@ interface Props { export default function TariffsDG({ handleSelectionChange }: Props) { const tariffs = useTariffStore((state) => state.tariffs); + console.log(tariffs); + const columns: GridColDef[] = [ { field: "id", headerName: "ID", width: 100 }, { field: "name", headerName: "Название тарифа", width: 150 }, @@ -34,7 +36,6 @@ export default function TariffsDG({ handleSelectionChange }: Props) { return ( { - console.log(row.id); deleteTariffs(row.id); }} > diff --git a/src/stores/mocks/exampleCartValues.ts b/src/stores/mocks/exampleCartValues.ts index 3633a7d..345d5c1 100644 --- a/src/stores/mocks/exampleCartValues.ts +++ b/src/stores/mocks/exampleCartValues.ts @@ -28,7 +28,7 @@ export const exampleCartValues: ExampleCartValues = { { serviceKey: "templategen", name: "unlim", - privilegeId: "1", + privilegeId: "6460f329472fe2d77d5ee661", description: "привилегия безлимитного доступа к шаблонизатору на время. в днях", type: "day", price: 0.5, @@ -36,7 +36,7 @@ export const exampleCartValues: ExampleCartValues = { { serviceKey: "templategen", name: "gencount", - privilegeId: "2", + privilegeId: "6460f329472fe2d77d5ee662", description: "привилегия на определённое количество генераций", type: "count", price: 0.1, @@ -44,7 +44,7 @@ export const exampleCartValues: ExampleCartValues = { { serviceKey: "squiz", name: "unlim", - privilegeId: "3", + privilegeId: "6460f329472fe2d77d5ee663", description: "привилегия безлимитного доступа к опроснику. в днях", type: "day", price: 3.0, @@ -52,7 +52,7 @@ export const exampleCartValues: ExampleCartValues = { { serviceKey: "squiz", name: "activequiz", - privilegeId: "4", + privilegeId: "6460f329472fe2d77d5ee664", description: "привилегия создания ограниченного количества опросов", type: "count", price: 1.0, @@ -60,7 +60,7 @@ export const exampleCartValues: ExampleCartValues = { { serviceKey: "dwarfener", name: "unlim", - privilegeId: "5", + privilegeId: "6460f329472fe2d77d5ee665", description: "привилегия безлимитного доступа к сокращателю на время. в днях", type: "day", price: 0.1, @@ -68,7 +68,7 @@ export const exampleCartValues: ExampleCartValues = { { serviceKey: "dwarfener", name: "abcount", - privilegeId: "6", + privilegeId: "6460f329472fe2d77d5ee666", description: "привилегия на количество активных ссылок в абтестах", type: "count", price: 0.7, @@ -76,7 +76,7 @@ export const exampleCartValues: ExampleCartValues = { { serviceKey: "dwarfener", name: "extended", - privilegeId: "7", + privilegeId: "6460f329472fe2d77d5ee667", description: "привилегия расширенной статистики, в днях", type: "day", price: 2, diff --git a/src/stores/mocks/tariffs.ts b/src/stores/mocks/tariffs.ts index 61b811a..6b50910 100644 --- a/src/stores/mocks/tariffs.ts +++ b/src/stores/mocks/tariffs.ts @@ -1,30 +1,29 @@ import { Tariff } from "@root/model/tariff"; - export const exampleTariffs: Tariff[] = [ - { - id: "tariffId1", - name: "Tariff 1", - privilegeId: "p1", - amount: 1000, - }, - { - id: "tariffId2", - name: "Tariff 2", - privilegeId: "p2", - amount: 2000, - customPricePerUnit: 3, - }, - { - id: "tariffId3", - name: "Tariff 3", - privilegeId: "p3", - amount: 3000, - }, - { - id: "tariffId4", - name: "Tariff 4", - privilegeId: "p6", - amount: 4000, - }, -]; \ No newline at end of file + { + id: "tariffId1", + name: "Tariff 1", + privilegeId: "p1", + amount: 1000, + }, + { + id: "tariffId2", + name: "Tariff 2", + privilegeId: "p2", + amount: 2000, + customPricePerUnit: 3, + }, + { + id: "tariffId3", + name: "Tariff 3", + privilegeId: "p3", + amount: 3000, + }, + { + id: "tariffId4", + name: "Tariff 4", + privilegeId: "p6", + amount: 4000, + }, +];