Browse Source

Fixed all remaining team features

master
Leo Lamprecht 7 years ago
parent
commit
9492e395ca
  1. 4
      src/providers/sh/commands/teams.js
  2. 17
      src/providers/sh/commands/teams/add.js
  3. 9
      src/providers/sh/commands/teams/invite.js
  4. 6
      src/providers/sh/commands/teams/list.js

4
src/providers/sh/commands/teams.js

@ -141,7 +141,7 @@ async function run({ token, config }) {
case 'ls': { case 'ls': {
await list({ await list({
teams, teams,
token config
}) })
break break
} }
@ -164,7 +164,7 @@ async function run({ token, config }) {
await invite({ await invite({
teams, teams,
args, args,
token config
}) })
break break
} }

17
src/providers/sh/commands/teams/add.js

@ -15,16 +15,16 @@ const note = require('../../../../util/output/note')
const uid = require('../../../../util/output/uid') const uid = require('../../../../util/output/uid')
const textInput = require('../../../../util/input/text') const textInput = require('../../../../util/input/text')
const exit = require('../../../../util/exit') const exit = require('../../../../util/exit')
const cfg = require('../../util/cfg')
const invite = require('./invite') const invite = require('./invite')
const {writeToConfigFile} = require('../../../../util/config-files')
function validateSlugKeypress(data, value) { const validateSlugKeypress = (data, value) => {
// TODO: the `value` here should contain the current value + the keypress // TODO: the `value` here should contain the current value + the keypress
// should be fixed on utils/input/text.js // should be fixed on utils/input/text.js
return /^[a-zA-Z]+[a-zA-Z0-9_-]*$/.test(value + data) return /^[a-zA-Z]+[a-zA-Z0-9_-]*$/.test(value + data)
} }
function gracefulExit() { const gracefulExit = () => {
console.log() // Blank line console.log() // Blank line
note( note(
`Your team is now active for all ${cmd('now')} commands!\n Run ${cmd( `Your team is now active for all ${cmd('now')} commands!\n Run ${cmd(
@ -37,7 +37,7 @@ function gracefulExit() {
const teamUrlPrefix = rightPad('Team URL', 14) + chalk.gray('zeit.co/') const teamUrlPrefix = rightPad('Team URL', 14) + chalk.gray('zeit.co/')
const teamNamePrefix = rightPad('Team Name', 14) const teamNamePrefix = rightPad('Team Name', 14)
module.exports = async function({ teams, token }) { module.exports = async function({ teams, config }) {
let slug let slug
let team let team
let elapsed let elapsed
@ -118,13 +118,18 @@ module.exports = async function({ teams, token }) {
console.log(chalk.cyan(`${tick} `) + teamNamePrefix + team.name + '\n') console.log(chalk.cyan(`${tick} `) + teamNamePrefix + team.name + '\n')
stopSpinner = wait('Saving') stopSpinner = wait('Saving')
await cfg.merge({ currentTeam: team })
// Update config file
const configCopy = Object.assign({}, config)
configCopy.sh.currentTeam = team
writeToConfigFile(configCopy)
stopSpinner() stopSpinner()
await invite({ await invite({
teams, teams,
args: [], args: [],
token, config,
introMsg: introMsg:
'Invite your team mates! When done, press enter on an empty field', 'Invite your team mates! When done, press enter on an empty field',
noopMsg: `You can invite team mates later by running ${cmd( noopMsg: `You can invite team mates later by running ${cmd(

9
src/providers/sh/commands/teams/invite.js

@ -4,7 +4,6 @@ const chalk = require('chalk')
// Utilities // Utilities
const regexes = require('../../../../util/input/regexes') const regexes = require('../../../../util/input/regexes')
const wait = require('../../../../util/output/wait') const wait = require('../../../../util/output/wait')
const cfg = require('../../util/cfg')
const fatalError = require('../../../../util/fatal-error') const fatalError = require('../../../../util/fatal-error')
const cmd = require('../../../../util/output/cmd') const cmd = require('../../../../util/output/cmd')
const info = require('../../../../util/output/info') const info = require('../../../../util/output/info')
@ -17,7 +16,7 @@ const eraseLines = require('../../../../util/output/erase-lines')
const success = require('../../../../util/output/success') const success = require('../../../../util/output/success')
const error = require('../../../../util/output/error') const error = require('../../../../util/output/error')
function validateEmail(data) { const validateEmail = data => {
return regexes.email.test(data.trim()) || data.length === 0 return regexes.email.test(data.trim()) || data.length === 0
} }
@ -38,7 +37,7 @@ const domains = Array.from(
]) ])
) )
function emailAutoComplete(value, teamSlug) { const emailAutoComplete = (value, teamSlug) => {
const parts = value.split('@') const parts = value.split('@')
if (parts.length === 2 && parts[1].length > 0) { if (parts.length === 2 && parts[1].length > 0) {
@ -61,9 +60,9 @@ function emailAutoComplete(value, teamSlug) {
} }
module.exports = async function( module.exports = async function(
{ teams, args, token, introMsg, noopMsg = 'No changes made' } = {} { teams, args, config, introMsg, noopMsg = 'No changes made' } = {}
) { ) {
const { user, currentTeam } = await cfg.read({ token }) const { user, currentTeam } = config.sh
domains.push(user.email.split('@')[1]) domains.push(user.email.split('@')[1])

6
src/providers/sh/commands/teams/list.js

@ -3,17 +3,17 @@ const chalk = require('chalk')
// Utilities // Utilities
const wait = require('../../../../util/output/wait') const wait = require('../../../../util/output/wait')
const cfg = require('../../util/cfg')
const info = require('../../../../util/output/info') const info = require('../../../../util/output/info')
const error = require('../../../../util/output/error') const error = require('../../../../util/output/error')
const { tick: tickChar } = require('../../../../util/output/chars') const { tick: tickChar } = require('../../../../util/output/chars')
const table = require('../../../../util/output/table') const table = require('../../../../util/output/table')
module.exports = async function({ teams, token }) { module.exports = async function({ teams, config }) {
const stopSpinner = wait('Fetching teams') const stopSpinner = wait('Fetching teams')
const list = (await teams.ls()).teams const list = (await teams.ls()).teams
let { user, currentTeam } = await cfg.read({ token }) let { user, currentTeam } = config.sh
const accountIsCurrent = !currentTeam const accountIsCurrent = !currentTeam
stopSpinner() stopSpinner()
if (accountIsCurrent) { if (accountIsCurrent) {

Loading…
Cancel
Save