Skip to content

Commit f73db44

Browse files
committed
feat: extract subcomponents.
1 parent 85e9c8d commit f73db44

File tree

2 files changed

+76
-73
lines changed

2 files changed

+76
-73
lines changed

src/app/account/AccountForm.tsx

Lines changed: 6 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"use client";
22

3+
import React, { useState } from "react";
34
import { LoadingOverlay } from "@/components/LoadingOverlay";
45
import { MessageDialog } from "@/components/MessageDialog";
56
import { Box, Button, TextField, Typography, useMediaQuery, useTheme } from "@mui/material";
6-
import React, { useState } from "react";
7+
import { InputSection, GridSection, SectionTitle, FieldTitle, FieldDescription } from "./sections";
78
import AccountBoxIcon from "@mui/icons-material/AccountBox";
89
import LinkIcon from "@mui/icons-material/Link";
910
import MailOutlineIcon from "@mui/icons-material/MailOutline";
@@ -12,75 +13,6 @@ import LocationOnIcon from "@mui/icons-material/LocationOn";
1213
import TocIcon from "@mui/icons-material/Toc";
1314
import LanguageIcon from "@mui/icons-material/Language";
1415

15-
const InputSection = ({ children }: { children: React.ReactNode[] }) => (
16-
<Box
17-
sx={{
18-
display: "flex",
19-
flexDirection: "column",
20-
gap: 2,
21-
height: "100%",
22-
}}
23-
>
24-
{children}
25-
</Box>
26-
);
27-
28-
const GridSection = ({
29-
children,
30-
isDesktop,
31-
}: {
32-
children: React.ReactNode;
33-
isDesktop: boolean;
34-
}) => (
35-
<Box
36-
sx={{
37-
display: "grid",
38-
gridTemplateColumns: isDesktop ? "1fr 1fr" : "1fr",
39-
gap: isDesktop ? 4 : 2,
40-
mt: 4,
41-
}}
42-
>
43-
{children}
44-
</Box>
45-
);
46-
47-
const SectionTitle = ({ children }: { children: React.ReactNode }) => (
48-
<Typography
49-
variant="h5"
50-
component="h2"
51-
color="textPrimary"
52-
sx={{
53-
gridColumn: "1 / -1",
54-
borderTop: "1px solid",
55-
paddingTop: 2,
56-
marginTop: 2,
57-
}}
58-
>
59-
{children}
60-
</Typography>
61-
);
62-
63-
const FieldTitle = ({ children }: { children: React.ReactNode }) => (
64-
<Typography
65-
variant="h6"
66-
component="p"
67-
color="textPrimary"
68-
sx={{
69-
display: "flex",
70-
alignItems: "center",
71-
gap: "0.5em",
72-
}}
73-
>
74-
{children}
75-
</Typography>
76-
);
77-
78-
const FieldDescription = ({ children }: { children: React.ReactNode }) => (
79-
<Typography variant="body2" color="textSecondary">
80-
{children}
81-
</Typography>
82-
);
83-
8416
const AccountForm = ({
8517
name,
8618
slug,
@@ -107,13 +39,14 @@ const AccountForm = ({
10739
siteTitle,
10840
siteDescription,
10941
});
110-
const theme = useTheme();
111-
const isDesktop = useMediaQuery(theme.breakpoints.up("md"));
112-
11342
const [errors, setErrors] = useState<{ name?: string; slug?: string; displayEmail?: string }>({});
11443
const [loading, setLoading] = useState(false);
11544
const [message, setMessage] = useState("");
11645

46+
// Used for styling.
47+
const theme = useTheme();
48+
const isDesktop = useMediaQuery(theme.breakpoints.up("md"));
49+
11750
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
11851
const { name, value } = e.target;
11952

src/app/account/sections.tsx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { Box, Typography } from "@mui/material";
2+
3+
export const InputSection = ({ children }: { children: React.ReactNode[] }) => (
4+
<Box
5+
sx={{
6+
display: "flex",
7+
flexDirection: "column",
8+
gap: 2,
9+
height: "100%",
10+
}}
11+
>
12+
{children}
13+
</Box>
14+
);
15+
16+
export const GridSection = ({
17+
children,
18+
isDesktop,
19+
}: {
20+
children: React.ReactNode;
21+
isDesktop: boolean;
22+
}) => (
23+
<Box
24+
sx={{
25+
display: "grid",
26+
gridTemplateColumns: isDesktop ? "1fr 1fr" : "1fr",
27+
gap: isDesktop ? 4 : 2,
28+
mt: 4,
29+
}}
30+
>
31+
{children}
32+
</Box>
33+
);
34+
35+
export const SectionTitle = ({ children }: { children: React.ReactNode }) => (
36+
<Typography
37+
variant="h5"
38+
component="h2"
39+
color="textPrimary"
40+
sx={{
41+
gridColumn: "1 / -1",
42+
borderTop: "1px solid",
43+
paddingTop: 2,
44+
marginTop: 2,
45+
}}
46+
>
47+
{children}
48+
</Typography>
49+
);
50+
51+
export const FieldTitle = ({ children }: { children: React.ReactNode }) => (
52+
<Typography
53+
variant="h6"
54+
component="p"
55+
color="textPrimary"
56+
sx={{
57+
display: "flex",
58+
alignItems: "center",
59+
gap: "0.5em",
60+
}}
61+
>
62+
{children}
63+
</Typography>
64+
);
65+
66+
export const FieldDescription = ({ children }: { children: React.ReactNode }) => (
67+
<Typography variant="body2" color="textSecondary">
68+
{children}
69+
</Typography>
70+
);

0 commit comments

Comments
 (0)