Skip to content

Commit 8a48485

Browse files
authored
refactor: clean up Welcome component (#11526)
1 parent 4fa0712 commit 8a48485

File tree

5 files changed

+53
-41
lines changed

5 files changed

+53
-41
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { Meta, StoryObj } from "@storybook/react";
2+
import { Welcome } from "./Welcome";
3+
4+
const meta: Meta<typeof Welcome> = {
5+
title: "components/Welcome",
6+
component: Welcome,
7+
};
8+
9+
export default meta;
10+
type Story = StoryObj<typeof Welcome>;
11+
12+
const Example: Story = {};
13+
14+
export { Example as Welcome };
+31-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { type Interpolation, type Theme } from "@emotion/react";
12
import { type FC, type PropsWithChildren } from "react";
2-
import { useTheme } from "@emotion/react";
33
import { CoderIcon } from "../Icons/CoderIcon";
44

55
const Language = {
@@ -10,43 +10,39 @@ const Language = {
1010
),
1111
};
1212

13-
export const Welcome: FC<
14-
PropsWithChildren<{ message?: JSX.Element | string }>
15-
> = ({ message = Language.defaultMessage }) => {
16-
const theme = useTheme();
17-
13+
export const Welcome: FC<PropsWithChildren> = ({ children }) => {
1814
return (
1915
<div>
20-
<div
21-
css={{
22-
display: "flex",
23-
justifyContent: "center",
24-
}}
25-
>
26-
<CoderIcon
27-
css={{
28-
color: theme.palette.text.primary,
29-
fontSize: 64,
30-
}}
31-
/>
16+
<div css={styles.container}>
17+
<CoderIcon css={styles.icon} />
3218
</div>
33-
<h1
34-
css={{
35-
textAlign: "center",
36-
fontSize: 32,
37-
fontWeight: 400,
38-
margin: 0,
39-
marginTop: 16,
40-
marginBottom: 32,
41-
lineHeight: 1.25,
42-
43-
"& strong": {
44-
fontWeight: 600,
45-
},
46-
}}
47-
>
48-
{message}
49-
</h1>
19+
<h1 css={styles.header}>{children || Language.defaultMessage}</h1>
5020
</div>
5121
);
5222
};
23+
24+
const styles = {
25+
container: {
26+
display: "flex",
27+
justifyContent: "center",
28+
},
29+
30+
icon: (theme) => ({
31+
color: theme.palette.text.primary,
32+
fontSize: 64,
33+
}),
34+
35+
header: {
36+
textAlign: "center",
37+
fontSize: 32,
38+
fontWeight: 400,
39+
margin: 0,
40+
marginTop: 16,
41+
marginBottom: 32,
42+
lineHeight: 1.25,
43+
44+
"& strong": {
45+
fontWeight: 600,
46+
},
47+
},
48+
} satisfies Record<string, Interpolation<Theme>>;

site/src/pages/CliAuthPage/CliAuthPageView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const CliAuthPageView: FC<CliAuthPageViewProps> = ({ sessionToken }) => {
2020

2121
return (
2222
<SignInLayout>
23-
<Welcome message="Session token" />
23+
<Welcome>Session token</Welcome>
2424

2525
<p
2626
css={{

site/src/pages/ExternalAuthPage/ExternalAuthPage.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ const ExternalAuthPage: FC = () => {
6969
// show an error there?
7070
return (
7171
<SignInLayout>
72-
<Welcome message="Failed to validate oauth access token" />
72+
<Welcome>Failed to validate oauth access token</Welcome>
73+
7374
<p css={{ textAlign: "center" }}>
7475
Attempted to validate the user&apos;s oauth access token from the
7576
authentication flow. This situation may occur as a result of an

site/src/pages/ExternalAuthPage/ExternalAuthPageView.tsx

+5-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const ExternalAuthPageView: FC<ExternalAuthPageViewProps> = ({
3333
if (!externalAuth.authenticated) {
3434
return (
3535
<SignInLayout>
36-
<Welcome message={`Authenticate with ${externalAuth.display_name}`} />
36+
<Welcome>Authenticate with {externalAuth.display_name}</Welcome>
3737

3838
{externalAuth.device && (
3939
<GitDeviceAuth
@@ -63,9 +63,10 @@ const ExternalAuthPageView: FC<ExternalAuthPageViewProps> = ({
6363

6464
return (
6565
<SignInLayout>
66-
<Welcome
67-
message={`You've authenticated with ${externalAuth.display_name}!`}
68-
/>
66+
<Welcome>
67+
You&apos;ve authenticated with {externalAuth.display_name}!
68+
</Welcome>
69+
6970
<p css={styles.text}>
7071
{externalAuth.user?.login && `Hey @${externalAuth.user?.login}! 👋 `}
7172
{(!externalAuth.app_installable ||

0 commit comments

Comments
 (0)