-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathoidc-providers-import.gjs
67 lines (61 loc) · 2.08 KB
/
oidc-providers-import.gjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import PixButtonUpload from '@1024pix/pix-ui/components/pix-button-upload';
import { action } from '@ember/object';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { t } from 'ember-intl';
import ENV from 'pix-admin/config/environment';
import AdministrationBlockLayout from '../block-layout';
export default class OidcProvidersImport extends Component {
@service intl;
@service pixToast;
@service session;
@action
async importOidcProviders(files) {
let response;
try {
const fileContent = files[0];
const token = this.session.data.authenticated.access_token;
response = await fetch(`${ENV.APP.API_HOST}/api/admin/oidc-providers/import`, {
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
Accept: 'application/json',
},
method: 'POST',
body: fileContent,
});
if (response.ok) {
this.pixToast.sendSuccessNotification({
message: this.intl.t('components.administration.oidc-providers-import.notifications.success'),
});
return;
}
const jsonResponse = await response.json();
if (!jsonResponse.errors) {
throw new Error('Generic error');
}
jsonResponse.errors.forEach((error) => {
this.pixToast.sendErrorNotification({ message: error.detail });
});
} catch {
this.pixToast.sendErrorNotification({ message: this.intl.t('common.notifications.generic-error') });
} finally {
this.isLoading = false;
}
}
<template>
<AdministrationBlockLayout
@title={{t "components.administration.oidc-providers-import.title"}}
@description={{t "components.administration.oidc-providers-import.description"}}
>
<PixButtonUpload
@id="oidc-providers-file-upload"
@onChange={{this.importOidcProviders}}
@variant="secondary"
accept=".json"
>
{{t "components.administration.oidc-providers-import.upload-button"}}
</PixButtonUpload>
</AdministrationBlockLayout>
</template>
}