blob: f57ea1b3dfe48b529b2b9a5b2bdb11460d4063ec [file] [log] [blame]
simon26e79f72022-10-05 22:16:08 -04001/*
2 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
simond47ef9e2022-09-28 22:24:28 -040018import { Divider, InputBase } from '@mui/material';
simon07b4eb02022-09-29 17:50:26 -040019import { Stack } from '@mui/system';
simon6b9ddfb2022-10-03 00:04:50 -040020import { ChangeEvent, FormEvent, useCallback, useState } from 'react';
simon07b4eb02022-09-29 17:50:26 -040021
simond47ef9e2022-09-28 22:24:28 -040022import {
23 RecordVideoMessageButton,
24 RecordVoiceMessageButton,
25 SelectEmojiButton,
26 SendMessageButton,
27 UploadFileButton,
simon6b9ddfb2022-10-03 00:04:50 -040028} from './Button';
Larbi Gharibe9af9732021-03-31 15:08:01 +010029
simon6b9ddfb2022-10-03 00:04:50 -040030type SendMessageFormProps = {
31 onSend: (message: string) => void;
32};
33
34export default function SendMessageForm(props: SendMessageFormProps) {
simond47ef9e2022-09-28 22:24:28 -040035 const [currentMessage, setCurrentMessage] = useState('');
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040036
simon6b9ddfb2022-10-03 00:04:50 -040037 const handleSubmit = (e: FormEvent<HTMLFormElement>) => {
simond47ef9e2022-09-28 22:24:28 -040038 e.preventDefault();
Adrien Béraud88a52442021-04-26 12:11:41 -040039 if (currentMessage) {
simond47ef9e2022-09-28 22:24:28 -040040 props.onSend(currentMessage);
41 setCurrentMessage('');
Adrien Béraud88a52442021-04-26 12:11:41 -040042 }
simond47ef9e2022-09-28 22:24:28 -040043 };
simon6b9ddfb2022-10-03 00:04:50 -040044 const handleInputChange = (event: ChangeEvent<HTMLInputElement>) => setCurrentMessage(event.target.value);
idillonaedab942022-09-01 14:29:43 -040045
Adrien Béraud023f7cf2022-09-18 14:57:53 -040046 const onEmojiSelected = useCallback(
simon6b9ddfb2022-10-03 00:04:50 -040047 (emoji: string) => setCurrentMessage((currentMessage) => currentMessage + emoji),
simond47ef9e2022-09-28 22:24:28 -040048 [setCurrentMessage]
49 );
Larbi Gharibe9af9732021-03-31 15:08:01 +010050
Adrien Béraud8a438f82021-04-14 16:18:57 -040051 return (
simond47ef9e2022-09-28 22:24:28 -040052 <Stack padding="30px 16px 0px 16px">
idillonaedab942022-09-01 14:29:43 -040053 <Divider
54 sx={{
simond47ef9e2022-09-28 22:24:28 -040055 bordeTop: '1px solid #E5E5E5',
idillonaedab942022-09-01 14:29:43 -040056 }}
57 />
58 <Stack
59 component="form"
Adrien Béraud8a438f82021-04-14 16:18:57 -040060 onSubmit={handleSubmit}
idillonaedab942022-09-01 14:29:43 -040061 direction="row"
62 alignItems="center"
63 flexGrow={1}
64 spacing="20px"
65 padding="16px 0px"
66 >
simond47ef9e2022-09-28 22:24:28 -040067 <UploadFileButton />
68 <RecordVoiceMessageButton />
69 <RecordVideoMessageButton />
Adrien Béraud8a438f82021-04-14 16:18:57 -040070
simond47ef9e2022-09-28 22:24:28 -040071 <Stack flexGrow={1}>
idillonaedab942022-09-01 14:29:43 -040072 <InputBase
73 placeholder="Write something nice"
74 value={currentMessage}
75 onChange={handleInputChange}
76 sx={{
simond47ef9e2022-09-28 22:24:28 -040077 fontSize: '15px',
78 color: 'black',
79 '& ::placeholder': {
80 color: '#7E7E7E',
idillonaedab942022-09-01 14:29:43 -040081 opacity: 1,
82 },
83 }}
84 />
85 </Stack>
simond47ef9e2022-09-28 22:24:28 -040086 <SelectEmojiButton onEmojiSelected={onEmojiSelected} />
87 {currentMessage && <SendMessageButton type="submit" />}
idillonaedab942022-09-01 14:29:43 -040088 </Stack>
89 </Stack>
Adrien Béraudab519ff2022-05-03 15:34:48 -040090 );
Larbi Gharibe9af9732021-03-31 15:08:01 +010091}