Skip to content

Commit

Permalink
Merge pull request #481 from woowacourse-teams/feature/#480
Browse files Browse the repository at this point in the history
기타 탭에서 장소 추가되는 문제 해결
  • Loading branch information
ashleysyheo authored Aug 17, 2023
2 parents 1c9f43c + ba5f1fd commit 8b468fe
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/jsx-no-useless-fragment */
import type { ChangeEvent } from 'react';
import { memo } from 'react';
import { memo, useEffect } from 'react';

import { Select } from 'hang-log-design-system';

Expand All @@ -22,6 +22,14 @@ interface DateInputProps {
const DateInput = ({ currentCategory, tripId, dayLogId, updateInputValue }: DateInputProps) => {
const { dates } = useTripDates(tripId);

useEffect(() => {
const indexOfDayLogId = dates.findIndex((date) => date.id === dayLogId);

if (indexOfDayLogId === dates.length - 1 || indexOfDayLogId === -1) {
updateInputValue('dayLogId', dates[0].id);
}
}, [dates, dayLogId, updateInputValue]);

const handleDateChange = (event: ChangeEvent<HTMLSelectElement>) => {
updateInputValue('dayLogId', Number(event.target.value));
};
Expand Down

0 comments on commit 8b468fe

Please sign in to comment.