Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | 21x 21x 21x 21x | import { showMessage } from "@common/Toast";
import { customInstance } from "@services/api";
import { useMutation, useQueryClient } from "react-query";
import { useAppDispatch, useAppSelector } from "@redux/hooks";
import {
selectConversationTopic,
setConversationTopic,
} from "@redux/slices/conversations";
import { selectSelectedAccount } from "@redux/slices/auth/accounts";
import { PROVIDER_PANEL_KEYS } from "@features/Merchants/MerchantSidePanel/constants";
const markAsSolved = async ({
merchantId,
challengeId,
}: {
merchantId: number;
challengeId: number;
}) => {
return customInstance({
url: `/merchants/${merchantId}/underwriting-challenges/${challengeId}/status`,
method: "PATCH",
data: {
status: "closed",
type: "enhanced_due_diligence",
},
});
};
const closeThread = async ({
ownerAccID,
threadId,
}: {
ownerAccID: number;
threadId: number;
}) => {
return customInstance({
url: `/merchants/${ownerAccID}/threads/${threadId}/status`,
method: "PATCH",
data: {
statusName: "closed",
},
});
};
const useMarkAsSolved = ({
merchantId,
ownerAccID,
isRiskMonitor,
threadId,
challengeId,
}: {
ownerAccID: number;
threadId: number;
merchantId: number;
challengeId: number;
isRiskMonitor: boolean;
}) => {
const dispatch = useAppDispatch();
const { queryObject } = useAppSelector(selectConversationTopic);
const queryClient = useQueryClient();
const onSuccess = () => {
const paths = queryObject?.paths;
const pathIndex = paths?.findIndex((item) => item.isConversation);
const newPaths = [...paths];
if (pathIndex !== -1) {
newPaths[pathIndex] = {
...newPaths[pathIndex],
hideInputs: ["module", "subject", "message"],
};
} else {
newPaths.push({
hideInputs: ["module", "subject", "message"],
isConversation: true,
pathName: "",
avatars: [],
});
}
dispatch(
setConversationTopic({
queryObject: {
...queryObject,
paths,
},
}),
);
queryClient.invalidateQueries("fetch-activity-list");
queryClient.invalidateQueries(PROVIDER_PANEL_KEYS.GET_CHALLENGES);
};
const markAsSolvedMutation = useMutation(
() => {
if (isRiskMonitor) {
return closeThread({ ownerAccID, threadId });
} else {
return Promise.all([
markAsSolved({ merchantId, challengeId }),
closeThread({ ownerAccID, threadId }).catch((e) => {
console.log("The thread wasn't closed", e);
}),
]);
}
},
{
onError: (err: unknown) => {
const axiosError = err as any;
const errorMessage = axiosError?.response?.data?.message;
showMessage("Error", errorMessage || "Unable to change assignee");
},
onSuccess: () => {
onSuccess();
},
},
);
return markAsSolvedMutation;
};
export const useCloseThread = ({ threadId }: { threadId?: number }) => {
const selectedUser = useAppSelector(selectSelectedAccount);
const ownerAccID = selectedUser?.id || 0;
const closeThreadMutation = useMutation(
() => {
if (threadId === 0 || threadId === undefined) {
throw new Error(
"Cannot close thread: threadId is required and must not be 0.",
);
}
return closeThread({ ownerAccID, threadId });
},
{
onError: () => {
showMessage("Error", "Unable to close topic");
},
},
);
return closeThreadMutation;
};
export default useMarkAsSolved;
|