Skip to content

Commit

Permalink
feat(FGR result): show multiple courts
Browse files Browse the repository at this point in the history
Co-Authored-By: SannyNguyenHung <[email protected]>
Co-Authored-By: Joschka <[email protected]>
  • Loading branch information
3 people committed Dec 1, 2023
1 parent fa02fee commit 4535936
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 9 deletions.
7 changes: 4 additions & 3 deletions app/models/flows/fluggastrechte/guards.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { partnerCourtAirports } from ".";
import type { FluggastrechtVorabcheckContext } from "./context";

type Guard = (context: FluggastrechtVorabcheckContext) => boolean;
Expand All @@ -15,10 +16,10 @@ function yesNoGuards<Field extends keyof FluggastrechtVorabcheckContext>(
}

const isPartnerAirport = (context: FluggastrechtVorabcheckContext) => {
const partnerAirports = ["BRE", "BER", "DUS", "FRA", "HAM", "MUC", "STR"];
const airportAbbreviations = Object.keys(partnerCourtAirports);
return (
partnerAirports.includes(context.startAirport ?? "") ||
partnerAirports.includes(context.endAirport ?? "")
airportAbbreviations.includes(context.startAirport ?? "") ||
airportAbbreviations.includes(context.endAirport ?? "")
);
};

Expand Down
25 changes: 25 additions & 0 deletions app/models/flows/fluggastrechte/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
import { guards as fluggastrechteVorabcheckGuards } from "~/models/flows/fluggastrechte/guards";
import fluggastrechteVorabcheckFlow from "~/models/flows/fluggastrechte/config.json";
import { fluggastrechteVorabcheckContext } from "~/models/flows/fluggastrechte/context";
import { findCourt } from "~/services/gerichtsfinder/amtsgerichtData.server";
import { type Jmtd14VTErwerberGerbeh } from "~/services/gerichtsfinder/types";

export const fluggastrechteVorabcheck = {
cmsSlug: "vorab-check-pages",
flow: fluggastrechteVorabcheckFlow,
guards: fluggastrechteVorabcheckGuards,
context: fluggastrechteVorabcheckContext,
} as const;

export const partnerCourtAirports = {
BRE: "28199",
BER: "12529",
DUS: "40474",
FRA: "60549", // eigtl 60547
HAM: "22335",
MUC: "85356",
STR: "70629",
} as const;

function partnerCourtFromAirport(airport: string) {
if (airport in partnerCourtAirports) {
const zipCode =
partnerCourtAirports[airport as keyof typeof partnerCourtAirports];
return findCourt({ zipCode });
}
}

export const partnerCourtFromAirports = (airports: string[]) =>
airports
.map(partnerCourtFromAirport)
.filter((airport) => airport) as Jmtd14VTErwerberGerbeh[];
62 changes: 56 additions & 6 deletions app/routes/shared/result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ import {
handleFeedback,
isFeedbackForm,
} from "~/services/feedback/handleFeedback";
import CourtDetails from "~/components/CourtDetails";
import { partnerCourtFromAirports } from "~/models/flows/fluggastrechte";
import Background from "~/components/Background";

export const loader = async ({
params,
Expand All @@ -57,10 +60,11 @@ export const loader = async ({

// Slug change to keep Strapi slugs without ergebnis/
const slug = pathname.replace(/ergebnis\//, "");
const [common, cmsData, parentMeta] = await Promise.all([
const [common, cmsData, parentMeta, amtsgerichtCommon] = await Promise.all([
fetchSingleEntry("vorab-check-common"),
fetchCollectionEntry("result-pages", slug),
fetchMeta({ slug: pathname.substring(0, pathname.lastIndexOf("/")) }),
fetchSingleEntry("amtsgericht-common"),
]);

const reasonElementsWithID =
Expand Down Expand Up @@ -95,6 +99,8 @@ export const loader = async ({
},
bannerState:
getFeedbackBannerState(session, pathname) ?? BannerState.ShowRating,
amtsgerichtCommon,
courts: partnerCourtFromAirports([data.startAirport, data.endAirport]),
},
{ headers: { "Set-Cookie": await commitSession(session) } },
);
Expand Down Expand Up @@ -136,6 +142,8 @@ export function Step() {
nextButton,
backButton,
bannerState,
amtsgerichtCommon,
courts,
} = useLoaderData<typeof loader>();

const documentsList = cmsData.documents.data?.attributes.element ?? [];
Expand Down Expand Up @@ -173,9 +181,8 @@ export function Step() {
</div>
</Container>
)}

{(cmsData.linkText || cmsData.backLinkInHeader) && (
<Container paddingTop="16" paddingBottom="16">
<Container paddingTop="16" paddingBottom="16">
{(cmsData.linkText || cmsData.backLinkInHeader) && (
<ButtonContainer>
{cmsData.backLinkInHeader && (
<a className="text-link" href={backButton.destination}>
Expand All @@ -191,9 +198,52 @@ export function Step() {
</a>
)}
</ButtonContainer>
</Container>
)}
)}
</Container>
</div>

{courts && courts.length > 0 && (
<>
{courts.length > 1 && (
<Background backgroundColor="blue">
<Container
backgroundColor="blue"
overhangingBackground
paddingBottom="0"
>
{/* TODO: Move to CMS */}
Wir haben für Sie mehrere passende Amtsgerichte gefunden. Sie
können entscheiden, bei welchem Gericht sie eine Klage
einreichen möchten.
</Container>
</Background>
)}

{courts.map((court) => (
<div key={court.BEZEICHNUNG}>
<Background
backgroundColor="blue"
paddingBottom="48"
paddingTop="40"
>
<Container backgroundColor="white" overhangingBackground>
<CourtDetails
name={court.BEZEICHNUNG}
street={court.STR_HNR}
city={`${court.PLZ_ZUSTELLBEZIRK} ${court.ORT}`}
website={court.URL1}
phone={court.TEL}
addressLabel={amtsgerichtCommon.resultAddress}
websiteLabel={amtsgerichtCommon.resultWebsite}
phoneLabel={amtsgerichtCommon.resultPhone}
/>
</Container>
</Background>
</div>
))}
</>
)}

{content.length > 0 && <PageContent content={content} />}
{reasons.length > 0 && (
<Container>
Expand Down

0 comments on commit 4535936

Please sign in to comment.