All files / src/features/GiveConversation types.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

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                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
import { SxProps } from "@mui/material";
import { Icon } from "@phosphor-icons/react";
import { Dispatch, MouseEventHandler, SetStateAction } from "react";
import { GiveConversationSectionType } from "./constants";
 
export type GiveConversationTabType = "team" | "merchant";
 
export type GiveConversationProps = {
  initialTab?: GiveConversationTabType;
  merchantData: {
    id: number;
    name?: string;
    imageURL?: string;
    pahInvitationStatus?: string;
    isOnboarding?: boolean;
    merchantType?: "submerchant" | "enterprise";
  };
  initialThreadID?: number; //for opening already existing thread by id IF passed down
  taskID?: number; //for opening task modal, opening/sending tasks related messages
  threadName?: string;
  riskTriggerID?: number; //for risk specific flow, opening/sending risk related messages
  factorID?: number; //for risk triggers
  isNewMessage?: boolean; // To open new message directly
  predefinedMessage?: string; //this can be used to pass down predefined message to the modal that will be prefilled in the input field
  escalationIDs?: number[];
  messageCount?: number; // unread message count
};
 
export type Attachment = {
  thumbFileUrl?: string;
  id: number;
  attTypeID: number;
  attTypeName: string;
  accID: number;
  fileURL: string;
  fileName: string;
  fileType: string;
  fileSize: number | null;
  fileMetadata: Record<string, unknown> | null; // Better than `any`
  s3ObjectKey: string;
  label: string; // or `string | null` if needed
  notes: string; // or `string | null`
  tag: string; // or `string | null`
  isUploaded: boolean;
  bankAccountID: number;
  legalPrincipalID: number;
  accMemberUserID: number;
  underwritingProfileID: number;
  merchantTaskID: number;
  matchReportID: number;
  conversationMessageID: number;
  userFullName: string;
  userEmail: string;
  createdAt: number; // UNIX timestamp
  updatedAt: number; // UNIX timestamp
  showProfileImage?: boolean; // Optional
};
 
export type MessagesChatTypes = {
  message: string;
  time: number;
  profileImage: string;
  isLoggedInUser?: boolean;
  isRead: boolean;
  fullName?: string;
  showProfileImageNextToMessage?: boolean;
  showProfileImageNextToFile?: boolean;
  files?: Attachment[];
  authorAccID: number;
  id: number;
  isKybAssignee?: boolean;
  isUwAssignee?: boolean;
  authorFirstName?: string;
  authorLastName?: string;
  authorEmail?: string;
};
 
export type MessagesArrayTypes = {
  date: number;
  isRead?: boolean;
  messages: MessagesChatTypes[];
};
export type ConversationCounterVariant = "unread" | "tagged" | "reply" | null;
 
export type User = {
  imageURL?: string;
  firstName?: string;
  lastName?: string;
  email: string;
};
export interface ChatTextAtomProps {
  isLoggedInUser?: boolean;
  mb?: string;
}
 
export type UploadedFile = {
  id: string;
  file: File;
};
export interface CustomHeaderRightIcon {
  Icons: Icon;
  handleClick: () => void;
  hidden?: boolean;
  disabled?: boolean;
  sx?: SxProps;
  dataTestId?: string;
}
 
export type Thread = {
  id?: number;
  name?: string;
  taskID?: number;
  predefinedMessage?: string;
  riskTriggerID?: number;
  count?: number;
  forceCreateNew?: boolean;
  factorID?: number;
  escalationIDs?: number[];
};
 
export type TThreadItem = {
  id: number;
  createdAt: number;
  updatedAt: number;
  title: string;
  typeName: GiveConversationTabType;
  ownerAccID: number;
  subjectAccID: number;
  authorAccID: number;
  lastAuthorFirstName: string;
  lastAuthorLastName: string;
  lastAuthorAvatarImageURL: string;
  lastAuthorEmail: string;
  secondLastAuthorFirstName: string;
  secondLastAuthorLastName: string;
  secondLastAuthorAvatarImageURL: string;
  secondLastAuthorEmail: string;
  lastMessageBody: string;
  taskID: number;
  didSubjectAccReply: boolean;
  isMentioned: boolean;
  unreadMessagesCount: number;
  lastMessageSentAt: number;
};
 
