feat: service deleting and rest categories placeholders

This commit is contained in:
2024-10-09 02:03:52 +03:00
parent dea1221016
commit 891b6cff9f
9 changed files with 41 additions and 21 deletions

View File

@@ -15,5 +15,6 @@ export type ServiceSchema = {
categoryPrices: Array<ServiceCategoryPriceSchema>; categoryPrices: Array<ServiceCategoryPriceSchema>;
cost: (number | null); cost: (number | null);
rank: string; rank: string;
isPlaceholder?: boolean;
}; };

View File

@@ -40,10 +40,20 @@ export class ServiceService {
* @returns ServiceGetAllResponse Successful Response * @returns ServiceGetAllResponse Successful Response
* @throws ApiError * @throws ApiError
*/ */
public static getAllServices(): CancelablePromise<ServiceGetAllResponse> { public static getAllServices({
withPlaceholders = false,
}: {
withPlaceholders?: boolean,
}): CancelablePromise<ServiceGetAllResponse> {
return __request(OpenAPI, { return __request(OpenAPI, {
method: 'GET', method: 'GET',
url: '/service/get-all', url: '/service/get-all',
query: {
'with_placeholders': withPlaceholders,
},
errors: {
422: `Validation Error`,
},
}); });
} }
/** /**

View File

@@ -16,7 +16,7 @@ type RestProps = {
}; };
type Props = Omit<ObjectSelectProps<ServiceSchema>, "data"> & RestProps; type Props = Omit<ObjectSelectProps<ServiceSchema>, "data"> & RestProps;
const ServiceSelectNew: FC<Props> = (props: Props) => { const ServiceSelectNew: FC<Props> = (props: Props) => {
const { services } = useServicesList(); const { services } = useServicesList({ withPlaceholders: false });
const data = props.filterType const data = props.filterType
? services.filter(service => service.serviceType === props.filterType) ? services.filter(service => service.serviceType === props.filterType)
: services; : services;
@@ -28,10 +28,10 @@ const ServiceSelectNew: FC<Props> = (props: Props) => {
return { return {
...option, ...option,
items: option.items.filter((item: ComboboxItem) => items: option.items.filter((item: ComboboxItem) =>
item.label.toLowerCase().includes(search.toLowerCase()) item.label.toLowerCase().includes(search.toLowerCase()),
), ),
}; };
} },
); );
}; };
return ( return (

View File

@@ -7,7 +7,7 @@ import useServicesList from "../../../pages/ServicesPage/hooks/useServicesList.t
type Props = Omit<ObjectMultiSelectProps<ServiceSchema>, "data">; type Props = Omit<ObjectMultiSelectProps<ServiceSchema>, "data">;
const ServicesMultiselect: FC<Props> = (props: Props) => { const ServicesMultiselect: FC<Props> = (props: Props) => {
const { services } = useServicesList(); const { services } = useServicesList({ withPlaceholders: false });
return ( return (
<ObjectMultiSelect <ObjectMultiSelect
data={services} data={services}

View File

@@ -20,7 +20,7 @@ const ServiceSelect: FC<Props> = props => {
ServiceSchema | undefined ServiceSchema | undefined
>(props.defaultValue); >(props.defaultValue);
const value = isControlled ? props.value : internalValue; const value = isControlled ? props.value : internalValue;
const { services } = useServicesList(); const { services } = useServicesList({ withPlaceholders: false });
const categories = useMemo( const categories = useMemo(
() => () =>
services.reduce((acc, service) => { services.reduce((acc, service) => {
@@ -29,7 +29,7 @@ const ServiceSelect: FC<Props> = props => {
} }
return acc; return acc;
}, [] as string[]), }, [] as string[]),
[services] [services],
); );
const data = useMemo( const data = useMemo(
@@ -43,22 +43,22 @@ const ServiceSelect: FC<Props> = props => {
label: service.name, label: service.name,
})), })),
})), })),
[services, categories] [services, categories],
); );
const handleOnChange = (value: string) => { const handleOnChange = (value: string) => {
if (isControlled) { if (isControlled) {
props.onChange( props.onChange(
services.find( services.find(
service => service.id.toString() === value service => service.id.toString() === value,
) as ServiceSchema ) as ServiceSchema,
); );
return; return;
} }
setInternalValue( setInternalValue(
services.find( services.find(
service => service.id.toString() === value service => service.id.toString() === value,
) as ServiceSchema ) as ServiceSchema,
); );
}; };
useEffect(() => { useEffect(() => {

View File

@@ -36,7 +36,6 @@ const ServicesTable: FC<Props> = ({
}); });
const minRank = categoryRanks.sort()[0]; const minRank = categoryRanks.sort()[0];
const maxRank = categoryRanks.sort()[categoryRanks.length - 1]; const maxRank = categoryRanks.sort()[categoryRanks.length - 1];
console.log(minRank, maxRank);
const onEditClick = (service: ServiceSchema) => { const onEditClick = (service: ServiceSchema) => {
if (!onChange) return; if (!onChange) return;
@@ -185,7 +184,7 @@ const ServicesTable: FC<Props> = ({
}, },
enableRowActions: true, enableRowActions: true,
renderRowActions: ({ row }) => ( renderRowActions: ({ row }) => (
<Flex gap="xs"> <Flex display={row.original.isPlaceholder ? "none" : "flex"} gap="xs">
<Tooltip label="Редактировать"> <Tooltip label="Редактировать">
<ActionIcon <ActionIcon
onClick={() => onEditClick(row.original)} onClick={() => onEditClick(row.original)}

View File

@@ -33,19 +33,23 @@ export const useServicesTableColumns = () => {
header: "Услуга", header: "Услуга",
enableGrouping: false, enableGrouping: false,
enableSorting: false, enableSorting: false,
Cell: ({ row, cell }) => {
return row.original.isPlaceholder ? "" : (cell.renderValue<string>());
},
}, },
{ {
accessorKey: "price", accessorKey: "price",
header: "Цена", header: "Цена",
enableGrouping: false, enableGrouping: false,
enableSorting: false, enableSorting: false,
Cell: ({ row }) => getPriceRow(row.original), Cell: ({ row }) => row.original.isPlaceholder ? "" : getPriceRow(row.original),
}, },
{ {
accessorKey: "cost", accessorKey: "cost",
header: "Себестоимость", header: "Себестоимость",
enableGrouping: false, enableGrouping: false,
enableSorting: false, enableSorting: false,
Cell: ({ row }) => row.original.isPlaceholder ? "" : `${row.original.cost}`,
}, },
], ],

View File

@@ -1,10 +1,16 @@
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { ServiceService } from "../../../client"; import { ServiceService } from "../../../client";
const useServicesList = () => { type Props = {
withPlaceholders?: boolean;
}
const useServicesList = (props: Props) => {
const { withPlaceholders = false } = props;
const { isPending, error, data, refetch } = useQuery({ const { isPending, error, data, refetch } = useQuery({
queryKey: ["getAllServices"], queryKey: ["getAllServices", withPlaceholders],
queryFn: ServiceService.getAllServices, queryFn: () => ServiceService.getAllServices({ withPlaceholders: withPlaceholders }),
}); });
const services = isPending || error || !data ? [] : data.services; const services = isPending || error || !data ? [] : data.services;

View File

@@ -9,7 +9,7 @@ import useServicesList from "./useServicesList.tsx";
import { Text } from "@mantine/core"; import { Text } from "@mantine/core";
const useServicesState = () => { const useServicesState = () => {
const { services, refetch } = useServicesList(); const { services, refetch } = useServicesList({ withPlaceholders: true });
const onCreateClick = () => { const onCreateClick = () => {
modals.openContextModal({ modals.openContextModal({
@@ -27,7 +27,7 @@ const useServicesState = () => {
notifications.guess(ok, { message: message }); notifications.guess(ok, { message: message });
if (!ok) return; if (!ok) return;
await refetch(); await refetch();
} },
); );
}; };
@@ -45,7 +45,7 @@ const useServicesState = () => {
ServiceService.createServiceCategory({ ServiceService.createServiceCategory({
requestBody: { category: category }, requestBody: { category: category },
}).then(({ ok, message }) => }).then(({ ok, message }) =>
notifications.guess(ok, { message: message }) notifications.guess(ok, { message: message }),
); );
}; };