рефакторинг
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Badge } from '@/component/ui/badge'
|
||||
import { Button } from '@/component/ui/button'
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/component/ui/card'
|
||||
import { Input } from '@/component/ui/input'
|
||||
import { Label } from '@/component/ui/label'
|
||||
import { ElementDefinition } from '@/lib/element-registry'
|
||||
import {
|
||||
AlertCircle,
|
||||
@@ -91,7 +91,7 @@ const formatLastUpdated = (dateString: string) => {
|
||||
const monthShortRu = date
|
||||
.toLocaleString('ru-RU', { month: 'short' })
|
||||
.replace(/\./, '')
|
||||
.replace(/^./, (s) => s.toUpperCase())
|
||||
.replace(/^./, s => s.toUpperCase())
|
||||
const day = date.getDate()
|
||||
const time: string = date.toLocaleString('ru-RU', {
|
||||
hour: '2-digit',
|
||||
@@ -103,8 +103,8 @@ const formatLastUpdated = (dateString: string) => {
|
||||
} else if (date.toDateString() === yesterday.toDateString()) {
|
||||
return `Вчера в ${time}`
|
||||
} else {
|
||||
return `${weekdayRu.replace(/^./, (s) =>
|
||||
s.toUpperCase(),
|
||||
return `${weekdayRu.replace(/^./, s =>
|
||||
s.toUpperCase()
|
||||
)} ${day} ${monthShortRu} ${time}`
|
||||
}
|
||||
}
|
||||
@@ -136,10 +136,10 @@ function CalibrationCondInfo({
|
||||
'frequency',
|
||||
]
|
||||
|
||||
fields.forEach((field) => {
|
||||
fields.forEach(field => {
|
||||
const validation = validateField(
|
||||
field,
|
||||
tempConditions[field as keyof CalibrationConditions] as string,
|
||||
tempConditions[field as keyof CalibrationConditions] as string
|
||||
)
|
||||
if (!validation.isValid && validation.message) {
|
||||
errors[field] = validation.message
|
||||
@@ -151,11 +151,11 @@ function CalibrationCondInfo({
|
||||
}
|
||||
|
||||
const handleFieldChange = (field: string, value: string) => {
|
||||
setTempConditions((prev) => ({ ...prev, [field]: value }))
|
||||
setTempConditions(prev => ({ ...prev, [field]: value }))
|
||||
|
||||
// Валидация в реальном времени
|
||||
const validation = validateField(field, value)
|
||||
setValidationErrors((prev) => ({
|
||||
setValidationErrors(prev => ({
|
||||
...prev,
|
||||
[field]: validation.isValid ? '' : validation.message || '',
|
||||
}))
|
||||
@@ -187,7 +187,7 @@ function CalibrationCondInfo({
|
||||
// Устанавливаем фокус на первое поле через небольшую задержку
|
||||
setTimeout(() => {
|
||||
const firstInput = document.getElementById(
|
||||
'modal-temperature',
|
||||
'modal-temperature'
|
||||
) as HTMLInputElement
|
||||
if (firstInput) {
|
||||
firstInput.focus()
|
||||
@@ -199,7 +199,7 @@ function CalibrationCondInfo({
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (
|
||||
e.key === 'Enter' &&
|
||||
!Object.keys(validationErrors).some((key) => validationErrors[key])
|
||||
!Object.keys(validationErrors).some(key => validationErrors[key])
|
||||
) {
|
||||
handleSave()
|
||||
}
|
||||
@@ -321,10 +321,10 @@ function CalibrationCondInfo({
|
||||
key as keyof CalibrationConditions
|
||||
] as string
|
||||
}
|
||||
onChange={(e) =>
|
||||
onChange={e =>
|
||||
handleFieldChange(key, e.target.value)
|
||||
}
|
||||
onKeyDown={(e) => {
|
||||
onKeyDown={e => {
|
||||
if (e.key === 'Enter') {
|
||||
e.preventDefault()
|
||||
handleSave()
|
||||
@@ -334,8 +334,8 @@ function CalibrationCondInfo({
|
||||
hasError
|
||||
? 'border-destructive focus-visible:ring-destructive'
|
||||
: isValid
|
||||
? 'border-green-500 focus-visible:ring-green-500'
|
||||
: ''
|
||||
? 'border-green-500 focus-visible:ring-green-500'
|
||||
: ''
|
||||
}`}
|
||||
placeholder={placeholder}
|
||||
type="number"
|
||||
@@ -361,7 +361,7 @@ function CalibrationCondInfo({
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
}
|
||||
)}
|
||||
</div>
|
||||
|
||||
@@ -385,7 +385,7 @@ function CalibrationCondInfo({
|
||||
disabled={
|
||||
isLoading ||
|
||||
Object.keys(validationErrors).some(
|
||||
(key) => validationErrors[key],
|
||||
key => validationErrors[key]
|
||||
)
|
||||
}
|
||||
>
|
||||
@@ -463,7 +463,7 @@ export const calibrationConditionsDefinition: ElementDefinition<
|
||||
<Input
|
||||
type="number"
|
||||
value={config.defaultConditions?.temperature || '20'}
|
||||
onChange={(e) =>
|
||||
onChange={e =>
|
||||
onChange({
|
||||
...config,
|
||||
defaultConditions: {
|
||||
@@ -489,7 +489,7 @@ export const calibrationConditionsDefinition: ElementDefinition<
|
||||
<Input
|
||||
type="number"
|
||||
value={config.defaultConditions?.humidity || '65'}
|
||||
onChange={(e) =>
|
||||
onChange={e =>
|
||||
onChange({
|
||||
...config,
|
||||
defaultConditions: {
|
||||
@@ -515,7 +515,7 @@ export const calibrationConditionsDefinition: ElementDefinition<
|
||||
<Input
|
||||
type="number"
|
||||
value={config.defaultConditions?.pressure || '101.3'}
|
||||
onChange={(e) =>
|
||||
onChange={e =>
|
||||
onChange({
|
||||
...config,
|
||||
defaultConditions: {
|
||||
@@ -541,7 +541,7 @@ export const calibrationConditionsDefinition: ElementDefinition<
|
||||
<Input
|
||||
type="number"
|
||||
value={config.defaultConditions?.voltage || '220'}
|
||||
onChange={(e) =>
|
||||
onChange={e =>
|
||||
onChange({
|
||||
...config,
|
||||
defaultConditions: {
|
||||
@@ -567,7 +567,7 @@ export const calibrationConditionsDefinition: ElementDefinition<
|
||||
<Input
|
||||
type="number"
|
||||
value={config.defaultConditions?.frequency || '50'}
|
||||
onChange={(e) =>
|
||||
onChange={e =>
|
||||
onChange({
|
||||
...config,
|
||||
defaultConditions: {
|
||||
@@ -632,7 +632,7 @@ export const calibrationConditionsDefinition: ElementDefinition<
|
||||
<CalibrationCondInfo
|
||||
conditions={conditions}
|
||||
isOutdated={isOutdated}
|
||||
onUpdate={async (newConditions) => {
|
||||
onUpdate={async newConditions => {
|
||||
onChange?.(newConditions)
|
||||
return true
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user