From 7f87785acac1deed1ecb6523a481cac53d76d372 Mon Sep 17 00:00:00 2001 From: Joonatan Kuosa Date: Sat, 11 Jan 2025 19:26:36 +0200 Subject: [PATCH] refactor: separate page queries fix: missing tax percentage in ReservationInfoCard --- apps/admin-ui/gql/gql-types.ts | 135 +- apps/admin-ui/src/common/queries.tsx | 2 - apps/ui/components/Instructions.tsx | 27 +- .../components/reservation-unit/Address.tsx | 49 +- .../ReservationInfoContainer.tsx | 6 +- .../ui/components/reservation/AcceptTerms.tsx | 7 +- apps/ui/components/reservation/EditStep0.tsx | 4 +- apps/ui/components/reservation/EditStep1.tsx | 4 +- .../reservation/ReservationInfoCard.tsx | 4 +- apps/ui/components/reservation/Step0.tsx | 18 +- apps/ui/components/reservation/Step1.tsx | 20 +- .../components/reservation/SummaryFields.tsx | 9 +- apps/ui/gql/gql-types.ts | 2028 +++++++++-------- apps/ui/modules/queries/fragments.tsx | 62 +- apps/ui/modules/queries/reservation.tsx | 86 +- apps/ui/modules/queries/reservationUnit.tsx | 48 +- apps/ui/modules/reservation.ts | 26 +- .../ui/pages/reservation-unit/[...params].tsx | 83 +- apps/ui/pages/reservation-unit/[id].tsx | 2 +- apps/ui/pages/reservations/[id]/cancel.tsx | 4 - .../pages/reservations/[id]/confirmation.tsx | 44 +- apps/ui/pages/reservations/[id]/edit.tsx | 47 +- apps/ui/pages/reservations/[id]/index.tsx | 149 +- packages/common/gql/gql-types.ts | 77 + packages/common/src/queries/fragments.tsx | 31 + 25 files changed, 1629 insertions(+), 1343 deletions(-) diff --git a/apps/admin-ui/gql/gql-types.ts b/apps/admin-ui/gql/gql-types.ts index 63040a3a0..ac6ef7212 100644 --- a/apps/admin-ui/gql/gql-types.ts +++ b/apps/admin-ui/gql/gql-types.ts @@ -5492,6 +5492,51 @@ export type ReserveeBillingFieldsFragment = { billingAddressZip?: string | null; }; +export type MetaFieldsFragment = { + applyingForFreeOfCharge?: boolean | null; + freeOfChargeReason?: string | null; + description?: string | null; + numPersons?: number | null; + reserveeFirstName?: string | null; + reserveeLastName?: string | null; + reserveeEmail?: string | null; + reserveePhone?: string | null; + reserveeType?: CustomerTypeChoice | null; + reserveeOrganisationName?: string | null; + reserveeId?: string | null; + reserveeIsUnregisteredAssociation?: boolean | null; + reserveeAddressStreet?: string | null; + reserveeAddressCity?: string | null; + reserveeAddressZip?: string | null; + billingFirstName?: string | null; + billingLastName?: string | null; + billingPhone?: string | null; + billingEmail?: string | null; + billingAddressStreet?: string | null; + billingAddressCity?: string | null; + billingAddressZip?: string | null; + ageGroup?: { + id: string; + pk?: number | null; + maximum?: number | null; + minimum: number; + } | null; + purpose?: { + id: string; + pk?: number | null; + nameFi?: string | null; + nameEn?: string | null; + nameSv?: string | null; + } | null; + homeCity?: { + id: string; + pk?: number | null; + nameFi?: string | null; + nameSv?: string | null; + nameEn?: string | null; + } | null; +}; + export type TermsOfUseNameFieldsFragment = { nameFi?: string | null; nameEn?: string | null; @@ -5962,8 +6007,6 @@ export type UnitQuery = { } | null; }>; location?: { - longitude?: string | null; - latitude?: string | null; id: string; addressStreetFi?: string | null; addressZip: string; @@ -8519,6 +8562,65 @@ export type SpaceQuery = { } | null; }; +export const ReserveeNameFieldsFragmentDoc = gql` + fragment ReserveeNameFields on ReservationNode { + reserveeFirstName + reserveeLastName + reserveeEmail + reserveePhone + reserveeType + reserveeOrganisationName + reserveeId + } +`; +export const ReserveeBillingFieldsFragmentDoc = gql` + fragment ReserveeBillingFields on ReservationNode { + reserveeId + reserveeIsUnregisteredAssociation + reserveeAddressStreet + reserveeAddressCity + reserveeAddressZip + billingFirstName + billingLastName + billingPhone + billingEmail + billingAddressStreet + billingAddressCity + billingAddressZip + } +`; +export const MetaFieldsFragmentDoc = gql` + fragment MetaFields on ReservationNode { + ...ReserveeNameFields + ...ReserveeBillingFields + applyingForFreeOfCharge + freeOfChargeReason + description + numPersons + ageGroup { + id + pk + maximum + minimum + } + purpose { + id + pk + nameFi + nameEn + nameSv + } + homeCity { + id + pk + nameFi + nameSv + nameEn + } + } + ${ReserveeNameFieldsFragmentDoc} + ${ReserveeBillingFieldsFragmentDoc} +`; export const TermsOfUseNameFieldsFragmentDoc = gql` fragment TermsOfUseNameFields on TermsOfUseNode { nameFi @@ -9021,33 +9123,6 @@ export const ReservationsInIntervalFragmentDoc = gql` } } `; -export const ReserveeNameFieldsFragmentDoc = gql` - fragment ReserveeNameFields on ReservationNode { - reserveeFirstName - reserveeLastName - reserveeEmail - reserveePhone - reserveeType - reserveeOrganisationName - reserveeId - } -`; -export const ReserveeBillingFieldsFragmentDoc = gql` - fragment ReserveeBillingFields on ReservationNode { - reserveeId - reserveeIsUnregisteredAssociation - reserveeAddressStreet - reserveeAddressCity - reserveeAddressZip - billingFirstName - billingLastName - billingPhone - billingEmail - billingAddressStreet - billingAddressCity - billingAddressZip - } -`; export const ReservationMetaFieldsFragmentDoc = gql` fragment ReservationMetaFields on ReservationNode { ageGroup { @@ -9497,8 +9572,6 @@ export const UnitDocument = gql` } location { ...LocationFields - longitude - latitude } } } diff --git a/apps/admin-ui/src/common/queries.tsx b/apps/admin-ui/src/common/queries.tsx index 2545e8d41..5b13b9ed2 100644 --- a/apps/admin-ui/src/common/queries.tsx +++ b/apps/admin-ui/src/common/queries.tsx @@ -43,8 +43,6 @@ export const UNIT_QUERY = gql` } location { ...LocationFields - longitude - latitude } } } diff --git a/apps/ui/components/Instructions.tsx b/apps/ui/components/Instructions.tsx index c7bbfe123..9bc7cd76d 100644 --- a/apps/ui/components/Instructions.tsx +++ b/apps/ui/components/Instructions.tsx @@ -1,8 +1,9 @@ import { + type InstructionsFragment, type Maybe, - type ReservationQuery, ReservationStateChoice, } from "@/gql/gql-types"; +import { gql } from "@apollo/client"; import { H4 } from "common"; import { convertLanguageCode, @@ -10,12 +11,28 @@ import { } from "common/src/common/util"; import { useTranslation } from "next-i18next"; -// TODO replace with a fragment -type NodeT = NonNullable; +export const INSTRUCTIOSN_FRAGMENT = gql` + fragment Instructions on ReservationNode { + id + state + reservationUnits { + id + reservationPendingInstructionsFi + reservationPendingInstructionsEn + reservationPendingInstructionsSv + reservationConfirmedInstructionsFi + reservationConfirmedInstructionsEn + reservationConfirmedInstructionsSv + reservationCancelledInstructionsFi + reservationCancelledInstructionsEn + reservationCancelledInstructionsSv + } + } +`; + type Props = { - reservation: Pick; + reservation: InstructionsFragment; }; - export function Instructions({ reservation }: Props): JSX.Element | null { const { t, i18n } = useTranslation(); diff --git a/apps/ui/components/reservation-unit/Address.tsx b/apps/ui/components/reservation-unit/Address.tsx index da7e00181..80dc5c365 100644 --- a/apps/ui/components/reservation-unit/Address.tsx +++ b/apps/ui/components/reservation-unit/Address.tsx @@ -5,7 +5,7 @@ import { fontMedium, H4 } from "common/src/common/typography"; import type { Maybe, LocationFieldsI18nFragment, - UnitFieldsFragment, + AddressFieldsFragment, } from "@gql/gql-types"; import { IconLinkExternal } from "hds-react"; import { IconButton } from "common/src/components"; @@ -16,6 +16,7 @@ import { getTranslationSafe, } from "common/src/common/util"; import { type LocalizationLanguages } from "common/src/helpers"; +import { gql } from "@apollo/client"; const AddressSpan = styled.span` font-size: var(--fontsize-body-l); @@ -39,7 +40,7 @@ type UrlReturn = string; function createHslUrl( locale: LocalizationLanguages, - location?: Maybe + location: Maybe | undefined ): UrlReturn { if (!location) { return ""; @@ -61,18 +62,14 @@ function createHslUrl( function createGoogleUrl( locale: LocalizationLanguages, - location?: Maybe + location: Maybe | undefined ): UrlReturn { if (!location) { return ""; } - const addressStreet = - getTranslationSafe(location, "addressStreet", locale) || - location.addressStreetFi; - const addressCity = - getTranslationSafe(location, "addressCity", locale) || - location.addressCityFi; + const addressStreet = getTranslationSafe(location, "addressStreet", locale); + const addressCity = getTranslationSafe(location, "addressCity", locale); const destination = addressStreet ? encodeURI(`${addressStreet},${addressCity}`) @@ -83,7 +80,7 @@ function createGoogleUrl( function createMapUrl( locale: LocalizationLanguages, - unit?: Maybe> + unit: Maybe> | undefined ): string { if (!unit?.tprekId) { return ""; @@ -94,7 +91,7 @@ function createMapUrl( function createAccessibilityUrl( locale: LocalizationLanguages, - unit?: Maybe> + unit: Maybe> | undefined ): UrlReturn { if (!unit?.tprekId) { return ""; @@ -105,7 +102,7 @@ function createAccessibilityUrl( type Props = { title: string; - unit?: Maybe | undefined; + unit: Maybe | undefined; }; export function AddressSection({ title, unit }: Props): JSX.Element { @@ -114,12 +111,12 @@ export function AddressSection({ title, unit }: Props): JSX.Element { const { location } = unit ?? {}; const lang = convertLanguageCode(i18n.language); - const addressStreet = - (location && getTranslationSafe(location, "addressStreet", lang)) || - location?.addressStreetFi; - const addressCity = - (location && getTranslationSafe(location, "addressCity", lang)) || - location?.addressCityFi; + const addressStreet = location + ? getTranslationSafe(location, "addressStreet", lang) + : undefined; + const addressCity = location + ? getTranslationSafe(location, "addressCity", lang) + : undefined; const unitMapUrl = createMapUrl(lang, unit); const googleUrl = createGoogleUrl(lang, location); @@ -137,24 +134,32 @@ export function AddressSection({ title, unit }: Props): JSX.Element { } + icon={