add
This commit is contained in:
parent
4ec92966ab
commit
4c89a43197
|
@ -5,39 +5,48 @@ import { ObjectType, Staff } from "@nice/common";
|
||||||
import { findQueryData } from "../utils";
|
import { findQueryData } from "../utils";
|
||||||
import { CrudOperation, emitDataChange } from "../../event";
|
import { CrudOperation, emitDataChange } from "../../event";
|
||||||
export function useStaff() {
|
export function useStaff() {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const queryKey = getQueryKey(api.staff);
|
const queryKey = getQueryKey(api.staff);
|
||||||
|
|
||||||
const create = api.staff.create.useMutation({
|
const create = api.staff.create.useMutation({
|
||||||
onSuccess: (result) => {
|
onSuccess: (result) => {
|
||||||
queryClient.invalidateQueries({ queryKey });
|
queryClient.invalidateQueries({ queryKey });
|
||||||
emitDataChange(ObjectType.STAFF, result as any, CrudOperation.CREATED)
|
emitDataChange(
|
||||||
},
|
ObjectType.STAFF,
|
||||||
});
|
result as any,
|
||||||
const updateUserDomain = api.staff.updateUserDomain.useMutation({
|
CrudOperation.CREATED
|
||||||
onSuccess: async (result) => {
|
);
|
||||||
queryClient.invalidateQueries({ queryKey });
|
},
|
||||||
},
|
});
|
||||||
});
|
const updateUserDomain = api.staff.updateUserDomain.useMutation({
|
||||||
const update = api.staff.update.useMutation({
|
onSuccess: async (result) => {
|
||||||
onSuccess: (result) => {
|
queryClient.invalidateQueries({ queryKey });
|
||||||
queryClient.invalidateQueries({ queryKey });
|
},
|
||||||
emitDataChange(ObjectType.STAFF, result as any, CrudOperation.UPDATED)
|
});
|
||||||
},
|
const update = api.staff.update.useMutation({
|
||||||
});
|
onSuccess: (result) => {
|
||||||
|
queryClient.invalidateQueries({ queryKey });
|
||||||
|
queryClient.invalidateQueries({ queryKey: getQueryKey(api.post) });
|
||||||
|
emitDataChange(
|
||||||
|
ObjectType.STAFF,
|
||||||
|
result as any,
|
||||||
|
CrudOperation.UPDATED
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
const softDeleteByIds = api.staff.softDeleteByIds.useMutation({
|
const softDeleteByIds = api.staff.softDeleteByIds.useMutation({
|
||||||
onSuccess: (result, variables) => {
|
onSuccess: (result, variables) => {
|
||||||
queryClient.invalidateQueries({ queryKey });
|
queryClient.invalidateQueries({ queryKey });
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const getStaff = (key: string) => {
|
const getStaff = (key: string) => {
|
||||||
return findQueryData<Staff>(queryClient, api.staff, key);
|
return findQueryData<Staff>(queryClient, api.staff, key);
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
create,
|
create,
|
||||||
update,
|
update,
|
||||||
softDeleteByIds,
|
softDeleteByIds,
|
||||||
getStaff,
|
getStaff,
|
||||||
updateUserDomain
|
updateUserDomain,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue