feat: services table, base segmented control

This commit is contained in:
2025-09-27 18:24:22 +04:00
parent 14140826a7
commit 47533ad7f5
29 changed files with 1489 additions and 44 deletions

View File

@ -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,