From 9a265c98870d0cf9f9b9b37061fcabd8a02b06b2 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 11 Jan 2025 00:02:16 +0800 Subject: [PATCH] :sparkles: Create & edit release --- packages/sn/package.json | 2 +- packages/sn/src/index.ts | 1 + src/components/matrix/MaReleaseForm.tsx | 25 +++++++++--- .../console/matrix/products/[id]/index.tsx | 38 ++++++++++++++++-- .../products/[id]/releases/[release]/edit.tsx | 40 +++++++++++++++++++ 5 files changed, 97 insertions(+), 9 deletions(-) create mode 100644 src/pages/console/matrix/products/[id]/releases/[release]/edit.tsx diff --git a/packages/sn/package.json b/packages/sn/package.json index 694919b..75e2c33 100644 --- a/packages/sn/package.json +++ b/packages/sn/package.json @@ -7,7 +7,7 @@ "name": "LittleSheep", "email": "littlesheep.code@hotmail.com" }, - "version": "0.0.3", + "version": "0.0.5", "tsup": { "entry": [ "src/index.ts" diff --git a/packages/sn/src/index.ts b/packages/sn/src/index.ts index 9d24474..9729448 100644 --- a/packages/sn/src/index.ts +++ b/packages/sn/src/index.ts @@ -1,4 +1,5 @@ export * from './matrix/product' +export * from './matrix/release' export * from './attachment' export * from './auth' export * from './checkIn' diff --git a/src/components/matrix/MaReleaseForm.tsx b/src/components/matrix/MaReleaseForm.tsx index 7d5b4cb..37d65b5 100644 --- a/src/components/matrix/MaReleaseForm.tsx +++ b/src/components/matrix/MaReleaseForm.tsx @@ -13,12 +13,13 @@ import { IconButton, } from '@mui/material' import { useRouter } from 'next-nprogress-bar' -import { useState } from 'react' +import { useEffect, useState } from 'react' import { useForm } from 'react-hook-form' import ErrorIcon from '@mui/icons-material/Error' import CloseIcon from '@mui/icons-material/Close' import { MaProduct } from 'solar-js-sdk' +import { version } from 'node:os' export interface MatrixReleaseForm { version: string @@ -39,13 +40,27 @@ export default function MaReleaseForm({ }: { onSubmit: (data: MatrixReleaseForm) => Promise onSuccess?: () => void - parent: MaProduct - defaultValue?: unknown + parent: Partial + defaultValue?: any }) { const { handleSubmit, register } = useForm({ - defaultValues: {}, + defaultValues: { + title: defaultValue?.meta.title, + version: defaultValue?.version, + type: defaultValue?.type ?? 0, + channel: defaultValue?.channel, + description: defaultValue?.meta.description, + content: defaultValue?.meta.content, + attachments: defaultValue?.meta.attachments, + }, }) + useEffect(() => { + if (defaultValue) { + setAssets(Object.keys(defaultValue.assets).map((k) => ({ k, v: defaultValue.assets[k] }))) + } + }, []) + const router = useRouter() const [assets, setAssets] = useState<{ k: string; v: string }[]>([]) @@ -61,7 +76,7 @@ export default function MaReleaseForm({ if (onSuccess) { onSuccess() } else { - router.push(`/console/matrix/products/${parent.id}`) + router.push(`/console/matrix/products/${parent?.id}`) } } diff --git a/src/pages/console/matrix/products/[id]/index.tsx b/src/pages/console/matrix/products/[id]/index.tsx index d2a0844..2f9a566 100644 --- a/src/pages/console/matrix/products/[id]/index.tsx +++ b/src/pages/console/matrix/products/[id]/index.tsx @@ -1,5 +1,5 @@ import { ConsoleLayout, getConsoleStaticProps } from '@/components/layouts/ConsoleLayout' -import { Box, Button, Container, Typography } from '@mui/material' +import { Box, Button, Container, Typography, Grid2 as Grid, Card, CardContent, CardActions } from '@mui/material' import { GetServerSideProps, InferGetServerSidePropsType } from 'next' import { sni, MaProduct } from 'solar-js-sdk' import NextLink from 'next/link' @@ -9,15 +9,22 @@ export const getServerSideProps: GetServerSideProps = (async (context) => { const { data } = await sni.get('/cgi/ma/products/' + id) + const { data: resp } = await sni.get<{ data: any[] }>('/cgi/ma/products/' + id + '/releases', { + params: { + take: 10, + }, + }) + return getConsoleStaticProps({ props: { title: `Product "${data.name}"`, product: data, + releases: resp.data, }, }) -}) satisfies GetServerSideProps<{ product: MaProduct }> +}) satisfies GetServerSideProps<{ product: MaProduct; releases: any[] }> -export default function ProductDetails({ product }: InferGetServerSidePropsType) { +export default function ProductDetails({ product, releases }: InferGetServerSidePropsType) { return ( @@ -36,6 +43,31 @@ export default function ProductDetails({ product }: InferGetServerSidePropsType< + + + {releases.map((r: any) => ( + + + + {r.version} + + {r.meta.title} + + + {r.type == 0 ? 'Full Release' : 'Patch Release'} + + + {r.meta.description} + + + + + + + + + ))} + diff --git a/src/pages/console/matrix/products/[id]/releases/[release]/edit.tsx b/src/pages/console/matrix/products/[id]/releases/[release]/edit.tsx new file mode 100644 index 0000000..4e7bd98 --- /dev/null +++ b/src/pages/console/matrix/products/[id]/releases/[release]/edit.tsx @@ -0,0 +1,40 @@ +import { ConsoleLayout, getConsoleStaticProps } from '@/components/layouts/ConsoleLayout' +import { Typography, Container, Box } from '@mui/material' +import { sni } from 'solar-js-sdk' +import { GetServerSideProps, InferGetServerSidePropsType } from 'next' +import MaReleaseForm, { MatrixReleaseForm } from '@/components/matrix/MaReleaseForm' + +export const getServerSideProps: GetServerSideProps = (async (context) => { + const id = context.params!.id + const releaseId = context.params!.release + + const { data } = await sni.get('/cgi/ma/products/' + id + '/releases/' + releaseId) + + return getConsoleStaticProps({ + props: { + title: `Edit Release "${data.name}"`, + release: data, + }, + }) +}) satisfies GetServerSideProps<{ release: any }> + +export default function ProductEdit({ release }: InferGetServerSidePropsType) { + async function onSubmit(data: MatrixReleaseForm) { + await sni.put('/cgi/ma/products/' + release.id + '/releases/' + release.productId, data) + } + + return ( + + + + + Edit releases + + {release.meta.title} + + + + + + ) +}