Skip to content

Commit

Permalink
Use defaultProps
Browse files Browse the repository at this point in the history
  • Loading branch information
antonis committed Dec 17, 2024
1 parent 0f3a244 commit 9a96e74
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions packages/core/src/js/feedback/FeedbackForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SendFeedbackParams } from '@sentry/core';
import { captureFeedback, getCurrentScope, lastEventId } from '@sentry/core';
import type { SendFeedbackParams } from '@sentry/types';
import * as React from 'react';
import type { KeyboardTypeOptions } from 'react-native';
import {
Expand All @@ -24,7 +24,7 @@ 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 static defaultProps: Partial<FeedbackFormProps>;

public constructor(props: FeedbackFormProps) {
super(props);
Expand All @@ -36,30 +36,30 @@ export class FeedbackForm extends React.Component<FeedbackFormProps, FeedbackFor
}
}

this._config = { ...defaultConfiguration, ...currentUser, ...props };
FeedbackForm.defaultProps = { ...defaultConfiguration, ...currentUser, ...props };
this.state = {
isVisible: true,
name: this._config.useSentryUser.name,
email: this._config.useSentryUser.email,
name: currentUser.useSentryUser.name,
email: currentUser.useSentryUser.email,
description: '',
};
}

public handleFeedbackSubmit: () => void = () => {
const { name, email, description } = this.state;
const { onFormClose } = this._config;
const text: FeedbackTextConfiguration = this._config;
const { onFormClose } = FeedbackForm.defaultProps;
const text: FeedbackTextConfiguration = FeedbackForm.defaultProps;

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

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

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

0 comments on commit 9a96e74

Please sign in to comment.