mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 16:15:42 -06:00
* UserProfile: Fixes infinite loading spinner * Refactor: some clean up * Refactor: some more cleanup * Tests: Adds tests for UserProfileEditPage * Chore: updates after PR comments * Refactor: removes unnecessary unmount/mount
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import { getBackendSrv } from '@grafana/runtime';
|
|
|
|
import { ChangePasswordFields, ProfileUpdateFields } from './types';
|
|
import { Team, UserDTO, UserOrg, UserSession } from '../../types';
|
|
|
|
async function changePassword(payload: ChangePasswordFields): Promise<void> {
|
|
try {
|
|
await getBackendSrv().put('/api/user/password', payload);
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
function loadUser(): Promise<UserDTO> {
|
|
return getBackendSrv().get('/api/user');
|
|
}
|
|
|
|
function loadTeams(): Promise<Team[]> {
|
|
return getBackendSrv().get('/api/user/teams');
|
|
}
|
|
|
|
function loadOrgs(): Promise<UserOrg[]> {
|
|
return getBackendSrv().get('/api/user/orgs');
|
|
}
|
|
|
|
function loadSessions(): Promise<UserSession[]> {
|
|
return getBackendSrv().get('/api/user/auth-tokens');
|
|
}
|
|
|
|
async function revokeUserSession(tokenId: number): Promise<void> {
|
|
await getBackendSrv().post('/api/user/revoke-auth-token', {
|
|
authTokenId: tokenId,
|
|
});
|
|
}
|
|
|
|
async function setUserOrg(org: UserOrg): Promise<void> {
|
|
await getBackendSrv().post('/api/user/using/' + org.orgId, {});
|
|
}
|
|
|
|
async function updateUserProfile(payload: ProfileUpdateFields): Promise<void> {
|
|
try {
|
|
await getBackendSrv().put('/api/user', payload);
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
}
|
|
|
|
export const api = {
|
|
changePassword,
|
|
revokeUserSession,
|
|
loadUser,
|
|
loadSessions,
|
|
loadOrgs,
|
|
loadTeams,
|
|
setUserOrg,
|
|
updateUserProfile,
|
|
};
|