Skip to content

Commit

Permalink
reuse modal to implement long message error modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Akshun-01 committed Jan 19, 2024
1 parent fed04d5 commit 42e8a29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 51 deletions.
32 changes: 25 additions & 7 deletions packages/react/src/components/ChatInput/ChatInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { CommandsList } from '../CommandList';
import { ActionButton } from '../ActionButton';
import useComponentOverrides from '../../theme/useComponentOverrides';
import { useToastBarDispatch } from '../../hooks/useToastBarDispatch';
import ErrorModal from './ErrorModal';
import { Modal } from '../Modal';

const editingMessageCss = css`
background-color: #fff8e0;
Expand Down Expand Up @@ -85,7 +85,7 @@ const ChatInput = ({ scrollToBottom }) => {
const setIsLoginModalOpen = loginModalStore(
(state) => state.setIsLoginModalOpen
);
const [errorModal, setErrorModal] = useState("Message too long");
const [errorModal, setErrorModal] = useState(false);
const [isAttachmentMode, setIsAttachmentMode] = useState(false);


Expand Down Expand Up @@ -121,16 +121,17 @@ const ChatInput = ({ scrollToBottom }) => {
const openLoginModal = () => {
setIsLoginModalOpen(true);
};
const openErrorModal = (errorMessage) => {
setErrorModal(errorMessage);
const openErrorModal = () => {
setErrorModal(true);
};
const closeErrorModal = () => {
setErrorModal(null);
setErrorModal(false);
};

useEffect(() => {
if(isAttachmentMode) sendMessage();
}, [isAttachmentMode]);

const handleConvertToAttachment = () => {
setIsAttachmentMode(true);
closeErrorModal();
Expand Down Expand Up @@ -178,7 +179,7 @@ const ChatInput = ({ scrollToBottom }) => {

const msgMaxLength = 500;
if (message.length > msgMaxLength) {
openErrorModal('Message is too long!');
openErrorModal();
return;
}

Expand Down Expand Up @@ -530,7 +531,24 @@ const ChatInput = ({ scrollToBottom }) => {
)}
</Box>
{errorModal && (
<ErrorModal message={errorModal} onClose={closeErrorModal} onConfirm={handleConvertToAttachment} />
<Modal css={css`padding: 1em;`}>
<Modal.Header>
<Modal.Title>
<Icon name="report" size="1.25rem" />
Message Too Long!
</Modal.Title>
<Modal.Close onClick={closeErrorModal} />
</Modal.Header>
<Modal.Content css={css`margin: 1em;`}> Send it as attachment instead? </Modal.Content>
<Modal.Footer>
<Button color="secondary" onClick={closeErrorModal}>
Cancel
</Button>
<Button onClick={handleConvertToAttachment} color="primary">
Ok
</Button>
</Modal.Footer>
</Modal>
)}
</Box>
);
Expand Down
44 changes: 0 additions & 44 deletions packages/react/src/components/ChatInput/ErrorModal.js

This file was deleted.

0 comments on commit 42e8a29

Please sign in to comment.