Proyectos de Subversion LeadersLinked - SPA

Rev

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

Rev 3292 Rev 3303
Línea 1... Línea 1...
1
import React, { useState } from 'react'
1
import React, { useState } from 'react'
2
import { useForm } from 'react-hook-form'
2
import { useForm } from 'react-hook-form'
-
 
3
import { useDispatch } from 'react-redux'
3
import { Button, styled, Tab, Tabs } from '@mui/material'
4
import { Button, styled, Tab, Tabs } from '@mui/material'
Línea -... Línea 5...
-
 
5
 
-
 
6
import { useFetch } from '@hooks'
4
 
7
import { getTemplate } from '@services/habits/habits'
-
 
8
import { INTELLIGENCES, WEEK_DAYS } from '@constants/habits'
Línea 5... Línea 9...
5
import { INTELLIGENCES, WEEK_DAYS } from '@constants/habits'
9
import { addNotification } from '@store/notification/notification.actions'
6
 
10
 
7
import Row from '@components/common/Row'
11
import Row from '@components/common/Row'
8
import Form from '@components/common/form'
12
import Form from '@components/common/form'
Línea 46... Línea 50...
46
    notification_30min_before: false,
50
    notification_30min_before: false,
47
    intelligence: ''
51
    intelligence: ''
48
  },
52
  },
49
  values = {}
53
  values = {}
50
}) {
54
}) {
-
 
55
  const { data: templates } = useFetch('/helpers/habits-and-skills')
-
 
56
  const [currentTemplate, setCurrentTemplate] = useState(null)
51
  const [currentTab, setCurrentTab] = useState(0)
57
  const [currentTab, setCurrentTab] = useState(0)
-
 
58
  const dispatch = useDispatch()
Línea 52... Línea 59...
52
 
59
 
53
  const {
60
  const {
54
    handleSubmit,
61
    handleSubmit,
55
    control,
62
    control,
56
    formState: { errors, isSubmitting },
63
    formState: { errors, isSubmitting },
57
    trigger
64
    trigger
58
  } = useForm({
65
  } = useForm({
59
    defaultValues,
66
    defaultValues,
60
    values
67
    values: currentTemplate ?? values
-
 
68
  })
-
 
69
 
-
 
70
  const getHabitTemplate = async (url) => {
-
 
71
    try {
-
 
72
      const response = await getTemplate(url)
-
 
73
      setCurrentTemplate(response)
-
 
74
    } catch (error) {
-
 
75
      dispatch(addNotification({ style: 'danger', msg: error.message }))
-
 
76
    }
-
 
77
  }
61
  })
78
 
62
  const handleChange = async (event, newValue) => {
79
  const handleChange = async (event, newValue) => {
63
    const valid = await trigger()
80
    const valid = await trigger()
64
    if (valid) setCurrentTab(newValue)
81
    if (valid) setCurrentTab(newValue)
Línea 106... Línea 123...
106
      <Widget.Body>
123
      <Widget.Body>
107
        <Form onSubmit={handleSubmit(dataAdapter)}>
124
        <Form onSubmit={handleSubmit(dataAdapter)}>
108
          <LoadingWrapper loading={isSubmitting} displayChildren>
125
          <LoadingWrapper loading={isSubmitting} displayChildren>
109
            {/* Detalles */}
126
            {/* Detalles */}
110
            <FormTabPanel value={0} index={currentTab}>
127
            <FormTabPanel value={0} index={currentTab}>
-
 
128
              <Select
-
 
129
                label='Inteligencias:'
-
 
130
                name='intelligence'
-
 
131
                options={templates.map((template) => ({
-
 
132
                  name: template.name,
-
 
133
                  value: template.link
-
 
134
                }))}
-
 
135
                onChange={getHabitTemplate}
-
 
136
              />
-
 
137
 
111
              <Input
138
              <Input
112
                label='Nombre del hábito o competencia:'
139
                label='Nombre del hábito o competencia:'
113
                name='name'
140
                name='name'
114
                placeholder='Escribe el nombre del hábito o competencia'
141
                placeholder='Escribe el nombre del hábito o competencia'
115
                control={control}
142
                control={control}