Skip to content

Commit

Permalink
refactor: adminページの一部レイアウトを修正
Browse files Browse the repository at this point in the history
  • Loading branch information
rito528 committed Apr 14, 2024
1 parent dff5be9 commit abc49e3
Show file tree
Hide file tree
Showing 15 changed files with 346 additions and 154 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@
"@azure/msal-browser": "^3.2.0",
"@azure/msal-node": "^2.6.4",
"@azure/msal-react": "^2.0.3",
"@emotion/cache": "^11.11.0",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@hookform/resolvers": "^3.3.4",
"@material-ui/core": "^4.12.4",
"@mui/icons-material": "^5.14.3",
"@mui/material": "^5.14.4",
"@mui/material-nextjs": "^5.15.11",
"@mui/x-data-grid": "^6.12.1",
"browserslist": "^4.23.0",
"dayjs": "^1.11.9",
Expand Down
27 changes: 20 additions & 7 deletions src/app/(authed)/admin/_components/AdminNavigationBar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';

import SearchIcon from '@mui/icons-material/Search';
import {
Typography,
Box,
Expand All @@ -10,16 +11,21 @@ import {
IconButton,
InputBase,
} from '@mui/material';
import SearchIcon from '@mui/icons-material/Search';
import Image from 'next/image';

const SearchField = () => {
return (
<Paper
component="form"
sx={{ p: '2px 4px', display: 'flex', alignItems: 'center', width: 400 }}
sx={{
p: '2px 4px',
display: 'flex',
alignItems: 'center',
width: 400,
background: 'rgba(255, 255, 255, 0.15)',
}}
>
<IconButton sx={{ p: '10px' }} aria-label="search">
<IconButton sx={{ p: '10px', color: '#FFFFFF' }} aria-label="search">
<SearchIcon />
</IconButton>
<InputBase
Expand All @@ -36,16 +42,23 @@ const NavBar = () => {
<Box sx={{ flexGrow: 1 }}>
<AppBar
position="fixed"
sx={{ zIndex: (theme) => theme.zIndex.drawer + 1 }}
sx={{
zIndex: (theme) => theme.zIndex.drawer + 1,
backgroundColor: (theme) => theme.palette.secondary.main,
}}
>
<Toolbar>
<Image
src="/favicon.ico"
width={32}
height={32}
width={48}
height={48}
alt={'seichi-portal logo'}
/>
<Typography variant="h6" component="div" sx={{ flexGrow: 1 }}>
<Typography
variant="h6"
component="div"
sx={{ flexGrow: 1, paddingLeft: '10px' }}
>
<Link href="/admin" color="#fff" sx={{ textDecoration: 'none' }}>
Seichi Portal Admin
</Link>
Expand Down
52 changes: 31 additions & 21 deletions src/app/(authed)/admin/_components/DashboardMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,57 @@

import { Star } from '@mui/icons-material';
import {
styled,
Typography,
MenuList,
MenuItem,
ListItemIcon,
Divider,
} from '@mui/material';
import Drawer from '@mui/material/Drawer';

const Demo = styled('div')(({ theme }) => ({
backgroundColor: theme.palette.background.paper,
color: theme.palette.text.primary,
}));

const drawerWidth = 240;

const DashboardMenu = () => {
return (
<Drawer
variant="permanent"
PaperProps={{
sx: {
background:
'linear-gradient(180deg, rgba(0, 31, 56, 0.15) 0%, rgba(255, 255, 255, 0.15) 100%), #001F38',
boxShadow:
'0px 8px 10px -5px rgba(0, 0, 0, 0.2), 0px 16px 24px 2px rgba(0, 0, 0, 0.14), 0px 6px 30px 5px rgba(0, 0, 0, 0.12)',
},
}}
sx={{
width: drawerWidth,
[`& .MuiDrawer-paper`]: { width: drawerWidth, boxSizing: 'border-box' },
[`& .MuiDrawer-paper`]: {
width: drawerWidth,
boxSizing: 'border-box',
},
}}
>
<Typography sx={{ mt: 4, mb: 2 }} variant="h6" component="div">
Menu
</Typography>
<Demo>
<MenuList>
{['Dashboard', 'Forms', 'Announcements'].map((value) => {
return (
<MenuItem key={value}>
<ListItemIcon>
<Star />
</ListItemIcon>
{value}
</MenuItem>
);
})}
</MenuList>
</Demo>
<MenuList>
{['Dashboard', 'Forms', 'Announcements'].map((value) => {
return (
<MenuItem key={value}>
<ListItemIcon
sx={{
color: 'rgba(255, 255, 255, 0.56)',
paddingRight: '32px',
}}
>
<Star />
</ListItemIcon>
{value}
</MenuItem>
);
})}
</MenuList>
<Divider />
</Drawer>
);
};
Expand Down
36 changes: 36 additions & 0 deletions src/app/(authed)/admin/forms/create/CreateForm2.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { zodResolver } from '@hookform/resolvers/zod';
import { Container, Stack, TextField, Typography } from '@mui/material';
import { useForm } from 'react-hook-form';
import { formSchema } from '@/_schemas/formSchema';
import type { Form} from '@/_schemas/formSchema';

export const CreateFormComponent = () => {
const {
control,
handleSubmit,
register,
formState: { errors },
} = useForm<Form>({
mode: 'onSubmit',
reValidateMode: 'onBlur',
resolver: zodResolver(formSchema),
});

const onSubmit = (data: Form) => {
// todo: データの送信処理を書く
};

return (
<Container component="form" onSubmit={handleSubmit(onSubmit)}>
<Stack spacing={2}>
<Typography variant="body1">フォームタイトル</Typography>
<TextField {...register('title')} required />
<TextField
{...register('description')}
label="フォーム説明"
variant="outlined"
/>
</Stack>
</Container>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { FieldValues, UseControllerProps } from 'react-hook-form';

export type RHFProps<T extends FieldValues = FieldValues> = Pick<
UseControllerProps<T>,
'name' | 'control'
> & {
label: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { Stack, TextField, Typography } from '@mui/material';
import { useController } from 'react-hook-form';
import type { RHFProps } from './RHFProps';
import type { FieldValues} from 'react-hook-form';

export const RHFTextField = <T extends FieldValues>({
name,
control,
label,
}: RHFProps<T>) => {
const {
field,
formState: { errors },
} = useController({ name, control });

const errorMessage = errors?.[name]?.message as string;

return (
<Stack direction="row" alignItems="center" m={2}>
<Typography>{label}</Typography>
<TextField
value={field.value ?? ''}
inputRef={field.ref}
name={field.name}
onChange={field.onChange}
onBlur={field.onBlur}
/>
{errorMessage && (
<Typography ml={3} color="red">
{errorMessage}
</Typography>
)}
</Stack>
);
};
10 changes: 7 additions & 3 deletions src/app/(authed)/admin/forms/create/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
'use client';

import { CreateFormComponent } from '@/features/form/components/CreateForm';
import { CssBaseline, ThemeProvider } from '@mui/material';
import { CreateFormComponent } from './CreateForm2';
import adminDashboardTheme from '../../theme/adminDashboardTheme';

const Home = () => {
return (
<>
<ThemeProvider theme={adminDashboardTheme}>
<CssBaseline />
<CreateFormComponent />
</>
</ThemeProvider>
);
};

Expand Down
81 changes: 73 additions & 8 deletions src/app/(authed)/admin/forms/page.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
'use client';

import { Add } from '@mui/icons-material';
import {
Autocomplete,
Box,
Button,
Chip,
Grid,
Stack,
TextField,
} from '@mui/material';
import { redirect } from 'next/navigation';
import useSWR from 'swr';
import {
CreateFormButton,
Forms,
} from '@/features/form/components/DashboardFormList';
import { Forms } from '@/features/form/components/DashboardFormList';
import type { MinimumForm } from '@/_schemas/formSchema';

const Home = () => {
Expand All @@ -22,10 +29,68 @@ const Home = () => {
}

return (
<>
<CreateFormButton />
<Forms forms={forms} />
</>
<Stack spacing={2}>
<Grid container sx={{ justifyContent: 'space-between' }}>
<Grid item>
<Autocomplete
multiple
id="filter-forms"
options={['Open', 'Closed']}
getOptionLabel={(option) => option}
defaultValue={['Open']}
renderTags={(value: readonly string[], getTagProps) =>
value.map((option: string, index: number) => (
<Chip
label={option}
sx={{ background: '#FFFFFF29' }}
{...getTagProps({ index })}
key={index}
/>
))
}
renderOption={(props, option) => {
return (
<Box component="span" {...props} style={{ color: 'black' }}>
{option}
</Box>
);
}}
renderInput={(params) => (
// @ts-expect-error (解決方法がよくわからないのでとりあえずignoreする)
// FIXME: あとで調べる
<TextField
{...params}
variant="standard"
label="Filter"
sx={{ borderBottom: '1px solid #FFFFFF6B' }}
InputLabelProps={{ style: { color: '#FFFFFF80' } }}
/>
)}
/>
</Grid>
<Grid item>
<Button
variant="contained"
startIcon={<Add />}
href="/admin/forms/create"
sx={{
width: '97px',
height: '36px',
boxShadow:
'0px 3px 5px -1px rgba(0, 0, 0, 0.2), 0px 6px 10px rgba(0, 0, 0, 0.14), 0px 1px 18px rgba(0, 0, 0, 0.12)',
borderRadius: '64px',
}}
>
NEW
</Button>
</Grid>
</Grid>
<Grid container spacing={2}>
<Grid item>
<Forms forms={forms} />
</Grid>
</Grid>
</Stack>
);
};

Expand Down
Loading

0 comments on commit abc49e3

Please sign in to comment.