Skip to content

Commit

Permalink
Merge properties only once
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis committed Dec 13, 2024
1 parent c45a5e6 commit 6e39119
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/core/src/js/feedback/FeedbackForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,35 @@ import type { FeedbackFormProps, FeedbackFormState, FeedbackFormStyles,FeedbackG
* Implements a feedback form screen that sends feedback to Sentry using Sentry.captureFeedback.
*/
export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFormState> {
private _config: FeedbackFormProps;

public constructor(props: FeedbackFormProps) {
super(props);

const config: FeedbackGeneralConfiguration = { ...defaultConfiguration, ...props };
this._config = { ...defaultConfiguration, ...props };
this.state = {
isVisible: true,
name: config.useSentryUser.name,
email: config.useSentryUser.email,
name: this._config.useSentryUser.name,
email: this._config.useSentryUser.email,
description: '',
};
}

public handleFeedbackSubmit: () => void = () => {
const { name, email, description } = this.state;
const { onFormClose } = { ...defaultConfiguration, ...this.props };
const config: FeedbackGeneralConfiguration = { ...defaultConfiguration, ...this.props };
const text: FeedbackTextConfiguration = { ...defaultConfiguration, ...this.props };
const { onFormClose } = this._config;
const text: FeedbackTextConfiguration = this._config;

const trimmedName = name?.trim();
const trimmedEmail = email?.trim();
const trimmedDescription = description?.trim();

if ((config.isNameRequired && !trimmedName) || (config.isEmailRequired && !trimmedEmail) || !trimmedDescription) {
if ((this._config.isNameRequired && !trimmedName) || (this._config.isEmailRequired && !trimmedEmail) || !trimmedDescription) {
Alert.alert(text.errorTitle, text.formError);
return;
}

if (config.shouldValidateEmail && (config.isEmailRequired || trimmedEmail.length > 0) && !this._isValidEmail(trimmedEmail)) {
if (this._config.shouldValidateEmail && (this._config.isEmailRequired || trimmedEmail.length > 0) && !this._isValidEmail(trimmedEmail)) {
Alert.alert(text.errorTitle, text.emailError);
return;
}
Expand All @@ -76,9 +77,9 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
*/
public render(): React.ReactNode {
const { name, email, description } = this.state;
const { onFormClose } = { ...defaultConfiguration, ...this.props };
const config: FeedbackGeneralConfiguration = { ...defaultConfiguration, ...this.props };
const text: FeedbackTextConfiguration = { ...defaultConfiguration, ...this.props };
const { onFormClose } = this._config;
const config: FeedbackGeneralConfiguration = this._config;
const text: FeedbackTextConfiguration = this._config;
const styles: FeedbackFormStyles = { ...defaultStyles, ...this.props.styles };
const onCancel = (): void => {
onFormClose();
Expand Down

0 comments on commit 6e39119

Please sign in to comment.