545 lines
19 KiB
React
545 lines
19 KiB
React
// Metro module 1205 (f1206).
|
|
import _classCallCheck from "./_classCallCheck";
|
|
import _createClass from "./_createClass";
|
|
import _possibleConstructorReturn from "./_possibleConstructorReturn";
|
|
import _getPrototypeOf from "./_getPrototypeOf";
|
|
import _inherits from "./_inherits";
|
|
import { Component } from "react";
|
|
import { Appearance, Keyboard, View, Text, Image, TextInput, TouchableWithoutFeedback, TouchableOpacity } from "react-native";
|
|
import { isValidEmail, feedbackAlertDialog, base64ToUint8Array } from "./Module1196";
|
|
import { debug, lastEventId, captureFeedback, getCurrentScope, getIsolationScope, getGlobalScope } from "./Module817";
|
|
import * as _Module1002 from "./Module1002";
|
|
import { isExpoGo, notWeb } from "./Module1002";
|
|
import { getDataFromUri, NATIVE } from "./Module1001";
|
|
import { defaultConfiguration } from "./Module1201";
|
|
import { lazyLoadFeedbackIntegration } from "./Module1198";
|
|
import { getTheme } from "./Module1199";
|
|
import _default from "./_default_1202";
|
|
import { getCapturedScreenshot } from "./takeScreenshot";
|
|
import { sentryLogo } from "./Module1206";
|
|
import { hideFeedbackButton, showScreenshotButton } from "./NOOP_SET_VISIBILITY";
|
|
function $mk117658($env) {
|
|
return function(a0) {
|
|
a0($env[0]);
|
|
};
|
|
}
|
|
function $mk118656($env) {
|
|
return (a0) => {
|
|
const r4 = $env;
|
|
if (a0 != null) {
|
|
r4[13].setState({
|
|
filename: r4[12],
|
|
attachment: a0,
|
|
attachmentUri: r4[0]
|
|
});
|
|
} else {
|
|
r4[13]._showImageRetrievalDevelopmentNote();
|
|
debug.error("Failed to read image data from uri:", r4[0]);
|
|
}
|
|
};
|
|
}
|
|
function $mk118657($env) {
|
|
return (a0) => {
|
|
const r1 = $env;
|
|
r1[13]._showImageRetrievalDevelopmentNote();
|
|
debug.error("Failed to read image data from uri:", r1[0], "error: ", a0);
|
|
};
|
|
}
|
|
let c1014_16;
|
|
let env1014 = {};
|
|
env1014[15] = function _isNativeReflectConstruct() {
|
|
let c12910_0;
|
|
try {
|
|
c12910_0 = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
|
|
} catch ($e) {}
|
|
const _isNativeReflectConstruct2 = function _isNativeReflectConstruct() {
|
|
return !!c12910_0;
|
|
};
|
|
env1014[15] = _isNativeReflectConstruct2;
|
|
return _isNativeReflectConstruct2();
|
|
};
|
|
c1014_16 = (this ? this.__awaiter : this) || function(c12911_0, c12911_1, a2, c12911_3) {
|
|
let r2 = a2;
|
|
let Promise2 = a2;
|
|
if (!a2) {
|
|
Promise2 = Promise;
|
|
r2 = Promise2;
|
|
}
|
|
return new r2(function(a0, c24315_1) {
|
|
let rejected2, step2;
|
|
let c24315_0 = a0;
|
|
const fulfilled2 = function fulfilled(a0) {
|
|
try {
|
|
step2(c12911_3.next(a0));
|
|
} catch ($e) {
|
|
c24315_1($e);
|
|
}
|
|
};
|
|
rejected2 = function rejected(a0) {
|
|
try {
|
|
step2(c12911_3.throw(a0));
|
|
} catch ($e) {
|
|
c24315_1($e);
|
|
}
|
|
};
|
|
step2 = function step(a0) {
|
|
if (a0.done) {
|
|
c24315_0(a0.value);
|
|
} else {
|
|
let env28860;
|
|
let value = a0.value;
|
|
const r10 = env28860 = {};
|
|
env28860[0] = value;
|
|
if (!(value instanceof Promise2)) {
|
|
value = new Promise2($mk117658(r10));
|
|
}
|
|
value.then(fulfilled2, rejected2);
|
|
}
|
|
};
|
|
const r16 = c12911_3.apply(c12911_0, c12911_1 || []);
|
|
c12911_3 = r16;
|
|
const r18 = r16.next();
|
|
const { done, value } = r18;
|
|
if (done) {
|
|
a0(value);
|
|
} else {
|
|
let env24316;
|
|
const r21 = env24316 = {};
|
|
env24316[0] = value;
|
|
(value instanceof Promise2 ? value : new Promise2($mk117658(r21))).then(fulfilled2, rejected2);
|
|
}
|
|
});
|
|
};
|
|
const FeedbackWidget = function FeedbackWidget(a0) {
|
|
_classCallCheck(this, FeedbackWidget);
|
|
const r12 = [a0];
|
|
const r11 = _getPrototypeOf(FeedbackWidget);
|
|
const r18 = (0, env1014[15])() ? Reflect.construct(r11, r12, _getPrototypeOf(this).constructor) : r11.apply(this, r12);
|
|
const _this = _possibleConstructorReturn(this, r18);
|
|
_this._didSubmitForm = false;
|
|
_this.handleFeedbackSubmit = () => {
|
|
const state = _this.state;
|
|
const { name, email, description } = state;
|
|
const props3 = _this.props;
|
|
const { onSubmitSuccess, onSubmitError, onFormSubmitted } = props3;
|
|
const props2 = _this.props;
|
|
const name2 = name == null ? void 0 : name.trim();
|
|
const email2 = email == null ? void 0 : email.trim();
|
|
const message = description == null ? void 0 : description.trim();
|
|
L27: {
|
|
if (!(_this.props.isNameRequired && !name2) && !(_this.props.isEmailRequired && !email2) && message) {
|
|
L17: {
|
|
if (_this.props.shouldValidateEmail) {
|
|
if (!_this.props.isEmailRequired && !(email2.length > 0)) {
|
|
break L17;
|
|
}
|
|
if (!isValidEmail(email2)) {
|
|
feedbackAlertDialog(props2.errorTitle, props2.emailError);
|
|
break L27;
|
|
}
|
|
}
|
|
}
|
|
const attachments = _this.state.filename ? _this.state.attachment ? [{
|
|
filename: _this.state.filename,
|
|
data: _this.state.attachment
|
|
}] : void 0 : void 0;
|
|
const r14 = {
|
|
message,
|
|
name: name2,
|
|
email: email2,
|
|
associatedEventId: lastEventId()
|
|
};
|
|
try {
|
|
if (!onFormSubmitted) {
|
|
_this.setState({
|
|
isVisible: false
|
|
});
|
|
}
|
|
captureFeedback(r14, attachments ? {
|
|
attachments
|
|
} : void 0);
|
|
onSubmitSuccess({
|
|
name: name2,
|
|
email: email2,
|
|
message,
|
|
attachments
|
|
});
|
|
feedbackAlertDialog(props2.successMessageText, "");
|
|
onFormSubmitted();
|
|
_this._didSubmitForm = true;
|
|
break L27;
|
|
} catch (r101) {
|
|
onSubmitError(new Error(`Feedback form submission failed: ${r101}`));
|
|
feedbackAlertDialog(props2.errorTitle, props2.genericError);
|
|
debug.error(`Feedback form submission failed: ${r101}`);
|
|
break L27;
|
|
}
|
|
}
|
|
feedbackAlertDialog(props2.errorTitle, props2.formError);
|
|
}
|
|
};
|
|
_this.onScreenshotButtonPress = async () => {
|
|
let c31226_1, c31226_2, _this4;
|
|
const _this3 = this;
|
|
L12: {
|
|
L50: {
|
|
L20: {
|
|
let env31887;
|
|
_this4 = _this3;
|
|
c31226_2 = void 0;
|
|
const r13 = env31887 = {
|
|
$parent: env1014
|
|
};
|
|
c31226_1 = r13;
|
|
env31887[13] = _this3;
|
|
env31887[1] = void 0;
|
|
env31887[2] = void 0;
|
|
env31887[3] = void 0;
|
|
env31887[4] = void 0;
|
|
env31887[5] = void 0;
|
|
env31887[6] = void 0;
|
|
env31887[7] = void 0;
|
|
env31887[8] = void 0;
|
|
env31887[9] = void 0;
|
|
env31887[10] = void 0;
|
|
env31887[11] = void 0;
|
|
env31887[12] = void 0;
|
|
env31887[0] = void 0;
|
|
if (_this3._hasScreenshot()) {
|
|
_this3.setState({
|
|
filename: void 0,
|
|
attachment: void 0,
|
|
attachmentUri: void 0
|
|
});
|
|
break L12;
|
|
}
|
|
const imagePicker = _this3.props.imagePicker;
|
|
env31887[6] = imagePicker;
|
|
if (imagePicker) {
|
|
const r51 = imagePicker.launchImageLibraryAsync ? () => {
|
|
const r6 = env31887[6];
|
|
const launchImageLibraryAsync = r6.launchImageLibraryAsync;
|
|
return launchImageLibraryAsync !== null ? launchImageLibraryAsync !== void 0 ? launchImageLibraryAsync.call(r6, {
|
|
mediaTypes: ["images"],
|
|
base64: _Module1002.isWeb()
|
|
}) : void 0 : void 0;
|
|
} : imagePicker.launchImageLibrary ? () => {
|
|
const r6 = env31887[6];
|
|
const launchImageLibrary = r6.launchImageLibrary;
|
|
return launchImageLibrary !== null ? launchImageLibrary !== void 0 ? launchImageLibrary.call(r6, {
|
|
mediaType: "photo",
|
|
includeBase64: _Module1002.isWeb()
|
|
}) : void 0 : void 0;
|
|
} : null;
|
|
if (r51) {
|
|
env31887[7] = await r51();
|
|
if (!(env31887[7] == null ? void 0 : env31887[7].assets)) {
|
|
break L50;
|
|
}
|
|
if (!(env31887[7].assets.length > 0)) {
|
|
break L50;
|
|
}
|
|
const isWeb = _Module1002.isWeb();
|
|
const r101 = env31887[7].assets[0];
|
|
if (isWeb) {
|
|
env31887[1] = r101;
|
|
env31887[8] = r101 !== null ? env31887[1] !== void 0 ? env31887[1].fileName : void 0 : void 0;
|
|
const r135 = env31887[7].assets[0];
|
|
env31887[2] = r135;
|
|
env31887[9] = r135 !== null ? env31887[2] !== void 0 ? env31887[2].uri : void 0 : void 0;
|
|
const r143 = env31887[7].assets[0];
|
|
env31887[3] = r143;
|
|
env31887[10] = r143 !== null ? env31887[3] !== void 0 ? env31887[3].base64 : void 0 : void 0;
|
|
env31887[11] = env31887[10] ? base64ToUint8Array(env31887[10]) : void 0;
|
|
if (env31887[11]) {
|
|
_this4.setState({
|
|
filename: env31887[8],
|
|
attachment: env31887[11],
|
|
attachmentUri: env31887[9]
|
|
});
|
|
break L50;
|
|
}
|
|
debug.error("Failed to read image data on the web");
|
|
break L50;
|
|
}
|
|
env31887[4] = r101;
|
|
env31887[12] = r101 !== null ? env31887[4] !== void 0 ? env31887[4].fileName : void 0 : void 0;
|
|
const r107 = env31887[7].assets[0];
|
|
env31887[5] = r107;
|
|
const r108 = r107 !== null ? env31887[5] !== void 0 ? env31887[5].uri : void 0 : void 0;
|
|
const r112 = c31226_1;
|
|
env31887[0] = r108;
|
|
if (!env31887[0]) {
|
|
break L50;
|
|
}
|
|
getDataFromUri(env31887[0]).then($mk118656(r112)).catch($mk118657(r112));
|
|
break L50;
|
|
}
|
|
debug.warn("No compatible image picker library found. Please provide a valid image picker library.");
|
|
break L20;
|
|
}
|
|
(0, ({
|
|
...defaultConfiguration,
|
|
..._this3.props
|
|
}).onAddScreenshot)((a0) => {
|
|
const attachmentUri = a0;
|
|
getDataFromUri(a0).then((result) => {
|
|
if (result != null) {
|
|
env31887[13].setState({
|
|
filename: "feedback_screenshot",
|
|
attachment: result,
|
|
attachmentUri
|
|
});
|
|
} else {
|
|
env31887[13]._showImageRetrievalDevelopmentNote();
|
|
debug.error("Failed to read image data from uri:", attachmentUri);
|
|
}
|
|
}).catch((error) => {
|
|
env31887[13]._showImageRetrievalDevelopmentNote();
|
|
debug.error("Failed to read image data from uri:", attachmentUri, "error: ", error);
|
|
});
|
|
});
|
|
break L12;
|
|
}
|
|
return void 0;
|
|
}
|
|
return void 0;
|
|
}
|
|
};
|
|
_this._setCapturedScreenshot = (a0) => {
|
|
if (a0.data != null) {
|
|
debug.log("Setting captured screenshot:", a0.filename);
|
|
NATIVE.encodeToBase64(a0.data).then((result) => {
|
|
if (result != null) {
|
|
_this.setState({
|
|
filename: a0.filename,
|
|
attachment: a0.data,
|
|
attachmentUri: `data:${a0.contentType};base64,${result}`
|
|
});
|
|
} else {
|
|
debug.error("Failed to read image data from:", a0.filename);
|
|
}
|
|
}).catch((error) => {
|
|
debug.error("Failed to read image data from:", a0.filename, "error: ", error);
|
|
});
|
|
} else {
|
|
debug.error("Failed to read image data from:", a0.filename);
|
|
}
|
|
};
|
|
_this._saveFormState = () => {
|
|
FeedbackWidget._savedState = {
|
|
..._this.state
|
|
};
|
|
};
|
|
_this._clearFormState = () => {
|
|
FeedbackWidget._savedState = {
|
|
name: "",
|
|
email: "",
|
|
description: "",
|
|
filename: void 0,
|
|
attachment: void 0,
|
|
attachmentUri: void 0
|
|
};
|
|
};
|
|
_this._hasScreenshot = () => _this.state.filename !== void 0 && _this.state.attachment !== void 0 && _this.state.attachmentUri !== void 0;
|
|
_this._getUser = () => {
|
|
const user = getCurrentScope().getUser();
|
|
if (user) {
|
|
return user;
|
|
}
|
|
return getIsolationScope().getUser() || getGlobalScope().getUser();
|
|
};
|
|
_this._showImageRetrievalDevelopmentNote = () => {
|
|
if (isExpoGo()) {
|
|
feedbackAlertDialog("Development note", "The feedback widget cannot retrieve image data in Expo Go. Please build your app to test this functionality.");
|
|
}
|
|
};
|
|
const props2 = _this.props;
|
|
const r34 = props2 !== null ? props2 !== void 0 ? props2.useSentryUser : void 0 : void 0;
|
|
let r35 = r34 !== null ? r34 !== void 0 ? r34.email : void 0 : void 0;
|
|
if (!r35) {
|
|
const r37 = _this._getUser();
|
|
r35 = r37 !== null ? r37 !== void 0 ? r37.email : void 0 : void 0;
|
|
}
|
|
if (!r35) {
|
|
r35 = "";
|
|
}
|
|
const props3 = _this.props;
|
|
const r40 = props3 !== null ? props3 !== void 0 ? props3.useSentryUser : void 0 : void 0;
|
|
let r41 = r40 !== null ? r40 !== void 0 ? r40.name : void 0 : void 0;
|
|
if (!r41) {
|
|
const r43 = _this._getUser();
|
|
r41 = r43 !== null ? r43 !== void 0 ? r43.name : void 0 : void 0;
|
|
}
|
|
if (!r41) {
|
|
r41 = "";
|
|
}
|
|
_this.state = {
|
|
isVisible: true,
|
|
name: FeedbackWidget._savedState.name || r41,
|
|
email: FeedbackWidget._savedState.email || r35,
|
|
description: FeedbackWidget._savedState.description || "",
|
|
filename: FeedbackWidget._savedState.filename || void 0,
|
|
attachment: FeedbackWidget._savedState.attachment || void 0,
|
|
attachmentUri: FeedbackWidget._savedState.attachmentUri || void 0
|
|
};
|
|
lazyLoadFeedbackIntegration();
|
|
return _this;
|
|
};
|
|
_inherits(FeedbackWidget, Component);
|
|
const r52 = _createClass(FeedbackWidget, [{
|
|
key: "componentDidMount",
|
|
value: function componentDidMount() {
|
|
this._themeListener = Appearance.addChangeListener(() => {
|
|
this.forceUpdate();
|
|
});
|
|
}
|
|
}, {
|
|
key: "componentWillUnmount",
|
|
value: function componentWillUnmount() {
|
|
if (this._didSubmitForm) {
|
|
this._clearFormState();
|
|
this._didSubmitForm = false;
|
|
} else {
|
|
this._saveFormState();
|
|
}
|
|
if (this._themeListener) {
|
|
this._themeListener.remove();
|
|
}
|
|
}
|
|
}, {
|
|
key: "render",
|
|
value: function render() {
|
|
const _this2 = this;
|
|
const theme = getTheme();
|
|
const state = this.state;
|
|
const { name, email, description } = state;
|
|
const onFormClose = this.props.onFormClose;
|
|
const props2 = this.props;
|
|
const props3 = this.props;
|
|
const props = this.props;
|
|
const r25 = {
|
|
..._default(theme),
|
|
...this.props.styles
|
|
};
|
|
const onCancel2 = () => {
|
|
if (onFormClose) {
|
|
onFormClose();
|
|
} else {
|
|
_this2.setState({
|
|
isVisible: false
|
|
});
|
|
}
|
|
};
|
|
if (this.state.isVisible) {
|
|
const capturedScreenshot = getCapturedScreenshot();
|
|
if (capturedScreenshot === "ErrorCapturingScreenshot") {
|
|
setTimeout(async () => {
|
|
feedbackAlertDialog(props.errorTitle, props.captureScreenshotError);
|
|
}, 100);
|
|
} else if (capturedScreenshot) {
|
|
this._setCapturedScreenshot(capturedScreenshot);
|
|
}
|
|
const props5 = {
|
|
onPress: notWeb() ? Keyboard.dismiss : void 0,
|
|
accessible: false,
|
|
accessibilityElementsHidden: false
|
|
};
|
|
const props4 = {
|
|
style: r25.container
|
|
};
|
|
const r94 = <View style={r25.titleContainer}>
|
|
<Text style={r25.title} testID="sentry-feedback-form-title">{props.formTitle}</Text>
|
|
{props2.showBranding && <Image source={{
|
|
uri: sentryLogo
|
|
}} style={r25.sentryLogo} testID="sentry-logo" />}
|
|
</View>;
|
|
const r95 = props2.showName && <>
|
|
<Text style={r25.label}>
|
|
{props.nameLabel}
|
|
{props2.isNameRequired && ` ${props.isRequiredLabel}`}
|
|
</Text>
|
|
<TextInput style={r25.input} testID="sentry-feedback-name-input" placeholder={props.namePlaceholder} value={name} onChangeText={(text) => _this2.setState({
|
|
name: text
|
|
})} />
|
|
</>;
|
|
const r121 = props2.showEmail && <>
|
|
<Text style={r25.label}>
|
|
{props.emailLabel}
|
|
{props2.isEmailRequired && ` ${props.isRequiredLabel}`}
|
|
</Text>
|
|
<TextInput style={r25.input} testID="sentry-feedback-email-input" placeholder={props.emailPlaceholder} keyboardType="email-address" value={email} onChangeText={(text) => _this2.setState({
|
|
email: text
|
|
})} />
|
|
</>;
|
|
const r161 = <Text style={r25.label}>
|
|
{props.messageLabel}
|
|
{` ${props.isRequiredLabel}`}
|
|
</Text>;
|
|
return <TouchableWithoutFeedback {...props5}>
|
|
<View {...props4}>
|
|
{r94}
|
|
{r95}
|
|
{r121}
|
|
{r161}
|
|
<TextInput style={[r25.input, r25.textArea]} testID="sentry-feedback-message-input" placeholder={props.messagePlaceholder} value={description} onChangeText={(text) => _this2.setState({
|
|
description: text
|
|
})} multiline />
|
|
{(props2.enableScreenshot || props3.imagePicker || this._hasScreenshot()) && <View style={r25.screenshotContainer}>
|
|
{this.state.attachmentUri && <Image source={{
|
|
uri: this.state.attachmentUri
|
|
}} style={r25.screenshotThumbnail} />}
|
|
<TouchableOpacity style={r25.screenshotButton} onPress={this.onScreenshotButtonPress}>
|
|
<Text style={r25.screenshotText}>
|
|
{this._hasScreenshot() ? props.removeScreenshotButtonLabel : props.addScreenshotButtonLabel}
|
|
</Text>
|
|
</TouchableOpacity>
|
|
</View>}
|
|
{notWeb() && props2.enableTakeScreenshot && !this.state.attachmentUri && <TouchableOpacity style={r25.takeScreenshotButton} onPress={() => {
|
|
hideFeedbackButton();
|
|
if (onFormClose) {
|
|
onFormClose();
|
|
} else {
|
|
_this2.setState({
|
|
isVisible: false
|
|
});
|
|
}
|
|
showScreenshotButton();
|
|
}}>
|
|
<Text style={r25.takeScreenshotText} testID="sentry-feedback-take-screenshot-button">{props.captureScreenshotButtonLabel}</Text>
|
|
</TouchableOpacity>}
|
|
<TouchableOpacity style={r25.submitButton} onPress={this.handleFeedbackSubmit}>
|
|
<Text style={r25.submitText} testID="sentry-feedback-submit-button">{props.submitButtonLabel}</Text>
|
|
</TouchableOpacity>
|
|
<TouchableOpacity style={r25.cancelButton} onPress={onCancel2}>
|
|
<Text style={r25.cancelText}>{props.cancelButtonLabel}</Text>
|
|
</TouchableOpacity>
|
|
</View>
|
|
</TouchableWithoutFeedback>;
|
|
}
|
|
return null;
|
|
}
|
|
}], [{
|
|
key: "reset",
|
|
value: function reset() {
|
|
FeedbackWidget._savedState = {
|
|
name: "",
|
|
email: "",
|
|
description: "",
|
|
filename: void 0,
|
|
attachment: void 0,
|
|
attachmentUri: void 0
|
|
};
|
|
}
|
|
}]);
|
|
r52.defaultProps = defaultConfiguration;
|
|
r52._savedState = {
|
|
name: "",
|
|
email: "",
|
|
description: "",
|
|
filename: void 0,
|
|
attachment: void 0,
|
|
attachmentUri: void 0
|
|
};
|
|
export { r52 as FeedbackWidget };
|