feat(cms): content not getting updated

This commit is contained in:
Amit Ranjan 2024-10-02 13:37:36 +05:30
parent 9ca6d46d9f
commit ad2845afec
4 changed files with 20 additions and 25 deletions

View File

@ -215,9 +215,7 @@ export class ContentController extends BaseController<
)
filters: TFilterQuery<Content>,
) {
return this.canPopulate(populate)
? await this.contentService.findPageAndPopulate(filters, pageQuery)
: await this.contentService.findPage(filters, pageQuery);
return await this.contentService.findPage(filters, pageQuery);
}
/**

View File

@ -165,7 +165,7 @@ export const ContentDialog: FC<ContentDialogProps> = ({
updateContent(
{
id: content.id,
params: { ...params, entity: (params.entity as any).id },
params: { ...params, entity: params.entity },
},
{
onError: () => {

View File

@ -23,7 +23,7 @@ import { renderHeader } from "@/app-components/tables/columns/renderHeader";
import { DataGrid } from "@/app-components/tables/DataGrid";
import { useDelete } from "@/hooks/crud/useDelete";
import { useFind } from "@/hooks/crud/useFind";
import { useGet, useGetFromCache } from "@/hooks/crud/useGet";
import { useGet } from "@/hooks/crud/useGet";
import { useUpdate } from "@/hooks/crud/useUpdate";
import { getDisplayDialogs, useDialog } from "@/hooks/useDialog";
import { useHasPermission } from "@/hooks/useHasPermission";
@ -82,7 +82,6 @@ export const Contents = () => {
toast.success(t("message.item_delete_success"));
},
});
const getEntityFromCache = useGetFromCache(EntityType.CONTENT_TYPE);
const actionColumns = useActionColumns<IContent>(
EntityType.CONTENT,
[
@ -165,10 +164,8 @@ export const Contents = () => {
field: "entity",
headerName: t("label.entity"),
flex: 1,
valueGetter: (row: IContent) => {
const contentType = getEntityFromCache(row.id);
return contentType?.name;
valueGetter: () => {
return data?.name;
},
},
{
@ -195,7 +192,7 @@ export const Contents = () => {
params: {
status: !params.row.status,
title: params.row.title,
entity: (params.row.entity as any).id,
entity: params.row.entity,
},
});
}}

View File

@ -17,7 +17,7 @@ import {
} from "@/types/base.types";
import { merge } from "@/utils/object";
import { isSameEntity, useNormalizeAndCache } from "./helpers";
import { useNormalizeAndCache } from "./helpers";
import { useGetFromCache } from "./useGet";
import { useEntityApiClient } from "../useApiClient";
@ -42,26 +42,26 @@ export const useUpdate = <
) => {
const api = useEntityApiClient<TAttr, TBasic, TFull>(entity);
const normalizeAndCache = useNormalizeAndCache<TBasic, string>(entity);
const queryClient = useQueryClient();
const { invalidate = true } = options || {};
// const queryClient = useQueryClient();
// const { invalidate = true } = options || {};
return useMutation({
mutationFn: async ({ id, params }) => {
const data = await api.update(id, params);
const { entities, result } = normalizeAndCache(data);
if (invalidate) {
queryClient.removeQueries({
predicate: ({ queryKey }) => {
const [qType, qEntity] = queryKey;
// if (invalidate) {
// queryClient.removeQueries({
// predicate: ({ queryKey }) => {
// const [qType, qEntity] = queryKey;
return (
(qType === QueryType.count || qType === QueryType.collection) &&
isSameEntity(qEntity, entity)
);
},
});
}
// return (
// (qType === QueryType.count || qType === QueryType.collection) &&
// isSameEntity(qEntity, entity)
// );
// },
// });
// }
return entities[entity]?.[result] as unknown as TBasic;
},