feat: deal updating on the server
This commit is contained in:
@ -3,11 +3,14 @@
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import StatusColumnsDnd from "@/app/deals/components/StatusColumnsDnd/StatusColumnsDnd";
|
||||
import { useStatusesContext } from "@/app/deals/contexts/StatusesContext";
|
||||
import { updateStatusMutation } from "@/client/@tanstack/react-query.gen";
|
||||
import {
|
||||
updateDealMutation,
|
||||
updateStatusMutation,
|
||||
} from "@/client/@tanstack/react-query.gen";
|
||||
import { notifications } from "@/lib/notifications";
|
||||
|
||||
const StatusColumns = () => {
|
||||
const { refetchStatuses } = useStatusesContext();
|
||||
const { refetchStatuses, refetchDeals } = useStatusesContext();
|
||||
|
||||
const updateStatus = useMutation({
|
||||
...updateStatusMutation(),
|
||||
@ -20,30 +23,36 @@ const StatusColumns = () => {
|
||||
},
|
||||
});
|
||||
|
||||
const updateDeals = useMutation({
|
||||
...updateDealMutation(),
|
||||
onError: error => {
|
||||
console.error(error);
|
||||
notifications.error({
|
||||
message: error.response?.data?.detail as string | undefined,
|
||||
});
|
||||
refetchDeals();
|
||||
},
|
||||
});
|
||||
|
||||
const onDealDragEnd = (
|
||||
dealId: number,
|
||||
statusId: number,
|
||||
lexorank?: string
|
||||
) => {
|
||||
// Send request to server
|
||||
console.log(
|
||||
"onDealDragEnd. dealId =",
|
||||
dealId,
|
||||
", statusId =",
|
||||
statusId,
|
||||
", lexorank =",
|
||||
lexorank
|
||||
);
|
||||
updateDeals.mutate({
|
||||
path: {
|
||||
dealId,
|
||||
},
|
||||
body: {
|
||||
deal: {
|
||||
statusId,
|
||||
lexorank,
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const onStatusDragEnd = (statusId: number, lexorank: string) => {
|
||||
console.log(
|
||||
"onStatusDragEnd, statusId:",
|
||||
statusId,
|
||||
", lexo:",
|
||||
lexorank
|
||||
);
|
||||
|
||||
updateStatus.mutate({
|
||||
path: {
|
||||
statusId,
|
||||
|
||||
@ -12,6 +12,7 @@ type StatusesContextState = {
|
||||
deals: DealSchema[];
|
||||
setDeals: React.Dispatch<React.SetStateAction<DealSchema[]>>;
|
||||
refetchStatuses: () => void;
|
||||
refetchDeals: () => void;
|
||||
};
|
||||
|
||||
const StatusesContext = createContext<StatusesContextState | undefined>(
|
||||
@ -20,13 +21,22 @@ const StatusesContext = createContext<StatusesContextState | undefined>(
|
||||
|
||||
const useStatusesContextState = () => {
|
||||
const { selectedBoard } = useBoardsContext();
|
||||
const { statuses, setStatuses, refetch } = useStatusesList({
|
||||
const {
|
||||
statuses,
|
||||
setStatuses,
|
||||
refetch: refetchStatuses,
|
||||
} = useStatusesList({
|
||||
boardId: selectedBoard?.id,
|
||||
});
|
||||
const { deals, setDeals } = useDealsList({ boardId: selectedBoard?.id });
|
||||
|
||||
const {
|
||||
deals,
|
||||
setDeals,
|
||||
refetch: refetchDeals,
|
||||
} = useDealsList({ boardId: selectedBoard?.id });
|
||||
|
||||
useEffect(() => {
|
||||
refetch();
|
||||
refetchStatuses();
|
||||
}, [selectedBoard]);
|
||||
|
||||
return {
|
||||
@ -34,7 +44,8 @@ const useStatusesContextState = () => {
|
||||
setStatuses,
|
||||
deals,
|
||||
setDeals,
|
||||
refetchStatuses: refetch,
|
||||
refetchStatuses,
|
||||
refetchDeals,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user