@availity/feedback 6.2.10 → 6.2.14-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/SmileField.js CHANGED
@@ -1,79 +1,79 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { useField, useFormikContext } from 'formik';
4
- import FeedbackButton from './FeedbackButton';
5
-
6
- const btnStyles = { flex: 1, margin: '0 2% 0 2%' };
7
-
8
- const SmileField = ({ name, options, onChange, autoFocusFeedbackButton, onClose, modal }) => {
9
- const [{ value }] = useField(name);
10
- const { setFieldValue } = useFormikContext();
11
-
12
- return options.map((option, i) => (
13
- <FeedbackButton
14
- autoFocus={i === 0 && autoFocusFeedbackButton}
15
- onKeyDown={(e) => {
16
- if (e.shiftKey && e.keyCode === 9 && i === 0 && !modal) {
17
- onClose();
18
- }
19
- if (e.keyCode === 13) {
20
- setFieldValue(name, option);
21
- if (onChange) {
22
- onChange(option);
23
- }
24
- }
25
- }}
26
- style={btnStyles}
27
- key={option.icon}
28
- icon={option.icon}
29
- iconSize="2x"
30
- value={option}
31
- active={value && value.icon}
32
- onClick={() => {
33
- setFieldValue(name, option);
34
- if (onChange) {
35
- onChange(option);
36
- }
37
- }}
38
- >
39
- {option.description}
40
- </FeedbackButton>
41
- ));
42
- };
43
-
44
- SmileField.propTypes = {
45
- name: PropTypes.string.isRequired,
46
- options: PropTypes.arrayOf(
47
- PropTypes.shape({
48
- icon: PropTypes.string,
49
- description: PropTypes.string,
50
- label: PropTypes.string,
51
- })
52
- ),
53
- onChange: PropTypes.func,
54
- autoFocusFeedbackButton: PropTypes.bool,
55
- modal: PropTypes.bool
56
- };
57
-
58
- SmileField.defaultProps = {
59
- options: [
60
- {
61
- icon: 'smile',
62
- description: 'Smiley face',
63
- label: 'What do you like?',
64
- },
65
- {
66
- icon: 'meh',
67
- description: 'Meh face',
68
- label: 'What would you improve?',
69
- },
70
- {
71
- icon: 'frown',
72
- description: 'Frowny face',
73
- label: "What don't you like?",
74
- },
75
- ],
76
- autoFocusFeedbackButton: true,
77
- };
78
-
79
- export default SmileField;
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { useField, useFormikContext } from 'formik';
4
+ import FeedbackButton from './FeedbackButton';
5
+
6
+ const btnStyles = { flex: 1, margin: '0 2% 0 2%' };
7
+
8
+ const SmileField = ({ name, options, onChange, autoFocusFeedbackButton, onClose, modal }) => {
9
+ const [{ value }] = useField(name);
10
+ const { setFieldValue } = useFormikContext();
11
+
12
+ return options.map((option, i) => (
13
+ <FeedbackButton
14
+ autoFocus={i === 0 && autoFocusFeedbackButton}
15
+ onKeyDown={(e) => {
16
+ if (e.shiftKey && e.keyCode === 9 && i === 0 && !modal) {
17
+ onClose();
18
+ }
19
+ if (e.keyCode === 13) {
20
+ setFieldValue(name, option);
21
+ if (onChange) {
22
+ onChange(option);
23
+ }
24
+ }
25
+ }}
26
+ style={btnStyles}
27
+ key={option.icon}
28
+ icon={option.icon}
29
+ iconSize="2x"
30
+ value={option}
31
+ active={value && value.icon}
32
+ onClick={() => {
33
+ setFieldValue(name, option);
34
+ if (onChange) {
35
+ onChange(option);
36
+ }
37
+ }}
38
+ >
39
+ {option.description}
40
+ </FeedbackButton>
41
+ ));
42
+ };
43
+
44
+ SmileField.propTypes = {
45
+ name: PropTypes.string.isRequired,
46
+ options: PropTypes.arrayOf(
47
+ PropTypes.shape({
48
+ icon: PropTypes.string,
49
+ description: PropTypes.string,
50
+ label: PropTypes.string,
51
+ })
52
+ ),
53
+ onChange: PropTypes.func,
54
+ autoFocusFeedbackButton: PropTypes.bool,
55
+ modal: PropTypes.bool,
56
+ };
57
+
58
+ SmileField.defaultProps = {
59
+ options: [
60
+ {
61
+ icon: 'smile',
62
+ description: 'Smiley face',
63
+ label: 'What do you like?',
64
+ },
65
+ {
66
+ icon: 'meh',
67
+ description: 'Meh face',
68
+ label: 'What would you improve?',
69
+ },
70
+ {
71
+ icon: 'frown',
72
+ description: 'Frowny face',
73
+ label: "What don't you like?",
74
+ },
75
+ ],
76
+ autoFocusFeedbackButton: true,
77
+ };
78
+
79
+ export default SmileField;
@@ -1,149 +1,149 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- import { Button, ModalBody, ModalHeader, ModalFooter } from 'reactstrap';
4
- import { Form } from '@availity/form';
5
- import { AvOrganizationSelect } from '@availity/select/resources';
6
- import * as yup from 'yup';
7
- import nativeForm from '@availity/native-form';
8
- import { avOrganizationsApi, avWebQLApi } from '@availity/api-axios';
9
- import '@availity/yup';
10
-
11
- const SUPPORT_PERMISSION_ID = '7205';
12
-
13
- const ORG_VALIDATION_MESSAGE = 'Please select an organization from the dropdown.';
14
-
15
- const getToken = () => document.cookie.replace(/(?:(?:^|.*;\s*)XSRF-TOKEN\s*=\s*([^;]*).*$)|^.*$/, '$1');
16
-
17
- const openSupport = async (values, setBlocking, setSupportIsActive, feedbackToggle) => {
18
- setBlocking(true);
19
- const orgsResp = await avOrganizationsApi.getOrganizations(SUPPORT_PERMISSION_ID);
20
- let salesforceResponse;
21
- if (orgsResp.data.organizations.some((org) => org.id === values.organization.id)) {
22
- salesforceResponse = await avWebQLApi.create({
23
- query: `
24
- query salesforceUser($organizationId: ID!) {
25
- salesforceUser(organizationId: $organizationId) {
26
- id
27
- accountId
28
- newCommunity
29
- }
30
- }
31
- `,
32
- variables: {
33
- organizationId: values.organization.id,
34
- },
35
- });
36
- }
37
-
38
- let href = 'mailto:support@availity.com';
39
- const target = '_top';
40
-
41
- if (!salesforceResponse || !salesforceResponse.data) {
42
- window.open(href, target);
43
- }
44
-
45
- const salesforceData = salesforceResponse.data.data.salesforceUser;
46
- const ssoId = 'BJx3fqX3BH';
47
- const newCommutySsoId = 'E-t_s_JQ0P';
48
-
49
- if (salesforceData) {
50
- const attributes = {
51
- orgGenKey: values.organization.customerId,
52
- organizationName: values.organization.name,
53
- partyId: values.organization.id,
54
- payerId: 'AVAILITY',
55
- X_Client_ID: '5430d59f-c5cc-4be7-be5a-34472ec30fe9',
56
- X_XSRF_TOKEN: getToken(),
57
- };
58
-
59
- if (salesforceData.id && salesforceData.accountId) {
60
- attributes.avSalesForceContactId = salesforceData.id;
61
- attributes.avSalesForceContactAccId = salesforceData.accountId;
62
- }
63
-
64
- href = `/ms/api/availity/internal/spc/magneto/sso/v1/saml/${salesforceData.newCommunity ? newCommutySsoId : ssoId}`;
65
-
66
- await nativeForm(ssoId, attributes, { action: href, target: '_blank' }, 'saml');
67
- setBlocking(false);
68
- } else {
69
- window.open(href, target);
70
- }
71
- setSupportIsActive(false);
72
- feedbackToggle(false);
73
- };
74
-
75
- function orgSelectTest(msg) {
76
- const orgSelectSchema = yup.object().shape({
77
- id: yup.string().isRequired(true, ORG_VALIDATION_MESSAGE),
78
- name: yup.string().isRequired(true, ORG_VALIDATION_MESSAGE),
79
- });
80
-
81
- return this.test({
82
- name: 'orgSelectTest',
83
- exclusive: true,
84
- message: msg || 'This field is invalid.',
85
- async test(componentValue) {
86
- if (!componentValue) return true;
87
-
88
- const valid = await orgSelectSchema.isValid(componentValue);
89
- return valid;
90
- },
91
- });
92
- }
93
-
94
- yup.addMethod(yup.object, 'orgSelectTest', orgSelectTest);
95
-
96
- const SupportForm = ({ setSupportIsActive, setBlocking, feedbackToggle }) => (
97
- <>
98
- <ModalHeader id="support-form-header" role="heading" aria-level="2" className="h5" tag="div">
99
- Open Support Ticket
100
- </ModalHeader>
101
- <Form
102
- aria-label="Support Form"
103
- aria-describedby="support-form-header"
104
- role="form"
105
- data-testid="support-form"
106
- initialValues={{
107
- organization: undefined,
108
- }}
109
- validationSchema={yup.object({
110
- organization: yup
111
- .object()
112
- .orgSelectTest(ORG_VALIDATION_MESSAGE)
113
- .isRequired(ORG_VALIDATION_MESSAGE)
114
- .typeError(ORG_VALIDATION_MESSAGE),
115
- })}
116
- onSubmit={(values) => openSupport(values, setBlocking, setSupportIsActive, feedbackToggle)}
117
- >
118
- <ModalBody>
119
- <AvOrganizationSelect
120
- name="organization"
121
- label="Select an Organization"
122
- data-testid="org-dropdown"
123
- getResult={(data) => data.organizations}
124
- />
125
- </ModalBody>
126
- <ModalFooter>
127
- <Button
128
- onClick={() => setSupportIsActive(false)}
129
- color="secondary"
130
- type="button"
131
- onKeyDown={({ keyCode }) => keyCode === 13 && setSupportIsActive(false)}
132
- >
133
- Close
134
- </Button>
135
- <Button data-testid="submit-btn" type="submit" color="primary">
136
- Continue
137
- </Button>
138
- </ModalFooter>
139
- </Form>
140
- </>
141
- );
142
-
143
- SupportForm.propTypes = {
144
- setSupportIsActive: PropTypes.func,
145
- setBlocking: PropTypes.func,
146
- feedbackToggle: PropTypes.func,
147
- };
148
-
149
- export default SupportForm;
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Button, ModalBody, ModalHeader, ModalFooter } from 'reactstrap';
4
+ import { Form } from '@availity/form';
5
+ import { AvOrganizationSelect } from '@availity/select/resources';
6
+ import * as yup from 'yup';
7
+ import nativeForm from '@availity/native-form';
8
+ import { avOrganizationsApi, avWebQLApi } from '@availity/api-axios';
9
+ import '@availity/yup';
10
+
11
+ const SUPPORT_PERMISSION_ID = '7205';
12
+
13
+ const ORG_VALIDATION_MESSAGE = 'Please select an organization from the dropdown.';
14
+
15
+ const getToken = () => document.cookie.replace(/(?:(?:^|.*;\s*)XSRF-TOKEN\s*=\s*([^;]*).*$)|^.*$/, '$1');
16
+
17
+ const openSupport = async (values, setBlocking, setSupportIsActive, feedbackToggle) => {
18
+ setBlocking(true);
19
+ const orgsResp = await avOrganizationsApi.getOrganizations(SUPPORT_PERMISSION_ID);
20
+ let salesforceResponse;
21
+ if (orgsResp.data.organizations.some((org) => org.id === values.organization.id)) {
22
+ salesforceResponse = await avWebQLApi.create({
23
+ query: `
24
+ query salesforceUser($organizationId: ID!) {
25
+ salesforceUser(organizationId: $organizationId) {
26
+ id
27
+ accountId
28
+ newCommunity
29
+ }
30
+ }
31
+ `,
32
+ variables: {
33
+ organizationId: values.organization.id,
34
+ },
35
+ });
36
+ }
37
+
38
+ let href = 'mailto:support@availity.com';
39
+ const target = '_top';
40
+
41
+ if (!salesforceResponse || !salesforceResponse.data) {
42
+ window.open(href, target);
43
+ }
44
+
45
+ const salesforceData = salesforceResponse.data.data.salesforceUser;
46
+ const ssoId = 'BJx3fqX3BH';
47
+ const newCommutySsoId = 'E-t_s_JQ0P';
48
+
49
+ if (salesforceData) {
50
+ const attributes = {
51
+ orgGenKey: values.organization.customerId,
52
+ organizationName: values.organization.name,
53
+ partyId: values.organization.id,
54
+ payerId: 'AVAILITY',
55
+ X_Client_ID: '5430d59f-c5cc-4be7-be5a-34472ec30fe9',
56
+ X_XSRF_TOKEN: getToken(),
57
+ };
58
+
59
+ if (salesforceData.id && salesforceData.accountId) {
60
+ attributes.avSalesForceContactId = salesforceData.id;
61
+ attributes.avSalesForceContactAccId = salesforceData.accountId;
62
+ }
63
+
64
+ href = `/ms/api/availity/internal/spc/magneto/sso/v1/saml/${salesforceData.newCommunity ? newCommutySsoId : ssoId}`;
65
+
66
+ await nativeForm(ssoId, attributes, { action: href, target: '_blank' }, 'saml');
67
+ setBlocking(false);
68
+ } else {
69
+ window.open(href, target);
70
+ }
71
+ setSupportIsActive(false);
72
+ feedbackToggle(false);
73
+ };
74
+
75
+ function orgSelectTest(msg) {
76
+ const orgSelectSchema = yup.object().shape({
77
+ id: yup.string().isRequired(true, ORG_VALIDATION_MESSAGE),
78
+ name: yup.string().isRequired(true, ORG_VALIDATION_MESSAGE),
79
+ });
80
+
81
+ return this.test({
82
+ name: 'orgSelectTest',
83
+ exclusive: true,
84
+ message: msg || 'This field is invalid.',
85
+ async test(componentValue) {
86
+ if (!componentValue) return true;
87
+
88
+ const valid = await orgSelectSchema.isValid(componentValue);
89
+ return valid;
90
+ },
91
+ });
92
+ }
93
+
94
+ yup.addMethod(yup.object, 'orgSelectTest', orgSelectTest);
95
+
96
+ const SupportForm = ({ setSupportIsActive, setBlocking, feedbackToggle }) => (
97
+ <>
98
+ <ModalHeader id="support-form-header" role="heading" aria-level="2" className="h5" tag="div">
99
+ Open Support Ticket
100
+ </ModalHeader>
101
+ <Form
102
+ aria-label="Support Form"
103
+ aria-describedby="support-form-header"
104
+ role="form"
105
+ data-testid="support-form"
106
+ initialValues={{
107
+ organization: undefined,
108
+ }}
109
+ validationSchema={yup.object({
110
+ organization: yup
111
+ .object()
112
+ .orgSelectTest(ORG_VALIDATION_MESSAGE)
113
+ .isRequired(ORG_VALIDATION_MESSAGE)
114
+ .typeError(ORG_VALIDATION_MESSAGE),
115
+ })}
116
+ onSubmit={(values) => openSupport(values, setBlocking, setSupportIsActive, feedbackToggle)}
117
+ >
118
+ <ModalBody>
119
+ <AvOrganizationSelect
120
+ name="organization"
121
+ label="Select an Organization"
122
+ data-testid="org-dropdown"
123
+ getResult={(data) => data.organizations}
124
+ />
125
+ </ModalBody>
126
+ <ModalFooter>
127
+ <Button
128
+ onClick={() => setSupportIsActive(false)}
129
+ color="secondary"
130
+ type="button"
131
+ onKeyDown={({ keyCode }) => keyCode === 13 && setSupportIsActive(false)}
132
+ >
133
+ Close
134
+ </Button>
135
+ <Button data-testid="submit-btn" type="submit" color="primary">
136
+ Continue
137
+ </Button>
138
+ </ModalFooter>
139
+ </Form>
140
+ </>
141
+ );
142
+
143
+ SupportForm.propTypes = {
144
+ setSupportIsActive: PropTypes.func,
145
+ setBlocking: PropTypes.func,
146
+ feedbackToggle: PropTypes.func,
147
+ };
148
+
149
+ export default SupportForm;