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 { useApi, useAlert } from '@shared/hooks';
4
import { saveGroupAccessibility } from '@groups/services';
5
 
6
import { parseHelperToSelect } from '@shared/utils';
7
import { Form, FormButton, FormSelect } from '@shared/components';
8
 
9
export function AccessibilityForm({
10
  uuid = '',
11
  privacy,
12
  accessibility,
13
  accessibilities = {},
14
  onSubmit = () => {}
15
}) {
16
  const accessibilitiesOptions = useMemo(() => {
17
    const options = parseHelperToSelect(accessibilities);
18
    return options.filter((acc) => (privacy === 'Privado' ? acc.value !== 'aj' : true));
19
  }, [accessibilities, privacy]);
20
 
21
  const currentAccessibility = useMemo(
22
    () => accessibilitiesOptions.find((acc) => acc.label === accessibility)?.value || '',
23
    [accessibilitiesOptions, accessibility]
24
  );
25
 
26
  const { showSuccess, showError } = useAlert();
27
 
28
  const { execute } = useApi(saveGroupAccessibility, {
29
    onSuccess: (data) => {
30
      showSuccess('Accesibilidad actualizada correctamente');
31
      onSubmit(data);
32
    },
33
    onError: (error) => {
34
      showError(error.message);
35
    }
36
  });
37
 
38
  const handleSubmit = (data) => {
39
    execute(uuid, data);
40
  };
41
 
42
  return (
43
    <Form onSubmit={handleSubmit} defaultValues={{ accessibility: currentAccessibility }}>
44
      <FormSelect
45
        name='accessibility'
46
        placeholder='Accesibilidad'
47
        rules={{ required: 'Por favor eliga una accesibilidad' }}
48
        options={accessibilitiesOptions}
49
      />
50
      <FormButton type='submit'>Guardar</FormButton>
51
    </Form>
52
  );
53
}