Skip to content

Commit

Permalink
TILA-1851 reservation unit redux (#379)
Browse files Browse the repository at this point in the history
* TILA-1851 reservation unit redux

* TILA-1851 cleanup

* TILA-1851 additional tests
  • Loading branch information
kieferbonk authored Aug 29, 2022
1 parent b5fdb9d commit 51bb9d2
Show file tree
Hide file tree
Showing 39 changed files with 2,108 additions and 2,379 deletions.
7 changes: 4 additions & 3 deletions ui/components/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const Button = styled(MediumButton).attrs({

const StyledCarousel = styled(NukaCarousel)<{ $showCenterControls: boolean }>`
width: calc(100% + var(--spacing-xs) * 2) !important;
height: fit-content !important;
margin-right: calc(var(--spacing-xs) * -1);
margin-left: calc(var(--spacing-xs) * -1);
Expand All @@ -53,18 +54,17 @@ const StyledCarousel = styled(NukaCarousel)<{ $showCenterControls: boolean }>`
transform: unset !important;
ul {
top: var(--spacing-m) !important;
gap: var(--spacing-s);
gap: var(--spacing-3-xs);
flex-wrap: wrap;
width: 100%;
justify-content: center;
position: static !important;
}
.paging-item {
button {
svg {
transform: scale(1.9);
border: 1px solid var(--color-black-50);
border-radius: 50%;
fill: var(--color-black-20);
}
Expand All @@ -74,6 +74,7 @@ const StyledCarousel = styled(NukaCarousel)<{ $showCenterControls: boolean }>`
@media (min-width: ${breakpoint.m}) {
width: 100% !important;
height: fit-content !important;
margin: 0 !important;
}
`;
Expand Down
15 changes: 1 addition & 14 deletions ui/components/Map.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React, { useState } from "react";
import Image from "next/image";
import ReactMapGL, {
Marker,
NavigationControl,
GeolocateControl,
} from "react-map-gl";
import ReactMapGL, { Marker, NavigationControl } from "react-map-gl";
import { mapboxToken, mapStyle } from "../modules/const";

type State = Record<string, number>;
Expand All @@ -21,11 +17,6 @@ const navControlStyle = {
bottom: 10,
};

const geolocateControlStyle = {
right: 10,
bottom: 72,
};

const Map = ({
title,
latitude,
Expand Down Expand Up @@ -59,10 +50,6 @@ const Map = ({
<Marker key={title} longitude={longitude} latitude={latitude}>
<Image src="/icons/map_marker_icon.svg" height="42" width="32" alt="" />
</Marker>
<GeolocateControl
style={geolocateControlStyle}
positionOptions={{ enableHighAccuracy: true }}
/>
</ReactMapGL>
);
};
Expand Down
4 changes: 4 additions & 0 deletions ui/components/calendar/Calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ const StyledCalendar = styled(BigCalendar)<{
.rbc-month-row {
min-width: 800px;
overflow: visible;
@media (min-width: ${(props) => props.overflowBreakpoint}) {
min-width: unset;
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions ui/components/calendar/ReservationInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ const ReservationInfo = ({
price: data.createReservation.price,
});
setIsRedirecting(true);
router.push(
`/reservation-unit/single/${reservationUnit.pk}/reservation`
);
router.push(`/reservation-unit/${reservationUnit.pk}/reservation`);
}
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
27 changes: 8 additions & 19 deletions ui/components/calendar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { breakpoint } from "../../modules/style";

export type ToolbarProps = {
onNavigate: (n: string) => void;
onNavigateToNextAvailableDate?: () => void;
onView: (n: string) => void;
view: string;
date: Date;
Expand All @@ -23,7 +22,6 @@ const Wrapper = styled.div`
&:before {
content: "";
display: block;
background-color: var(--tilavaraus-gray);
position: absolute;
top: 0;
right: 0;
Expand Down Expand Up @@ -137,8 +135,7 @@ const ButtonWrapper = styled.div`
// eslint-disable-next-line react/prefer-stateless-function
export default class Toolbar extends React.Component<ToolbarProps> {
render(): JSX.Element {
const { onNavigate, onNavigateToNextAvailableDate, onView, view, date } =
this.props;
const { onNavigate, onView, view, date } = this.props;

const culture = { locale: locales[i18n.language] };

Expand All @@ -165,17 +162,17 @@ export default class Toolbar extends React.Component<ToolbarProps> {
const end = endOfWeek(date, culture);
const startDay = format(start, "d", culture);
const endDay = format(end, "d", culture);
const startMonth = format(start, "MMMM", culture);
const endMonth = format(end, "MMMM", culture);
const startMonth = format(start, "M", culture);
const endMonth = format(end, "M", culture);
const startYear = format(start, "yyyy", culture);
const endYear = format(end, "yyyy", culture);
const currentYear = format(new Date(), "yyyy", culture);
title = `${startDay}.${
startMonth !== endMonth ? ` ${startMonth}` : ""
} ${
startYear !== endYear ? ` ${startYear}` : ""
}${endDay}. ${endMonth} ${
startYear !== endYear || endYear !== currentYear ? ` ${endYear}` : ""
startMonth !== endMonth ? `${startMonth}.` : ""
}${
startYear !== endYear ? `${startYear}` : ""
}${endDay}.${endMonth}.${
startYear !== endYear || endYear !== currentYear ? `${endYear}` : ""
}`;
}
}
Expand All @@ -190,14 +187,6 @@ export default class Toolbar extends React.Component<ToolbarProps> {
>
{i18n.t("common:today")}
</button>
<button
type="button"
onClick={() => onNavigateToNextAvailableDate()}
aria-label={i18n.t("reservationCalendar:nextAvailableTime")}
disabled={!onNavigateToNextAvailableDate}
>
{i18n.t("reservationCalendar:nextAvailableTime")}
</button>
</ButtonWrapper>
<div className="rbc-toolbar-navigation-hz">
<button
Expand Down
7 changes: 5 additions & 2 deletions ui/components/common/Accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useState } from "react";
import { Button, IconAngleDown, IconAngleUp, useAccordion } from "hds-react";
import styled from "styled-components";
import { H4 } from "../../modules/style/typography";

type Theme = "default" | "thin";

Expand Down Expand Up @@ -31,7 +32,7 @@ const HeadingButton = styled(Button).attrs({
width: 100%;
padding-left: 0;
border-left: 0;
border-bottom: 1px solid var(--color-black-60) !important;
border-bottom: 1px solid var(--color-black-50) !important;
span {
${({ theme }) => {
Expand Down Expand Up @@ -76,6 +77,8 @@ const Content = styled.div<{ $open: boolean }>`
display: ${({ $open }) => ($open ? "block" : "none")};
`;

const Heading = styled(H4).attrs({ as: "div" })``;

const Accordion = ({
heading,
open = false,
Expand Down Expand Up @@ -111,7 +114,7 @@ const Accordion = ({
onClick={onToggle}
theme={theme}
>
{heading}
<Heading>{heading}</Heading>
</HeadingButton>
<Content $open={isOpen}>{children}</Content>
</AccordionElement>
Expand Down
2 changes: 1 addition & 1 deletion ui/components/index/Recommendations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Recommendations = ({ recommendations }: Props): JSX.Element => {
<Wrapper>
<Container>
<Heading>{t("recommendations")}</Heading>
<RelatedUnits units={recommendations} viewType="single" />
<RelatedUnits units={recommendations} />
</Container>
</Wrapper>
);
Expand Down
17 changes: 6 additions & 11 deletions ui/components/reservation-unit/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@ const Container = styled.div`
margin-bottom: var(--spacing-layout-l);
`;

const Name = styled(H4).attrs({ as: "h3" })`
margin-top: 0;
`;
const Name = styled(H4).attrs({ as: "h3" })``;

const AddressLine = styled.div`
font-family: var(--font-medium);
font-weight: 500;
font-size: var(--fontsize-body-m);
margin-top: var(--spacing-2-xs);
const AddressSpan = styled.span`
font-size: var(--fontsize-body-l);
`;

const Links = styled.div`
Expand All @@ -36,7 +31,7 @@ const Links = styled.div`
font-weight: 500;
a {
color: var(--color-bus);
color: var(--color-black-90);
}
`;

Expand Down Expand Up @@ -85,9 +80,9 @@ const Address = ({ reservationUnit }: Props): JSX.Element => {
return (
<Container data-testid="reservation-unit__address--container">
<Name>{getTranslation(reservationUnit, "name")}</Name>
{addressStreet && <AddressLine>{addressStreet}</AddressLine>}
{addressStreet && <AddressSpan>{addressStreet}</AddressSpan>}
{location?.addressZip && addressCity && (
<AddressLine>{`${location?.addressZip} ${addressCity}`}</AddressLine>
<AddressSpan>{`, ${location?.addressZip} ${addressCity}`}</AddressSpan>
)}
<Links>
<ExternalLink
Expand Down
72 changes: 72 additions & 0 deletions ui/components/reservation-unit/EquipmentList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Button, IconAngleDown, IconAngleUp } from "hds-react";
import React, { useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import styled from "styled-components";
import { EquipmentType } from "../../modules/gql-types";
import { getEquipmentList } from "../../modules/reservationUnit";
import { breakpoint } from "../../modules/style";

type Props = {
equipment: EquipmentType[];
itemsToShow?: number;
};

const Wrapper = styled.div``;

const List = styled.ul`
list-style: none;
display: grid;
grid-template-columns: 1fr;
gap: var(--spacing-2-xs) var(--spacing-m);
padding: 0;
@media (min-width: ${breakpoint.s}) {
grid-template-columns: 1fr 1fr;
row-gap: var(--spacing-s);
}
`;

const EquipmentItem = styled.li`
font-size: var(--fontsize-body-m);
@media (min-width: ${breakpoint.s}) {
font-size: var(--fontsize-body-l);
}
`;

const ToggleButton = styled(Button)`
font-size: var(--fontsize-body-m);
`;

const EquipmentList = ({ equipment, itemsToShow = 6 }: Props): JSX.Element => {
const { t } = useTranslation();

const [showAll, setShowAll] = useState(false);

const equipmentList = useMemo(() => {
const items = showAll ? equipment : equipment.slice(0, itemsToShow);
return getEquipmentList(items);
}, [equipment, showAll, itemsToShow]);

return (
<Wrapper>
<List>
{equipmentList.map((item) => (
<EquipmentItem key={item}>{item}</EquipmentItem>
))}
</List>
{itemsToShow < equipment.length && (
<ToggleButton
variant="supplementary"
size="small"
onClick={() => setShowAll(!showAll)}
iconRight={showAll ? <IconAngleUp /> : <IconAngleDown />}
>
{t(`common:show${showAll ? "Less" : "More"}`)}
</ToggleButton>
)}
</Wrapper>
);
};

export default EquipmentList;
7 changes: 3 additions & 4 deletions ui/components/reservation-unit/ExternalLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ const Container = styled.div`
margin-top: var(--spacing-s);
display: flex;
align-items: center;
& svg {
margin-left: var(--spacing-xs);
}
color: inherit;
text-decoration: underline;
gap: var(--spacing-3-xs);
`;

const Name = styled.span`
Expand Down
Loading

0 comments on commit 51bb9d2

Please sign in to comment.