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

Allow campaigns to be created in the past (admin console only). #269

Merged
merged 3 commits into from
Oct 22, 2022
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
2 changes: 1 addition & 1 deletion frontend/components/campaigns/form/CampaignForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const CampaignForm = ({

<FormDatePicker name="start" label="Start Date" />

<FormDatePicker name="end" label="End Date" />
<FormDatePicker name="end" label="End Date" minDate={values.start ?? undefined} />

<FormImageUpload name="imageBase64" label="Upload Campaign Image" />
</Stack>
Expand Down
7 changes: 4 additions & 3 deletions frontend/components/forms/FormDatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TextField, useMediaQuery } from '@mui/material';
import { DesktopDatePicker, MobileDatePicker } from '@mui/x-date-pickers';
import { Nullable } from '../../types/utils';
import moment, { Moment } from 'moment';
import { Moment } from 'moment';
import { useTheme } from '@mui/system';
import React from 'react';
import { MuiTextFieldProps } from '@mui/x-date-pickers/internals';
Expand All @@ -11,18 +11,19 @@ import { DATE_FORMAT } from '../../utils/constants';
interface Props {
name: string;
label: string;
minDate?: Moment | undefined;
}

const FormDatePicker = ({ name, label }: Props) => {
const FormDatePicker = ({ name, label, minDate }: Props) => {
const theme = useTheme();
const isMobile = useMediaQuery(theme.breakpoints.down('md'));
const [, { error, touched, value }, { setTouched, setValue }] = useField(name);

const innerProps = {
label,
value,
minDate,
inputFormat: DATE_FORMAT,
minDate: moment().add(1, 'day').startOf('day'),
onChange: (value: Nullable<Moment>) => {
const corrected = value === null ? value : value.startOf('day');
// It is not explicitly stated in the docs / types, but it appears setFieldValue is an
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/interests/form/InterestForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default function InterestForm({ onSubmit }: InterestFormProps) {
minRows={2}
/>

<FormDatePicker name="start" label={'Start Date'} />
<FormDatePicker name="start" label={'Start Date'} minDate={moment().add(1, 'day').startOf('day')} />

<FormTextInput
name="lengthOfCampaign"
Expand Down
3 changes: 1 addition & 2 deletions frontend/pages/admin/campaigns/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ const createCampaignSchema = Yup.object().shape(
.typeError('Start date must be a date.')
.when('end', (endDate, schema) =>
isValidDate(endDate) ? schema.max(endDate, 'Start date cannot be after End date') : schema,
)
.min(moment().endOf('day'), 'Start date cannot be today or in the past.'),
),
end: Yup.date()
.required('End date is required.')
.typeError('End date must be a date.')
Expand Down