feat: 콘텐츠 삭제 작업
This commit is contained in:
@@ -59,8 +59,13 @@ export class ContentsApiService implements ContentsService {
|
|||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteContents(contsSn: number): Promise<void> {
|
public async deleteContents(
|
||||||
await client.delete(`${ENDPOINT.CMS_SERVICE.CONTENTS}/${contsSn}`);
|
contsSn: number,
|
||||||
|
contsVer: number,
|
||||||
|
): Promise<void> {
|
||||||
|
await client.delete(
|
||||||
|
`${ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS}/${contsSn}/${contsVer}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,5 +90,5 @@ export interface ContentsService {
|
|||||||
contsVer: number,
|
contsVer: number,
|
||||||
data: ContentsFormData,
|
data: ContentsFormData,
|
||||||
): Promise<void>;
|
): Promise<void>;
|
||||||
deleteContents(contsSn: number): Promise<void>;
|
deleteContents(contsSn: number, contsVer: number): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ function ModifyPage({ sequential }: { sequential: string }) {
|
|||||||
queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, sequential],
|
queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, sequential],
|
||||||
queryFn: () =>
|
queryFn: () =>
|
||||||
ContentsApi.getContentsVersionList({
|
ContentsApi.getContentsVersionList({
|
||||||
contsSn: Number(sequential),
|
contsSn: contsSn,
|
||||||
page: 0,
|
page: 0,
|
||||||
size: 100,
|
size: 100,
|
||||||
}),
|
}),
|
||||||
@@ -42,8 +42,7 @@ function ModifyPage({ sequential }: { sequential: string }) {
|
|||||||
|
|
||||||
const { data: contentsDetail } = useQuery({
|
const { data: contentsDetail } = useQuery({
|
||||||
queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, contentsVersion],
|
queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, contentsVersion],
|
||||||
queryFn: () =>
|
queryFn: () => ContentsApi.getLatestContentsInfo(contsSn, contentsVersion),
|
||||||
ContentsApi.getLatestContentsInfo(Number(sequential), contentsVersion),
|
|
||||||
enabled: !!contentsVersion,
|
enabled: !!contentsVersion,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -59,21 +58,28 @@ function ModifyPage({ sequential }: { sequential: string }) {
|
|||||||
|
|
||||||
const { mutateAsync: updateContents } = useMutation({
|
const { mutateAsync: updateContents } = useMutation({
|
||||||
mutationFn: (data: ContentsFormData) =>
|
mutationFn: (data: ContentsFormData) =>
|
||||||
ContentsApi.updateContents(
|
ContentsApi.updateContents(contsSn, contentsDetail?.contsVer ?? 0, data),
|
||||||
Number(sequential),
|
|
||||||
contentsDetail?.contsVer ?? 0,
|
|
||||||
data,
|
|
||||||
),
|
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
alert("수정되었습니다.");
|
alert("수정되었습니다.");
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const { mutateAsync: deleteContents } = useMutation({
|
||||||
|
mutationFn: () => ContentsApi.deleteContents(contsSn, contentsVersion),
|
||||||
|
onSuccess: () => {
|
||||||
|
alert("삭제되었습니다.");
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: [ENDPOINT.CMS_SERVICE.CONTENTS_DETAILS, sequential],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const form = useForm<ContentsFormData>({
|
const form = useForm<ContentsFormData>({
|
||||||
resolver: zodResolver(contentsFormSchema),
|
resolver: zodResolver(contentsFormSchema),
|
||||||
values: contentsDetail,
|
values: contentsDetail,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const contsSn = Number(sequential);
|
||||||
const isApprovedContents =
|
const isApprovedContents =
|
||||||
contentsDetail?.aprvCd === CONTENTS_APPROVAL_STATUS.APPROVED;
|
contentsDetail?.aprvCd === CONTENTS_APPROVAL_STATUS.APPROVED;
|
||||||
|
|
||||||
@@ -120,9 +126,10 @@ function ModifyPage({ sequential }: { sequential: string }) {
|
|||||||
</div>
|
</div>
|
||||||
<ContentsForm
|
<ContentsForm
|
||||||
form={form}
|
form={form}
|
||||||
contsSn={Number(sequential)}
|
contsSn={contsSn}
|
||||||
disabledFields={disabledFields}
|
disabledFields={disabledFields}
|
||||||
handleSave={isApprovedContents ? createContents : updateContents}
|
handleSave={isApprovedContents ? createContents : updateContents}
|
||||||
|
handleDelete={deleteContents}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user