Skip to content

Commit

Permalink
Fixes after internal review
Browse files Browse the repository at this point in the history
  • Loading branch information
zDudaHang committed Oct 15, 2024
1 parent af332c8 commit f9e12b1
Showing 1 changed file with 26 additions and 51 deletions.
77 changes: 26 additions & 51 deletions src/components/MonthRangePicker/MonthRangePicker.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,39 @@ export default {
title: 'Components/MonthRangePicker',
}

export const Default = () => {
const [range, setRange] = useState<ReferenceMonthRange>(initialValue)
const handleChange = (setRange: (referenceMonthRange: ReferenceMonthRange) => void) => (dateRange: DateRange) => {
const { startDate, endDate } = dateRange

const handleChange = (dateRange: DateRange) => {
const { startDate, endDate } = dateRange
if (startDate && endDate) {
setRange({
start: { month: startDate.getMonth(), year: startDate.getFullYear() },
end: { month: endDate.getMonth(), year: endDate.getFullYear() },
})
} else if (startDate) {
setRange({
start: { month: startDate.getMonth(), year: startDate.getFullYear() },
end: undefined,
})
} else if (endDate) {
setRange({
start: undefined,
end: { month: endDate.getMonth(), year: endDate.getFullYear() },
})
} else {
setRange({ start: undefined, end: undefined })
}

if (startDate && endDate) {
setRange({
start: { month: startDate.getMonth(), year: startDate.getFullYear() },
end: { month: endDate.getMonth(), year: endDate.getFullYear() },
})
} else if (startDate) {
setRange({
start: { month: startDate.getMonth(), year: startDate.getFullYear() },
end: undefined,
})
} else if (endDate) {
setRange({
start: undefined,
end: { month: endDate.getMonth(), year: endDate.getFullYear() },
})
} else {
setRange({ start: undefined, end: undefined })
}
action('changed')(dateRange)
}

action('changed')(dateRange)
}
export const Default = () => {
const [range, setRange] = useState<ReferenceMonthRange>(initialValue)

return (
<MonthRangePicker
label={text('label', 'Month Field')}
error={text('error', '')}
onChange={handleChange}
onChange={(dateRange) => handleChange(setRange)(dateRange)}
inline={boolean('inline', false)}
required={boolean('required', false)}
disabled={boolean('disabled', false)}
Expand All @@ -60,36 +60,11 @@ export const Default = () => {
export const MinMax = () => {
const [range, setRange] = useState<ReferenceMonthRange>(initialValue)

const handleChange = (dateRange: DateRange) => {
const { startDate, endDate } = dateRange

if (startDate && endDate) {
setRange({
start: { month: startDate.getMonth(), year: startDate.getFullYear() },
end: { month: endDate.getMonth(), year: endDate.getFullYear() },
})
} else if (startDate) {
setRange({
start: { month: startDate.getMonth(), year: startDate.getFullYear() },
end: undefined,
})
} else if (endDate) {
setRange({
start: undefined,
end: { month: endDate.getMonth(), year: endDate.getFullYear() },
})
} else {
setRange({ start: undefined, end: undefined })
}

action('changed')(dateRange)
}

return (
<MonthRangePicker
label={text('label', 'Month Field')}
error={text('error', '')}
onChange={handleChange}
onChange={(dateRange) => handleChange(setRange)(dateRange)}
disabled={boolean('disabled', false)}
value={range}
minMonth={object('minMonth', minMonth)}
Expand Down

0 comments on commit f9e12b1

Please sign in to comment.