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

[MM-73]: Fixed the issue of getting invalid start/end time even though they were set #79

Merged
merged 6 commits into from
Jun 14, 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
7 changes: 4 additions & 3 deletions webapp/src/components/modals/create_event_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {Modal} from 'react-bootstrap';

import {getTheme} from 'mattermost-redux/selectors/entities/preferences';

import ChannelSelector from '../channel_selector';

import {CreateEventPayload} from '@/types/calendar_api_types';

import {getModalStyles} from '@/utils/styles';
Expand All @@ -17,7 +19,6 @@ import Loading from '@/components/loading';
import Setting from '@/components/setting';
import AttendeeSelector from '@/components/attendee_selector';
import TimeSelector from '@/components/time_selector';
import ChannelSelector from '../channel_selector';
import {capitalizeFirstCharacter} from '@/utils/text';
import {CreateCalendarEventResponse, createCalendarEvent} from '@/actions';
import {getTodayString} from '@/utils/datetime';
Expand Down Expand Up @@ -221,7 +222,7 @@ const ActualForm = (props: ActualFormProps) => {
value={formValues.start_time}
endTime={formValues.end_time}
date={formValues.date}
onChange={(value) => setFormValue('start_time', value)}
onChange={(name: keyof CreateEventPayload, value: string) => setFormValue(name, value)}
/>
),
},
Expand All @@ -233,7 +234,7 @@ const ActualForm = (props: ActualFormProps) => {
value={formValues.end_time}
startTime={formValues.start_time}
date={formValues.date}
onChange={(value) => setFormValue('end_time', value)}
onChange={(name: keyof CreateEventPayload, value: string) => setFormValue(name, value)}
/>
),
},
Expand Down
17 changes: 14 additions & 3 deletions webapp/src/components/time_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import {useSelector} from 'react-redux';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';

import {getTodayString} from '@/utils/datetime';
import {CreateEventPayload} from '@/types/calendar_api_types';

import ReactSelectSetting from './react_select_setting';

const minuteStep = 15;

type Props = {
value: string;
onChange: (value: string) => void;
onChange: (name: keyof CreateEventPayload, value: string) => void;
startTime?: string
endTime?: string
date?: string
Expand Down Expand Up @@ -69,13 +70,23 @@ export default function TimeSelector(props: Props) {
}));
}, [props.startTime, props.endTime, props.date]);

let value: Option | undefined | null = options[0];
let value: Option | undefined | null;
Kshitij-Katiyar marked this conversation as resolved.
Show resolved Hide resolved
if (props.value) {
value = options.find((option: Option) => option.value === props.value);
}

const handleChange = (_: string, newValue: string) => {
props.onChange(newValue);
if (props.startTime) {
props.onChange('end_time', newValue);
} else {
props.onChange('start_time', newValue);

options.forEach((option: Option, i: number) => {
if (option.value === newValue && i + 2 < options.length) {
props.onChange('end_time', options[i + 2].value);
}
});
}
};

return (
Expand Down