Skip to content

refactor: clean up Welcome component #11526

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

Merged
merged 3 commits into from
Jan 9, 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
14 changes: 14 additions & 0 deletions site/src/components/Welcome/Welcome.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Meta, StoryObj } from "@storybook/react";
import { Welcome } from "./Welcome";

const meta: Meta<typeof Welcome> = {
title: "components/Welcome",
component: Welcome,
};

export default meta;
type Story = StoryObj<typeof Welcome>;

const Example: Story = {};

export { Example as Welcome };
66 changes: 31 additions & 35 deletions site/src/components/Welcome/Welcome.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Interpolation, type Theme } from "@emotion/react";
import { type FC, type PropsWithChildren } from "react";
import { useTheme } from "@emotion/react";
import { CoderIcon } from "../Icons/CoderIcon";

const Language = {
Expand All @@ -10,43 +10,39 @@ const Language = {
),
};

export const Welcome: FC<
PropsWithChildren<{ message?: JSX.Element | string }>
> = ({ message = Language.defaultMessage }) => {
const theme = useTheme();

export const Welcome: FC<PropsWithChildren> = ({ children }) => {
return (
<div>
<div
css={{
display: "flex",
justifyContent: "center",
}}
>
<CoderIcon
css={{
color: theme.palette.text.primary,
fontSize: 64,
}}
/>
<div css={styles.container}>
<CoderIcon css={styles.icon} />
</div>
<h1
css={{
textAlign: "center",
fontSize: 32,
fontWeight: 400,
margin: 0,
marginTop: 16,
marginBottom: 32,
lineHeight: 1.25,

"& strong": {
fontWeight: 600,
},
}}
>
{message}
</h1>
<h1 css={styles.header}>{children || Language.defaultMessage}</h1>
</div>
);
};

const styles = {
container: {
display: "flex",
justifyContent: "center",
},

icon: (theme) => ({
color: theme.palette.text.primary,
fontSize: 64,
}),

header: {
textAlign: "center",
fontSize: 32,
fontWeight: 400,
margin: 0,
marginTop: 16,
marginBottom: 32,
lineHeight: 1.25,

"& strong": {
fontWeight: 600,
},
},
} satisfies Record<string, Interpolation<Theme>>;
2 changes: 1 addition & 1 deletion site/src/pages/CliAuthPage/CliAuthPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const CliAuthPageView: FC<CliAuthPageViewProps> = ({ sessionToken }) => {

return (
<SignInLayout>
<Welcome message="Session token" />
<Welcome>Session token</Welcome>

<p
css={{
Expand Down
3 changes: 2 additions & 1 deletion site/src/pages/ExternalAuthPage/ExternalAuthPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ const ExternalAuthPage: FC = () => {
// show an error there?
return (
<SignInLayout>
<Welcome message="Failed to validate oauth access token" />
<Welcome>Failed to validate oauth access token</Welcome>

<p css={{ textAlign: "center" }}>
Attempted to validate the user&apos;s oauth access token from the
authentication flow. This situation may occur as a result of an
Expand Down
9 changes: 5 additions & 4 deletions site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ExternalAuthPageView: FC<ExternalAuthPageViewProps> = ({
if (!externalAuth.authenticated) {
return (
<SignInLayout>
<Welcome message={`Authenticate with ${externalAuth.display_name}`} />
<Welcome>Authenticate with {externalAuth.display_name}</Welcome>

{externalAuth.device && (
<GitDeviceAuth
Expand Down Expand Up @@ -63,9 +63,10 @@ const ExternalAuthPageView: FC<ExternalAuthPageViewProps> = ({

return (
<SignInLayout>
<Welcome
message={`You've authenticated with ${externalAuth.display_name}!`}
/>
<Welcome>
You&apos;ve authenticated with {externalAuth.display_name}!
</Welcome>

<p css={styles.text}>
{externalAuth.user?.login && `Hey @${externalAuth.user?.login}! 👋 `}
{(!externalAuth.app_installable ||
Expand Down