Files
Fulfillment-Frontend/src/pages/AdminPage/tabs/RolesAndPositions/RolesAndPositionsTab.tsx
2024-09-27 04:47:04 +03:00

40 lines
1.2 KiB
TypeScript

import PositionsTable from "../../components/PositionsTable/PositionsTable.tsx";
import usePositionsList from "../../hooks/usePositionsList.tsx";
import { PositionSchema, PositionService } from "../../../../client";
import { notifications } from "../../../../shared/lib/notifications.ts";
const RolesAndPositionsTab = () => {
const { objects: positions, refetch } = usePositionsList();
const onCreate = (position: PositionSchema) => {
PositionService.createPosition({
requestBody: {
data: position,
},
}).then(async ({ ok, message }) => {
notifications.guess(ok, { message });
if (!ok) return;
await refetch();
});
};
const onDelete = (position: PositionSchema) => {
PositionService.deletePosition({
requestBody: {
positionKey: position.key,
},
}).then(async ({ ok, message }) => {
notifications.guess(ok, { message });
if (!ok) return;
await refetch();
});
};
return (
<PositionsTable
items={positions}
onCreate={onCreate}
onDelete={onDelete}
/>
);
};
export default RolesAndPositionsTab;