Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

M2-5293: validating date and time items values before passing to activityProgress, bug fixes #377

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/entities/applet/model/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const mapItemAnswerToUserEventResponse = (item: ItemRecord): UserEventRes
}

if (responseType === "timeRange") {
const fromDate = new Date(itemAnswer[0])
const fromDate = itemAnswer[0] ? new Date(itemAnswer[0]) : new Date()
const toDate = itemAnswer[1] ? new Date(itemAnswer[1]) : new Date()

return {
Expand Down
17 changes: 15 additions & 2 deletions src/shared/ui/Items/Date/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
import { useCallback } from "react"

import { DatePicker } from "@mui/x-date-pickers/DatePicker"

type Props = {
label?: string
value: Date | null

onChange: (value: Date | null) => void
onChange: (value: Date) => void
}

export const DateItemBase = ({ label, value, onChange }: Props) => {
return <DatePicker<Date> label={label} value={value ?? null} onChange={onChange} />
const handleChange = useCallback(
(value: Date | null) => {
const isValidDate = value !== null && !isNaN(value.getTime())

if (isValidDate) {
onChange(value)
}
},
[onChange],
)

return <DatePicker<Date> label={label} value={value ?? null} onChange={handleChange} />
}
17 changes: 15 additions & 2 deletions src/shared/ui/Items/Time/index.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import { useCallback } from "react"

import { DesktopTimePicker } from "@mui/x-date-pickers/DesktopTimePicker"

type Props = {
label?: string
value?: string
onChange: (value: Date | null) => void
onChange: (value: Date) => void
}

export const TimeItemBase = ({ label, value, onChange }: Props) => {
const formatedValue = value ? new Date(value) : null

const handleChange = useCallback(
(value: Date | null) => {
const isValidDate = value !== null && !isNaN(value.getTime())

if (isValidDate) {
onChange(value)
}
},
[onChange],
)

return (
<DesktopTimePicker<Date>
label={label}
value={formatedValue}
onChange={onChange}
onChange={handleChange}
slotProps={{ textField: { placeholder: "HH:MM AM/PM" } }}
/>
)
Expand Down