Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tags #1384

Merged
merged 7 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions apps/admin-ui/gql/gql-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6290,7 +6290,6 @@ export type UnitQuery = {
tprekId?: string | null;
shortDescriptionFi?: string | null;
reservationunitSet: Array<{
isArchived: boolean;
isDraft: boolean;
id: string;
pk?: number | null;
Expand Down Expand Up @@ -10099,7 +10098,6 @@ export const UnitDocument = gql`
shortDescriptionFi
reservationunitSet {
...ReservationUnitCommonFields
isArchived
resources {
id
pk
Expand Down
1 change: 0 additions & 1 deletion apps/admin-ui/src/common/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export const UNIT_QUERY = gql`
shortDescriptionFi
reservationunitSet {
...ReservationUnitCommonFields
isArchived
resources {
id
pk
Expand Down
1 change: 1 addition & 0 deletions apps/admin-ui/src/component/SearchTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function SearchTags({
<StyledTag
onDelete={() => handleDelete(tag)}
key={`${tag.key}-${tag.value}`}
id={`search-tag-${tag.key}`}
>
{tag.tr}
</StyledTag>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Address,
Name,
Parent,
RoundTag,
StyledTag,
Title,
UnitInfo,
} from "./modules/newSpaceModal";
Expand Down Expand Up @@ -41,7 +41,7 @@ export function Page1({
<>
<CustomDialogHeader
id="dialog-title"
extras={<RoundTag>{t("SpaceModal.phase")} 1/2</RoundTag>}
extras={<StyledTag>{t("SpaceModal.phase")} 1/2</StyledTag>}
title={t(
hasFixedParent
? "SpaceModal.page1.subSpaceModalTitle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Address,
Name,
Parent,
RoundTag,
StyledTag,
UnitInfo,
} from "./modules/newSpaceModal";
import { parseAddress } from "@/common/util";
Expand Down Expand Up @@ -49,7 +49,7 @@ export function Page2({
? "SpaceModal.page2.subSpaceModalTitle"
: "SpaceModal.page2.modalTitle"
)}
extras={<RoundTag>{t("SpaceModal.phase")} 2/2</RoundTag>}
extras={<StyledTag>{t("SpaceModal.phase")} 2/2</StyledTag>}
close={closeModal}
/>
<Dialog.Content>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export const EditorColumns = styled.div`
padding-bottom: var(--spacing-m);
`;

export const RoundTag = styled(Tag)`
border-radius: 10px;
export const StyledTag = styled(Tag)`
background-color: var(--color-bus-light);
color: var(--color-bus);
font-weight: 600;
Expand Down
26 changes: 9 additions & 17 deletions apps/admin-ui/src/component/Unit/ReservationUnitCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import {
IconLayers,
IconHome,
IconGroup,
Tag,
IconPen,
IconCheck,
} from "hds-react";
import { useTranslation } from "react-i18next";
import { H2, fontMedium } from "common/src/common/typography";
import { breakpoints } from "common/src/common/style";
import { ImageType, type UnitQuery } from "@gql/gql-types";
import { BasicLink } from "@/styles/util";
import IconDraft from "@/images/icon_draft.svg";
import { getImageSource } from "common/src/helpers";
import { NoWrap } from "common/styles/util";
import StatusLabel from "common/src/components/StatusLabel";

type UnitType = NonNullable<UnitQuery["unit"]>;
type ReservationUnitType = NonNullable<UnitType["reservationunitSet"]>[0];
Expand Down Expand Up @@ -95,11 +96,6 @@ const Prop = styled.div<{ $disabled?: boolean }>`
}
`;

const Published = styled(Tag)`
background-color: var(--color-success);
color: var(--color-white);
`;

export function ReservationUnitCard({
reservationUnit,
unitId,
Expand Down Expand Up @@ -157,18 +153,14 @@ export function ReservationUnitCard({
t("ReservationUnitCard.noMaxPersons")}
</Prop>
<Prop>
{reservationUnit.isArchived ? (
<>
<IconDraft />
{t("ReservationUnitCard.stateArchived")}
</>
) : reservationUnit.isDraft ? (
<>
<IconDraft />
{reservationUnit.isDraft ? (
<StatusLabel type="draft" icon={<IconPen ariaHidden />}>
{t("ReservationUnitCard.stateDraft")}
</>
</StatusLabel>
) : (
<Published>{t("ReservationUnitCard.statePublished")}</Published>
<StatusLabel type="success" icon={<IconCheck ariaHidden />}>
{t("ReservationUnitCard.statePublished")}
</StatusLabel>
)}
</Prop>
</Props>
Expand Down
46 changes: 34 additions & 12 deletions apps/admin-ui/src/component/notifications/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { Controller, useForm } from "react-hook-form";
import {
Button,
IconCheck,
IconClock,
IconPen,
RadioButton,
Select,
SelectionGroup,
Tag,
TextInput,
} from "hds-react";
import {
Expand Down Expand Up @@ -49,6 +51,9 @@ import { base64encode } from "common/src/helpers";
import ControlledDateInput from "@/component/ControlledDateInput";
import ControlledTimeInput from "@/component/ControlledTimeInput";
import { errorToast, successToast } from "common/src/common/toast";
import StatusLabel, {
type StatusLabelType,
} from "common/src/components/StatusLabel";

const RichTextInput = dynamic(() => import("@/component/RichTextInput"), {
ssr: false,
Expand Down Expand Up @@ -112,35 +117,52 @@ function convertTarget(
}
}

const StyledTag = styled(Tag)`
const StyledStatusLabel = styled(StatusLabel)`
justify-content: center;
white-space: nowrap;
`;

function BannerNotificationStateTag({
type NotificationStatus = {
type: StatusLabelType;
icon: JSX.Element;
};

function BannerNotificationStatusLabel({
state,
}: {
state: BannerNotificationState;
}) {
const color = ((s: BannerNotificationState) => {
const statusLabelProps = ((
s: BannerNotificationState
): NotificationStatus => {
switch (s) {
case BannerNotificationState.Draft:
return "var(--color-summer-light)";
return {
type: "draft",
icon: <IconPen ariaHidden />,
};
case BannerNotificationState.Active:
return "var(--color-bus-light)";
return {
type: "success",
icon: <IconCheck ariaHidden />,
};
case BannerNotificationState.Scheduled:
return "var(--color-black-5)";
return {
type: "info",
icon: <IconClock ariaHidden />,
};
}
})(state);

const { t } = useTranslation();

return (
<StyledTag
theme={{ "--tag-background": color }}
labelProps={{ style: { whiteSpace: "nowrap" } }}
<StyledStatusLabel
type={statusLabelProps.type}
icon={statusLabelProps.icon}
>
{t(`Notifications.state.${state}`)}
</StyledTag>
</StyledStatusLabel>
);
}

Expand Down Expand Up @@ -705,7 +727,7 @@ function LoadedContent({
<StatusTagContainer>
<H1 $legacy>{name}</H1>
{notification?.state && (
<BannerNotificationStateTag state={notification.state} />
<BannerNotificationStatusLabel state={notification.state} />
)}
</StatusTagContainer>
{(notification || isNew) && (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import React, { forwardRef } from "react";
import { Tag } from "hds-react";
import { IconEuroSign } from "hds-react";
import styled from "styled-components";
import { useTranslation } from "react-i18next";
import { H1, fontMedium } from "common/src/common/typography";
import { fontMedium, H1 } from "common/src/common/typography";
import { breakpoints } from "common/src/common/style";
import {
useReservationApplicationLinkQuery,
type Maybe,
OrderStatus,
type ReservationQuery,
useReservationApplicationLinkQuery,
} from "@gql/gql-types";
import { getName } from "./util";
import { HorisontalFlex } from "@/styles/layout";
import { formatDateTime } from "@/common/util";
import { getApplicationUrl } from "@/common/urls";
import { gql } from "@apollo/client";
import { ExternalLink } from "@/component/ExternalLink";
import StatusLabel, {
type StatusLabelType,
} from "common/src/components/StatusLabel";

const Dot = styled.div`
display: inline-block;
Expand Down Expand Up @@ -116,20 +121,36 @@ const ReservationTitleSection = forwardRef<HTMLDivElement, Props>(
: null;

const order = reservation.paymentOrder[0];
const statusLabelType = ((s?: Maybe<OrderStatus>): StatusLabelType => {
switch (s) {
case OrderStatus.Paid:
case OrderStatus.Refunded:
return "success";
case OrderStatus.Expired:
return "error";
case OrderStatus.PaidManually:
case OrderStatus.Draft:
return "alert";
case OrderStatus.Cancelled:
default:
return "neutral";
}
})(order?.status);

return (
<div>
<NameState ref={ref}>
<H1 $legacy>{overrideTitle ?? getName(reservation, t)}</H1>
<HorisontalFlex>
<AlignVertically>
{order?.status != null && (
<Tag
theme={{ "--tag-background": "var(--color-engel-light)" }}
<StatusLabel
type={statusLabelType}
data-testid="reservation_title_section__order_status"
id="reservation-order_status"
icon={<IconEuroSign ariaHidden />}
>
{t(`Payment.status.${order?.status}`)}
</Tag>
</StatusLabel>
)}
</AlignVertically>
<AlignVertically style={{ gap: "var(--spacing-xs)" }}>
Expand Down
Loading