-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10875 from wellcomecollection/remove-available-da…
…te-code-not-needed-anymore Remove available date code not needed anymore
- Loading branch information
Showing
10 changed files
with
62 additions
and
1,034 deletions.
There are no files selected for viewing
89 changes: 35 additions & 54 deletions
89
content/webapp/components/CalendarSelect/CalendarSelect.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,49 @@ | ||
import { FunctionComponent } from 'react'; | ||
import Select, { SelectOption } from '@weco/content/components/Select'; | ||
import { isRequestableDate } from '../../utils/dates'; | ||
import { getDatesBetween } from '@weco/common/utils/dates'; | ||
import Select from '@weco/content/components/Select'; | ||
import { dateAsValue } from '../ItemRequestModal/format-date'; | ||
import { | ||
formatDayName, | ||
formatDayMonth, | ||
DayOfWeek, | ||
} from '@weco/common/utils/format-date'; | ||
import { AvailabilitySlot } from '@weco/content/services/wellcome/catalogue/types'; | ||
import { formatDayName, formatDayMonth } from '@weco/common/utils/format-date'; | ||
|
||
type Props = { | ||
startDate?: Date; | ||
endDate?: Date; | ||
excludedDates: Date[]; | ||
excludedDays: DayOfWeek[]; | ||
availableDates: AvailabilitySlot[]; | ||
chosenDate?: string; | ||
setChosenDate: (value: string) => void; | ||
}; | ||
|
||
function getAvailableDates( | ||
startDate: Date, | ||
endDate: Date, | ||
excludedDates: Date[], | ||
excludedDays: DayOfWeek[] | ||
): SelectOption[] { | ||
return getDatesBetween({ startDate, endDate }) | ||
.filter(date => | ||
isRequestableDate({ | ||
date, | ||
startDate, | ||
endDate, | ||
excludedDates, | ||
excludedDays, | ||
}) | ||
) | ||
.map(date => ({ | ||
value: dateAsValue(date), | ||
text: `${formatDayName(date)} ${formatDayMonth(date)}`, | ||
})); | ||
} | ||
const availabilitySlotsToSelectOptions = ( | ||
availableDates: AvailabilitySlot[] | ||
) => { | ||
// AvailabilitySlots have open and close dateTimestamps | ||
// right now we only care about the day, not the time | ||
// so we're only using "from" = opening date/time | ||
return ( | ||
availableDates | ||
.map(availabilitySlot => new Date(availabilitySlot.from)) | ||
.map(availableDate => ({ | ||
value: dateAsValue(availableDate), | ||
text: `${formatDayName(availableDate)} ${formatDayMonth( | ||
availableDate | ||
)}`, | ||
})) | ||
// the list of available dates is returned from the itemsAPI in various lenghts | ||
// trimming down to 12 | ||
.slice(0, 12) | ||
); | ||
}; | ||
|
||
const CalendarSelect: FunctionComponent<Props> = ({ | ||
startDate, | ||
endDate, | ||
excludedDates, | ||
excludedDays, | ||
availableDates, | ||
chosenDate, | ||
setChosenDate, | ||
}) => { | ||
const availableDates = | ||
startDate && | ||
endDate && | ||
getAvailableDates(startDate, endDate, excludedDates, excludedDays); | ||
|
||
return availableDates ? ( | ||
<Select | ||
name="calendar_dates" | ||
label="Select a date" | ||
hideLabel={true} | ||
options={availableDates} | ||
value={chosenDate || 'Select a date'} | ||
onChange={e => setChosenDate(e.target.value)} | ||
/> | ||
) : null; | ||
}; | ||
}) => ( | ||
<Select | ||
name="calendar_dates" | ||
label="Select a date" | ||
hideLabel={true} | ||
options={availabilitySlotsToSelectOptions(availableDates)} | ||
value={chosenDate || 'Select a date'} | ||
onChange={e => setChosenDate(e.target.value)} | ||
/> | ||
); | ||
|
||
export default CalendarSelect; |
49 changes: 0 additions & 49 deletions
49
content/webapp/components/CalendarSelect/NewCalendarSelect.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
import { FunctionComponent, FormEvent, useState } from 'react'; | ||
import { useAvailableDates } from './useAvailableDates'; | ||
import { isRequestableDate } from '../../utils/dates'; | ||
import { allowedRequests } from '@weco/common/values/requests'; | ||
import { font } from '@weco/common/utils/classnames'; | ||
import Space from '@weco/common/views/components/styled/Space'; | ||
import RequestingDayPicker from '../RequestingDayPicker/RequestingDayPicker'; | ||
import NewRequestingDayPicker from '../RequestingDayPicker/NewRequestingDayPicker'; | ||
import Button, { ButtonTypes } from '@weco/common/views/components/Buttons'; | ||
import { | ||
PhysicalItem, | ||
|
@@ -15,7 +12,6 @@ import styled from 'styled-components'; | |
import { CTAs, CurrentRequests, Header } from './common'; | ||
import { themeValues } from '@weco/common/views/themes/config'; | ||
import { dateAsValue, dateFromValue } from './format-date'; | ||
import { useToggles } from '@weco/common/server-data/Context'; | ||
|
||
const PickUpDate = styled(Space).attrs({ | ||
$v: { size: 'l', properties: ['padding-top', 'padding-bottom'] }, | ||
|
@@ -86,11 +82,11 @@ const RequestDialog: FunctionComponent<RequestDialogProps> = ({ | |
setIsActive, | ||
currentHoldNumber, | ||
}) => { | ||
const { offsiteRequesting } = useToggles(); | ||
|
||
const availableDates = useAvailableDates(); | ||
const firstAvailableDate = item.availableDates | ||
? item.availableDates[0] | ||
: undefined; | ||
const [pickUpDate, setPickUpDate] = useState<string | undefined>( | ||
availableDates.nextAvailable && dateAsValue(availableDates.nextAvailable) | ||
firstAvailableDate && dateAsValue(new Date(firstAvailableDate.from)) | ||
); | ||
|
||
function handleConfirmRequest(event: FormEvent<HTMLFormElement>) { | ||
|
@@ -104,16 +100,7 @@ const RequestDialog: FunctionComponent<RequestDialogProps> = ({ | |
// these DD-MM-YYYY values, and hopefully they've kept those bugs at bay. | ||
const pickUpDateValue = pickUpDate ? dateFromValue(pickUpDate) : undefined; | ||
|
||
if ( | ||
pickUpDateValue && | ||
isRequestableDate({ | ||
date: pickUpDateValue, | ||
startDate: availableDates.nextAvailable, | ||
endDate: availableDates.lastAvailable, | ||
excludedDates: availableDates.exceptionalClosedDates, | ||
excludedDays: availableDates.regularClosedDays, | ||
}) | ||
) { | ||
if (pickUpDateValue) { | ||
confirmRequest(pickUpDateValue); | ||
} | ||
} | ||
|
@@ -151,36 +138,23 @@ const RequestDialog: FunctionComponent<RequestDialogProps> = ({ | |
</PickupDeadline> | ||
</PickUpDateDescription> | ||
<PickUpDateInputWrapper> | ||
<> | ||
{offsiteRequesting && | ||
(item.availableDates?.length ? ( | ||
<NewRequestingDayPicker | ||
availableDates={item.availableDates} | ||
pickUpDate={pickUpDate} | ||
setPickUpDate={setPickUpDate} | ||
/> | ||
) : ( | ||
<ErrorMessage> | ||
Error fetching available dates. | ||
<br /> | ||
Try again later or email us at | ||
<br /> | ||
<a href="mailto:[email protected]"> | ||
[email protected] | ||
</a> | ||
</ErrorMessage> | ||
))} | ||
{!offsiteRequesting && ( | ||
<RequestingDayPicker | ||
startDate={availableDates.nextAvailable} | ||
endDate={availableDates.lastAvailable} | ||
exceptionalClosedDates={availableDates.exceptionalClosedDates} | ||
regularClosedDays={availableDates.regularClosedDays} | ||
pickUpDate={pickUpDate} | ||
setPickUpDate={setPickUpDate} | ||
/> | ||
)} | ||
</> | ||
{item.availableDates?.length ? ( | ||
<RequestingDayPicker | ||
availableDates={item.availableDates} | ||
pickUpDate={pickUpDate} | ||
setPickUpDate={setPickUpDate} | ||
/> | ||
) : ( | ||
<ErrorMessage> | ||
Error fetching available dates. | ||
<br /> | ||
Try again later or email us at | ||
<br /> | ||
<a href="mailto:[email protected]"> | ||
[email protected] | ||
</a> | ||
</ErrorMessage> | ||
)} | ||
</PickUpDateInputWrapper> | ||
</PickUpDate> | ||
</Space> | ||
|
57 changes: 0 additions & 57 deletions
57
content/webapp/components/ItemRequestModal/useAvailableDates.ts
This file was deleted.
Oops, something went wrong.
27 changes: 0 additions & 27 deletions
27
content/webapp/components/RequestingDayPicker/NewRequestingDayPicker.tsx
This file was deleted.
Oops, something went wrong.
17 changes: 4 additions & 13 deletions
17
content/webapp/components/RequestingDayPicker/RequestingDayPicker.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.