Added createTeam sagas, createTeam reducer, new Team string and update CreateChannelView
This commit is contained in:
parent
8b82bd456e
commit
c8b8680541
|
@ -714,5 +714,6 @@
|
|||
"Team_Name": "Team Name",
|
||||
"Private_Team": "Private Team",
|
||||
"Read_Only_Team": "Read Only Team",
|
||||
"Broadcast_Team": "Broadcast Team"
|
||||
"Broadcast_Team": "Broadcast Team",
|
||||
"creating_team" : "creating team"
|
||||
}
|
||||
|
|
|
@ -728,9 +728,13 @@ const RocketChat = {
|
|||
prid, pmid, t_name, reply, users, encrypted
|
||||
});
|
||||
},
|
||||
createTeam(name) {
|
||||
createTeam({
|
||||
name, users, type, readOnly, broadcast, encrypted
|
||||
}) {
|
||||
// RC 3.13.0
|
||||
return this.post('teams.create', name);
|
||||
return this.post('teams.create', {
|
||||
name, users, type, readOnly, broadcast, encrypted
|
||||
});
|
||||
},
|
||||
joinRoom(roomId, joinCode, type) {
|
||||
// TODO: join code
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
import { CREATE_TEAM } from '../actions/actionsTypes';
|
||||
|
||||
const initialState = {
|
||||
isFetching: false,
|
||||
failure: false,
|
||||
result: {},
|
||||
error: {}
|
||||
};
|
||||
|
||||
export default function(state = initialState, action) {
|
||||
switch (action.type) {
|
||||
case CREATE_TEAM.REQUEST:
|
||||
return {
|
||||
...state,
|
||||
isFetching: true,
|
||||
failure: false,
|
||||
error: {}
|
||||
};
|
||||
case CREATE_TEAM.SUCCESS:
|
||||
return {
|
||||
...state,
|
||||
isFetching: false,
|
||||
failure: false,
|
||||
result: action.data
|
||||
};
|
||||
case CREATE_TEAM.FAILURE:
|
||||
return {
|
||||
...state,
|
||||
isFetching: false,
|
||||
failure: true,
|
||||
error: action.err
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import rooms from './rooms';
|
|||
import server from './server';
|
||||
import selectedUsers from './selectedUsers';
|
||||
import createChannel from './createChannel';
|
||||
import createTeam from './createTeam';
|
||||
import app from './app';
|
||||
import sortPreferences from './sortPreferences';
|
||||
import share from './share';
|
||||
|
@ -29,6 +30,7 @@ export default combineReducers({
|
|||
server,
|
||||
selectedUsers,
|
||||
createChannel,
|
||||
createTeam,
|
||||
app,
|
||||
room,
|
||||
rooms,
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
import {
|
||||
select, put, call, take, takeLatest
|
||||
} from 'redux-saga/effects';
|
||||
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
||||
|
||||
import { CREATE_TEAM, LOGIN } from '../actions/actionsTypes';
|
||||
import { createTeamSuccess, createTeamFailure } from '../actions/createTeam';
|
||||
import { showErrorAlert } from '../utils/info';
|
||||
import RocketChat from '../lib/rocketchat';
|
||||
import Navigation from '../lib/Navigation';
|
||||
import database from '../lib/database';
|
||||
import I18n from '../i18n';
|
||||
import { logEvent, events } from '../utils/log';
|
||||
import { goRoom } from '../utils/goRoom';
|
||||
|
||||
const createTeam = function createTeam(data) {
|
||||
return RocketChat.createTeam(data);
|
||||
};
|
||||
|
||||
const handleRequest = function* handleRequest({ data }) {
|
||||
try {
|
||||
const auth = yield select(state => state.login.isAuthenticated);
|
||||
if (!auth) {
|
||||
yield take(LOGIN.SUCCESS);
|
||||
}
|
||||
|
||||
const {
|
||||
type, readOnly, broadcast, encrypted
|
||||
} = data;
|
||||
|
||||
logEvent(events.CR_CREATE, {
|
||||
type,
|
||||
readOnly,
|
||||
broadcast,
|
||||
encrypted
|
||||
});
|
||||
const sub = yield call(createTeam, data);
|
||||
|
||||
try {
|
||||
const db = database.active;
|
||||
const subCollection = db.get('subscriptions');
|
||||
yield db.action(async() => {
|
||||
await subCollection.create((s) => {
|
||||
s._raw = sanitizedRaw({ id: sub.rid }, subCollection.schema);
|
||||
Object.assign(s, sub);
|
||||
});
|
||||
});
|
||||
} catch {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
yield put(createTeamSuccess(sub));
|
||||
} catch (err) {
|
||||
logEvent(events[data.group ? 'SELECTED_USERS_CREATE_GROUP_F' : 'CR_CREATE_F']);
|
||||
yield put(createTeamFailure(err));
|
||||
}
|
||||
};
|
||||
|
||||
const handleSuccess = function* handleSuccess({ data }) {
|
||||
const isMasterDetail = yield select(state => state.app.isMasterDetail);
|
||||
if (isMasterDetail) {
|
||||
Navigation.navigate('DrawerNavigator');
|
||||
}
|
||||
goRoom({ item: data, isMasterDetail });
|
||||
};
|
||||
|
||||
const handleFailure = function handleFailure({ err }) {
|
||||
setTimeout(() => {
|
||||
const msg = err.reason || I18n.t('There_was_an_error_while_action', { action: I18n.t('creating_team') });
|
||||
showErrorAlert(msg);
|
||||
}, 300);
|
||||
};
|
||||
|
||||
const root = function* root() {
|
||||
yield takeLatest(CREATE_TEAM.REQUEST, handleRequest);
|
||||
yield takeLatest(CREATE_TEAM.SUCCESS, handleSuccess);
|
||||
yield takeLatest(CREATE_TEAM.FAILURE, handleFailure);
|
||||
};
|
||||
|
||||
export default root;
|
|
@ -5,6 +5,7 @@ import room from './room';
|
|||
import messages from './messages';
|
||||
import selectServer from './selectServer';
|
||||
import createChannel from './createChannel';
|
||||
import createTeam from './createTeam';
|
||||
import init from './init';
|
||||
import state from './state';
|
||||
import deepLinking from './deepLinking';
|
||||
|
@ -18,6 +19,7 @@ const root = function* root() {
|
|||
yield all([
|
||||
init(),
|
||||
createChannel(),
|
||||
createTeam(),
|
||||
rooms(),
|
||||
room(),
|
||||
login(),
|
||||
|
|
|
@ -376,13 +376,16 @@ class CreateChannelView extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
const { route } = ownProps;
|
||||
return {
|
||||
baseUrl: state.server.server,
|
||||
isFetching: state.createChannel.isFetching,
|
||||
isFetching: route?.params?.isTeam ? state.createTeam.isFetching : state.createChannel.isFetching,
|
||||
encryptionEnabled: state.encryption.enabled,
|
||||
users: state.selectedUsers.users,
|
||||
user: getUserSelector(state)
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
createChannel: data => dispatch(createChannelRequestAction(data)),
|
||||
|
|
Loading…
Reference in New Issue