diff --git a/src/components/CapDrawer.tsx b/src/components/CapDrawer.tsx index acd00a2..d24fafe 100644 --- a/src/components/CapDrawer.tsx +++ b/src/components/CapDrawer.tsx @@ -52,6 +52,10 @@ export function CapDrawer({ width, open, onClose }: { width: number; open: boole title: 'Terms & Conditions', href: '/terms', }, + { + title: 'SN Console', + href: '/console', + }, ] return ( @@ -93,7 +97,7 @@ export function CapDrawer({ width, open, onClose }: { width: number; open: boole ))} - + {additionalLinks.map((l) => ( diff --git a/src/components/layouts/ConsoleLayout.tsx b/src/components/layouts/ConsoleLayout.tsx index e504e1f..80ffa46 100644 --- a/src/components/layouts/ConsoleLayout.tsx +++ b/src/components/layouts/ConsoleLayout.tsx @@ -1,9 +1,10 @@ import { checkAuthenticatedClient, redirectToLogin } from '@/services/auth' import { JSX, useEffect } from 'react' import { DashboardLayout, Navigation } from '@toolpad/core' -import { Stack, Typography } from '@mui/material' +import { Box, Stack, Typography } from '@mui/material' import NextLink from 'next/link' +import HomeIcon from '@mui/icons-material/Home' import AppsIcon from '@mui/icons-material/Apps' export function ConsoleLayout({ children }: { children: JSX.Element }) { @@ -12,6 +13,11 @@ export function ConsoleLayout({ children }: { children: JSX.Element }) { }, []) const navigation: Navigation = [ + { + segment: '', + title: 'Home', + icon: , + }, { segment: 'console/matrix', title: 'Matrix', @@ -35,6 +41,9 @@ export function ConsoleLayout({ children }: { children: JSX.Element }) { ) }, + toolbarActions(_) { + return + }, }} sidebarExpandedWidth={300} defaultSidebarCollapsed diff --git a/src/pages/console/index.tsx b/src/pages/console/index.tsx index 06ebfbf..1ef9c78 100644 --- a/src/pages/console/index.tsx +++ b/src/pages/console/index.tsx @@ -30,7 +30,7 @@ export default function ConsoleLanding() { - {}}> + diff --git a/src/pages/console/matrix/index.tsx b/src/pages/console/matrix/index.tsx index 7a0aa48..4a37dcf 100644 --- a/src/pages/console/matrix/index.tsx +++ b/src/pages/console/matrix/index.tsx @@ -1,5 +1,9 @@ import { ConsoleLayout, getConsoleStaticProps } from '@/components/layouts/ConsoleLayout' -import { Typography, Container } from '@mui/material' +import { MaProduct } from '@/services/matrix/product' +import { sni } from '@/services/network' +import { Typography, Container, Box, Button, Grid2 as Grid, Card, CardActionArea, CardContent } from '@mui/material' +import NextLink from 'next/link' +import { useEffect, useState } from 'react' export async function getStaticProps() { return getConsoleStaticProps({ @@ -10,12 +14,52 @@ export async function getStaticProps() { } export default function MatrixMarketplace() { + const [products, setProducts] = useState([]) + + async function fetchProducts() { + const { data: resp } = await sni.get<{ data: MaProduct[] }>('/cgi/ma/products/created', { + params: { + take: 10, + }, + }) + setProducts(resp.data) + } + + useEffect(() => { + fetchProducts() + }, []) + return ( - + Matrix Marketplace + + + {products.map((p) => ( + + + + + + + {p.name} + + {p.description} + + + + + + ))} + + + + + + + ) diff --git a/src/pages/console/matrix/products/new.tsx b/src/pages/console/matrix/products/new.tsx new file mode 100644 index 0000000..5376c62 --- /dev/null +++ b/src/pages/console/matrix/products/new.tsx @@ -0,0 +1,82 @@ +import { ConsoleLayout, getConsoleStaticProps } from '@/components/layouts/ConsoleLayout' +import { Typography, Container, Box, Button, TextField, Collapse, Alert } from '@mui/material' +import { useForm } from 'react-hook-form' +import { useState } from 'react' +import { useRouter } from 'next/router' +import NextLink from 'next/link' +import { sni } from '@/services/network' + +import ErrorIcon from '@mui/icons-material/Error' + +export async function getStaticProps() { + return getConsoleStaticProps({ + props: { + title: 'Matrix', + }, + }) +} + +interface MatrixProductNewForm { + name: string + alias: string + description: string + introduction: string +} + +export default function ProductNew() { + const { handleSubmit, register } = useForm() + + const router = useRouter() + + const [error, setError] = useState(null) + const [busy, setBusy] = useState(false) + + async function onSubmit(data: any) { + try { + setBusy(true) + await sni.post('/cgi/ma/products', data) + router.push('/console/matrix') + } catch (err: any) { + setError(err.toString()) + } finally { + setBusy(false) + } + } + + return ( + + + + Create a product + + +
+ + + } severity="error"> + {error} + + + + + + + + + + + + + + + + + + +
+
+
+ ) +} diff --git a/src/services/matrix/product.ts b/src/services/matrix/product.ts new file mode 100644 index 0000000..a59e677 --- /dev/null +++ b/src/services/matrix/product.ts @@ -0,0 +1,25 @@ +export interface MaProduct { + id: number + created_at: Date + updated_at: Date + deleted_at?: Date + icon: string + name: string + alias: string + description: string + previews: string[] + tags: string[] + meta: MaProductMeta + releases: null + account_id: number +} + +export interface MaProductMeta { + id: number + created_at: Date + updated_at: Date + deleted_at?: Date + introduction: string + attachments: string[] + product_id: number +}