Skip to content

Commit f5cd6ec

Browse files
committed
move feedback class to integration.ts, make isAnonymous work, hide false in createElement
1 parent 1fbd163 commit f5cd6ec

File tree

9 files changed

+524
-497
lines changed

9 files changed

+524
-497
lines changed

packages/feedback/src/index.ts

Lines changed: 2 additions & 417 deletions
Large diffs are not rendered by default.

packages/feedback/src/integration.ts

Lines changed: 422 additions & 0 deletions
Large diffs are not rendered by default.

packages/feedback/src/types/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,22 @@ export interface FeedbackConfigurationWithDefaults {
5252
isAnonymous: boolean;
5353

5454
/**
55-
* Should the email field be required
55+
* Should the email field be required?
5656
*/
5757
isEmailRequired: boolean;
5858

5959
/**
60-
* Should the name field be required
60+
* Should the name field be required?
6161
*/
6262
isNameRequired: boolean;
6363

6464
/**
65-
* Should the email input field be visible?
65+
* Should the email input field be visible? Note: email will still be collected if set via `Sentry.setUser()`
6666
*/
6767
showEmail: boolean;
68+
6869
/**
69-
* Should the name input field be visible?
70+
* Should the name input field be visible? Note: name will still be collected if set via `Sentry.setUser()`
7071
*/
7172
showName: boolean;
7273

packages/feedback/src/util/handleFeedbackSubmit.ts

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,40 @@ import type { FeedbackFormData } from '../types';
22
import { DialogComponent } from '../widget/Dialog';
33
import { sendFeedback } from '../sendFeedback';
44

5-
export async function handleFeedbackSubmit(dialog: DialogComponent|null, feedback: FeedbackFormData): Promise<Response | false> {
5+
export async function handleFeedbackSubmit(
6+
dialog: DialogComponent | null,
7+
feedback: FeedbackFormData,
8+
): Promise<Response | false> {
9+
if (!dialog) {
10+
// Not sure when this would happen
11+
return false;
12+
}
13+
14+
const showFetchError = () => {
615
if (!dialog) {
7-
// Not sure when this would happen
8-
return false;
16+
return;
917
}
18+
dialog.setSubmitEnabled();
19+
dialog.showError('There was a problem submitting feedback, please wait and try again.');
20+
};
1021

11-
const showFetchError = () => {
12-
if (!dialog) {
13-
return;
14-
}
15-
dialog.setSubmitEnabled();
16-
dialog.showError('There was a problem submitting feedback, please wait and try again.');
17-
};
18-
19-
try {
20-
dialog.hideError();
21-
dialog.setSubmitDisabled();
22-
const resp = await sendFeedback(feedback);
23-
console.log({ resp });
22+
try {
23+
dialog.hideError();
24+
dialog.setSubmitDisabled();
25+
const resp = await sendFeedback(feedback);
26+
console.log({ resp });
2427

25-
if (!resp) {
26-
// Errored... re-enable submit button
27-
showFetchError();
28-
return false;
29-
}
30-
31-
// Success!
32-
return resp;
33-
} catch {
28+
if (!resp) {
3429
// Errored... re-enable submit button
3530
showFetchError();
3631
return false;
3732
}
33+
34+
// Success!
35+
return resp;
36+
} catch {
37+
// Errored... re-enable submit button
38+
showFetchError();
39+
return false;
40+
}
3841
}

packages/feedback/src/widget/Actor.css.ts

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,9 @@
1-
import type { FeedbackTheme } from '../types';
2-
31
/**
42
* Creates <style> element for widget actor (button that opens the dialog)
53
*/
6-
export function createActorStyles(d: Document, theme: FeedbackTheme): HTMLStyleElement {
4+
export function createActorStyles(d: Document): HTMLStyleElement {
75
const style = d.createElement('style');
86
style.textContent = `
9-
:host {
10-
position: fixed;
11-
right: 1rem;
12-
bottom: 1rem;
13-
font-family: 'Helvetica Neue', Arial, sans-serif;
14-
font-size: 14px;
15-
--bg-color: ${theme.light.background};
16-
--bg-hover-color: #f6f6f7;
17-
--fg-color: ${theme.light.foreground};
18-
--error-color: #df3338;
19-
--success-color: #268d75;
20-
--border: 1.5px solid rgba(41, 35, 47, 0.13);
21-
--box-shadow: 0px 4px 24px 0px rgba(43, 34, 51, 0.12);
22-
}
23-
24-
.__dark-mode:host {
25-
--bg-color: ${theme.dark.background};
26-
--bg-hover-color: #352f3b;
27-
--fg-color: ${theme.dark.foreground};
28-
--error-color: #f55459;
29-
--success-color: #2da98c;
30-
--border: 1.5px solid rgba(235, 230, 239, 0.15);
31-
--box-shadow: 0px 4px 24px 0px rgba(43, 34, 51, 0.12);
32-
}
33-
347
.widget__actor {
358
line-height: 25px;
369

packages/feedback/src/widget/Dialog.css.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import type { FeedbackTheme } from '../types';
2-
31
/**
42
* Creates <style> element for widget dialog
53
*/
6-
export function createDialogStyles(d: Document, theme: FeedbackTheme): HTMLStyleElement {
4+
export function createDialogStyles(d: Document): HTMLStyleElement {
75
const style = d.createElement('style');
86

97
style.textContent = `

packages/feedback/src/widget/Form.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ export function Form({ defaultName, defaultEmail, onCancel, onSubmit, options }:
100100

101101
const $name = h('input', {
102102
id: 'name',
103-
type: 'text', // TODO can be hidden
104-
ariaHidden: 'false',
103+
type: options.showName ? 'text' : 'hidden',
104+
ariaHidden: options.showName ? 'false' : 'true',
105105
name: 'name',
106106
className: 'form__input',
107107
placeholder: options.namePlaceholder,
@@ -110,8 +110,8 @@ export function Form({ defaultName, defaultEmail, onCancel, onSubmit, options }:
110110

111111
const $email = h('input', {
112112
id: 'email',
113-
type: 'text', // TODO can be hidden
114-
ariaHidden: 'false',
113+
type: options.showEmail ? 'text' : 'hidden',
114+
ariaHidden: options.showEmail ? 'false' : 'true',
115115
name: 'email',
116116
className: 'form__input',
117117
placeholder: options.emailPlaceholder,
@@ -158,23 +158,30 @@ export function Form({ defaultName, defaultEmail, onCancel, onSubmit, options }:
158158
},
159159
[
160160
$error,
161-
h(
162-
'label',
163-
{
164-
htmlFor: 'name',
165-
className: 'form__label',
166-
},
167-
[options.nameLabel, $name],
168-
),
169161

170-
h(
171-
'label',
172-
{
173-
htmlFor: 'email',
174-
className: 'form__label',
175-
},
176-
[options.emailLabel, $email],
177-
),
162+
!options.isAnonymous &&
163+
options.showName &&
164+
h(
165+
'label',
166+
{
167+
htmlFor: 'name',
168+
className: 'form__label',
169+
},
170+
[options.nameLabel, $name],
171+
),
172+
!options.isAnonymous && !options.showName && $name,
173+
174+
!options.isAnonymous &&
175+
options.showEmail &&
176+
h(
177+
'label',
178+
{
179+
htmlFor: 'email',
180+
className: 'form__label',
181+
},
182+
[options.emailLabel, $email],
183+
),
184+
!options.isAnonymous && !options.showEmail && $email,
178185

179186
h(
180187
'label',
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { FeedbackTheme } from '../types';
2+
3+
/**
4+
* Creates <style> element for widget actor (button that opens the dialog)
5+
*/
6+
export function createMainStyles(d: Document, theme: FeedbackTheme): HTMLStyleElement {
7+
const style = d.createElement('style');
8+
style.textContent = `
9+
:host {
10+
position: fixed;
11+
right: 1rem;
12+
bottom: 1rem;
13+
font-family: 'Helvetica Neue', Arial, sans-serif;
14+
font-size: 14px;
15+
--bg-color: ${theme.light.background};
16+
--bg-hover-color: #f6f6f7;
17+
--fg-color: ${theme.light.foreground};
18+
--error-color: #df3338;
19+
--success-color: #268d75;
20+
--border: 1.5px solid rgba(41, 35, 47, 0.13);
21+
--box-shadow: 0px 4px 24px 0px rgba(43, 34, 51, 0.12);
22+
}
23+
24+
.__dark-mode:host {
25+
--bg-color: ${theme.dark.background};
26+
--bg-hover-color: #352f3b;
27+
--fg-color: ${theme.dark.foreground};
28+
--error-color: #f55459;
29+
--success-color: #2da98c;
30+
--border: 1.5px solid rgba(235, 230, 239, 0.15);
31+
--box-shadow: 0px 4px 24px 0px rgba(43, 34, 51, 0.12);
32+
}
33+
`;
34+
35+
return style;
36+
}

packages/feedback/src/widget/util/createElement.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ function appendChild(parent: Node, child: any): void {
3939
for (const value of child) {
4040
appendChild(parent, value);
4141
}
42+
} else if (child === false) {
43+
// do nothing if child evaluated to false
4244
} else if (typeof child === 'string') {
4345
parent.appendChild(document.createTextNode(child));
4446
} else if (child instanceof Node) {

0 commit comments

Comments
 (0)