mirror of https://github.com/grafana/grafana
Migration: Select org (#24739)
* Add SelectoOrgPage * Remove old code * Remove importpull/24773/head^2
parent
f0a161807a
commit
54ee4f4f72
@ -1,45 +0,0 @@ |
||||
import angular from 'angular'; |
||||
import config from 'app/core/config'; |
||||
import { getBackendSrv } from '@grafana/runtime'; |
||||
import { promiseToDigest } from 'app/core/utils/promiseToDigest'; |
||||
|
||||
export class SelectOrgCtrl { |
||||
/** @ngInject */ |
||||
constructor($scope: any, contextSrv: any) { |
||||
contextSrv.sidemenu = false; |
||||
|
||||
$scope.navModel = { |
||||
main: { |
||||
icon: 'grafana', |
||||
subTitle: 'Preferences', |
||||
text: 'Select active organization', |
||||
}, |
||||
}; |
||||
|
||||
$scope.init = () => { |
||||
$scope.getUserOrgs(); |
||||
}; |
||||
|
||||
$scope.getUserOrgs = () => { |
||||
promiseToDigest($scope)( |
||||
getBackendSrv() |
||||
.get('/api/user/orgs') |
||||
.then((orgs: any) => { |
||||
$scope.orgs = orgs; |
||||
}) |
||||
); |
||||
}; |
||||
|
||||
$scope.setUsingOrg = (org: any) => { |
||||
getBackendSrv() |
||||
.post('/api/user/using/' + org.orgId) |
||||
.then(() => { |
||||
window.location.href = config.appSubUrl + '/'; |
||||
}); |
||||
}; |
||||
|
||||
$scope.init(); |
||||
} |
||||
} |
||||
|
||||
angular.module('grafana.controllers').controller('SelectOrgCtrl', SelectOrgCtrl); |
@ -0,0 +1,58 @@ |
||||
import React, { FC, useState } from 'react'; |
||||
import Page from 'app/core/components/Page/Page'; |
||||
import { getBackendSrv, config } from '@grafana/runtime'; |
||||
import { UserOrg } from 'app/types'; |
||||
import { useAsync } from 'react-use'; |
||||
import { Button, HorizontalGroup } from '@grafana/ui'; |
||||
|
||||
const navModel = { |
||||
main: { |
||||
icon: 'grafana', |
||||
subTitle: 'Preferences', |
||||
text: 'Select active organization', |
||||
}, |
||||
node: { |
||||
text: 'Select active organization', |
||||
}, |
||||
}; |
||||
|
||||
const getUserOrgs = async () => { |
||||
return await getBackendSrv().get('/api/user/orgs'); |
||||
}; |
||||
const setUserOrg = async (org: UserOrg) => { |
||||
return await getBackendSrv() |
||||
.post('/api/user/using/' + org.orgId) |
||||
.then(() => { |
||||
window.location.href = config.appSubUrl + '/'; |
||||
}); |
||||
}; |
||||
|
||||
export const SelectOrgPage: FC = () => { |
||||
const [orgs, setOrgs] = useState<UserOrg[]>(); |
||||
|
||||
useAsync(async () => { |
||||
setOrgs(await getUserOrgs()); |
||||
}, []); |
||||
return ( |
||||
<Page navModel={navModel}> |
||||
<Page.Contents> |
||||
<div> |
||||
<p> |
||||
You have been added to another Organization due to an open invitation! Please select which organization you |
||||
want to use right now (you can change this later at any time). |
||||
</p> |
||||
<HorizontalGroup wrap> |
||||
{orgs && |
||||
orgs.map(org => ( |
||||
<Button key={org.orgId} icon="signin" onClick={() => setUserOrg(org)}> |
||||
{org.name} |
||||
</Button> |
||||
))} |
||||
</HorizontalGroup> |
||||
</div> |
||||
</Page.Contents> |
||||
</Page> |
||||
); |
||||
}; |
||||
|
||||
export default SelectOrgPage; |
@ -1 +0,0 @@ |
||||
import './SelectOrgCtrl'; |
@ -1,27 +0,0 @@ |
||||
<page-header model="navModel"></page-header> |
||||
|
||||
<div class="page-container page-body"> |
||||
|
||||
<div class="signup"> |
||||
<div class="login-form"> |
||||
|
||||
<div class="modal-tagline"> |
||||
You have been added to another Organization due to an open invitation! |
||||
|
||||
Please select which organization you want to <br> |
||||
use right now (you can change this later at any time). |
||||
</div> |
||||
|
||||
<div style="display: inline-block; width: 400px; margin: 30px 0"> |
||||
<div ng-repeat="org in orgs"> |
||||
<a ng-click="setUsingOrg(org)" class="btn btn-primary"> |
||||
{{org.name}} ({{org.role}}) |
||||
</a> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
|
||||
|
||||
<footer /> |
Loading…
Reference in new issue