Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
3736 stevensc 1
import React, { useMemo } from 'react';
2
 
3
import { useAlert, useApi } from '@shared/hooks';
4
import { parseHelperToSelect } from '@shared/utils';
5
import { saveGroupIndustry } from '@groups/services';
6
 
7
import { Form, FormButton, FormSelect } from '@shared/components';
8
 
9
export function IndustryForm({ industries, industry, uuid, onSubmit }) {
10
  const industriesOptions = useMemo(() => parseHelperToSelect(industries), [industries]);
11
  const industryId = useMemo(
12
    () => industriesOptions.find((value) => value.label === industry)?.value || '',
13
    [industriesOptions, industry]
14
  );
15
 
16
  const { showError, showSuccess } = useAlert();
17
 
18
  const { execute } = useApi(saveGroupIndustry, {
19
    onSuccess: (data) => {
20
      showSuccess('Industria actualizada correctamente');
21
      onSubmit(data);
22
    },
23
    onError: (error) => {
24
      showError(error.message);
25
    }
26
  });
27
 
28
  const handleSubmit = (data) => {
29
    execute(uuid, data);
30
  };
31
 
32
  return (
33
    <Form onSubmit={handleSubmit} defaultValues={{ industry_id: industryId }}>
34
      <FormSelect
35
        name='industry_id'
36
        placeholder='Industria'
37
        rules={{ required: 'Por favor eliga una industria' }}
38
        options={industriesOptions}
39
      />
40
      <FormButton type='submit'>Guardar</FormButton>
41
    </Form>
42
  );
43
}