Skip to content

Commit

Permalink
feat(feedback): Make "required" text for input elements configurable (g…
Browse files Browse the repository at this point in the history
…etsentry#11152) (getsentry#11153)

Fix getsentry#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 <billyvg@users.noreply.github.com>
  • Loading branch information
2 people authored and cadesalaberry committed Apr 19, 2024
1 parent 0aa512c commit fc2160c
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/feedback/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const MESSAGE_LABEL = 'Description';
export const NAME_PLACEHOLDER = 'Your Name';
export const NAME_LABEL = 'Name';
export const SUCCESS_MESSAGE_TEXT = 'Thank you for your report!';
export const IS_REQUIRED_TEXT = '(required)';

export const FEEDBACK_WIDGET_SOURCE = 'widget';
export const FEEDBACK_API_SOURCE = 'api';
Expand Down
3 changes: 3 additions & 0 deletions packages/feedback/src/core/integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
EMAIL_LABEL,
EMAIL_PLACEHOLDER,
FORM_TITLE,
IS_REQUIRED_TEXT,
MESSAGE_LABEL,
MESSAGE_PLACEHOLDER,
NAME_LABEL,
Expand Down Expand Up @@ -76,6 +77,7 @@ export const _feedbackIntegration = (({
nameLabel = NAME_LABEL,
namePlaceholder = NAME_PLACEHOLDER,
successMessageText = SUCCESS_MESSAGE_TEXT,
isRequiredText = IS_REQUIRED_TEXT,

// FeedbackCallbacks
onFormOpen,
Expand Down Expand Up @@ -116,6 +118,7 @@ export const _feedbackIntegration = (({
nameLabel,
namePlaceholder,
successMessageText,
isRequiredText,

onFormClose,
onFormOpen,
Expand Down
16 changes: 11 additions & 5 deletions packages/feedback/src/modal/components/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface Props
| 'showEmail'
| 'showName'
| 'submitButtonLabel'
| 'isRequiredText'
> {
defaultEmail: string;
defaultName: string;
Expand Down Expand Up @@ -66,6 +67,7 @@ export function Form({
showEmail,
showName,
submitButtonLabel,
isRequiredText,
screenshotInput,
}: Props): VNode {
// TODO: set a ref on the form, and whenever an input changes call proceessForm() and setError()
Expand Down Expand Up @@ -145,7 +147,7 @@ export function Form({

{showName ? (
<label for="name" class="form__label">
<LabelText label={nameLabel} isRequired={isNameRequired} />
<LabelText label={nameLabel} isRequiredText={isRequiredText} isRequired={isNameRequired} />
<input
class="form__input"
defaultValue={defaultName}
Expand All @@ -162,7 +164,7 @@ export function Form({

{showEmail ? (
<label for="email" class="form__label">
<LabelText label={emailLabel} isRequired={isEmailRequired} />
<LabelText label={emailLabel} isRequiredText={isRequiredText} isRequired={isEmailRequired} />
<input
class="form__input"
defaultValue={defaultEmail}
Expand All @@ -178,7 +180,7 @@ export function Form({
)}

<label for="message" class="form__label">
<LabelText label={messageLabel} isRequired />
<LabelText label={messageLabel} isRequiredText={isRequiredText} isRequired />
<textarea
autoFocus
class="form__input form__input--textarea"
Expand Down Expand Up @@ -223,11 +225,15 @@ export function Form({
);
}

function LabelText({ label, isRequired }: { label: string; isRequired: boolean }): VNode {
function LabelText({
label,
isRequired,
isRequiredText,
}: { label: string; isRequired: boolean; isRequiredText: string }): VNode {
return (
<span class="form__label__text">
{label}
{isRequired && <span class="form__label__text--required">(required)</span>}
{isRequired && <span class="form__label__text--required">{isRequiredText}</span>}
</span>
);
}
1 change: 1 addition & 0 deletions packages/feedback/src/modal/createDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export function createDialog({ options, screenshotIntegration, sendFeedback, sha
defaultName={(userKey && user && user[userKey.name]) || ''}
defaultEmail={(userKey && user && user[userKey.email]) || ''}
successMessageText={options.successMessageText}
isRequiredText={options.isRequiredText}
onFormClose={() => {
renderContent(false);
options.onFormClose && options.onFormClose();
Expand Down
5 changes: 5 additions & 0 deletions packages/feedback/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ export interface FeedbackTextConfiguration {
* Message after feedback was sent successfully
*/
successMessageText: string;

/**
* Text which indicates that a field is required
*/
isRequiredText: string;
}

/**
Expand Down

0 comments on commit fc2160c

Please sign in to comment.