-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
227 additions
and
211 deletions.
There are no files selected for viewing
11 changes: 0 additions & 11 deletions
11
packages/_leaa-common/src/dtos/article/update-article.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,30 @@ | ||
import { IsOptional } from 'class-validator'; | ||
import { Field, InputType, Int } from '@nestjs/graphql'; | ||
|
||
@InputType() | ||
export class UpdateArticleInput { | ||
@IsOptional() | ||
@Field(() => String, { nullable: true }) | ||
title?: string; | ||
|
||
@IsOptional() | ||
@Field(() => String, { nullable: true }) | ||
slug?: string; | ||
|
||
@IsOptional() | ||
@Field(() => String, { nullable: true }) | ||
user_id?: string; | ||
|
||
@IsOptional() | ||
@Field(() => String, { nullable: true }) | ||
description?: string; | ||
|
||
@IsOptional() | ||
@Field(() => String, { nullable: true }) | ||
content?: string; | ||
|
||
@IsOptional() | ||
@Field(() => Int, { nullable: true }) | ||
status?: number; | ||
|
||
@IsOptional() | ||
@Field(() => Date, { nullable: true }) | ||
released_at?: Date; | ||
|
||
@IsOptional() | ||
@Field(() => [String], { nullable: true }) | ||
categoryIds?: string[] | null; | ||
|
||
@IsOptional() | ||
@Field(() => [String], { nullable: true }) | ||
tagIds?: string[] | null; | ||
} |
9 changes: 3 additions & 6 deletions
9
packages/_leaa-common/src/dtos/category/create-category.input.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
import { IsNotEmpty } from 'class-validator'; | ||
import { Field, InputType, Int } from '@nestjs/graphql'; | ||
import { Category } from '@leaa/common/src/entrys'; | ||
|
||
@InputType() | ||
export class CreateCategoryInput { | ||
@IsNotEmpty() | ||
@Field(() => String) | ||
name!: string; | ||
|
||
@IsNotEmpty() | ||
@Field(() => String) | ||
slug!: string; | ||
|
||
@Field(() => String, { nullable: true }) | ||
parent_id?: string; | ||
|
||
@Field(() => String, { nullable: true }) | ||
description?: string; | ||
|
||
parent?: Category | null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 34 additions & 5 deletions
39
packages/leaa-api/src/modules/category/category.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/leaa-dashboard/src/pages/Category/CategoryCreate/CategoryCreate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useState, useRef } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Button } from 'antd'; | ||
|
||
import { Category } from '@leaa/common/src/entrys'; | ||
import { UPDATE_BUTTON_ICON } from '@leaa/dashboard/src/constants'; | ||
import { UpdateCategoryInput } from '@leaa/common/src/dtos/category'; | ||
import { IPage, ICommenFormRef, ISubmitData, IHttpRes, IHttpError } from '@leaa/dashboard/src/interfaces'; | ||
import { msg, errorMsg, ajax } from '@leaa/dashboard/src/utils'; | ||
|
||
import { envConfig } from '@leaa/dashboard/src/configs'; | ||
import { PageCard, HtmlMeta, Rcon, SubmitBar } from '@leaa/dashboard/src/components'; | ||
|
||
import { CategoryInfoForm } from '../_components/CategoryInfoForm/CategoryInfoForm'; | ||
|
||
import style from './style.module.less'; | ||
|
||
const API_PATH = 'categories'; | ||
|
||
export default (props: IPage) => { | ||
const { t } = useTranslation(); | ||
|
||
const infoFormRef = useRef<ICommenFormRef<UpdateCategoryInput>>(null); | ||
|
||
const [submitLoading, setSubmitLoading] = useState(false); | ||
|
||
const onCreateItem = async () => { | ||
const infoData: ISubmitData<UpdateCategoryInput> = await infoFormRef.current?.onValidateForm(); | ||
|
||
if (!infoData) return; | ||
|
||
const data: ISubmitData<UpdateCategoryInput> = { | ||
...infoData, | ||
}; | ||
|
||
setSubmitLoading(true); | ||
|
||
ajax | ||
.post(`${envConfig.API_URL}/${API_PATH}`, data) | ||
.then((res: IHttpRes<Category>) => { | ||
msg(t('_lang:createdSuccessfully')); | ||
|
||
props.history.push(`/${API_PATH}/${res.data.data?.id}`); | ||
}) | ||
.catch((err: IHttpError) => errorMsg(err.response?.data?.message || err.message)) | ||
.finally(() => setSubmitLoading(false)); | ||
}; | ||
|
||
return ( | ||
<PageCard route={props.route} title="@CREATE" className={style['wapper']} loading={submitLoading}> | ||
<HtmlMeta title={t(`${props.route.namei18n}`)} /> | ||
|
||
<CategoryInfoForm ref={infoFormRef} /> | ||
|
||
<SubmitBar full> | ||
<Button | ||
type="primary" | ||
size="large" | ||
icon={<Rcon type={UPDATE_BUTTON_ICON} />} | ||
className="g-submit-bar-button" | ||
loading={submitLoading} | ||
onClick={onCreateItem} | ||
> | ||
{t('_lang:update')} | ||
</Button> | ||
</SubmitBar> | ||
</PageCard> | ||
); | ||
}; |
File renamed without changes.
Oops, something went wrong.