From 8927fb88b45853fd11ae42a996c6cdb92d232d12 Mon Sep 17 00:00:00 2001 From: bicochan Date: Fri, 18 Apr 2025 18:19:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=BD=98=ED=85=90=EC=B8=A0=20=EC=8A=B9?= =?UTF-8?q?=EC=9D=B8=20=EB=A1=9C=EC=A7=81=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entities/content/api/contents-service.ts | 9 +++ .../content/model/contents-interface.ts | 1 + apps/cs/src/entities/editor/ui/editor.tsx | 1 + .../src/pages/contents/ui/contents-form.tsx | 13 +++- apps/cs/src/pages/contents/ui/modify-page.tsx | 71 +++++++++++-------- 5 files changed, 64 insertions(+), 31 deletions(-) diff --git a/apps/cs/src/entities/content/api/contents-service.ts b/apps/cs/src/entities/content/api/contents-service.ts index 355a04b1a..00d2a8c67 100644 --- a/apps/cs/src/entities/content/api/contents-service.ts +++ b/apps/cs/src/entities/content/api/contents-service.ts @@ -76,6 +76,15 @@ export class ContentsApiService implements ContentsService { `${ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS}/${contsSn}/${contsVer}/approveRequest`, ); } + + public async approveContents( + contsSn: number, + contsVer: number, + ): Promise { + await client.put( + `${ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS}/${contsSn}/${contsVer}/approve`, + ); + } } export const ContentsApi = new ContentsApiService(); diff --git a/apps/cs/src/entities/content/model/contents-interface.ts b/apps/cs/src/entities/content/model/contents-interface.ts index 0048b0906..72456149b 100644 --- a/apps/cs/src/entities/content/model/contents-interface.ts +++ b/apps/cs/src/entities/content/model/contents-interface.ts @@ -96,4 +96,5 @@ export interface ContentsService { ): Promise; deleteContents(contsSn: number, contsVer: number): Promise; requestApprove(contsSn: number, contsVer: number): Promise; + approveContents(contsSn: number, contsVer: number): Promise; } diff --git a/apps/cs/src/entities/editor/ui/editor.tsx b/apps/cs/src/entities/editor/ui/editor.tsx index b5ef02153..797a6c1bf 100644 --- a/apps/cs/src/entities/editor/ui/editor.tsx +++ b/apps/cs/src/entities/editor/ui/editor.tsx @@ -49,6 +49,7 @@ const Editor = ({ ...props }: IAllProps) => { }} init={{ ...baseConfig.init, + disabled: props.disabled, images_upload_handler: imagesUploadHandler, file_picker_callback: filePickerCallback, }} diff --git a/apps/cs/src/pages/contents/ui/contents-form.tsx b/apps/cs/src/pages/contents/ui/contents-form.tsx index d61084646..823d30173 100644 --- a/apps/cs/src/pages/contents/ui/contents-form.tsx +++ b/apps/cs/src/pages/contents/ui/contents-form.tsx @@ -27,7 +27,8 @@ const Editor = dynamic( interface ContentsFormProps { form: UseFormReturn; contsSn?: number; - disabledFields?: Partial>; + isEditable?: boolean; + isContsTtlDisabled?: boolean; handleSave: (data: ContentsFormData) => Promise; handleDelete?: () => Promise; } @@ -35,7 +36,8 @@ interface ContentsFormProps { function ContentsForm({ form, contsSn, - disabledFields, + isEditable, + isContsTtlDisabled, ...props }: ContentsFormProps) { const { data: cclCode } = useQuery({ @@ -71,7 +73,7 @@ function ContentsForm({ value={field.value ?? ""} className="!text-[1.3rem]" placeholder="콘텐츠 제목을 입력하십시오." - disabled={disabledFields?.contsTtl} + disabled={!isEditable || isContsTtlDisabled} /> @@ -91,6 +93,7 @@ function ContentsForm({ @@ -112,6 +115,7 @@ function ContentsForm({ name="cclCd" value={field.value ?? ""} onValueChange={field.onChange} + disabled={!isEditable} >
@@ -162,6 +166,7 @@ function ContentsForm({ name="koglCd" value={field.value ?? ""} onValueChange={field.onChange} + disabled={!isEditable} >
@@ -214,6 +219,7 @@ function ContentsForm({ value={field.value ?? ""} className="!text-[1.3rem]" placeholder="태그를 입력하십시오." + disabled={!isEditable} /> @@ -235,6 +241,7 @@ function ContentsForm({ name="useYn" value={field.value ?? ""} onValueChange={field.onChange} + disabled={!isEditable} >
diff --git a/apps/cs/src/pages/contents/ui/modify-page.tsx b/apps/cs/src/pages/contents/ui/modify-page.tsx index 82738dfff..e4b765f24 100644 --- a/apps/cs/src/pages/contents/ui/modify-page.tsx +++ b/apps/cs/src/pages/contents/ui/modify-page.tsx @@ -24,16 +24,12 @@ import { } from "@common/components/ui"; function ModifyPage({ sequential }: { sequential: string }) { - const contsSn = Number(sequential); - const { confirm } = useConfirm(); const queryClient = useQueryClient(); const { setMessage: alert } = useAlertStore((state) => state); - const [contentsVersion, setContentsVersion] = useState(0); - const [disabledFields, setDisabledFields] = useState< - Partial> - >({}); + const contsSn = Number(sequential); + const [contsVer, setContsVer] = useState(0); const { data: contentsVersionList } = useQuery({ queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, contsSn], @@ -46,14 +42,15 @@ function ModifyPage({ sequential }: { sequential: string }) { }); const { data: contentsDetail } = useQuery({ - queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, contentsVersion], - queryFn: () => ContentsApi.getLatestContentsInfo(contsSn, contentsVersion), - enabled: !!contentsVersion, + queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, contsVer], + queryFn: () => ContentsApi.getLatestContentsInfo(contsSn, contsVer), + enabled: !!contsVer, }); const { mutateAsync: createContents } = useMutation({ mutationFn: (data: ContentsFormData) => ContentsApi.createContents(data), onSuccess: () => { + setContsVer(0); alert("수정되었습니다."); queryClient.invalidateQueries({ queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, contsSn], @@ -63,15 +60,16 @@ function ModifyPage({ sequential }: { sequential: string }) { const { mutateAsync: updateContents } = useMutation({ mutationFn: (data: ContentsFormData) => - ContentsApi.updateContents(contsSn, contentsVersion, data), + ContentsApi.updateContents(contsSn, contsVer, data), onSuccess: () => { alert("수정되었습니다."); }, }); const { mutateAsync: deleteContents } = useMutation({ - mutationFn: () => ContentsApi.deleteContents(contsSn, contentsVersion), + mutationFn: () => ContentsApi.deleteContents(contsSn, contsVer), onSuccess: () => { + setContsVer(0); alert("삭제되었습니다."); queryClient.invalidateQueries({ queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, contsSn], @@ -80,11 +78,21 @@ function ModifyPage({ sequential }: { sequential: string }) { }); const { mutateAsync: requestApprove } = useMutation({ - mutationFn: () => ContentsApi.requestApprove(contsSn, contentsVersion), + mutationFn: () => ContentsApi.requestApprove(contsSn, contsVer), onSuccess: () => { alert("승인 요청이 완료되었습니다."); queryClient.invalidateQueries({ - queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, contentsVersion], + queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS], + }); + }, + }); + + const { mutateAsync: approveContents } = useMutation({ + mutationFn: () => ContentsApi.approveContents(contsSn, contsVer), + onSuccess: () => { + alert("승인되었습니다."); + queryClient.invalidateQueries({ + queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS], }); }, }); @@ -94,12 +102,9 @@ function ModifyPage({ sequential }: { sequential: string }) { values: contentsDetail, }); - const isDraftContents = - contentsDetail?.aprvCd === CONTENTS_APPROVE_STATUS.DRAFT; - const isRequestedContents = - contentsDetail?.aprvCd === CONTENTS_APPROVE_STATUS.REQUESTED; - const isApprovedContents = - contentsDetail?.aprvCd === CONTENTS_APPROVE_STATUS.APPROVED; + const approveStatus = contentsDetail?.aprvCd; + const isContsTtlDisabled = + (contentsVersionList?.content?.[0]?.contsVer ?? 0) > 1; const onRequestApprove = async () => { const message = @@ -107,14 +112,19 @@ function ModifyPage({ sequential }: { sequential: string }) { if (await confirm(message)) requestApprove(); }; + const onApprove = async () => { + const message = "승인하시겠습니까?"; + if (await confirm(message)) approveContents(); + }; + useEffect(() => { + if (contsVer) return; if (!contentsVersionList?.content?.length) return; const latestContent = contentsVersionList?.content[0]; if (!latestContent) return; - if (latestContent?.contsVer > 1) setDisabledFields({ contsTtl: true }); - setContentsVersion(latestContent?.contsVer ?? 0); + setContsVer(latestContent?.contsVer ?? 0); }, [contentsVersionList?.content]); return ( @@ -123,9 +133,9 @@ function ModifyPage({ sequential }: { sequential: string }) {

템플릿 수정

- {isDraftContents && ( + {approveStatus === CONTENTS_APPROVE_STATUS.DRAFT && ( )} - {isRequestedContents && ( + {approveStatus === CONTENTS_APPROVE_STATUS.REQUESTED && ( <> - + )} @@ -156,8 +166,13 @@ function ModifyPage({ sequential }: { sequential: string }) {