export interface ConversationMenuProps
  extends Pick<
    GiveConversationProps,
    | "initialThreadID"
    | "merchantData"
    | "taskID"
    | "threadName"
    | "predefinedMessage"
    | "riskTriggerID"
    | "factorID"
  > {
  disabled?: boolean;
  canSendTeamMessage?: boolean;
  maxImagesShown?: number;
  images?: string[];
  hideImages?: boolean;
  messageCount?: number;
  counterVariant?: ConversationCounterVariant;
  CustomFrontButton?: (props: {
    onClick: MouseEventHandler<HTMLButtonElement>;
    disabled?: boolean;
  }) => React.ReactElement;
  isRiskTrigger?: boolean;
}
 
export type FormValuesChatInput = {
  message: string;
  files: UploadedFile[];
};
 
export interface ConversationMessageAttachment {
  url: string;
  size: number;
}
 
export interface ConversationMessagePayload {
  body: string;
  mentions?: number[];
  attachments?: ConversationMessageAttachment[];
  attachmentOnly?: boolean;
}
 
export interface CreateThreadPayload {
  title?: string;
  isInternal?: boolean;
  subjectAccID: number;
  message: ConversationMessagePayload;
  escalationIDs?: number[];
  factorID?: number;
  taskID?: number;
  riskTriggerID?: number;
}
 
export interface ConversationStats {
  totalUnreadMessages: number;
  isMentioned: boolean;
  didMerchantReply: boolean;
  totalUnreadMessagesInternal: number;
  isMentionedInternal: boolean;
  didMerchantReplyInternal: boolean;
  totalUnreadMessagesExternal: number;
  isMentionedExternal: boolean;
  didMerchantReplyExternal: boolean;
}
 
export interface ConversationContextTypes
  extends Pick<GiveConversationProps, "merchantData" | "riskTriggerID"> {
  tab: GiveConversationTabType;
  setTab: Dispatch<SetStateAction<GiveConversationTabType>>;
  searchState: { searchValue: string; isOpened: boolean };
  setSearchState: Dispatch<
    SetStateAction<{ searchValue: string; isOpened: boolean }>
  >;
  showMentions: boolean;
  toggleMentions: () => void;
  openThread: (
    id: number,
    name: string,
    taskID?: number,
    count?: number,
  ) => void;
  clearThread: () => void;
  sectionInView: GiveConversationSectionType;
  setSectionInView: Dispatch<SetStateAction<GiveConversationSectionType>>;
 
  matchingMessagesCount?: number;
  currentMatchIndex: number;
  setCurrentMatchIndex: Dispatch<SetStateAction<number>>;
  navigateToNextMatch: () => void;
  navigateToPreviousMatch: () => void;
  currentThread?: Thread;
  setCurrentThread: Dispatch<SetStateAction<Thread | undefined>>;
  threads?: TThreadItem[];
  isThreadListLoading: boolean;
  isThreadMessagesLoading: boolean;
  fetchNextPageThreadList?: () => void;
  fetchNextPageMessages?: () => void;
  hasNextPageThreadList?: boolean;
  isFetchingNextPageThreadList?: boolean;
  merchantID: number;
  messages: MessagesArrayTypes[];
  isFetchingNextPageMessages?: boolean;
  hasNextPageMessages?: boolean;
  isBackgroundFetchingMessages?: boolean;
  stats?: ConversationStats;
  subject: string;
  setSubject: Dispatch<SetStateAction<string>>;
  //we should get unread count as well from BE in merchant endpoint, in that case we should pass it down for the tabs counters
}