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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | 118x 118x 118x 34x 34x 34x 34x 1x 1x 118x 678x 118x 577x 566x 566x 118x 12080x 12080x 12080x 12080x 12080x 12080x 12080x 12080x 2x 12080x 12080x 1x 12080x 18x 18x 9x 9x 12080x | import { useAppDispatch, useAppSelector } from "@redux/hooks";
import {
resetConversationsState,
selectConversation,
selectConversationTopic,
setConversationTopic,
setModalOpenConversation,
setReplies,
setThreads,
} from "@redux/slices/conversations";
import { customInstance } from "@services/api";
import { useState } from "react";
import { useQuery } from "react-query";
import { Replies, TQueryObject, TThreadInfo } from "../types";
import { MERCHANT_FILE_TEXT } from "@constants/stringConstants";
export const GlobalTopics: Record<string, string> = {
[MERCHANT_FILE_TEXT]: "merchant_info",
"Bank Accounts": "bank_account",
"Bank Account": "bank_account",
"Primary Account Holder": "primary_account_holder",
"Business Profile": "business_profile",
"Business Address": "business_address",
"Business Owners": "business_owners",
"PEP Check": "pep_check",
"OFAC Check": "ofac_check",
"Risk Activity": "risk_activity",
"Risk Monitor": "risk_monitor",
Underwriting: "underwriting",
Snapshots: "snapshots",
Documents: "documents",
"Merchant Fees": "merchant_fees",
"Merchant Agreement": "merchant_agreement",
"MATCH Check": "match_check",
"Enhanced Due Diligence": "enhanced_due_diligence",
"Merchant Onboarding": "merchant_onboarding",
"Merchant Specific": "merchant_specific",
// TODO: this might change when BE is ready
"Provider Info": "enterprise_info",
"Provider Fees": "enterprise_fees",
"Provider Agreement": "enterprise_agreement",
Sponsor: "sponsor",
General: "general",
KYB: "kyb",
};
const cache: { [key: string]: any } = {};
type Props = {
topicName?: string;
merchantId?: number;
};
export const getGlobalTopic = async ({ topicName, merchantId }: Props) => {
const basePath = merchantId
? `/merchants/${merchantId}/topics`
: "/topics";
const cacheKey = topicName
? `${basePath}?q=${encodeURIComponent(topicName)}`
: basePath;
Iif (cache[cacheKey]) {
return cache[cacheKey];
}
const response = await customInstance({
method: "GET",
url: cacheKey,
});
cache[cacheKey] = response;
return response;
};
export const getGlobalTopicLabel = (value: string): string | undefined =>
Object.keys(GlobalTopics).find((key) => GlobalTopics[key] === value);
export const useGetGlobalTopics = () => {
const dispatch = useAppDispatch();
const {
isOpenedFromSidePanel,
disableGlobalLauncher,
isOpen,
queryObject: {
name: topicName,
paths,
challengeId,
escalationIds,
factorId,
defaultMessage,
shouldHideMentionIcon,
},
} = useAppSelector(selectConversationTopic);
return useQuery(
["get-global-topics", topicName, GlobalTopics[topicName]],
async () => {
const data = await getGlobalTopic({ topicName: GlobalTopics[topicName] });
return data;
},
{
enabled:
!!topicName &&
isOpenedFromSidePanel &&
!disableGlobalLauncher &&
isOpen,
onSuccess: (data: any) => {
if (!data.data) return;
const { ID, DisplayName, Name } = data.data[0];
if (disableGlobalLauncher) return;
const name = getGlobalTopicLabel(Name) || DisplayName;
dispatch(
setConversationTopic({
isOpen: true,
isOpenedFromSidePanel: undefined,
queryObject: {
id: ID,
name,
paths: paths.length > 0 ? paths : [],
challengeId,
factorId,
escalationIds,
defaultMessage,
shouldHideMentionIcon,
},
}),
);
},
},
);
};
export const useConversationsModal = () => {
const {
isOpen: isThereOpenTopic,
queryObject: { id: topicId },
} = useAppSelector(selectConversationTopic);
const [isTopicModalOpen, setIsTopicModalOpen] = useState<boolean>(false);
const [isExpanded, setIsExpanded] = useState<boolean>(false);
const {
modal: { isOpen },
} = useAppSelector(selectConversation);
const updateThreads = (threads: Array<TThreadInfo>) => {
dispatch(setThreads(threads));
};
const openConversationHandler = ({
name,
paths,
id,
defaultMessage = "",
challengeId,
escalationIds,
factorId,
openThread,
forceTopicOpen,
isOpenedFromSidePanel,
shouldHideMentionIcon,
disableGlobalLauncher,
onMessageSubmit,
challengeID,
challengeTypeName,
closeOnPost,
originalThreadID,
}: {
name: string;
paths?: Array<{ avatars: string[]; pathName: string }>;
id?: number;
defaultMessage?: string;
challengeId?: number;
escalationIds?: number[];
factorId?: number;
openThread?: Replies;
forceTopicOpen?: boolean;
isOpenedFromSidePanel?: boolean;
shouldHideMentionIcon?: boolean;
disableGlobalLauncher?: boolean;
onMessageSubmit?: (...props: any[]) => void;
challengeID?: number;
challengeTypeName?: TQueryObject["challengeTypeName"];
closeOnPost?: boolean;
originalThreadID?: number | null;
}) => {
// first we dispatch a partial object
dispatch(
setConversationTopic({
isOpen: forceTopicOpen || isThereOpenTopic || false,
isOpenedFromSidePanel,
disableGlobalLauncher,
queryObject: {
id: topicId && topicId > 0 ? topicId : id,
name,
paths: paths || [],
defaultMessage,
challengeId,
challengeID,
challengeTypeName,
factorId,
escalationIds,
shouldHideMentionIcon,
onMessageSubmit,
closeOnPost,
originalThreadID,
},
}),
);
if (openThread)
dispatch(
setReplies({
...openThread,
}),
);
handleOpenConversationsModal(true);
};
const dispatch = useAppDispatch();
const handleOpenTopicModal = () => {
setIsTopicModalOpen((v) => !v);
};
const handleOpenConversationActivityThread = ({
isEnterprise,
}: {
isEnterprise: boolean;
}) => {
dispatch(
setConversationTopic({
isOpen: true,
isOpenedFromSidePanel: false,
numberOfUnreadMessages: 0,
queryObject: {
tabs: "Activity",
id: topicId,
name: `Notify ${isEnterprise ? "Provider" : "Merchant"} `,
paths: [
{
isConversation: true,
pathName: `Notify ${isEnterprise ? "Provider" : "Merchant"} `,
pathID: "new",
avatars: [],
hideInputs: ["none"],
},
],
},
}),
);
};
const handleExpandModal = () => {
setIsExpanded((v) => !v);
};
const handleOpenConversationsModal = (open?: boolean) => {
dispatch(setModalOpenConversation(!!open));
if (!open) {
if (isTopicModalOpen) handleOpenTopicModal();
dispatch(resetConversationsState());
}
};
return {
handleOpenTopicModal,
isOpen,
isTopicModalOpen,
handleOpenConversationsModal,
handleExpandModal,
openConversationHandler,
updateThreads,
isExpanded,
handleOpenConversationActivityThread,
};
};
|