Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3040 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3040 Rev 3041
Línea 1... Línea 1...
1
import { useEffect, useState } from 'react'
1
import { useEffect, useState } from 'react'
2
import { useDispatch } from 'react-redux'
2
import { useDispatch } from 'react-redux'
-
 
3
 
3
import { addNotification } from '@store/notification/notification.actions'
4
import { addNotification } from '@store/notification/notification.actions'
Línea 4... Línea 5...
4
 
5
 
5
export function useResource({
6
export function useResource({
6
  defaultResources = [],
7
  defaultResources = [],
Línea 16... Línea 17...
16
  const showModal = (type, resource = null) => {
17
  const showModal = (type, resource = null) => {
17
    setCurrentResource(resource)
18
    setCurrentResource(resource)
18
    setModalState(modalState === type ? null : type)
19
    setModalState(modalState === type ? null : type)
19
  }
20
  }
Línea 20... Línea 21...
20
 
21
 
-
 
22
  const clearModal = () => {
-
 
23
    showModal(null)
-
 
24
    setCurrentResource(null)
Línea 21... Línea 25...
21
  const clearModal = () => showModal(null)
25
  }
22
 
26
 
23
  const onAdd = async (uuid, resource) => {
27
  const onAdd = async (uuid, resource) => {
24
    try {
28
    try {
25
      const newResources = await addResource(uuid, resource)
29
      const newResources = await addResource(uuid, resource)
26
      setResources(newResources)
30
      setResources(newResources)
27
      showModal(null)
31
      clearModal()
28
    } catch (error) {
32
    } catch (error) {
29
      dispatch(addNotification({ style: 'danger', msg: error.message }))
33
      dispatch(addNotification({ style: 'danger', msg: error.message }))
Línea 30... Línea 34...
30
    }
34
    }
31
  }
35
  }
-
 
36
 
32
 
37
  const onEdit = async (resource) => {
33
  const onEdit = async (resource) => {
38
    try {
34
    try {
39
      console.log('Editing')
35
      const newResources = await editResource(
40
      const newResources = await editResource(
-
 
41
        currentResource.link_edit,
36
        currentResource.link_edit,
42
        resource
37
        resource
43
      )
38
      )
44
      console.log(newResources)
39
      setResources(newResources)
45
      setResources(newResources)
40
      showModal(null)
46
      clearModal()
41
    } catch (error) {
47
    } catch (error) {
Línea 42... Línea 48...
42
      dispatch(addNotification({ style: 'danger', msg: error.message }))
48
      dispatch(addNotification({ style: 'danger', msg: error.message }))
43
    }
49
    }
44
  }
50
  }
45
 
51
 
46
  const onDelete = async () => {
52
  const onDelete = async () => {
47
    try {
53
    try {
48
      const newResources = await deleteResource(currentResource.link_delete)
54
      const newResources = await deleteResource(currentResource.link_delete)
49
      setResources(newResources)
55
      setResources(newResources)
50
      showModal(null)
56
      clearModal()