Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3638 | Rev 3642 | 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
    console.log(data);
14
    console.log(files);
15
    onSubmit({ ...data, file: files[0] });
16
  };
17
 
3638 stevensc 18
  const attachFile = () => {
19
    showModal(
20
      'Elegir archivo',
21
      <FileModal
22
        onSubmit={(data) => {
3639 stevensc 23
          setFiles(data);
3638 stevensc 24
          closeModal();
25
        }}
26
      />
27
    );
3634 stevensc 28
  };
3622 stevensc 29
  return (
3628 stevensc 30
    <Form
3638 stevensc 31
      defaultValues={{ message: '' }}
3628 stevensc 32
      reset
3639 stevensc 33
      onSubmit={handleSubmit}
3628 stevensc 34
      style={{ display: 'flex', alignItems: 'center', gap: 1, width: '100%' }}
35
    >
3638 stevensc 36
      <IconButton onClick={attachFile}>
3622 stevensc 37
        <AttachFile />
38
      </IconButton>
39
      <FormInput
40
        name='message'
41
        placeholder='Escribe un mensaje'
42
        autoComplete='off'
3639 stevensc 43
        rules={{ required: true }}
3622 stevensc 44
        endAdornment={
45
          <IconButton type='submit' sx={{ padding: 0.4 }}>
46
            <SendRounded />
47
          </IconButton>
48
        }
49
      />
50
    </Form>
51
  );
52
};