-
Notifications
You must be signed in to change notification settings - Fork 182
/
auth-dialog.examples.tsx
88 lines (73 loc) · 1.98 KB
/
auth-dialog.examples.tsx
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from 'react';
import reactDecorator from '../../.storybook/react-decorator';
import Button from '../button/button';
import AuthDialog from './auth-dialog';
// eslint-disable-next-line import/order
import youtrackLogo from '!file-loader!@jetbrains/logos/youtrack/youtrack.svg';
export default {
title: 'Components/Auth Dialog',
decorators: [reactDecorator()],
parameters: {
notes: 'A component that shows an authentication dialog.',
hermione: {captureSelector: '*[data-test~=ring-dialog]'},
a11y: {element: '*[data-test~=ring-dialog]'}
}
};
interface AuthDialogArgs {
onConfirm: () => void
onCancel: () => void
}
export const authDialog = ({onConfirm, onCancel}: AuthDialogArgs) => {
class AuthDialogDemo extends React.Component {
state = {
confirm: {
show: true,
onConfirm: () => {},
onReject: () => {}
}
};
componentDidMount() {
this.showAuthDialog();
}
hideAuthDialog = () => {
this.setState({confirm: {show: false}});
};
showAuthDialog = () =>
new Promise<void>((resolve, reject) => {
this.setState({
confirm: {
show: true,
errorMessage: 'Authorization is required',
serviceName: 'YouTrack',
onConfirm: () => {
this.hideAuthDialog();
resolve();
},
onCancel: () => {
this.hideAuthDialog();
reject();
}
}
});
}).
then(onConfirm).
catch(onCancel);
render() {
return (
<div>
<div>
<Button onClick={this.showAuthDialog}>Show dialog</Button>
</div>
<AuthDialog
{...this.state.confirm}
serviceImage={youtrackLogo}
confirmLabel="Log in"
cancelLabel="Stay a guest"
/>
</div>
);
}
}
return <AuthDialogDemo/>;
};
authDialog.argTypes = {onConfirm: {}, onCancel: {}};