Skip to content

Commit

Permalink
Redirect automatically when Room Deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
GBS-Skile authored and y123ob committed Jun 19, 2019
1 parent bb87282 commit edf5324
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
6 changes: 1 addition & 5 deletions frontend/src/containers/RoomCreatePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ import { RoomCreatePage } from 'components'
import { Redirect } from 'react-router-dom'

const RoomCreatePageContainer = (props) => {
const { room, username } = props
const { username } = props

if ( !username ) {
return <Redirect to="/" />
}
// else if( room ) {
// return <Redirect to={`/room/${room.url}/`}/>
// }
else {
return <RoomCreatePage {...props} />
}
}

const mapStateToProps = state => ({
// room: state.room.room,
username: state.user.username,
token: state.user.token,
})
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/services/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export const checkStatus = (response) => {
throw error
}

export const parseJSON = response => response.json()
export const parseJSON = response => {
return response.status === 204 ? {} : response.json()
}

export const parseSettings = ({
method = 'get', data, locale, token, ...otherSettings
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/store/room/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ export const roomSettingRequest = ( {url} ) => ({
type: ROOM_SETTING_REQUEST,
url,
})
export const roomDeleteSuccess = () => ({
export const roomDeleteSuccess = ( url ) => ({
type: ROOM_DELETE_SUCCESS,
url,
})
export const roomDeleteFailed = () => ({
export const roomDeleteFailed = error => ({
type: ROOM_DELETE_FAILED,
error,
})


Expand Down
13 changes: 8 additions & 5 deletions frontend/src/store/room/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const roomReducer = (state = initialState, action) => {
case actions.ROOM_CREATE_SUCCESS:
return {
...state,
// room: action.room,
roomList: [
...state.roomList,
action.room,
Expand All @@ -61,15 +60,19 @@ const roomReducer = (state = initialState, action) => {
return{
...initialState,
}
case action.ROOM_DELETE_SUCCESS:
return{
...initialState,
}
case action.ROOM_DELETE_FAILED:
return{
...initialState,
}
*/
case actions.ROOM_DELETE_SUCCESS:
return {
...state,
roomList: state.roomList.slice().filter(
room => room.url !== action.url
),
}
case actions.ROOM_LIST_SUCCESS:
return {
...state,
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/store/room/sagas.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { push } from 'connected-react-router'
import { push, replace } from 'connected-react-router'
import { fork, takeEvery, put } from 'redux-saga/effects'
import { toastr } from 'react-redux-toastr'
import api from 'services/api'
Expand Down Expand Up @@ -28,7 +28,7 @@ function* roomCreateRequest({ roomname, members, username, token }){
{ icon: 'success', status: 'success', }
)
yield put(actions.roomCreateSuccess(room))
yield put(push(`/room/${room.url}/`))
yield put(replace(`/room/${room.url}/`))
} catch(e) {
console.log(e)
}
Expand Down Expand Up @@ -61,7 +61,8 @@ function* getRequest({ url }) {
yield put(memberGetRequest(url))
yield put(paymentGetRequest(room))
} catch(e) {
yield put(actions.roomGetFailed(e))
yield put(actions.roomGetFailed(yield e.response.json()))
yield put(push(`/user/`))
}
}

Expand All @@ -74,9 +75,11 @@ function* watchRoomGetRequest() {
function* deleteRequest( { url } ) {

try {
const room = yield api.delete(`/rooms/${url}/`)
yield put(actions.roomDeleteSuccess())
yield api.delete(`/rooms/${url}/`)
yield put(actions.roomDeleteSuccess(url))
yield put(replace(`/user/`))
} catch(e) {
console.log(e)
yield put(actions.roomDeleteFailed(e))
}

Expand Down

0 comments on commit edf5324

Please sign in to comment.