import calleeTypes from '@ringcentral-integration/commons/enums/calleeTypes';
import React, { Component } from 'react';
import BackButton from '../BackButton';
import BackHeader from '../BackHeader';
import ConfirmRemoveModal from './ConfirmRemoveModal';
import ParticipantItem from './ParticipantItem';
import i18n from './i18n';
import styles from './styles.scss';
type ParticipantsContainerProps = {
currentLocale: string;
showCallerIdName?: boolean;
removeFunc?: (...args: any[]) => any;
participants: object[];
onBackButtonClick?: (...args: any[]) => any;
formatPhone?: (...args: any[]) => any;
afterOnCancel?: (...args: any[]) => any;
afterOnRemoveBtnClick?: (...args: any[]) => any;
};
type ParticipantsContainerState = (() => {
detail: any;
showModal: boolean;
}) & { showModal: boolean; detail: null } & {
showModal: boolean;
detail: null;
};
class ParticipantsContainer extends Component<
ParticipantsContainerProps,
ParticipantsContainerState
> {
constructor(props: any) {
super(props);
this.state = {
showModal: false,
detail: null,
};
this.formatPrticipants(props);
this.onRemoveBtnClick = this.onRemoveBtnClick.bind(this);
this.onCancel = this.onCancel.bind(this);
this.onCancelNoAfter = this.onCancelNoAfter.bind(this);
}
formatPrticipants(props = this.props) {
const { participants, formatPhone } = props;
participants.forEach((participant) => {
// @ts-expect-error TS(2339): Property 'partyNumber' does not exist on type 'obj... Remove this comment to see the full error message
participant.partyNumber = formatPhone(participant.partyNumber);
});
}
onRemoveBtnClick(participant: any) {
this.setState(() => ({
detail: participant,
showModal: true,
}));
// @ts-expect-error TS(2722): Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
this.props.afterOnRemoveBtnClick();
}
onCancel() {
this.onCancelNoAfter();
// @ts-expect-error TS(2722): Cannot invoke an object which is possibly 'undefin... Remove this comment to see the full error message
this.props.afterOnCancel();
}
// onCancel without track
onCancelNoAfter() {
this.setState({
showModal: false,
detail: null,
});
}
// @ts-expect-error TS(4114): This member must have an 'override' modifier becau... Remove this comment to see the full error message
UNSAFE_componentWillReceiveProps(nextProps: any) {
this.formatPrticipants(nextProps);
if (
this.state.showModal &&
!nextProps.participants.find(
// @ts-expect-error TS(2531): Object is possibly 'null'.
(participant: any) => participant.id === this.state.detail.id,
)
) {
this.onCancelNoAfter();
}
}
// @ts-expect-error TS(4114): This member must have an 'override' modifier becau... Remove this comment to see the full error message
render() {
const {
showCallerIdName,
participants,
currentLocale,
removeFunc,
onBackButtonClick,
} = this.props;
const { detail, showModal } = this.state;
const backHeader = (