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 | import { useAppSelector } from "@redux/hooks";
import { selectConversationTopic } from "@redux/slices/conversations";
import { customInstance } from "@services/api";
import { useMemo } from "react";
import { useQuery } from "react-query";
import { ApiResponse } from "../Modal/types";
export default function useGetActivityList({
merchantId,
}: {
merchantId?: number;
}) {
const { queryObject } = useAppSelector(selectConversationTopic);
const selectedThreadPathConversation = queryObject?.paths?.find(
(item) => item?.isConversation,
);
const { data, ...rest } = useQuery(
["fetch-activity-list", queryObject?.id, merchantId, queryObject?.paths],
async () => {
const response: ApiResponse = await customInstance({
url: `/merchants/${merchantId}/topics/${queryObject?.id}/threads?sort=createdAt`,
});
return response;
},
{
enabled: !!queryObject?.id && !!merchantId,
refetchOnMount: true,
},
);
const selectedThread = useMemo(() => {
const found = data?.data?.find(
(item) => item.id === selectedThreadPathConversation?.pathID,
);
return found;
}, [selectedThreadPathConversation?.pathID, data?.data]);
return {
data,
selectedThread,
selectedThreadPathConversation,
...rest,
};
}
|