Skip to content

Instantly share code, notes, and snippets.

@bnhansn
Created October 21, 2016 19:54
Show Gist options
  • Save bnhansn/54780a12e8d44d9d95ef560696e2a2ae to your computer and use it in GitHub Desktop.
Save bnhansn/54780a12e8d44d9d95ef560696e2a2ae to your computer and use it in GitHub Desktop.
import api from '../api';
export function fetchRooms() {
return dispatch => api.fetch('/rooms')
.then((response) => {
dispatch({ type: 'FETCH_ROOMS_SUCCESS', response });
});
}
export function fetchUserRooms(userId) {
return dispatch => api.fetch(`/users/${userId}/rooms`)
.then((response) => {
dispatch({ type: 'FETCH_USER_ROOMS_SUCCESS', response });
});
}
export function createRoom(data, router) {
return dispatch => api.post('/rooms', data)
.then((response) => {
dispatch({ type: 'CREATE_ROOM_SUCCESS', response });
router.transitionTo(`/r/${response.data.id}`);
});
}
export function joinRoom(roomId, router) {
return dispatch => api.post(`/rooms/${roomId}/join`)
.then((response) => {
dispatch({ type: 'ROOM_JOINED', response });
router.transitionTo(`/r/${response.data.id}`);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment