mirror of
https://github.com/desktop/desktop
synced 2024-11-05 20:49:32 +00:00
Remove some users
This commit is contained in:
parent
e900396337
commit
7b51de52c2
5 changed files with 38 additions and 3 deletions
|
@ -30,6 +30,12 @@ export interface IAddUserAction {
|
|||
readonly user: IUser
|
||||
}
|
||||
|
||||
/** Remove a user from the app. */
|
||||
export interface IRemoveUserAction {
|
||||
readonly name: 'remove-user'
|
||||
readonly user: IUser
|
||||
}
|
||||
|
||||
export type Action = IGetUsersAction | IGetRepositoriesAction |
|
||||
IAddRepositoriesAction | IUpdateGitHubRepositoryAction |
|
||||
IRemoveRepositoriesAction | IAddUserAction
|
||||
IRemoveRepositoriesAction | IAddUserAction | IRemoveUserAction
|
||||
|
|
|
@ -391,4 +391,9 @@ export class Dispatcher {
|
|||
public async addUser(user: User): Promise<void> {
|
||||
return this.dispatchToSharedProcess<void>({ name: 'add-user', user })
|
||||
}
|
||||
|
||||
/** Remove the given user. */
|
||||
public removeUser(user: User): Promise<void> {
|
||||
return this.dispatchToSharedProcess<void>({ name: 'remove-user', user })
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,12 @@ register('add-user', async ({ user }: IAddUserAction) => {
|
|||
return Promise.resolve()
|
||||
})
|
||||
|
||||
register('remove-user', async ({ user }: IAddUserAction) => {
|
||||
usersStore.removeUser(User.fromJSON(user))
|
||||
broadcastUpdate()
|
||||
return Promise.resolve()
|
||||
})
|
||||
|
||||
register('add-repositories', async ({ paths }: IAddRepositoriesAction) => {
|
||||
const addedRepos: Repository[] = []
|
||||
for (const path of paths) {
|
||||
|
|
|
@ -26,6 +26,18 @@ export class UsersStore {
|
|||
this.save()
|
||||
}
|
||||
|
||||
/** Remove the user from the store. */
|
||||
public removeUser(user: User) {
|
||||
this.secureStore.deleteItem(getKeyForUser(user), user.login)
|
||||
|
||||
const index = this.users.findIndex(u => u.id === user.id)
|
||||
if (index > -1) {
|
||||
this.users.splice(index, 1)
|
||||
}
|
||||
|
||||
this.save()
|
||||
}
|
||||
|
||||
/** Change the users in the store by mapping over them. */
|
||||
public async map(fn: (user: User) => Promise<User>) {
|
||||
const users = new Array<User>()
|
||||
|
|
|
@ -15,11 +15,11 @@ export class Accounts extends React.Component<IAccountsProps, void> {
|
|||
<div>
|
||||
<h2>GitHub.com</h2>
|
||||
{this.props.dotComUser ? this.renderUser(this.props.dotComUser) : null}
|
||||
<Button onClick={this.logOutDotCom}>Log Out</Button>
|
||||
<Button disabled={!this.props.dotComUser} onClick={this.logOutDotCom}>Log Out</Button>
|
||||
|
||||
<h2>Enterprise</h2>
|
||||
{this.props.enterpriseUser ? this.renderUser(this.props.enterpriseUser) : null}
|
||||
<Button onClick={this.logOutEnterprise}>Log Out</Button>
|
||||
<Button disabled={!this.props.dotComUser} onClick={this.logOutEnterprise}>Log Out</Button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -34,10 +34,16 @@ export class Accounts extends React.Component<IAccountsProps, void> {
|
|||
}
|
||||
|
||||
private logOutDotCom = () => {
|
||||
const user = this.props.dotComUser
|
||||
if (!user) { return }
|
||||
|
||||
this.props.dispatcher.removeUser(user)
|
||||
}
|
||||
|
||||
private logOutEnterprise = () => {
|
||||
const user = this.props.enterpriseUser
|
||||
if (!user) { return }
|
||||
|
||||
this.props.dispatcher.removeUser(user)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue