Skip to content
Snippets Groups Projects
auth.js 2.24 KiB
Newer Older
  • Learn to ignore specific revisions
  • import { GET_USERDATA, PROFILE_CHANGE, GROUP_CHANGE, GET_DEADLINE } from './types';
    
    
    
    export const getUserData = () => (
      async (dispatch) => {
    
    Barnabás Czémán's avatar
    Barnabás Czémán committed
        try {
          const user = await axios.get('/api/v1/profiles/me');
          const {
            id,
            join_date: joinDate,
            nick,
            motivation_about: motivationAbout,
            motivation_profession: motivationProfession,
            motivation_exercise: motivationExercise,
    
    Barnabás Czémán's avatar
    Barnabás Czémán committed
            signed,
            groups,
    
    Barnabás Czémán's avatar
    Barnabás Czémán committed
          } = user.data;
    
          let permission;
          switch (role) {
            case 'Applicant':
    
              break;
            case 'Student':
    
              break;
            case 'Staff':
    
              break;
            default:
    
    Barnabás Czémán's avatar
    Barnabás Czémán committed
          dispatch({
            type: GET_USERDATA,
            payload: {
    
              id, joinDate, nick, motivationAbout, motivationProfession, motivationExercise, full_name, signed, groups, role, permission
    
    Barnabás Czémán's avatar
    Barnabás Czémán committed
            },
          });
    
        } catch (e) {
          console.log(e);
        }
    
    export const getDeadline = () => (
      async (dispatch) => {
        try {
          const response = await axios.get('/api/v1/profiles/deadline');
    
          dispatch({
            type: GET_DEADLINE,
            payload: response.data,
          });
        } catch (e) {
          console.log(e);
        }
      }
    );
    
    
    export const textChange = ({ target: { name, value } }) => (
      (dispatch) => {
        dispatch({ type: PROFILE_CHANGE, payload: value, target: name });
      }
    );
    
    export const groupChange = groups => (
      dispatch => (dispatch({ type: GROUP_CHANGE, payload: groups }))
    );
    
    
    Tamás Szabó's avatar
    Tamás Szabó committed
    export const submitRegistration = ({
    
    Tamás Szabó's avatar
    Tamás Szabó committed
      nick, groups, signed, motivationAbout, motivationProfession, motivationExercise, id,
    
    Tamás Szabó's avatar
    Tamás Szabó committed
    }) => (
    
      async () => {
    
    Barnabás Czémán's avatar
    Barnabás Czémán committed
        try {
          const response = await axios.patch(`/api/v1/profiles/${id}/`, {
            nick,
            groups,
            signed,
            motivation_about: motivationAbout,
            motivation_profession: motivationProfession,
            motivation_exercise: motivationExercise,
          });
          if (response.data.id === id) {
            alert('Sikeres mentés!');
          } else {
            alert('Mentés nem sikerült!');
          }
    
        } catch (e) {
          console.log(e);
        }