Files
discord-decomp/modules/qualtrics/QualtricsActionCreators.tsx
T
2026-11-01 12:12:55 +02:00

241 lines
6.7 KiB
TypeScript

// Metro module 9273 (f9274).
import SurveyStore from "../../stores/SurveyStore";
import { useQualtricsResponseStore } from "./QualtricsResponseStore";
import QualtricsStore from "./QualtricsStore";
import { QuestionTypeEnum, QuestionSelectorEnum } from "./QualtricsConstants";
import { Endpoints } from "../../Constants";
import { HTTP } from "../../_bundle/sendRequest";
import Dispatcher from "../../Dispatcher";
import SentryUtils_native from "../../utils/SentryUtils.native";
import { SURVEY_ACTION_SAMPLE_PERCENTS } from "../../_bundle/Module9279";
let env6103 = {};
export async function fetchSurveyDetails(c26409_0) {
let r62;
let c26409_3;
let c26409_4 = 0;
let c30077_0, c30077_1, c30077_2;
try {
c30077_0 = c26409_0;
c30077_1 = void 0;
c26409_4 = 1;
c30077_1 = (await HTTP.get({
url: Endpoints.EMBEDDED_SURVEY(c26409_0),
rejectWithError: true
})).body;
Dispatcher.dispatch({
type: "QUALTRICS_SURVEY_FETCH_SUCCESS",
surveyId: c30077_0,
surveyDetails: c30077_1
});
r62 = c30077_1;
c26409_4 = 0;
} catch ($e) {
const r25 = $e;
let r8 = r25;
c26409_3 = r25;
if (c26409_4 !== 0) {
while (true) {
try {
const r71 = c26409_3;
c26409_4 = 0;
c30077_2 = r71;
SentryUtils_native.captureException(c30077_2);
} catch (r67) {
r8 = r67;
c26409_3 = r67;
if (c26409_4 === 0) {
break;
}
continue;
}
return null;
}
}
throw r8;
}
return r62;
}
export async function submitSurveyResponse(c26410_0, c26410_1) {
let displayedQuestions, value, c26410_4, c26410_5, c26410_7;
let c26410_6 = 0;
const r10 = env6103;
L14: {
try {
let env30078;
c26410_5 = r10;
const r32 = env30078 = {
$parent: r10
};
c26410_4 = r32;
const displayedQuestions2 = useQualtricsResponseStore.getState().getDisplayedQuestions(c26410_0);
displayedQuestions = displayedQuestions2;
if (displayedQuestions2 == null) {
displayedQuestions = [];
}
const r21 = (function parseSurveyResponses(a0, a1, a2) {
const survey = QualtricsStore.getSurvey(a0);
if (survey == null) {
return null;
}
const r39 = {};
let c31501_1 = r39;
for (const item of Object.entries(a1)) {
const [r48, r50] = item;
const r52 = survey.Questions[r48];
if (r52 != null) {
if (r52.QuestionType === QuestionTypeEnum.MULTIPLE_CHOICE && r52.Selector === QuestionSelectorEnum.MULTIPLE_ANSWER) {
r39[r48] = r50.split(",");
if (r52.ChoiceOrder == null) {
continue;
}
r39[`${r48}_DO`] = r52.ChoiceOrder;
continue;
}
if (r52.QuestionType === QuestionTypeEnum.MULTIPLE_CHOICE && r52.Selector === QuestionSelectorEnum.SINGLE_ANSWER) {
if (r50.includes(":TEXT:")) {
const r23 = r50.split(":TEXT:", 2)[0];
const r90 = r50.split(":TEXT:", 2)[1];
r39[r48] = parseInt(r23);
r39[`${r48}_${r23}_TEXT`] = r90;
} else {
r39[r48] = parseInt(r50);
}
if (r52.ChoiceOrder == null) {
continue;
}
r39[`${r48}_DO`] = r52.ChoiceOrder;
continue;
}
if (r52.QuestionType === QuestionTypeEnum.TEXT_ENTRY) {
r39[`${r48}_TEXT`] = r50;
} else {
r39[r48] = r50;
}
}
}
let c31501_2 = Object.keys(a1);
a2.forEach((item) => {
if (!c31501_2.includes(item)) {
const r11 = survey.Questions[item];
if (r11 == null) {
return void 0;
}
if (r11.ChoiceOrder != null && r11.QuestionType === QuestionTypeEnum.MULTIPLE_CHOICE) {
if (r11.Selector === QuestionSelectorEnum.MULTIPLE_ANSWER) {
c31501_1[item] = [];
}
c31501_1[`${item}_DO`] = r11.ChoiceOrder;
}
}
});
return r39;
})(c26410_0, c26410_1, displayedQuestions);
if (r21 == null) {
break L14;
}
c26410_6 = 1;
value = {};
value.responseId = (await HTTP.post({
url: Endpoints.EMBEDDED_SURVEY_RESPONSE(c26410_0),
body: {
values_json: JSON.stringify(r21)
},
rejectWithError: true
})).body.responseId;
c26410_6 = 0;
} catch ($e) {
const r30 = $e;
let r8 = r30;
c26410_7 = r30;
if (c26410_6 !== 0) {
while (true) {
try {
const r85 = c26410_7;
c26410_6 = 0;
env30078[0] = r85;
SentryUtils_native.captureException(env30078[0]);
} catch (r81) {
r8 = r81;
c26410_7 = r81;
if (c26410_6 === 0) {
break;
}
continue;
}
return {
responseId: "null"
};
}
}
throw r8;
}
return value;
}
return {
responseId: "null"
};
}
export async function fireSurveyAction(action_type, metadata) {
let c26411_2, c26411_3;
let c26411_4 = 0;
const r10 = env6103;
L18: {
try {
let env30079;
c26411_3 = r10;
const r15 = env30079 = {
$parent: r10
};
c26411_2 = r15;
env30079[0] = void 0;
if ((function shouldFireSurveyAction(a0) {
return !!SurveyStore.shouldAllowSurveyAction() && SURVEY_ACTION_SAMPLE_PERCENTS[a0] >= 100 * Math.random();
})(action_type)) {
const body = {
action_type
};
if (metadata != null) {
body.metadata = metadata;
}
c26411_4 = 1;
env30079[0] = await HTTP.post({
url: Endpoints.EMBEDDED_SURVEY_ACTION,
body,
rejectWithError: true
});
const r62 = env30079[0];
Dispatcher.dispatch({
type: "SURVEY_FETCHED",
survey: r62 == null ? void 0 : r62.body?.survey,
isActionTriggered: true
});
c26411_4 = 0;
break L18;
}
} catch ($e) {
let r24 = $e;
if (c26411_4 !== 0) {
while (true) {
try {
c26411_4 = 0;
break L18;
} catch ($e) {
r24 = $e;
if (c26411_4 === 0) {
break;
}
}
}
}
throw r24;
}
return void 0;
}
}
const r36 = {
fetchSurveyDetails,
submitSurveyResponse,
fireSurveyAction
};
export default r36;