Skip to content

Commit

Permalink
feat: add file upload limit alert
Browse files Browse the repository at this point in the history
  • Loading branch information
bang9 committed Sep 6, 2024
1 parent 4e7d98e commit c3ccd37
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
10 changes: 2 additions & 8 deletions src/components/BotMessageFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { BaseMessage, Feedback, FeedbackRating } from '@sendbird/chat/message';
import { useReducer } from 'react';

import FeedbackIconButton from '@uikit/ui/FeedbackIconButton';
import MessageFeedbackFailedModal from '@uikit/ui/MessageFeedbackFailedModal';
import MessageFeedbackModal from '@uikit/ui/MessageFeedbackModal';
import MobileFeedbackMenu from '@uikit/ui/MobileFeedbackMenu';

import { AlertModal } from './ui/AlertModal';
import { elementIds } from '../const';
import { useConstantState } from '../context/ConstantContext';
import { Icon } from '../foundation/components/Icon';
Expand Down Expand Up @@ -137,13 +137,7 @@ function BotMessageFeedback({ message }: { message: BaseMessage }) {
}
{
// error modal
!!state.errorText && (
<MessageFeedbackFailedModal
text={state.errorText}
rootElementId={elementIds.widgetWindow}
onCancel={() => setState({ errorText: '' })}
/>
)
!!state.errorText && <AlertModal message={state.errorText} onClose={() => setState({ errorText: '' })} />
}
</>
);
Expand Down
8 changes: 7 additions & 1 deletion src/components/chat/ui/ChatInput.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { css } from '@linaria/core';
import { useRef } from 'react';
import { useRef, useState } from 'react';

import useSendbirdStateContext from '@uikit/hooks/useSendbirdStateContext';
import MessageInputWrapperView from '@uikit/modules/GroupChannel/components/MessageInputWrapper/MessageInputWrapperView';

import { themedColors } from '../../../foundation/colors/css';
import { useBlockWhileBotResponding } from '../../../hooks/useBlockWhileBotResponding';
import { isIOSMobile } from '../../../utils';
import { AlertModal } from '../../ui/AlertModal';
import { useChatContext } from '../context/ChatProvider';

// TODO: Remove UIKit
export const ChatInput = () => {
const { channel, botUser, dataSource, handlers } = useChatContext();

const ref = useRef<HTMLDivElement>(null);
const [limitError, setLimitError] = useState(false);

const { config } = useSendbirdStateContext();
const isMessageInputDisabled = useBlockWhileBotResponding({
Expand Down Expand Up @@ -41,7 +43,11 @@ export const ChatInput = () => {
handlers.onAfterSendMessage();
return message;
}}
onFileLimitError={() => setLimitError(true)}
/>
{limitError && (
<AlertModal message={"You can't upload more than one image"} onClose={() => setLimitError(false)} />
)}
</div>
);
};
Expand Down
14 changes: 3 additions & 11 deletions src/components/messages/FormMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import styled from 'styled-components';

import { isFormVersionCompatible } from '@uikit/modules/GroupChannel/context/utils';
import Button from '@uikit/ui/Button';
import MessageFeedbackFailedModal from '@uikit/ui/MessageFeedbackFailedModal';

import FallbackUserMessage from './FallbackUserMessage';
import { elementIds, widgetStringSet } from '../../const';
import { widgetStringSet } from '../../const';
import { useConstantState } from '../../context/ConstantContext';
import { Label } from '../../foundation/components/Label';
import FormInput from '../FormInput';
import { AlertModal } from '../ui/AlertModal';

interface Props {
message: BaseMessage;
Expand Down Expand Up @@ -196,15 +196,7 @@ export default function FormMessage(props: Props) {
<ButtonText disabled={isButtonDisabled}>{isSubmitted ? 'Submitted successfully' : 'Submit'}</ButtonText>
</Label>
</SubmitButton>
{submitFailed && (
<MessageFeedbackFailedModal
text={'Submit failed.'}
rootElementId={elementIds.widgetWindow}
onCancel={() => {
setSubmitFailed(false);
}}
/>
)}
{submitFailed && <AlertModal message={'Submit failed.'} onClose={() => setSubmitFailed(false)} />}
</Root>
);
}
13 changes: 13 additions & 0 deletions src/components/ui/AlertModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import MessageFeedbackFailedModal from '@uikit/ui/MessageFeedbackFailedModal';

import { elementIds } from '../../const';

interface Props {
message: string;
onClose: () => void;
}

// TODO: Remove UIKit
export const AlertModal = ({ message, onClose }: Props) => {
return <MessageFeedbackFailedModal text={message} rootElementId={elementIds.widgetWindow} onCancel={onClose} />;
};

0 comments on commit c3ccd37

Please sign in to comment.