feat: drawers registry
This commit is contained in:
@ -1,36 +1,18 @@
|
||||
"use client";
|
||||
|
||||
import React, { createContext, FC, useContext, useState } from "react";
|
||||
import { useMutation, UseMutationResult } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
import React, { createContext, FC, useContext } from "react";
|
||||
import { useBoardsContext } from "@/app/deals/contexts/BoardsContext";
|
||||
import useStatusesList from "@/hooks/useStatusesList";
|
||||
import { useStatusesOperations } from "@/hooks/useStatusesOperations";
|
||||
import {
|
||||
HttpValidationError,
|
||||
Options,
|
||||
StatusSchema,
|
||||
UpdateStatusData,
|
||||
UpdateStatusResponse,
|
||||
UpdateStatusSchema,
|
||||
} from "@/lib/client";
|
||||
import { updateStatusMutation } from "@/lib/client/@tanstack/react-query.gen";
|
||||
import { notifications } from "@/lib/notifications";
|
||||
import { StatusSchema, UpdateStatusSchema } from "@/lib/client";
|
||||
|
||||
type StatusesContextState = {
|
||||
statuses: StatusSchema[];
|
||||
setStatuses: React.Dispatch<React.SetStateAction<StatusSchema[]>>;
|
||||
updateStatus: UseMutationResult<
|
||||
UpdateStatusResponse,
|
||||
AxiosError<HttpValidationError>,
|
||||
Options<UpdateStatusData>
|
||||
>;
|
||||
refetchStatuses: () => void;
|
||||
onCreateStatus: (name: string) => void;
|
||||
onUpdateStatus: (statusId: number, status: UpdateStatusSchema) => void;
|
||||
onDeleteStatus: (status: StatusSchema) => void;
|
||||
isEditorDrawerOpened: boolean;
|
||||
setIsEditorDrawerOpened: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
};
|
||||
|
||||
const StatusesContext = createContext<StatusesContextState | undefined>(
|
||||
@ -46,19 +28,6 @@ const useStatusesContextState = () => {
|
||||
} = useStatusesList({
|
||||
boardId: selectedBoard?.id,
|
||||
});
|
||||
const [isEditorDrawerOpened, setIsEditorDrawerOpened] =
|
||||
useState<boolean>(false);
|
||||
|
||||
const updateStatus = useMutation({
|
||||
...updateStatusMutation(),
|
||||
onError: error => {
|
||||
console.error(error);
|
||||
notifications.error({
|
||||
message: error.response?.data?.detail as string | undefined,
|
||||
});
|
||||
refetchStatuses();
|
||||
},
|
||||
});
|
||||
|
||||
const { onCreateStatus, onUpdateStatus, onDeleteStatus } =
|
||||
useStatusesOperations({
|
||||
@ -71,13 +40,10 @@ const useStatusesContextState = () => {
|
||||
return {
|
||||
statuses,
|
||||
setStatuses,
|
||||
updateStatus,
|
||||
refetchStatuses,
|
||||
onCreateStatus,
|
||||
onUpdateStatus,
|
||||
onDeleteStatus,
|
||||
isEditorDrawerOpened,
|
||||
setIsEditorDrawerOpened,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user