Skip to content

Commit

Permalink
Change: 編集画面へのリンクを表示した
Browse files Browse the repository at this point in the history
  • Loading branch information
itizawa committed Dec 1, 2024
1 parent c1fdacc commit e180309
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
13 changes: 11 additions & 2 deletions apps/web/src/app/dashboards/blogs/[blogId]/articles/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Stack, Typography } from '@mui/material';
import { Settings } from '@mui/icons-material';
import { Box, IconButton, Link, Stack, Typography } from '@mui/material';
import type { Blog } from '@repo/types';
import { notFound } from 'next/navigation';
import { Suspense } from 'react';
Expand All @@ -10,6 +11,7 @@ import { ArticleSummaryPaperForAdmin } from '~/components/models/article/Article
import { CreateNewArticleButton } from '~/components/models/article/CreateNewArticleButton';
import { LoadingBox } from '~/components/uiParts/LoadingBox';
import { WisblogTabs } from '~/components/uiParts/WisblogTabs';
import { appUrls } from '~/constants/appUrls';
import { generateWisblogMetadata } from '~/libs/generateWisblogMetadata';

export const metadata = generateWisblogMetadata({ title: '記事一覧' });
Expand All @@ -24,7 +26,14 @@ export default async function Page({ params }: { params: { blogId: string } }) {

return (
<Stack maxWidth={900} mx='auto' pt={2} pb={4} gap={3} px={2}>
<Typography variant='h4'>{blog.name}</Typography>
<Box display='flex' justifyContent='space-between'>
<Typography variant='h4'>{blog.name}</Typography>
<Link href={appUrls.dashboard.blogs.edit(blog.id)}>
<IconButton>
<Settings />
</IconButton>
</Link>
</Box>
<Stack direction='row' justifyContent='space-between' columnGap={2}>
<Typography variant='h5'>記事一覧</Typography>
<CreateNewArticleButton blogId={blog.id} />
Expand Down
17 changes: 17 additions & 0 deletions apps/web/src/app/dashboards/blogs/[blogId]/edit/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Stack, Typography } from '@mui/material';
import { notFound } from 'next/navigation';
import { getBlog } from '~/actions/blog';
import { EditBlogForm } from '~/components/models/blog/EditBlogForm';

export default async function Page({ params }: { params: { blogId: string } }) {
const blog = await getBlog({ id: params.blogId });

if (!blog) return notFound();

return (
<Stack maxWidth={600} mx='auto' pt={4} gap={3} px={2}>
<Typography variant='h5'>編集</Typography>
<EditBlogForm existingBlog={blog} />
</Stack>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useSnackbar } from 'notistack';
import type { FC } from 'react';
import { Controller, useForm } from 'react-hook-form';
import type { z } from 'zod';
import { createBlog } from '~/actions/blog';
import { createBlog, updateBlog } from '~/actions/blog';
import { generateSubDomainUrl } from '~/utils/generateSubDomainUrl';

const inputSchema = BlogSchema.pick({ name: true, subDomain: true });
Expand Down Expand Up @@ -40,11 +40,11 @@ export const EditBlogForm: FC<Props> = ({ existingBlog }) => {
const onSubmit = handleSubmit(async ({ name, subDomain }) => {
try {
if (existingBlog) {
// await updateBlog({
// id: existingBlog.id,
// name,
// subDomain,
// });
await updateBlog({
id: existingBlog.id,
name,
subDomain,
});
enqueueSnackbar({ message: 'ブログを更新しました', variant: 'success' });
} else {
await createBlog({
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/constants/appUrls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export const appUrls = {
blogs: {
new: () => '/dashboards/blogs/new' as const,
list: () => '/blogs' as const,
edit: (blogId: string) => `/dashboards/blogs/${blogId}/edit` as const,
articles: {
list: (blogId: string) => `/dashboards/blogs/${blogId}/articles` as const,
new: (blogId: string) => `/dashboards/blogs/${blogId}/articles/new` as const,
Expand Down

0 comments on commit e180309

Please sign in to comment.