import { format } from '@ringcentral-integration/utils';
import {
RcAvatar,
RcButton,
RcDialogActions,
RcDrawer,
RcIconButton,
RcLink,
RcList,
RcListItem,
RcListItemAvatar,
RcListItemSecondaryAction,
RcListItemText,
RcTypography,
spacing,
styled,
useAvatarShortName,
} from '@ringcentral/juno';
import { RemoveMemberBorder } from '@ringcentral/juno-icon';
import React, { useState, type FunctionComponent } from 'react';
import { ConferenceCallParticipantsProps } from './ConferenceCallParticipants.interface';
import i18n from './i18n';
const InnerContainer = styled.div`
display: grid;
gap: ${spacing(3)};
padding: ${spacing(0, 4)};
margin: ${spacing(4, 0)};
${RcDialogActions} {
margin-top: ${spacing(2)};
padding: 0;
}
${RcList} {
overflow: hidden;
${RcListItem} {
padding-left: 0;
padding-right: 0;
}
}
`;
export const ConferenceCallParticipants: FunctionComponent<
ConferenceCallParticipantsProps
> = ({
isOpen,
currentLocale,
participants = [],
toggleConference,
currentTelephonySessionId,
getContactNameInfo,
renderAvatar,
onRemoveParticipant,
clickRemoveParticipantTrack,
openEntityDetailLink,
}) => {
const [removeData, setRemoveData] = useState<{
removedPartyId: string;
name: string;
} | void>();
const closeRemoveModal = () => {
setRemoveData(undefined);
};
const length = participants.length;
const removedModalOpen = !!removeData && isOpen;
return (
<>
{i18n.getString('removeTitle', currentLocale)}
{format(i18n.getString('removeDescription', currentLocale), {
name: removeData?.name,
})}
{
await onRemoveParticipant(
currentTelephonySessionId,
removeData?.removedPartyId!,
);
closeRemoveModal();
}}
>
{i18n.getString('confirmButtonText', currentLocale)}
{i18n.getString('cancelButtonText', currentLocale)}
toggleConference(false)}
>
{`${i18n.getString('participants', currentLocale)} (${length})`}
{participants.map(
({
telephonySessionId,
sessionId,
partyId,
isHost,
sessionName,
}) => {
const {
logName = sessionName,
entityDetailLink,
displayEntity,
entityType,
entityDetailLinkId,
} = getContactNameInfo(sessionId, isHost);
const ConferenceAvatarIcon = renderAvatar ? (
renderAvatar({ displayEntity, entityType, name: logName })
) : (
);
const displayName = isHost
? `${logName} ${i18n.getString('host', currentLocale)}`
: logName;
return (
{ConferenceAvatarIcon}
{
return openEntityDetailLink
? openEntityDetailLink(entityDetailLinkId)
: window.open(entityDetailLink, '_blank');
}}
>
{displayName}
) : (
displayName
)
}
/>
{!isHost && (
{
clickRemoveParticipantTrack?.();
setRemoveData({
removedPartyId: partyId,
name: logName,
});
}}
/>
)}
);
},
)}
>
);
};
export const ConferenceAvatar: FunctionComponent<{ name: string }> = ({
name,
}) => {
const [firstName, lastName] = name?.split(/\s+/) || [];
const presentAvatarName = useAvatarShortName({
firstName,
lastName,
});
return (
{presentAvatarName}
);
};