Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 40 | Ir a la última revisión | | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5 stevensc 1
import { axios } from "../../utils";
2
import { intlTypes } from "./intl.types";
3
 
4
export const getLanguage = () => {
5
  return async (dispatch) => {
6
    try {
7
      const { data: response } = await axios.get("/language");
8
      const { success, data } = response;
9
 
10
      if (!success) {
11
        throw new Error(data.message);
12
      }
13
 
14
      dispatch(setIntlLabels(labelsAdapter(data)));
15
    } catch (error) {
16
      throw new Error(error);
17
    }
18
  };
19
};
20
 
21
const labelsAdapter = (labels) => {
22
  const newKeys = Object.entries(labels).map(([key, value]) => [
23
    key.replace("LABEL_", "").toLowerCase(),
24
    value,
25
  ]);
26
 
27
  return Object.fromEntries(newKeys);
28
};
29
 
30
export const setIntlLabels = (labels) => ({
31
  type: intlTypes.SET_LABELS,
32
  payload: labels,
33
});