client/src/actions/sessionsActions.js
author Alexandre Segura <mex.zktk@gmail.com>
Thu, 22 Jun 2017 12:37:53 +0200
changeset 78 49c5ea36d0a4
parent 74 043477fd5c5c
child 93 469da13402e2
permissions -rw-r--r--
Store margin comment.

import { now } from '../utils';
import * as types from '../constants/actionTypes';

export const createSession = (sessionId) => {

  const newSession = {
      _id: sessionId,
      ext_id: sessionId,
      date: now(),
      title: '',
      description: '',
  };

  return {
    type: types.CREATE_SESSION,
    session: newSession,
    meta: {
      offline: {
        effect: {
          url: `/api/notes/sessions/`,
          method: 'POST',
          data: newSession
        },
        commit: { type: types.NOOP },
        rollback: { type: types.NOOP }
      }
    }
  };
}

export const updateSession = (session, values) => {
  return {
    type: types.UPDATE_SESSION,
    session: session,
    values: values,
    meta: {
      offline: {
        effect: {
          url: `/api/notes/sessions/${session.get('_id')}/`,
          method: 'PUT',
          data: values
        },
        commit: { type: types.NOOP },
        rollback: { type: types.NOOP }
      }
    }
  };
}

export const loadSessions = () => {
  return {
    type: types.LOAD_SESSIONS
  }
}