Skip to content

Commit 02bb052

Browse files
Fix template Avatar (#5294)
1 parent 02dcd0e commit 02bb052

File tree

3 files changed

+97
-47
lines changed

3 files changed

+97
-47
lines changed

site/src/pages/CreateWorkspacePage/CreateWorkspacePageView.tsx

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { AlertBanner } from "components/AlertBanner/AlertBanner"
1414
import { makeStyles } from "@material-ui/core/styles"
1515
import { FullPageHorizontalForm } from "components/FullPageForm/FullPageHorizontalForm"
1616
import { FullScreenLoader } from "components/Loader/FullScreenLoader"
17+
import { SelectedTemplate } from "./SelectedTemplate"
1718

1819
export enum CreateWorkspaceErrors {
1920
GET_TEMPLATES_ERROR = "getTemplatesError",
@@ -171,28 +172,7 @@ export const CreateWorkspacePageView: FC<
171172
className={styles.formSectionFields}
172173
>
173174
{props.selectedTemplate && (
174-
<Stack
175-
direction="row"
176-
spacing={2}
177-
className={styles.template}
178-
alignItems="center"
179-
>
180-
<div className={styles.templateIcon}>
181-
<img src={props.selectedTemplate.icon} alt="" />
182-
</div>
183-
<Stack direction="column" spacing={0.5}>
184-
<span className={styles.templateName}>
185-
{props.selectedTemplate.display_name.length > 0
186-
? props.selectedTemplate.display_name
187-
: props.selectedTemplate.name}
188-
</span>
189-
{props.selectedTemplate.description && (
190-
<span className={styles.templateDescription}>
191-
{props.selectedTemplate.description}
192-
</span>
193-
)}
194-
</Stack>
195-
</Stack>
175+
<SelectedTemplate template={props.selectedTemplate} />
196176
)}
197177

198178
<TextField
@@ -327,31 +307,6 @@ const useStyles = makeStyles((theme) => ({
327307
formSectionFields: {
328308
width: "100%",
329309
},
330-
331-
template: {
332-
padding: theme.spacing(2.5, 3),
333-
borderRadius: theme.shape.borderRadius,
334-
backgroundColor: theme.palette.background.paper,
335-
border: `1px solid ${theme.palette.divider}`,
336-
},
337-
338-
templateName: {
339-
fontSize: 16,
340-
},
341-
342-
templateDescription: {
343-
fontSize: 14,
344-
color: theme.palette.text.secondary,
345-
},
346-
347-
templateIcon: {
348-
width: theme.spacing(5),
349-
lineHeight: 1,
350-
351-
"& img": {
352-
width: "100%",
353-
},
354-
},
355310
}))
356311

357312
const useFormFooterStyles = makeStyles((theme) => ({
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ComponentMeta, Story } from "@storybook/react"
2+
import { MockTemplate } from "../../testHelpers/entities"
3+
import { SelectedTemplate, SelectedTemplateProps } from "./SelectedTemplate"
4+
5+
export default {
6+
title: "components/SelectedTemplate",
7+
component: SelectedTemplate,
8+
} as ComponentMeta<typeof SelectedTemplate>
9+
10+
const Template: Story<SelectedTemplateProps> = (args) => (
11+
<SelectedTemplate {...args} />
12+
)
13+
14+
export const WithIcon = Template.bind({})
15+
WithIcon.args = {
16+
template: MockTemplate,
17+
}
18+
19+
export const WithoutIcon = Template.bind({})
20+
WithoutIcon.args = {
21+
template: {
22+
...MockTemplate,
23+
icon: "",
24+
},
25+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import Avatar from "@material-ui/core/Avatar"
2+
import { makeStyles } from "@material-ui/core/styles"
3+
import { Template } from "api/typesGenerated"
4+
import { Stack } from "components/Stack/Stack"
5+
import React, { FC } from "react"
6+
import { firstLetter } from "util/firstLetter"
7+
8+
export interface SelectedTemplateProps {
9+
template: Template
10+
}
11+
12+
export const SelectedTemplate: FC<SelectedTemplateProps> = ({ template }) => {
13+
const styles = useStyles()
14+
15+
return (
16+
<Stack
17+
direction="row"
18+
spacing={3}
19+
className={styles.template}
20+
alignItems="center"
21+
>
22+
<div className={styles.templateIcon}>
23+
{template.icon === "" ? (
24+
<Avatar>{firstLetter(template.name)}</Avatar>
25+
) : (
26+
<img src={template.icon} alt="" />
27+
)}
28+
</div>
29+
<Stack direction="column" spacing={0.5}>
30+
<span className={styles.templateName}>
31+
{template.display_name.length > 0
32+
? template.display_name
33+
: template.name}
34+
</span>
35+
{template.description && (
36+
<span className={styles.templateDescription}>
37+
{template.description}
38+
</span>
39+
)}
40+
</Stack>
41+
</Stack>
42+
)
43+
}
44+
45+
const useStyles = makeStyles((theme) => ({
46+
template: {
47+
padding: theme.spacing(2.5, 3),
48+
borderRadius: theme.shape.borderRadius,
49+
backgroundColor: theme.palette.background.paper,
50+
border: `1px solid ${theme.palette.divider}`,
51+
},
52+
53+
templateName: {
54+
fontSize: 16,
55+
},
56+
57+
templateDescription: {
58+
fontSize: 14,
59+
color: theme.palette.text.secondary,
60+
},
61+
62+
templateIcon: {
63+
width: theme.spacing(4),
64+
lineHeight: 1,
65+
66+
"& img": {
67+
width: "100%",
68+
},
69+
},
70+
}))

0 commit comments

Comments
 (0)