From 7b04b42964457939023c37b9cb1a076a76e842e4 Mon Sep 17 00:00:00 2001 From: Pavel Torbeev Date: Sun, 27 Aug 2023 04:11:28 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D1=83=20=D1=84=D0=BE?= =?UTF-8?q?=D1=82=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/deck/createAnswer.ts | 26 ++++++- src/api/deck/types.ts | 20 ++--- src/assets/icons/upload.svg | 5 ++ .../UploadButton/UploadButton.module.scss | 17 +++++ src/components/UploadButton/UploadButton.tsx | 35 +++++++++ src/components/UploadButton/index.ts | 1 + src/pages/chat/ChatPage.tsx | 12 ++- .../components/ChatForm/QuestionFactory.tsx | 58 ++++++++++++++- ...hatFormMultipleDateDescription.module.scss | 4 + .../ChatFormMultipleDateDescription.tsx | 6 +- .../ChatFormMultipleLinkDescription.tsx | 4 +- .../ChatFormMultiplePhoto.tsx | 51 +++++++++++++ .../components/ChatFormMultiplePhoto/index.ts | 1 + .../ChatFormMultiplePhotoDescription.tsx | 73 +++++++++++++++++++ .../ChatFormMultiplePhotoDescription/index.ts | 1 + .../ChatFormPhotoDescription.module.scss | 40 ++++++++++ .../ChatFormPhotoDescription.tsx | 52 +++++++++++++ .../ChatFormPhotoDescription/index.ts | 1 + .../chat/utils/generateAnswerFromData.ts | 6 ++ .../utils/generateFieldsForFileAnswers.ts | 20 +++++ .../chat/utils/generateTextFromAnswer.ts | 13 +++- 21 files changed, 426 insertions(+), 20 deletions(-) create mode 100644 src/assets/icons/upload.svg create mode 100644 src/components/UploadButton/UploadButton.module.scss create mode 100644 src/components/UploadButton/UploadButton.tsx create mode 100644 src/components/UploadButton/index.ts create mode 100644 src/pages/chat/components/ChatForm/components/ChatFormMultiplePhoto/ChatFormMultiplePhoto.tsx create mode 100644 src/pages/chat/components/ChatForm/components/ChatFormMultiplePhoto/index.ts create mode 100644 src/pages/chat/components/ChatForm/components/ChatFormMultiplePhotoDescription/ChatFormMultiplePhotoDescription.tsx create mode 100644 src/pages/chat/components/ChatForm/components/ChatFormMultiplePhotoDescription/index.ts create mode 100644 src/pages/chat/components/ChatForm/components/ChatFormPhotoDescription/ChatFormPhotoDescription.module.scss create mode 100644 src/pages/chat/components/ChatForm/components/ChatFormPhotoDescription/ChatFormPhotoDescription.tsx create mode 100644 src/pages/chat/components/ChatForm/components/ChatFormPhotoDescription/index.ts create mode 100644 src/pages/chat/utils/generateFieldsForFileAnswers.ts diff --git a/src/api/deck/createAnswer.ts b/src/api/deck/createAnswer.ts index 1eec40c..8d5340e 100644 --- a/src/api/deck/createAnswer.ts +++ b/src/api/deck/createAnswer.ts @@ -9,6 +9,8 @@ export type CreateAnswerDTO = { deckId: number; questionId: number; answer: any; + isFile?: boolean; + file?: File; }; export type CreateAnswerResponse = Answer; @@ -18,7 +20,29 @@ export const createAnswer = (data: CreateAnswerDTO): Promise + + + + \ No newline at end of file diff --git a/src/components/UploadButton/UploadButton.module.scss b/src/components/UploadButton/UploadButton.module.scss new file mode 100644 index 0000000..8bc57f5 --- /dev/null +++ b/src/components/UploadButton/UploadButton.module.scss @@ -0,0 +1,17 @@ +@import 'src/app/styles/vars'; + +.UploadButton { + width: 100%; + height: 80px !important; + //background-color: $color-on-surface-dark-400; +} + +.UploadButton__icon { + width: 24px; + height: 24px; + color: white; +} + +.UploadButton__input { + display: none; +} \ No newline at end of file diff --git a/src/components/UploadButton/UploadButton.tsx b/src/components/UploadButton/UploadButton.tsx new file mode 100644 index 0000000..425e969 --- /dev/null +++ b/src/components/UploadButton/UploadButton.tsx @@ -0,0 +1,35 @@ +import clsx from 'clsx'; +import s from './UploadButton.module.scss'; +import {ReactFCC} from '../../utils/ReactFCC'; +import {Button, ButtonVariant} from '../Button'; +import { ReactComponent as UploadIcon } from '../../assets/icons/upload.svg'; +import {useId} from 'react'; + +export interface UploadButtonProps { + /** + * Дополнительный css-класс + */ + className?: string; + onChange?: (e: any) => void; + multiple?: boolean; +} + +export const UploadButton: ReactFCC = (props) => { + const {className, onChange, multiple} = props; + + const id = useId(); + + return ( + + ); +}; + diff --git a/src/components/UploadButton/index.ts b/src/components/UploadButton/index.ts new file mode 100644 index 0000000..52f301f --- /dev/null +++ b/src/components/UploadButton/index.ts @@ -0,0 +1 @@ +export * from './UploadButton'; \ No newline at end of file diff --git a/src/pages/chat/ChatPage.tsx b/src/pages/chat/ChatPage.tsx index e993349..6f34e7f 100644 --- a/src/pages/chat/ChatPage.tsx +++ b/src/pages/chat/ChatPage.tsx @@ -18,6 +18,7 @@ import {generateTextFromAnswer} from './utils/generateTextFromAnswer'; import {Button, ButtonVariant} from '../../components/Button'; import {useNavigate} from 'react-router-dom'; import {DECK_PAGE_PARAM, DECK_PAGE_ROUTE} from '../../app/routes'; +import {generateFieldsForFileAnswers} from './utils/generateFieldsForFileAnswers'; export interface ChatPageProps { /** @@ -28,8 +29,8 @@ export interface ChatPageProps { const QUESTION_POLLING_MS = 1000; -const DEFAULT_DECK_ID = 0; -const DEFAULT_QUESTION_ID = 0; +const DEFAULT_DECK_ID = 80; +const DEFAULT_QUESTION_ID = 25; export const ChatPage: ReactFCC = (props) => { const {className} = props; @@ -127,16 +128,19 @@ export const ChatPage: ReactFCC = (props) => { timeout.clear(); const answerValue = generateAnswerFromData(question, data); + const additionalFields = generateFieldsForFileAnswers(question, data); const answer = await createAnswer({ deckId, questionId, - answer: answerValue + answer: answerValue, + ...additionalFields, + isFile: !!additionalFields && Object.keys(additionalFields).length !== 0 }); pushHistory({ type: ChatItemType.send, - text: generateTextFromAnswer(question.type, answer) + text: generateTextFromAnswer(question.type, answer, additionalFields) }); if (question.next_id) { diff --git a/src/pages/chat/components/ChatForm/QuestionFactory.tsx b/src/pages/chat/components/ChatForm/QuestionFactory.tsx index c0490b8..aebba77 100644 --- a/src/pages/chat/components/ChatForm/QuestionFactory.tsx +++ b/src/pages/chat/components/ChatForm/QuestionFactory.tsx @@ -1,12 +1,15 @@ import {ReactFCC} from '../../../../utils/ReactFCC'; -import {EntityType, Hint, Question} from '../../../../api/deck'; +import {EntityType, Question} from '../../../../api/deck'; import {Form} from '../../../../components/Form'; -import {ChatFormText} from './components/ChatFormText/ChatFormText'; +import {ChatFormText} from './components/ChatFormText'; import {ChatFormSelect} from './components/ChatFormSelect'; import {ChatFormMultipleRange, RangeType} from './components/ChatFormMultipleRange'; import {ChatFormMultipleDateDescription} from './components/ChatFormMultipleDateDescription'; import {ChatFormRange} from './components/ChatFormRange'; import {ChatFormMultipleLinkDescription} from './components/ChatFormMultipleLinkDescription'; +import {ChatFormPhotoDescription} from './components/ChatFormPhotoDescription'; +import {ChatFormMultiplePhoto} from './components/ChatFormMultiplePhoto'; +import {ChatFormMultiplePhotoDescription} from './components/ChatFormMultiplePhotoDescription'; export interface QuestionFactoryProps { type: EntityType; @@ -183,6 +186,57 @@ export const QuestionFactory: ReactFCC = (props) => { )} ) + case EntityType.photo_description: + return ( +
+ {({ handleSubmit, register, control }) => ( + + )} + + ); + case EntityType.multiple_photo: + return ( +
+ {({ handleSubmit, register, control }) => ( + + )} + + ); + case EntityType.multiple_photo_description: + return ( +
+ {({ handleSubmit, register, control }) => ( + + )} + + ); default: return null; } diff --git a/src/pages/chat/components/ChatForm/components/ChatFormMultipleDateDescription/ChatFormMultipleDateDescription.module.scss b/src/pages/chat/components/ChatForm/components/ChatFormMultipleDateDescription/ChatFormMultipleDateDescription.module.scss index 124e380..f6331b5 100644 --- a/src/pages/chat/components/ChatForm/components/ChatFormMultipleDateDescription/ChatFormMultipleDateDescription.module.scss +++ b/src/pages/chat/components/ChatForm/components/ChatFormMultipleDateDescription/ChatFormMultipleDateDescription.module.scss @@ -31,4 +31,8 @@ .ChatFormMultipleDateDescription__hint { white-space: pre-wrap; +} + +.ChatFormMultipleDateDescription__itemName { + align-self: flex-start; } \ No newline at end of file diff --git a/src/pages/chat/components/ChatForm/components/ChatFormMultipleDateDescription/ChatFormMultipleDateDescription.tsx b/src/pages/chat/components/ChatForm/components/ChatFormMultipleDateDescription/ChatFormMultipleDateDescription.tsx index 3c1e468..b8082d2 100644 --- a/src/pages/chat/components/ChatForm/components/ChatFormMultipleDateDescription/ChatFormMultipleDateDescription.tsx +++ b/src/pages/chat/components/ChatForm/components/ChatFormMultipleDateDescription/ChatFormMultipleDateDescription.tsx @@ -58,7 +58,11 @@ export const ChatFormMultipleDateDescription: ReactFCC -