mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-21 11:20:17 -04:00
event creator includes recurring events!
This commit is contained in:
parent
3fc96ca3d4
commit
c0a00945ef
|
@ -4,6 +4,7 @@ import { toggleBit } from './bits';
|
||||||
import { green, lightgrey } from './colors';
|
import { green, lightgrey } from './colors';
|
||||||
import { IGroup } from './Group';
|
import { IGroup } from './Group';
|
||||||
import UIButton from './UIButton';
|
import UIButton from './UIButton';
|
||||||
|
import UIDateInput from './UIDateInput';
|
||||||
import UIDatetimeInput from './UIDatetimeInput';
|
import UIDatetimeInput from './UIDatetimeInput';
|
||||||
import UIPlacesAutocomplete from './UIPlacesAutocomplete';
|
import UIPlacesAutocomplete from './UIPlacesAutocomplete';
|
||||||
import UISecondaryBox from './UISecondaryBox';
|
import UISecondaryBox from './UISecondaryBox';
|
||||||
|
@ -86,12 +87,14 @@ export default function EventCreator({ group }: { group: IGroup }) {
|
||||||
|
|
||||||
const [recurring, toggleRecurring] = useToggle(false);
|
const [recurring, toggleRecurring] = useToggle(false);
|
||||||
const [daysOfWeek, setDaysOfWeek] = useState(0);
|
const [daysOfWeek, setDaysOfWeek] = useState(0);
|
||||||
|
const [endDate, setEndDate] = useState<Date | null>(null);
|
||||||
|
|
||||||
const buttonEnabled =
|
const buttonEnabled =
|
||||||
name.length > 0 &&
|
name.length > 0 &&
|
||||||
startTime != null &&
|
startTime != null &&
|
||||||
endTime != null &&
|
endTime != null &&
|
||||||
placeId != null &&
|
placeId != null &&
|
||||||
|
(!recurring || daysOfWeek || endDate !== null) &&
|
||||||
!creating;
|
!creating;
|
||||||
|
|
||||||
const createEvent = useCallback(() => {
|
const createEvent = useCallback(() => {
|
||||||
|
@ -139,12 +142,18 @@ export default function EventCreator({ group }: { group: IGroup }) {
|
||||||
backgroundColor: recurring ? green : lightgrey,
|
backgroundColor: recurring ? green : lightgrey,
|
||||||
color: recurring ? 'white' : 'black',
|
color: recurring ? 'white' : 'black',
|
||||||
transition: 'color 0.2s, background-color 0.2s',
|
transition: 'color 0.2s, background-color 0.2s',
|
||||||
|
marginBottom: '1.5rem',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Recurring event
|
Recurring event
|
||||||
</UIButton>
|
</UIButton>
|
||||||
{recurring && (
|
{recurring && (
|
||||||
<DaysOfWeekSelector daysOfWeek={daysOfWeek} update={setDaysOfWeek} />
|
<>
|
||||||
|
Days of week
|
||||||
|
<DaysOfWeekSelector daysOfWeek={daysOfWeek} update={setDaysOfWeek} />
|
||||||
|
Date of last occurence
|
||||||
|
<UIDateInput onChangedDate={setEndDate} />
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
{createdEventId === -1 ? (
|
{createdEventId === -1 ? (
|
||||||
<UIButton
|
<UIButton
|
||||||
|
|
44
src/components/NewUI/UIDateInput.tsx
Normal file
44
src/components/NewUI/UIDateInput.tsx
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
|
const baseStyle = {
|
||||||
|
marginTop: '0.5em',
|
||||||
|
padding: '0.5em',
|
||||||
|
fontFamily: 'Inter',
|
||||||
|
fontSize: '1.25rem',
|
||||||
|
borderRadius: '0.5em',
|
||||||
|
border: '0px',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function UIDateInput({
|
||||||
|
onChangedDate,
|
||||||
|
disabled = false,
|
||||||
|
}: {
|
||||||
|
onChangedDate: (date: Date | null) => void;
|
||||||
|
disabled?: boolean;
|
||||||
|
}) {
|
||||||
|
const onChange = useCallback(
|
||||||
|
(e) => {
|
||||||
|
// YYYY-MM-DD or "" (empty string)
|
||||||
|
const dateAsString = e.target.value as string;
|
||||||
|
if (typeof dateAsString !== 'string' || dateAsString.length === 0) {
|
||||||
|
onChangedDate(null);
|
||||||
|
}
|
||||||
|
const year = dateAsString.slice(0, 4);
|
||||||
|
const month = dateAsString.slice(5, 7);
|
||||||
|
const day = dateAsString.slice(8, 10);
|
||||||
|
|
||||||
|
// Midnight in the timezone of the user
|
||||||
|
const date = new Date(`${year}-${month}-${day}T00:00:00`);
|
||||||
|
onChangedDate(date);
|
||||||
|
},
|
||||||
|
[onChangedDate]
|
||||||
|
);
|
||||||
|
return (
|
||||||
|
<input
|
||||||
|
style={baseStyle}
|
||||||
|
type="date"
|
||||||
|
disabled={disabled}
|
||||||
|
onChange={onChange}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user