UNPKG

@sendbird/uikit-react

Version:

Sendbird UIKit for React: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.

97 lines (94 loc) 6.78 kB
import React__default, { useRef, useState, useContext } from 'react'; import { L as LocalizationContext } from '../../chunks/bundle-Del33VzI.js'; import { p as pubSubTopics } from '../../chunks/bundle-BOykFtQ3.js'; import { M as Modal } from '../../chunks/bundle-CtQtfJlT.js'; import Input, { InputLabel } from '../../ui/Input.js'; import { A as Avatar } from '../../chunks/bundle-CAEBoiEz.js'; import '../../chunks/bundle-yl5d1NoZ.js'; import { L as Label, a as LabelTypography, b as LabelColors } from '../../chunks/bundle-viBng0Kh.js'; import { ButtonTypes } from '../../ui/Button.js'; import TextButton from '../../ui/TextButton.js'; import ChannelAvatar from '../../ui/OpenChannelAvatar.js'; import { useOpenChannelSettingsContext } from '../context.js'; import { u as useSendbird } from '../../chunks/bundle-i_3w58Zd.js'; import '../../chunks/bundle-C1dqPUnT.js'; import '../../chunks/bundle-BZGITC2g.js'; import 'react-dom'; import '../../chunks/bundle-MlG9piGf.js'; import '../../chunks/bundle-DBhJIxHw.js'; import '../../ui/IconButton.js'; import '../../ui/Icon.js'; import '../../chunks/bundle-DGh2T5IL.js'; import '../../ui/ImageRenderer.js'; import '../../chunks/bundle-Dl_v8XoN.js'; import '../../chunks/bundle-Bokm7tQ9.js'; import '../../chunks/bundle-B2BBbSEN.js'; import '@sendbird/chat/openChannel'; import '../../chunks/bundle-B0s_McF0.js'; import '../../chunks/bundle-BUYU9H94.js'; import '../../chunks/bundle-CqLLOVG5.js'; import '@sendbird/chat'; import '@sendbird/chat/groupChannel'; var EditDetails = function (props) { var onCancel = props.onCancel; var state = useSendbird().state; var _a = state.config, logger = _a.logger, theme = _a.theme, pubSub = _a.pubSub; var _b = useOpenChannelSettingsContext(), channel = _b.channel, onBeforeUpdateChannel = _b.onBeforeUpdateChannel, onChannelModified = _b.onChannelModified, setChannel = _b.setChannel; var inputRef = useRef(null); var formRef = useRef(null); var hiddenInputRef = useRef(null); var _c = useState(null), currentImg = _c[0], setCurrentImg = _c[1]; var _d = useState(null), newFile = _d[0], setNewFile = _d[1]; var stringSet = useContext(LocalizationContext).stringSet; var title = channel === null || channel === void 0 ? void 0 : channel.name; return (React__default.createElement(Modal, { isFullScreenOnMobile: true, titleText: stringSet.MODAL__CHANNEL_INFORMATION__TITLE, submitText: stringSet.BUTTON__SAVE, onCancel: onCancel, onSubmit: function () { var _a, _b, _c, _d, _e; if (title !== '' && !((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value)) { if ((_b = formRef.current) === null || _b === void 0 ? void 0 : _b.reportValidity) { // might not work in explorer formRef.current.reportValidity(); } return; } var currentTitle = (_d = (_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : ''; var currentImg = newFile; logger.info('ChannelSettings: Channel information being updated'); var params = onBeforeUpdateChannel ? onBeforeUpdateChannel(currentTitle, currentImg, (_e = channel === null || channel === void 0 ? void 0 : channel.data) !== null && _e !== void 0 ? _e : '') : { name: currentTitle, coverUrlOrImage: currentImg !== null && currentImg !== void 0 ? currentImg : undefined, data: channel === null || channel === void 0 ? void 0 : channel.data, }; logger.info('ChannelSettings: Updating channel information', params); channel === null || channel === void 0 ? void 0 : channel.updateChannel(params).then(function (updatedChannel) { logger.info('ChannelSettings: Channel information update succeeded', updatedChannel); onChannelModified === null || onChannelModified === void 0 ? void 0 : onChannelModified(updatedChannel); setChannel === null || setChannel === void 0 ? void 0 : setChannel(updatedChannel); pubSub === null || pubSub === void 0 ? void 0 : pubSub.publish(pubSubTopics.UPDATE_OPEN_CHANNEL, updatedChannel); }).catch(function (error) { logger.error('ChannelSettings: Channel infomation update failed', error); setChannel === null || setChannel === void 0 ? void 0 : setChannel(null); }); onCancel(); }, type: ButtonTypes.PRIMARY }, React__default.createElement("form", { className: "channel-profile-form", ref: formRef, onSubmit: function (e) { e.preventDefault(); } }, React__default.createElement("div", { className: "channel-profile-form__img-section" }, React__default.createElement(InputLabel, null, stringSet.MODAL__CHANNEL_INFORMATION__CHANNEL_IMAGE), React__default.createElement("div", { className: "channel-profile-form__avatar" }, currentImg ? (React__default.createElement(Avatar, { height: "80px", width: "80px", src: currentImg })) : (React__default.createElement(ChannelAvatar, { height: 80, width: 80, channel: channel, theme: theme }))), React__default.createElement("input", { ref: hiddenInputRef, type: "file", accept: "image/gif, image/jpeg, image/png", style: { display: 'none' }, onChange: function (e) { if (e.target.files) { setCurrentImg(URL.createObjectURL(e.target.files[0])); setNewFile(e.target.files[0]); } if (hiddenInputRef.current) hiddenInputRef.current.value = ''; } }), React__default.createElement(TextButton, { className: "channel-profile-form__avatar-button", onClick: function () { var _a; return (_a = hiddenInputRef.current) === null || _a === void 0 ? void 0 : _a.click(); }, disableUnderline: true }, React__default.createElement(Label, { type: LabelTypography.BUTTON_1, color: LabelColors.PRIMARY }, stringSet.MODAL__CHANNEL_INFORMATION__UPLOAD))), React__default.createElement("div", { className: "channel-profile-form__name-section" }, React__default.createElement(InputLabel, null, stringSet.MODAL__CHANNEL_INFORMATION__CHANNEL_NAME), React__default.createElement(Input, { required: title !== '', name: "channel-profile-form__name", ref: inputRef, value: title, placeHolder: stringSet.MODAL__CHANNEL_INFORMATION__INPUT__PLACE_HOLDER }))))); }; export { EditDetails as default }; //# sourceMappingURL=EditDetailsModal.js.map