@@ -1,7 +1,7 @@ import React, { useState } from 'react' import { Box, TextField, Typography } from '@mui/material' import axios from 'axios' -import { Dayjs } from 'dayjs' +import dayjs, { Dayjs } from 'dayjs' import { useRouter } from 'next/navigation' import { useSession } from 'next-auth/react' @@ -38,6 +38,11 @@ export const ApiKeyModal = ({ const keyName = `Ключ ${Math.floor(Math.random() * 100000) + 1}` + if (endDate && dayjs(endDate).isBefore(dayjs(), 'day')) { + showMessage('Указана неверная дата') + return + } + setIsLoading(true) const response = endDate && endDate !== '' @@ -5,9 +5,12 @@ import { useSession } from 'next-auth/react' import { TooltipCustom } from '#/shared' import { getApiUrl } from '#/shared/lib/constants' +import { useShowDataStore } from '#/shared/lib/hooks/use-show-data' import { InputStyleSmallDark } from '#/shared/ui/input' import axios from 'axios' +const isValidLimit = (value: string) => value === '' || /^[1-9]\d*$/.test(value) + export type KeyItemBaseProps = { keyValue: string name: string @@ -32,6 +35,7 @@ export const KeyItem: React.FC = ({ children, limit: initialLimit, const [isCopy, setIsCopy] = useState(false) const [limit, setLimit] = useState(initialLimit) const { data: session } = useSession() + const { showMessage } = useShowDataStore() useEffect(() => { setLimit(initialLimit) @@ -72,6 +76,10 @@ export const KeyItem: React.FC = ({ children, limit: initialLimit, }, [initialLimit, limit, name, session?.access]) const handleLimitChange = (value: string) => { + if (!isValidLimit(value)) { + showMessage('Укажите целое число больше нуля') + return + } setLimit(value) }