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

Commit

Permalink
Frontend cleanups
Browse files Browse the repository at this point in the history
Including:

  - use a readonly field for the email list
  - use the MFA control
  - compound upgrade
  - stopped using deprecated compound exports/components
  • Loading branch information
sandhose committed Oct 27, 2023
1 parent 8a40eb3 commit 4497ce8
Show file tree
Hide file tree
Showing 20 changed files with 261 additions and 293 deletions.
20 changes: 14 additions & 6 deletions frontend/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
},
"session": {
"current_badge": "Current",
"finished_date": "Finished <1/>",
"signed_in_date": "Signed in <1/>"
"finished_date": "Finished <datetime/>",
"signed_in_date": "Signed in <datetime/>"
},
"session_detail": {
"alert": {
Expand Down Expand Up @@ -141,12 +141,20 @@
"heading": "Where you're signed in"
},
"verify_email": {
"code_field_error": "Code not recognised",
"code_field_label": "6-digit code",
"enter_code_prompt": "Enter the 6-digit code sent to <2>{{email}}</2>",
"code_field_wrong_shape": "Code must be 6 digits",
"email_sent_alert": {
"description": "Enter the new code below.",
"title": "New code sent"
},
"enter_code_prompt": "Enter the 6-digit code sent to: <email>{{email}}</email>",
"heading": "Verify your email",
"invalid_code_alert": "Invalid code",
"resend_email": "Resend email",
"sent": "Sent!",
"invalid_code_alert": {
"description": "Check the code sent to your email and update the fields below to continue.",
"title": "You entered the wrong code"
},
"resend_code": "Resend code",
"unknown_email": "Unknown email"
}
}
Expand Down
20 changes: 10 additions & 10 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"@urql/exchange-graphcache": "^6.3.3",
"@urql/exchange-refocus": "^1.0.2",
"@urql/exchange-request-policy": "^1.0.2",
"@vector-im/compound-design-tokens": "^0.0.6",
"@vector-im/compound-web": "^0.6.0",
"@vector-im/compound-design-tokens": "^0.0.7",
"@vector-im/compound-web": "^0.6.1",
"classnames": "^2.3.2",
"date-fns": "^2.30.0",
"graphql": "^16.8.1",
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/BlockList/BlockList.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

import { Meta, StoryObj } from "@storybook/react";
import { H2, Body } from "@vector-im/compound-web";
import { H2, Text } from "@vector-im/compound-web";

import Block from "../Block";

Expand All @@ -33,11 +33,11 @@ export const Basic: Story = {
<BlockList {...args}>
<Block>
<H2>Block 1</H2>
<Body>Body 1</Body>
<Text>Body 1</Text>
</Block>
<Block>
<H2>Block 2</H2>
<Body>Body 2</Body>
<Text>Body 2</Text>
</Block>
</BlockList>
),
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/components/BrowserSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { useCallback } from "react";

