Skip to content

Commit fca5c03

Browse files
soerfacebillyvg
andauthored
feat(feedback): Make "required" text for input elements configurable (#11152) (#11153)
Fix #11152 This introduces an option `isRequiredLabel`, and I planned to also add `errorMessageText`. However, this PR is branched off from a version that is a couple days old. Right now, @c298lee is currently working on getsentry/sentry#63749, which is causing major changes and the current version on master doesn't work yet. Therefore, I didn't yet implement `errorMessageText`. So consider this PR as a PoC, and either feel free to tag me when the screenshot changes are done – then I'll redo the changes based on the version that supports screenshots – or add the option on your own; however you prefer 🙂 One open question: Until now, there was only the error message: > There was a problem submitting feedback, please wait and try again. Now, depending on the status code, we have three error messages: > - 'Unable to send Feedback. This is because of network issues, or because you are using an ad-blocker.' > - 'Unable to send Feedback. Invalid response from server.' > - 'Unable to send Feedback' Do you have a suggestion how we could make the message configurable, without introducing too many and redundant settings? Maybe we should go back to only one message? I'm not sure if an end-user cares about whether it is a network issue or a server error. --------- Co-authored-by: Billy Vong <[email protected]>
1 parent da83bbd commit fca5c03

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

packages/feedback/src/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const MESSAGE_LABEL = 'Description';
2020
export const NAME_PLACEHOLDER = 'Your Name';
2121
export const NAME_LABEL = 'Name';
2222
export const SUCCESS_MESSAGE_TEXT = 'Thank you for your report!';
23+
export const IS_REQUIRED_TEXT = '(required)';
2324

2425
export const FEEDBACK_WIDGET_SOURCE = 'widget';
2526
export const FEEDBACK_API_SOURCE = 'api';

packages/feedback/src/core/integration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
EMAIL_LABEL,
1010
EMAIL_PLACEHOLDER,
1111
FORM_TITLE,
12+
IS_REQUIRED_TEXT,
1213
MESSAGE_LABEL,
1314
MESSAGE_PLACEHOLDER,
1415
NAME_LABEL,
@@ -76,6 +77,7 @@ export const _feedbackIntegration = (({
7677
nameLabel = NAME_LABEL,
7778
namePlaceholder = NAME_PLACEHOLDER,
7879
successMessageText = SUCCESS_MESSAGE_TEXT,
80+
isRequiredText = IS_REQUIRED_TEXT,
7981

8082
// FeedbackCallbacks
8183
onFormOpen,
@@ -116,6 +118,7 @@ export const _feedbackIntegration = (({
116118
nameLabel,
117119
namePlaceholder,
118120
successMessageText,
121+
isRequiredText,
119122

120123
onFormClose,
121124
onFormOpen,

packages/feedback/src/modal/components/Form.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export interface Props
2929
| 'showEmail'
3030
| 'showName'
3131
| 'submitButtonLabel'
32+
| 'isRequiredText'
3233
> {
3334
defaultEmail: string;
3435
defaultName: string;
@@ -66,6 +67,7 @@ export function Form({
6667
showEmail,
6768
showName,
6869
submitButtonLabel,
70+
isRequiredText,
6971
screenshotInput,
7072
}: Props): VNode {
7173
// TODO: set a ref on the form, and whenever an input changes call proceessForm() and setError()
@@ -145,7 +147,7 @@ export function Form({
145147

146148
{showName ? (
147149
<label for="name" class="form__label">
148-
<LabelText label={nameLabel} isRequired={isNameRequired} />
150+
<LabelText label={nameLabel} isRequiredText={isRequiredText} isRequired={isNameRequired} />
149151
<input
150152
class="form__input"
151153
defaultValue={defaultName}
@@ -162,7 +164,7 @@ export function Form({
162164

163165
{showEmail ? (
164166
<label for="email" class="form__label">
165-
<LabelText label={emailLabel} isRequired={isEmailRequired} />
167+
<LabelText label={emailLabel} isRequiredText={isRequiredText} isRequired={isEmailRequired} />
166168
<input
167169
class="form__input"
168170
defaultValue={defaultEmail}
@@ -178,7 +180,7 @@ export function Form({
178180
)}
179181

180182
<label for="message" class="form__label">
181-
<LabelText label={messageLabel} isRequired />
183+
<LabelText label={messageLabel} isRequiredText={isRequiredText} isRequired />
182184
<textarea
183185
autoFocus
184186
class="form__input form__input--textarea"
@@ -223,11 +225,15 @@ export function Form({
223225
);
224226
}
225227

226-
function LabelText({ label, isRequired }: { label: string; isRequired: boolean }): VNode {
228+
function LabelText({
229+
label,
230+
isRequired,
231+
isRequiredText,
232+
}: { label: string; isRequired: boolean; isRequiredText: string }): VNode {
227233
return (
228234
<span class="form__label__text">
229235
{label}
230-
{isRequired && <span class="form__label__text--required">(required)</span>}
236+
{isRequired && <span class="form__label__text--required">{isRequiredText}</span>}
231237
</span>
232238
);
233239
}

packages/feedback/src/modal/createDialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export function createDialog({ options, screenshotIntegration, sendFeedback, sha
6969
defaultName={(userKey && user && user[userKey.name]) || ''}
7070
defaultEmail={(userKey && user && user[userKey.email]) || ''}
7171
successMessageText={options.successMessageText}
72+
isRequiredText={options.isRequiredText}
7273
onFormClose={() => {
7374
renderContent(false);
7475
options.onFormClose && options.onFormClose();

packages/feedback/src/types/config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ export interface FeedbackTextConfiguration {
135135
* Message after feedback was sent successfully
136136
*/
137137
successMessageText: string;
138+
139+
/**
140+
* Text which indicates that a field is required
141+
*/
142+
isRequiredText: string;
138143
}
139144

140145
/**

0 commit comments

Comments
 (0)