|
1 | 1 | import type { Interpolation, Theme } from "@emotion/react";
|
| 2 | +import Card from "@mui/material/Card"; |
| 3 | +import CardActionArea from "@mui/material/CardActionArea"; |
| 4 | +import CardContent from "@mui/material/CardContent"; |
| 5 | +import Stack from "@mui/material/Stack"; |
2 | 6 | import { useState, type FC } from "react";
|
3 |
| -import { useQuery } from "react-query"; |
4 |
| -import { Link, useSearchParams } from "react-router-dom"; |
5 |
| -import { templateExamples } from "api/queries/templates"; |
6 |
| -import type { Organization, TemplateExample } from "api/typesGenerated"; |
| 7 | +import { Link as RouterLink } from "react-router-dom"; |
| 8 | +import type { Organization } from "api/typesGenerated"; |
7 | 9 | import { ErrorAlert } from "components/Alert/ErrorAlert";
|
| 10 | +import { ExternalImage } from "components/ExternalImage/ExternalImage"; |
8 | 11 | import { Loader } from "components/Loader/Loader";
|
9 | 12 | import { Margins } from "components/Margins/Margins";
|
10 | 13 | import { OrganizationAutocomplete } from "components/OrganizationAutocomplete/OrganizationAutocomplete";
|
11 | 14 | import { PageHeader, PageHeaderTitle } from "components/PageHeader/PageHeader";
|
12 |
| -import { Stack } from "components/Stack/Stack"; |
13 |
| -import { useDashboard } from "modules/dashboard/useDashboard"; |
14 |
| -import { TemplateExampleCard } from "modules/templates/TemplateExampleCard/TemplateExampleCard"; |
15 |
| -import { |
16 |
| - getTemplatesByTag, |
17 |
| - type StarterTemplatesByTag, |
18 |
| -} from "utils/starterTemplates"; |
| 15 | +// import { useDashboard } from "modules/dashboard/useDashboard"; |
| 16 | +import type { StarterTemplatesByTag } from "utils/starterTemplates"; |
19 | 17 | import { StarterTemplates } from "./StarterTemplates";
|
20 | 18 |
|
21 |
| -// const getTagLabel = (tag: string) => { |
22 |
| -// const labelByTag: Record<string, string> = { |
23 |
| -// all: "All templates", |
24 |
| -// digitalocean: "DigitalOcean", |
25 |
| -// aws: "AWS", |
26 |
| -// google: "Google Cloud", |
27 |
| -// }; |
28 |
| -// // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- this can be undefined |
29 |
| -// return labelByTag[tag] ?? tag; |
30 |
| -// }; |
31 |
| - |
32 |
| -// const selectTags = (starterTemplatesByTag: StarterTemplatesByTag) => { |
33 |
| -// return starterTemplatesByTag |
34 |
| -// ? Object.keys(starterTemplatesByTag).sort((a, b) => a.localeCompare(b)) |
35 |
| -// : undefined; |
36 |
| -// }; |
37 |
| - |
38 | 19 | export interface CreateTemplatePageViewProps {
|
39 | 20 | starterTemplatesByTag?: StarterTemplatesByTag;
|
40 | 21 | error?: unknown;
|
41 | 22 | }
|
42 | 23 |
|
43 |
| -// const removeScratchExample = (data: TemplateExample[]) => { |
44 |
| -// return data.filter((example) => example.id !== "scratch"); |
45 |
| -// }; |
46 |
| - |
47 | 24 | export const CreateTemplatesPageView: FC<CreateTemplatePageViewProps> = ({
|
48 | 25 | starterTemplatesByTag,
|
49 | 26 | error,
|
50 | 27 | }) => {
|
51 | 28 | const [selectedOrg, setSelectedOrg] = useState<Organization | null>(null);
|
52 | 29 | // const { organizationId } = useDashboard();
|
53 |
| - // const templateExamplesQuery = useQuery(templateExamples(organizationId)); |
54 |
| - // const starterTemplatesByTag = templateExamplesQuery.data |
55 |
| - // ? // Currently, the scratch template should not be displayed on the starter templates page. |
56 |
| - // getTemplatesByTag(removeScratchExample(templateExamplesQuery.data)) |
57 |
| - // : undefined; |
| 30 | + // TODO: if there is only 1 organization, set the dropdown to the default organizationId |
58 | 31 |
|
59 | 32 | return (
|
60 | 33 | <Margins>
|
61 | 34 | <PageHeader>
|
62 | 35 | <PageHeaderTitle>Create a Template</PageHeaderTitle>
|
63 | 36 | </PageHeader>
|
| 37 | + <Stack spacing={8}> |
| 38 | + <Stack direction="row" spacing={7}> |
| 39 | + <h2 css={styles.sectionTitle}>Choose an Organization</h2> |
| 40 | + <OrganizationAutocomplete |
| 41 | + css={styles.autoComplete} |
| 42 | + value={selectedOrg} |
| 43 | + onChange={(newValue) => { |
| 44 | + setSelectedOrg(newValue); |
| 45 | + }} |
| 46 | + /> |
| 47 | + </Stack> |
64 | 48 |
|
65 |
| - <OrganizationAutocomplete |
66 |
| - css={styles.autoComplete} |
67 |
| - value={selectedOrg} |
68 |
| - onChange={(newValue) => { |
69 |
| - setSelectedOrg(newValue); |
70 |
| - }} |
71 |
| - /> |
| 49 | + <Stack direction="row" spacing={7}> |
| 50 | + <h2 css={styles.sectionTitle}>Choose a starting point</h2> |
| 51 | + <div |
| 52 | + css={{ |
| 53 | + display: "flex", |
| 54 | + flexWrap: "wrap", |
| 55 | + gap: 32, |
| 56 | + height: "max-content", |
| 57 | + }} |
| 58 | + > |
| 59 | + <Card variant="outlined" sx={{ width: 320 }}> |
| 60 | + <CardActionArea |
| 61 | + component={RouterLink} |
| 62 | + to="../templates/new?exampleId=scratch" |
| 63 | + sx={{ height: 115, padding: 1 }} |
| 64 | + > |
| 65 | + <CardContent> |
| 66 | + <Stack |
| 67 | + direction="row" |
| 68 | + spacing={3} |
| 69 | + css={{ alignItems: "center" }} |
| 70 | + > |
| 71 | + <div css={styles.icon}> |
| 72 | + <ExternalImage |
| 73 | + src="/emojis/1f4c4.png" |
| 74 | + css={{ |
| 75 | + width: "100%", |
| 76 | + height: "100%", |
| 77 | + }} |
| 78 | + /> |
| 79 | + </div> |
| 80 | + <div> |
| 81 | + <h4 css={styles.cardTitle}>Scratch Template</h4> |
| 82 | + <span css={styles.cardDescription}> |
| 83 | + Create a minimal starter template that you can customize |
| 84 | + </span> |
| 85 | + </div> |
| 86 | + </Stack> |
| 87 | + </CardContent> |
| 88 | + </CardActionArea> |
| 89 | + </Card> |
| 90 | + <Card variant="outlined" sx={{ width: 320 }}> |
| 91 | + <CardActionArea |
| 92 | + component={RouterLink} |
| 93 | + to="../templates/new" |
| 94 | + sx={{ height: 115, padding: 1 }} |
| 95 | + > |
| 96 | + <CardContent> |
| 97 | + <Stack |
| 98 | + direction="row" |
| 99 | + spacing={3} |
| 100 | + css={{ alignItems: "center" }} |
| 101 | + > |
| 102 | + <div css={styles.icon}> |
| 103 | + <ExternalImage |
| 104 | + src="/emojis/1f4e1.png" |
| 105 | + css={{ |
| 106 | + width: "100%", |
| 107 | + height: "100%", |
| 108 | + }} |
| 109 | + /> |
| 110 | + </div> |
| 111 | + <div> |
| 112 | + <h4 css={styles.cardTitle}>Upload Template</h4> |
| 113 | + <span css={styles.cardDescription}> |
| 114 | + Get started by uploading an existing template |
| 115 | + </span> |
| 116 | + </div> |
| 117 | + </Stack> |
| 118 | + </CardContent> |
| 119 | + </CardActionArea> |
| 120 | + </Card> |
| 121 | + </div> |
| 122 | + </Stack> |
72 | 123 |
|
73 |
| - {Boolean(error) && <ErrorAlert error={error} />} |
| 124 | + {Boolean(error) && <ErrorAlert error={error} />} |
74 | 125 |
|
75 |
| - {Boolean(!starterTemplatesByTag) && <Loader />} |
| 126 | + {Boolean(!starterTemplatesByTag) && <Loader />} |
76 | 127 |
|
77 |
| - <StarterTemplates starterTemplatesByTag={starterTemplatesByTag} /> |
| 128 | + <StarterTemplates starterTemplatesByTag={starterTemplatesByTag} /> |
| 129 | + </Stack> |
78 | 130 | </Margins>
|
79 | 131 | );
|
80 | 132 | };
|
81 | 133 |
|
82 | 134 | const styles = {
|
83 | 135 | autoComplete: {
|
84 |
| - width: 300, |
| 136 | + width: 415, |
85 | 137 | },
|
86 | 138 |
|
87 |
| - filterCaption: (theme) => ({ |
88 |
| - textTransform: "uppercase", |
89 |
| - fontWeight: 600, |
90 |
| - fontSize: 12, |
91 |
| - color: theme.palette.text.secondary, |
92 |
| - letterSpacing: "0.1em", |
| 139 | + sectionTitle: (theme) => ({ |
| 140 | + color: theme.palette.text.primary, |
| 141 | + fontSize: 16, |
| 142 | + fontWeight: 400, |
| 143 | + margin: 0, |
93 | 144 | }),
|
94 | 145 |
|
95 |
| - tagLink: (theme) => ({ |
96 |
| - color: theme.palette.text.secondary, |
97 |
| - textDecoration: "none", |
| 146 | + cardTitle: (theme) => ({ |
98 | 147 | fontSize: 14,
|
99 |
| - textTransform: "capitalize", |
| 148 | + fontWeight: 600, |
| 149 | + margin: 0, |
| 150 | + marginBottom: 4, |
| 151 | + }), |
100 | 152 |
|
101 |
| - "&:hover": { |
102 |
| - color: theme.palette.text.primary, |
103 |
| - }, |
| 153 | + cardDescription: (theme) => ({ |
| 154 | + fontSize: 13, |
| 155 | + color: theme.palette.text.secondary, |
| 156 | + lineHeight: "1.6", |
| 157 | + display: "block", |
104 | 158 | }),
|
105 | 159 |
|
106 |
| - tagLinkActive: (theme) => ({ |
107 |
| - color: theme.palette.text.primary, |
108 |
| - fontWeight: 600, |
| 160 | + icon: { |
| 161 | + flexShrink: 0, |
| 162 | + width: 32, |
| 163 | + height: 32, |
| 164 | + }, |
| 165 | + |
| 166 | + menuItemIcon: (theme) => ({ |
| 167 | + color: theme.palette.text.secondary, |
| 168 | + width: 20, |
| 169 | + height: 20, |
109 | 170 | }),
|
110 | 171 | } satisfies Record<string, Interpolation<Theme>>;
|
0 commit comments