Skip to content

Commit

Permalink
refactor: simplify application queries
Browse files Browse the repository at this point in the history
  • Loading branch information
joonatank committed Dec 18, 2024
1 parent 6ffeecf commit 572f1b7
Show file tree
Hide file tree
Showing 10 changed files with 853 additions and 1,404 deletions.
780 changes: 258 additions & 522 deletions apps/admin-ui/gql/gql-types.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions apps/admin-ui/src/spa/applications/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export const APPLICATION_ADMIN_QUERY = gql`
application(id: $id) {
...ApplicationAdmin
workingMemo
user {
id
email
}
}
}
`;
Expand Down
8 changes: 5 additions & 3 deletions apps/ui/components/application/ApplicantInfoPreview.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { useTranslation } from "next-i18next";
import { ApplicantTypeChoice, type ApplicationQuery } from "@gql/gql-types";
import { type ApplicantFragment, ApplicantTypeChoice } from "@gql/gql-types";
import {
ApplicationInfoContainer,
InfoItemContainer,
Expand All @@ -25,11 +25,13 @@ const LabelValue = ({
</InfoItemContainer>
);
};
type Node = NonNullable<ApplicationQuery["application"]>;

type ApplicantT = Omit<ApplicantFragment, "homeCity" | "additionalInformation">;

export function ApplicantInfoPreview({
application,
}: {
application: Node;
application: ApplicantT;
}): JSX.Element {
const { t } = useTranslation();
const applicant = {
Expand Down
19 changes: 12 additions & 7 deletions apps/ui/components/application/ApplicationEventList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import type { TFunction } from "i18next";
import { useTranslation } from "next-i18next";
import {
type AgeGroupNode,
type ApplicationQuery,
type Maybe,
type SuitableTimeRangeNode,
Priority,
ApplicationSectionStatusChoice,
type ApplicationSectionUiFragment,
type ApplicationCommonFragment,
} from "@gql/gql-types";
import { getTranslation } from "common/src/common/util";
import { convertWeekday } from "common/src/conversion";
Expand Down Expand Up @@ -103,15 +104,17 @@ const InfoListItem = ({ label, value }: { label: string; value: string }) => (
</li>
);

const SingleApplicationSection = ({
type ApplicationSectionT = ApplicationSectionUiFragment;

function SingleApplicationSection({
applicationEvent,
primaryTimes,
secondaryTimes,
}: {
applicationEvent: NonNullable<Node["applicationSections"]>[0];
applicationEvent: ApplicationSectionT;
primaryTimes: ApplicationEventScheduleFormType[];
secondaryTimes: ApplicationEventScheduleFormType[];
}) => {
}) {
const { t } = useTranslation();
const reservationUnits = filterNonNullable(
applicationEvent.reservationUnitOptions
Expand Down Expand Up @@ -208,15 +211,16 @@ const SingleApplicationSection = ({
</ApplicationInfoContainer>
</ApplicationSection>
);
};
}

// NOTE: used by Preview and View
// No form context unlike the edit pages, use application query result
type Node = NonNullable<ApplicationQuery["application"]>;
type ApplicationT = Pick<ApplicationCommonFragment, "applicationSections">;

export function ApplicationEventList({
application,
}: {
application: Node;
application: ApplicationT;
}): JSX.Element {
const sections = filterNonNullable(application.applicationSections).map(
(applicationEvent) => {
Expand All @@ -241,6 +245,7 @@ export function ApplicationEventList({
);
}
);

return <>{sections}</>;
}

Expand Down
29 changes: 17 additions & 12 deletions apps/ui/components/application/ViewApplication.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ import React from "react";
import { Checkbox } from "hds-react";
import { useTranslation } from "next-i18next";
import {
type ApplicationQuery,
type ApplicationCommonFragment,
ApplicationStatusChoice,
type Maybe,
type TermsOfUseTextFieldsFragment,
} from "@gql/gql-types";
import { getTranslation } from "@/modules/util";
import { ApplicantInfoPreview } from "./ApplicantInfoPreview";
import {
ApplicationSection,
Expand All @@ -18,20 +17,26 @@ import {
import { ApplicationEventList } from "./ApplicationEventList";
import Sanitize from "../common/Sanitize";
import TermsBox from "common/src/termsbox/TermsBox";
import {
convertLanguageCode,
getTranslationSafe,
} from "common/src/common/util";

type ViewApplicationProps = {
application: ApplicationCommonFragment;
tos: Maybe<TermsOfUseTextFieldsFragment>;
acceptTermsOfUse?: boolean;
setAcceptTermsOfUse?: (value: boolean) => void;
};

type Node = NonNullable<ApplicationQuery["application"]>;
export function ViewApplication({
application,
tos,
acceptTermsOfUse,
setAcceptTermsOfUse,
}: {
application: Node;
tos: Maybe<TermsOfUseTextFieldsFragment>;
acceptTermsOfUse?: boolean;
setAcceptTermsOfUse?: (value: boolean) => void;
}): JSX.Element {
const { t } = useTranslation();
}: ViewApplicationProps): JSX.Element {
const { t, i18n } = useTranslation();
const lang = convertLanguageCode(i18n.language);

const tos2 = application.applicationRound?.termsOfUse;
const shouldShowNotification =
Expand All @@ -56,15 +61,15 @@ export function ViewApplication({
>
<TermsBox
id="preview.acceptTermsOfUse"
body={<Sanitize html={getTranslation(tos, "text")} />}
body={<Sanitize html={getTranslationSafe(tos, "text", lang)} />}
/>
</Accordion>
)}
{tos2 && (
<Accordion heading={t("application:preview.reservationUnitTerms")} open>
<TermsBox
id="preview.acceptServiceSpecificTerms"
body={<Sanitize html={getTranslation(tos2, "text")} />}
body={<Sanitize html={getTranslationSafe(tos2, "text", lang)} />}
/* TODO TermsBox has accepted and checkbox we could use but for now leaving the single
* page specific checkbox to accept all terms */
/>
Expand Down
Loading

0 comments on commit 572f1b7

Please sign in to comment.