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 { CrudOperation, emitDataChange } from "../../event";
|
||||
export function useStaff() {
|
||||
const queryClient = useQueryClient();
|
||||
const queryKey = getQueryKey(api.staff);
|
||||
const queryClient = useQueryClient();
|
||||
const queryKey = getQueryKey(api.staff);
|
||||
|
||||
const create = api.staff.create.useMutation({
|
||||
onSuccess: (result) => {
|
||||
queryClient.invalidateQueries({ queryKey });
|
||||
emitDataChange(ObjectType.STAFF, result as any, CrudOperation.CREATED)
|
||||
},
|
||||
});
|
||||
const updateUserDomain = api.staff.updateUserDomain.useMutation({
|
||||
onSuccess: async (result) => {
|
||||
queryClient.invalidateQueries({ queryKey });
|
||||
},
|
||||
});
|
||||
const update = api.staff.update.useMutation({
|
||||
onSuccess: (result) => {
|
||||
queryClient.invalidateQueries({ queryKey });
|
||||
emitDataChange(ObjectType.STAFF, result as any, CrudOperation.UPDATED)
|
||||
},
|
||||
});
|
||||
const create = api.staff.create.useMutation({
|
||||
onSuccess: (result) => {
|
||||
queryClient.invalidateQueries({ queryKey });
|
||||
emitDataChange(
|
||||
ObjectType.STAFF,
|
||||
result as any,
|
||||
CrudOperation.CREATED
|
||||
);
|
||||
},
|
||||
});
|
||||
const updateUserDomain = api.staff.updateUserDomain.useMutation({
|
||||
onSuccess: async (result) => {
|
||||
queryClient.invalidateQueries({ queryKey });
|
||||
},
|
||||
});
|
||||
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({
|
||||
onSuccess: (result, variables) => {
|
||||
queryClient.invalidateQueries({ queryKey });
|
||||
},
|
||||
});
|
||||
const getStaff = (key: string) => {
|
||||
return findQueryData<Staff>(queryClient, api.staff, key);
|
||||
};
|
||||
return {
|
||||
create,
|
||||
update,
|
||||
softDeleteByIds,
|
||||
getStaff,
|
||||
updateUserDomain
|
||||
};
|
||||
const getStaff = (key: string) => {
|
||||
return findQueryData<Staff>(queryClient, api.staff, key);
|
||||
};
|
||||
return {
|
||||
create,
|
||||
update,
|
||||
softDeleteByIds,
|
||||
getStaff,
|
||||
updateUserDomain,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue