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

fix: input problem on appointment creation on safari #322

Merged
merged 2 commits into from
Aug 10, 2023
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
17 changes: 9 additions & 8 deletions src/pages/create-appointment/AppointmentForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Box, FormControl, Select, Stack, TextArea, useBreakpointValue, VStack, WarningTwoIcon } from 'native-base';
import { Box, FormControl, Stack, TextArea, useBreakpointValue, VStack, WarningTwoIcon } from 'native-base';
import { useTranslation } from 'react-i18next';
import DatePicker from '../../components/DatePicker';
import { useCreateAppointment } from '../../context/AppointmentContext';
Expand All @@ -9,6 +9,7 @@ import { useCallback, useState } from 'react';
import { FormErrors } from './AppointmentCreation';
import { isDateToday } from '../../helper/appointment-helper';
import { DateTime } from 'luxon';
import Select from '../../widgets/Select';

type FormProps = {
errors: FormErrors;
Expand All @@ -26,14 +27,14 @@ const AppointmentForm: React.FC<FormProps> = ({ errors, appointmentsCount, onSet
lg: '50%',
});

const [title, setTitle] = useState('');
const [description, setDescription] = useState('');
const [date, setDate] = useState('');
const [time, setTime] = useState('');
const [title, setTitle] = useState<string>('');
const [description, setDescription] = useState<string>('');
const [date, setDate] = useState<string>('');
const [time, setTime] = useState<string>('');
const [isToday, setIsToday] = useState<boolean>(false);

const handleTitleInput = (e: any) => {
setTitle(e.target.value);
const handleTitleInput = (text: string) => {
setTitle(text);
};

const handleDurationSelection = (e: any) => {
Expand Down Expand Up @@ -138,7 +139,7 @@ const AppointmentForm: React.FC<FormProps> = ({ errors, appointmentsCount, onSet
{/* DURATION */}
<FormControl isInvalid={'duration' in errors} width={inputWidth}>
<FormControl.Label>{t('appointment.create.durationLabel')}</FormControl.Label>
<Select placeholder="Dauer der Unterrichtseinheit" onValueChange={(e) => handleDurationSelection(e)}>
<Select placeholder="Dauer der Unterrichtseinheit" onValueChange={(duration: string) => handleDurationSelection(duration)}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did this even work before? 😅

<Select.Item value="15" label={t('course.selectOptions._15minutes')} />
<Select.Item value="30" label={t('course.selectOptions._30minutes')} />
<Select.Item value="45" label={t('course.selectOptions._45minutes')} />
Expand Down
11 changes: 11 additions & 0 deletions src/widgets/Select.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Select as NBSelect } from 'native-base';

const Select = (props: any) => {
const isSafari = () => /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);

return <NBSelect {...props} selection={isSafari() ? 1 : null} />;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this hack come from? Could you add a comment, cause I do not understand how it works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I found the same issue here: GeekyAnts/NativeBase#5111
And the solution therefore is: https://github.com/spr-networks/super/blob/main/frontend/src/components/Select.web.js
I honestly cant explain to you how it works... 😅

};

Select.Item = NBSelect.Item;
export default Select;
export { Select };