feat: 게시판 템플릿 작업
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { client } from "@/shared/api";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
import type {
|
||||
BoardTemplate,
|
||||
BoardTemplateService,
|
||||
} from "../model/board-template-interface";
|
||||
|
||||
export class BoardTemplateApiService implements BoardTemplateService {
|
||||
public async getBoardTemplate(bbsTypeCd: string): Promise<BoardTemplate> {
|
||||
const response = await client.get<BoardTemplate>(
|
||||
`${ENDPOINT.BOARD_SERVICE.BBS_TEMPLATES}/${bbsTypeCd}`,
|
||||
);
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
|
||||
export const BoardTemplateApi = new BoardTemplateApiService();
|
||||
@@ -6,3 +6,4 @@ export {
|
||||
type BoardParams,
|
||||
type BoardPopup,
|
||||
} from "./model/board-interface";
|
||||
export { BoardTemplateApi } from "./api/board-template-service";
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
export interface BoardTemplate {
|
||||
bbsTypeCd: string;
|
||||
rfrncUseYn: string;
|
||||
atflUseYn: string;
|
||||
atflMaxCnt: number;
|
||||
atflMaxFileSz: number;
|
||||
ansUseYn: string;
|
||||
cmntUseYn: string;
|
||||
dgstfnEvlUseYn: string;
|
||||
smsUseYn: string;
|
||||
upndFixUseYn: string;
|
||||
pstgPrdUseYn: string;
|
||||
popupUseYn: string;
|
||||
regDt: string;
|
||||
rgtr: string;
|
||||
mdfcnDt: string;
|
||||
mdfr: string;
|
||||
rgtrNm: string;
|
||||
mdfrNm: string;
|
||||
}
|
||||
|
||||
export interface BoardTemplateService {
|
||||
getBoardTemplate: (bbsTypeCd: string) => Promise<BoardTemplate>;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import type { UseFormReturn } from "react-hook-form";
|
||||
import {
|
||||
Input,
|
||||
@@ -19,7 +20,12 @@ import {
|
||||
} from "@common/components";
|
||||
import { FormWrapper } from "@/widgets/form-wrapper";
|
||||
import { CodeSelect } from "@/entities/code";
|
||||
import type { Board, BoardFormData } from "@/entities/board";
|
||||
import {
|
||||
BoardTemplateApi,
|
||||
type Board,
|
||||
type BoardFormData,
|
||||
} from "@/entities/board";
|
||||
import { ENDPOINT } from "@/shared/config";
|
||||
import { FormControl, FormField, FormItem } from "@/shared/ui/form";
|
||||
|
||||
type BbsFormProps = {
|
||||
@@ -29,6 +35,15 @@ type BbsFormProps = {
|
||||
};
|
||||
|
||||
function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
const bbsTypeCd = form.watch("bbsTypeCd");
|
||||
const formDisabled = !!bbsTypeCd && bbsTypeCd !== "BBSNORMAL";
|
||||
|
||||
const { data: boardTemplate } = useQuery({
|
||||
queryKey: [ENDPOINT.BOARD_SERVICE.BBS_TEMPLATES, bbsTypeCd],
|
||||
queryFn: () => BoardTemplateApi.getBoardTemplate(bbsTypeCd),
|
||||
enabled: !formDisabled,
|
||||
});
|
||||
|
||||
return (
|
||||
<FormWrapper form={form} isModifyMode={!!bbsId} {...props}>
|
||||
<div className="card">
|
||||
@@ -109,7 +124,12 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<RadioGroup {...field} onValueChange={field.onChange}>
|
||||
<RadioGroup
|
||||
{...field}
|
||||
value={boardTemplate?.rfrncUseYn ?? field.value}
|
||||
onValueChange={field.onChange}
|
||||
disabled={formDisabled}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="Y" id="rfrncUseY" />
|
||||
<Label htmlFor="rfrncUseY">사용</Label>
|
||||
@@ -134,7 +154,12 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<RadioGroup {...field} onValueChange={field.onChange}>
|
||||
<RadioGroup
|
||||
{...field}
|
||||
value={boardTemplate?.atflUseYn ?? field.value}
|
||||
onValueChange={field.onChange}
|
||||
disabled={formDisabled}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="Y" id="atflUseY" />
|
||||
<Label htmlFor="atflUseY">사용</Label>
|
||||
@@ -163,7 +188,7 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
{...field}
|
||||
type="number"
|
||||
min={0}
|
||||
value={field.value ?? ""}
|
||||
value={boardTemplate?.atflMaxCnt ?? field.value ?? ""}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
if (isNaN(parseInt(value))) return;
|
||||
@@ -173,7 +198,9 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
}}
|
||||
className="w-[12rem] !text-[1.3rem]"
|
||||
placeholder="최대 개수 입력"
|
||||
disabled={form.watch("atflUseYn") === "N"}
|
||||
disabled={
|
||||
form.getValues("atflUseYn") === "N" || formDisabled
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
@@ -194,7 +221,9 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
{...field}
|
||||
type="number"
|
||||
min={0}
|
||||
value={field.value ?? ""}
|
||||
value={
|
||||
boardTemplate?.atflMaxFileSz ?? field.value ?? ""
|
||||
}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
if (isNaN(parseInt(value))) return;
|
||||
@@ -204,7 +233,9 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
}}
|
||||
className="w-[12rem] !text-[1.3rem]"
|
||||
placeholder="최대 크기 입력"
|
||||
disabled={form.watch("atflUseYn") === "N"}
|
||||
disabled={
|
||||
form.getValues("atflUseYn") === "N" || formDisabled
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
</FormItem>
|
||||
@@ -221,7 +252,12 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<RadioGroup {...field} onValueChange={field.onChange}>
|
||||
<RadioGroup
|
||||
{...field}
|
||||
value={boardTemplate?.ansUseYn ?? field.value}
|
||||
onValueChange={field.onChange}
|
||||
disabled={formDisabled}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="Y" id="ansUseY" />
|
||||
<Label htmlFor="ansUseY">사용</Label>
|
||||
@@ -249,7 +285,7 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
<Select
|
||||
value={field.value ?? ""}
|
||||
onValueChange={field.onChange}
|
||||
disabled={form.watch("ansUseYn") === "N"}
|
||||
disabled={form.getValues("ansUseYn") === "N"}
|
||||
>
|
||||
<SelectTrigger className="w-[12rem]">
|
||||
<SelectValue placeholder="선택" />
|
||||
@@ -275,7 +311,12 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<RadioGroup {...field} onValueChange={field.onChange}>
|
||||
<RadioGroup
|
||||
{...field}
|
||||
value={boardTemplate?.cmntUseYn ?? field.value}
|
||||
onValueChange={field.onChange}
|
||||
disabled={formDisabled}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="Y" id="cmntUseY" />
|
||||
<Label htmlFor="cmntUseY">사용</Label>
|
||||
@@ -300,7 +341,12 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<RadioGroup {...field} onValueChange={field.onChange}>
|
||||
<RadioGroup
|
||||
{...field}
|
||||
value={boardTemplate?.dgstfnEvlUseYn ?? field.value}
|
||||
onValueChange={field.onChange}
|
||||
disabled={formDisabled}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="Y" id="dgstfnEvlUseY" />
|
||||
<Label htmlFor="dgstfnEvlUseY">사용</Label>
|
||||
@@ -325,7 +371,12 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<RadioGroup {...field} onValueChange={field.onChange}>
|
||||
<RadioGroup
|
||||
{...field}
|
||||
value={boardTemplate?.popupUseYn ?? field.value}
|
||||
onValueChange={field.onChange}
|
||||
disabled={formDisabled}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="Y" id="popupUseY" />
|
||||
<Label htmlFor="popupUseY">사용</Label>
|
||||
@@ -350,7 +401,12 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<RadioGroup {...field} onValueChange={field.onChange}>
|
||||
<RadioGroup
|
||||
{...field}
|
||||
value={boardTemplate?.smsUseYn ?? field.value}
|
||||
onValueChange={field.onChange}
|
||||
disabled={formDisabled}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="Y" id="smsUseY" />
|
||||
<Label htmlFor="smsUseY">사용</Label>
|
||||
@@ -375,7 +431,12 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<RadioGroup {...field} onValueChange={field.onChange}>
|
||||
<RadioGroup
|
||||
{...field}
|
||||
value={boardTemplate?.upndFixUseYn ?? field.value}
|
||||
onValueChange={field.onChange}
|
||||
disabled={formDisabled}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="Y" id="upndFixUseY" />
|
||||
<Label htmlFor="upndFixUseY">사용</Label>
|
||||
@@ -400,7 +461,12 @@ function BbsForm({ form, bbsId, ...props }: BbsFormProps) {
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormControl>
|
||||
<RadioGroup {...field} onValueChange={field.onChange}>
|
||||
<RadioGroup
|
||||
{...field}
|
||||
value={boardTemplate?.pstgPrdUseYn ?? field.value}
|
||||
onValueChange={field.onChange}
|
||||
disabled={formDisabled}
|
||||
>
|
||||
<div className="flex items-center space-x-2">
|
||||
<RadioGroupItem value="Y" id="pstgPrdUseY" />
|
||||
<Label htmlFor="pstgPrdUseY">사용</Label>
|
||||
|
||||
@@ -36,6 +36,7 @@ export const ENDPOINT = {
|
||||
},
|
||||
BOARD_SERVICE: {
|
||||
BBS: "/board-service/api/v1/bbs",
|
||||
BBS_TEMPLATES: "/board-service/api/v1/bbsTmplt",
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user