Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 4360 Rev 4363
Línea 12... Línea 12...
12
const Notifications = ({ addNotification }) => {
12
const Notifications = ({ addNotification }) => {
Línea 13... Línea 13...
13
 
13
 
14
  const { register, handleSubmit, setValue } = useForm();
14
  const { register, handleSubmit, setValue } = useForm();
Línea 15... Línea 15...
15
  const [loading, setLoading] = useState(false);
15
  const [loading, setLoading] = useState(false);
16
 
16
 
17
  const handleOnSubmit = async (data) => {
17
  const handleOnSubmit = (data) => {
-
 
18
    setLoading(true);
-
 
19
    const formData = new FormData();
18
    setLoading(true);
20
 
19
    const formData = new FormData();
21
    Object.
20
    Object.entries(data).map(([key, value]) => {
22
      entries(data)
21
      if (value) formData.append(key, value === 'y' ? value : 'n');
23
      .map(([key, value]) => value && FormData.append(key, value === 'y' ? value : 'n'))
22
    });
24
 
23
    await axios
25
    axios
24
      .post("/account-settings/notification", formData)
-
 
25
      .then((response) => {
26
      .post("/account-settings/notification", formData)
26
        const resData = response.data;
-
 
27
        if (resData.success) {
-
 
28
          addNotification({
-
 
29
            style: "success",
-
 
30
            msg: resData.data,
-
 
31
          });
-
 
32
        } else {
-
 
33
          const errorMessage =
-
 
34
            typeof resData.data === "string"
27
      .then(({ data: response }) => {
35
              ? resData.data
-
 
36
              : "Ha ocurrido un error, Por favor intente mas tarde";
-
 
37
          addNotification({
28
        if (!response.success) {
38
            style: "danger",
-
 
39
            msg: errorMessage,
29
          const errorMessage = typeof response.data === "string" ? response.data : "Ha ocurrido un error, Por favor intente mas tarde"
-
 
30
          return addNotification({ style: "danger", msg: errorMessage })
-
 
31
        }
40
          });
32
 
41
        }
33
        return addNotification({ style: "success", msg: response.data })
42
      });
34
      })
Línea 43... Línea 35...
43
    setLoading(false);
35
      .finally(() => setLoading(false))
44
  };
36
  };
-
 
37
 
45
 
38
  useEffect(() => {
46
  useEffect(async () => {
39
    setLoading(true);
47
    setLoading(true);
40
    axios
-
 
41
      .get("/account-settings/notification")
48
    await axios.get("/account-settings/notification").then((response) => {
42
      .then(({ data: response }) => {
49
      const resData = response.data;
43
        if (response.success) {
50
      if (resData.success) {
44
          Object
51
        Object.entries(resData.data).map(([key, value]) => {
45
            .entries(response.data)
52
          setValue(key, value);
-
 
53
        });
46
            .map(([key, value]) => setValue(key, value))
54
      }
47
        }
Línea 55... Línea 48...
55
    });
48
      })
56
    setLoading(false);
49
      .finally(() => setLoading(false))
57
  }, []);
50
  }, []);
Línea 96... Línea 89...
96
    }
89
    }
97
  ]
90
  ]
Línea 98... Línea 91...
98
 
91
 
99
  return (
92
  return (
100
    <div className="acc-setting">
93
    <div className="acc-setting">
101
      <h3>Notificaciones</h3>
94
      <h3>Notificaciónes de Correo Electrónico</h3>
102
      {loading
95
      {loading
103
        ? <Spinner />
96
        ? <Spinner />
104
        :
97
        :
105
        <form onSubmit={handleSubmit(handleOnSubmit)}>
98
        <form onSubmit={handleSubmit(handleOnSubmit)}>
106
          {NOTIFICATION_OPTIONS.map((option , index) => {
99
          {NOTIFICATION_OPTIONS.map((option, index) => {
107
            return (
100
            return (
108
              <div className="notbat" key={index}>
101
              <div className="notbat" key={index}>
109
                <span>
102
                <span>
110
                  {option.label}
103
                  {option.label}