diff --git a/apps/app/src/components/Changelog/Version/Create/Step01.tsx b/apps/app/src/components/Changelog/Version/Create/Step01.tsx index c6d30fc..ebf11c9 100644 --- a/apps/app/src/components/Changelog/Version/Create/Step01.tsx +++ b/apps/app/src/components/Changelog/Version/Create/Step01.tsx @@ -1,17 +1,21 @@ import { Link, useParams } from '@tanstack/react-router' import { HandIcon, WorkflowIcon } from 'lucide-react' -export const ChangelogVersionCreateStep01 = () => { +export const ChangelogVersionCreateStep01 = ({ + nextStep, +}: { nextStep: () => void }) => { const { id } = useParams({ from: '/changelog/$id' }) + return (
-
+
+ { + const { id } = useParams({ from: '/changelog/$id' }) + const navigate = useNavigate({ from: `/changelog/${id}` }) + const autoVersion = useChangelogVersionCreateAuto() + + const form = useForm>({ + resolver: zodResolver(VersionCreateAutoInput), + defaultValues: { + changelogId: id, + version: null, + }, + }) + + const onSubmit = (values: z.infer) => { + autoVersion.mutate(values, { + onSuccess(data) { + navigate({ + to: '/changelog/$id/version/$versionId', + params: { id, versionId: data.id }, + }) + }, + }) + } + + return ( +
+
+ + ( + + Version + + + {' '} + + Leave blank for auto generating. + + + + )} + /> + +
+ +
+ + +
+ ) +} diff --git a/apps/app/src/components/Changelog/Version/Create/index.tsx b/apps/app/src/components/Changelog/Version/Create/index.tsx index 466de35..f78cbc5 100644 --- a/apps/app/src/components/Changelog/Version/Create/index.tsx +++ b/apps/app/src/components/Changelog/Version/Create/index.tsx @@ -7,11 +7,23 @@ import { DialogTrigger, } from '@boring.tools/ui' import { PlusCircleIcon } from 'lucide-react' +import { useEffect, useState } from 'react' import { ChangelogVersionCreateStep01 } from './Step01' +import { ChangelogVersionCreateStep02 } from './Step02' export const ChangelogVersionCreate = () => { + const [isOpen, setIsOpen] = useState(false) + const [step, setStep] = useState(1) + const nextStep = () => setStep((prev) => prev + 1) + + useEffect(() => { + if (!isOpen) { + setStep(1) + } + }, [isOpen]) + return ( - + setIsOpen(state)}> @@ -25,7 +37,8 @@ export const ChangelogVersionCreate = () => { - + {step === 1 && } + {step === 2 && } ) diff --git a/apps/app/src/hooks/useChangelog.ts b/apps/app/src/hooks/useChangelog.ts index 86757c4..a28660d 100644 --- a/apps/app/src/hooks/useChangelog.ts +++ b/apps/app/src/hooks/useChangelog.ts @@ -3,6 +3,7 @@ import type { ChangelogOutput, ChangelogUpdateInput, CommitOutput, + VersionCreateAutoInput, VersionCreateInput, VersionOutput, VersionUpdateInput, @@ -18,6 +19,7 @@ type ChangelogUpdate = z.infer type Version = z.infer type VersionCreate = z.infer +type VersionCreateAuto = z.infer type VersionUpdate = z.infer type Commit = z.infer @@ -155,6 +157,29 @@ export const useChangelogVersionCreate = () => { }) } +export const useChangelogVersionCreateAuto = () => { + const { getToken } = useAuth() + const queryClient = useQueryClient() + + return useMutation({ + mutationFn: async ( + payload: VersionCreateAuto, + ): Promise> => + await queryFetch({ + path: 'changelog/version/auto', + data: payload, + method: 'post', + token: await getToken(), + }), + onSuccess: (data) => { + queryClient.invalidateQueries({ queryKey: ['changelogList'] }) + queryClient.invalidateQueries({ + queryKey: ['changelogById', data.changelogId], + }) + }, + }) +} + export const useChangelogVersionById = ({ id }: { id: string }) => { const { getToken } = useAuth() diff --git a/apps/app/src/routes/changelog.$id.version.$versionId.tsx b/apps/app/src/routes/changelog.$id.version.$versionId.tsx index 2cc605c..2e3ab74 100644 --- a/apps/app/src/routes/changelog.$id.version.$versionId.tsx +++ b/apps/app/src/routes/changelog.$id.version.$versionId.tsx @@ -43,7 +43,7 @@ import { import '@mdxeditor/editor/style.css' import { format } from 'date-fns' import { CalendarIcon } from 'lucide-react' -import { useEffect, useRef } from 'react' +import { useEffect, useRef, useState } from 'react' import { ChangelogVersionDelete } from '../components/Changelog/VersionDelete' import { VersionStatus } from '../components/Changelog/VersionStatus' @@ -55,6 +55,7 @@ const Component = () => { const { data, error, isPending, refetch } = useChangelogVersionById({ id: versionId, }) + const [editorValue, setEditorValue] = useState('') const form = useForm>({ resolver: zodResolver(VersionUpdateInput), defaultValues: data, @@ -74,9 +75,8 @@ const Component = () => { useEffect(() => { if (data) { mdxEditorRef.current?.setMarkdown(data.markdown) - form.reset(data) } - }, [data, form.reset]) + }, [data]) if (error) { return ( diff --git a/apps/app/src/routes/changelog.create.lazy.tsx b/apps/app/src/routes/changelog.create.lazy.tsx index bb4c93c..1a28d84 100644 --- a/apps/app/src/routes/changelog.create.lazy.tsx +++ b/apps/app/src/routes/changelog.create.lazy.tsx @@ -29,6 +29,7 @@ const Component = () => { title: '', description: '', isSemver: true, + isConventional: true, }, }) @@ -115,6 +116,33 @@ const Component = () => { )} /> + + ( + + + + +
+ Using Conventional Commits + + If this changelog is using{' '} + + conventional commits + + +
+
+ )} + /> diff --git a/bruno/Changelog/Version/Create Auto.bru b/bruno/Changelog/Version/Create Auto.bru new file mode 100644 index 0000000..eec0da4 --- /dev/null +++ b/bruno/Changelog/Version/Create Auto.bru @@ -0,0 +1,22 @@ +meta { + name: Create Auto + type: http + seq: 1 +} + +post { + url: {{API_URL}}/v1/changelog/version/auto + body: json + auth: bearer +} + +auth:bearer { + token: {{TOKEN}} +} + +body:json { + { + "changelogId": "d83fe688-3331-4e64-9af6-318f82e511d4", + "commitIds": ["01cc79df-6d16-4496-b9ba-b238d686efc4"] + } +} diff --git a/bruno/Statistic.bru b/bruno/Statistic.bru index b12472d..786d7c1 100644 --- a/bruno/Statistic.bru +++ b/bruno/Statistic.bru @@ -11,5 +11,5 @@ get { } auth:bearer { - token: bt_7b83481e2ae0f6ab728730511adbe491f6668eb3 + token: {{TOKEN}} } diff --git a/bruno/environments/Development.bru b/bruno/environments/Development.bru index fcbed5b..c47f8eb 100644 --- a/bruno/environments/Development.bru +++ b/bruno/environments/Development.bru @@ -1,3 +1,6 @@ vars { API_URL: http://localhost:3000 } +vars:secret [ + TOKEN +] diff --git a/bun.lockb b/bun.lockb index 63fa326..63514d4 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/packages/schema/src/changelog/create.ts b/packages/schema/src/changelog/create.ts index e038d83..900d40e 100644 --- a/packages/schema/src/changelog/create.ts +++ b/packages/schema/src/changelog/create.ts @@ -7,6 +7,7 @@ export const ChangelogCreateInput = z title: z.string().min(3, 'Title must contain at least 3 charachters.'), description: z.string(), isSemver: z.boolean().default(true), + isConventional: z.boolean().default(true), }) .openapi({ required: ['title', 'userId'], diff --git a/packages/schema/src/version/create.ts b/packages/schema/src/version/create.ts index 2256a4d..4cc5169 100644 --- a/packages/schema/src/version/create.ts +++ b/packages/schema/src/version/create.ts @@ -14,3 +14,12 @@ export const VersionCreateInput = z .openapi({ required: ['changelogId', 'version', 'markdown', 'releasedAt'], }) + +export const VersionCreateAutoInput = z + .object({ + version: z.string().optional().nullable(), + changelogId: z.string().uuid(), + }) + .openapi({ + required: ['changelogId'], + })