Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
add: loading states to relevant reservation buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
vincit-matu committed Feb 21, 2024
1 parent a28d63b commit 62def40
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 21 deletions.
47 changes: 33 additions & 14 deletions apps/ui/components/calendar/ReservationCalendarControls.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState, useMemo } from "react";
import { useTranslation } from "next-i18next";
import { useTranslation, type TFunction } from "next-i18next";
import styled from "styled-components";
import {
differenceInMinutes,
Expand Down Expand Up @@ -238,7 +238,7 @@ const ResetButton = styled(Button).attrs({

const SelectButton = styled(Button)`
order: 7;
${truncatedText}
${truncatedText};
@media (min-width: ${breakpoints.m}) {
display: none;
Expand Down Expand Up @@ -290,6 +290,28 @@ const StyledSelect = styled(Select<OptionType>)`
}
`;

const TogglerLabelContent = ({
areControlsVisible,
togglerLabel,
t,
price,
}: {
areControlsVisible: boolean;
togglerLabel: string;
t: TFunction;
price?: string;
}) => {
if (areControlsVisible) return <div>&nbsp;</div>;
return (
<>
<TogglerDate>{togglerLabel}</TogglerDate>
<TogglerPrice>
{t("reservationUnit:price")}: {price}
</TogglerPrice>
</>
);
};

const ReservationCalendarControls = <T extends Record<string, unknown>>({
reservationUnit,
initialReservation,
Expand All @@ -310,7 +332,7 @@ const ReservationCalendarControls = <T extends Record<string, unknown>>({
}: Props<T>): JSX.Element => {
const { t, i18n } = useTranslation();

const { begin, end } = initialReservation || {};
const { begin, end } = initialReservation ?? {};
const {
minReservationDuration,
maxReservationDuration,
Expand Down Expand Up @@ -640,7 +662,8 @@ const ReservationCalendarControls = <T extends Record<string, unknown>>({
});
}
}}
disabled={!isReservable || isReserving}
disabled={!isReservable}
isLoading={isReserving}
data-test="reservation__button--submit"
>
{t("reservationCalendar:makeReservation")}
Expand All @@ -657,16 +680,12 @@ const ReservationCalendarControls = <T extends Record<string, unknown>>({
<ToggleControls>
<TogglerLabel>
{isReservable ? (
areControlsVisible ? (
<div>&nbsp;</div>
) : (
<>
<TogglerDate>{togglerLabel}</TogglerDate>
<TogglerPrice>
{t("reservationUnit:price")}: {price}
</TogglerPrice>
</>
)
<TogglerLabelContent
areControlsVisible={areControlsVisible}
togglerLabel={togglerLabel}
t={t}
price={price}
/>
) : (
t("reservationCalendar:selectTime")
)}
Expand Down
4 changes: 3 additions & 1 deletion apps/ui/components/reservation-unit/QuickReservation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ const QuickReservation = ({
minReservationDuration,
maxReservationDuration,
reservationStartInterval,
t,
]);

// TODO this should be on a timer
Expand Down Expand Up @@ -696,13 +697,14 @@ const QuickReservation = ({
componentIfAuthenticated={
isReservationUnitReservable && (
<MediumButton
disabled={!slot || isReserving}
disabled={!slot}
onClick={() => {
if (localReservation != null) {
setIsReserving(true);
createReservation(localReservation);
}
}}
isLoading={isReserving}
data-test="quick-reservation__button--submit"
>
{t("reservationCalendar:makeReservation")}
Expand Down
3 changes: 3 additions & 0 deletions apps/ui/components/reservation/EditStep0.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Props = {
setErrorMsg: React.Dispatch<React.SetStateAction<string | null>>;
nextStep: () => void;
apiBaseUrl: string;
isLoading: boolean;
};

type WeekOptions = "day" | "week" | "month";
Expand Down Expand Up @@ -121,6 +122,7 @@ const EditStep0 = ({
setErrorMsg,
nextStep,
apiBaseUrl,
isLoading,
}: Props): JSX.Element => {
const { t, i18n } = useTranslation();
const router = useRouter();
Expand Down Expand Up @@ -489,6 +491,7 @@ const EditStep0 = ({
}
}}
data-testid="reservation-edit__button--continue"
isLoading={isLoading}
>
{t("reservationCalendar:nextStep")}
</MediumButton>
Expand Down
1 change: 1 addition & 0 deletions apps/ui/components/reservation/EditStep1.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ const EditStep1 = ({
type="submit"
disabled={isSubmitting}
data-testid="reservation-edit__button--submit"
isLoading={isSubmitting}
>
{t("reservations:saveNewTime")}
</MediumButton>
Expand Down
9 changes: 5 additions & 4 deletions apps/ui/components/reservation/ReservationCancellation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import {
CANCEL_RESERVATION,
GET_RESERVATION,
GET_RESERVATION_CANCEL_REASONS,
} from "../../modules/queries/reservation";
import { JustForDesktop, JustForMobile } from "../../modules/style/layout";
import { getSelectedOption, getTranslation } from "../../modules/util";
} from "@/modules/queries/reservation";
import { JustForDesktop, JustForMobile } from "@/modules/style/layout";
import { getSelectedOption, getTranslation } from "@/modules/util";
import { CenterSpinner } from "../common/common";
import { BlackButton, MediumButton, Toast } from "../../styles/util";
import { BlackButton, MediumButton, Toast } from "@/styles/util";
import ReservationInfoCard from "./ReservationInfoCard";
import { Paragraph } from "./styles";
import { signOut } from "@/hooks/auth";
Expand Down Expand Up @@ -338,6 +338,7 @@ const ReservationCancellation = ({ id, apiBaseUrl }: Props): JSX.Element => {
type="submit"
disabled={!watch("reason")}
data-testid="reservation-cancel__button--cancel"
isLoading={loading}
>
{t("reservations:cancelReservation")}
</MediumButton>
Expand Down
1 change: 1 addition & 0 deletions apps/ui/components/reservation/ReservationEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ const ReservationEdit = ({ id, apiBaseUrl }: Props): JSX.Element => {
setErrorMsg={setErrorMsg}
nextStep={() => setStep(1)}
apiBaseUrl={apiBaseUrl}
isLoading={isLoading}
/>
)}
{step === 1 && (
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/components/reservation/Step0.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { Trans, useTranslation } from "next-i18next";
import styled from "styled-components";
import { fontMedium, fontRegular } from "common/src/common/typography";
import MetaFields from "common/src/reservation-form/MetaFields";
import { MediumButton } from "../../styles/util";
import { MediumButton } from "@/styles/util";
import { ActionContainer } from "./styles";
import { getTranslation } from "../../modules/util";
import InfoDialog from "../common/InfoDialog";
import { JustForMobile } from "../../modules/style/layout";
import { JustForMobile } from "@/modules/style/layout";
import {
ErrorAnchor,
ErrorBox,
Expand Down

0 comments on commit 62def40

Please sign in to comment.