-
Notifications
You must be signed in to change notification settings - Fork 180
/
user-agreement.examples.tsx
130 lines (113 loc) · 3.02 KB
/
user-agreement.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React, {Component} from 'react';
import {Story} from '@storybook/react';
import reactDecorator from '../../.storybook/react-decorator';
import alert from '../alert-service/alert-service';
import UserAgreement, {UserAgreementAttrs} from './user-agreement';
import UserAgreementService, {Agreement, Consent, ConsentResponse} from './service';
import text from './toolbox.eula';
export default {
title: 'Components/User Agreement',
decorators: [reactDecorator()],
parameters: {
component: UserAgreement,
framework: 'react',
hermione: {captureSelector: '*[data-test~=ring-dialog]'},
a11y: {element: '*[data-test~=ring-dialog]'}
}
};
export const dialog: Story<UserAgreementAttrs> = args => (
<div>
<UserAgreement {...args}/>
</div>
);
dialog.args = {
show: true,
text,
onRemindLater: null
};
dialog.argTypes = {
onRemindLater: {}
};
dialog.parameters = {
actions: {argTypesRegex: '^on(?!RemindLater).*'}
};
dialog.storyName = 'dialog';
function noop() {}
interface ServiceArgs {
onGetUserAgreement?: ((agreement: Agreement) => void) | undefined
onGetUserConsent?: ((response: ConsentResponse) => void) | undefined
onSetUserConsent?: ((consent: Consent) => void) | undefined
onAccept?: (() => void) | null | undefined
onDecline?: (() => void) | null | undefined
onDialogShow?: (() => void) | null | undefined
onDialogHide?: (() => void) | null | undefined
}
export const service: Story<ServiceArgs> = ({
onGetUserAgreement = noop,
onGetUserConsent = noop,
onSetUserConsent = noop,
onAccept,
onDecline,
onDialogShow,
onDialogHide
}) => {
const fakeUserAgreement: Agreement = {
enabled: true,
majorVersion: 1.0,
text
};
const fakeUserConsent: Consent = {
accepted: false
};
const fakeUserConsentResponse: ConsentResponse = {
guest: true,
endUserAgreementConsent: fakeUserConsent
};
const agreementService = new UserAgreementService({
getUserAgreement: () => {
onGetUserAgreement(fakeUserAgreement);
return fakeUserAgreement;
},
getUserConsent: () => {
onGetUserConsent(fakeUserConsentResponse);
return fakeUserConsentResponse;
},
setUserConsent: () => {
onSetUserConsent(fakeUserConsent);
return fakeUserConsent;
},
onAccept,
onDecline,
onDialogShow,
onDialogHide,
interval: 10000
});
class UserAgreementServiceDemo extends Component {
componentDidMount() {
agreementService.startChecking();
}
componentWillUnmount() {
agreementService.stopChecking();
alert._getShowingAlerts().forEach(item => alert.removeWithoutAnimation(item.key));
}
render() {
return null;
}
}
return <UserAgreementServiceDemo/>;
};
service.argTypes = {
onGetUserAgreement: {},
onGetUserConsent: {},
onSetUserConsent: {},
onAccept: {},
onDecline: {},
onDialogShow: {},
onDialogHide: {}
};
service.storyName = 'service';
service.parameters = {
component: null,
hermione: {skip: true},
a11y: {element: '*[data-test="alert-container"]'}
};