Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3634 | Rev 3638 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import React from 'react';
import { IconButton } from '@mui/material';
import { AttachFile, SendRounded } from '@mui/icons-material';

import { Form, FormHiddenInput, FormInput } from '@shared/components';

export const ChatForm = ({ onSubmit }) => {
  const handleSubmit = (data) => {
    console.log(data);
    if (!data.message && !data.file) return;
    const message = {
      message: data.message,
      file: data.file ? data.file[0] : null
    };
    onSubmit(message);
  };

  return (
    <Form
      defaultValues={{ message: '', file: null }}
      reset
      onSubmit={handleSubmit}
      style={{ display: 'flex', alignItems: 'center', gap: 1, width: '100%' }}
    >
      <IconButton component='label' role={undefined} variant='contained' tabIndex={-1}>
        <AttachFile />
        <FormHiddenInput name='file' type='file' />
      </IconButton>
      <FormInput
        name='message'
        placeholder='Escribe un mensaje'
        autoComplete='off'
        endAdornment={
          <IconButton type='submit' sx={{ padding: 0.4 }}>
            <SendRounded />
          </IconButton>
        }
      />
    </Form>
  );
};