валидация для тарифов, удалена кнопка камера и добавлена на главную на страницу 404

This commit is contained in:
Tamara 2023-11-14 19:29:56 +03:00
parent 99a3325b50
commit 5a7697c5aa
3 changed files with 54 additions and 26 deletions

@ -1,8 +1,9 @@
import * as React from "react";
import { Box, Typography } from "@mui/material";
import {Box, Button, Typography} from "@mui/material";
import { ThemeProvider } from "@mui/material";
import theme from "../../theme";
import CssBaseline from '@mui/material/CssBaseline';
import {Link} from "react-router-dom";
const Error404: React.FC = () => {
@ -46,6 +47,13 @@ const Error404: React.FC = () => {
4
</Typography>
</Box>
<Box>
<Link
to="/users">
<Button>На главную</Button>
</Link>
</Box>
</Box>
</Box>
</ThemeProvider>

@ -9,10 +9,9 @@ import {
InputLabel,
useTheme,
Box,
OutlinedInput
} from "@mui/material";
import { enqueueSnackbar } from "notistack";
import OutlinedInput from "@kitUI/outlinedInput";
import { CustomTextField } from "@root/kitUI/CustomTextField";
import { requestTariffs } from "@root/services/tariffs.service";
import { createTariff } from "@root/api/tariffs";
@ -43,29 +42,28 @@ export default function CreateTariff() {
const privilege = findPrivilegeById(privilegeIdField);
// const checkFulledFields = (values: Values) => {
// if (values.nameField.length === 0) {
// enqueueSnackbar("Пустое название тарифа");
// return false;
// }
// if (values.amountField.length === 0) {
// enqueueSnackbar("Пустое кол-во едениц привилегии");
// return false;
// }
// if (privilegeIdField.length === 0) {
// enqueueSnackbar("Не выбрана привилегия");
// return false;
// }
// if (!privilege) {
// enqueueSnackbar("Привилегия с таким id не найдена");
// return false;
// }
// return true;
// };
const checkFulledFields = (values: Values) => {
const errors = {nameField: "", amountField: "", privilegeIdField: ""} as any;
// values.nameField = "aa"
// values.amountField = "aa"
if (values.nameField.length === 0) {
errors.nameField = "Пустое название тарифа"
}
if (values.amountField.length === 0) {
errors.amountField = "Пустое кол-во едениц привилегии"
}
if (privilegeIdField.length === 0) {
errors.privilegeIdField = "Не выбрана привилегия"
}
console.log(values.amountField)
return errors;
};
const initialValues: Values = {
nameField: "hello",
amountField: "54",
nameField: "",
amountField: "",
customPriceField: "",
privilegeIdField: "",
};
@ -119,10 +117,11 @@ export default function CreateTariff() {
return (
<Formik
initialValues={initialValues}
validate={checkFulledFields}
onSubmit={createTariffBackend}
>
{(props) => (
<Form>
<Form style={{width: "100%"}} >
<Container
sx={{
p: "20px",
@ -131,6 +130,7 @@ export default function CreateTariff() {
display: "flex",
flexDirection: "column",
gap: "12px",
}}
>
<Typography variant="h6" sx={{ textAlign: "center", mb: "16px" }}>
@ -164,6 +164,7 @@ export default function CreateTariff() {
id="privilege-select"
value={privilegeIdField}
label="Привилегия"
error={props.touched.privilegeIdField && !!props.errors.privilegeIdField}
onChange={(e) => setPrivilegeIdField(e.target.value)}
sx={{
color: theme.palette.secondary.main,
@ -214,15 +215,29 @@ export default function CreateTariff() {
as={OutlinedInput}
id="tariff-name"
name="nameField"
variant="filled"
label="Название тарифа"
type="text"
error={props.touched.nameField && !!props.errors.nameField}
helperText={
<Typography sx={{ fontSize: "12px", width: "200px" }}>
{props.errors.nameField}
</Typography>
}
/>
<Field
as={OutlinedInput}
id="tariff-amount"
type="number"
variant="filled"
name="amountField"
label="Кол-во единиц привилегии"
error={props.touched.amountField && !!props.errors.amountField}
helperText={
<Typography sx={{ fontSize: "12px", width: "200px" }}>
{props.errors.amountField}
</Typography>
}
/>
<Field
as={OutlinedInput}
@ -238,6 +253,12 @@ export default function CreateTariff() {
>
Создать
</Button>
<Button
className="btn_createTariffBackend"
onClick={() => {console.log(props)}}
>
проверка
</Button>
</Container>
</Form>
)}

@ -106,7 +106,6 @@ const links: { path: string; element: JSX.Element; title: string; className: str
{ path: "/discounts", element: <AddPhotoAlternateOutlinedIcon />, title: "Скидки", className: "menu" },
{ path: "/promocode", element: <NaturePeopleOutlinedIcon />, title: "Промокод", className: "menu" },
{ path: "/settingRoles", element: <SettingsIcon />, title: "Настройки", className: "menu" },
{ path: "/jjj", element: <CameraIcon />, title: "Камера", className: "menu" },
{ path: "/support", element: <HeadsetMicOutlinedIcon />, title: "Служба поддержки", className: "menu" },
];