@sendbird/uikit-react
Version:
Sendbird UIKit for React: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.
76 lines (73 loc) • 4.43 kB
JavaScript
import React__default from 'react';
import { n as noop } from '../../chunks/bundle-DX6fRIJl.js';
import { a as Modal } from '../../chunks/bundle-C4anRHWY.js';
import { u as useLocalization } from '../../chunks/bundle-Cdqsdoa8.js';
import { u as useMediaQueryContext } from '../../chunks/bundle-C2ARCMSL.js';
import TextButton from '../../ui/TextButton.js';
import { L as Label, a as LabelColors, c as LabelTypography } from '../../chunks/bundle-Cdplrrlw.js';
import { y as isDefaultChannelName } from '../../chunks/bundle-BZSLsKkw.js';
import { u as useChannelSettings } from '../../chunks/bundle-5y4qYKhm.js';
import { u as useSendbird } from '../../chunks/bundle-4clodtJA.js';
import '../../chunks/bundle-Bpofr334.js';
import 'react-dom';
import '../../ui/IconButton.js';
import '../../ui/Button.js';
import '../../ui/Icon.js';
import '../../chunks/bundle-LLA95Pqf.js';
import '../../chunks/bundle-oM0Fxt9G.js';
import '../../chunks/bundle-DmnXeBdU.js';
import '../../chunks/bundle-C1npFBfj.js';
import '@sendbird/chat/groupChannel';
import '../../utils/message/getOutgoingMessageState.js';
import '../../chunks/bundle-CglqREVl.js';
import '../../chunks/bundle-lqEjT2ED.js';
import '../../chunks/bundle-BqKoZDqX.js';
import '../../chunks/bundle-JhKiWlXT.js';
import '../../chunks/bundle-B56O1y8C.js';
import '../../chunks/bundle-DpOgiF9r.js';
import '../../chunks/bundle-B5LKcMN_.js';
import '@sendbird/chat';
import '@sendbird/chat/openChannel';
var LeaveChannel = function (props) {
var _a, _b;
var _c = props.onSubmit, onSubmit = _c === void 0 ? noop : _c, _d = props.onCancel, onCancel = _d === void 0 ? noop : _d;
var _e = useChannelSettings().state, channel = _e.channel, onLeaveChannel = _e.onLeaveChannel;
var stringSet = useLocalization().stringSet;
var state = useSendbird().state;
var logger = (_a = state === null || state === void 0 ? void 0 : state.config) === null || _a === void 0 ? void 0 : _a.logger;
var isOnline = (_b = state === null || state === void 0 ? void 0 : state.config) === null || _b === void 0 ? void 0 : _b.isOnline;
var isMobile = useMediaQueryContext().isMobile;
var getChannelName = function (channel) {
if (!(channel === null || channel === void 0 ? void 0 : channel.name) && !(channel === null || channel === void 0 ? void 0 : channel.members))
return stringSet.NO_TITLE;
if (isDefaultChannelName(channel))
return ((channel === null || channel === void 0 ? void 0 : channel.members) || []).map(function (member) { return member.nickname || stringSet.NO_NAME; }).join(', ');
return channel.name;
};
if (isMobile) {
return (React__default.createElement(Modal, { className: "sendbird-channel-settings__leave--mobile", titleText: getChannelName(channel), hideFooter: true, isCloseOnClickOutside: true, onCancel: onCancel },
React__default.createElement(TextButton, { onClick: function () {
logger.info('ChannelSettings: Leaving channel', channel);
channel === null || channel === void 0 ? void 0 : channel.leave().then(function () {
logger.info('ChannelSettings: Leaving channel successful!', channel);
onLeaveChannel === null || onLeaveChannel === void 0 ? void 0 : onLeaveChannel();
});
}, className: "sendbird-channel-settings__leave-label--mobile" },
React__default.createElement(Label, { type: LabelTypography.SUBTITLE_1, color: LabelColors.ONBACKGROUND_1 }, stringSet.CHANNEL_PREVIEW_MOBILE_LEAVE))));
}
return (React__default.createElement(Modal, { isFullScreenOnMobile: true, disabled: !isOnline, onCancel: onCancel, onSubmit: function () {
logger.info('ChannelSettings: Leaving channel', channel);
channel === null || channel === void 0 ? void 0 : channel.leave().then(function () {
logger.info('ChannelSettings: Leaving channel successful!', channel);
// is for backward compactability
if (onLeaveChannel) {
onLeaveChannel();
}
else {
onSubmit();
}
});
}, submitText: stringSet.MODAL__LEAVE_CHANNEL__FOOTER, titleText: stringSet.MODAL__LEAVE_CHANNEL__TITLE }));
};
export { LeaveChannel as default };
//# sourceMappingURL=LeaveChannel.js.map