feat: services table, base segmented control
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import { LexoRank } from "lexorank";
|
||||
import { useCrudOperations } from "@/hooks/cruds/baseCrud";
|
||||
import {
|
||||
CreateServiceSchema,
|
||||
@ -9,9 +10,11 @@ import {
|
||||
deleteServiceMutation,
|
||||
updateServiceMutation,
|
||||
} from "@/lib/client/@tanstack/react-query.gen";
|
||||
import { getMaxByLexorank, getNewLexorank } from "@/utils/lexorank";
|
||||
|
||||
type UseServicesProps = {
|
||||
queryKey: any[];
|
||||
services: ServiceSchema[];
|
||||
};
|
||||
|
||||
export type ServicesCrud = {
|
||||
@ -26,6 +29,7 @@ export type ServicesCrud = {
|
||||
|
||||
export const useServicesCrud = ({
|
||||
queryKey,
|
||||
services,
|
||||
}: UseServicesProps): ServicesCrud => {
|
||||
return useCrudOperations<
|
||||
ServiceSchema,
|
||||
@ -39,6 +43,15 @@ export const useServicesCrud = ({
|
||||
update: updateServiceMutation(),
|
||||
delete: deleteServiceMutation(),
|
||||
},
|
||||
getCreateEntity: service => {
|
||||
const maxRankStr = getMaxByLexorank(services)?.lexorank;
|
||||
const maxRank = maxRankStr ? LexoRank.parse(maxRankStr) : null;
|
||||
|
||||
return {
|
||||
...(service as CreateServiceSchema),
|
||||
lexorank: getNewLexorank(maxRank).toString(),
|
||||
};
|
||||
},
|
||||
getUpdateEntity: (old, update) =>
|
||||
({
|
||||
...old,
|
||||
|
||||
Reference in New Issue
Block a user