Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 16261 Rev 16264
Línea 11... Línea 11...
11
  show = false,
11
  show = false,
12
  timezones = {},
12
  timezones = {},
13
  zoomUrl = "",
13
  zoomUrl = "",
14
  onCreate = () => null,
14
  onCreate = () => null,
15
}) => {
15
}) => {
16
  const dt = new Date();
-
 
17
 
-
 
18
  const { handleSubmit, register, errors, reset } = useForm({ mode: "all" });
16
  const { handleSubmit, register, errors } = useForm({ mode: "all" });
19
  const [date, setDate] = useState({
-
 
20
    year: dt.toLocaleString("default", { year: "numeric" }),
-
 
21
    month: dt.toLocaleString("default", { month: "2-digit" }),
-
 
22
    day: dt.toLocaleString("default", { day: "2-digit" }),
-
 
23
  });
-
 
24
  const [time, setTime] = useState(
-
 
25
    dt.toLocaleString("es", {
-
 
26
      hour: "numeric",
-
 
27
      minute: "2-digit",
-
 
28
      second: "2-digit",
-
 
29
    })
-
 
30
  );
-
 
31
  const [coferenceType, setConferenceType] = useState(1);
17
  const [coferenceType, setConferenceType] = useState(1);
32
  const [isShow, setIsShow] = useState(show);
18
  const [isShow, setIsShow] = useState(show);
33
  const dispatch = useDispatch();
-
 
Línea 34... Línea 19...
34
 
19
 
35
  const closeModal = () => {
20
  const closeModal = () => {
36
    setIsShow(false);
21
    setIsShow(false);
Línea 37... Línea 22...
37
  };
22
  };
38
 
23
 
39
  const handleChange = (value) => {
24
  const handleChange = (value) => {
Línea 40... Línea -...
40
    setConferenceType(value);
-
 
41
  };
-
 
42
 
-
 
43
  const handleDateTime = (value) => {
-
 
44
    setDate({
-
 
45
      ...date,
-
 
46
      year: new Intl.DateTimeFormat("es", { year: "numeric" }).format(value),
-
 
47
      month: new Intl.DateTimeFormat("es", { month: "2-digit" }).format(value),
-
 
48
      day: new Intl.DateTimeFormat("es", { day: "2-digit" }).format(value),
-
 
49
    });
-
 
50
    setTime(
-
 
51
      new Intl.DateTimeFormat("es", {
-
 
52
        hour: "numeric",
-
 
53
        minute: "2-digit",
-
 
54
        second: "numeric",
-
 
55
      }).format(value)
-
 
56
    );
-
 
57
  };
-
 
58
 
-
 
59
  const onSubmit = async (data) => {
-
 
60
    try {
-
 
61
      const formData = new FormData();
-
 
62
 
-
 
63
      Object.entries(data).forEach(([key, value]) =>
-
 
64
        formData.append(key, value)
-
 
65
      );
-
 
66
      formData.append("date", `${date.year}-${date.month}-${date.day}`);
-
 
67
      formData.append("time", time);
-
 
68
 
-
 
69
      const { data: response } = await axios.post(zoomUrl, formData);
-
 
70
 
-
 
71
      if (!response.success && typeof response.data === "string") {
-
 
72
        dispatch(addNotification({ msg: response.data, style: "danger" }));
-
 
73
        return;
-
 
74
      }
-
 
75
 
-
 
76
      if (!response.success && typeof response.data === "object") {
-
 
77
        Object.entries(response.data).forEach(([key, value]) => {
-
 
78
          dispatch(
-
 
79
            addNotification({ msg: `${key}: ${value[0]}`, style: "danger" })
-
 
80
          );
-
 
81
        });
-
 
82
        return;
-
 
83
      }
-
 
84
 
-
 
85
      dispatch(addNotification({ msg: response.data, style: "success" }));
-
 
86
      onCreate();
-
 
87
      reset();
-
 
88
    } catch (error) {
-
 
89
      console.log(`Error: ${error.message}`);
-
 
90
      return dispatch(
-
 
91
        addNotification({ msg: "Ha ocurrido un error", style: "danger" })
-
 
92
      );
-
 
93
    }
25
    setConferenceType(value);
94
  };
26
  };
95
 
27
 
Línea 96... Línea 28...
96
  useEffect(() => {
28
  useEffect(() => {
97
    setIsShow(show);
29
    setIsShow(show);
98
  }, [show]);
30
  }, [show]);
99
 
31
 
100
  return (
32
  return (
-
 
33
    <Modal show={isShow} onHide={closeModal}>
-
 
34
      <Modal.Header closeButton>
-
 
35
        <Modal.Title>Crear Conferencia</Modal.Title>
-
 
36
      </Modal.Header>
-
 
37
      <Modal.Body>
-
 
38
        <form onSubmit={handleSubmit(onSubmit)} autoComplete="new-password">
-
 
39
          <div className="form-group">
-
 
40
            <label htmlFor="first_name">Título</label>
-
 
41
            <input
-
 
42
              type="text"
-
 
43
              name="title"
-
 
44
              className="form-control"
-
 
45
              maxLength={128}
-
 
46
              ref={register({ required: "Por favor ingrese un título" })}
-
 
47
            />
-
 
48
            {errors.title && (
-
 
49
              <FormErrorFeedback>{errors.title.message}</FormErrorFeedback>
-
 
50
            )}
-
 
51
          </div>
-
 
52
          <div className="form-group">
-
 
53
            <label htmlFor="first_name">Descripción</label>
-
 
54
            <input
-
 
55
              type="text"
-
 
56
              name="description"
-
 
57
              className="form-control"
-
 
58
              ref={register({ required: "Por favor ingrese una descripción" })}
-
 
59
            />
-
 
60
            {errors.description && (
-
 
61
              <FormErrorFeedback>
-
 
62
                {errors.description.message}
-
 
63
              </FormErrorFeedback>
-
 
64
            )}
-
 
65
          </div>
-
 
66
          <div className="form-group">
-
 
67
            <label htmlFor="timezone">Tipo de conferencia</label>
-
 
68
            <select
-
 
69
              name="type"
-
 
70
              className="form-control"
-
 
71
              onChange={({ target }) => handleChange(target.value)}
-
 
72
              ref={register}
-
 
73
            >
-
 
74
              <option value="i">Inmediata</option>
-
 
75
              <option value="s">Programada</option>
-
 
76
            </select>
-
 
77
          </div>
-
 
78
          <div className="form-group">
-
 
79
            <label htmlFor="timezone">Zona horaria</label>
-
 
80
            <select
-
 
81
              className="form-control"
-
 
82
              name="timezone"
-
 
83
              ref={register({ required: "Por favor elige una Zona horaria" })}
-
 
84
            >
-
 
85
              <option value="" hidden>
-
 
86
                Zona horaria
-
 
87
              </option>
-
 
88
              {Object.entries(timezones).map(([key, value]) => (
-
 
89
                <option value={key} key={key}>
-
 
90
                  {value}
-
 
91
                </option>
-
 
92
              ))}
-
 
93
            </select>
-
 
94
            {errors.timezone && (
-
 
95
              <FormErrorFeedback>{errors.timezone.message}</FormErrorFeedback>
-
 
96
            )}
-
 
97
          </div>
-
 
98
          <div className="form-group">
-
 
99
            <label htmlFor="timezone">Duración</label>
-
 
100
            <select className="form-control" name="duration" ref={register}>
-
 
101
              <option value={5}>5-min</option>
-
 
102
              <option value={10}>10-min</option>
-
 
103
              <option value={15}>15-min</option>
-
 
104
              <option value={20}>20-min</option>
-
 
105
              <option value={25}>25-min</option>
-
 
106
              <option value={30}>30-min</option>
-
 
107
              <option value={35}>35-min</option>
-
 
108
              <option value={40}>40-min</option>
-
 
109
              <option value={45}>45-min</option>
-
 
110
            </select>
-
 
111
          </div>
-
 
112
          <div className="form-group">
-
 
113
            <label htmlFor="first_name">Contraseña de ingreso</label>
-
 
114
            <input
-
 
115
              type="password"
-
 
116
              name="password"
-
 
117
              className="form-control"
-
 
118
              ref={register({
-
 
119
                required: "Por favor ingrese una contraseña",
-
 
120
                maxLength: {
-
 
121
                  value: 6,
-
 
122
                  message: "La contraseña debe tener al menos 6 digitos",
-
 
123
                },
-
 
124
              })}
-
 
125
            />
-
 
126
            {errors.password && (
-
 
127
              <FormErrorFeedback>{errors.password.message}</FormErrorFeedback>
-
 
128
            )}
-
 
129
          </div>
101
    <Modal show={isShow} onHide={closeModal}>
130
          <button className="btn btn-primary" type="submit">
102
      <Modal.Header closeButton>
131
            Crear
103
        <Modal.Title>Crear Conferencia</Modal.Title>
132
          </button>
104
      </Modal.Header>
133
        </form>
Línea 105... Línea 134...
105
      <Modal.Body></Modal.Body>
134
      </Modal.Body>