Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3639 | Rev 3644 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3639 stevensc 1
import React, { useState } from 'react';
3622 stevensc 2
import { IconButton } from '@mui/material';
3
import { AttachFile, SendRounded } from '@mui/icons-material';
4
 
3638 stevensc 5
import { FileModal, Form, FormInput } from '@shared/components';
6
import { useModal } from '@shared/hooks';
3622 stevensc 7
 
8
export const ChatForm = ({ onSubmit }) => {
3639 stevensc 9
  const [files, setFiles] = useState([]);
3638 stevensc 10
  const { showModal, closeModal } = useModal();
11
 
3639 stevensc 12
  const handleSubmit = (data) => {
13
    onSubmit({ ...data, file: files[0] });
14
  };
15
 
3638 stevensc 16
  const attachFile = () => {
17
    showModal(
18
      'Elegir archivo',
19
      <FileModal
20
        onSubmit={(data) => {
3639 stevensc 21
          setFiles(data);
3638 stevensc 22
          closeModal();
23
        }}
24
      />
25
    );
3634 stevensc 26
  };
3622 stevensc 27
  return (
3628 stevensc 28
    <Form
3638 stevensc 29
      defaultValues={{ message: '' }}
3628 stevensc 30
      reset
3639 stevensc 31
      onSubmit={handleSubmit}
3628 stevensc 32
      style={{ display: 'flex', alignItems: 'center', gap: 1, width: '100%' }}
33
    >
3638 stevensc 34
      <IconButton onClick={attachFile}>
3622 stevensc 35
        <AttachFile />
36
      </IconButton>
37
      <FormInput
38
        name='message'
39
        placeholder='Escribe un mensaje'
40
        autoComplete='off'
3639 stevensc 41
        rules={{ required: true }}
3622 stevensc 42
        endAdornment={
43
          <IconButton type='submit' sx={{ padding: 0.4 }}>
44
            <SendRounded />
45
          </IconButton>
46
        }
47
      />
48
    </Form>
49
  );
50
};