From cf0f0e0ba9d745bdc0d266c723cbff53737948d0 Mon Sep 17 00:00:00 2001 From: testusuke Date: Sun, 19 May 2024 21:38:21 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20Tag=E3=81=AB=E9=96=A2=E3=81=99?= =?UTF-8?q?=E3=82=8B=E5=9F=BA=E6=9C=AC=E7=9A=84=E3=81=AA=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(authenticated)/tags/[id]/page.tsx | 41 +++++++++++++ app/(authenticated)/tags/create/page.tsx | 25 ++++++++ app/(authenticated)/tags/page.tsx | 26 ++++++++ components/tags/tagCreator.tsx | 63 +++++++++++++++++++ components/tags/tagEditor.tsx | 67 ++++++++++++++++++++ components/tags/tagsAgGrid.tsx | 78 ++++++++++++++++++++++++ 6 files changed, 300 insertions(+) create mode 100644 app/(authenticated)/tags/[id]/page.tsx create mode 100644 app/(authenticated)/tags/create/page.tsx create mode 100644 app/(authenticated)/tags/page.tsx create mode 100644 components/tags/tagCreator.tsx create mode 100644 components/tags/tagEditor.tsx create mode 100644 components/tags/tagsAgGrid.tsx diff --git a/app/(authenticated)/tags/[id]/page.tsx b/app/(authenticated)/tags/[id]/page.tsx new file mode 100644 index 0000000..f5a4dd7 --- /dev/null +++ b/app/(authenticated)/tags/[id]/page.tsx @@ -0,0 +1,41 @@ +import {Alert, Breadcrumbs, Button, Link, Stack, Typography} from "@mui/material"; +import CardBackground from "@/components/layout/cardBackground"; +import {tagFactory} from "@/src/models/TagModel"; +import TagEditor from "@/components/tags/tagEditor"; + +export default async function RoleDetailPage({params}: { params: { id: string } }) { + const tagId = parseInt(params.id, 10) + const tag = await tagFactory().show(tagId) + + if (isNaN(tagId) || !tag) { + return ( + + + タグが存在しません。 + + + + + ) + } + + return ( + + + + 管理者のダッシュボード + + + タグ管理 + + {tag.name} + + + + + + + ) +} diff --git a/app/(authenticated)/tags/create/page.tsx b/app/(authenticated)/tags/create/page.tsx new file mode 100644 index 0000000..d5dcbe4 --- /dev/null +++ b/app/(authenticated)/tags/create/page.tsx @@ -0,0 +1,25 @@ +import {Stack, Breadcrumbs, Link, Typography} from "@mui/material"; +import CardBackground from "@/components/layout/cardBackground"; +import TagCreator from "@/components/tags/tagCreator"; + +export default function TagCreatePage() { + + return ( + + + + 管理者のダッシュボード + + + タグ管理 + + タグ作成 + + + + + + ); +} diff --git a/app/(authenticated)/tags/page.tsx b/app/(authenticated)/tags/page.tsx new file mode 100644 index 0000000..3793592 --- /dev/null +++ b/app/(authenticated)/tags/page.tsx @@ -0,0 +1,26 @@ +import {Stack, Breadcrumbs, Link, Typography} from "@mui/material"; +import CardBackground from "@/components/layout/cardBackground"; +import {tagFactory} from "@/src/models/TagModel"; +import TagsAgGrid from "@/components/tags/tagsAgGrid"; + +export default async function TagsPage() { + const tags = await tagFactory().index() + + return ( + + + + 管理者のダッシュボード + + タグ管理 + + + + + + ); +} diff --git a/components/tags/tagCreator.tsx b/components/tags/tagCreator.tsx new file mode 100644 index 0000000..e333eac --- /dev/null +++ b/components/tags/tagCreator.tsx @@ -0,0 +1,63 @@ +'use client' +import {Button, Stack, TextField, TextFieldProps} from "@mui/material"; +import {useRouter} from "next/navigation"; +import {useRef} from "react"; +import {tagFactory} from "@/src/models/TagModel"; + +export default function TagCreator() { + const router = useRouter() + const nameRef = useRef(null) + + const handleCreate = async () => { + // create role + const name = nameRef.current?.value as string + + if (!name) { + alert("名前を入力してください") + return + } + + await tagFactory().create({ + name: name, + enabled: true, + }) + + // redirect to role page + router.push('/tags') + } + + return ( + + + + + + + + + + ) +} diff --git a/components/tags/tagEditor.tsx b/components/tags/tagEditor.tsx new file mode 100644 index 0000000..bdb7086 --- /dev/null +++ b/components/tags/tagEditor.tsx @@ -0,0 +1,67 @@ +'use client' +import {useRef, useState} from "react"; +import { + Button, + Checkbox, + FormControlLabel, + Stack, + TextField, + TextFieldProps +} from "@mui/material"; +import {useRouter} from "next/navigation"; +import {Tag, tagFactory} from "@/src/models/TagModel"; + +export type TagEditorProps = { + tag: Tag +} + +export default function TagEditor(props: TagEditorProps) { + const router = useRouter() + const [enabled, setEnabled] = useState(props.tag.enabled) + const nameRef = useRef(null) + + const handleSubmit = async () => { + const name = nameRef.current?.value as string + + await tagFactory().update(props.tag.id, { + name: name, + enabled: enabled, + }) + + // reload + router.push("/tags") + } + + return ( + + + + { + setEnabled(e.target.checked) + }} + /> + } + label={"有効"} + /> + + + + ) +} diff --git a/components/tags/tagsAgGrid.tsx b/components/tags/tagsAgGrid.tsx new file mode 100644 index 0000000..0cd7480 --- /dev/null +++ b/components/tags/tagsAgGrid.tsx @@ -0,0 +1,78 @@ +'use client' +import {useEffect, useState} from 'react'; +import {AgGridReact} from 'ag-grid-react'; +import "ag-grid-community/styles/ag-grid.css"; // Mandatory CSS required by the grid +import "ag-grid-community/styles/ag-theme-quartz.css"; // Optional Theme applied to the grid + +import {ColDef, ModuleRegistry, RowClickedEvent} from 'ag-grid-community'; +import {ClientSideRowModelModule} from 'ag-grid-community'; +import {useRouter} from "next/navigation"; +import {Tag} from "@/src/models/TagModel"; + +ModuleRegistry.registerModules([ClientSideRowModelModule]); + +export type TagsAgGridProps = { + tags: Tag[] +} + +// Row Data Interface +type IRow = { + tagId: number, + name: string, + enabled: boolean, +} + +// Create new GridExample component +export default function TagsAgGrid(props: TagsAgGridProps) { + const height = 'calc(100vh - 230px)'; + const router = useRouter() + // Row Data: The data to be displayed. + const [rowData, setRowData] = useState([]) + // Column Definitions: Defines & controls grid columns. + const [colDefs] = useState[]>([ + {field: "tagId", headerName: "タグID"}, + {field: "name", headerName: "名前"}, + {field: "enabled", headerName: "有効"}, + ]); + + useEffect(() => { + const tags = props.tags.map((tag): IRow => { + return { + tagId: tag.id, + name: tag.name, + enabled: tag.enabled + } + }) + + // set row data + setRowData(tags) + }, [props.tags]) + + const handleRowClick = (e: RowClickedEvent) => { + const data = e.data + + // ignore undefined + if (!data) return + + // redirect + router.push(`/tags/${data.tagId}`) + } + + // Container: Defines the grid's theme & dimensions. + return ( +
+ +
+ ); +} \ No newline at end of file From 64463e69a970d5b3dce203b14b346eb7beb28492 Mon Sep 17 00:00:00 2001 From: testusuke Date: Sun, 19 May 2024 21:40:31 +0900 Subject: [PATCH 2/2] =?UTF-8?q?change:=20=E3=82=B5=E3=82=A4=E3=83=89?= =?UTF-8?q?=E3=83=90=E3=83=BC=E3=81=ABTag=E9=A0=85=E7=9B=AE=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/layout/navigation.tsx | 80 +++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 28 deletions(-) diff --git a/components/layout/navigation.tsx b/components/layout/navigation.tsx index 0b9ca9f..43e40e7 100644 --- a/components/layout/navigation.tsx +++ b/components/layout/navigation.tsx @@ -9,11 +9,11 @@ import { HiUser, HiUserGroup, HiTrophy, - HiMapPin, HiIdentification + HiMapPin, HiIdentification, HiMiniTag } from "react-icons/hi2"; import {SiGithub} from "react-icons/si"; import WiderLogo from "@/components/svg/wider"; -import Link from "next/link" +import Link from "next/link" import NavPrivacyPolicyDrawer from "@/components/layout/navPrivacyPolicyDrawer"; import LogoutButton from "@/components/auth/LogoutButton"; @@ -27,9 +27,9 @@ export const Navigation = () => { position="fixed" sx={{ zIndex: (theme) => theme.zIndex.drawer + 1, - background:"rgba(62,78,179,0.8)", + background: "rgba(62,78,179,0.8)", backdropFilter: 'blur(30px)', - }}> + }}> {"SPORTSDAY @@ -42,26 +42,27 @@ export const Navigation = () => { sx: { backgroundColor: "#7F8CD6", color: "#fff", - pt:8 + pt: 8 } }} sx={{ width: drawerWidth, flexShrink: 0, - [`& .MuiDrawer-paper`]: { width: drawerWidth, boxSizing: 'border-box' }, + [`& .MuiDrawer-paper`]: {width: drawerWidth, boxSizing: 'border-box'}, }} > - + - 全体 + 全体 + - + @@ -180,7 +203,8 @@ export const Navigation = () => { - + (C)2024