import { currentBrowserSessionIdAtom, currentUserIdAtom } from "../atoms";
import { FragmentType, graphql, useFragment } from "../gql";
import Link from "../routing/Link";
import {
parseUserAgent,
sessionNameFromDeviceInformation,
Expand Down Expand Up @@ -114,19 +113,17 @@ const BrowserSession: React.FC<Props> = ({ session }) => {
const sessionName =
sessionNameFromDeviceInformation(deviceInformation) || "Browser session";

const name = (
<Link route={{ type: "browser-session", id: data.id }}>{sessionName}</Link>
);
return (
<Session
id={data.id}
name={name}
name={sessionName}
createdAt={createdAt}
finishedAt={finishedAt}
isCurrent={isCurrent}
deviceType={deviceInformation?.deviceType}
lastActiveIp={data.lastActiveIp || undefined}
lastActiveAt={lastActiveAt}
link={{ type: "browser-session", id: data.id }}
>
{!data.finishedAt && <EndSessionButton endSession={onSessionEnd} />}
</Session>
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/components/CompatSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { atomFamily } from "jotai/utils";
import { atomWithMutation } from "jotai-urql";

import { FragmentType, graphql, useFragment } from "../gql";
import { Link } from "../routing";

import { Session } from "./Session";
import EndSessionButton from "./Session/EndSessionButton";
Expand Down Expand Up @@ -93,10 +92,6 @@ const CompatSession: React.FC<{
await endCompatSession();
};

const sessionName = (
<Link route={{ type: "session", id: data.deviceId }}>{data.deviceId}</Link>
);

const clientName = data.ssoLogin?.redirectUri
? simplifyUrl(data.ssoLogin.redirectUri)
: undefined;
Expand All @@ -110,12 +105,13 @@ const CompatSession: React.FC<{
return (
<Session
id={data.id}
name={sessionName}
name={data.deviceId}
createdAt={createdAt}
finishedAt={finishedAt}
clientName={clientName}
lastActiveIp={data.lastActiveIp || undefined}
lastActiveAt={lastActiveAt}
link={{ type: "session", id: data.deviceId }}
>
{!data.finishedAt && <EndSessionButton endSession={onSessionEnd} />}
</Session>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Layout: React.FC<{ children?: React.ReactNode }> = ({ children }) => {
</>
)}

<main>{children}</main>
{children}

<Footer
imprint={appConfig.branding?.imprint}
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/components/OAuth2Session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { atomWithMutation } from "jotai-urql";

import { FragmentType, graphql, useFragment } from "../gql";
import { Oauth2ApplicationType } from "../gql/graphql";
import { Link } from "../routing";
import { getDeviceIdFromScope } from "../utils/deviceIdFromScope";
import { DeviceType } from "../utils/parseUserAgent";

Expand Down Expand Up @@ -94,9 +93,9 @@ const OAuth2Session: React.FC<Props> = ({ session }) => {

const deviceId = getDeviceIdFromScope(data.scope);

const name = deviceId && (
<Link route={{ type: "session", id: deviceId }}>{deviceId}</Link>
);
const link = deviceId
? { type: "session" as const, id: deviceId }
: undefined;

const createdAt = parseISO(data.createdAt);
const finishedAt = data.finishedAt ? parseISO(data.finishedAt) : undefined;
Expand All @@ -111,14 +110,15 @@ const OAuth2Session: React.FC<Props> = ({ session }) => {
return (
<Session
id={data.id}
name={name}
name={deviceId}
createdAt={createdAt}
finishedAt={finishedAt}
clientName={data.client.clientName || data.client.clientId || undefined}
clientLogoUri={data.client.logoUri || undefined}
deviceType={deviceType}
lastActiveIp={data.lastActiveIp || undefined}
lastActiveAt={lastActiveAt}
link={link}
>
{!data.finishedAt && <EndSessionButton endSession={onSessionEnd} />}
</Session>
Expand Down
29 changes: 17 additions & 12 deletions frontend/src/components/Session/Session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import { H6, Body, Badge } from "@vector-im/compound-web";
import { ReactNode } from "react";
import { H6, Text, Badge } from "@vector-im/compound-web";
import { Trans, useTranslation } from "react-i18next";

import { Route, Link } from "../../routing";
import { DeviceType } from "../../utils/parseUserAgent";
import Block from "../Block";
import DateTime from "../DateTime";
Expand All @@ -25,13 +25,13 @@ import DeviceTypeIcon from "./DeviceTypeIcon";
import LastActive from "./LastActive";
import styles from "./Session.module.css";

const SessionMetadata: React.FC<React.ComponentProps<typeof Body>> = (
const SessionMetadata: React.FC<React.ComponentProps<typeof Text>> = (
props,
) => <Body {...props} size="sm" className={styles.sessionMetadata} />;
) => <Text {...props} size="sm" className={styles.sessionMetadata} />;

type SessionProps = {
id: string;
name?: string | ReactNode;
name?: string;
createdAt: Date;
finishedAt?: Date;
clientName?: string;
Expand All @@ -40,7 +40,9 @@ type SessionProps = {
deviceType?: DeviceType;
lastActiveIp?: string;
lastActiveAt?: Date;
link?: Route;
};

const Session: React.FC<React.PropsWithChildren<SessionProps>> = ({
id,
name,
Expand All @@ -53,6 +55,7 @@ const Session: React.FC<React.PropsWithChildren<SessionProps>> = ({
isCurrent,
children,
deviceType,
link,
}) => {
const { t } = useTranslation();

Expand All @@ -64,18 +67,20 @@ const Session: React.FC<React.PropsWithChildren<SessionProps>> = ({
<Badge kind="success">{t("frontend.session.current_badge")}</Badge>
)}
<H6 className={styles.sessionName} title={id}>
{name || id}
{link ? <Link route={link}>{name || id}</Link> : name || id}
</H6>
<SessionMetadata weight="semibold">
<Trans i18nKey="frontend.session.signed_in_date">
Signed in <DateTime datetime={createdAt} />
</Trans>
<Trans
i18nKey="frontend.session.signed_in_date"
components={{ datetime: <DateTime datetime={createdAt} /> }}
/>
</SessionMetadata>
{!!finishedAt && (
<SessionMetadata weight="semibold" data-finished={true}>
<Trans i18nKey="frontend.session.finished_date">
Finished <DateTime datetime={finishedAt} />
</Trans>
<Trans
i18nKey="frontend.session.finished_date"
components={{ datetime: <DateTime datetime={finishedAt} /> }}
/>
</SessionMetadata>
)}
{!!lastActiveAt && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ exports[`<CompatSessionDetail> > renders a compatability session details 1`] = `
<span
title="Sat, 29 Jul 2023, 03:35"
>
Active Sat, 29 Jul 2023, 03:35
Inactive for 90+ days
</span>
</p>
</li>
Expand Down Expand Up @@ -305,7 +305,7 @@ exports[`<CompatSessionDetail> > renders a compatability session without an ssoL
<span
title="Sat, 29 Jul 2023, 03:35"
>
Active Sat, 29 Jul 2023, 03:35
Inactive for 90+ days
</span>
</p>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ exports[`<OAuth2SessionDetail> > renders session details 1`] = `
<span
title="Sat, 29 Jul 2023, 03:35"
>
Active Sat, 29 Jul 2023, 03:35
Inactive for 90+ days
</span>
</p>
</li>
Expand Down
Loading

0 comments on commit 4497ce8

Please sign in to comment.